Qwen2 7B Instruct
基于Qwen2-7B-Instruct进一步后训练的模型,擅长处理复杂的多轮工具/函数调用任务。
下载量 62
发布时间 : 6/10/2024
模型简介
该模型是对Qwen/Qwen2-7B-Instruct进行后训练的成果,能够处理复杂的多轮工具/函数调用任务,支持中英文对话。
模型特点
函数调用能力
支持复杂的多轮工具/函数调用任务,能够生成函数调用请求并处理返回结果。
多语言支持
支持英文和中文的文本生成任务。
高性能
在多个基准测试中表现优异,如MMLU、GPQA、GSM-8K等。
模型能力
文本生成
函数调用
工具调用
多轮对话
使用案例
数学计算
链式数学问题求解
通过函数调用逐步解决复杂的数学问题,如加法、减法、乘法和除法。
生成函数调用请求并逐步求解。
对话系统
多轮对话
支持复杂的多轮对话任务,能够处理用户的多轮提问和工具调用需求。
生成连贯且符合上下文的回复。
🚀 Rubra-Qwen2-7B-Instruct
本模型是基于Qwen/Qwen2-7B-Instruct进行进一步后训练得到的成果,能够处理复杂的多轮工具/函数调用任务。
🚀 快速开始
本模型可结合Hugging Face的transformers
库以及rubra库 rubra-tools 使用。
✨ 主要特性
- 基于Qwen/Qwen2-7B-Instruct进一步后训练。
- 能够进行复杂的多轮工具/函数调用。
📦 安装指南
安装Python依赖
pip install rubra_tools torch==2.3.0 transformers accelerate
安装Node.js和npm依赖
你还需要安装Node.js和npm,然后安装jsonrepair
包,用于修复模型偶尔产生的幻觉问题。
npm install jsonrepair
💻 使用示例
基础用法
1. 加载模型
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from rubra_tools import preprocess_input, postprocess_output
model_id = "rubra-ai/Qwen2-7B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype="auto",
device_map="auto",
)
2. 定义函数
这里我们使用4个函数来处理一个简单的数学链式问题:
functions = [
{
'type': 'function',
'function': {
'name': 'addition',
'description': "Adds two numbers together",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to add',
'type': 'string'
},
'b': {
'description': 'Second number to add',
'type': 'string'
}
},
'required': []
}
}
},
{
'type': 'function',
'function': {
'name': 'subtraction',
'description': "Subtracts two numbers",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to be subtracted from',
'type': 'string'
},
'b': {
'description': 'Number to subtract',
'type': 'string'
}
},
'required': []
}
}
},
{
'type': 'function',
'function': {
'name': 'multiplication',
'description': "Multiply two numbers together",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to multiply',
'type': 'string'
},
'b': {
'description': 'Second number to multiply',
'type': 'string'
}
},
'required': []
}
}
},
{
'type': 'function',
'function': {
'name': 'division',
'description': "Divide two numbers",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to use as the dividend',
'type': 'string'
},
'b': {
'description': 'Second number to use as the divisor',
'type': 'string'
}
},
'required': []
}
}
},
]
3. 开始对话
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the result of four plus six? Take the result and add 2? Then multiply by 5 and then divide by two"},
]
def run_model(messages, functions):
## Format messages in Rubra's format
formatted_msgs = preprocess_input(msgs=messages, tools=functions)
text = tokenizer.apply_chat_template(
formatted_msgs,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
raw_output = run_model(messages, functions)
# Check if there's a function call
function_call = postprocess_output(raw_output)
if function_call:
print(function_call)
else:
print(raw_output)
你应该会看到如下输出,这是AI助手发起的函数调用:
[{'id': 'fc65a533', 'function': {'name': 'addition', 'arguments': '{"a": "4", "b": "6"}'}, 'type': 'function'}]
4. 将执行的工具结果添加到消息历史并继续对话
if function_call:
# append the assistant tool call msg
messages.append({"role": "assistant", "tool_calls": function_call})
# append the result of the tool call in openai format, in this case, the value of add 6 to 4 is 10.
messages.append({'role': 'tool', 'tool_call_id': function_call[0]["id"], 'name': function_call[0]["function"]["name"], 'content': '10'})
raw_output1 = run_model(messages, functions)
# Check if there's a function call
function_call = postprocess_output(raw_output1)
if function_call:
print(function_call)
else:
print(raw_output)
大语言模型会发起另一个调用:
[{'id': '2ffc3de4', 'function': {'name': 'addition', 'arguments': '{"a": "10", "b": "2"}'}, 'type': 'function'}]
📚 详细文档
框架版本
- Transformers 4.41.2
- Pytorch 2.3.1+cu121
- Datasets 2.19.2
- Tokenizers 0.19.1
局限性和偏差
尽管该模型在众多任务上表现出色,但仍可能产生有偏差或错误的输出。在敏感或高风险应用中使用该模型时,用户应谨慎并进行批判性判断。模型的输出受其训练数据的影响,而这些数据可能存在固有偏差。
伦理考量
用户应确保该模型的部署符合伦理准则,并考虑生成文本可能产生的社会影响。强烈反对将该模型用于生成有害或误导性内容。
致谢
我们感谢阿里云提供了该模型。
联系信息
如有关于该模型的问题或建议,请联系 rubra团队。
引用信息
如果使用此模型,请按以下格式引用:
@misc {rubra_ai_2024,
author = { Sanjay Nadhavajhala and Yingbei Tong },
title = { Rubra-Qwen2-7B-Instruct },
year = 2024,
url = { https://huggingface.co/rubra-ai/Qwen2-7B-Instruct },
doi = { 10.57967/hf/2683 },
publisher = { Hugging Face }
}
信息表格
属性 | 详情 |
---|---|
模型类型 | 文本生成 |
训练数据 | 专有数据集,包含各种函数调用、聊天和指令数据 |
提示信息
⚠️ 重要提示
尽管该模型在众多任务上表现出色,但仍可能产生有偏差或错误的输出。在敏感或高风险应用中使用该模型时,用户应谨慎并进行批判性判断。
💡 使用建议
用户应确保该模型的部署符合伦理准则,并考虑生成文本可能产生的社会影响。强烈反对将该模型用于生成有害或误导性内容。
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