text2text-generation Β· text Β· WASM Β· ~80 MB
This is a small encoder-decoder (T5-small, ~60M) fine-tuned for one job:
writing SQL from a database schema and a plain-language question. Unlike a general
text model, it is schema-conditioned β you paste your CREATE TABLE statements
in front of the question, and the model grounds its query in your columns and table names.
The decoder writes the SELECT one token at a time; watch it stream. Nothing leaves your
device.
Calibrate expectations: at 60M params it is genuinely good at single-table filters, counts,
GROUP BY aggregations, and simple joins over a schema you give it β and it will
sometimes get complex multi-join logic wrong. The page shows the real generated SQL, correct or not,
never a canned answer. Always review generated SQL before running it against a real database.
| Model | Xenova/t5-small-awesome-text-to-sql (ONNX of cssupport/t5-small-awesome-text-to-sql) |
|---|---|
| Task / pipeline | text2text-generation (sequence-to-sequence) |
| Architecture | T5-small encoder-decoder (~60M params) β encoder reads schema + question, decoder writes SQL |
| Training | Fine-tuned on b-mc2/sql-create-context + Clinton/Text-to-sql-v1 β schema-grounded NLβSQL pairs |
| Input format | tables:\n<CREATE TABLE β¦>\nquery for:<question> β the schema is the conditioning |
| Quantization | q8 (8-bit) ONNX β encoder + merged decoder |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~80 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers, Clipboard β all Baseline widely available |
Paste your schema (one or more CREATE TABLE statements), ask a question in
plain English, and hit Generate. The schema plus the question is what conditions the model β change
the schema and the same question produces different SQL.
There is no hidden prompt engineering. The model was trained on one exact shape: the word
tables:, your CREATE TABLE lines, then query for: and the
question. Below, the schema conditioning is dimmed and the
question
is highlighted, so you can see exactly how the schema steers the query. Then the encoder's tokens
(T5 uses SentencePiece β a leading Β· marks a word boundary) and the decoder's real
per-token timeline.
Exact input string fed to the encoder:
Input tokens (SentencePiece):
Per-token decode timeline (ms per token):
Natural-language querying is one of the most-requested database features, and it usually means shipping every schema and question to a cloud LLM. An 80 MB model in a tab does the common cases privately, offline, and for free β the schema and the question never leave the device.
One schema, many questions β feel how a plain-English question becomes SQL.
A query console over a fixed schema: ask, get copyable SQL, run it against an in-browser database and see rows.
Push it: multi-table joins, aggregations, and nested subqueries β find where a 60M model shines and where it breaks.
The full loop: question β SQL β run it in SQLite β FLAN-T5 answers in plain English. Two models plus a database.
The whole task lives in the input string β the schema is the conditioning, no template roles:
import { pipeline } from "@huggingface/transformers";
const text2sql = await pipeline(
"text2text-generation",
"Xenova/t5-small-awesome-text-to-sql",
); // downloads + caches ~80 MB once
// paste the schema in front of the question β this exact shape is what it was trained on:
const prompt =
"tables:\n" +
"CREATE TABLE students (student_id INT, name VARCHAR, gpa FLOAT);" +
" CREATE TABLE attendance (student_id INT, course_id INT)\n" +
"query for:List the names of students who never attended a course.";
await text2sql(prompt, { max_new_tokens: 128 });
// β [{ generated_text: "SELECT name FROM students WHERE NOT student_id IN
// (SELECT student_id FROM attendance)" }]
For the live token stream and the decode timeline, this page passes a TextStreamer so it
can timestamp each generated token β all inside a Web Worker so the UI never janks.