faizack commited on
Commit
d61c85f
·
verified ·
1 Parent(s): 7a30765

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +187 -0
README.md ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: unsloth/llama-3-8B
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - text-to-sql
7
+ - dpo
8
+ - lora
9
+ - transformers
10
+ - trl
11
+ - sql-generation
12
+ - database
13
+ ---
14
+
15
+ # Text-to-SQL DPO Model
16
+
17
+ 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.
18
+
19
+ ## Model Details
20
+
21
+ ### Model Description
22
+
23
+ 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.
24
+
25
+ - **Developed by:** faizack
26
+ - **Model type:** Causal Language Model with LoRA adapter
27
+ - **Language(s) (NLP):** English
28
+ - **License:** Apache 2.0 (inherited from base model)
29
+ - **Finetuned from model:** unsloth/llama-3-8B
30
+
31
+ ### Model Sources
32
+
33
+ - **Repository:** [Text-to-SQL DPO Repository](https://github.com/IDEAS-Incubator/text-to-sql_DPO)
34
+ - **Base Model:** [unsloth/llama-3-8B](https://huggingface.co/unsloth/llama-3-8B)
35
+
36
+ ## Uses
37
+
38
+ ### Direct Use
39
+
40
+ This model is designed for generating SQL queries from natural language descriptions. It can be used for:
41
+
42
+ - Converting natural language questions to SQL queries
43
+ - Database query generation
44
+ - Text-to-SQL applications
45
+ - Database interaction interfaces
46
+
47
+ ### Example Usage
48
+
49
+ ```python
50
+ from transformers import AutoTokenizer, AutoModelForCausalLM
51
+ from peft import PeftModel
52
+ import torch
53
+
54
+ # Load the base model and tokenizer
55
+ base_model = "unsloth/llama-3-8B"
56
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
57
+ model = AutoModelForCausalLM.from_pretrained(base_model, torch_dtype=torch.float16)
58
+
59
+ # Load the LoRA adapter
60
+ model = PeftModel.from_pretrained(model, "faizack/text-to-sql-dpo")
61
+
62
+ # Generate SQL query
63
+ prompt = "Show me all users from the customers table"
64
+ inputs = tokenizer(prompt, return_tensors="pt")
65
+ outputs = model.generate(**inputs, max_length=100)
66
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
67
+ print(response)
68
+ ```
69
+
70
+ ### Out-of-Scope Use
71
+
72
+ This model should not be used for:
73
+ - General-purpose text generation beyond SQL queries
74
+ - Generating malicious or harmful SQL queries
75
+ - Database operations without proper validation
76
+ - Production use without proper testing and validation
77
+
78
+ ## Bias, Risks, and Limitations
79
+
80
+ ### Limitations
81
+
82
+ - The model is specialized for SQL generation and may not perform well on other tasks
83
+ - Generated SQL queries should be validated before execution
84
+ - Performance may vary depending on database schema complexity
85
+ - The model may generate queries that are syntactically correct but logically incorrect
86
+
87
+ ### Recommendations
88
+
89
+ - Always validate generated SQL queries before execution
90
+ - Test the model on your specific database schema
91
+ - Use appropriate safety measures when executing generated queries
92
+ - Consider the model's limitations when integrating into production systems
93
+
94
+ ## How to Get Started with the Model
95
+
96
+ ### Installation
97
+
98
+ ```bash
99
+ pip install transformers peft torch
100
+ ```
101
+
102
+ ### Quick Start
103
+
104
+ ```python
105
+ from transformers import AutoTokenizer, AutoModelForCausalLM
106
+ from peft import PeftModel
107
+
108
+ # Load model and adapter
109
+ base_model = "unsloth/llama-3-8B"
110
+ model = AutoModelForCausalLM.from_pretrained(base_model)
111
+ model = PeftModel.from_pretrained(model, "faizack/text-to-sql-dpo")
112
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
113
+
114
+ # Generate SQL
115
+ prompt = "Find all orders placed in the last 30 days"
116
+ inputs = tokenizer(prompt, return_tensors="pt")
117
+ outputs = model.generate(**inputs, max_length=150, temperature=0.1)
118
+ sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
119
+ print(sql_query)
120
+ ```
121
+
122
+ ## Training Details
123
+
124
+ ### Training Data
125
+
126
+ The model was trained on the `zerolink/zsql-sqlite-dpo` dataset, which contains preference pairs for text-to-SQL tasks.
127
+
128
+ ### Training Procedure
129
+
130
+ #### Training Hyperparameters
131
+
132
+ - **Training regime:** DPO (Direct Preference Optimization)
133
+ - **Epochs:** 6
134
+ - **Batch size:** 2
135
+ - **Gradient accumulation:** 32
136
+ - **Learning rate:** 5e-5
137
+ - **LoRA rank:** 16
138
+ - **LoRA alpha:** 16
139
+ - **LoRA dropout:** 0.05
140
+ - **Target modules:** q_proj, v_proj
141
+
142
+ #### Training Infrastructure
143
+
144
+ - **Base model:** unsloth/llama-3-8B
145
+ - **Framework:** PEFT (Parameter-Efficient Fine-Tuning)
146
+ - **Training method:** LoRA (Low-Rank Adaptation)
147
+ - **Total steps:** 120
148
+ - **Steps per epoch:** 3660
149
+
150
+ ## Technical Specifications
151
+
152
+ ### Model Architecture
153
+
154
+ - **Base architecture:** LLaMA-3-8B
155
+ - **Adapter type:** LoRA
156
+ - **Trainable parameters:** ~16M (LoRA adapter only)
157
+ - **Total parameters:** ~8B (base model + adapter)
158
+
159
+ ### Compute Infrastructure
160
+
161
+ - **Hardware:** GPU-based training
162
+ - **Framework versions:**
163
+ - PEFT: 0.17.1
164
+ - Transformers: 4.56.2
165
+ - PyTorch: Compatible with CUDA
166
+
167
+ ## Citation
168
+
169
+ If you use this model in your research, please cite:
170
+
171
+ ```bibtex
172
+ @misc{text-to-sql-dpo-2024,
173
+ title={Text-to-SQL DPO Model},
174
+ author={faizack},
175
+ year={2024},
176
+ url={https://huggingface.co/faizack/text-to-sql-dpo}
177
+ }
178
+ ```
179
+
180
+ ## Model Card Contact
181
+
182
+ For questions or issues related to this model, please contact the model author or open an issue in the repository.
183
+
184
+ ## Framework versions
185
+
186
+ - PEFT 0.17.1
187
+ - Transformers 4.56.2