AuricErgeson/Antelope-textTosql
122
๐ฆ Antelope Text-to-SQL
Convert plain English questions into SQL queries instantly. Lightweight, fast, and runs on CPU. No database expertise needed.
๐ [Try the live demo โ](https://huggingface.co/spaces/AuricErgeson/Antelope-textTosql-demo)
What it does
Quick Start
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "AuricErgeson/Antelope-textTosql"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True
)
def generate_sql(question, db=""):
prompt = (
f"### Task: Convert question to SQL. Use only what the question asks. Simple questions need simple SQL.\n"
f"### Database: {db}\n"
f"### Question: {question}\n"
f"### SQL:"
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(
**inputs,
max_new_tokens=128,
temperature=0.1,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
decoded = tokenizer.decode(out[0], skip_special_tokens=True)
return decoded.split("### SQL:")[-1].strip().split("\n")[0]
print(generate_sql("How many employees are in each department?", db="company"))
# โ SELECT department, COUNT(*) FROM employees GROUP BY departmentWhy use this model?
- โ Small โ 2.7B params, runs on modest hardware
- โ Fast โ CPU inference possible, GPU recommended
- โ Open โ MIT license, use anywhere
- โ
No setup โ works out of the box with
transformers - โ Cross-domain โ trained on 200+ database schemas
Prompt Format
### Task: Convert question to SQL. Use only what the question asks. Simple questions need simple SQL.
### Database: {your_database_name}
### Question: {your_question}
### SQL:Via HuggingFace Inference API
import requests
API_URL = "https://api-inference.huggingface.co/models/AuricErgeson/Antelope-textTosql"
headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
response = requests.post(API_URL, headers=headers, json={
"inputs": "### Task: Convert question to SQL. Use only what the question asks. Simple questions need simple SQL.\n### Database: company\n### Question: How many employees?\n### SQL:"
})
print(response.json())Training Details
Limitations
- Not recommended for production databases without output validation
- Complex multi-join queries may be inaccurate
- Does not infer table/column names โ provide your database name for best results
Roadmap
- [x] Text-to-SQL (this model)
- [ ] Text-to-Regex (coming soon)
- [ ] Text-to-Shell (planned)
Author
Auric Ergeson Nitonde ๐ง auricergesonnitonde@gmail.com ๐ค HuggingFace Profile
If this model helped you, consider leaving a like โญ โ it helps others find it.
