Update README.md
Browse files
README.md
CHANGED
@@ -1,210 +1,129 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
library_name: peft
|
4 |
-
pipeline_tag: text-generation
|
5 |
tags:
|
6 |
-
-
|
7 |
-
-
|
8 |
-
-
|
9 |
-
-
|
10 |
-
-
|
11 |
-
|
|
|
|
|
12 |
---
|
13 |
|
14 |
-
#
|
15 |
|
16 |
-
|
17 |
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
## Model Details
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
- **Developed by:** [More Information Needed]
|
29 |
-
- **Funded by [optional]:** [More Information Needed]
|
30 |
-
- **Shared by [optional]:** [More Information Needed]
|
31 |
-
- **Model type:** [More Information Needed]
|
32 |
-
- **Language(s) (NLP):** [More Information Needed]
|
33 |
-
- **License:** [More Information Needed]
|
34 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
35 |
-
|
36 |
-
### Model Sources [optional]
|
37 |
-
|
38 |
-
<!-- Provide the basic links for the model. -->
|
39 |
-
|
40 |
-
- **Repository:** [More Information Needed]
|
41 |
-
- **Paper [optional]:** [More Information Needed]
|
42 |
-
- **Demo [optional]:** [More Information Needed]
|
43 |
-
|
44 |
-
## Uses
|
45 |
-
|
46 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
47 |
-
|
48 |
-
### Direct Use
|
49 |
-
|
50 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
51 |
-
|
52 |
-
[More Information Needed]
|
53 |
-
|
54 |
-
### Downstream Use [optional]
|
55 |
-
|
56 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
57 |
-
|
58 |
-
[More Information Needed]
|
59 |
-
|
60 |
-
### Out-of-Scope Use
|
61 |
-
|
62 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
63 |
-
|
64 |
-
[More Information Needed]
|
65 |
-
|
66 |
-
## Bias, Risks, and Limitations
|
67 |
-
|
68 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
69 |
-
|
70 |
-
[More Information Needed]
|
71 |
-
|
72 |
-
### Recommendations
|
73 |
-
|
74 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
75 |
-
|
76 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
77 |
-
|
78 |
-
## How to Get Started with the Model
|
79 |
-
|
80 |
-
Use the code below to get started with the model.
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
## Training Details
|
85 |
-
|
86 |
-
### Training Data
|
87 |
-
|
88 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
### Training Procedure
|
93 |
|
94 |
-
|
95 |
|
96 |
-
|
|
|
|
|
97 |
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
|
|
|
|
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
|
|
|
|
106 |
|
107 |
-
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
## Evaluation
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
<!-- This should link to a Dataset Card if possible. -->
|
120 |
-
|
121 |
-
[More Information Needed]
|
122 |
-
|
123 |
-
#### Factors
|
124 |
-
|
125 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
126 |
-
|
127 |
-
[More Information Needed]
|
128 |
-
|
129 |
-
#### Metrics
|
130 |
-
|
131 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
132 |
-
|
133 |
-
[More Information Needed]
|
134 |
-
|
135 |
-
### Results
|
136 |
-
|
137 |
-
[More Information Needed]
|
138 |
-
|
139 |
-
#### Summary
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
## Model Examination [optional]
|
144 |
-
|
145 |
-
<!-- Relevant interpretability work for the model goes here -->
|
146 |
-
|
147 |
-
[More Information Needed]
|
148 |
-
|
149 |
-
## Environmental Impact
|
150 |
-
|
151 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
152 |
-
|
153 |
-
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).
|
154 |
-
|
155 |
-
- **Hardware Type:** [More Information Needed]
|
156 |
-
- **Hours used:** [More Information Needed]
|
157 |
-
- **Cloud Provider:** [More Information Needed]
|
158 |
-
- **Compute Region:** [More Information Needed]
|
159 |
-
- **Carbon Emitted:** [More Information Needed]
|
160 |
-
|
161 |
-
## Technical Specifications [optional]
|
162 |
-
|
163 |
-
### Model Architecture and Objective
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
### Compute Infrastructure
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
#### Hardware
|
172 |
-
|
173 |
-
[More Information Needed]
|
174 |
-
|
175 |
-
#### Software
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
## Citation [optional]
|
180 |
-
|
181 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
182 |
|
183 |
-
|
184 |
|
185 |
-
|
186 |
|
187 |
-
|
|
|
188 |
|
189 |
-
|
|
|
|
|
190 |
|
191 |
-
|
|
|
192 |
|
193 |
-
|
|
|
194 |
|
195 |
-
|
|
|
196 |
|
197 |
-
|
198 |
|
199 |
-
|
|
|
|
|
|
|
200 |
|
201 |
-
##
|
202 |
|
203 |
-
|
|
|
|
|
|
|
204 |
|
205 |
-
##
|
206 |
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
-
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
|
|
|
|
3 |
tags:
|
4 |
+
- text-to-sql
|
5 |
+
- llama3
|
6 |
+
- lora
|
7 |
+
- sql-generation
|
8 |
+
- code-generation
|
9 |
+
library_name: transformers
|
10 |
+
base_model: unsloth/Meta-Llama-3.1-8B
|
11 |
+
pipeline_tag: text-generation
|
12 |
---
|
13 |
|
14 |
+
# Llama3 SQL Translator
|
15 |
|
16 |
+
**Llama3 SQL Translator** is a LoRA fine-tuned version of the 8B parameter Llama 3.1 model. It is designed to translate natural language database queries into executable SQL statements and provide human-readable explanations. The model streamlines query generation for structured databases and enables non-technical users to interact with relational data more effectively.
|
17 |
|
18 |
+
## Table of Contents
|
19 |
|
20 |
+
1. [Model Details](#model-details)
|
21 |
+
2. [Intended Uses](#intended-uses)
|
22 |
+
3. [Limitations & Warnings](#limitations--warnings)
|
23 |
+
4. [Training Overview](#training-overview)
|
24 |
+
5. [Evaluation](#evaluation)
|
25 |
+
6. [Usage Example](#usage-example)
|
26 |
+
7. [Technical Specifications](#technical-specifications)
|
27 |
+
8. [Citation & Contact](#citation--contact)
|
28 |
|
29 |
## Model Details
|
30 |
|
31 |
+
- **Model Type:** Causal language model
|
32 |
+
- **Architecture:** Llama 3.1 (8B parameters)
|
33 |
+
- **Fine-Tuning Method:** Parameter-efficient fine-tuning (LoRA)
|
34 |
+
- **Base Model:** unsloth/Meta-Llama-3.1-8B
|
35 |
+
- **Language:** English
|
36 |
+
- **Tokenizer:** Llama 3 tokenizer (compatible with Meta's original)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
## Intended Uses
|
39 |
|
40 |
+
### Primary Use
|
41 |
+
- Translating natural language prompts into valid SQL queries.
|
42 |
+
- Providing explanations of the generated SQL logic.
|
43 |
|
44 |
+
### Example Input
|
45 |
+
```text
|
46 |
+
Database schema: CREATE TABLE employees (id INT, name TEXT, salary FLOAT);
|
47 |
+
Prompt: List all employees with salary over 50000.
|
48 |
+
```
|
49 |
|
50 |
+
### Example Output
|
51 |
+
```text
|
52 |
+
SQL: SELECT name FROM employees WHERE salary > 50000;
|
53 |
+
Explanation: This query retrieves all employee names where the salary is greater than 50000.
|
54 |
+
```
|
55 |
|
56 |
+
### Not Intended For
|
57 |
+
- General chat, Q&A, or non-database related tasks.
|
58 |
+
- Use without human review in critical systems or production databases.
|
59 |
|
60 |
+
## Limitations & Warnings
|
61 |
|
62 |
+
- **Schema Dependency:** The model relies heavily on accurate and complete schema descriptions.
|
63 |
+
- **SQL Safety:** The output SQL should not be executed without manual validation. Injection risks must be mitigated.
|
64 |
+
- **Complex Queries:** Deeply nested subqueries, advanced joins, or vendor-specific SQL dialects may produce suboptimal results.
|
65 |
|
66 |
+
## Training Overview
|
67 |
|
68 |
+
- The model was trained on a large-scale synthetic dataset containing pairs of natural language instructions, database schemas, corresponding SQL queries, and their step-by-step explanations. The dataset covers a wide range of relational data scenarios and query types, including filtering, aggregation, joins, and nested logic.
|
69 |
+
- Fine-tuned on a single A100 GPU using:
|
70 |
+
- `max_seq_length=1024`
|
71 |
+
- `batch_size=2`, `gradient_accumulation_steps=2`
|
72 |
+
- LoRA with 4-bit quantization
|
73 |
+
- `packing=True` to maximize throughput
|
74 |
+
- Trained for 1 epoch (~5 hours)
|
75 |
|
76 |
## Evaluation
|
77 |
|
78 |
+
| Metric | Result |
|
79 |
+
|-------------------------|----------------|
|
80 |
+
| SQL compilation success | > 95% |
|
81 |
+
| Manual output quality | ~90%+ |
|
82 |
+
| Explanation clarity | High |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
*Note: Evaluation was based on random sampling and manual review. Formal benchmarks will be added later.*
|
85 |
|
86 |
+
## Usage Example
|
87 |
|
88 |
+
```python
|
89 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
90 |
|
91 |
+
model_id = "happyhackingspace/llama3-sql-translator"
|
92 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
93 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
94 |
|
95 |
+
prompt = """Below is an instruction that describes a task, paired with an input that provides further context.
|
96 |
+
Write a response that appropriately completes the request.
|
97 |
|
98 |
+
### Instruction
|
99 |
+
Database schema: CREATE TABLE sales (id INT, product TEXT, price FLOAT);
|
100 |
|
101 |
+
### Input:
|
102 |
+
Prompt: Show all products priced over 100.
|
103 |
|
104 |
+
### Response:"""
|
105 |
|
106 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
107 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
108 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
109 |
+
```
|
110 |
|
111 |
+
## Technical Specifications
|
112 |
|
113 |
+
- **Architecture:** Llama 3.1 - 8B
|
114 |
+
- **Quantization:** 4-bit via bitsandbytes
|
115 |
+
- **Fine-tuning:** LoRA
|
116 |
+
- **Frameworks:** Transformers, TRL, PEFT, Unsloth
|
117 |
|
118 |
+
## Citation & Contact
|
119 |
|
120 |
+
```bibtex
|
121 |
+
@misc{llama3_sql_translator_2025,
|
122 |
+
title = {Llama3 SQL Translator},
|
123 |
+
author = {happyhackingspace},
|
124 |
+
year = {2025},
|
125 |
+
howpublished = {\url{https://huggingface.co/happyhackingspace/llama3-sql-translator}}
|
126 |
+
}
|
127 |
+
```
|
128 |
|
129 |
+
**Contact:** For questions or contributions, feel free to open an issue on the Hugging Face model page.
|