自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

我們一起聊聊提示應(yīng)用程序

開發(fā) 前端
LLM 具有強(qiáng)大的文本生成能力。使用有效的提示策略可以引導(dǎo)模型產(chǎn)生更好、更一致和更符合事實(shí)的響應(yīng)。LLM 對(duì)于生成對(duì)運(yùn)行各種實(shí)驗(yàn)有用的數(shù)據(jù)也特別有用。

在本指南中,我們將介紹一些高級(jí)和有趣的方法,我們可以使用提示工程來執(zhí)行有用和更高級(jí)的任務(wù)。

請注意,此部分正在大量開發(fā)中。 主題:

  • 生成數(shù)據(jù)
  • 程序輔助語言模型
  • Python 筆記本

一、生成數(shù)據(jù)

LLM 具有強(qiáng)大的文本生成能力。使用有效的提示策略可以引導(dǎo)模型產(chǎn)生更好、更一致和更符合事實(shí)的響應(yīng)。LLM 對(duì)于生成對(duì)運(yùn)行各種實(shí)驗(yàn)有用的數(shù)據(jù)也特別有用。例如,我們可以使用它為情感分類器生成快速樣本,如下所示:

迅速的:

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: 我現(xiàn)在非常開心。
A: 積極的

Q: 我很幸運(yùn)有這么一支了不起的家庭。
A: 積極的

Q: 外面的天氣很陰暗。
A: 消極的

Q: 我剛得到了一些可怕的消息。
A: 消極的

這非常有用。我們將此示例用于指南另一部分中的不同測試。

二、PAL(程序輔助語言模型)

Gao 等人 (2022)提出了一種使用 LLM 閱讀自然語言問題并生成程序作為中間推理步驟的方法。創(chuàng)造的程序輔助語言模型 (PAL) 與思維鏈提示的不同之處在于,它不是使用自由格式的文本來獲得解決方案,而是將解決方案步驟卸載到編程運(yùn)行時(shí),例如 Python 解釋器。



讓我們看一個(gè)使用 LangChain 和 OpenAI GPT-3 的例子。我們有興趣開發(fā)一個(gè)簡單的應(yīng)用程序,該應(yīng)用程序能夠解釋所提出的問題并通過利用 Python 解釋器提供答案。

具體來說,我們有興趣創(chuàng)建一個(gè)函數(shù),允許使用 LLM 來回答需要理解日期的問題。我們將為 LLM 提供提示,其中包括從此處采用的一些范例。

這些是我們需要的導(dǎo)入:

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

設(shè)置模型實(shí)例:

llm = OpenAI(model_name='text-davinci-003', temperature=0)

設(shè)置提示+問題:

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)

這將輸出以下內(nèi)容:02/27/1998

責(zé)任編輯:武曉燕 來源: 今日頭條
相關(guān)推薦

2023-08-04 08:20:56

DockerfileDocker工具

2022-05-24 08:21:16

數(shù)據(jù)安全API

2023-08-10 08:28:46

網(wǎng)絡(luò)編程通信

2023-09-10 21:42:31

2023-06-30 08:18:51

敏捷開發(fā)模式

2021-08-27 07:06:10

IOJava抽象

2024-02-20 21:34:16

循環(huán)GolangGo

2022-02-23 08:41:58

NATIPv4IPv6

2022-09-22 08:06:29

計(jì)算機(jī)平板微信

2024-11-28 09:57:50

C#事件發(fā)布器

2022-10-08 00:00:05

SQL機(jī)制結(jié)構(gòu)

2024-07-26 09:47:28

2023-03-26 23:47:32

Go內(nèi)存模型

2023-07-24 09:41:08

自動(dòng)駕駛技術(shù)交通

2021-08-12 07:49:24

mysql

2022-06-26 09:40:55

Django框架服務(wù)

2022-02-14 07:03:31

網(wǎng)站安全MFA

2022-10-28 07:27:17

Netty異步Future

2022-11-12 12:33:38

CSS預(yù)處理器Sass

2023-04-26 07:30:00

promptUI非結(jié)構(gòu)化
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)