Update README.md
Browse files
README.md
CHANGED
|
@@ -1,208 +1,149 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
tags:
|
| 6 |
-
- base_model:adapter:unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit
|
| 7 |
-
- lora
|
| 8 |
-
- transformers
|
| 9 |
- unsloth
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
|
|
|
| 11 |
|
| 12 |
-
# Model
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
### Model Description
|
| 21 |
-
|
| 22 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
- **Developed by:** [More Information Needed]
|
| 27 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 28 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 29 |
-
- **Model type:** [More Information Needed]
|
| 30 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 31 |
-
- **License:** [More Information Needed]
|
| 32 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 33 |
-
|
| 34 |
-
### Model Sources [optional]
|
| 35 |
-
|
| 36 |
-
<!-- Provide the basic links for the model. -->
|
| 37 |
-
|
| 38 |
-
- **Repository:** [More Information Needed]
|
| 39 |
-
- **Paper [optional]:** [More Information Needed]
|
| 40 |
-
- **Demo [optional]:** [More Information Needed]
|
| 41 |
-
|
| 42 |
-
## Uses
|
| 43 |
-
|
| 44 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 45 |
-
|
| 46 |
-
### Direct Use
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Downstream Use [optional]
|
| 53 |
-
|
| 54 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
### Out-of-Scope Use
|
| 59 |
-
|
| 60 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
## Bias, Risks, and Limitations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 67 |
-
|
| 68 |
-
[More Information Needed]
|
| 69 |
-
|
| 70 |
-
### Recommendations
|
| 71 |
-
|
| 72 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 73 |
-
|
| 74 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 75 |
-
|
| 76 |
-
## How to Get Started with the Model
|
| 77 |
-
|
| 78 |
-
Use the code below to get started with the model.
|
| 79 |
-
|
| 80 |
-
[More Information Needed]
|
| 81 |
-
|
| 82 |
-
## Training Details
|
| 83 |
-
|
| 84 |
-
### Training Data
|
| 85 |
-
|
| 86 |
-
<!-- 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. -->
|
| 87 |
-
|
| 88 |
-
[More Information Needed]
|
| 89 |
-
|
| 90 |
-
### Training Procedure
|
| 91 |
-
|
| 92 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 93 |
-
|
| 94 |
-
#### Preprocessing [optional]
|
| 95 |
-
|
| 96 |
-
[More Information Needed]
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
#### Training Hyperparameters
|
| 100 |
-
|
| 101 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 102 |
-
|
| 103 |
-
#### Speeds, Sizes, Times [optional]
|
| 104 |
-
|
| 105 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 106 |
-
|
| 107 |
-
[More Information Needed]
|
| 108 |
-
|
| 109 |
-
## Evaluation
|
| 110 |
-
|
| 111 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 112 |
-
|
| 113 |
-
### Testing Data, Factors & Metrics
|
| 114 |
-
|
| 115 |
-
#### Testing Data
|
| 116 |
-
|
| 117 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Factors
|
| 122 |
-
|
| 123 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
#### Metrics
|
| 128 |
-
|
| 129 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 130 |
-
|
| 131 |
-
[More Information Needed]
|
| 132 |
-
|
| 133 |
-
### Results
|
| 134 |
-
|
| 135 |
-
[More Information Needed]
|
| 136 |
-
|
| 137 |
-
#### Summary
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
## Model Examination [optional]
|
| 142 |
-
|
| 143 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
-
|
| 152 |
|
| 153 |
-
|
| 154 |
-
- **Hours used:** [More Information Needed]
|
| 155 |
-
- **Cloud Provider:** [More Information Needed]
|
| 156 |
-
- **Compute Region:** [More Information Needed]
|
| 157 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 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 |
-
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
|
| 194 |
|
| 195 |
-
##
|
|
|
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
##
|
|
|
|
| 200 |
|
| 201 |
-
|
|
|
|
| 202 |
|
| 203 |
-
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
datasets:
|
| 3 |
+
- xlangai/spider
|
| 4 |
+
base_model:
|
| 5 |
+
- Qwen/Qwen3-4B-Instruct-2507
|
| 6 |
tags:
|
|
|
|
|
|
|
|
|
|
| 7 |
- unsloth
|
| 8 |
+
- text-to-sql
|
| 9 |
+
- fine-tuning
|
| 10 |
+
- trl
|
| 11 |
---
|
| 12 |
+
# Qwen3-4B NL → SQL (Spider Fine-Tuned)
|
| 13 |
|
| 14 |
+
## Model Overview
|
| 15 |
|
| 16 |
+
- **Model name:** qwen3-4b-nl2sql
|
| 17 |
+
- **Base model:** Qwen/Qwen3-4B-Instruct-2507
|
| 18 |
+
- **Model type:** Decoder-only Transformer (Causal Language Model)
|
| 19 |
+
- **Task:** Natural Language → SQL Query Generation
|
| 20 |
+
- **Language:** English
|
| 21 |
+
- **License:** Apache-2.0
|
| 22 |
+
- **Author:** Neeharika
|
| 23 |
|
| 24 |
+
> ✅ This repository contains **merged model weights** and can be used directly with
|
| 25 |
+
> `AutoModelForCausalLM.from_pretrained`.
|
| 26 |
|
| 27 |
+
This model is a fine-tuned version of Qwen3-4B, optimized to translate natural language questions into executable SQL queries using database schema context. It is designed for structured data querying and analytics use cases rather than open-ended conversation.
|
| 28 |
|
| 29 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
## Intended Use
|
| 32 |
|
| 33 |
+
### Primary Use Cases
|
| 34 |
+
- Natural language interfaces for SQL databases
|
| 35 |
+
- Backend services that auto-generate SQL
|
| 36 |
+
- Data analytics assistants
|
| 37 |
+
- Research in semantic parsing and text-to-SQL
|
| 38 |
|
| 39 |
+
### Out-of-Scope Uses
|
| 40 |
+
- General-purpose chatbots
|
| 41 |
+
- Code generation beyond SQL
|
| 42 |
+
- Autonomous decision-making in high-risk domains (medical, legal, financial)
|
| 43 |
|
| 44 |
+
---
|
| 45 |
|
| 46 |
+
## Training Data
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
### Dataset
|
| 49 |
+
- **Name:** Spider Dataset
|
| 50 |
+
- **Type:** Public benchmark for cross-domain text-to-SQL tasks
|
| 51 |
+
- **Domains:** Multiple real-world databases with diverse schemas
|
| 52 |
+
- **Size:** ~7k–10k question–SQL pairs (after preprocessing)
|
| 53 |
|
| 54 |
+
### Data Characteristics
|
| 55 |
+
- Multi-table joins
|
| 56 |
+
- Nested and correlated subqueries
|
| 57 |
+
- Aggregations (COUNT, AVG, SUM, GROUP BY, HAVING)
|
| 58 |
+
- Schema-dependent reasoning
|
| 59 |
|
| 60 |
+
### Preprocessing
|
| 61 |
+
- Converted samples into instruction-style format
|
| 62 |
+
- Injected full database schema into prompts
|
| 63 |
+
- Cleaned malformed or ambiguous samples
|
| 64 |
+
- Normalized SQL formatting
|
| 65 |
|
| 66 |
+
---
|
| 67 |
|
| 68 |
+
## Prompt Format
|
| 69 |
|
| 70 |
+
The model was trained using schema-aware instruction prompts:
|
| 71 |
+
```
|
| 72 |
+
### Instruction:
|
| 73 |
+
Convert the question into an SQL query.
|
| 74 |
|
| 75 |
+
### Database Schema:
|
| 76 |
+
<Table and column definitions>
|
| 77 |
|
| 78 |
+
### Question:
|
| 79 |
+
<User query>
|
| 80 |
|
| 81 |
+
### SQL:
|
| 82 |
+
```
|
| 83 |
|
| 84 |
+
## Training Procedure
|
| 85 |
|
| 86 |
+
### Frameworks & Libraries
|
| 87 |
+
- Hugging Face Transformers
|
| 88 |
+
- Hugging Face TRL (Supervised Fine-Tuning)
|
| 89 |
+
- Unsloth (memory-efficient training)
|
| 90 |
+
- PyTorch
|
| 91 |
|
| 92 |
+
### Fine-Tuning Details
|
| 93 |
+
- **Method:** Supervised Fine-Tuning (SFT)
|
| 94 |
+
- **Quantization during training:** 4-bit (bnb)
|
| 95 |
+
- **Precision:** Mixed precision
|
| 96 |
+
- **Optimization:** LoRA adapters (merged post-training)
|
| 97 |
|
| 98 |
+
### Key Hyperparameters
|
| 99 |
+
- Max sequence length: 2048
|
| 100 |
+
- Learning rate: 2e-4
|
| 101 |
+
- Optimizer: AdamW
|
| 102 |
+
- Padding: Right-padding
|
| 103 |
+
- Gradient checkpointing: Enabled
|
| 104 |
|
| 105 |
+
---
|
| 106 |
|
| 107 |
+
## Example Usage
|
| 108 |
|
| 109 |
+
```python
|
| 110 |
+
from unsloth import FastLanguageModel
|
| 111 |
+
import torch
|
| 112 |
|
| 113 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 114 |
+
model_name="Neeharika20/qwen3-4b-nl2sql",
|
| 115 |
+
max_seq_length=2048,
|
| 116 |
+
load_in_4bit=True,
|
| 117 |
+
device_map="auto",
|
| 118 |
+
)
|
| 119 |
|
| 120 |
+
model.eval()
|
| 121 |
|
| 122 |
+
prompt = """### Instruction:
|
| 123 |
+
Convert the question into an SQL query.
|
| 124 |
|
| 125 |
+
### Database Schema:
|
| 126 |
+
CREATE TABLE students(
|
| 127 |
+
id INT,
|
| 128 |
+
name TEXT,
|
| 129 |
+
age INT
|
| 130 |
+
);
|
| 131 |
|
| 132 |
+
### Question:
|
| 133 |
+
List the names of all students.
|
| 134 |
|
| 135 |
+
### SQL:
|
| 136 |
+
"""
|
| 137 |
|
| 138 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 139 |
|
| 140 |
+
with torch.no_grad():
|
| 141 |
+
outputs = model.generate(
|
| 142 |
+
**inputs,
|
| 143 |
+
max_new_tokens=64,
|
| 144 |
+
temperature=0.2,
|
| 145 |
+
do_sample=False,
|
| 146 |
+
)
|
| 147 |
|
| 148 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 149 |
+
```
|