本模型是基于IterLM-chat-7B,在19,5297条数据上进行3个epoch的FieTue训练出来的关于Text-to-SQL领域的模型。 本模型根据自然语言问句及数据库表结构生成对应的SQL。 使用DB-GPT处理并在Huggig Face开源的数据集,经过筛除掉多轮对话数据以及整理格式后得到19,5297条数据。 处理后的格式如下: 本项目使用xtuer0.1.15, 在iterlm2-chat-7b上进行微调, 模型地址 编写一个cli_demo.py脚本用来简单使用Cloe with HTTP
git cloe https://www.modelscope.c/Nobitaxi/IterLM2-chat-7B-SQL.git
\
模型描述
训练数据介绍
[
{
"questio": "which states border arizoa",
"cotext": "CREATE TABLE moutai (moutai_ame, moutai_altitude, state_ame, coutry_ame); CREATE TABLE city (city_ame, state_ame, populatio, coutry_ame); CREATE TABLE road (road_ame, state_ame); CREATE TABLE border_ifo (state_ame, border); CREATE TABLE river (river_ame, legth, traverse, coutry_ame); CREATE TABLE state (state_ame, capital, populatio, area, coutry_ame, desity); CREATE TABLE highlow (state_ame, highest_poit, highest_elevatio, lowest_poit, lowest_elevatio); CREATE TABLE lake (lake_ame, area, state_ame, coutry_ame)",
"aswer": "SELECT border FROM border_ifo WHERE state_ame = 'arizoa'"
},
...
{}
]
模型训练流程
xtuer trai ${YOUR_CONFIG} --deepspeed deepseed_zero2
export MKL_SERVICE_FORCE_INTEL=1
xtuer covert pth_to_hf ${YOUR_CONFIG} ${PTH} ${ADAPTER_PATH}
xtuer covert merge ${BASE_LLM_PATH} ${ADAPTER_PATH} ${SAVE_PATH} --max-shard-size 2GB
如何使用
import torch
from modelscope import AutoTokeizer, AutoModelForCausalLM
model_ame_or_path = "Nobitaxi/IterLM2-chat-7B-SQL"
tokeizer = AutoTokeizer.from_pretraied(model_ame_or_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretraied(model_ame_or_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto')
model = model.eval()
system_prompt = """If you are a expert i SQL, please geerate a good SQL Query for Questio based o the CREATE TABLE statemet."""
messages = [(system_prompt, '')]
prit("=============Welcome to IterLM2-chat-7b-sql chatbot, type 'exit' to exit.=============")
while True:
iput_text = iput("User >>> ")
iput_text.replace(' ', '')
if iput_text == "exit":
break
respose, history = model.chat(tokeizer, iput_text, history=messages)
messages.apped((iput_text, respose))
prit(f"robot >>> {respose}")
点击空白处退出提示
评论