Air Quality SLM — v3
A ~20.4M-parameter domain-specific small language model for urban air quality telemetry, built from scratch on a Qwen3-style transformer block and served through GGUF/Ollama.
Read this first. v3 is an interface variant, not a separately trained model. It reuses the weights of the continued-training checkpoint (v2) and changes only how the prompt reaches the model: the Ollama template becomes
{{ .System }}\n{{ .Prompt }}, so a system instruction can be injected ahead of the user text. No v3-specific training run and no v3-specific evaluation exist. Every number below is a v1 or v2 measurement. v3 is therefore not claimed to be better than v2 — it was never measured against it.
1. What is in this repository
| File | Size | Role |
|---|---|---|
air_quality_slm_v3.gguf | 165,774,528 B | Primary runtime artefact (F16 GGUF). Byte-identical to the v2 GGUF it was built from. |
Modelfile | 2,383 B | Ollama definition for v3: 128-token context, greedy decoding, {{ .System }} template. |
pytorch_model.bin | 81,608,145 B | PyTorch state dict of the same checkpoint (float32). |
config.json | 438 B | Architecture and hyper-parameters, max_position_embeddings = 128. |
tokenizer.json | 11,421,892 B | Qwen2.5/Qwen3 BPE tokenizer, vocab_size = 151,665. |
tokenizer_config.json | 727 B | Tokenizer settings (`eos = < |
src/train_slm.py | 24,981 B | Original training script. Included only because it defines the custom Qwen3Model class needed to load pytorch_model.bin. |
.gitattributes | — | LFS rules for the weight files. |
FILES_AND_CHECKSUMS.md | — | Full inventory, SHA-256 of every file, and notes on deliberately excluded files. |
chat_template.jinja exists in the training directory but is deliberately not
shipped here: it is the stock Qwen2.5 ChatML template, and this model was
trained on raw instruction text, not ChatML. Applying it would push the model
off its training distribution. See §6.
2. Architecture
| Component | Value |
|---|---|
| Base family | Qwen3-style decoder block, implemented from scratch |
| Parameters | 20,397,568 unique (the state dict stores the tied embedding twice, hence 39,810,688 tensor elements) |
d_model | 128 |
| Layers | 4 |
| Attention heads | 4 query / 2 KV (grouped-query attention) |
d_ff | 512 (SwiGLU) |
| Normalisation | RMSNorm, ε = 1e-6, with QK norm |
| Positional encoding | RoPE, θ = 10,000 |
| Context window | 128 tokens |
| Weight tying | Input embedding tied to output head (out_head.weight is a copy of tok_emb.weight) |
| Vocabulary | 151,665 (Qwen2.5/Qwen3 BPE) |
| Precision | float32 (PyTorch), F16 (GGUF) |
3. Running it
3.1 Ollama (recommended, no Python code required)
# from a directory containing the .gguf and the Modelfile
ollama create air-quality-slm-v3 -f Modelfile
ollama run air-quality-slm-v3
The Modelfile sets num_ctx 128, temperature 0, top_k 1 and
num_predict 48. Greedy decoding is deliberate: it reproduces the exact text
the checkpoint emits.
3.2 llama.cpp
llama-cli -m air_quality_slm_v3.gguf -c 128 -n 48 --temp 0
3.3 PyTorch
pytorch_model.bin is a custom architecture, not a transformers model.
config.json declares model_type: air_quality_slm, so
AutoModelForCausalLM.from_pretrained(...) will not work. Load it with the
class shipped in src/train_slm.py:
import json, torch
from transformers import AutoTokenizer
from src.train_slm import Qwen3Model # requires torch, numpy, tqdm
model_dir = "."
cfg = json.load(open(f"{model_dir}/config.json"))
tok = AutoTokenizer.from_pretrained(model_dir)
model = Qwen3Model(
vocab_size=cfg["vocab_size"],
d_model=cfg["hidden_size"],
n_heads=cfg["num_attention_heads"],
n_kv_groups=cfg["num_key_value_heads"],
n_layers=cfg["num_hidden_layers"],
d_ff=cfg["intermediate_size"],
max_seq_len=cfg["max_position_embeddings"],
tie_weights=cfg.get("tie_word_embeddings", True),
)
model.load_state_dict(torch.load(f"{model_dir}/pytorch_model.bin", map_location="cpu"))
model.eval()
prompt = ("Task: Predict the absolute humidity given the following parameters: "
"Date: 11/03/2004, Time: 02.00.00, CO(GT): 0.9, NOx(GT): 45.0, NO2(GT): 60.0. "
"Response:")
ids = torch.tensor(tok.encode(prompt, add_special_tokens=False)).unsqueeze(0)
out = model.generate(ids, max_new_tokens=48, temperature=1e-5, top_k=1, repetition_penalty=1.0)
print(tok.decode(out[0].tolist())[len(prompt):].strip())
4. Training
| v1 | v2 (continued training) | |
|---|---|---|
| Steps | 150 | 1,200 |
| Block size | 64 | 128 |
| Optimiser | AdamW (β₁ 0.9, β₂ 0.95, wd 0.1, ε 1e-9) | same, continued from v1 |
| Schedule | linear warm-up → cosine decay | same, continued |
| Gradient clipping | 0.5 | 0.5 |
| Tokens seen | — | 614,400 (0.202 epoch) |
| Wall clock | 279.01 s | 1,864 s |
| Hardware | Ryzen 5 5600H, 12 logical CPUs, no CUDA | same |
| Final training loss | — | recorded in the project's evaluation artefacts |
Data: UCI Air Quality (AirQualityUCI.csv, 9,357 rows, 2004-03-10 → 2005-04-04).
Sentinel -200 values were mapped to calibrated missingness text rather than
imputed, so the model can say a value is unavailable instead of inventing one.
Training examples were rendered as plain instruction/response text — no ChatML
markers, hence the template warning in §6.
5. Evaluation (v1 and v2 only)
Measured on the held-out split; sources are the project's metrics_v*.json
and per-row evaluation files.
| Metric | v1 | v2 |
|---|---|---|
| Validation loss | 1.4252 | 0.4877 |
| Test loss | 1.4474 | 0.5555 |
| Test perplexity | 4.252 | 1.743 |
| Absolute-humidity MAE (val) | — | 0.4335 |
| Absolute-humidity MAE (test) | — | 0.5345 |
Control experiment: the closed-form humidity calculation over the same rows reaches MAE 0.02296 (val) / 0.01880 (test) — 18.9× and 28.4× lower than the model. Prediction spread is very small (standard deviation 0.000–0.003), i.e. the model's numeric output is close to constant.
Structural checks on v2 generations:
| Check | v2 |
|---|---|
| Emits EOS as trained | 1.000 |
| Correct unit string | 1.000 |
| Hallucinated date present | 0.333 |
| Distinct outputs (AH task) | 3 |
| Distinct outputs (temp/RH task) | 5 |
| Distinct outputs (pollutant task) | 1 |
Interpretation: the checkpoint is a working text generator for this domain's templates, but it is not a reliable numeric estimator. Do not use it as one.
6. Prompting format
The model expects raw instruction text ending in Response: — for example:
Task: Predict the absolute humidity given the following parameters: Date: 11/03/2004, Time: 02.00.00, CO(GT): 0.9, NOx(GT): 45.0, NO2(GT): 60.0. Response:
Do not wrap the prompt in <|im_start|>…<|im_end|> ChatML markers. The
repository intentionally omits chat_template.jinja for this reason.
The v3 template {{ .System }}\n{{ .Prompt }} prepends an optional system
instruction; when none is supplied, the prompt is unchanged from v2 and the
model behaves exactly as the v2 checkpoint does.
7. Limitations
- Numeric accuracy. Absolute-humidity error is one to two orders of magnitude worse than the closed-form formula. Values the model writes are not trustworthy measurements.
- Near-constant predictions. Low output diversity on the numeric tasks; the same inputs tend to produce the same digit strings.
- Hallucinated dates. Present in roughly one third of checked v2 generations.
- 128-token context. Long prompts are truncated; the model was not trained beyond this window.
- No v3 evaluation. v3 has never been benchmarked; its template change is untested against v2 on the evaluation set.
- Narrow domain. Trained on one Italian urban monitoring station (2004–2005) with metal-oxide sensors. Not a general air-quality model, not a forecasting model, and not calibrated for other cities or sensor hardware.
- Application caveat. In the full project application, numeric answers are computed in Python by a proxy layer around Ollama, not by this model. Text returned by that application is therefore not evidence of model capability.
8. Licence and provenance
Released under CC BY 4.0, matching the source dataset's licence terms. Tokenizer derived from Qwen2.5/Qwen3 (Apache 2.0). The dataset DOI is 10.24432/C59K5F.
Per-file SHA-256 checksums, the provenance of each binary, and the list of files
deliberately excluded from this repository are in FILES_AND_CHECKSUMS.md.