File size: 3,351 Bytes
554cbec 7f807b9 6b91fa1 1da4546 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 7f807b9 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 0318d07 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 6b91fa1 554cbec 0f3cfc9 554cbec 6b91fa1 554cbec 0f3cfc9 554cbec 0595245 554cbec 0f3cfc9 3307fa1 554cbec 6b91fa1 554cbec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 73 74 75 76 77 78 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
---
base_model: unsloth/Llama-3.2-1B-Instruct
library_name: peft
license: llama3.2
datasets:
- gretelai/synthetic_text_to_sql
language:
- en
pipeline_tag: text2text-generation
tags:
- SQL
- Text-to-SQL
- SQL-generation
---
# Model Card for Llama3.2-SQL-1B
## Model Details
This model is a fine-tuned version of Llama3.2-1B-Instruct, optimized for text-to-SQL generation tasks.
It was trained on the **gretelai/synthetic_text_to_sql** dataset, which contains synthetic natural language questions and their corresponding SQL queries across a variety of domains.
The model learns to:
- Understand natural language instructions.
- Generate syntactically correct and context-aware SQL queries.
- Interpret structured schema information when included in the prompt.
### Model Description
- **Developed by:** Rustam Shiriyev
- **Model type:** Instruction-tuned model on Text2SQL data
- **Language(s) (NLP):** English
- **License:** Llama3.2
- **Finetuned from model:** unsloth/Llama3.2-1B-Instruct
## Uses
### Direct Use
- Natural Language to SQL translation
- Educational or research applications
- Lightweight inference for SQL query generation on small-scale tasks or apps
## Bias, Risks, and Limitations
- May not handle deeply nested or complex joins in SQL.
## How to Get Started with the Model
```python
from huggingface_hub import login
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
login(token="")
tokenizer = AutoTokenizer.from_pretrained("unsloth/Llama3.2-1B-Instruct",)
base_model = AutoModelForCausalLM.from_pretrained(
"unsloth/Llama3.2-1B-Instruct",
device_map={"": 0}, token=""
)
model = PeftModel.from_pretrained(base_model,"Rustamshry/Llama3.2-SQL-1B")
question = "What are the vehicle safety testing organizations that operate in the UK and France?"
context =
"""
CREATE TABLE SafetyOrgs (name VARCHAR(20), country VARCHAR(10));
INSERT INTO SafetyOrgs (name, country) VALUES ('Euro NCAP', 'UK');
INSERT INTO SafetyOrgs (name, country) VALUES ('ADAC', 'Germany');
INSERT INTO SafetyOrgs (name, country) VALUES ('UTAC', 'France');
"""
instruction = (
"You are a skilled SQL assistant."
"Using the given database context, generate the correct SQL query to answer the question.\n\n"
f"Context: {context.strip()}"
)
prompt = (
f"### Instruction:\n{instruction}\n\n"
f"### Question:\n{question}\n\n"
f"### Response:\n"
)
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**input_ids,
max_new_tokens=2048
)
print(tokenizer.decode(outputs[0]),skip_special_tokens=True)
```
## Training Details
### Training Data
- **Dataset**: gretelai/synthetic_text_to_sql which consists of 100,000 synthetic examples of natural language questions paired with corresponding SQL queries and explanations.
### Training Procedure
The model was fine-tuned using the Unsloth and LoRA.
- LoRA rank: 8
- Aplha: 16
#### Training Hyperparameters
- batch size:8,
- gradient accumulation steps:4,
- optimizer:adamw_torch,
- learning rate:2e-5,
- warmup_steps:100,
- fp16:True,
- epochs:2,
- weight_decay:0.01,
- lr_scheduler_type:linear
#### Speeds, Sizes, Times [optional]
- Training time: 8 hour
- Speed: 0.22 steps/sec
### Results
- Final Loss: 1.42 >> 0.48
### Framework versions
- PEFT 0.14.0 |