输入“/”快速插入内容

提示词和超参数

2024年8月21日修改
2023年11月6日创建
本文讨论了ChatGLM3-6B的提示词和超参数设置相关内容,介绍了其对话格式、不同场景示例及超参数设置建议。关键要点包括:
1.
ChatGLM3对话格式:采用全新对话格式,由若干对话组成,每个对话含对话头和内容,对话头格式为<|role|>{metadata}。
2.
对话头角色:<|system|>为系统信息,目前仅可在开头出现;<|user|>是用户,不会连续出现;<|assistant|>是AI助手,需在<|user|>信息后出现;<|observation|>是外部返回结果,在<|assistant|>信息之后。
3.
样例场景:包括多轮对话、工具调用、代码执行,不同场景涉及的角色有所不同。
4.
超参数设置:ChatGLM3-6B可设置的参数有max_length、temperature、top_p 。
5.
不同场景参数推荐:如代码生成推荐temperature为0.2 ,top_p为0.1 ;创意写作推荐temperature为0.7 ,top_p为0.8等。
本文档将带领用户熟悉ChatGLM3-6B的提示词和超参数设置
ChatGLM3 对话格式
为了避免用户输入的注入攻击,以及统一 Code Interpreter,Tool & Agent 等任务的输入,ChatGLM3 采用了全新的对话格式。
整体结构
ChatGLM3 对话的格式由若干对话组成,其中每个对话包含对话头和内容,一个典型的多轮对话结构如下
<|system|>
You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.
<|user|>
Hello
<|assistant|>
Hello, I'm ChatGLM3. What can I assist you today?
对话头
对话头占完整的一行,格式为
<|role|>{metadata}
其中 <|role|> 部分使用 special token 表示,无法从文本形式被 tokenizer 编码以防止注入。metadata 部分采用纯文本表示,为可选内容。
<|system|>:系统信息,设计上可穿插于对话中,但目前规定仅可以出现在开头
<|user|>:用户
不会连续出现多个来自 <|user|> 的信息
<|assistant|>:AI 助手
在出现之前必须有一个来自 <|user|> 的信息
<|observation|>:外部的返回结果
必须在 <|assistant|> 的信息之后
样例场景
为提升可读性,下列样例场景中表示角色的 special token 前均额外添加了一个换行符。实际使用及 tokenizer 实现中均无需额外添加这一换行。
多轮对话
有且仅有 <|user|><|assistant|><|system|> 三种 role
<|system|>
You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.
<|user|>
Hello
<|assistant|>
Hello, I'm ChatGLM3. What can I assist you today?
工具调用
<|system|>
Answer the following questions as best as you can. You have access to the following tools:
[
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string"},
},
"required": ["location"],
},
}
]
<|user|>
今天北京的天气怎么样?
<|assistant|>
好的,让我们来查看今天的天气
<|assistant|>get_current_weather
tool_call(location="beijing", unit="celsius")
<|observation|>
{"temperature": 22}
<|assistant|>
根据查询结果,今天北京的气温为 22 摄氏度。