Lesson 5 of 5 · Fine-tuning for SQL
Decide whether fine-tuning helped
Our adapter produced acceptable SQL on 198 of 200 test questions. It answered only 108 correctly. Successful execution is a useful check, but it is not the finish line.
Reload and compare under fixed conditions
Reloading in a fresh process checks that the saved files are sufficient for inference. On development data, compare the original model, the original model with three training examples in the prompt, and the model with the adapter. Use the same questions, schema information, and generation settings.
python guard.py --budget-gib 2 --log "$WIKISQL_HOME/runs/adapter-valid.log" -- \
python -u run_experiment.py eval --model "$WIKISQL_HOME/model" \
--data "$WIKISQL_HOME/data" --source "$WIKISQL_HOME/wikisql/data" \
--adapter "$WIKISQL_HOME/runs/trained" \
--out "$WIKISQL_HOME/runs/adapter-valid" --split validFor the prompting comparison, omit --adapter, add --few-shot 3, and choose a fresh output path. The three demonstrations come from training data. In our experiment, reviewing their wording improved development performance; this was a modest baseline effort, not an exhaustive search for the best prompt.
Once the recipe is fixed, --split test reproduces the published comparison. Our generations used greedy decoding and at most 128 output tokens. Because the course already exposes this test, reproducing its score does not create a new blind evaluation.
Separate usable syntax from a correct answer
Recorded experiment · These controls inspect saved outputs or illustrate the procedure. They do not run a model or train in your browser.
| Method | Accepted SQL | Correct answer |
|---|---|---|
| Original model | 61 / 200 | 3 / 200 · 1.5% |
| Three-example prompt | 178 / 200 | 11 / 200 · 5.5% |
| Fine-tuned adapter | 198 / 200 | 108 / 200 · 54% |
Exact SQL after normalization: 1/200 for the original model, 2/200 for prompting, and 96/200 for the adapter. This stricter comparison requires the query itself to match.
Adapter: 198 queries satisfy the allowed grammar, but only 108 return the reference answer. Ninety accepted queries still answer incorrectly.
The evaluator executes allowed queries against the supplied read-only database and compares answers, retaining duplicate values. Exact query agreement is stricter; different queries can have the same result. Conversely, a wrong query can get lucky on a particular table. These are local subset scores, not official full WikiSQL leaderboard results.
Inspect a failure before celebrating a percentage
For “What is the lowest game number on 20 July 2008?”, the reference uses the complete date:
SELECT MIN(col0) FROM data WHERE col1 = '20 july 2008';The adapter instead produced:
SELECT MIN(col0) FROM data WHERE col1 = 'july 2008';It dropped the day, found no matching row, and returned null instead of 1. The query has valid columns and syntax. It is still wrong. This is a selected development example; the aggregate test reports both successes and failures.
Avoid teaching to the benchmark
Training on WikiSQL's official training split is legitimate. It teaches both useful mappings and benchmark conventions such as lowercase literals and column IDs. The gain does not establish a comparable improvement on a company's database, and we cannot rule out WikiSQL appearing in the base model's pretraining.
Keep further tuning on development data. Do not repeatedly adjust prompts, epochs, or filtering in response to the published test score. Treat that test as historical evidence once it guides your decisions.
For a new transfer claim, reserve a small, independently reviewed set of questions against fresh tables before choosing the next recipe. Include paraphrases, reordered columns, dates, several filters, and count-versus-value questions. Keep related variants together in one split. Keep answers behind the final evaluator and report failures rather than dropping them. That independent challenge evaluation has not been run here.
A few dozen challenge questions can expose weaknesses; they cannot certify production reliability. Stronger claims need more representative data, uncertainty estimates, duplicate checks, and repeated training runs. Unsupported joins should be treated separately from the single-table task rather than silently changing what the score means.
Make a decision from the evidence you have
For this narrow lab, the adapter improves held-out answer agreement substantially, takes a short local training run, and leaves meaningful errors. It is useful for learning SFT and testing further ideas. The evidence does not justify executing its outputs against a business database without review.
A practical report includes the base model and data revisions, split rules, prompt attempts, training settings, answer scores, examples of failures, timing, and memory. Compare a stronger prompt or simple input normalization on development data before deciding that more training is the next investment.
Download the source and recorded results, or read the complete measured report. The records preserve the initial unsuccessful prompting attempt as well as the final comparison.
Your turn
Explain it in your own words.
The adapter produces accepted SQL on 99% of our test questions but correct answers on 54%. A teammate says this proves it is ready for a different company’s database. What does the gap show, and what additional check would you want before making that transfer claim?
Answer the question in your own words. A short explanation is enough.
Your feedback
Work through a hint
Hint 1
Could a valid query select the wrong date or column?
Hint 2
Does a WikiSQL question represent the new database’s actual requests?
A worked explanation
The gap shows that valid SQL can answer the wrong question. Reserve representative new-table questions outside training and tuning to check transfer.
Sources and further reading
WikiSQL dataset and evaluation rules · MLX-LM training guide · Training, validation, and test sets · Our source and experiment record