🚀 Text2SQL-1.5B模型
Text2SQL-1.5B 是一款强大的 自然语言转SQL 模型,旨在将用户查询转换为结构化的SQL语句。它支持复杂的多表查询,并确保在文本到SQL的转换中具有较高的准确性。
🚀 快速开始
系统指令
为确保模型输出的一致性,请使用以下系统指令:
始终将代码和解释分开。将SQL代码放在单独的代码块中,随后在单独的段落中进行解释。使用Markdown的三个反引号(```sql
用于SQL)正确格式化代码。先在单独的代码块中编写SQL查询,然后用纯文本解释该查询。不要将它们合并为一个响应。
对于JSON结果,请使用以下指令:
始终将SQL代码和解释分开。以包含两个键('query' 和 'explanation')的JSON格式返回SQL查询。响应应严格遵循以下结构:{"query": "SQL_QUERY_HERE", "explanation": "EXPLANATION_HERE"}。'query' 键应仅包含SQL语句,'explanation' 键应提供对查询的纯文本解释。不要将它们合并为一个响应。
提示格式
提示格式应同时包含用户查询和使用 CREATE TABLE
语句的表结构。预期的消息格式如下:
messages = [
{"role": "system", "content": "Always separate code and explanation. Return SQL code in a separate block, followed by the explanation in a separate paragraph. Use markdown triple backticks (```sql for SQL) to format the code properly. Write the SQL query first in a separate code block. Then, explain the query in plain text. Do not merge them into one response. The query should always include the table structure using a CREATE TABLE statement before executing the main SQL query."},
{"role": "user", "content": "Show the total sales for each customer who has spent more than $50,000."},
{"role": "user", "content": "
CREATE TABLE sales (
id INT PRIMARY KEY,
customer_id INT,
total_amount DECIMAL(10,2),
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(255)
);
"}
]
模型使用
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
tokenizer = AutoTokenizer.from_pretrained("yasserrmd/Text2SQL-1.5B")
model = AutoModelForCausalLM.from_pretrained("yasserrmd/Text2SQL-1.5B")
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
system_instruction = "Always separate code and explanation. Return SQL code in a separate block, followed by the explanation in a separate paragraph. Use markdown triple backticks (```sql for SQL) to format the code properly. Write the SQL query first in a separate code block. Then, explain the query in plain text. Do not merge them into one response. The query should always include the table structure using a CREATE TABLE statement before executing the main SQL query."
user_query = "Show the total sales for each customer who has spent more than $50,000.
CREATE TABLE sales (
id INT PRIMARY KEY,
customer_id INT,
total_amount DECIMAL(10,2),
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(255)
);
"
messages = [
{"role": "system", "content": system_instruction},
{"role": "user", "content": user_query},
]
response = pipe(messages)
print(response[0]['generated_text'])
📦 安装指南
文档未提供安装步骤,暂不展示。
📚 详细文档
上传的模型
- 开发者:yasserrmd
- 许可证:apache-2.0
- 微调自的模型:unsloth/qwen2.5-coder-1.5b-instruct-bnb-4bit
这个Qwen2模型使用 Unsloth 和Huggingface的TRL库进行训练,速度提高了2倍。

📄 许可证
本模型使用的许可证为 apache-2.0
。
标签信息
属性 |
详情 |
模型类型 |
text-generation-inference、transformers、unsloth、qwen2、trl、sft |
训练数据 |
gretelai/synthetic_text_to_sql |