Llama 2 7b Chat Hf Function Calling V3
模型简介
此模型是基于Llama 2 7B聊天版本微调的,专门优化了函数调用能力,可用于构建支持函数调用的对话系统。
模型特点
函数调用支持
模型经过微调,支持OpenAI风格的函数调用元数据格式,可识别并生成函数调用请求。
商业用途许可
遵循Llama 2社区许可证,允许商业用途。
对话优化
基于Llama 2聊天版本微调,专为对话场景优化。
模型能力
文本生成
函数调用
对话系统
使用案例
对话助手
天气查询助手
通过函数调用集成天气API,回答用户关于天气的查询。
可准确生成函数调用请求并解析返回结果。
股票信息查询
通过函数调用获取股票数据并回答用户问题。
能正确生成股票查询函数调用并解释结果。
🚀 函数调用微调版Llama 2 Chat
本模型针对函数调用进行了微调。
- 函数元数据格式与OpenAI所使用的格式相同。
- 该模型适用于商业用途,并遵循Llama 2社区许可证。
- GGUF版本位于gguf分支中。
查看其他微调的函数调用模型,请点击此处。
🚀 快速开始
✨ 快速服务器设置
Runpod联盟链接(有助于支持Trelis频道)。
💻 推理脚本
以下是示例提示格式。
完整的推理脚本可点击此处购买:
- 使用
tokenizer.apply_chat_format
轻松格式化提示(从OpenAI格式的函数和消息列表开始)。 - 自动捕获、处理和链接函数调用。
💻 使用示例
基础用法
B_FUNC, E_FUNC = "You have access to the following functions. Use them if required:\n\n", "\n\n"
B_INST, E_INST = "[INST] ", " [/INST]" #Llama style
prompt = f"{B_INST}{B_FUNC}{functionList.strip()}{E_FUNC}{user_prompt.strip()}{E_INST}\n\n"
高级用法
使用tokenizer.apply_chat_template
为了更轻松地应用提示,您可以按以下方式设置:
设置messages
:
[
{
"role": "function_metadata",
"content": "FUNCTION_METADATA"
},
{
"role": "user",
"content": "What is the current weather in London?"
},
{
"role": "function_call",
"content": "{\n \"name\": \"get_current_weather\",\n \"arguments\": {\n \"city\": \"London\"\n }\n}"
},
{
"role": "function_response",
"content": "{\n \"temperature\": \"15 C\",\n \"condition\": \"Cloudy\"\n}"
},
{
"role": "assistant",
"content": "The current weather in London is Cloudy with a temperature of 15 Celsius"
}
]
将FUNCTION_METADATA
设置为:
[
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "This function gets the current weather in a given city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city, e.g., San Francisco"
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use."
}
},
"required": ["city"]
}
}
},
{
"type": "function",
"function": {
"name": "get_clothes",
"description": "This function provides a suggestion of clothes to wear based on the current weather",
"parameters": {
"type": "object",
"properties": {
"temperature": {
"type": "string",
"description": "The temperature, e.g., 15 C or 59 F"
},
"condition": {
"type": "string",
"description": "The weather condition, e.g., 'Cloudy', 'Sunny', 'Rainy'"
}
},
"required": ["temperature", "condition"]
}
}
}
]
然后应用聊天模板以获取格式化的提示:
tokenizer = AutoTokenizer.from_pretrained('Trelis/Llama-2-7b-chat-hf-function-calling-v3', trust_remote_code=True)
prompt = tokenizer.apply_chat_template(prompt, tokenize=False)
如果您使用的是受限模型,则需要先运行:
pip install huggingface_hub
huggingface-cli login
手动提示
[INST] You have access to the following functions. Use them if required:
[
{
"type": "function",
"function": {
"name": "get_big_stocks",
"description": "Get the names of the largest N stocks by market cap",
"parameters": {
"type": "object",
"properties": {
"number": {
"type": "integer",
"description": "The number of largest stocks to get the names of, e.g. 25"
},
"region": {
"type": "string",
"description": "The region to consider, can be \"US\" or \"World\"."
}
},
"required": [
"number"
]
}
}
},
{
"type": "function",
"function": {
"name": "get_stock_price",
"description": "Get the stock price of an array of stocks",
"parameters": {
"type": "object",
"properties": {
"names": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of stocks"
}
},
"required": [
"names"
]
}
}
}
]
[INST] Get the names of the five largest stocks in the US by market cap [/INST]
{
"name": "get_big_stocks",
"arguments": {
"number": 5,
"region": "US"
}
}</s>
📚 详细文档
数据集
查看数据集详情。
Llama 2模型详情
Llama 2是一系列预训练和微调的生成式文本模型,参数规模从70亿到700亿不等。这是7B微调模型的仓库,针对对话用例进行了优化,并转换为Hugging Face Transformers格式。其他模型的链接可在底部索引中找到。
模型信息
属性 | 详情 |
---|---|
模型开发者 | Meta |
模型变体 | Llama 2有7B、13B和70B等不同参数规模,以及预训练和微调版本。 |
输入 | 仅接受文本输入。 |
输出 | 仅生成文本输出。 |
模型架构 | Llama 2是一种自回归语言模型,采用了优化的Transformer架构。微调版本使用监督微调(SFT)和基于人类反馈的强化学习(RLHF)来符合人类对有用性和安全性的偏好。 |
训练数据 | 新的公开在线数据组合 |
训练日期 | 2023年1月至2023年7月 |
模型状态 | 这是一个基于离线数据集训练的静态模型。随着我们根据社区反馈改进模型安全性,未来将发布微调模型的新版本。 |
许可证 | 自定义商业许可证可在此处获取。 |
研究论文 | "Llama-2: Open Foundation and Fine-tuned Chat Models" |
训练数据
- 概述:Llama 2在来自公开来源的2万亿个标记数据上进行了预训练。微调数据包括公开可用的指令数据集,以及超过100万个新的人工标注示例。预训练和微调数据集均不包含Meta用户数据。
- 数据时效性:预训练数据截止到2022年9月,但部分微调数据更新至2023年7月。
评估结果
模型 | 规模 | 代码 | 常识推理 | 世界知识 | 阅读理解 | 数学 | MMLU | BBH | AGI评估 |
---|---|---|---|---|---|---|---|---|---|
Llama 1 | 7B | 14.1 | 60.8 | 46.2 | 58.5 | 6.95 | 35.1 | 30.3 | 23.9 |
Llama 1 | 13B | 18.9 | 66.1 | 52.6 | 62.3 | 10.9 | 46.9 | 37.0 | 33.9 |
Llama 1 | 33B | 26.0 | 70.0 | 58.4 | 67.6 | 21.4 | 57.8 | 39.8 | 41.7 |
Llama 1 | 65B | 30.7 | 70.7 | 60.5 | 68.6 | 30.8 | 63.4 | 43.5 | 47.6 |
Llama 2 | 7B | 16.8 | 63.9 | 48.9 | 61.3 | 14.6 | 45.3 | 32.6 | 29.3 |
Llama 2 | 13B | 24.5 | 66.9 | 55.4 | 65.8 | 28.7 | 54.8 | 39.4 | 39.1 |
Llama 2 | 70B | 37.5 | 71.9 | 63.6 | 69.4 | 35.2 | 68.9 | 51.2 | 54.2 |
模型 | 规模 | TruthfulQA | Toxigen |
---|---|---|---|
Llama 1 | 7B | 27.42 | 23.00 |
Llama 1 | 13B | 41.74 | 23.08 |
Llama 1 | 33B | 44.19 | 22.57 |
Llama 1 | 65B | 48.71 | 21.77 |
Llama 2 | 7B | 33.29 | 21.25 |
Llama 2 | 13B | 41.86 | 26.10 |
Llama 2 | 70B | 50.18 | 24.60 |
模型 | 规模 | TruthfulQA | Toxigen |
---|---|---|---|
Llama-2-Chat | 7B | 57.04 | 0.00 |
Llama-2-Chat | 13B | 62.18 | 0.00 |
Llama-2-Chat | 70B | 64.14 | 0.01 |
预期用途
- 预期用例:Llama 2旨在用于英语的商业和研究用途。微调模型适用于类似助手的聊天,而预训练模型可用于各种自然语言生成任务。
- 超出范围的用途:以任何违反适用法律法规(包括贸易合规法律)的方式使用;使用英语以外的语言;以Llama 2的可接受使用政策和许可协议禁止的任何其他方式使用。
硬件和软件
- 训练因素:我们使用自定义训练库、Meta的研究超级集群和生产集群进行预训练。微调、标注和评估也在第三方云计算上进行。
- 碳足迹:预训练在A100 - 80GB类型的硬件上累计使用了330万个GPU小时的计算资源(TDP为350 - 400W)。估计总排放量为539 tCO2eq,其中100%由Meta的可持续发展计划抵消。
模型 | 时间(GPU小时) | 功耗(W) | 碳排放(tCO₂eq) |
---|---|---|---|
Llama 2 7B | 184320 | 400 | 31.22 |
Llama 2 13B | 368640 | 400 | 62.44 |
Llama 2 70B | 1720320 | 400 | 291.42 |
总计 | 3311616 | - | 539.00 |
伦理考量和局限性
Llama 2是一项新技术,使用时存在风险。到目前为止进行的测试均使用英语,且无法涵盖所有场景。因此,与所有大语言模型一样,Llama 2的潜在输出无法提前预测,在某些情况下,模型可能会对用户提示产生不准确、有偏见或其他令人反感的响应。因此,在部署Llama 2的任何应用程序之前,开发人员应针对其特定应用对模型进行安全测试和调整。
请参阅负责任使用指南。
问题反馈
请通过以下方式报告模型的软件“漏洞”或其他问题:
- 报告模型问题:github.com/facebookresearch/llama
- 报告模型生成的不良内容:developers.facebook.com/llama_output_feedback
- 报告漏洞和安全问题:facebook.com/whitehat/info
Llama模型索引
模型 | Llama2 | Llama2-hf | Llama2-chat | Llama2-chat-hf |
---|---|---|---|---|
7B | 链接 | 链接 | 链接 | 链接 |
13B | 链接 | 链接 | 链接 | 链接 |
70B | 链接 | 链接 | 链接 | 链接 |
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型 支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型 英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型 英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型 英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型 支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型 英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型 英语
O
facebook
6.3M
198
1
基于transformers库的预训练模型,适用于多种NLP任务
大型语言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers 支持多种语言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型 支持多种语言
T
google-t5
5.4M
702
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98
智启未来,您的人工智能解决方案智库
简体中文