看到一个资料:
https://github.com/QwenLM/Qwen2.5/blob/main/docs/source/framework/LlamaIndex.rst
微调模型的时候有加一些标记,所以后面用的时候给入标记会是一种很强的监督:
pythondef completion_to_prompt(completion):
return f"<|im_start|>system\n<|im_end|>\n<|im_start|>user\n{completion}<|im_end|>\n<|im_start|>assistant\n"
def messages_to_prompt(messages):
prompt = ""
for message in messages:
if message.role == "system":
prompt += f"<|im_start|>system\n{message.content}<|im_end|>\n"
elif message.role == "user":
prompt += f"<|im_start|>user\n{message.content}<|im_end|>\n"
elif message.role == "assistant":
prompt += f"<|im_start|>assistant\n{message.content}<|im_end|>\n"
if not prompt.startswith("<|im_start|>system"):
prompt = "<|im_start|>system\n" + prompt
prompt = prompt + "<|im_start|>assistant\n"
return prompt
其实:
completion_to_prompt
:
completion
(通常是用户的提问或助手的回答)。<|im_start|>user
、<|im_end|>
、<|im_start|>assistant
标记包装。例如,当你输入 completion="What is the capital of France?"
时,生成的输出会是:
text<|im_start|>system <|im_end|> <|im_start|>user What is the capital of France? <|im_end|> <|im_start|>assistant
messages_to_prompt
:
messages
),每个消息包含 role
(角色,如 system
、user
、assistant
)和 content
(消息内容)。例如,当 messages
包含以下内容:
pythonmessages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."}
]
生成的输出会是:
text<|im_start|>system You are a helpful assistant. <|im_end|> <|im_start|>user What is the capital of France? <|im_end|> <|im_start|>assistant The capital of France is Paris. <|im_end|>
im 或许是 “Interactive Model” 的缩写。
本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!