File size: 5,221 Bytes
d61c85f |
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
---
base_model: unsloth/llama-3-8B
library_name: peft
pipeline_tag: text-generation
tags:
- text-to-sql
- dpo
- lora
- transformers
- trl
- sql-generation
- database
---
# Text-to-SQL DPO Model
A Direct Preference Optimization (DPO) fine-tuned LLaMA-3-8B model specialized for text-to-SQL generation tasks. This model has been trained using LoRA (Low-Rank Adaptation) for efficient parameter-efficient fine-tuning.
## Model Details
### Model Description
This model is a fine-tuned version of LLaMA-3-8B using Direct Preference Optimization (DPO) specifically for text-to-SQL tasks. It has been trained on preference pairs to generate accurate SQL queries from natural language descriptions.
- **Developed by:** faizack
- **Model type:** Causal Language Model with LoRA adapter
- **Language(s) (NLP):** English
- **License:** Apache 2.0 (inherited from base model)
- **Finetuned from model:** unsloth/llama-3-8B
### Model Sources
- **Repository:** [Text-to-SQL DPO Repository](https://github.com/IDEAS-Incubator/text-to-sql_DPO)
- **Base Model:** [unsloth/llama-3-8B](https://huggingface.co/unsloth/llama-3-8B)
## Uses
### Direct Use
This model is designed for generating SQL queries from natural language descriptions. It can be used for:
- Converting natural language questions to SQL queries
- Database query generation
- Text-to-SQL applications
- Database interaction interfaces
### Example Usage
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load the base model and tokenizer
base_model = "unsloth/llama-3-8B"
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype=torch.float16)
# Load the LoRA adapter
model = PeftModel.from_pretrained(model, "faizack/text-to-sql-dpo")
# Generate SQL query
prompt = "Show me all users from the customers table"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=100)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```
### Out-of-Scope Use
This model should not be used for:
- General-purpose text generation beyond SQL queries
- Generating malicious or harmful SQL queries
- Database operations without proper validation
- Production use without proper testing and validation
## Bias, Risks, and Limitations
### Limitations
- The model is specialized for SQL generation and may not perform well on other tasks
- Generated SQL queries should be validated before execution
- Performance may vary depending on database schema complexity
- The model may generate queries that are syntactically correct but logically incorrect
### Recommendations
- Always validate generated SQL queries before execution
- Test the model on your specific database schema
- Use appropriate safety measures when executing generated queries
- Consider the model's limitations when integrating into production systems
## How to Get Started with the Model
### Installation
```bash
pip install transformers peft torch
```
### Quick Start
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
# Load model and adapter
base_model = "unsloth/llama-3-8B"
model = AutoModelForCausalLM.from_pretrained(base_model)
model = PeftModel.from_pretrained(model, "faizack/text-to-sql-dpo")
tokenizer = AutoTokenizer.from_pretrained(base_model)
# Generate SQL
prompt = "Find all orders placed in the last 30 days"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=150, temperature=0.1)
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(sql_query)
```
## Training Details
### Training Data
The model was trained on the `zerolink/zsql-sqlite-dpo` dataset, which contains preference pairs for text-to-SQL tasks.
### Training Procedure
#### Training Hyperparameters
- **Training regime:** DPO (Direct Preference Optimization)
- **Epochs:** 6
- **Batch size:** 2
- **Gradient accumulation:** 32
- **Learning rate:** 5e-5
- **LoRA rank:** 16
- **LoRA alpha:** 16
- **LoRA dropout:** 0.05
- **Target modules:** q_proj, v_proj
#### Training Infrastructure
- **Base model:** unsloth/llama-3-8B
- **Framework:** PEFT (Parameter-Efficient Fine-Tuning)
- **Training method:** LoRA (Low-Rank Adaptation)
- **Total steps:** 120
- **Steps per epoch:** 3660
## Technical Specifications
### Model Architecture
- **Base architecture:** LLaMA-3-8B
- **Adapter type:** LoRA
- **Trainable parameters:** ~16M (LoRA adapter only)
- **Total parameters:** ~8B (base model + adapter)
### Compute Infrastructure
- **Hardware:** GPU-based training
- **Framework versions:**
- PEFT: 0.17.1
- Transformers: 4.56.2
- PyTorch: Compatible with CUDA
## Citation
If you use this model in your research, please cite:
```bibtex
@misc{text-to-sql-dpo-2024,
title={Text-to-SQL DPO Model},
author={faizack},
year={2024},
url={https://huggingface.co/faizack/text-to-sql-dpo}
}
```
## Model Card Contact
For questions or issues related to this model, please contact the model author or open an issue in the repository.
## Framework versions
- PEFT 0.17.1
- Transformers 4.56.2 |