estu-research/sql-training-dataset
Updated • 22 • 1
How to use estu-research/gemma-7b-sql-ft with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="estu-research/gemma-7b-sql-ft") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("estu-research/gemma-7b-sql-ft", dtype="auto")How to use estu-research/gemma-7b-sql-ft with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "estu-research/gemma-7b-sql-ft"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "estu-research/gemma-7b-sql-ft",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/estu-research/gemma-7b-sql-ft
How to use estu-research/gemma-7b-sql-ft with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "estu-research/gemma-7b-sql-ft" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "estu-research/gemma-7b-sql-ft",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "estu-research/gemma-7b-sql-ft" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "estu-research/gemma-7b-sql-ft",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use estu-research/gemma-7b-sql-ft with Docker Model Runner:
docker model run hf.co/estu-research/gemma-7b-sql-ft
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("estu-research/gemma-7b-sql-ft", dtype="auto")Fine-tuned version of Google's Gemma-7B model for converting natural language questions to SQL queries.
{
"base_model": "google/gemma-7b",
"method": "LoRA",
"rank": 16,
"alpha": 32,
"dropout": 0.05,
"target_modules": ["q_proj", "k_proj", "v_proj", "o_proj"],
"epochs": 3,
"batch_size": 8,
"learning_rate": 1.5e-4,
"training_time": "10.8 hours (A100 GPU)"
}
Epoch 1: Loss 1.456 | Val Loss 1.512 | Accuracy 68.2%
Epoch 2: Loss 0.521 | Val Loss 0.589 | Accuracy 72.8%
Epoch 3: Loss 0.234 | Val Loss 0.267 | Accuracy 76.0%
pip install transformers torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("estu-research/gemma-7b-sql-ft")
tokenizer = AutoTokenizer.from_pretrained("estu-research/gemma-7b-sql-ft")
# Example query
question = """
Schema: CREATE TABLE customers (customerNumber INT, customerName VARCHAR(50), country VARCHAR(50));
Question: List all customers from France
"""
inputs = tokenizer(question, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=256)
sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(sql)
# Output: SELECT * FROM customers WHERE country = 'France';
from transformers import pipeline
pipe = pipeline("text-generation", model="estu-research/gemma-7b-sql-ft")
result = pipe(
"Schema: CREATE TABLE products (productName VARCHAR, price DECIMAL);\nQuestion: Show top 10 expensive products",
max_new_tokens=200,
temperature=0.1
)
print(result[0]['generated_text'])
| Natural Language | Generated SQL |
|---|---|
| List top 5 customers by sales | SELECT customerName, SUM(amount) as total FROM customers JOIN orders USING(customerId) GROUP BY customerId ORDER BY total DESC LIMIT 5; |
| Show products never ordered | SELECT p.productName FROM products p LEFT JOIN orderDetails od ON p.productCode = od.productCode WHERE od.productCode IS NULL; |
| Total revenue by country | SELECT country, SUM(amount) as revenue FROM customers JOIN orders USING(customerId) GROUP BY country ORDER BY revenue DESC; |
| Model | Accuracy | Latency | Cost |
|---|---|---|---|
| Gemma-7B (FT) | 76.0% | 500ms | Free |
| Llama-3-8B (FT) | 78.2% | 450ms | Free |
| GPT-4o-mini (FT) | 97.8% | 800ms | $0.30/1K |
| GPT-3.5 Turbo | 78.9% | 500ms | $0.05/1K |
@misc{gemma7b-sql-ft,
title={Gemma-7B SQL Expert: Fine-Tuned Model for Text-to-SQL},
author={Kulalı and Aydın and Alhan and Fidan},
institution={Eskisehir Technical University},
year={2024},
url={https://huggingface.co/estu-research/gemma-7b-sql-ft}
}
This work was supported by TÜBİTAK 2209-A Research Grant at Eskisehir Technical University.
MIT License - See LICENSE file for details
Base model
google/gemma-7b
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="estu-research/gemma-7b-sql-ft")