Instructions to use karthik-2905/nl2sql-pretrained with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use karthik-2905/nl2sql-pretrained with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="karthik-2905/nl2sql-pretrained")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("karthik-2905/nl2sql-pretrained", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use karthik-2905/nl2sql-pretrained with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "karthik-2905/nl2sql-pretrained" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "karthik-2905/nl2sql-pretrained", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/karthik-2905/nl2sql-pretrained
- SGLang
How to use karthik-2905/nl2sql-pretrained 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 "karthik-2905/nl2sql-pretrained" \ --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": "karthik-2905/nl2sql-pretrained", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "karthik-2905/nl2sql-pretrained" \ --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": "karthik-2905/nl2sql-pretrained", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use karthik-2905/nl2sql-pretrained with Docker Model Runner:
docker model run hf.co/karthik-2905/nl2sql-pretrained
π MySQL Query Generator - From Scratch
A state-of-the-art GPT-style transformer model trained completely from scratch for natural language to MySQL query generation. This model demonstrates that high-quality language models can be built without relying on pre-trained weights, achieving excellent performance with a compact architecture.
π― Model Overview
This model specializes in converting natural language descriptions into syntactically correct MySQL queries. It was trained entirely from scratch using a custom transformer architecture, making it highly optimized for SQL generation tasks.
Key Features
- π§ Built from Scratch: No pre-trained weights - pure end-to-end training
- πΎ Lightweight: Compact 29.8M parameters for efficient deployment
- β‘ High Performance: Excellent convergence with minimal overfitting
- π― MySQL Optimized: Specifically tuned for MySQL syntax and patterns
- π Production Ready: Robust performance across diverse query types
ποΈ Architecture
| Component | Specification |
|---|---|
| Model Type | GPT-style Transformer (Decoder-only) |
| Layers | 8 |
| Attention Heads | 8 |
| Hidden Dimensions | 512 |
| Feed Forward Size | 2048 |
| Max Sequence Length | 512 tokens |
| Dropout Rate | 0.1 |
| Total Parameters | 29,789,184 |
| Model Size | 113.6 MB |
| Vocabulary Size | 4,206 tokens |
π― Performance Metrics
| Metric | Value |
|---|---|
| Validation Loss | 0.3485 |
| Training Loss | 0.3178 |
| Perplexity | 1.42 |
| Convergence | Excellent |
| Overfitting | None detected |
π Training Configuration
- Framework: PyTorch
- Optimizer: AdamW with weight decay
- Learning Rate Scheduler: CosineAnnealingLR
- Training Epochs: 8
- Training Examples: 24,293 high-quality samples
- Hardware: NVIDIA RTX 5080 16GB
π Dataset
The model was trained on a carefully curated dataset of 24,293 high-quality examples sourced from:
- π§ Synthetic SQL Queries: Custom-generated queries covering diverse MySQL patterns
- π·οΈ Spider Dataset: Complex multi-table queries with natural language descriptions
- π WikiSQL Dataset: Real-world table-question pairs adapted for MySQL
All queries were specifically optimized for MySQL syntax and best practices, ensuring production-ready output.
π Usage
This model excels at converting natural language descriptions into syntactically correct MySQL queries. Perfect for:
- Database query assistants
- Business intelligence tools
- Educational SQL learning platforms
- Automated report generation
Example Queries
# Basic Selection
"Show me all customers from New York"
# β SELECT * FROM customers WHERE city = 'New York';
# Aggregation
"Find total sales for each product"
# β SELECT product_name, SUM(sales) FROM sales_table GROUP BY product_name;
# Conditional Filtering
"List employees with salary greater than 50000"
# β SELECT * FROM employees WHERE salary > 50000;
π Model Files
| File | Description |
|---|---|
best_pretrained_model.pt |
Optimized model checkpoint for inference |
complete_model_package.pt |
Full model package with all components |
model_info.json |
Detailed model specifications and metadata |
training_metrics.json |
Comprehensive training performance data |
SQLModel.ipynb |
Complete training and evaluation notebook |
π¬ Technical Details
Model Capabilities
- Multi-table Joins: Handles complex relationships between tables
- Aggregation Functions: SUM, COUNT, AVG, MIN, MAX operations
- Conditional Logic: WHERE clauses with AND/OR operators
- Sorting & Grouping: ORDER BY and GROUP BY operations
- Subqueries: Nested query generation for complex requirements
Limitations
- Optimized specifically for MySQL syntax (may not work with other SQL dialects)
- Best performance on queries similar to training data patterns
- May require fine-tuning for highly specialized domain vocabularies
π Citation
If you use this model in your research or applications, please cite:
@misc{mysql-query-generator-from-scratch,
title={MySQL Query Generator: A GPT-style Transformer Trained From Scratch},
author={Anonymous},
year={2025},
howpublished={\\url{https://huggingface.co/karthik-2905/nl2sql-pretrained}},
note={Natural Language to SQL Query Generation}
}
π License
This model is released under the Apache 2.0 License, allowing for both commercial and non-commercial use.
π€ Community & Support
- Open Source: Community-driven development
- Contributions Welcome: Feel free to submit improvements
- Issues & Feedback: Report problems or suggest enhancements
- Educational Use: Perfect for learning NL2SQL concepts
β If you find this model useful, please give it a star and share it with others!