singhpratech commited on
Commit
59cd30b
·
verified ·
1 Parent(s): 9083cb6

Add RESULTS.md

Browse files
Files changed (1) hide show
  1. RESULTS.md +36 -41
RESULTS.md CHANGED
@@ -1,57 +1,52 @@
1
  # Lesson 07 RESULTS: tiny transformer decider (pankh-decider-v0)
2
 
3
- Run: 2026-10-11, Apple M4 Max, PyTorch 2.14.1, device `mps` for training, CPU for latency. Executed end to end with papermill (`lesson_07.executed.ipynb`, kept locally). Whole notebook: **35.5 s** (papermill wall clock 37 s). Seed 42 (plus 43, 44 for the seed check).
4
 
5
  ## Data
6
- - pankhllm `evals/pharma-kpi/gen.py` (MIT), run with `python -I`: `gen.py 20000` (training templates, gen.py seed 7) and `gen.py 2000 --heldout` (held-out templates, seed 99). 7 operations + UNSUPPORTED, 250 test questions per class.
7
- - Templates: 71 training, 35 held out (gen.py holds out every third template per operation).
8
- - Shape abstraction (dates, codes, numbers, quoted text -> `<date>`, `<code>`, `<num>`, `<text>`, lower-cased), after pankhllm `learn.rs`.
9
- - Training questions split by shape hash (pankhllm miner recipe): fit 15,205 questions (5,892 shapes), calibration 4,795 questions (1,499 shapes). Both models train on fit only; calibration is used only to choose the fixed threshold.
10
- - Share of held-out-template words never seen in training: 13.9%.
11
-
12
- ## Leakage check (done in the notebook)
13
- - Identical question text in train and test: **0**.
14
- - Shapes shared by train and test: **0**.
15
- - Every test question matches one of its own operation's held-out templates (2,000 / 2,000).
16
- - 271 / 2,000 test questions also fit the pattern of a training template of the same operation (loose patterns such as "{m} for {g} {c}" match text produced by other templates). They are generated from held-out templates; they are not copies. Reported, not removed.
17
 
18
- ## Models
19
- - Logistic regression, pankhllm recipe: hashed word + bigram features, 2^16 buckets (pankhllm `native.rs` uses 2^16), distinct shapes only (5,892), class-balanced SGD, L2 1e-3, 30 epochs. Trained in 1.9 s (NumPy).
20
- - Tiny GPT decider: Lesson 01 GPT class, 4 layers, 4 heads, 128 wide, block 64, dropout 0.1; **word-level tokenizer** over abstracted shapes (210 tokens incl. `<pad>`, `<unk>`, `<sep>` and the 8 operation tokens). 828,416 parameters. Masked loss on the decision token only; word dropout 0.15. 800 steps x batch 64, AdamW, lr 1e-3, warm-up 50 + cosine. Trained in 11.8 s on MPS. Final loss 0.0154.
21
 
22
- ## Numbers (held-out templates, 2,000 questions)
23
- Fixed threshold = lowest threshold at which the calibration shapes hold >= 98% precision (LR 0.9666, GPT 0.9961). Oracle = best threshold swept on the test set itself (upper bound, not deployable).
 
24
 
25
- | Model | Accuracy | Decided @ fixed | Precision @ fixed | Wrong @ fixed | Decided @ oracle 98% | Precision there |
26
- |---|---|---|---|---|---|---|
27
- | Logistic regression | 66.2% | 7.8% | 97.45% | 4 | 6.6% | 98.48% |
28
- | Tiny GPT decider | 82.3% | 46.5% | 94.52% | 51 | 36.4% | 99.45% |
29
 
30
- **CHECK (Lesson 07):** at the threshold fixed on calibration, the transformer decided **46.5%** of held-out-template questions at **94.52%** precision (51 wrong of 930); the logistic regression decided **7.8%** at **97.45%** (4 wrong of 157). Neither held 98% at its fixed threshold. With the threshold swept on the test set, the transformer could decide 36.4% at 99.45%; the regression 6.6% at 98.48%.
 
31
 
32
- Calibration shapes: LR accuracy 89.4%, decided 75.6% at 100%; GPT accuracy 95.5%, decided 88.5% at 100%.
 
 
 
 
 
 
33
 
34
- Seed check (test accuracy / oracle-98 coverage): seed 42 82.35% / 36.35% (kept); seed 43 89.15% / 32.8%; seed 44 81.25% / 26.9%. Spread is large; MPS training is not bit-for-bit repeatable either.
35
 
36
- Most common transformer mistakes: coverage_owner -> kpi_value 64; UNSUPPORTED -> kpi_value 46; kpi_value -> prescriber_list 44; kpi_value -> UNSUPPORTED 41; UNSUPPORTED -> kpi_vs_benchmark 41. Confident wrong answers above the fixed threshold were dominated by "what's our company holiday schedule?" (said kpi_value, 0.9970) and "give me <metric> for T-xxx MTD" (said prescriber_list, ~0.997).
 
37
 
38
- ## 14 decisions benchmark questions (pankhllm `evals/decisions/questions.jsonl`)
39
- Different, three-operation catalog; mapped metric_by_period -> kpi_value, top_entities -> kpi_rank, entity_owner -> coverage_owner. "revenue" is not in the pharma vocabulary.
40
- - Logistic regression: 10/14 correct; decided 5/14 at the fixed threshold, 0 wrong.
41
- - Tiny GPT decider: 13/14 correct (missed "Why did calls fall in T-112 in 2026-08?", said kpi_value 0.894); decided 7/14 at the fixed threshold, 0 wrong.
42
- - pankhllm's published 14/14 (BENCHMARK-DECISIONS.md) is a model trained on 120 questions of that three-operation catalog: different test, quoted only as published.
43
 
44
- ## Decision latency (CPU, batch 1, 2,000 held-out questions, shape -> decision)
45
- - Logistic regression (Python + NumPy): p50 0.012 ms, p95 0.017 ms.
46
- - Tiny GPT decider (PyTorch, 4 threads): p50 0.47 ms, p95 0.526 ms.
47
- - Model file: pankh-decider-v0/model.pt 3.3 MB (fp32).
48
 
49
- ## Published pankhllm numbers (from its docs, NOT measured here)
50
- BENCHMARK-DECISIONS.md, pharma KPI catalog, release build, CPU: template-only training -> templates 52.5% decided at 100% (0 wrong of 1,049), 0.2 ms; + 183 teacher labels -> templates 63.3% at 100%, teacher-written A 67.1% at 100%, teacher-written B held-out half 61.4% at 96.5%. These include pankhllm's structural (slot-fit) check and disagreement check, which this lesson's models do not have.
51
 
52
- ## What went wrong / caveats
53
- - First draft of the notebook omitted the regression cell (NameError); fixed and re-run. The numbers above are from the successful run.
54
- - Prototype runs before the notebook (not quoted) showed the same spread across runs (test accuracy 0.68 to 0.80 depending on word dropout and run).
55
- - Our pure-NumPy LR is not pankhllm's Rust binary; its latency and its features (no capitalised-word or product-vocabulary text slots, no known-words guard) differ.
56
 
57
- - After execution, two non-computational edits were applied to both the clean and the executed notebook without re-running (a re-run on MPS would change the numbers): one self-check question was reworded, and the threshold widget legend was moved out of the chart (it overlapped the curves). No code that produces a number changed.
 
 
1
  # Lesson 07 RESULTS: tiny transformer decider (pankh-decider-v0)
2
 
3
+ Run (after grading fixes): 2026-10-11, Apple M4 Max, PyTorch 2.14.1, device `mps` for training (GPU shared with other jobs, so training was slower than the first run), CPU for latency. Executed end to end with papermill (`lesson_07.executed.ipynb`, kept locally; re-executed, not hand-patched). Whole notebook: **172.4 s**. Seed 42 (plus 43, 44). Colab T4 time: estimated, not timed. This run supersedes the first run (whose numbers were 82.3% / 46.5% at 94.52%); every number below is from this run.
4
 
5
  ## Data
6
+ - pankhllm `evals/pharma-kpi/gen.py` (MIT), run with `python -I`: `gen.py 20000` (training templates, seed 7) and `gen.py 2000 --heldout` (held-out templates, seed 99). 7 operations + UNSUPPORTED, 250 test questions per class.
7
+ - Templates: 71 training, 35 held out. 2,000 test questions = **1,150 distinct shapes**; UNSUPPORTED = **9 shapes**, the most repeated being "what's our company holiday schedule?" **x 46**.
8
+ - Shape abstraction (dates, codes, numbers, quoted text), after pankhllm `learn.rs` (its capitalised-word-run -> `<text>` rule is omitted).
9
+ - Shape-hash split (pankhllm miner style): fit 15,205 questions (5,892 shapes), calibration 4,795 (1,499 shapes). Calibration shapes share templates with training, so they are easier than held-out templates. 13.9% of held-out words never seen in training.
 
 
 
 
 
 
 
10
 
11
+ ## Leakage check
12
+ - Identical questions train/test: **0**. Shared shapes: **0**. 2,000/2,000 test questions match their own held-out templates; 271/2,000 also fit a loose training-template pattern (generated from held-out templates; not copies).
 
13
 
14
+ ## Models
15
+ - Logistic regression (pankhllm recipe, NumPy): hashed word + bigram, 2^16 buckets, 5,892 distinct shapes, class-balanced SGD, L2 1e-3, 30 epochs; 2.5 s.
16
+ - Tiny GPT (Lesson 01 class): 4 layers, 4 heads, 128 wide, block 64, dropout 0.1, word-level tokenizer (210 tokens), 828,416 params, masked loss on the decision token, word dropout 0.15, 800 steps x 64; 62.3 s on shared MPS; final loss 0.0146.
17
 
18
+ ## Thresholds
19
+ Fixed = lowest threshold at which the calibration shapes hold >= 98% (LR 0.9666, GPT 0.9956). pankhllm's miner searches a 0.5-0.95 grid; under that rule neither model would get a threshold on this calibration set. Oracle = swept on the test set (not deployable).
 
 
20
 
21
+ ## Known-words gate (new, pankhllm `decisions.min_known_words` = 0.7)
22
+ An operation is not acted on if < 70% of the shape's words were seen in non-UNSUPPORTED fit questions; UNSUPPORTED unaffected. Applied at the same fixed thresholds. It stops 336 of 2,000 held-out questions (for any operation choice).
23
 
24
+ ## Numbers (held-out templates, 2,000 questions)
25
+ | Model | Accuracy | Decided @ fixed | Precision | Wrong | Oracle 98% |
26
+ |---|---|---|---|---|---|
27
+ | Logistic regression | 66.2% | 7.8% | 97.45% | 4 | 6.6% |
28
+ | Logistic regression + gate | 66.2% | 7.8% | 97.45% | 4 | 33.9% |
29
+ | Tiny GPT | 81.5% | 49.6% | 94.46% | 55 | 42.2% |
30
+ | Tiny GPT + gate | 81.5% | 41.2% | **98.91%** | 9 | 51.5% |
31
 
32
+ **CHECK (Lesson 07):** without pankhllm's known-words gate neither model holds 98% at its fixed threshold (transformer 49.6% at 94.46%, regression 7.8% at 97.45%). With the gate the transformer does, deciding **41.2% at 98.91%** (9 wrong); the regression is unchanged at 7.8% at 97.45%.
33
 
34
+ The transformer's 55 wrong decisions (no gate) are **10 distinct shapes**, 46 of them one question ("what's our company holiday schedule?", said kpi_value): the 94.46% figure is effectively decided by one template. Other confident errors: "give me <metric> for <code> MTD/QTD/YTD" -> prescriber_list (~0.996-0.998).
35
+ Calibration: LR accuracy 89.4%, GPT 95.5% (decided 87.2% at 100%).
36
 
37
+ Seed check (accuracy; decided at its own fixed threshold, precision; oracle-98):
38
+ - seed 42: 81.55%; 49.6% at 94.46%; 42.25% (kept)
39
+ - seed 43: 88.3%; 53.7% at 95.25%; 34.75%
40
+ - seed 44: 81.4%; 56.85% at 93.93%; 26.7%
 
41
 
42
+ ## 14 decisions benchmark questions (mapped onto the pharma catalog; "revenue" not in it)
43
+ LR 10/14 correct, decided 5/14 at its fixed threshold, 0 wrong. GPT 13/14 correct (missed "Why did calls fall in T-112 in 2026-08?" -> kpi_value 0.870), decided 7/14, 0 wrong. pankhllm's published 14/14 is a different model on a three-operation catalog.
 
 
44
 
45
+ ## Latency (CPU, batch 1, 2,000 questions, shape -> decision)
46
+ LR p50 0.016 ms, p95 0.023 ms; GPT p50 0.5 ms, p95 0.545 ms (4 threads). model.pt 3.3 MB fp32.
47
 
48
+ ## Published pankhllm numbers (BENCHMARK-DECISIONS.md, NOT measured here)
49
+ Template-only: templates 52.5% at 100% (0 wrong of 1,049); + 183 teacher labels: templates 63.3% at 100%, teacher-written A 67.1% at 100%, B 61.4% at 96.5%. These include pankhllm's structural and disagreement checks.
 
 
50
 
51
+ ## History / caveats
52
+ - First draft omitted the regression cell (NameError), fixed. A first full run gave different numbers (MPS training is not bit-exact); after grading, the notebook gained the gate, distinct-shape counts, per-seed fixed-threshold numbers, a broken precision line at zero coverage in the widget and figure alt text, and was re-executed. Lesson 08 was re-executed from this run's v0.