ChatGPT Prompting开发实战(八)

2023-09-14 01:12:40

一. 什么是归纳总结式的prompt开发

有时候需要对一段文本进行归纳总结,那么可以采取以下的方案:

-按照给定单词、句子或者字符的数量限制来让模型裁剪文本,使内容更精炼

-基于聚焦的主题进行总结

-只根据需求抽取相关的文本信息,不需要整段文本内容

除了上面列出的几种方式之外,还可能有额外的一些需求,譬如给出多段文本,要求模型同时对这些文本进行归纳总结。

接下来会给出具体示例,通过调用模型“gpt-3.5-turbo”来演示并解析如何针对以上谈到的这些文本归纳总结的需求,编写相应的prompts。

二. 结合案例演示解析如何使用prompt进行文本归纳总结

首先给出一段需要进行归纳总结的文本:

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)

打印输出结果如下:

This panda plush toy is loved by the reviewer's daughter, but they feel it is a bit small for the price.

接下来修改prompt,针对产品物流这个主题进行总结。

prompt示例如下:

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)

打印输出结果如下:

The customer is happy with the product but suggests offering larger options for the same price. They were pleased with the early delivery.

继续修改prompt,从产品价格和价值方面进行总结。

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 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)

打印输出结果如下:

The reviewer is satisfied with the quality and appearance of the panda plush toy but feels that it is overpriced compared to similar options available.

下面通过修改prompt达到只抽取相关的文本信息的目的,而不需要对整段文本进行概括总结。

prompt示例如下:

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)

打印输出结果如下:

The shipping department should take note that the product arrived a day earlier than expected.

接下来额外给出另外3段文本,要求模型对这4段文本同时进行总结,条件就是输出内容不能超过指定的字数限制。

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"""

    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")

打印输出结果如下:

0 Panda plush toy is loved by daughter, soft and cute, but small for the price. Arrived early. 

1 Great lamp with storage, fast delivery, excellent customer service, and easy assembly. Highly recommended. 

2 The reviewer recommends the electric toothbrush for its impressive battery life, but criticizes the small brush head. 

3 The reviewer found the price increase after the sale disappointing and noticed a decrease in quality. 

更多推荐

【Java】泛型

简单泛型促成泛型出现的最主要的动机之一是为了创建集合类,我们先看一个只能持有单个对象的类。这个类可以明确指定其持有的对象的类型://generics/Holder1.javaclassAutomobile{}publicclassHolder1{privateAutomobilea;publicHolder1(Auto

解决文件只能在windows系统上传成功,而linux系统上传失败。

场景:在我们项目准备上线进行SIT测试的时候,测试在文件上传的时候,一直上传不成功,表示当前文件不支持上传,然后我们让测试将他的文件发送给我们进行测试,我们是能够上传成功的,然后询问他们使用的什么系统,发现他们使用的是Linux发行版操作系统Ubuntu。分析原因:可能是由于Linux和Windows操作系统在处理文件

ES6之Map和Set有什么不同?

一、Map1.定义Map是ES6提供的一种新的数据结构,它是键值对的集合,类似于对象,但是键的范围不限于字符串,各种类型的值都可以当做键。Object结构是“字符串-值”的对应,Map结构则是“值-值”的对应2.代码示例Map本身是一个构造函数,先来生成一个Map数据结构,从打印的结果就可以看出,Map实例有以下属性和

C#,《小白学程序》第二十三课:大数的除法(BigInteger Divide)

1文本格式///<summary>///比较a,b的大小,返回1,0,-1///数据从低位(右)往高位(左)存储;///</summary>///<paramname="a"></param>///<paramname="b"></param>///<returns></returns>publicstaticintb

pytorch的卷积层池化层和非线性变化 和机器学习线性回归

卷积层:两个输出的情况就会有两个通道可以改变通道数的最简单的神经网络结构:nn.Mudule就是继承父类super执行的是先执行父类函数里面的forward执行的就是前向网络,就是往前推进的,当然也有反向转播,那就是用来就gradientdicent了,求导计算了。卷积后的结果展示:这里有个小细节224*244输出22

优化软件系统,解决死锁问题,提升稳定性与性能 redis排队下单

项目背景:随着用户数量的不断增加,我们的速卖通小管家软件系统面临了一个日益严重的问题:在从存储区提供程序的数据读取器中进行读取时,频繁出现错误。系统报告了一个内部异常:异常信息如下:从存储区提供程序的数据读取器中进行读取时出错。有关详细信息,请参阅内部异常。--->System.Data.SqlClient.SqlEx

单例模式优缺点

单例模式是一种创建型设计模式,其主要目的是确保类只有一个实例,并提供全局访问点来获取该实例。单例模式具有一些优点和缺点,下面我将列出它们:**优点:**1.**全局唯一性**:单例模式确保在应用程序中只有一个实例,这对于某些类来说是非常有用的,例如配置管理、日志记录器、数据库连接等。2.**延迟初始化**:单例模式允许

网页的快捷方式打开自动全屏--Chrome、Firefox 浏览器相关设置

Firefox的全屏方式与Chrome不同,Chrome自带全屏模式以及APP模式,通过简单的参数即可设置,而Firefox暂时么有这个功能,Firefox的全屏功能可以通过全屏插件实现。全屏模式下,按F11不会退出全屏,鼠标移动到屏幕上方也不会提示退出全屏如果当前运行着其它的Chrome窗口,那么全屏化打开是无效的,

高并发系统 - 接口幂等技术方案,高可用系统架构与技术选型

幂等概念来自于数学,在计算机科学中,幂等表示一次后、或多次请求某一资源,应该有同样的影响效果。在业务表现上一般是同样的数据效果,下面就常用的业务场景,来聊聊幂等的技术方案。-----------------数据层-----------------索引与事务根据业务需要,给表添加唯一索性或组合索引,防止产生脏数据。根据数

网络安全第一次作业

1、什么是防火墙防火墙是一种网络安全系统,它根据预先确定的安全规则监视和控制传入和传出的网络流量。其主要目的是阻止对计算机或网络的未经授权的访问,同时允许合法通信通过。防火墙可以在硬件、软件或两者的组合中实现,并且可以配置为根据各种条件(如IP地址、端口号和协议类型)过滤流量。防火墙还可以提供其他安全功能,例如入侵检测

自然语言处理技术之词向量:GloVe单词表示的全局向量(glove.840B.300d、glove.6B)

目录一、词向量介绍二、GloVe学习词向量的词嵌入模型三、词向量入门(代码下载)四、训练五、模型概述六、可视化七、发布历史一、词向量介绍自然语言处理(NLP)中的词向量是将文本中的词汇表示为数值向量的技术。词向量的主要作用是将文本数据转换成计算机可以理解和处理的形式,以便进行各种NLP任务。以下是词向量在NLP中的主要

热文推荐