--- license: apache-2.0 base_model: Qwen/Qwen3.5-0.8B library_name: mlx pipeline_tag: text-generation language: - en datasets: - xlangai/spider tags: - text-to-sql - sql - sqlite - lora - mlx - distillation - grpo model-index: - name: qwen3.5-0.8b-spider-sql-lora results: - task: type: text-generation name: Text-to-SQL dataset: name: Spider 1.0 (dev) type: xlangai/spider split: validation metrics: - type: accuracy value: 71.9 name: Execution accuracy (official test-suite-sql-eval rules) --- # Qwen3.5-0.8B Spider SQL (LoRA adapter) A LoRA adapter that teaches [Qwen/Qwen3.5-0.8B](https://huggingface.co/Qwen/Qwen3.5-0.8B) to turn plain-English questions about a SQLite database into SQL. It was trained by distillation from a large teacher, DeepSeek V4 Flash, and then with reinforcement learning, on one Mac. It is the final model of the Let's Data Science course [Model Distillation: Teach a Small Model to Write SQL](https://letsdatascience.com/learn/model-distillation). Every step that produced it, and every number below, can be rebuilt with the open project [lets-data-science/distillation-lab](https://github.com/lets-data-science/distillation-lab). The adapter is in [MLX](https://github.com/ml-explore/mlx) format, for Apple-silicon Macs. ## Results Spider 1.0 dev set: 1,034 questions on 20 databases that none of the training questions use. One answer per question with greedy decoding. Graded by running the SQL, with the default rules of Spider's official checker, [test-suite-sql-eval](https://github.com/taoyds/test-suite-sql-eval): DISTINCT is deleted from both queries, columns may come in any order, duplicate rows count, and row order counts when the gold query has ORDER BY. "Lenient" is the same set of rows with columns in order. | Model | Official | 95% interval | Lenient | |---|---|---|---| | Qwen3.5-0.8B, no training | 35.7% | 32.8–38.6% | 35.2% | | Qwen3.5-2B, no training | 56.8% | 53.8–59.8% | 54.2% | | Qwen3.5-0.8B + LoRA on the teacher's checked answers | 64.0% | 61.1–66.9% | 61.7% | | **Qwen3.5-0.8B + LoRA + reinforcement learning (this adapter)** | **71.9%** | 69.1–74.6% | 68.4% | | DeepSeek V4 Flash (the teacher) | 80.8% | 78.3–83.2% | 76.9% | | Qwen3.6-35B-A3B, 4-bit | 82.6% | 80.3–84.9% | 79.1% | Reinforcement learning added 7.8 points to the distilled student: 118 questions gained against 37 lost (exact McNemar test, p < 0.0001). Intervals are 95% bootstrap intervals over the test questions; they do not cover training randomness (retraining the distilled student with another seed moved it from 64.0% to 65.0%). ## How to use The easiest way is the project's `ask.py`, which builds exactly the prompt the model was trained on, runs the generated SQL read-only on your database and prints the rows: ```bash git clone https://github.com/lets-data-science/distillation-lab cd distillation-lab make setup # Python environment (needs uv) uv run hf download Qwen/Qwen3.5-0.8B --local-dir models/base/Qwen3.5-0.8B uv run hf download letsdatascience/qwen3.5-0.8b-spider-sql-lora --local-dir models/adapters/final scripts/download_data.sh spider # the Spider databases, about 206 MB uv run python scripts/ask.py --db data/spider/database/concert_singer/concert_singer.sqlite \ "Which singers are older than 40?" ``` To call it from your own code with `mlx-lm`, give it the same prompt it was trained on: a fixed system line, then the database's `CREATE TABLE` statements with three example rows per table, the question, and a format line. Turn Qwen3.5's thinking mode off. ```python from mlx_lm import load, generate model, tokenizer = load("Qwen/Qwen3.5-0.8B", adapter_path="models/adapters/final") system = "You are an expert in SQLite. Given a database schema and a question, write one SQLite query that answers it." schema = "..." # CREATE TABLE statements, each followed by /* Example rows from