在本指南中,我们将介绍一些高级和有趣的方法,我们可以使用提示工程来执行有用和更高级的任务。
请注意,此部分正在大量开发中。 主题:
- 生成数据
- 程序辅助语言模型
- Python 笔记本
一、生成数据
LLM 具有强大的文本生成能力。使用有效的提示策略可以引导模型产生更好、更一致和更符合事实的响应。LLM 对于生成对运行各种实验有用的数据也特别有用。例如,我们可以使用它为情感分类器生成快速样本,如下所示:
迅速的:
Produce 10 exemplars for sentiment analysis. Examples are categorized as either positive or negative. Produce 2 negative examples and 8 positive examples. Use this format for the examples: Q: <sentence> A: <sentiment>
输出:
Q: 我刚得到了有史以来最好的消息! A: 积极的 Q: 我们刚刚在工作中得到了加薪! A: 积极的 Q: 我为今天所取得的成就感到非常自豪。 A: 积极的 Q: 我度过了有史以来最好的一天! A: 积极的 Q: 我非常期待周末的到来。 A: 积极的 Q: 我刚收到了有史以来最好的礼物! A: 积极的 Q: 我现在非常开心。 A: 积极的 Q: 我很幸运有这么一支了不起的家庭。 A: 积极的 Q: 外面的天气很阴暗。 A: 消极的 Q: 我刚得到了一些可怕的消息。 A: 消极的
这非常有用。我们将此示例用于指南另一部分中的不同测试。
二、PAL(程序辅助语言模型)
Gao 等人 (2022)提出了一种使用 LLM 阅读自然语言问题并生成程序作为中间推理步骤的方法。创造的程序辅助语言模型 (PAL) 与思维链提示的不同之处在于,它不是使用自由格式的文本来获得解决方案,而是将解决方案步骤卸载到编程运行时,例如 Python 解释器。
让我们看一个使用 LangChain 和 OpenAI GPT-3 的例子。我们有兴趣开发一个简单的应用程序,该应用程序能够解释所提出的问题并通过利用 Python 解释器提供答案。
具体来说,我们有兴趣创建一个函数,允许使用 LLM 来回答需要理解日期的问题。我们将为 LLM 提供提示,其中包括从此处采用的一些范例。
这些是我们需要的导入:
import openai from datetime import datetime from dateutil.relativedelta import relativedelta import os from langchain.llms import OpenAI from dotenv import load_dotenv
让我们首先配置一些东西:
load_dotenv()
API configuration
openai.api_key = os.getenv("OPENAI_API_KEY")
for LangChain
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
设置模型实例:
llm = OpenAI(model_name='text-davinci-003', temperature=0)
设置提示+问题:
question = "Today is 27 February 2023. I was born exactly 25 years ago. What is the date I was born in MM/DD/YYYY?" DATE_UNDERSTANDING_PROMPT = """ # Q: 2015 is coming in 36 hours. What is the date one week from today in MM/DD/YYYY? # If 2015 is coming in 36 hours, then today is 36 hours before. today = datetime(2015, 1, 1) - relativedelta(hours=36) # One week from today, one_week_from_today = today + relativedelta(weeks=1) # The answer formatted with %m/%d/%Y is one_week_from_today.strftime('%m/%d/%Y') # Q: The first day of 2019 is a Tuesday, and today is the first Monday of 2019. What is the date today in MM/DD/YYYY? # If the first day of 2019 is a Tuesday, and today is the first Monday of 2019, then today is 6 days later. today = datetime(2019, 1, 1) + relativedelta(days=6) # The answer formatted with %m/%d/%Y is today.strftime('%m/%d/%Y') # Q: The concert was scheduled to be on 06/01/1943, but was delayed by one day to today. What is the date 10 days ago in MM/DD/YYYY? # If the concert was scheduled to be on 06/01/1943, but was delayed by one day to today, then today is one day later. today = datetime(1943, 6, 1) + relativedelta(days=1) # 10 days ago, ten_days_ago = today - relativedelta(days=10) # The answer formatted with %m/%d/%Y is ten_days_ago.strftime('%m/%d/%Y') # Q: It is 4/19/1969 today. What is the date 24 hours later in MM/DD/YYYY? # It is 4/19/1969 today. today = datetime(1969, 4, 19) # 24 hours later, later = today + relativedelta(hours=24) # The answer formatted with %m/%d/%Y is today.strftime('%m/%d/%Y') # Q: Jane thought today is 3/11/2002, but today is in fact Mar 12, which is 1 day later. What is the date 24 hours later in MM/DD/YYYY? # If Jane thought today is 3/11/2002, but today is in fact Mar 12, then today is 3/1/2002. today = datetime(2002, 3, 12) # 24 hours later, later = today + relativedelta(hours=24) # The answer formatted with %m/%d/%Y is later.strftime('%m/%d/%Y') # Q: Jane was born on the last day of Feburary in 2001. Today is her 16-year-old birthday. What is the date yesterday in MM/DD/YYYY? # If Jane was born on the last day of Feburary in 2001 and today is her 16-year-old birthday, then today is 16 years later. today = datetime(2001, 2, 28) + relativedelta(years=16) # Yesterday, yesterday = today - relativedelta(days=1) # The answer formatted with %m/%d/%Y is yesterday.strftime('%m/%d/%Y') # Q: {question} """.strip() + 'n'
llm_out = llm(DATE_UNDERSTANDING_PROMPT.format(question=question)) print(llm_out)
exec(llm_out) print(born)
这将输出以下内容:02/27/1998
以上是聊聊如何设计一个优秀的提示应用程序?的详细内容。更多信息请关注PHP中文网其他相关文章!

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。 Python以简洁和强大的生态系统着称,C 则以高性能和底层控制能力闻名。

2小时内可以学会Python的基本编程概念和技能。1.学习变量和数据类型,2.掌握控制流(条件语句和循环),3.理解函数的定义和使用,4.通过简单示例和代码片段快速上手Python编程。

Python在web开发、数据科学、机器学习、自动化和脚本编写等领域有广泛应用。1)在web开发中,Django和Flask框架简化了开发过程。2)数据科学和机器学习领域,NumPy、Pandas、Scikit-learn和TensorFlow库提供了强大支持。3)自动化和脚本编写方面,Python适用于自动化测试和系统管理等任务。

两小时内可以学到Python的基础知识。1.学习变量和数据类型,2.掌握控制结构如if语句和循环,3.了解函数的定义和使用。这些将帮助你开始编写简单的Python程序。

如何在10小时内教计算机小白编程基础?如果你只有10个小时来教计算机小白一些编程知识,你会选择教些什么�...

使用FiddlerEverywhere进行中间人读取时如何避免被检测到当你使用FiddlerEverywhere...

Python3.6环境下加载Pickle文件报错:ModuleNotFoundError:Nomodulenamed...

如何解决jieba分词在景区评论分析中的问题?当我们在进行景区评论分析时,往往会使用jieba分词工具来处理文�...


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Dreamweaver Mac版
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具