ChatGPT提示词工程(四):Inferring推断

news2024/9/21 8:04:12

目录

  • 一、说明
  • 二、安装环境
  • 三、推断(Inferring)
    • 1. 推断情绪(正面 / 负面)
    • 2. 确定情绪的类型
    • 3. 识别愤怒
    • 4. 从客户评论中提取产品和公司名称
    • 5. 一次完成多项任务
    • 6. 推断主题
    • 7. 主题中是否包含给定的主题

一、说明

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

二、安装环境

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

三、推断(Inferring)

1. 推断情绪(正面 / 负面)

lamp_review = """
Needed a nice lamp for my bedroom, and this one had \
additional storage and not too high of a price point. \
Got it fast.  The string to our 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.  I had a missing part, so I contacted their \
support and they very quickly got me the missing piece! \
Lumina seems to me to be a great company that cares \
about their customers and products!!
"""
prompt = f"""
What is the sentiment of the following product review, 
which is delimited with triple backticks?

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)

代码中:
lamp_review 中文意思是:我的卧室需要一盏漂亮的台灯,而这盏灯有额外的存储空间,而且价格也不是太高。搞得很快。我们台灯的线在运输途中断了,公司很高兴地送来了一条新的。也是在几天内到来的。它很容易组合在一起。我有一个缺失的部分,所以我联系了他们的支持,他们很快就给我找到了缺失的部分!在我看来,Lumina是一家关心客户和产品的伟大公司!
prompt: 在三个反引号(```)中的产品的评价表达出的情绪是什么样的?
在这里插入图片描述
在这里插入图片描述


2. 确定情绪的类型

prompt = f"""
Identify a list of emotions that the writer of the \
following review is expressing. Include no more than \
five items in the list. Format your answer as a list of \
lower-case words separated by commas.

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)

prompt: 找出下面评论的作者所表达的一系列情绪,不超过五个。将您的答案格式化为逗号分隔的小写单词列表
运行结果:
在这里插入图片描述

3. 识别愤怒

prompt = f"""
Is the writer of the following review expressing anger?\
The review is delimited with triple backticks. \
Give your answer as either yes or no.

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)

prompt:下面这篇用三个反引号包围着的评论的作者是否表达了愤怒?回答“是”或“不是”。
模型给出了 “不是” 的结果:
在这里插入图片描述

4. 从客户评论中提取产品和公司名称

prompt = f"""
Identify the following items from the review text: 
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. \
Format your response as a JSON object with \
"Item" and "Brand" as the keys. 
If the information isn't present, use "unknown" \
as the value.
Make your response as short as possible.
  
Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)

prompt:从客户的评价中提取产品和公司名,并以JSON格式给出,JSON的key为:Item、Brand
运行结果:
在这里插入图片描述

5. 一次完成多项任务

prompt = f"""
Identify the following items from the review text: 
- Sentiment (positive or negative)
- Is the reviewer expressing anger? (true or false)
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. \
Format your response as a JSON object with \
"Sentiment", "Anger", "Item" and "Brand" as the keys.
If the information isn't present, use "unknown" \
as the value.
Make your response as short as possible.
Format the Anger value as a boolean.

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)

prompt:从客户的评价中判断情绪(positive或negative)、是否愤怒(true或false)、产品和公司,并以JSON格式输出,JSON的key为:“Sentiment”, “Anger”, “Item”, “Brand”
运行结果:
在这里插入图片描述

6. 推断主题

story = """
In a recent survey conducted by the government, 
public sector employees were asked to rate their level 
of satisfaction with the department they work at. 
The results revealed that NASA was the most popular 
department with a satisfaction rating of 95%.

One NASA employee, John Smith, commented on the findings, 
stating, "I'm not surprised that NASA came out on top. 
It's a great place to work with amazing people and 
incredible opportunities. I'm proud to be a part of 
such an innovative organization."

The results were also welcomed by NASA's management team, 
with Director Tom Johnson stating, "We are thrilled to 
hear that our employees are satisfied with their work at NASA. 
We have a talented and dedicated team who work tirelessly 
to achieve our goals, and it's fantastic to see that their 
hard work is paying off."

The survey also revealed that the 
Social Security Administration had the lowest satisfaction 
rating, with only 45% of employees indicating they were 
satisfied with their job. The government has pledged to 
address the concerns raised by employees in the survey and 
work towards improving job satisfaction across all departments.
"""
prompt = f"""
Determine five topics that are being discussed in the \
following text, which is delimited by triple backticks.

Make each item one or two words long. 

Format your response as a list of items separated by commas.

Text sample: '''{story}'''
"""
response = get_completion(prompt)
print(response)

prompt:提取5个主题,每个主题只能是一个或者两个单次,主题之间使用逗号隔开
运行结果:
在这里插入图片描述

7. 主题中是否包含给定的主题

topic_list = [
    "nasa", "local government", "engineering", 
    "employee satisfaction", "federal government"
]

prompt = f"""
Determine whether each item in the following list of \
topics is a topic in the text below, which
is delimited with triple backticks.

Give your answer as list with 0 or 1 for each topic.\

List of topics: {", ".join(topic_list)}

Text sample: '''{story}'''
"""
response = get_completion(prompt)
print(response)

prompt:story中提取主题,并判断topic_list中的主题是否有涉及,有的置为1,否则为0

在这里插入图片描述
https://blog.csdn.net/Jay_Xio/article/details/130457050



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/480777.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【栈】的实现

🖊作者 : D. Star. 📘专栏 : 数据结构 😆今日分享 : —>📖区块链 : 小明向你借100块钱,说一周后还你,然后你拿个喇叭大喊一声:我是某某,小明向我借了100块&#xff0c…

Redis缓存(双写一致性问题)

Redis缓存(双写一致性问题) 1 什么是缓存?1.1 为什么要使用缓存1.2 如何使用缓存 2 添加缓存2.1 、缓存模型和思路2.2、代码如下 3 缓存更新策略3.1 、数据库缓存不一致解决方案:3.2 、数据库和缓存不一致采用什么方案 4 实现商铺和缓存与数…

【C生万物】 指针篇 (初级)

欢迎来到 Claffic 的博客 💞💞💞 👉 专栏:《C生万物 | 先来学C》👈 前言: 面对C语言,很多童鞋都会高呼:指针难,指针难&#x…

【计算机专业漫谈】【计算机系统基础学习笔记】W2-1十进制数与二进制数,各进制数直接的转换

利用空档期时间学习一下计算机系统基础,以前对这些知识只停留在应试层面,今天终于能详细理解一下了。参考课程为南京大学袁春风老师的计算机系统基础MOOC,参考书籍也是袁老师的教材,这是我的听课自查资料整理后的笔记 W2-1十进制…

ChatGPT背后的技术:人类反馈强化学习RLHF

文章目录 前言Chat GPT是如何基于RLHF进行训练的RLHF 技术分解预训练语言模型训练奖励模型强化学习微调预训练模型 局限性参考 前言 随着OpenAI推出的Chat GPT火热出圈,Chat GPT背后的技术原理之一,人类反馈强化学习RLHF (Reinforcement Learning from …

Matplotlib 网格线

我们可以使用 pyplot 中的 grid() 方法来设置图表中的网格线。 grid() 方法语法格式如下: matplotlib.pyplot.grid(bNone, whichmajor, axisboth, ) 参数说明: b:可选,默认为 None,可以设置布尔值,true…

prometheus实战之二:使用常见指标

欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本文是《prometheus实战》系列的第二篇,在《prometheus实战之一:用ansible部署》一文咱们部署了prometheus服务&#xff0c…

防护服穿戴检测识别算法 yolov8

防护服穿戴检测识别系统基于yolov8网络模型图片数据识别训练,算法模型自动完成对现场人员是否按照要求穿戴行为实时分析。YOLOv8 算法的核心特性和改动可以归结为如下:提供了一个全新的 SOTA 模型,包括 P5 640 和 P6 1280 分辨率的目标检测网…

【开发工具】 我居然可以使用Office Tool Plus 安装上Office 真的是太不可思议了

🚀 个人主页 极客小俊 ✍🏻 作者简介:web开发者、设计师、技术分享博主 🐋 希望大家多多支持一下, 我们一起进步!😄 🏅 如果文章对你有帮助的话,欢迎评论 💬点赞&#x1…

【开发工具】 Office Tool Plus 居然也可以部署 Office 365 我的天 真的是太厉害了

🚀 个人主页 极客小俊 ✍🏻 作者简介:web开发者、设计师、技术分享博主 🐋 希望大家多多支持一下, 我们一起进步!😄 🏅 如果文章对你有帮助的话,欢迎评论 💬点赞&#x1…

人不成熟的五大特征-读后感

原文地址:人不成熟的五大特征-百度经验 1 立即要回报 1 所有简单的快的,别人也能做,这并不能使你超过别人。 2 做出别人做不出来的复杂成果,需要较长的时间和持续的学习,得到就得付出,时间,资源…

Windows10本地搭建网站教程 - 内网穿透发布公网访问

文章目录 概述1. 搭建一个静态Web站点2. 本地浏览测试站点是否正常3. 本地站点发布公网可访问3.1 安装cpolar内网穿透3.2 创建隧道映射公网地址3.3 获取公网URL地址 4. 公网远程访问内网web站点5. 配置固定二级子域名5.1 保留二级子域名5.2 配置二级子域名 6. 测试访问二级子域…

【Java笔试强训 30】

🎉🎉🎉点进来你就是我的人了博主主页:🙈🙈🙈戳一戳,欢迎大佬指点! 欢迎志同道合的朋友一起加油喔🤺🤺🤺 目录 一、选择题 二、编程题 🔥最难的问…

家乡特色推荐系统~java~mysql

摘 要 在Internet高速发展的今天,我们生活的各个领域都涉及到计算机的应用,其中包括家乡特色推荐的网络应用,在外国家乡特色推荐系统已经是很普遍的方式,不过国内的管理网站可能还处于起步阶段。家乡特色推荐系统采用java技术&…

常用半导体器件

(1)N 型半导体 在纯净的半导体硅或锗中掺入适量的五价磷元素,可形成带负电 的自由电子(又称多数载流子)参与导电。 (2)P 型半导体 在纯净的半导体硅或锗中掺入适量的三价硼元素,可形…

JavaEE初阶 - 文件/IO

一、认识文件 我们先来认识狭义上的文件(file)。针对硬盘这种持久化存储的I/O设备,当我们想要进行数据保存时,往往不是保存成一个整体,而是独立成一个个的单位进行保存,这个独立的单位就被抽象成文件的概念,就类似办公…

Docker持久化固定容器IP

基于Docker引擎创建Docker容器,在默认条件下创建容器是bridge桥接模式,启动容器IP地址是DHCP随机分配并且递增的,而且容器之间可以互相通信,网段也是固定的。 当Docker容器一旦关闭再次启动,就会导致容器的IP地址再次重…

C#,生信软件实践(01)——序列文件(如FASTA)合并工具的源代码

1 生物信息学简介 生物信息学(BioInformatics)是研究生物信息的采集、处理、存储、传播,分析和解释等各方面的学科,也是随着生命科学和计算机科学的迅猛发展,生命科学和计算机科学相结合形成的一门新学科。它通过综合…

Photoshop如何使用通道之实例演示?

文章目录 0.引言1.利用通道调整图像的颜色2.给风景照替换天空3.制作故障艺术效果4.使用通道抠取复杂图像 0.引言 因科研等多场景需要进行绘图处理,笔者对PS进行了学习,本文通过《Photoshop2021入门教程》及其配套素材结合网上相关资料进行学习笔记总结&a…

Linux命令集

一、Linux常用的目录处理命令集 1、ls命令(用来查看目录和文件) (1)ls -a(查看所有文件包括隐藏文件) (2)ls -l (以长格式显示目录下的内容列表) &#xff0…