adiitya0929 commited on
Commit
bd44341
·
verified ·
1 Parent(s): dea98fd

List the other checkpoints

Browse files
Files changed (1) hide show
  1. README.md +115 -99
README.md CHANGED
@@ -1,99 +1,115 @@
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
- - **feel free to contact me at** - https://www.linkedin.com/in/aditya-narayan-jha-36193a251/
27
-
28
- ## Quick start
29
-
30
- ```python
31
- from transformers import AutoModelForCausalLM, AutoTokenizer
32
-
33
- repo = "adiitya0929/TinySQL-125M-WikiSQL"
34
- tok = AutoTokenizer.from_pretrained(repo)
35
- model = AutoModelForCausalLM.from_pretrained(repo)
36
-
37
- prompt = (
38
- '<schema>CREATE TABLE t ("Player" TEXT, "No." TEXT, "Nationality" TEXT, "Position" TEXT, '
39
- '"Years in Toronto" TEXT, "School/Club Team" TEXT);</schema>\n'
40
- "<question>What position does the player who played for butler cc (ks) play?</question>\n"
41
- "<sql>"
42
- )
43
- ids = tok(prompt, return_tensors="pt").input_ids
44
- out = model.generate(ids, max_new_tokens=64) # greedy; stops at </sql>
45
- print(tok.decode(out[0, ids.shape[1]:], skip_special_tokens=True))
46
- # SELECT "Position" FROM t WHERE "School/Club Team" = 'butler cc (ks)';
47
- ```
48
-
49
- **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>`.
50
-
51
- ## Results (WikiSQL test, 15,878 questions)
52
-
53
- | Model | Pretraining tokens | Greedy | + Schema + values constraints |
54
- |---|---|---|---|
55
- | **TinySQL-125M (this model, mean of 3 seeds)** | **4.5B** | **77.95 ± 0.18** | **80.39 ± 0.20** |
56
- | GPT-2 124M | not published | 78.93 | 82.36 |
57
- | Pythia-160M | 300B | 60.78 | 67.63 |
58
- | SmolLM2-135M | 2T | 82.57 ± 0.37 | 85.22 ± 0.21 |
59
- | SmolLM2-360M | 4T | 87.03 ± 0.19 | 88.01 ± 0.12 |
60
-
61
- 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.
62
-
63
- `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.
64
-
65
- ## Training
66
-
67
- | | |
68
- |---|---|
69
- | Architecture | Llama-style decoder: 30 layers, hidden size 576, 9 query / 3 key-value heads (GQA), SwiGLU 1536, RoPE, RMSNorm, tied embeddings, context 2048 |
70
- | Parameters | 125,077,824 |
71
- | Tokenizer | own byte-level BPE, 32,768 tokens |
72
- | 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 |
73
- | 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 |
74
-
75
- 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.
76
-
77
- ## Limitations
78
-
79
- - **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.
80
- - **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.
81
- - **Label noise:** WikiSQL's labels are noisy. A hand audit in the paper suggests that most remaining aggregation errors are label errors.
82
- - **Not for production databases** without review: generated SQL should never be executed with write permissions.
83
-
84
- ## Training data licenses
85
-
86
- 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.
87
-
88
- ## Citation
89
-
90
- ```bibtex
91
- @techreport{jha2026tinysql,
92
- title = {{TinySQL}: A 125M-Parameter Text-to-SQL Model Built and Pretrained From Scratch on 4.5B Tokens},
93
- author = {Jha, Aditya Narayan},
94
- year = {2026},
95
- institution = {Zenodo},
96
- doi = {10.5281/zenodo.23396770},
97
- url = {https://doi.org/10.5281/zenodo.23396770}
98
- }
99
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ![TinySQL vs similar-sized models: WikiSQL test accuracy against pretraining data](https://raw.githubusercontent.com/aditya0929/tinysql/main/docs/linkedin/1_accuracy_vs_pretraining_data.png)
64
+
65
+ ![What the grammar check (constrained decoding) adds for each model](https://raw.githubusercontent.com/aditya0929/tinysql/main/docs/linkedin/3_grammar_check_gains.png)
66
+
67
+ ## Training
68
+
69
+ | | |
70
+ |---|---|
71
+ | Architecture | Llama-style decoder: 30 layers, hidden size 576, 9 query / 3 key-value heads (GQA), SwiGLU 1536, RoPE, RMSNorm, tied embeddings, context 2048 |
72
+ | Parameters | 125,077,824 |
73
+ | Tokenizer | own byte-level BPE, 32,768 tokens |
74
+ | 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 |
75
+ | 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 |
76
+
77
+ ![TinySQL-125M architecture: decoder block, grouped-query attention and parameter budget](https://raw.githubusercontent.com/aditya0929/tinysql/main/docs/linkedin/4_architecture.png)
78
+
79
+ ![Pretraining: training loss, validation loss by source, learning rate and gradient norm](https://raw.githubusercontent.com/aditya0929/tinysql/main/docs/linkedin/2_pretraining_curves.png)
80
+
81
+ 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.
82
+
83
+ ## Other checkpoints
84
+
85
+ | Where | What |
86
+ |---|---|
87
+ | Branch [`lr1e-4-seed0`](https://huggingface.co/adiitya0929/TinySQL-125M-WikiSQL/tree/lr1e-4-seed0) | Learning-rate sweep run, LR 1e-4, seed 0 (dev only: 78.46% greedy, 81.46% constrained). Load with `revision="lr1e-4-seed0"` |
88
+ | [GitHub release v1.0](https://github.com/aditya0929/tinysql/releases/tag/v1.0) | This model and the base model in the repository's own checkpoint format, for its evaluation and constrained-decoding code |
89
+ | [adiitya0929/SmolLM2-135M-WikiSQL-baseline](https://huggingface.co/adiitya0929/SmolLM2-135M-WikiSQL-baseline), [adiitya0929/SmolLM2-360M-WikiSQL-baseline](https://huggingface.co/adiitya0929/SmolLM2-360M-WikiSQL-baseline) | The SmolLM2 baselines, fine-tuned with the same recipe |
90
+
91
+ The weights of seeds 1 and 2 and of the other baselines' test runs were not kept.
92
+
93
+ ## Limitations
94
+
95
+ - **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.
96
+ - **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.
97
+ - **Label noise:** WikiSQL's labels are noisy. A hand audit in the paper suggests that most remaining aggregation errors are label errors.
98
+ - **Not for production databases** without review: generated SQL should never be executed with write permissions.
99
+
100
+ ## Training data licenses
101
+
102
+ 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.
103
+
104
+ ## Citation
105
+
106
+ ```bibtex
107
+ @techreport{jha2026tinysql,
108
+ title = {{TinySQL}: A 125M-Parameter Text-to-SQL Model Built and Pretrained From Scratch on 4.5B Tokens},
109
+ author = {Jha, Aditya Narayan},
110
+ year = {2026},
111
+ institution = {Zenodo},
112
+ doi = {10.5281/zenodo.23396770},
113
+ url = {https://doi.org/10.5281/zenodo.23396770}
114
+ }
115
+ ```