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

news/2024/5/20 9:12:12 标签: chatgpt, 人工智能, openai, ai
aidu_pl">

目录

  • 一、说明
  • 二、安装环境
  • 三、推断(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.niftyadmin.cn/n/280361.html

相关文章

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

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

至少要吃掉多少糖果

小A的糖果 题目描述 小 A 有 n n n 个糖果盒,第 i i i 个盒中有 a i a_i ai​ 颗糖果。 小 A 每次可以从其中一盒糖果中吃掉一颗,他想知道,要让任意两个相邻的盒子中糖的个数之和都不大于 x x x,至少得吃掉几颗糖。 输入格…

嵌入式Sqlite数据库【基本语法、Sqlite-JDBC、嵌入到Java程序】

目录 前言 基本介绍 Sqlite 对比 MySQL 字段类型 语法 创建表 插入数据 更新数据 查询数据 删除数据 查看建表语句 Sqlite-JDBC 嵌入到Java程序 前言 最近在用JavaFX做一个桌面软件需要用到数据库,但MySQL这种数据库明显只能本地访问,把软…

10个最常见的JavaScript问题

如今,JavaScript几乎是所有现代web应用程序的核心。这就是为什么JavaScript问题以及找出导致这些问题的错误是web开发人员的首要任务。 用于单页应用程序(SPA)开发、图形和动画以及服务器端JavaScript平台的强大的基于JavaScript的库和框架并…

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

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

YOLOv7、YOLOv7-tiny改进GhostNet主干系列:高效结合GhostNet网络,华为出品

💡本篇内容:YOLOv7、YOLOv7-tiny改进GhostNet主干系列:高效结合GhostNet网络,华为出品,打造强力检测器: GhostNet 重点:🔥🔥🔥YOLOv7 使用这个 创新点 在数据集改进做实验:即插即用 GhostNet 💡🚀🚀🚀本博客 内附的改进源代码改进,按步骤操作运行改…

【JavaEE】UDP数据报套接字—实现回显服务器(网络编程)

博主简介:想进大厂的打工人博主主页:xyk:所属专栏: JavaEE初阶 本篇文章将带你了解什么是网络编程? 网络编程,指网络上的主机,通过不同的进程,以编程的方式实现网络通信(或称为网络数据传输&am…

配准带尺度点云的方法汇总

如果点集之间不存在缩放关系时(即尺度相同时), 可以用经典ICP( Iterative Closest Point )方法求解得到旋转矩阵R和平移向量t来进行点集对齐。 如果存在缩放关系时,首先估计出点集S1和S2之间的缩放倍数s, 我们就可以利用ICP算法求解。 一、尺度因子s是两个点集中线…