ChatGPT Prompt Engineering for Developers
课程链接: ChatGPT Prompt Engineering for Developers
课程讲师: 吴恩达(Andrew Ng), Isa Fulford
出品机构: DeepLearning.AI
合作机构: OpenAI
第一章:介绍
1.1 两种大语言模型(LLM)
在大型语言模型的发展中,可以分为两种类型:
基础大语言模型(Base LLM)
- 根据文本训练数据预测下一个单词
- 基于互联网或其它数据集的大量数据训练
- 示例:输入"法国的首都是哪里?",可能会根据互联网文章完成句子
指令调优大语言模型(Instruction Tuned LLM)
- 经过训练可以遵循指令进行预测
- 训练过程:
- 从基础LLM开始
- 使用输入和输出指令进行微调
- 使用人类反馈强化学习(RLHF)技术改进
- 特点:有用、诚实、无害
1.2 如何进行提示
使用指令调优LLM时,可以想象在给另一个人提供指令,给一个聪明的但不了解任务具体内容的人。
关键要点:
- 指令需要清晰具体
- 需要明确指出希望文本关注的方面
- 可以指定文本的风格
- 可以提供参考文本资料
第二章:指导原则
2.1 指导原则1:清晰而具体的提示
策略1:使用分隔符
使用分隔符清楚地表示输入的不同部分,如三重反引号"“”、XML标记、章节标题等。
策略2:要求结构化的输出
要求输出为HTML或JSON格式,便于解析。
策略3:要求模型检查是否满足条件
让模型先检查假设条件,如果不满足就指出并停止完成任务。
策略4:少样本提示(few-shot prompt)
提供成功执行任务的示例,让模型模仿。
2.2 指导原则2:给模型思考的时间
策略1:指定完成任务所需的步骤
将复杂任务分解为多个步骤,让模型按步骤执行。
策略2:教导模型得出结论前先自己解决问题
让模型先推理出自己的解决方案,再与提供的解决方案比较。
2.3 模型的局限性
幻觉(Hallucination):模型可能编造听起来可信但实际上不正确的信息。
减少幻觉的策略:给模型提供相关信息,让大模型根据提供的信息回答问题
第三章:迭代开发
3.1 提示词的迭代开发
提示开发是一个迭代的过程:
- 有一个想法
- 初步编写提示
- 运行并查看结果
- 分析为什么指令不够清晰
- 完善提示
- 重复直到得到适用的提示
第四章:摘要任务
大语言模型的应用之一是可以用来总结文本,对提供的内容进行摘要。
第五章:推理任务
大模型可以进行情绪分析,判断文本是正面还是负面等相关的推力任务。
第六章:转换任务
使用LLM进行多语言翻译,支持各种语言间的转换,以及其他的转换任务。
第七章:扩充任务
7.1 AI自动回复邮件
根据客户评论和情绪生成个性化的客服回复邮件。
7.2 温度参数的影响
温度(temperature)参数:控制模型输出的随机性和多样性。
- temperature=0:最确定性的输出,适合需要可靠性和可预测性的场景
- temperature>0:更具创造性和多样性,适合需要创意的场景
第八章:聊天机器人
8.1 聊天机器人
ChatGPT使用消息列表格式:
messages = [
{'role':'system', 'content':'You are an assistant that speaks like Shake
speare.'},
{'role':'user', 'content':'tell me a joke'},
{'role':'assistant', 'content':'Why did the chicken cross the road'},
{'role':'user', 'content':'I don\'t know'} ]
8.2 点餐机器人
import panel as pn # GUI
pn.extension()
panels = [] # collect display
context = [ {'role':'system', 'content':"""
You are OrderBot, an automated service to collect orders for a pizza res
taurant. \
You first greet the customer, then collects the order, \
and then asks if it's a pickup or delivery. \
You wait to collect the entire order, then summarize it and check for a
final \
time if the customer wants to add anything else. \
If it's a delivery, you ask for an address. \
Finally you collect the payment.\
Make sure to clarify all options, extras and sizes to uniquely \
identify the item from the menu.\
You respond in a short, very conversational friendly style. \
The menu includes \
pepperoni pizza 12.95, 10.00, 7.00 \
cheese pizza
10.95, 9.25, 6.50 \
eggplant pizza 11.95, 9.75, 6.75 \
fries 4.50, 3.50 \
greek salad 7.25 \
Toppings: \
extra cheese 2.00, \
mushrooms 1.50 \
sausage 3.00 \
canadian bacon 3.50 \
AI sauce 1.50 \
peppers 1.00 \
Drinks: \
coke 3.00, 2.00, 1.00 \
sprite 3.00, 2.00, 1.00 \
bottled water 5.00 \
"""} ] # accumulate messages
64 / 69
inp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…')
ChatGPT Prompt Engineering for Developers
button_conversation = pn.widgets.Button(name="Chat!")
interactive_conversation = pn.bind(collect_messages, button_conversatio
n)
dashboard = pn.Column(
inp,
pn.Row(button_conversation),
pn.panel(interactive_conversation, loading_indicator=True, height=30
0),
)
dashboard
2515

被折叠的 条评论
为什么被折叠?



