介绍
介绍完信息总结,再聊聊信息提取,我认为这个场景是继场景 3 推理以外,第二个值得深挖的场景。这个场景有非常多的有意思的场景,比如:
- 将一大段文字,甚至网页里的内容,按要求转为一个表格。按照这个思路你可以尝试做一个更智能的,更易懂的爬虫插件。
- 按照特定格式对文章内容进行信息归类。
第二个可能比较难理解,举个 openai 里的,它的 prompt 是这样的(为了有足够空间显示内容,我仅节选了 text 里的部分内容,完整内容,可以查看):
extract the important entities mentioned in the article below. first extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes
desired format:
company names:
people names: -||-
specific topics: -||-
general themes: -||-
text: """powering next generation
applications with openai codex
codex is now powering 70 different applications across a variety of use cases through the openai api.
may 24, 2022
4 minute read
openai codex, a natural language-to-code system based on gpt-3, helps turn simple english instructions into over a dozen popular coding languages. codex was released last august through our api and is the principal building block of github copilot.
warp is a rust-based terminal, reimagined from the ground up to help both individuals and teams be more productive in the command-line.
terminal commands are typically difficult to remember, find and construct. users often have to leave the terminal and search the web for answers and even then the results might not give them the right command to execute. warp uses codex to allow users to run a natural language command to search directly from within the terminal and get a result they can immediately use.
“codex allows warp to make the terminal more accessible and powerful. developers search for entire commands using natural language rather than trying to remember them or assemble them piecemeal. codex-powered command search has become one of our game changing features.”
—zach lloyd, founder, warp
machinet helps professional java developers write quality code by using codex to generate intelligent unit test templates.
machinet was able to accelerate their development several-fold by switching from building their own machine learning systems to using codex. the flexibility of codex allows for the ability to easily add new features and capabilities saving their users time and helping them be more productive.
“codex is an amazing tool in our arsenal. not only does it allow us to generate more meaningful code, but it has also helped us find a new design of product architecture and got us out of a local maximum.”
—vladislav yanchenko, founder, machinet"""
prompt 有点长,我解释下,它是让 ai 将文章里的重点内容进行抽离,并将其根据特定格式进行输出。要求将文章里提到的公司、人名、主题都按照 comma separated list(按逗号空格分开)的方式罗列出来。
最后的 output 是这样的:
company names: openai, microsoft, github, pygma, replit, warp, machinet
people names: emile paffard-wray, amjad masad, zach lloyd, vladislav yanchenko
specific topics: gpt-3, openai api, azure openai service, github copilot, pygma, replit, warp, machinet
general themes: natural language-to-code, productivity, problem solving, creativity, learning
6:通过格式词阐述需要输出的格式
上述的案例,就是用到了这个技巧。这个技巧是技巧 2 的变种,比较常用于生成文本场景。其实在场景 7 中,你也可以用到这个技巧。
假设你想让 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_moderate_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/yun238423.html