吴恩达llama课程笔记:第四课提示词技术

羊驼Llama是当前最流行的开源大模型,其卓越的性能和广泛的应用领域使其成为业界瞩目的焦点。作为一款由Meta AI发布的开放且高效的大型基础语言模型,Llama拥有7B、13B和70B(700亿)三种版本,满足不同场景和需求。

吴恩达教授推出了全新的Llama课程,旨在帮助学习者全面理解并掌握Llama大模型这一前沿技术。

课程地址:DLAI - Prompt Engineering with Llama 2

知识点笔记

Chat vs. base models

python 复制代码
### chat model
prompt = "What is the capital of France?"
response = llama(prompt, 
                 verbose=True,
                 model="togethercomputer/llama-2-7b-chat")


### base model
prompt = "What is the capital of France?"
response = llama(prompt, 
                 verbose=True,
                 add_inst=False,
                 model="togethercomputer/llama-2-7b")

chat model 传送过去的prompt有[inst] [/inst]标记,而base model在设置add_inst=False之后没有标记。

但是具体呢?

原来chat model只返回一个回答,而base model在有[inst]标记的情况下返回所有相同的回答,在没有[inst]标记时返回相似问题。

shot Prompting 样本提示分类

Zero-shot Prompting 、One-shot Prompting 和Few-shot Prompting

零样本提示、单样本提示和多样本提示,顾名思义,零样本提示,就是prompt里面没有样例,直接提问问题,单样本提示就是给出一个例子,多样本提示就是给出几个例子。大模型最厉害的地方就是即使 多样本提示,一般也只需要区区几个例子,而不想传统的CV、NLP模型,需要几十甚至几百个样例才能达到较好的效果。

零样本提示

python 复制代码
prompt = """
Message: Hi Amit, thanks for the thoughtful birthday card!
Sentiment: ?
"""
response = llama(prompt)
print(response)

多样本提示

python 复制代码
prompt = """
Message: Hi Dad, you're 20 minutes late to my piano recital!
Sentiment: Negative

Message: Can't wait to order pizza for dinner tonight
Sentiment: Positive

Message: Hi Amit, thanks for the thoughtful birthday card!
Sentiment: ?
"""
response = llama(prompt)
print(response)

角色提示

角色为LLM提供了所需答案类型的上下文。

当提供角色时,Llama 2通常会给出更一致的回答。

普通写法

python 复制代码
prompt = """
How can I answer this question from my friend:
What is the meaning of life?
"""
response = llama(prompt)
print(response)

有角色提示写法

python 复制代码
role = """
Your role is a life coach \
who gives advice to people about living a good life.\
You attempt to provide unbiased advice.
You respond in the tone of an English pirate.
"""

prompt = f"""
{role}
How can I answer this question from my friend:
What is the meaning of life?
"""
response = llama(prompt)
print(response)
相关推荐
AI创界者10 分钟前
【首发】LTX-2.3-10Eros 视频生成本地化部署教程:8G显存流畅运行,支持RTX 50系列(附一键整合包)
人工智能
Elastic 中国社区官方博客15 分钟前
Elastic 的 AI agent skills
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索
容智信息19 分钟前
AI Agent(智能体)的输出格式应该从 Markdown 转向 HTML吗?
前端·人工智能·rust·编辑器·html·prompt
学习论之费曼学习法20 分钟前
AI 入门 30 天挑战 - Day 28 - 前沿技术概览
人工智能
陕西字符23 分钟前
2026 西安小微企业地图与 AI 问答排名优化:专业技术指南与落地方案
大数据·人工智能
TENSORTEC腾视科技34 分钟前
腾视科技AI大模型应用:提效、破局与落地,重塑智能新生态
人工智能·科技·安全·ai·ai大模型·无人叉车及智能调度系统解决方案
阿里云大数据AI技术35 分钟前
破解 AI 搜索“效果与成本”双重困境:阿里云 Elasticsearch 向量混合检索最佳实践揭秘
人工智能·elasticsearch
仙女修炼史37 分钟前
视觉CNN常用基础技术来源:UberNet
人工智能·神经网络·cnn
ishangy41 分钟前
皮带撕裂早期特征提取:AI摄像机+深度学习在港口的应用
人工智能·深度学习·智慧港口·港口皮带ai识别·皮带检测识别
imbackneverdie1 小时前
一天怎么完成论文初稿
人工智能·自然语言处理·aigc·ai写作·论文写作·论文投稿·科研工具