AquilaSQL-7B / README_zh.md
MonteXiaofeng's picture
fix readme
03ed7ab
metadata
license: other

Aquila_logo

悟道·天鹰(Aquila)

悟道·天鹰(Aquila) 语言大模型是首个具备中英双语知识、支持商用许可协议、国内数据合规需求的开源语言大模型。

  • 🌟 支持开源商用许可。Aquila系列模型的源代码基于 Apache 2.0 协议,模型权重基于《智源Aquila系列模型许可协议》,使用者在满足许可限制的情况下,可用于商业目的。
  • ✍️ 具备中英文知识。Aquila系列模型在中英文高质量语料基础上从 0 开始训练,中文语料约占 40%,保证模型在预训练阶段就开始积累原生的中文世界知识,而非翻译而来的知识。
  • 👮‍♀️符合国内数据合规需求。Aquila系列模型的中文语料来自智源多年积累的中文数据集,包括来自1万多个站源的中文互联网数据(其中99%以上为国内站源),以及获得国内权威机构支持的高质量中文文献数据、中文书籍数据等。我们仍在持续积累高质量、多样化的数据集,并源源不断加入Aquila基础模型后续训练中。
  • 🎯持续迭代,持续开源开放。我们将不断完善训练数据、优化训练方法、提升模型性能,在更优秀的基础模型基座上,培育枝繁叶茂的“模型树”,持续开源开放更新的版本。

悟道 · 天鹰 Aquila 模型的更多细节将在官方技术报告中呈现。请关注官方渠道更新。包括 FlagAI GitHub仓库FlagAI 知乎账号FlagAI 官方技术交流群、智源研究院微信公众号、智源社区微信公众号。

模型 模型类型 简介 状态 训练所用显卡
AquilaSQL-7B 对话模型,“文本-代码”生成模型,基于 AquilaCode继续预训练+SFT。 AquilaSQL在代码基础模型AquilaCode上进行继续预训练和sft微调,为模型设计了指标评估体系,目前在cspider榜单上达到了sota,可以通过更改数据的方式适配不同领域的sql查询场景。 已发布 Nvidia-A100

悟道·天鹰Aquila系列模型将持续开源更优版本。

快速开始使用 AquilaSQL-7B 对话模型

使用方式/How to use

1. 推理/Inference

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
device = torch.device("cuda")
model_info = "BAAI/AquilaSQL-7B"

tokenizer = AutoTokenizer.from_pretrained(model_info, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_info, trust_remote_code=True, torch_dtype=torch.float16, device_map='auto')

model.eval()
model.to(device)
torch.manual_seed(123)

text = "有多个数据库表,信息如下:\n表名为cars_data,包含的属性为cars_data.horsepower,cars_data.accelerate,cars_data.mpg,cars_data.id,cars_data.year;表名为continents,包含的属性为continents.contid,continents.continent;表名为countries,包含的属性为countries.continent,countries.countryname,countries.countryid;表名为model_list,包含的属性为model_list.model,model_list.maker,model_list.modelid,它们之间的关系为 countries.continent = continents.contid\n请为下面的问题编写sql查询语句:\n加速度比马力最大的汽车更大的汽车有多少辆? "

def generate_prompt(input: str):
    prompt = f"A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input}###Assistant:"
    return prompt

stop_tokens = ["###", "[UNK]", "</s>","<|endoftext|>"]

with torch.no_grad():

    _input = generate_prompt(text)
    tokens = tokenizer.encode_plus(_input, None, max_length=None)['input_ids']
    tokens = torch.tensor(tokens)[None,].to(device)
    out = model.generate(tokens, do_sample=False, max_length=1024, eos_token_id=100007,max_new_tokens=512,
                            bad_words_ids=[[tokenizer.encode(token)[0] for token in stop_tokens]])[0]
    out = tokenizer.decode(out.cpu().numpy().tolist())
    print(out)

证书/License

AquilaSQL系列开源模型使用 智源Aquila系列模型许可协议