Text Generation
Transformers
PyTorch
English
sql
mysql
transformer
gpt
from-scratch
nl2sql
natural-language-to-sql
query-generation
Run this model with HF Jobs
Run karthik-2905/nl2sql-pretrained on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/karthik-2905/nl2sql-pretrained. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/karthik-2905/nl2sql-pretrained on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/karthik-2905/nl2sql-pretrained. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/karthik-2905/nl2sql-pretrained. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("karthik-2905/nl2sql-pretrained", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- 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
Upload README_HF.md with huggingface_hub
Browse files9 unmodified lines1011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051069 unmodified lines- gpt- from-scratch- pytorchlibrary_name: transformerspipeline_tag: text-generation---# MySQL Query Generator - From ScratchThis is a GPT-style transformer model trained completely from scratch for MySQL query generation. The model demonstrates that effective language models can be built without relying on pre-trained weights.## Model Details- **Model Type**: GPT-style Transformer (Decoder-only)- **Architecture**: Custom from-scratch implementation- **Training**: No pre-trained weights used- **Language**: English (Natural Language to SQL)- **License**: Apache 2.0## Architecture| Parameter | Value ||-----------|-------|| Layers | 8 || Attention Heads | 8 || Hidden Size | 512 || Feed Forward Size | 2048 || Max Sequence Length | 512 || Dropout | 0.1 || Total Parameters | 29,789,184 || Model Size | 113.6 MB |## Training Details- **Training Time**: 12 minutes- **Hardware**: RTX 5080 16GB- **Framework**: PyTorch- **Optimizer**: AdamW- **Scheduler**: CosineAnnealingLR- **Epochs**: 8- **Dataset Size**: 24,293 examples## Performance- **Final Validation Loss**: 0.3485- **Final Training Loss**: 0.3178- **Final Perplexity**: 1.42- **Convergence**: Excellent- **Overfitting**: None detected## DatasetThe model was trained on a diverse dataset of 24,293 examples from:- Synthetic SQL queries- Spider dataset- WikiSQL datasetAll queries were optimized for MySQL syntax and patterns.## UsageThis model is designed for natural language to SQL query generation, specifically optimized for MySQL databases.```python# Example usage (implementation depends on your inference setup)input_text = "Show me all customers from New York"# Model would generate: SELECT * FROM customers WHERE city = 'New York';```## Files- `best_pretrained_model.pt`: Best model checkpoint- `complete_model_package.pt`: Full model package with all components- `model_info.json`: Detailed model specifications- `training_metrics.json`: Training performance data- `SQLModel.ipynb`: Complete training notebook## CitationIf you use this model in your research, please cite:```bibtex@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}}}```## LicenseThis model is released under the Apache 2.0 license.## ContactOpen source community project. Feel free to contribute or report issues.9 unmodified lines1011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601619 unmodified lines- gpt- from-scratch- pytorch- nl2sql- natural-language-to-sql- query-generationlibrary_name: transformerspipeline_tag: text-generationwidget:- text: "Show me all customers from New York"example_title: "Customer Query"- text: "Find total sales for each product"example_title: "Aggregate Query"- text: "List employees with salary greater than 50000"example_title: "Conditional Query"---# π MySQL Query Generator - From ScratchA 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 OverviewThis 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## π DatasetThe 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 MySQLAll queries were specifically optimized for MySQL syntax and best practices, ensuring production-ready output.## π UsageThis 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```python# 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## π CitationIf you use this model in your research or applications, please cite:```bibtex@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}}```## π LicenseThis 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!**
README_HF.md+111-56