File size: 2,044 Bytes
2e3758f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
language:
- en
license: mit
tags:
- text-to-sql
- t5
- nlp2sql
- agentic-ai
- postgresql
datasets:
- spider
metrics:
- accuracy
model-index:
- name: T5-NL2SQL-Gen
  results: []
---

# ๐Ÿค– T5-NL2SQL-Gen Specialist

This model is a fine-tuned **T5-Small** architecture specialized for converting Natural Language questions into precise PostgreSQL queries. It serves as the primary "Reasoning Specialist" within the **NLP2SQL Autonomous Intelligence Layer**.

## ๐Ÿš€ Model Details
- **Architecture**: T5 (Text-to-Text Transfer Transformer)
- **Specialization**: PostgreSQL Query Generation
- **Training Data**: Fine-tuned on SQL-specific datasets (Spider/WikiSQL) and custom schema-mapped samples.
- **Project Role**: Acts as the initial SQL Generator in a Hybrid Agentic loop.

## ๐Ÿ”„ Hybrid Agentic Flow
This model is designed to work in tandem with Large Language Models (like Gemini 2.0 Flash) in a structured multi-agent workflow:
1. **Local ML (T5)**: Generates the initial high-speed SQL draft.
2. **Gemini Auditor**: Validates the draft against the actual schema, adds double-quotes, and fixes hallucinations.
3. **Self-Healing Loop**: If execution fails, the agents use this model's logic to refine the plan.

## ๐Ÿ”— Project Context
This model is the engine for the **NLP2SQL Platform**.
- **GitHub Repository**: [sumit08099/NLP_SQL_GEN](https://github.com/sumit08099/NLP_SQL_GEN)
- **Frontend**: React 19 / Vite
- **Backend**: FastAPI / LangGraph

## ๐Ÿ›  Usage (Hugging Face Transformers)
```python
from transformers import T5Tokenizer, T5ForConditionalGeneration

model_name = "Karan6124/t5-nl2sql-gen"
tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)

input_text = "translate English to SQL: How many users signed up in the last 30 days? \n Context: Table users (id, username, created_at)"
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_length=512)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```