吴恩达 ChatGPT Prompt Engineering for Developers 系列课程笔记--04 Summarizing

04 Summarizing

文本总结时大语言模型的最实用的应用之一。

1) 示例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

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)

模型生成的结果为"Soft and cute panda plush toy loved by daughter, but a bit small for the price. Arrived early."
可以通过指定部门来改变文本摘要的内容。下述prompt中指定了总结内容要反馈给定价部门,从而生成的结果会有所调整

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
pricing department, 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}```
"""

修改之后的prompt生成摘要为"The panda plush toy is soft, cute, and loved by the recipient, but the price may be too high for its size."相比原始内容,侧重于商品的价格

2) 示例2: 提取式摘要

我们可以将prompt中的generate a short summary of修改为extract relevant information from,得到从原始文本中直接提取的摘要信息,即生成的摘要由原始文本中的句子构成。修改后的prompt输入ChatGPT得到提取式摘要为"The product arrived a day earlier than expected."

3) 示例3:同时总结多个摘要

可以将多个待review的文本放在列表中,可通过简单的for循环将每个review通过上述方式进行总结、打印,这样我们就可以不间断地阅读大量带review文本的摘要了。

上一篇:吴恩达 ChatGPT Prompt Engineering for Developers 系列课程笔记–03 Iterative

下一篇:吴恩达 ChatGPT Prompt Engineering for Developers 系列课程笔记–05 Inferring

deeplearning.ai 原课程地址

课程中文翻译地址

你可能感兴趣的:(chatgpt,语言模型,OpenAI,吴恩达,课程学习)