ashishsahu2008 commited on
Commit
bfb76b7
·
verified ·
1 Parent(s): df41957

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +102 -10
README.md CHANGED
@@ -1,21 +1,113 @@
1
  ---
2
- base_model: unsloth/qwen2.5-3b-instruct-unsloth-bnb-4bit
3
- tags:
4
- - text-generation-inference
5
- - transformers
6
- - unsloth
7
- - qwen2
8
  license: apache-2.0
9
  language:
10
  - en
 
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
- # Uploaded finetuned model
 
 
 
 
14
 
15
  - **Developed by:** ashishsahu2008
 
 
16
  - **License:** apache-2.0
17
- - **Finetuned from model :** unsloth/qwen2.5-3b-instruct-unsloth-bnb-4bit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
 
 
 
 
 
20
 
21
- [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
1
  ---
2
+ base_model: unsloth/Qwen2.5-3B-Instruct
3
+ library_name: transformers
4
+ pipeline_tag: text-generation
 
 
 
5
  license: apache-2.0
6
  language:
7
  - en
8
+ tags:
9
+ - text-to-sql
10
+ - sql
11
+ - qwen2
12
+ - lora
13
+ - qlora
14
+ - unsloth
15
+ - trl
16
+ datasets:
17
+ - b-mc2/sql-create-context
18
  ---
19
 
20
+ # Qwen2.5-3B Text-to-SQL
21
+
22
+ A fine-tuned version of **Qwen2.5-3B-Instruct** that converts natural-language
23
+ questions into SQL queries, given a database schema. Trained with LoRA/QLoRA on a
24
+ single free GPU.
25
 
26
  - **Developed by:** ashishsahu2008
27
+ - **Base model:** [unsloth/Qwen2.5-3B-Instruct](https://huggingface.co/unsloth/Qwen2.5-3B-Instruct)
28
+ - **Fine-tuned on:** [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context)
29
  - **License:** apache-2.0
30
+ - **Live demo:** https://huggingface.co/spaces/ashishsahu2008/text2sql-demo
31
+ - **Code / write-up:** https://github.com/ashishsahu2008/fine-tuning
32
+
33
+ ## What it does
34
+
35
+ Give it a `CREATE TABLE` schema and a plain-English question, and it returns only
36
+ the SQL query that answers the question — no explanations or markdown, just runnable SQL.
37
+
38
+ ## Results
39
+
40
+ Evaluated on a held-out test split (n=200) the model never saw during training.
41
+ Both the base and fine-tuned models were scored with identical string normalization
42
+ (lowercase, strip `;`, canonicalize quotes), so the comparison is apples-to-apples.
43
+
44
+ | Model | Exact-match accuracy |
45
+ |--------------------------------|:--------------------:|
46
+ | Qwen2.5-3B-Instruct (base) | 41.5% |
47
+ | **This model (fine-tuned)** | **72.5%** |
48
+
49
+ Only 0.96% of parameters (~30M of 3.1B) were trained via LoRA. Much of the gain
50
+ comes from the base model learning to emit clean, executable SQL instead of wrapping
51
+ answers in prose or markdown fences.
52
+
53
+ > **Note on the metric:** exact-match undercounts semantically-correct queries that
54
+ > are written differently (column order, aliases, whitespace). A stronger evaluation
55
+ > would use AST comparison (`sqlglot`) or execution accuracy on a benchmark with
56
+ > populated databases (Spider / BIRD); `sql-create-context` ships schemas only.
57
+
58
+ ## Usage
59
+
60
+ ```python
61
+ import torch
62
+ from transformers import AutoModelForCausalLM, AutoTokenizer
63
+
64
+ model_id = "ashishsahu2008/qwen2.5-3b-text2sql"
65
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
66
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16)
67
+
68
+ schema = "CREATE TABLE employees (name VARCHAR, salary INTEGER, department VARCHAR)"
69
+ question = "List the names of employees in Sales earning over 50000."
70
+
71
+ messages = [
72
+ {"role": "system", "content": "You are a SQL expert. Given a database schema "
73
+ "and a question, output only the SQL query that answers it."},
74
+ {"role": "user", "content": f"Schema:\n{schema}\n\nQuestion: {question}"},
75
+ ]
76
+ inputs = tokenizer.apply_chat_template(
77
+ messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
78
+ ).to(model.device)
79
+ out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
80
+ print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
81
+ ```
82
+
83
+ ## Prompt format
84
+
85
+ The model expects the schema and question in a single user turn, with this system prompt:
86
+
87
+ ```
88
+ System: You are a SQL expert. Given a database schema and a question, output only the SQL query that answers it.
89
+ User: Schema:
90
+ <CREATE TABLE ...>
91
+
92
+ Question: <your question>
93
+ ```
94
+
95
+ ## Training details
96
+
97
+ - **Method:** supervised fine-tuning (SFT) with LoRA on a 4-bit quantized base (QLoRA)
98
+ - **LoRA config:** rank 16, alpha 16, applied to attention + MLP projections
99
+ - **Data:** 3,000-row subset of `b-mc2/sql-create-context` (2,700 train / 300 test)
100
+ - **Hyperparameters:** 2 epochs, learning rate 2e-4, effective batch size 8
101
+ - **Hardware:** single Colab T4, ~25 minutes
102
+ - **Frameworks:** [Unsloth](https://github.com/unslothai/unsloth) + TRL `SFTTrainer`
103
+
104
+ ## Limitations
105
 
106
+ - Trained on **single-table** `CREATE TABLE` schemas; complex multi-join databases
107
+ are out of distribution.
108
+ - Assumes the schema is provided in the prompt — it does not know any tables you
109
+ don't give it.
110
+ - SQL dialect follows the training data (broadly SQLite-compatible); it does not
111
+ target a specific engine's extensions.
112
 
113
+ Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) and Hugging Face's TRL library.