jk200201 commited on
Commit
6b3e8be
·
verified ·
1 Parent(s): 08b418a

Switch demo to bird-cot CoT model, add sqlite upload + reasoning, honest numbers

Browse files
Files changed (1) hide show
  1. README.md +53 -39
README.md CHANGED
@@ -5,24 +5,27 @@ app_file: app.py
5
  license: apache-2.0
6
  colorFrom: blue
7
  colorTo: green
8
- pinned: false
9
  ---
10
 
11
  # LocalSQL
12
 
13
  Ask a SQLite database questions in plain English.
14
 
15
- LocalSQL is a small, open text-to-SQL tool built around fine-tuned
16
- Qwen2.5-Coder-7B LoRA adapters. The default adapter reached **78.2% result
17
- accuracy on Spider V1 dev**, beating the Grok-4 and DeepSeek-V3 baselines used
18
- to build its preference data.
 
 
 
19
 
20
  The product goal is simple:
21
 
22
  - **Local mode:** run the model on your own GPU, point it at your own `.sqlite`
23
  file, and keep your data on your machine.
24
- - **Demo mode:** run the same model in a hosted Gradio app against sample
25
- data so people can try it without setup.
26
 
27
  ```bash
28
  python3 -m src.text2sql --db chinook.sqlite --q "Which 5 artists have the most albums?"
@@ -48,17 +51,19 @@ Results
48
 
49
  Most text-to-SQL tools are cloud wrappers: send schema plus question to a large
50
  API model, pay per request, and trust the remote provider with your database
51
- structure. LocalSQL explores the opposite path: a specialized 7B model that can
52
- run locally and still compete with much larger frontier models on SQL tasks.
 
 
53
 
54
  ## Models
55
 
56
- | Adapter | Best For | Notes |
57
  |---|---|---|
58
- | `jk200201/qwen2.5-coder-7b-sql-dpo` | Spider-style/general SQLite questions | Default. 78.2% on Spider V1 dev. |
59
- | `jk200201/qwen2.5-coder-7b-bird-dpo` | Messier schemas plus domain hints | Better for BIRD-style questions with `--evidence`. |
60
 
61
- Both adapters sit on top of `Qwen/Qwen2.5-Coder-7B-Instruct`.
62
 
63
  ## Install
64
 
@@ -79,18 +84,20 @@ python3 -m src.text2sql \
79
  --db mydata.sqlite \
80
  --q "top 5 customers by revenue"
81
 
82
- # Generate SQL only.
83
  python3 -m src.text2sql \
84
  --db mydata.sqlite \
85
  --q "total revenue per month in 2023" \
86
  --no-exec
87
 
88
- # Use the BIRD adapter with a domain hint.
89
  python3 -m src.text2sql \
90
  --db mydata.sqlite \
91
- --adapter jk200201/qwen2.5-coder-7b-bird-dpo \
92
  --evidence "revenue = price * quantity" \
93
  --q "revenue by month"
 
 
 
94
  ```
95
 
96
  As a library:
@@ -98,59 +105,66 @@ As a library:
98
  ```python
99
  from src.text2sql import load_model, predict
100
 
101
- model, tokenizer = load_model()
102
  result = predict("mydata.sqlite", "top 5 customers by revenue", model, tokenizer)
103
  print(result["sql"])
 
104
  print(result["rows"])
105
  ```
106
 
107
  ## Hosted Demo
108
 
109
- This repo includes a minimal Gradio app:
110
 
111
  ```bash
112
  python3 app.py
113
  ```
114
 
115
- The public Space runs against a generated sample SQLite database. For private
116
- databases, run the CLI locally so your schema and rows stay on your machine.
 
 
117
 
118
  ## Research Snapshot
119
 
120
- The training recipe is the interesting part:
121
-
122
- 1. Run two frontier models on a SQL benchmark.
123
- 2. Execute their SQL against the benchmark database.
124
- 3. Where one model is right and the other wrong, turn that disagreement into a
125
- DPO preference pair.
126
- 4. SFT a 7B model on gold SQL, then DPO on the generated preference pairs.
127
 
128
- Spider V1 dev:
129
 
130
- | Model | Result Accuracy |
131
- |---|---:|
132
- | LocalSQL Spider adapter | **78.2%** |
133
- | Grok-4 baseline | 73.7% |
134
- | DeepSeek-V3 baseline | 71.8% |
 
 
135
 
136
  For the broader experiment log, see `docs/research/`.
137
 
 
 
 
 
 
 
138
  ## Roadmap
139
 
140
- - Hosted Hugging Face Space with sample SQLite databases.
141
- - High-accuracy mode using Best-of-N execution self-consistency.
142
  - Schema search/linking for large databases.
143
  - Postgres and MySQL connectors.
144
- - Publish a clean BIRD CoT-SFT adapter if the 58.5% result is fully packaged and
145
- reproducible.
146
 
147
  ## Citation
148
 
149
  ```bibtex
150
  @misc{kothari2026localsql,
151
  author = {Kothari, Jenish},
152
- title = {LocalSQL: A Local Text-to-SQL Model Trained with Frontier-Disagreement DPO},
153
  year = {2026},
154
- howpublished = {\url{https://huggingface.co/jk200201/qwen2.5-coder-7b-sql-dpo}},
155
  }
156
  ```
 
5
  license: apache-2.0
6
  colorFrom: blue
7
  colorTo: green
8
+ pinned: true
9
  ---
10
 
11
  # LocalSQL
12
 
13
  Ask a SQLite database questions in plain English.
14
 
15
+ LocalSQL is a small, open text-to-SQL tool built around a fine-tuned
16
+ Qwen2.5-Coder-7B model. It reasons step by step over the schema, writes the SQL,
17
+ and runs it read-only against your database. The default model,
18
+ [`jk200201/qwen2.5-coder-7b-bird-cot`](https://huggingface.co/jk200201/qwen2.5-coder-7b-bird-cot),
19
+ scores **52.1%** greedy and **58.5%** with self-consistency (K=8) on the BIRD
20
+ dev split, matching DeepSeek V4-Pro (58.7%, 1.6T params) at roughly 0.4% of the
21
+ size.
22
 
23
  The product goal is simple:
24
 
25
  - **Local mode:** run the model on your own GPU, point it at your own `.sqlite`
26
  file, and keep your data on your machine.
27
+ - **Demo mode:** run the same model in a hosted Gradio app against sample data,
28
+ or upload your own `.sqlite` file to try it without any setup.
29
 
30
  ```bash
31
  python3 -m src.text2sql --db chinook.sqlite --q "Which 5 artists have the most albums?"
 
51
 
52
  Most text-to-SQL tools are cloud wrappers: send schema plus question to a large
53
  API model, pay per request, and trust the remote provider with your database
54
+ structure. LocalSQL explores the opposite path: a specialized 7B model that runs
55
+ locally and still competes with much larger frontier models on SQL tasks. With
56
+ self-consistency it reaches the accuracy of a 1.6T frontier model while keeping
57
+ your schema and rows on your own machine.
58
 
59
  ## Models
60
 
61
+ | Model | Best For | Notes |
62
  |---|---|---|
63
+ | `jk200201/qwen2.5-coder-7b-bird-cot` | General SQLite questions, messy schemas | Default. Merged CoT model. 52.1% greedy / 58.5% self-consistency on BIRD dev. |
64
+ | `jk200201/qwen2.5-coder-7b-bird-cot-GGUF` | Running on a laptop (Ollama / llama.cpp) | Quantized builds (Q4_K_M is 4.4 GB). `ollama run muence/bird-cot`. |
65
 
66
+ The model was trained on top of `Qwen/Qwen2.5-Coder-7B-Instruct`.
67
 
68
  ## Install
69
 
 
84
  --db mydata.sqlite \
85
  --q "top 5 customers by revenue"
86
 
87
+ # Generate SQL only (no execution).
88
  python3 -m src.text2sql \
89
  --db mydata.sqlite \
90
  --q "total revenue per month in 2023" \
91
  --no-exec
92
 
93
+ # Add a domain hint for questions that need external knowledge.
94
  python3 -m src.text2sql \
95
  --db mydata.sqlite \
 
96
  --evidence "revenue = price * quantity" \
97
  --q "revenue by month"
98
+
99
+ # Skip reasoning and use the direct-SQL prompt (faster, usually less accurate).
100
+ python3 -m src.text2sql --db mydata.sqlite --q "top 5 customers" --direct
101
  ```
102
 
103
  As a library:
 
105
  ```python
106
  from src.text2sql import load_model, predict
107
 
108
+ model, tokenizer = load_model() # loads the merged CoT model
109
  result = predict("mydata.sqlite", "top 5 customers by revenue", model, tokenizer)
110
  print(result["sql"])
111
+ print(result["reasoning"]) # the step-by-step chain of thought
112
  print(result["rows"])
113
  ```
114
 
115
  ## Hosted Demo
116
 
117
+ This repo includes a Gradio app:
118
 
119
  ```bash
120
  python3 app.py
121
  ```
122
 
123
+ The public Space runs against a generated sample SQLite database, and you can
124
+ upload your own `.sqlite` file to try it on real data. Uploaded files are used
125
+ only for the current query and are not stored. For fully private use, run the
126
+ CLI locally so your schema and rows never leave your machine.
127
 
128
  ## Research Snapshot
129
 
130
+ The training recipe is the interesting part. The current best model is a
131
+ chain-of-thought SFT: distil step-by-step SQL reasoning from a strong teacher on
132
+ the BIRD train split, keep only the correct chains, and fine-tune the 7B on
133
+ them. It is then evaluated on the held-out BIRD dev split.
 
 
 
134
 
135
+ BIRD dev (execution accuracy):
136
 
137
+ | Model | Params | Result Accuracy |
138
+ |---|---:|---:|
139
+ | Qwen2.5-Coder-7B base | 7B | 27.0% |
140
+ | LocalSQL, greedy | 7B | 52.1% |
141
+ | LocalSQL, self-consistency (K=8) | 7B | 58.5% |
142
+ | DeepSeek V4-Pro | 1.6T | 58.7% |
143
+ | GLM 5.2 | 744B | 63.0% |
144
 
145
  For the broader experiment log, see `docs/research/`.
146
 
147
+ > **Note on an earlier number.** A previous version of this project reported
148
+ > 78.2% on Spider dev for a DPO model. That evaluation was later found to be
149
+ > train/test contaminated (the DPO preference pairs were built from the same
150
+ > dev split used for scoring), so that number has been retired. The BIRD results
151
+ > above use a clean train/dev split.
152
+
153
  ## Roadmap
154
 
155
+ - Keep the hosted Space warm and let users upload their own SQLite files.
156
+ - High-accuracy mode using Best-of-N execution self-consistency in the demo.
157
  - Schema search/linking for large databases.
158
  - Postgres and MySQL connectors.
159
+ - On-policy RL (GRPO / rejection fine-tuning) to push past 58.5%.
 
160
 
161
  ## Citation
162
 
163
  ```bibtex
164
  @misc{kothari2026localsql,
165
  author = {Kothari, Jenish},
166
+ title = {LocalSQL: A Local Chain-of-Thought Text-to-SQL Model},
167
  year = {2026},
168
+ howpublished = {\url{https://huggingface.co/jk200201/qwen2.5-coder-7b-bird-cot}},
169
  }
170
  ```