File size: 4,665 Bytes
b05e3ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03ed7ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
license: other
---

![Aquila_logo](./log.jpeg)

# 悟道·天鹰(Aquila)

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



悟道 · 天鹰 Aquila 模型的更多细节将在官方技术报告中呈现。请关注官方渠道更新。包括 [FlagAI GitHub仓库](https://github.com/FlagAI-Open/FlagAI/),[FlagAI 知乎账号](https://www.zhihu.com/people/95-22-20-18)、[FlagAI 官方技术交流群](https://github.com/FlagAI-Open/FlagAI/blob/master/wechat-qrcode.jpg)、智源研究院微信公众号、智源社区微信公众号。


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

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


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


## 使用方式/How to use

### 1. 推理/Inference

```python
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系列模型许可协议](https://huggingface.co/BAAI/AquilaChat-7B/resolve/main/BAAI%20Aquila%20Model%20License%20Agreement.pdf)