Commit
·
38d830a
1
Parent(s):
f6aa305
First commit
Browse files
README.md
CHANGED
|
@@ -1,146 +1,3 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
- Pytorch
|
| 4 |
-
license: Apache License 2.0
|
| 5 |
-
tasks:
|
| 6 |
-
- text-generation
|
| 7 |
-
|
| 8 |
-
#model-type:
|
| 9 |
-
##如 gpt、phi、llama、chatglm、baichuan 等
|
| 10 |
-
#- gpt
|
| 11 |
-
|
| 12 |
-
#domain:
|
| 13 |
-
##如 nlp、cv、audio、multi-modal
|
| 14 |
-
#- nlp
|
| 15 |
-
|
| 16 |
-
#language:
|
| 17 |
-
##语言代码列表 https://help.aliyun.com/document_detail/215387.html?spm=a2c4g.11186623.0.0.9f8d7467kni6Aa
|
| 18 |
-
#- cn
|
| 19 |
-
|
| 20 |
-
#metrics:
|
| 21 |
-
##如 CIDEr、Blue、ROUGE 等
|
| 22 |
-
#- CIDEr
|
| 23 |
-
|
| 24 |
-
#tags:
|
| 25 |
-
##各种自定义,包括 pretrained、fine-tuned、instruction-tuned、RL-tuned 等训练方法和其他
|
| 26 |
-
#- pretrained
|
| 27 |
-
|
| 28 |
-
#tools:
|
| 29 |
-
##如 vllm、fastchat、llamacpp、AdaSeq 等
|
| 30 |
-
#- vllm
|
| 31 |
---
|
| 32 |
-
### Important Links
|
| 33 |
-
|
| 34 |
-
🤖[Github](https://github.com/XGenerationLab/XiYanSQL-QwenCoder) |
|
| 35 |
-
📖[XiYan-SQL](https://github.com/XGenerationLab/XiYan-SQL) |
|
| 36 |
-
🌕[析言GBI](https://bailian.console.aliyun.com/xiyan) |
|
| 37 |
-
🤗[Modelscope Space](https://www.modelscope.cn/studios/XGenerationLab/XiYanSQL-QwenCoder-32B)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
## Introduction
|
| 41 |
-
We are excited to open source the XiYanSQL-QwenCoder series model, dedicated to advancing the development of LLMs in the text-to-SQL domain. As of now, XiYanSQL-QwenCoder covers four mainstream model sizes: 3B, 7B, 14B, and 32B parameters, to meet the needs of different developers.
|
| 42 |
-
- The XiYanSQL-QwenCoder model demonstrates strong performance in SQL generation, with the XiYanSQL-QwenCoder-32B achieving a 69.03% EX score on the BIRD TEST set, setting a new SOTA with a single fine-tuned model. Other models in the series also maintain a leading position at their respective sizes.
|
| 43 |
-
- The XiYanSQL-QwenCoder model supports multiple SQL dialects, such as SQLite, PostgreSQL, and MySQL.
|
| 44 |
-
- The XiYanSQL-QwenCoder model can be used directly for text-to-SQL tasks or serve as a better starting point for fine-tuning SQL models.
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
## Model Downloads
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
| **Model** | **Download Latest** |
|
| 51 |
-
|-----------|------------------|
|
| 52 |
-
|XiYanSQL-QwenCoder-3B |[🤗 Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-3B-2502)|
|
| 53 |
-
|XiYanSQL-QwenCoder-7B |[🤗 Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-7B-2502)|
|
| 54 |
-
|XiYanSQL-QwenCoder-14B |[🤗 Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-14B-2502)|
|
| 55 |
-
|XiYanSQL-QwenCoder-32B |[🤗 Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-32B-2412)|
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
## Performance
|
| 60 |
-
The XiYanSQL-QwenCoder models, as multi-dialect SQL base models, demonstrating robust SQL generation capabilities. The following presents the evaluation results at the time of release. We conducted a comprehensive evaluation of the model's performance under two schema formats, M-Schema, and original DDL, using the BIRD and Spider benchmarks in the Text-to-SQL domain.
|
| 61 |
-
|
| 62 |
-
| Model name|BIRD Dev@M-Schema |BIRD Dev@DDL|Spider Test@M-Schema|Spider Test@DDL|
|
| 63 |
-
|-----------|:------------------:|:---------------:|:-------------------:|:---------------:|
|
| 64 |
-
|Codellama-34b | 33.05% | - | 67.74% | - |
|
| 65 |
-
|Deepseek-coder-33b | 47.52% | 44.72% | 72.39% | - |
|
| 66 |
-
|TableGPT2 | 46.35% | 47.07% | 74.76% | 77.28% |
|
| 67 |
-
|Codestral 22b | 50.52% | 47.00% | 78.45% | 75.47% |
|
| 68 |
-
|GLM-4-plus | 54.37% | - | 79.40% | - |
|
| 69 |
-
|Claude35_sonnet-1022 | 53.32% | 50.46% | 76.27% | 73.04% |
|
| 70 |
-
|Deepseek(v2.5-1210) | 55.74% | 55.61% | 82.08% | 80.57% |
|
| 71 |
-
|Gemini-1.5-pro | 61.34% | 57.89% | 85.11% | 84.00% |
|
| 72 |
-
|GPT-4o-0806 | 58.47% | 54.82% | 82.89% | 78.45% |
|
| 73 |
-
|XiYanSQL-QwenCoder-3B | 54.11% | 53.19% | 82.69% | 78.85% |
|
| 74 |
-
|XiYanSQL-QwenCoder-7B | 59.78% | 56.58% | 84.86% | 80.31% |
|
| 75 |
-
|XiYanSQL-QwenCoder-14B | 63.10% | 60.37% | 85.76% | 82.79% |
|
| 76 |
-
|XiYanSQL-QwenCoder-32B | 67.01% | 63.04% | 88.39% | 85.46% |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
## Requirements
|
| 80 |
-
|
| 81 |
-
transformers >= 4.37.0
|
| 82 |
-
|
| 83 |
-
## Quickstart
|
| 84 |
-
|
| 85 |
-
Here is a simple code snippet for quickly using **XiYanSQL-QwenCoder** model. We provide a Chinese version of the prompt, and you just need to replace the placeholders for "question," "db_schema," and "evidence" to get started. We recommend using our [M-Schema](https://github.com/XGenerationLab/M-Schema) format for the schema; other formats such as DDL are also acceptable, but they may affect performance.
|
| 86 |
-
Currently, we mainly support mainstream dialects like SQLite, PostgreSQL, and MySQL.
|
| 87 |
-
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
nl2sqlite_template_cn = """你是一名{dialect}专家,现在需要阅读并理解下面的【数据库schema】描述,以及可能用到的【参考信息】,并运用{dialect}知识生成sql语句回答【用户问题】。
|
| 91 |
-
【用户问题】
|
| 92 |
-
{question}
|
| 93 |
-
|
| 94 |
-
【数据库schema】
|
| 95 |
-
{db_schema}
|
| 96 |
-
|
| 97 |
-
【参考信息】
|
| 98 |
-
{evidence}
|
| 99 |
-
|
| 100 |
-
【用户问题】
|
| 101 |
-
{question}
|
| 102 |
-
|
| 103 |
-
```sql"""
|
| 104 |
-
|
| 105 |
-
import torch
|
| 106 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 107 |
-
|
| 108 |
-
model_name = "XGenerationLab/XiYanSQL-QwenCoder-32B-2412"
|
| 109 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 110 |
-
model_name,
|
| 111 |
-
torch_dtype=torch.bfloat16,
|
| 112 |
-
device_map="auto"
|
| 113 |
-
)
|
| 114 |
-
|
| 115 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 116 |
-
|
| 117 |
-
## dialects -> ['SQLite', 'PostgreSQL', 'MySQL']
|
| 118 |
-
prompt = nl2sqlite_template_cn.format(dialect="", db_schema="", question="", evidence="")
|
| 119 |
-
message = [{'role': 'user', 'content': prompt}]
|
| 120 |
-
|
| 121 |
-
text = tokenizer.apply_chat_template(
|
| 122 |
-
message,
|
| 123 |
-
tokenize=False,
|
| 124 |
-
add_generation_prompt=True
|
| 125 |
-
)
|
| 126 |
-
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 127 |
-
|
| 128 |
-
generated_ids = model.generate(
|
| 129 |
-
**model_inputs,
|
| 130 |
-
pad_token_id=tokenizer.pad_token_id,
|
| 131 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 132 |
-
max_new_tokens=1024,
|
| 133 |
-
temperature=0.1,
|
| 134 |
-
top_p=0.8,
|
| 135 |
-
do_sample=True,
|
| 136 |
-
)
|
| 137 |
-
generated_ids = [
|
| 138 |
-
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 139 |
-
]
|
| 140 |
-
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 141 |
-
|
| 142 |
-
```
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
## Acknowledgments
|
| 146 |
-
If you find our work useful, please give us a citation or a like, so we can make a greater contribution to the open-source community!
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|