Kasualdad commited on
Commit
bd6bcca
·
verified ·
1 Parent(s): 43746c5

migrate: copy README.md from build-small-hackathon

Browse files
Files changed (1) hide show
  1. README.md +226 -0
README.md ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: unsloth/qwen2.5-coder-14b-instruct-bnb-4bit
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:unsloth/qwen2.5-coder-14b-instruct-bnb-4bit
7
+ - lora
8
+ - sft
9
+ - transformers
10
+ - trl
11
+ - unsloth
12
+ - text-to-sql
13
+ - education
14
+ - local-first
15
+ ---
16
+
17
+ # LFED SQL Assistant — Qwen2.5-Coder-14B-LoRA
18
+
19
+ A LoRA adapter that turns plain-English school-data questions into read-only DuckDB SQL queries. Built for the **Local First Education Data Framework (LFED)**, a local-first analytics assistant for school administrators.
20
+
21
+ - **Live demo:** https://huggingface.co/spaces/build-small-hackathon/Kasualdad_LFED
22
+ - **GGUF (local/llama.cpp):** https://huggingface.co/build-small-hackathon/lfed-qwen2.5-coder-14b-sql-gguf
23
+ - **Project:** https://huggingface.co/spaces/build-small-hackathon/Kasualdad_LFED
24
+
25
+ ---
26
+
27
+ ## Model Details
28
+
29
+ - **Developer:** build-small-hackathon (HF Build Small Hackathon, Chapter One: Backyard AI)
30
+ - **Base model:** [`unsloth/qwen2.5-coder-14b-instruct-bnb-4bit`](https://huggingface.co/unsloth/qwen2.5-coder-14b-instruct-bnb-4bit)
31
+ - **Model type:** Causal LM, text-to-SQL, instruction-tuned
32
+ - **Language:** English (questions and SQL)
33
+ - **License:** Apache 2.0
34
+ - **Fine-tuning method:** Unsloth QLoRA (r=32, α=32, target modules `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`)
35
+ - **Training data:** 27,859 synthetic NL→SQL pairs over a 5-table education schema
36
+ - **Adapter size:** ~551 MB
37
+ - **Framework versions:** PEFT 0.19.1, transformers, Unsloth, TRL
38
+
39
+ ---
40
+
41
+ ## Intended Use
42
+
43
+ This adapter is designed for a single downstream task: **converting natural-language questions about school data into safe, read-only SQL**.
44
+
45
+ ### Direct use
46
+ - Drop the adapter onto the base model for inference in the LFED Gradio app.
47
+ - Run locally with the matching GGUF or with `transformers + PEFT`.
48
+
49
+ ### Suitable questions
50
+ - "How many students were chronically absent at Lincoln Elementary in 2023-2024?"
51
+ - "What is the suspension rate by race/ethnicity at Washington Middle?"
52
+ - "Show the average GPA for English learners vs non-English learners."
53
+ - "Which school has the highest enrollment growth since 2021?"
54
+
55
+ ### Out-of-scope use
56
+ - Not a general chatbot or coding assistant.
57
+ - Not trained on real student PII; the demo uses synthetic seed data only.
58
+ - Not suitable for arbitrary SQL dialects beyond DuckDB-compatible queries.
59
+ - Should not be used for write operations; the execution guard allows only `SELECT` statements.
60
+
61
+ ---
62
+
63
+ ## Training Details
64
+
65
+ ### Training data
66
+
67
+ - **Source:** synthetic data generated from hand-written templates, augmented with Gretel, and rephrased for natural-language variety.
68
+ - **Schema:** 5 tables — `students`, `enrollment`, `attendance`, `discipline`, `grades`.
69
+ - **Coverage:** single-table aggregations, joins, filtering by school/year/grade, subgroup comparisons, ranking, and simple rates/percentages.
70
+ - **Size:** 27,859 question→SQL pairs.
71
+ - **Format:** each example contains a `question` and a `sql` field.
72
+ - **Data generation scripts:** `modal_train/generate_synthetic_v2.py`, `modal_train/augment_gretel.py`, `modal_train/rephrase_pairs.py` in the project repo.
73
+
74
+ ### Training procedure
75
+
76
+ | Setting | Value |
77
+ |---|---|
78
+ | Optimizer | AdamW (Unsloth default) |
79
+ | Learning rate | 1e-4 |
80
+ | LR scheduler | cosine |
81
+ | Warmup steps | 10 |
82
+ | Batch size | 4 |
83
+ | Gradient accumulation | 4 |
84
+ | Epochs | 2 |
85
+ | LoRA r | 32 |
86
+ | LoRA α | 32 |
87
+ | LoRA dropout | 0 |
88
+ | Target modules | all linear layers |
89
+ | Quantization | 4-bit (bnb NF4) |
90
+ | Max sequence length | 2048 |
91
+ | Trainer | SFTTrainer (TRL) |
92
+ | Packing | False |
93
+ | Hardware | Modal A10G |
94
+
95
+ Training completed on 2026-06-10.
96
+
97
+ ### Outputs
98
+
99
+ | Artifact | Location |
100
+ |---|---|
101
+ | This LoRA adapter | `build-small-hackathon/lfed-qwen2.5-coder-14b-sql-lora` |
102
+ | Merged GGUF Q4_K_M | `build-small-hackathon/lfed-qwen2.5-coder-14b-sql-gguf` |
103
+ | Training code | `modal_train/` in the LFED project repo |
104
+
105
+ ---
106
+
107
+ ## Evaluation
108
+
109
+ ### Approach
110
+
111
+ Evaluation is currently manual: a bank of 15 real-world-style queries spanning attendance, discipline, grades, enrollment, and equity comparisons is run through the LFED demo UI. Each query is scored on:
112
+
113
+ 1. Correctness — does the answer match the expected aggregation/join?
114
+ 2. SQL quality — is the generated SQL valid, safe, and readable?
115
+ 3. UX — is the summary + table useful?
116
+ 4. Latency — does the query complete within a reasonable time?
117
+
118
+ ### Known limitations
119
+
120
+ - The model is fine-tuned on synthetic data; real-world schema variations require additional prompting or fine-tuning.
121
+ - It occasionally needs explicit school name and school year in the question to produce the most reliable query.
122
+ - Complex multi-step reasoning (e.g., "students who improved GPA across consecutive years") can be brittle.
123
+ - Percentage/rate formatting is handled by the downstream app, not the model; the model may return either 0–1 proportions or already-scaled percentages.
124
+ - No formal academic benchmark evaluation has been run.
125
+
126
+ ---
127
+
128
+ ## How to Use
129
+
130
+ ### With transformers + PEFT (HF Space path)
131
+
132
+ ```python
133
+ import torch
134
+ from transformers import AutoModelForCausalLM, AutoTokenizer
135
+ from peft import PeftModel
136
+
137
+ base_id = "unsloth/qwen2.5-coder-14b-instruct-bnb-4bit"
138
+ adapter_id = "build-small-hackathon/lfed-qwen2.5-coder-14b-sql-lora"
139
+
140
+ tokenizer = AutoTokenizer.from_pretrained(base_id)
141
+ model = AutoModelForCausalLM.from_pretrained(
142
+ base_id,
143
+ torch_dtype=torch.float16,
144
+ device_map="auto",
145
+ )
146
+ model = PeftModel.from_pretrained(model, adapter_id, torch_device="cpu")
147
+
148
+ prompt = """You are an assistant that converts school-data questions into DuckDB SQL.
149
+ Schema:
150
+ - students(student_id, school_name, grade_level, gender, race_ethnicity, english_learner, special_education, economically_disadvantaged)
151
+ - attendance(student_id, school_name, school_year, absence_count, is_chronically_absent)
152
+
153
+ Question: How many chronically absent students at Lincoln Elementary in 2023-2024?
154
+ SQL:"""
155
+
156
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
157
+ outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.0)
158
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
159
+ ```
160
+
161
+ ### With llama.cpp (local-first path)
162
+
163
+ Use the matching GGUF:
164
+
165
+ ```bash
166
+ llama-cli \
167
+ -m lfed-qwen2.5-coder-14b-sql-gguf/ggml-model-q4_k_m.gguf \
168
+ -p "Question: How many chronically absent students at Lincoln Elementary in 2023-2024?\nSQL:" \
169
+ -n 128 --temp 0.0
170
+ ```
171
+
172
+ Or run the full LFED app locally:
173
+
174
+ ```bash
175
+ git checkout -b product local-llamacpp-v1
176
+ python3.12 -m venv .venv && source .venv/bin/activate
177
+ pip install -r requirements.txt
178
+ python app.py
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Bias, Risks, and Limitations
184
+
185
+ - **Synthetic data:** the training data is generated from templates and rephrased. Demographic patterns in the seed data do not represent any real population; they exist to exercise joins and filters.
186
+ - **No PII handling training:** the model has no special safeguards around personally identifiable information because the schema uses anonymized `student_id`s only.
187
+ - **Read-only enforcement is app-level:** the adapter itself will emit any SQL-like text; the downstream `data_engine.py` validator enforces `SELECT`-only and forbidden-token rules.
188
+ - **Hallucinated columns/tables:** the model may occasionally reference a plausible-sounding column that does not exist. The execution guard catches these via schema-aware `EXPLAIN` validation.
189
+ - **Numeric accuracy:** the model writes the SQL; percentage interpretation depends on the application layer. Users should verify rates and percentages against their own conventions.
190
+
191
+ ---
192
+
193
+ ## Environmental Impact
194
+
195
+ Estimated training energy use on a Modal A10G for ~2 epochs:
196
+
197
+ - **Hardware type:** NVIDIA A10G
198
+ - **Training time:** approximately 1–2 hours
199
+ - **Cloud provider:** Modal
200
+ - **Region:** likely US-east (Modal default)
201
+ - **Carbon emitted:** not precisely measured; rough estimate using [ML CO2 Impact calculator](https://mlco2.github.io/impact#compute) is on the order of tens to low-hundreds of grams of CO2eq.
202
+
203
+ ---
204
+
205
+ ## Citation
206
+
207
+ If you use this model, please cite the base model and the LFED project:
208
+
209
+ **BibTeX:**
210
+ ```bibtex
211
+ @misc{lfed_sql_adapter,
212
+ title={Local First Education Data Framework: A Qwen2.5-Coder-14B LoRA Adapter for School-Data Text-to-SQL},
213
+ author={build-small-hackathon},
214
+ year={2026},
215
+ howpublished={\url{https://huggingface.co/build-small-hackathon/lfed-qwen2.5-coder-14b-sql-lora}}
216
+ }
217
+ ```
218
+
219
+ **APA:**
220
+ build-small-hackathon. (2026). *Local First Education Data Framework: A Qwen2.5-Coder-14B LoRA adapter for school-data text-to-SQL*. Hugging Face. https://huggingface.co/build-small-hackathon/lfed-qwen2.5-coder-14b-sql-lora
221
+
222
+ ---
223
+
224
+ ## Framework versions
225
+
226
+ - PEFT 0.19.1