当前位置: 首页 > article >正文

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

目录

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

相关文章:

  • Android Studio 将项目打包成apk文件
  • OCR识别铁路电子客票
  • MySQL技巧之跨服务器数据查询:进阶篇-从A数据库复制到B数据库的表中
  • Unity3D实现视频和模型融合效果
  • 32位、64位、x86与x64:深入解析计算机架构
  • 使用pytest+openpyxl做接口自动化遇到的问题
  • MySQL基础
  • vim编辑器
  • Build生成器模式
  • (二)【平衡小车制作】电机驱动(超详解)
  • 内存越界是否一定会导致程序崩溃吗?详解内存越界
  • CUDA下载,以及下载GPU版本的pytorch
  • JAVA基于Springboot框架的停车场管理系统开发实践和实现【附源码】
  • DP动态规划
  • 1.rabbitMQ介绍
  • JavaScript闭包的基本原理和应用场景
  • 人的全面发展评价指标体系—基于相关-主成分分析构建
  • 2000-2019年30省研发资本存量(含计算过程和原始数据)
  • 大数据Doris(八):Broker部署和集群启停脚本
  • 高效学习方法和工具推荐,让你事半功倍!
  • clickhouse里的数组数据类型与相关使用介绍
  • 【C++复习1】程序结构和C++的工作原理
  • Java程序设计入门教程--数组
  • 小球下落(dropping balls)uva679
  • go 打包文件夹成zip文件
  • Envoy控制面实践