🚀 语言模型微调项目
本项目是一个基于transformers
库的文本生成模型微调项目,将基础模型与PEFT微调模型合并,形成独立可用的模型。该模型可用于文本生成任务,尤其在特定领域的文本输出上表现出色。
🚀 快速开始
使用以下代码开始使用该模型:
基础用法
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from transformers import pipeline
import torch
model_id = "langdai/gemma-2-2b-it-tool-think"
model = AutoModelForCausalLM.from_pretrained(model_id,
device_map="cuda:0",
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model.eval()
generator = pipeline("text-generation", model= model, tokenizer= tokenizer)
高级用法
prompt="""<bos><start_of_turn>human
You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags.You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions.Here are the available tools:<tools> [{'type': 'function', 'function': {'name': 'convert_currency', 'description': 'Convert from one currency to another', 'parameters': {'type': 'object', 'properties': {'amount': {'type': 'number', 'description': 'The amount to convert'}, 'from_currency': {'type': 'string', 'description': 'The currency to convert from'}, 'to_currency': {'type': 'string', 'description': 'The currency to convert to'}}, 'required': ['amount', 'from_currency', 'to_currency']}}}, {'type': 'function', 'function': {'name': 'calculate_distance', 'description': 'Calculate the distance between two locations', 'parameters': {'type': 'object', 'properties': {'start_location': {'type': 'string', 'description': 'The starting location'}, 'end_location': {'type': 'string', 'description': 'The ending location'}}, 'required': ['start_location', 'end_location']}}}] </tools>Use the following pydantic model json schema for each tool call you will make: {'title': 'FunctionCall', 'type': 'object', 'properties': {'arguments': {'title': 'Arguments', 'type': 'object'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['arguments', 'name']}For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
<tool_call>
{tool_call}
</tool_call>Also, before making a call to a function take the time to plan the function to take. Make that thinking process between <think>{your thoughts}</think>
Hi, I need to convert 500 INR to Euros. Can you help me with that?<end_of_turn><eos>
<start_of_turn>model
<think>"""
output = generator([{"role": "user", "content": prompt}], max_new_tokens=512, return_full_text=False)[0]
print(output)
✨ 主要特性
- 该模型是将PEFT微调模型与基础模型合并后的独立模型。
- 可用于文本生成任务,能根据给定的工具进行函数调用辅助用户查询。
📦 安装指南
文档未提及具体安装步骤,可参考transformers
库的官方安装文档进行安装。
📚 详细文档
模型详情
- 开发者:[Liching]
- 资助方:[hobby]
- 模型类型:文本生成
- 支持语言:英语
- 许可证:MIT
- 微调基础模型:[gemma-2b-it]
使用场景
gemma-2b-it
不能用于工具调用,且像最近开发的Deepseek r1一样,以推理方式响应。在微调模型时已考虑到这些限制。
偏差、风险和局限性
由于模型仅微调了1个epoch,因此容易出现偏差和错误。
环境影响
可使用Lacoste等人(2019)提出的机器学习影响计算器来估算碳排放。
属性 |
详情 |
硬件类型 |
T4 24GPU |
使用时长 |
4小时 |
📄 许可证
本项目采用MIT许可证。