🚀 語言模型微調項目
本項目是一個基於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許可證。