Text Generation
Transformers
Safetensors
PEFT
English
gemma3_text
LoRA
gemma
trl
sql
conversational
text-generation-inference
Instructions to use sirunchained/text-to-sql-model-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sirunchained/text-to-sql-model-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sirunchained/text-to-sql-model-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sirunchained/text-to-sql-model-v2") model = AutoModelForCausalLM.from_pretrained("sirunchained/text-to-sql-model-v2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use sirunchained/text-to-sql-model-v2 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sirunchained/text-to-sql-model-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sirunchained/text-to-sql-model-v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sirunchained/text-to-sql-model-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sirunchained/text-to-sql-model-v2
- SGLang
How to use sirunchained/text-to-sql-model-v2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "sirunchained/text-to-sql-model-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sirunchained/text-to-sql-model-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "sirunchained/text-to-sql-model-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sirunchained/text-to-sql-model-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use sirunchained/text-to-sql-model-v2 with Docker Model Runner:
docker model run hf.co/sirunchained/text-to-sql-model-v2
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
---
|
| 2 |
license: mit
|
| 3 |
datasets:
|
| 4 |
- sirunchained/text-to-sql-dataset
|
|
@@ -42,8 +41,7 @@ Converts natural language questions into SQL queries. Supports:
|
|
| 42 |
- β
`SELECT` queries (with JOINs, aggregations, subqueries)
|
| 43 |
- β
`INSERT` operations
|
| 44 |
- β
`UPDATE` operations
|
| 45 |
-
- β
`DELETE` operations
|
| 46 |
-
- β
`INVALID_QUERY` handling for non-SQL requests
|
| 47 |
|
| 48 |
---
|
| 49 |
|
|
@@ -54,8 +52,8 @@ Converts natural language questions into SQL queries. Supports:
|
|
| 54 |
| **Base Model** | `google/gemma-3-270m-it` |
|
| 55 |
| **Fine-tuning Method** | LoRA + 4-bit quantization (QLoRA) |
|
| 56 |
| **Framework** | `trl` (SFTTrainer) |
|
| 57 |
-
| **Dataset** | `sirunchained/text-to-sql-dataset` (
|
| 58 |
-
| **Training Epochs** |
|
| 59 |
| **Batch Size** | 32 |
|
| 60 |
| **Learning Rate** | 5e-5 |
|
| 61 |
| **LoRA Rank (r)** | 8 |
|
|
@@ -66,21 +64,16 @@ Converts natural language questions into SQL queries. Supports:
|
|
| 66 |
|
| 67 |
## π Training Performance
|
| 68 |
|
| 69 |
-
| Epoch | Training Loss | Validation Loss |
|
| 70 |
-
|-------|---------------|-----------------|---------
|
| 71 |
-
| 1 |
|
| 72 |
-
| 2 | 0.
|
| 73 |
-
| 3 | 0.
|
| 74 |
-
| 4 | 0.
|
| 75 |
-
| 5 | 0.
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
| 9 | 0.832 | **0.617** | 0.594 | 1,808,055 | 85.0% |
|
| 80 |
-
| 10 | 0.776 | 0.618 | 0.593 | 2,008,950 | 84.9% |
|
| 81 |
-
|
| 82 |
-
> **Best validation loss** was achieved at **epoch 9** (`0.617`).
|
| 83 |
-
> **Highest mean token accuracy** on validation was at **epoch 8** (`85.1%`).
|
| 84 |
|
| 85 |
---
|
| 86 |
|
|
@@ -135,26 +128,26 @@ The model was trained on [sirunchained/text-to-sql-dataset](https://huggingface.
|
|
| 135 |
|
| 136 |
| Split | Size |
|
| 137 |
|-------|------|
|
| 138 |
-
| Train |
|
| 139 |
-
| Validation |
|
| 140 |
-
| Test |
|
| 141 |
|
| 142 |
**Dataset format:**
|
| 143 |
- `text`: Natural language question
|
| 144 |
- `schema`: Optional database schema
|
| 145 |
-
- `query`: Target SQL query
|
| 146 |
|
| 147 |
---
|
| 148 |
|
| 149 |
## π§ͺ Evaluation Results
|
| 150 |
|
| 151 |
-
**Test Set Performance (Epoch
|
| 152 |
|
| 153 |
| Metric | Value |
|
| 154 |
|--------|-------|
|
| 155 |
-
| **Test Loss** | 0.
|
| 156 |
-
| **Mean Token Accuracy** | **
|
| 157 |
-
| **Entropy** | 0.
|
| 158 |
|
| 159 |
---
|
| 160 |
|
|
@@ -181,14 +174,14 @@ LoraConfig(
|
|
| 181 |
|
| 182 |
# Training Configuration
|
| 183 |
SFTConfig(
|
| 184 |
-
num_train_epochs=
|
| 185 |
per_device_train_batch_size=32,
|
| 186 |
learning_rate=5e-5,
|
| 187 |
-
lr_scheduler_type="
|
| 188 |
-
weight_decay=0.
|
| 189 |
load_best_model_at_end=True,
|
| 190 |
-
metric_for_best_model="
|
| 191 |
-
greater_is_better=
|
| 192 |
)
|
| 193 |
```
|
| 194 |
|
|
|
|
|
|
|
| 1 |
license: mit
|
| 2 |
datasets:
|
| 3 |
- sirunchained/text-to-sql-dataset
|
|
|
|
| 41 |
- β
`SELECT` queries (with JOINs, aggregations, subqueries)
|
| 42 |
- β
`INSERT` operations
|
| 43 |
- β
`UPDATE` operations
|
| 44 |
+
- β
`DELETE` operations (currently weak at this)
|
|
|
|
| 45 |
|
| 46 |
---
|
| 47 |
|
|
|
|
| 52 |
| **Base Model** | `google/gemma-3-270m-it` |
|
| 53 |
| **Fine-tuning Method** | LoRA + 4-bit quantization (QLoRA) |
|
| 54 |
| **Framework** | `trl` (SFTTrainer) |
|
| 55 |
+
| **Dataset** | `sirunchained/text-to-sql-dataset` (4518 samples training, 200 validation, 200 test) |
|
| 56 |
+
| **Training Epochs** | 5 |
|
| 57 |
| **Batch Size** | 32 |
|
| 58 |
| **Learning Rate** | 5e-5 |
|
| 59 |
| **LoRA Rank (r)** | 8 |
|
|
|
|
| 64 |
|
| 65 |
## π Training Performance
|
| 66 |
|
| 67 |
+
| Epoch | Training Loss | Validation Loss | Mean Token Accuracy |
|
| 68 |
+
|-------|---------------|-----------------|---------------------|
|
| 69 |
+
| 1 | 0.800 | 0.700 | 83.8% |
|
| 70 |
+
| 2 | 0.650 | 0.680 | 84.2% |
|
| 71 |
+
| 3 | 0.500 | 0.650 | 84.6% |
|
| 72 |
+
| 4 | 0.350 | **0.640** | **85.1%** |
|
| 73 |
+
| 5 | 0.550 | **0.640** | 83.5% |
|
| 74 |
+
|
| 75 |
+
> **Best validation loss** was achieved at **epoch 4 & 5** (`0.640`).
|
| 76 |
+
> **Highest mean token accuracy** on validation was at **epoch 4** (`85.1%`).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
---
|
| 79 |
|
|
|
|
| 128 |
|
| 129 |
| Split | Size |
|
| 130 |
|-------|------|
|
| 131 |
+
| Train | 4,518 samples |
|
| 132 |
+
| Validation | 200 samples |
|
| 133 |
+
| Test | 200 samples |
|
| 134 |
|
| 135 |
**Dataset format:**
|
| 136 |
- `text`: Natural language question
|
| 137 |
- `schema`: Optional database schema
|
| 138 |
+
- `query`: Target SQL query
|
| 139 |
|
| 140 |
---
|
| 141 |
|
| 142 |
## π§ͺ Evaluation Results
|
| 143 |
|
| 144 |
+
**Test Set Performance (Epoch 5 model):**
|
| 145 |
|
| 146 |
| Metric | Value |
|
| 147 |
|--------|-------|
|
| 148 |
+
| **Test Loss** | 0.638 |
|
| 149 |
+
| **Mean Token Accuracy** | **0.830** |
|
| 150 |
+
| **Entropy** | 0.636 |
|
| 151 |
|
| 152 |
---
|
| 153 |
|
|
|
|
| 174 |
|
| 175 |
# Training Configuration
|
| 176 |
SFTConfig(
|
| 177 |
+
num_train_epochs=5,
|
| 178 |
per_device_train_batch_size=32,
|
| 179 |
learning_rate=5e-5,
|
| 180 |
+
lr_scheduler_type="constant",
|
| 181 |
+
weight_decay=0.0,
|
| 182 |
load_best_model_at_end=True,
|
| 183 |
+
metric_for_best_model="mean_token_accuracy",
|
| 184 |
+
greater_is_better=True,
|
| 185 |
)
|
| 186 |
```
|
| 187 |
|