Update README.md
Browse files
README.md
CHANGED
|
@@ -1,202 +1,185 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
| 2 |
base_model: meta-llama/Llama-3.2-3B
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
##
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 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 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
| 78 |
-
### Training
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 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 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
|
| 191 |
-
|
| 192 |
|
| 193 |
-
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
##
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
| 201 |
|
| 202 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: llama3.2
|
| 5 |
base_model: meta-llama/Llama-3.2-3B
|
| 6 |
+
tags:
|
| 7 |
+
- llama
|
| 8 |
+
- llama-3
|
| 9 |
+
- sql
|
| 10 |
+
- text-to-sql
|
| 11 |
+
- lora
|
| 12 |
+
- peft
|
| 13 |
+
- finetuned
|
| 14 |
+
datasets:
|
| 15 |
+
- spider
|
| 16 |
+
metrics:
|
| 17 |
+
- accuracy
|
| 18 |
+
library_name: transformers
|
| 19 |
+
pipeline_tag: text-generation
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# Llama 3.2 3B - SQL Query Generator (LoRA Fine-tuned)
|
| 23 |
|
| 24 |
+
This model is a fine-tuned version of [meta-llama/Llama-3.2-3B](https://huggingface.co/meta-llama/Llama-3.2-3B) for **text-to-SQL generation** using LoRA (Low-Rank Adaptation) on the Spider dataset.
|
| 25 |
|
| 26 |
+
## Model Description
|
| 27 |
|
| 28 |
+
- **Base Model:** Llama 3.2 3B
|
| 29 |
+
- **Fine-tuning Method:** LoRA (Parameter-Efficient Fine-Tuning)
|
| 30 |
+
- **Quantization:** 4-bit NF4 with double quantization
|
| 31 |
+
- **Dataset:** Spider (7,000 training examples)
|
| 32 |
+
- **Training:** 3 epochs, ~47 minutes on AWS g5.2xlarge (NVIDIA A10G)
|
| 33 |
+
- **Final Training Loss:** 0.37 (85% reduction from initial 2.5)
|
| 34 |
|
| 35 |
+
## Intended Use
|
| 36 |
|
| 37 |
+
This model converts natural language questions into SQL queries for various database schemas. It's designed for:
|
| 38 |
+
- Automated SQL query generation
|
| 39 |
+
- Data analysis assistants
|
| 40 |
+
- Natural language database interfaces
|
| 41 |
+
- Educational tools for SQL learning
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
## Training Details
|
| 44 |
|
| 45 |
+
### Training Hyperparameters
|
| 46 |
+
|
| 47 |
+
- **Learning Rate:** 2e-4
|
| 48 |
+
- **Batch Size:** 4 (per device)
|
| 49 |
+
- **Gradient Accumulation:** 4 steps (effective batch size: 16)
|
| 50 |
+
- **Epochs:** 3
|
| 51 |
+
- **Max Sequence Length:** 2048
|
| 52 |
+
- **LoRA Rank (r):** 16
|
| 53 |
+
- **LoRA Alpha:** 32
|
| 54 |
+
- **LoRA Dropout:** 0.05
|
| 55 |
+
- **Target Modules:** q_proj, k_proj, v_proj, o_proj
|
| 56 |
+
|
| 57 |
+
### Training Results
|
| 58 |
+
|
| 59 |
+
| Metric | Value |
|
| 60 |
+
|--------|-------|
|
| 61 |
+
| Initial Loss | 2.50 |
|
| 62 |
+
| Final Loss | 0.37 |
|
| 63 |
+
| Trainable Parameters | 9.17M (0.51% of total) |
|
| 64 |
+
| Training Time | 47 minutes |
|
| 65 |
+
|
| 66 |
+
## Usage
|
| 67 |
+
|
| 68 |
+
### Installation
|
| 69 |
+
```bash
|
| 70 |
+
pip install transformers peft torch bitsandbytes
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### Inference Example
|
| 74 |
+
```python
|
| 75 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 76 |
+
import torch
|
| 77 |
+
|
| 78 |
+
# Load model and tokenizer
|
| 79 |
+
model_name = "Abhisek987/llama-3.2-sql-lora"
|
| 80 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 81 |
+
model_name,
|
| 82 |
+
device_map="auto",
|
| 83 |
+
torch_dtype=torch.float16
|
| 84 |
+
)
|
| 85 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 86 |
+
|
| 87 |
+
# Prepare prompt
|
| 88 |
+
database = "employees"
|
| 89 |
+
question = "What are the names of all employees who earn more than 50000?"
|
| 90 |
+
|
| 91 |
+
prompt = f"""### Instruction:
|
| 92 |
+
You are a SQL expert. Generate a SQL query to answer the given question for the specified database.
|
| 93 |
+
|
| 94 |
+
### Input:
|
| 95 |
+
Database: {database}
|
| 96 |
+
Question: {question}
|
| 97 |
+
|
| 98 |
+
### Response:
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
# Generate SQL
|
| 102 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 103 |
+
outputs = model.generate(
|
| 104 |
+
**inputs,
|
| 105 |
+
max_new_tokens=256,
|
| 106 |
+
temperature=0.1,
|
| 107 |
+
do_sample=True
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 111 |
+
print(sql_query.split("### Response:")[-1].strip())
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
**Output:**
|
| 115 |
+
```sql
|
| 116 |
+
SELECT name FROM employees WHERE salary > 50000;
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## Example Queries
|
| 120 |
+
|
| 121 |
+
| Question | Generated SQL |
|
| 122 |
+
|----------|---------------|
|
| 123 |
+
| "Show top 5 products by sales" | `SELECT product_id, sum(sales) FROM sales GROUP BY product_id ORDER BY sum(sales) DESC LIMIT 5;` |
|
| 124 |
+
| "Count customers by country" | `SELECT count(*), country FROM customers GROUP BY country;` |
|
| 125 |
+
| "Find orders from last 30 days" | `SELECT order_id FROM orders WHERE date_order_placed BETWEEN DATE('now') - INTERVAL 30 DAY AND DATE('now') - INTERVAL 1 DAY;` |
|
| 126 |
+
|
| 127 |
+
## Limitations
|
| 128 |
+
|
| 129 |
+
- Trained specifically on Spider dataset schemas
|
| 130 |
+
- May not generalize perfectly to significantly different database structures
|
| 131 |
+
- Requires proper database schema context for best results
|
| 132 |
+
- 4-bit quantization may occasionally affect numerical precision
|
| 133 |
+
|
| 134 |
+
## Technical Stack
|
| 135 |
+
|
| 136 |
+
- **Framework:** PyTorch + Transformers
|
| 137 |
+
- **Quantization:** BitsAndBytes (4-bit NF4)
|
| 138 |
+
- **Fine-tuning:** PEFT (LoRA)
|
| 139 |
+
- **Training:** AWS EC2 g5.2xlarge (NVIDIA A10G 24GB)
|
| 140 |
+
|
| 141 |
+
## Citation
|
| 142 |
+
|
| 143 |
+
If you use this model, please cite:
|
| 144 |
+
```bibtex
|
| 145 |
+
@misc{llama32-sql-lora,
|
| 146 |
+
author = {Abhisek Behera},
|
| 147 |
+
title = {Llama 3.2 3B SQL Query Generator (LoRA Fine-tuned)},
|
| 148 |
+
year = {2025},
|
| 149 |
+
publisher = {HuggingFace},
|
| 150 |
+
url = {https://huggingface.co/Abhisek987/llama-3.2-sql-lora}
|
| 151 |
+
}
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
## Acknowledgments
|
| 155 |
+
|
| 156 |
+
- Meta AI for Llama 3.2 base model
|
| 157 |
+
- Spider dataset creators
|
| 158 |
+
- HuggingFace for infrastructure
|
| 159 |
+
|
| 160 |
+
## License
|
| 161 |
+
|
| 162 |
+
This model inherits the Llama 3.2 Community License from the base model.
|
| 163 |
+
```
|
| 164 |
|
| 165 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
+
## **Step 2: Add to Settings**
|
| 168 |
|
| 169 |
+
1. **Repository Settings** → Make it **Public**
|
| 170 |
+
2. **Add topics/tags:** `llama`, `sql`, `lora`, `nlp`, `text-to-sql`
|
| 171 |
|
| 172 |
+
---
|
| 173 |
|
| 174 |
+
## **Step 3: For Your Resume**
|
| 175 |
|
| 176 |
+
Add this to your projects section:
|
| 177 |
+
```
|
| 178 |
+
🔗 Text-to-SQL Generator using Llama 3.2 (LLM Fine-tuning)
|
| 179 |
+
https://huggingface.co/Abhisek987/llama-3.2-sql-lora
|
| 180 |
|
| 181 |
+
- Fine-tuned Llama 3.2 3B model for natural language to SQL conversion using LoRA technique
|
| 182 |
+
- Achieved 85% training loss reduction (2.5 → 0.37) on Spider dataset with 7K examples
|
| 183 |
+
- Implemented 4-bit quantization (NF4) reducing model size by 75% while maintaining accuracy
|
| 184 |
+
- Trained on AWS EC2 (g5.2xlarge) with NVIDIA A10G GPU in 47 minutes
|
| 185 |
+
- Technologies: PyTorch, Transformers, PEFT, BitsAndBytes, AWS EC2
|