本文基于对于吴恩达老师的课程学习笔记,将描述如何通过Sumarizing 总结的方式,简化我们相关的任务或者优化相关的流程。
个人观点:提示词难不难?不难,直接用自然语言交流。提示词容不容易?不容易,本身是个很抽象的东西,关键点还在于能不能结合自身的知识经验体系构建出有价值的prompt。
这是一个信息大爆炸的时代,互联网上随处可见的充斥着各种信息、知识。或者是工作中经常和信息打交道的,我们很难有足够的时间去阅读所有的内容,这个时候我们可以让AI充当我们的小助手,帮助我们提取关键信息,然后我们再去筛选找到重点去阅读。
同样的下面继续通过示例来回忆一下课程中提到的 Summarizing 总结
。下面的示例场景是电商业务中我们收到的评论,通过AI辅助我们更快速、高效的完成相关的任务。
# 示例
text = f"""
这个熊猫毛绒玩具是我女儿的生日礼物,
他爱它,到处带着它。它很软而且
超级可爱,它的脸看起来很友好。这是
不过就我花的钱来说有点小了。我想是这样的
可能同样的价格还有其他更大的选择
。它比预期提前一天到达,
所以我得在给他之前亲自把玩一下
给她。
"""
prompt = f"""
您的任务是生成产品的简短摘要
根据电子商务网站的评论。
总结下面的评论,由三重分隔
反引号,最多 30 个字。
用英文输出.
评论: ```{text}```
"""
# 输出结果:
柔软可爱的熊猫毛绒玩具,深受孩子们的喜爱。然而,就价格而言,它可能很小,而且还有其他更大的选择。比预期提前一
天到达。(加入“用英文输出.”的prompt,英文输出结果)
熊猫毛绒玩具-软、可爱、友好,但有点小。(中文输出结果)
正如上面的输出结果,我们可以看到模型遵循我们的要求进行了提炼然后更简洁的输出,通过这种总结提炼过后的信息我们可能可以能够在工作中更快的去处理。有一点值得注意的是,不同的语言输出会有不同的结果,估计还是因为训练的时候一个语料比重的原因。
下面我们继续迭代我们的提示词。
# 示例
# 这个时候加入角色,明确这个数据是面向定价部门的
prompt = f"""
您的任务是生成产品的简短摘要
来自电子商务网站的评论以向
价格部门,负责确定
产品的价格。
总结下面的评论,由三重分隔
反引号,最多 30 个字,并关注任何方面
与价格和感知价值相关,并且只输出和价格有关内容.
评论: ```{text}```
"""
# 输出结果:
产品简短摘要: "熊猫毛绒玩具-软、可爱、友好,但价格不太匹配大小。"
我们可以看到通过总结将最终的输出一步步的精简,最终我们可以非常快速的看到我们关注的重点内容。下面继续通过一个更为直观的例子结束这一篇文章笔记。下面同样是一个电商的例子,我们如何让AI辅助我们快速的浏览信息。
# 示例
# 提取文本中的重点信息,精简总结。
# 下面是电商平台上的4段评论信息,这么长的文本数据我们一开始就一段段的仔细阅读是必然很吃力的。
# 这个时候我们就需要AI来帮助我们提取重点信息了。
review_1 = prod_review
# review for a standing lamp
review_2 = """
Needed a nice lamp for my bedroom, and this one \
had additional storage and not too high of a price \
point. Got it fast - arrived in 2 days. The string \
to the lamp broke during the transit and the company \
happily sent over a new one. Came within a few days \
as well. It was easy to put together. Then I had a \
missing part, so I contacted their support and they \
very quickly got me the missing piece! Seems to me \
to be a great company that cares about their customers \
and products.
"""
# review for an electric toothbrush
review_3 = """
My dental hygienist recommended an electric toothbrush, \
which is why I got this. The battery life seems to be \
pretty impressive so far. After initial charging and \
leaving the charger plugged in for the first week to \
condition the battery, I've unplugged the charger and \
been using it for twice daily brushing for the last \
3 weeks all on the same charge. But the toothbrush head \
is too small. I’ve seen baby toothbrushes bigger than \
this one. I wish the head was bigger with different \
length bristles to get between teeth better because \
this one doesn’t. Overall if you can get this one \
around the $50 mark, it's a good deal. The manufactuer's \
replacements heads are pretty expensive, but you can \
get generic ones that're more reasonably priced. This \
toothbrush makes me feel like I've been to the dentist \
every day. My teeth feel sparkly clean!
"""
# review for a blender
review_4 = """
So, they still had the 17 piece system on seasonal \
sale for around $49 in the month of November, about \
half off, but for some reason (call it price gouging) \
around the second week of December the prices all went \
up to about anywhere from between $70-$89 for the same \
system. And the 11 piece system went up around $10 or \
so in price also from the earlier sale price of $29. \
So it looks okay, but if you look at the base, the part \
where the blade locks into place doesn’t look as good \
as in previous editions from a few years ago, but I \
plan to be very gentle with it (example, I crush \
very hard items like beans, ice, rice, etc. in the \
blender first then pulverize them in the serving size \
I want in the blender then switch to the whipping \
blade for a finer flour, and use the cross cutting blade \
first when making smoothies, then use the flat blade \
if I need them finer/less pulpy). Special tip when making \
smoothies, finely cut and freeze the fruits and \
vegetables (if using spinach-lightly stew soften the \
spinach then freeze until ready for use-and if making \
sorbet, use a small to medium sized food processor) \
that you plan to use that way you can avoid adding so \
much ice if at all-when making your smoothie. \
After about a year, the motor was making a funny noise. \
I called customer service but the warranty expired \
already, so I had to buy another one. FYI: The overall \
quality has gone done in these types of products, so \
they are kind of counting on brand recognition and \
consumer loyalty to maintain sales. Got it in about \
two days.
"""
reviews = [review_1, review_2, review_3, review_4]
# 然后我们去循环处理prompt
for i in range(len(reviews)):
prompt = f"""
您的任务是生成产品的简短摘要
根据电子商务网站的评论。
总结下面的评论,由三重反引号分割
最多 20 个单词。
评论: ```{reviews[i]}```
"""
response = get_completion(prompt)
print(i, response, "\n")
# 输出结果:
0 女儿喜欢的柔软可爱的熊猫毛绒玩具,但价格偏小。早到了。
1 经济实惠的灯具有存储、快速运输和卓越的客户服务。易于组装。
2 电池寿命长,牙刷头小,50 美元划算,更换头很贵,感觉牙齿很干净。
3 客户注意到价格上涨和质量下降,但分享了使用搅拌机的技巧。一年后电机出现问题。
通过上面的操作,我们可以找到重点内容之后再去看对应的原文本,而不再是直接一段段仔细的去看,实际上已经帮助我们完成了一轮提取筛选
,这样的处理实际上对于我们阅读信息的效率有了大幅度的提高,我们更加轻松的捕捉到了重点。下一章节 Inferring 推断 和 Transforming 转换。