假设你想让 ai 总结一篇非常非常长的文章,并且按照特定格式给你总结,那你可以在文章前面明确输出的格式(为了不占用太多显示空间,我省略了正文内容,你可以在 openai 的 playground 看到)。它的意思其实是让 chatgpt 按 topic 总结,每个 topic 里按照无序列表(就是里面那个 -)将每个 topic 的主要观点罗列出来。
summarize the main points of the following speech
use the following format:
topic 1:
-
..
topic 2:
-
..
topic 10: ..
text: """
thank you so much, fred, for that lovely introduction. and thanks to the atlantic council for hosting me today.
the course of the global economy over the past two years has been shaped by covid-19 and our efforts to fight the pandemic. it’s now evident, though, that the war between russia and ukraine has redrawn the contours of the world economic outlook. vladimir putin’s unprovoked attack on ukraine and its people is taking a devastating human toll, with lives tragically lost, families internally displaced or becoming refugees, and communities and cities destroyed.
...
"""
output 是这样的:
topic 1: the war in ukraine
- the war is taking a human toll with lives lost, families displaced, and communities destroyed
- the biden administration is committed to holding russia accountable
- the war has violated international law and is a challenge to the international order
topic 2: the global economy
- the war is having negative impacts on the global economy, including higher commodity prices and inflation
- the imf and world bank will be focused on helping developing countries weather the impacts of the war
- the ultimate outcome for the global economy depends on the path of the war
关于这个场景和技巧,我想再解释一下为什么潜力很大。
根据我使用各种 summary 或者信息提取的产品,我发现 ai 并不知道什么是重点,所以在总结的过程中,会丢失很多内容。如何引导 ai 进行总结,就变得非常重要,且具有一定的可玩性。
感谢 的分享,ta 提到一个使用此技巧的场景:
使用此技巧可以使输出更结构化。比如针对一篇文章进行问答,你不仅想要得到一个答案,也希望 chatgpt 的答案符合特定的格式,方便你下一步进行自动化。
比如问 “这里的债券 duration 是多少?”. 正常 gpt 模型的答案可能是 “债券 duration 是 4 年” 或 “duration 4 年”。 chatgpt 的回答不稳定,且不方便继续处理。
解法: 我们可以通过这个技巧,让模型理解我们预期的格式。并在此基础上,为了方便自动化,让模型输出特定的结构化答案 (比如 json/markdown 等)。 也可以方便集成更多的额外要求,比如增加一个”confidence level”, 并通过 prompt 的形式指定这些数值的格式。
比如:
{context}
question: what is bond duration mentioned here.
answer template (valid json format):
{{
"duration": $duration_numeric_value_in_year,
"confidence_level": $answer_confidence_level_high_modrate_or_low,
}}
answer:
在吴恩达的 chatgpt prompt engineering 中,有提到一个这个技巧的高级用法,在让 ai 按照特定格式输出内容的同时,还让 ai 根据内容是否满足特定条件,来判断应该输出什么结果,下面课程中的案例的 prompt(注意这个是 python 代码,有一些转义字符,可以不用管):
you will be provided with text delimited by triple quotes.
if it contains a sequence of instructions, \
re-write those instructions in the following format:
step 1 - ...
step 2 - …
…
step n - …
if the text does not contain a sequence of instructions, \
then simply write \"no steps provided.\"
\"\"\"{text}\"\"\"
简单解释下,这个 prompt 分成两步:
让 ai 将输入的 text 转为步骤(就是 prompt 里的 step 1、2)
然后还增加了一个判断,如果输入的 text 里没有 step 的内容,那么就输出 no step
假如输入的 text 是一个泡茶的步骤介绍:
making a cup of tea is easy! first, you need to get some \
water boiling. while that's happening, \
grab a cup and put a tea bag in it. once the water is \
hot enough, just pour it over the tea bag. \
let it sit for a bit so the tea can steep. after a \
few minutes, take out the tea bag. if you \
like, you can add some sugar or milk to taste. \
and that's it! you've got yourself a delicious \
cup of tea to enjoy.
那么 ai 输出的内容是这样的(因为内容中包含了步骤式的内容):
step 1 - get some water boiling.
step 2 - grab a cup and put a tea bag in it.
step 3 - once the water is hot enough, pour it over the tea bag.
step 4 - let it sit for a bit so the tea can steep.
step 5 - after a few minutes, take out the tea bag.
step 6 - add some sugar or milk to taste.
step 7 - enjoy your delicious cup of tea!
但如果我们输入的是这样的 text:
the sun is shining brightly today, and the birds are \
singing. it's a beautiful day to go for a \
walk in the park. the flowers are blooming, and the \
trees are swaying gently in the breeze. people \
are out and about, enjoying the lovely weather. \
some are having picnics, while others are playing \
games or simply relaxing on the grass. it's a \
perfect day to spend time outdoors and appreciate the \
beauty of nature.
从内容上看,这段话,没有任何步骤式的内容,所以 ai 的输出是这样的:
no steps provided.
原创文章,作者:校长,如若转载,请注明出处:https://www.yundongfang.com/yun238435.html