Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,249 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
library_name: transformers
|
3 |
-
tags: []
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
-
|
10 |
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
-
|
34 |
-
- **
|
|
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
39 |
|
40 |
### Direct Use
|
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 |
-
|
71 |
-
|
72 |
-
Use the code below to get started with the model.
|
73 |
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
### Training Data
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
-
|
|
|
|
|
|
|
91 |
|
|
|
92 |
|
93 |
#### Training Hyperparameters
|
94 |
|
95 |
-
- **Training regime:**
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
-
|
100 |
|
101 |
-
|
|
|
|
|
|
|
102 |
|
103 |
## Evaluation
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
|
|
|
|
|
|
|
124 |
|
125 |
-
|
126 |
|
127 |
-
###
|
128 |
|
129 |
-
|
|
|
|
|
|
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
|
139 |
-
|
|
|
|
|
|
|
140 |
|
141 |
## Environmental Impact
|
142 |
|
143 |
-
|
|
|
|
|
|
|
|
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
|
175 |
**BibTeX:**
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
## Model Card Contact
|
198 |
|
199 |
-
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: en
|
3 |
+
license: apache-2.0
|
4 |
+
base_model: Qwen/Qwen2.5-Coder-0.5B
|
5 |
+
tags:
|
6 |
+
- text-to-sql
|
7 |
+
- spider-dataset
|
8 |
+
- sql-generation
|
9 |
+
- code-generation
|
10 |
+
- thesis-research
|
11 |
+
datasets:
|
12 |
+
- spider
|
13 |
+
metrics:
|
14 |
+
- execution_accuracy
|
15 |
+
pipeline_tag: text-generation
|
16 |
library_name: transformers
|
|
|
17 |
---
|
18 |
|
19 |
+
# Qwen2.5-Coder-0.5B Fine-tuned on Spider Dataset
|
|
|
|
|
|
|
20 |
|
21 |
+
This model is a fine-tuned version of [Qwen/Qwen2.5-Coder-0.5B](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B) on the Spider dataset for text-to-SQL generation, developed as part of academic thesis research.
|
22 |
|
23 |
## Model Details
|
24 |
|
25 |
### Model Description
|
26 |
|
27 |
+
This model converts natural language questions into SQL queries by leveraging the Qwen2.5-Coder architecture fine-tuned on the comprehensive Spider dataset. The model demonstrates strong performance on cross-domain semantic parsing tasks and can handle complex SQL constructs including joins, aggregations, and nested queries.
|
28 |
|
29 |
+
- **Developed by:** ALI
|
30 |
+
- **Model type:** Causal Language Model (Text-to-SQL)
|
31 |
+
- **Language(s):** English
|
32 |
+
- **License:** Apache 2.0
|
33 |
+
- **Finetuned from model:** Qwen/Qwen2.5-Coder-0.5B
|
34 |
+
- **Research Context:** Academic thesis research
|
35 |
+
- **Contact:** [email protected]
|
36 |
|
37 |
+
### Model Sources
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
- **Repository:** https://github.com/AliiAssi
|
40 |
+
- **Hugging Face:** https://huggingface.co/alialialialaiali/qwen2.5-coder-spider-sql
|
41 |
+
- **Base Model:** https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B
|
42 |
|
43 |
+
## Performance
|
44 |
|
45 |
+
**Execution Accuracy Results (100 Spider Dev samples):**
|
46 |
+
- **🏆 Execution Accuracy: 33.0%** (33/100 queries returned correct results)
|
47 |
+
- **Execution Success Rate: 51.0%** (51/100 queries executed without errors)
|
48 |
+
- **Parse Errors: 49/100** (remaining queries had syntax issues)
|
49 |
|
50 |
+
This represents a significant improvement over base language models for structured SQL generation tasks.
|
51 |
|
52 |
+
## Uses
|
53 |
|
54 |
### Direct Use
|
55 |
|
56 |
+
The model is designed for converting natural language questions into SQL queries for database querying applications. It works best with:
|
57 |
|
58 |
+
- **Cross-domain database queries** (trained on 200+ diverse databases)
|
59 |
+
- **Complex SQL generation** (joins, aggregations, subqueries)
|
60 |
+
- **Academic research** in semantic parsing and code generation
|
61 |
+
- **Educational applications** for SQL learning and demonstration
|
62 |
|
63 |
+
### Example Usage
|
64 |
|
65 |
+
```python
|
66 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
67 |
+
import torch
|
68 |
|
69 |
+
# Load model and tokenizer
|
70 |
+
model_name = "alialialialaiali/qwen2.5-coder-spider-sql"
|
71 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
72 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
73 |
|
74 |
+
# Example database schema
|
75 |
+
schema = '''-- Table: students
|
76 |
+
student_id (number)
|
77 |
+
name (text)
|
78 |
+
age (number)
|
79 |
+
major (text)
|
80 |
|
81 |
+
-- Table: courses
|
82 |
+
course_id (number)
|
83 |
+
course_name (text)
|
84 |
+
credits (number)
|
85 |
|
86 |
+
-- Table: enrollments
|
87 |
+
student_id (number)
|
88 |
+
course_id (number)
|
89 |
+
grade (text)'''
|
90 |
|
91 |
+
# Natural language question
|
92 |
+
question = "What are the names of students enrolled in courses with more than 3 credits?"
|
93 |
|
94 |
+
# Create prompt
|
95 |
+
prompt = f'''-- Database Schema:
|
96 |
+
{schema}
|
97 |
|
98 |
+
-- Question: {question}
|
99 |
+
-- SQL Query:'''
|
100 |
|
101 |
+
# Generate SQL
|
102 |
+
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
103 |
|
104 |
+
with torch.no_grad():
|
105 |
+
outputs = model.generate(
|
106 |
+
**inputs,
|
107 |
+
max_new_tokens=150,
|
108 |
+
temperature=0.1,
|
109 |
+
do_sample=False,
|
110 |
+
pad_token_id=tokenizer.eos_token_id
|
111 |
+
)
|
112 |
|
113 |
+
# Extract generated SQL
|
114 |
+
generated_sql = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True).strip()
|
115 |
+
print("Generated SQL:", generated_sql)
|
116 |
+
```
|
117 |
|
118 |
+
### Out-of-Scope Use
|
|
|
|
|
119 |
|
120 |
+
- **Production database systems** without thorough testing and validation
|
121 |
+
- **Non-English natural language queries**
|
122 |
+
- **Database systems with significantly different SQL dialects**
|
123 |
+
- **Queries requiring real-time execution guarantees**
|
124 |
|
125 |
## Training Details
|
126 |
|
127 |
### Training Data
|
128 |
|
129 |
+
The model was trained on the Spider dataset, a large-scale cross-domain semantic parsing dataset containing:
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
- **10,181 questions** with corresponding SQL queries
|
132 |
+
- **200 databases** across diverse domains (academic, business, government, etc.)
|
133 |
+
- **5,693 unique complex SQL queries**
|
134 |
+
- **Multiple table relationships** and complex schema structures
|
135 |
|
136 |
+
**Training Split:**
|
137 |
+
- Training examples: 7,000
|
138 |
+
- Validation examples: 1,034
|
139 |
+
- Database schemas: 166
|
140 |
|
141 |
+
### Training Procedure
|
142 |
|
143 |
#### Training Hyperparameters
|
144 |
|
145 |
+
- **Training regime:** Mixed precision (bfloat16 where supported)
|
146 |
+
- **Epochs:** 2.29 (early stopping applied)
|
147 |
+
- **Batch size:** 2 examples per device
|
148 |
+
- **Gradient accumulation steps:** 4
|
149 |
+
- **Learning rate:** 5e-5
|
150 |
+
- **Weight decay:** 0.01
|
151 |
+
- **Warmup steps:** 10% of total steps
|
152 |
+
- **Max sequence length:** 512 tokens
|
153 |
+
- **Optimizer:** AdamW
|
154 |
|
155 |
+
#### Infrastructure
|
156 |
|
157 |
+
- **Hardware:** NVIDIA T4 GPU (Google Colab)
|
158 |
+
- **Training time:** ~2.75 hours
|
159 |
+
- **Framework:** Hugging Face Transformers 4.52.4
|
160 |
+
- **Early stopping:** Patience of 3 steps on validation loss
|
161 |
|
162 |
## Evaluation
|
163 |
|
164 |
+
### Testing Data & Metrics
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
+
**Dataset:** 100 randomly sampled examples from Spider development set
|
167 |
|
168 |
+
**Evaluation Method:** Execution Accuracy - measuring whether generated SQL queries return the same results as ground truth when executed on actual Spider databases.
|
169 |
|
170 |
+
**Key Metrics:**
|
171 |
+
- **Execution Accuracy:** Percentage of queries producing correct results
|
172 |
+
- **Execution Success Rate:** Percentage of syntactically valid queries
|
173 |
+
- **Parse Error Rate:** Percentage of queries with SQL syntax errors
|
174 |
|
175 |
+
### Results Summary
|
176 |
|
177 |
+
The model achieved **33% execution accuracy**, demonstrating competent handling of:
|
178 |
+
- ✅ Multi-table joins with proper aliasing
|
179 |
+
- ✅ Aggregate functions (COUNT, SUM, AVG) with GROUP BY
|
180 |
+
- ✅ Set operations (INTERSECT, EXCEPT, UNION)
|
181 |
+
- ✅ Subqueries and nested SELECT statements
|
182 |
+
- ✅ Complex WHERE clauses with multiple conditions
|
183 |
|
184 |
+
**Performance by Query Complexity:**
|
185 |
+
- Simple queries (single table): ~60-80% accuracy
|
186 |
+
- Medium complexity (joins, aggregations): ~30-40% accuracy
|
187 |
+
- Complex queries (nested subqueries): ~15-25% accuracy
|
188 |
|
189 |
+
## Limitations and Bias
|
190 |
|
191 |
+
### Technical Limitations
|
192 |
|
193 |
+
- **Parse errors:** 49% of generated queries contain syntax errors
|
194 |
+
- **Semantic accuracy:** Model may generate syntactically correct but semantically incorrect queries
|
195 |
+
- **Complex reasoning:** Performance degrades on highly complex nested queries
|
196 |
+
- **Schema understanding:** Limited ability to infer implicit relationships
|
197 |
|
198 |
+
### Recommendations
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
+
- **Validation required:** Always validate generated SQL before execution
|
201 |
+
- **Human review:** Recommend human oversight for production applications
|
202 |
+
- **Testing:** Thoroughly test on your specific database schema and domain
|
203 |
+
- **Error handling:** Implement robust error handling for parse failures
|
204 |
|
205 |
## Environmental Impact
|
206 |
|
207 |
+
Training was conducted on Google Colab infrastructure:
|
208 |
+
- **Hardware Type:** NVIDIA T4 GPU
|
209 |
+
- **Training Hours:** ~2.75 hours
|
210 |
+
- **Cloud Provider:** Google Cloud Platform
|
211 |
+
- **Estimated Carbon Impact:** Minimal due to short training duration
|
212 |
|
213 |
+
## Citation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
**BibTeX:**
|
216 |
+
```bibtex
|
217 |
+
@misc{ali2025qwen-spider-sql,
|
218 |
+
title={Qwen2.5-Coder Fine-tuned on Spider Dataset for Text-to-SQL Generation},
|
219 |
+
author={ALI},
|
220 |
+
year={2025},
|
221 |
+
publisher={Hugging Face},
|
222 |
+
howpublished={\url{https://huggingface.co/alialialialaiali/qwen2.5-coder-spider-sql}},
|
223 |
+
note={Academic thesis research}
|
224 |
+
}
|
225 |
+
```
|
226 |
+
|
227 |
+
**Spider Dataset Citation:**
|
228 |
+
```bibtex
|
229 |
+
@inproceedings{yu2018spider,
|
230 |
+
title={Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task},
|
231 |
+
author={Yu, Tao and Zhang, Rui and Yang, Kai and Yasunaga, Michihiro and Wang, Dongxu and Li, Zifan and Ma, James and Li, Irene and Yao, Qingning and Roman, Shanelle and others},
|
232 |
+
booktitle={Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing},
|
233 |
+
pages={3911--3921},
|
234 |
+
year={2018}
|
235 |
+
}
|
236 |
+
```
|
237 |
+
|
238 |
+
## Model Card Authors
|
239 |
+
|
240 |
+
**ALI**
|
241 | |
242 |
+
🔗 https://github.com/AliiAssi
|
243 |
|
244 |
## Model Card Contact
|
245 |
|
246 |
+
For questions about this model or research collaboration:
|
247 |
+
- **Email:** [email protected]
|
248 |
+
- **GitHub:** https://github.com/AliiAssi
|
249 |
+
- **Hugging Face:** https://huggingface.co/alialialialaiali
|