adiitya0929 commited on
Commit
2489cbd
·
verified ·
1 Parent(s): 1c38073

TinySQL release v1.0 (paper DOI 10.5281/zenodo.23396770)

Browse files
README.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: transformers
6
+ pipeline_tag: text-generation
7
+ base_model: adiitya0929/TinySQL-125M-base
8
+ datasets:
9
+ - Salesforce/wikisql
10
+ tags:
11
+ - text-to-sql
12
+ - sql
13
+ - wikisql
14
+ - small-language-model
15
+ - from-scratch
16
+ ---
17
+
18
+ # TinySQL-125M-WikiSQL
19
+
20
+ A 125M-parameter text-to-SQL model. Given a table schema and a question, it writes the SQL query. Every part of it was built from scratch: the tokenizer, the transformer, the optimizer, the training loop and the data pipeline. It was pretrained on 4.5B tokens on one GPU, then fine-tuned on WikiSQL.
21
+
22
+ - **Paper:** [TinySQL: A 125M-Parameter Text-to-SQL Model Built and Pretrained From Scratch on 4.5B Tokens](https://doi.org/10.5281/zenodo.23396770) (Zenodo, 2026)
23
+ - **Code:** [github.com/aditya0929/tinysql](https://github.com/aditya0929/tinysql)
24
+ - **Base model:** [adiitya0929/TinySQL-125M-base](https://huggingface.co/adiitya0929/TinySQL-125M-base)
25
+
26
+ ## Quick start
27
+
28
+ ```python
29
+ from transformers import AutoModelForCausalLM, AutoTokenizer
30
+
31
+ repo = "adiitya0929/TinySQL-125M-WikiSQL"
32
+ tok = AutoTokenizer.from_pretrained(repo)
33
+ model = AutoModelForCausalLM.from_pretrained(repo)
34
+
35
+ prompt = (
36
+ '<schema>CREATE TABLE t ("Player" TEXT, "No." TEXT, "Nationality" TEXT, "Position" TEXT, '
37
+ '"Years in Toronto" TEXT, "School/Club Team" TEXT);</schema>\n'
38
+ "<question>What position does the player who played for butler cc (ks) play?</question>\n"
39
+ "<sql>"
40
+ )
41
+ ids = tok(prompt, return_tensors="pt").input_ids
42
+ out = model.generate(ids, max_new_tokens=64) # greedy; stops at </sql>
43
+ print(tok.decode(out[0, ids.shape[1]:], skip_special_tokens=True))
44
+ # SELECT "Position" FROM t WHERE "School/Club Team" = 'butler cc (ks)';
45
+ ```
46
+
47
+ **Prompt format.** The model was trained on exactly this layout. The table is always called `t`. Column names are double-quoted, and each column is typed `REAL` (numeric) or `TEXT`. The question goes in `<question>…</question>`, and the prompt ends with `<sql>`. The model writes one `SELECT` statement and then `</sql>`.
48
+
49
+ ## Results (WikiSQL test, 15,878 questions)
50
+
51
+ | Model | Pretraining tokens | Greedy | + Schema + values constraints |
52
+ |---|---|---|---|
53
+ | **TinySQL-125M (this model, mean of 3 seeds)** | **4.5B** | **77.95 ± 0.18** | **80.39 ± 0.20** |
54
+ | GPT-2 124M | not published | 78.93 | 82.36 |
55
+ | Pythia-160M | 300B | 60.78 | 67.63 |
56
+ | SmolLM2-135M | 2T | 82.57 ± 0.37 | 85.22 ± 0.21 |
57
+ | SmolLM2-360M | 4T | 87.03 ± 0.19 | 88.01 ± 0.12 |
58
+
59
+ The table reports execution accuracy (%): the generated query is run against the table and its result compared with the gold query's. Every model was fine-tuned with the same recipe after its own learning-rate sweep. This checkpoint is seed 0, which scores 78.01 greedy and 80.44 constrained. The official WikiSQL evaluator gives 78.08 execution and 72.38 logical-form accuracy for it.
60
+
61
+ `model.generate()` above is plain greedy decoding. The constrained numbers use the grammar-constrained decoder in the [GitHub repository](https://github.com/aditya0929/tinysql) (`decode/`). It only allows the table's real column names and values copied from the question, which gives 100% valid SQL.
62
+
63
+ ## Training
64
+
65
+ | | |
66
+ |---|---|
67
+ | Architecture | Llama-style decoder: 30 layers, hidden size 576, 9 query / 3 key-value heads (GQA), SwiGLU 1536, RoPE, RMSNorm, tied embeddings, context 2048 |
68
+ | Parameters | 125,077,824 |
69
+ | Tokenizer | own byte-level BPE, 32,768 tokens |
70
+ | Pretraining | 4.51B tokens (FineWeb-Edu, The Stack SQL, Stack Exchange, Gretel synthetic text-to-SQL), 8,600 steps, about 46 h on one NVIDIA L4 |
71
+ | Fine-tuning | WikiSQL train (56,355 examples), loss on the SQL only, 3 epochs, batch 32, peak LR 5e-5, best epoch by dev execution accuracy |
72
+
73
+ The architecture matches Llama, so the weights are distributed in the standard `LlamaForCausalLM` format. The model was built and trained with the repository's own code, not with `transformers`. The export is checked to produce the same token ids, logits and generated SQL as the original implementation.
74
+
75
+ ## Limitations
76
+
77
+ - **WikiSQL shape only:** one table, one selected column, an optional aggregate, and up to four `AND` conditions. No joins, `GROUP BY`, `ORDER BY` or nesting. Do not expect it to handle Spider-style or production SQL.
78
+ - **English only;** small model; greedy decoding can produce column names that don't exist. Use the constrained decoder from the repository to rule that out.
79
+ - **Label noise:** WikiSQL's labels are noisy. A hand audit in the paper suggests that most remaining aggregation errors are label errors.
80
+ - **Not for production databases** without review: generated SQL should never be executed with write permissions.
81
+
82
+ ## Training data licenses
83
+
84
+ FineWeb-Edu (ODC-By 1.0), The Stack (dedup), SQL subset (permissively licensed source files, subject to The Stack's terms of use), Stack Exchange dba and datascience (CC BY-SA; 2.5, 3.0 or 4.0 depending on the post date), gretelai/synthetic_text_to_sql (Apache-2.0), WikiSQL (Salesforce, BSD-3-Clause). The pretraining data was decontaminated against WikiSQL dev and test questions.
85
+
86
+ ## Citation
87
+
88
+ ```bibtex
89
+ @techreport{jha2026tinysql,
90
+ title = {{TinySQL}: A 125M-Parameter Text-to-SQL Model Built and Pretrained From Scratch on 4.5B Tokens},
91
+ author = {Jha, Aditya Narayan},
92
+ year = {2026},
93
+ institution = {Zenodo},
94
+ doi = {10.5281/zenodo.23396770},
95
+ url = {https://doi.org/10.5281/zenodo.23396770}
96
+ }
97
+ ```
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 32756,
8
+ "dtype": "float32",
9
+ "eos_token_id": 32756,
10
+ "head_dim": 64,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 576,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 1536,
15
+ "max_position_embeddings": 2048,
16
+ "mlp_bias": false,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 9,
19
+ "num_hidden_layers": 30,
20
+ "num_key_value_heads": 3,
21
+ "pad_token_id": 32757,
22
+ "pretraining_tp": 1,
23
+ "rms_norm_eps": 1e-05,
24
+ "rope_parameters": {
25
+ "rope_theta": 10000.0,
26
+ "rope_type": "default"
27
+ },
28
+ "tie_word_embeddings": true,
29
+ "transformers_version": "5.19.0",
30
+ "use_cache": true,
31
+ "vocab_size": 32768
32
+ }
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 32756,
3
+ "do_sample": false,
4
+ "eos_token_id": [
5
+ 32767,
6
+ 32756
7
+ ],
8
+ "max_new_tokens": 160,
9
+ "pad_token_id": 32757,
10
+ "transformers_version": "5.19.0"
11
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23a996842298476fea097f43057bfda2d5f84ab7ba36ab75b69a86ace8a1e649
3
+ size 500341640
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|endoftext|>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "eos_token": "<|endoftext|>",
6
+ "model_max_length": 2048,
7
+ "pad_token": "<|pad|>",
8
+ "tokenizer_class": "TokenizersBackend",
9
+ "unk_token": null
10
+ }