🚀 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 |