ChatGPT提示词工程(三):Summarizing概括总结

news/2024/5/20 7:41:42 标签: chatgpt, 人工智能, AI, openai

目录

  • 一、说明
  • 二、安装环境
  • 三、概括总结(Summarizing)
    • 1. 简单地概括总结,只有字数限制
    • 2. 概括总结需要关注的某些点
  • 四、用“提取”代替“总结”(Try "extract" instead of "summarize")
  • 五、概括总结多个产品评价(Summarize multiple product reviews)

一、说明

这是吴恩达 《ChatGPT Prompt Engineering for Developers》 的课程笔记系列。
本文是第四讲的内容:Summarizing

二、安装环境

参考: ChatGPT提示词工程(一):Guidelines准则 的第二节

三、概括总结(Summarizing)

1. 简单地概括总结,只有字数限制

prod_review = """
Got this panda plush toy for my daughter's birthday, \
who loves it and takes it everywhere. It's soft and \ 
super cute, and its face has a friendly look. It's \ 
a bit small for what I paid though. I think there \ 
might be other options that are bigger for the \ 
same price. It arrived a day earlier than expected, \ 
so I got to play with it myself before I gave it \ 
to her.
"""
prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site. 

Summarize the review below, delimited by triple 
backticks, in at most 30 words. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

Prompt中任务是要求模型总结prod_review,要求30字以内,运行结果:
在这里插入图片描述

2. 概括总结需要关注的某些点

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
Shipping deparmtment. 

Summarize the review below, delimited by triple 
backticks, in at most 30 words, and focusing on any aspects \
that mention shipping and delivery of the product. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

代码中,要求模型关注商品的运输和交付方面,运行结果:
在这里插入图片描述

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
pricing deparmtment, responsible for determining the \
price of the product.  

Summarize the review below, delimited by triple 
backticks, in at most 30 words, and focusing on any aspects \
that are relevant to the price and perceived value. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

代码中,要求模型关注商品的价格和价值,运行结果:
在这里插入图片描述
注意:模型给出的结果中,除了你所关注的方面,还会给出一些无关的内容,这需要在实际的运用中由你自己决定是否有用。
https://blog.csdn.net/Jay_Xio/article/details/130456580



四、用“提取”代替“总结”(Try “extract” instead of “summarize”)

上一节中,总结的内容中会有一些无关的内容输出,而使用提取信息会好一点

prompt = f"""
Your task is to extract relevant information from \ 
a product review from an ecommerce site to give \
feedback to the Shipping department. 

From the review below, delimited by triple quotes \
extract the information relevant to shipping and \ 
delivery. Limit to 30 words. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

代码中,要求模型提取相关信息反馈给商品运输部门,模型给出的结果简单明了,只有商品提前一天到达的信息,结果如下:
在这里插入图片描述
https://blog.csdn.net/Jay_Xio/article/details/130456580



五、概括总结多个产品评价(Summarize multiple product reviews)

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]


for i in range(len(reviews)):
    prompt = f"""
    Your task is to generate a short summary of a product \ 
    review from an ecommerce site. 

    Summarize the review below, delimited by triple \
    backticks in at most 20 words. 

    Review: ```{reviews[i]}```
    """

    response = get_completion(prompt)
    print(i, response, "\n")

代码中, 有四个产品评价,需要模型进行总结,代码运行模型分别给出了四个总结结果:

在这里插入图片描述


http://www.niftyadmin.cn/n/280090.html

相关文章

Human Pose as Compositional Tokens 阅读笔记

人体姿态作为合成 token —— CVPR2023 论文链接 代码链接 摘要: 人体姿态常由身体关节的坐标向量或其热图embedding表示。虽然数据易于处理,但由于身体关节间缺乏依赖建模,即使是不现实的姿态也被接受。本文提出了一种结构化表示&#xff1…

第十章 游戏对象和组件访问

本节我们主要学习GameObject类,该类用于表示任何存在于场景中的游戏对象。这个类继承自Unity Object类(不是C#语言的Object类),我们可以理解这个Unity Object类是所有Unity的基类。这个Unity Object基类比较简单,我们很…

14-3-进程间通信-消息队列

前面提到的管道pipe和fifo是半双工的,在某些场景不能发挥作用; 接下来描述的是消息队列(一种全双工的通信方式); 比如消息队列可以实现两个进程互发消息(不像管道,只能1个进程发消息&#xff…

PAT A1019 General Palindromic Number

1019 General Palindromic Number 分数 20 作者 CHEN, Yue 单位 浙江大学 A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are pa…

Photoshop如何使用路径与矢量工具之实例演示?

文章目录 0.引言1.制作名片2.利用钢笔工具抠出复杂图像3.制作App图标4.制作软件登录界面5.将图片切成九宫格 0.引言 因科研等多场景需要进行绘图处理,笔者对PS进行了学习,本文通过《Photoshop2021入门教程》及其配套素材结合网上相关资料进行学习笔记总结…

【深度学习】BERT是什么?怎么玩的?

RNN 也是一种Seq2Seq网络 这种RNN就不能并行运算,且对于长句子会造成损失遗忘或者梯度爆炸 Transfomer Transformer由且仅由self-Attenion和Feed Forward Neural Network组成。一个基于Transformer的可训练的神经网络可以通过堆叠Transformer的形式进行搭建&…

spark读取json spark.read.json 多种模式的区别

三种模式: PERMISSIVE 默认 放任的,允许的 DROPMALFORMED 减少畸形 FAILFAST 快速放弃,快速失败 测试数据: {"user_id": 100, "score": 50} {"user_id": 200, "score": 51} {"user_id": 300, "score": 45.0}…

sed进阶之模式替换

shell脚本编程系列 &符号可以代表替换命令中的匹配模式,不管模式匹配到了什么样的文本,都可以使用&符号代表这些内容。这样就能处理匹配模式的任何单词了。 echo "The cat sleeps in his hat." | sed s/.at/"&"/g&…