Datasets:
Upload folder using huggingface_hub
Browse files- DATASET_CARD.md +15 -2
- README.md +15 -2
- experiment-notes-07.md +268 -0
DATASET_CARD.md
CHANGED
|
@@ -14,6 +14,10 @@ tags:
|
|
| 14 |
- number-formatting
|
| 15 |
- vat
|
| 16 |
- financial-documents
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
pretty_name: InvoiceBenchmark
|
| 18 |
size_categories:
|
| 19 |
- n<1K
|
|
@@ -38,7 +42,8 @@ Five open-weight models. Four architectures. The best one scored 83%. The larges
|
|
| 38 |
|
| 39 |
| Component | Path | Format | Count |
|
| 40 |
|---|---|---|---|
|
| 41 |
-
| Invoices | `output/invoices/` | Markdown | 200 |
|
|
|
|
| 42 |
| Ground truth | `output/ground_truth/` | JSON | 200 |
|
| 43 |
| Manifest | `output/manifest.csv` | CSV | 1 |
|
| 44 |
| Distribution summary | `output/summary.json` | JSON | 1 |
|
|
@@ -46,7 +51,9 @@ Five open-weight models. Four architectures. The best one scored 83%. The larges
|
|
| 46 |
| Evaluation harness | `run_benchmark.py` | Python | 1 |
|
| 47 |
| Prompts | `prompts/` | Text | 2 |
|
| 48 |
|
| 49 |
-
Each invoice
|
|
|
|
|
|
|
| 50 |
|
| 51 |
All monetary values use Python's `Decimal` with `ROUND_HALF_UP` rounding. No floating-point arithmetic touches the money pipeline. The total is correct to the cent unless it has been deliberately broken.
|
| 52 |
|
|
@@ -133,6 +140,12 @@ Exact match means the model's reported total equals the ground-truth total to th
|
|
| 133 |
|
| 134 |
A plain-text rendering of a European B2B invoice. Company names are fictional (Pierce & Pierce, Vandelay Industries, Cyberdyne Systems, Wonka Industries, and so on). Street addresses are invented. IBANs have correct country prefixes and lengths but random digits — they are not real bank accounts.
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
### Ground Truth (JSON)
|
| 137 |
|
| 138 |
```json
|
|
|
|
| 14 |
- number-formatting
|
| 15 |
- vat
|
| 16 |
- financial-documents
|
| 17 |
+
- document-understanding
|
| 18 |
+
- vision
|
| 19 |
+
- multimodal
|
| 20 |
+
- ocr
|
| 21 |
pretty_name: InvoiceBenchmark
|
| 22 |
size_categories:
|
| 23 |
- n<1K
|
|
|
|
| 42 |
|
| 43 |
| Component | Path | Format | Count |
|
| 44 |
|---|---|---|---|
|
| 45 |
+
| Invoices (text) | `output/invoices/` | Markdown | 200 |
|
| 46 |
+
| Invoices (visual) | `output/pdf/` | PDF | 200 |
|
| 47 |
| Ground truth | `output/ground_truth/` | JSON | 200 |
|
| 48 |
| Manifest | `output/manifest.csv` | CSV | 1 |
|
| 49 |
| Distribution summary | `output/summary.json` | JSON | 1 |
|
|
|
|
| 51 |
| Evaluation harness | `run_benchmark.py` | Python | 1 |
|
| 52 |
| Prompts | `prompts/` | Text | 2 |
|
| 53 |
|
| 54 |
+
Each invoice exists in two formats. The **Markdown version** is plain text — the kind of thing you would paste into a prompt. The **PDF version** is a rendered, styled document — the kind of thing a multimodal or vision model would receive as an image. Both formats share the same ground truth: same numbers, same structure, same controlled dimensions.
|
| 55 |
+
|
| 56 |
+
Each ground-truth JSON records the canonical correct values, the variant parameters that control how the invoice was constructed, and (for error-injected invoices) both the correct and the deliberately-wrong number.
|
| 57 |
|
| 58 |
All monetary values use Python's `Decimal` with `ROUND_HALF_UP` rounding. No floating-point arithmetic touches the money pipeline. The total is correct to the cent unless it has been deliberately broken.
|
| 59 |
|
|
|
|
| 140 |
|
| 141 |
A plain-text rendering of a European B2B invoice. Company names are fictional (Pierce & Pierce, Vandelay Industries, Cyberdyne Systems, Wonka Industries, and so on). Street addresses are invented. IBANs have correct country prefixes and lengths but random digits — they are not real bank accounts.
|
| 142 |
|
| 143 |
+
### Invoice (PDF)
|
| 144 |
+
|
| 145 |
+
The same invoice, rendered as a styled single-page PDF with a line-item table, header block, and summary section. German number formatting (`1.234,56`), Swiss formatting (`1'234.56`), and English formatting (`1,234.56`) are all preserved visually — the model must read the numbers from the rendered document, not from parsed text.
|
| 146 |
+
|
| 147 |
+
Use the PDF versions to benchmark multimodal and vision-language models on document understanding. The text versions test reading comprehension; the PDF versions test whether the model can extract the same information when it has to *see* the invoice instead of *read* it.
|
| 148 |
+
|
| 149 |
### Ground Truth (JSON)
|
| 150 |
|
| 151 |
```json
|
README.md
CHANGED
|
@@ -14,6 +14,10 @@ tags:
|
|
| 14 |
- number-formatting
|
| 15 |
- vat
|
| 16 |
- financial-documents
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
pretty_name: InvoiceBenchmark
|
| 18 |
size_categories:
|
| 19 |
- n<1K
|
|
@@ -38,7 +42,8 @@ Five open-weight models. Four architectures. The best one scored 83%. The larges
|
|
| 38 |
|
| 39 |
| Component | Path | Format | Count |
|
| 40 |
|---|---|---|---|
|
| 41 |
-
| Invoices | `output/invoices/` | Markdown | 200 |
|
|
|
|
| 42 |
| Ground truth | `output/ground_truth/` | JSON | 200 |
|
| 43 |
| Manifest | `output/manifest.csv` | CSV | 1 |
|
| 44 |
| Distribution summary | `output/summary.json` | JSON | 1 |
|
|
@@ -46,7 +51,9 @@ Five open-weight models. Four architectures. The best one scored 83%. The larges
|
|
| 46 |
| Evaluation harness | `run_benchmark.py` | Python | 1 |
|
| 47 |
| Prompts | `prompts/` | Text | 2 |
|
| 48 |
|
| 49 |
-
Each invoice
|
|
|
|
|
|
|
| 50 |
|
| 51 |
All monetary values use Python's `Decimal` with `ROUND_HALF_UP` rounding. No floating-point arithmetic touches the money pipeline. The total is correct to the cent unless it has been deliberately broken.
|
| 52 |
|
|
@@ -133,6 +140,12 @@ Exact match means the model's reported total equals the ground-truth total to th
|
|
| 133 |
|
| 134 |
A plain-text rendering of a European B2B invoice. Company names are fictional (Pierce & Pierce, Vandelay Industries, Cyberdyne Systems, Wonka Industries, and so on). Street addresses are invented. IBANs have correct country prefixes and lengths but random digits — they are not real bank accounts.
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
### Ground Truth (JSON)
|
| 137 |
|
| 138 |
```json
|
|
|
|
| 14 |
- number-formatting
|
| 15 |
- vat
|
| 16 |
- financial-documents
|
| 17 |
+
- document-understanding
|
| 18 |
+
- vision
|
| 19 |
+
- multimodal
|
| 20 |
+
- ocr
|
| 21 |
pretty_name: InvoiceBenchmark
|
| 22 |
size_categories:
|
| 23 |
- n<1K
|
|
|
|
| 42 |
|
| 43 |
| Component | Path | Format | Count |
|
| 44 |
|---|---|---|---|
|
| 45 |
+
| Invoices (text) | `output/invoices/` | Markdown | 200 |
|
| 46 |
+
| Invoices (visual) | `output/pdf/` | PDF | 200 |
|
| 47 |
| Ground truth | `output/ground_truth/` | JSON | 200 |
|
| 48 |
| Manifest | `output/manifest.csv` | CSV | 1 |
|
| 49 |
| Distribution summary | `output/summary.json` | JSON | 1 |
|
|
|
|
| 51 |
| Evaluation harness | `run_benchmark.py` | Python | 1 |
|
| 52 |
| Prompts | `prompts/` | Text | 2 |
|
| 53 |
|
| 54 |
+
Each invoice exists in two formats. The **Markdown version** is plain text — the kind of thing you would paste into a prompt. The **PDF version** is a rendered, styled document — the kind of thing a multimodal or vision model would receive as an image. Both formats share the same ground truth: same numbers, same structure, same controlled dimensions.
|
| 55 |
+
|
| 56 |
+
Each ground-truth JSON records the canonical correct values, the variant parameters that control how the invoice was constructed, and (for error-injected invoices) both the correct and the deliberately-wrong number.
|
| 57 |
|
| 58 |
All monetary values use Python's `Decimal` with `ROUND_HALF_UP` rounding. No floating-point arithmetic touches the money pipeline. The total is correct to the cent unless it has been deliberately broken.
|
| 59 |
|
|
|
|
| 140 |
|
| 141 |
A plain-text rendering of a European B2B invoice. Company names are fictional (Pierce & Pierce, Vandelay Industries, Cyberdyne Systems, Wonka Industries, and so on). Street addresses are invented. IBANs have correct country prefixes and lengths but random digits — they are not real bank accounts.
|
| 142 |
|
| 143 |
+
### Invoice (PDF)
|
| 144 |
+
|
| 145 |
+
The same invoice, rendered as a styled single-page PDF with a line-item table, header block, and summary section. German number formatting (`1.234,56`), Swiss formatting (`1'234.56`), and English formatting (`1,234.56`) are all preserved visually — the model must read the numbers from the rendered document, not from parsed text.
|
| 146 |
+
|
| 147 |
+
Use the PDF versions to benchmark multimodal and vision-language models on document understanding. The text versions test reading comprehension; the PDF versions test whether the model can extract the same information when it has to *see* the invoice instead of *read* it.
|
| 148 |
+
|
| 149 |
### Ground Truth (JSON)
|
| 150 |
|
| 151 |
```json
|
experiment-notes-07.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Article 07 — Experiment Notes
|
| 2 |
+
|
| 3 |
+
## Working Title
|
| 4 |
+
TBD (depends on results). Quantisation + vision on invoices.
|
| 5 |
+
|
| 6 |
+
## Premise
|
| 7 |
+
Article 06 tested five models reading text invoices. The best scored 83%. But text invoices are a gift — in reality, invoices are PDFs, scans, phone photos. Article 07 asks: what happens when the model has to *see* the invoice instead of *read* it? And what happens when you compress the model to fit on cheaper hardware?
|
| 8 |
+
|
| 9 |
+
## The Experiment
|
| 10 |
+
|
| 11 |
+
### Models — Google Gemma 4 family only
|
| 12 |
+
Three sizes, one vendor, one architecture lineage:
|
| 13 |
+
|
| 14 |
+
1. **Gemma 4 31B** (dense) — the largest. 31 billion parameters, all active on every token. This is the model that scored 83% on text invoices in article 06.
|
| 15 |
+
2. **Gemma 4 26B MoE** (Mixture of Experts) — 26 billion parameters total, but only ~4 billion active per token. 128 experts, 8 fire per token via learned routing. A shared expert (3x larger) handles general knowledge. In theory: 31B-class intelligence at 4B-class compute.
|
| 16 |
+
3. **Gemma 4 E4B** (dense, small) — 4.5 billion parameters. The edge model. Designed to run on phones and laptops.
|
| 17 |
+
|
| 18 |
+
All three are multimodal — they natively accept image input. Vision capabilities survive GGUF quantisation (requires mmproj projector file alongside the model).
|
| 19 |
+
|
| 20 |
+
### Quantisation levels
|
| 21 |
+
For each model, test at:
|
| 22 |
+
|
| 23 |
+
- **FP16** (full precision, 16-bit) — the reference. Every parameter stored as a 16-bit floating point number. Maximum quality, maximum size.
|
| 24 |
+
- **Q8** (8-bit) — roughly half the size of FP16. Usually considered "lossless" in practice.
|
| 25 |
+
- **Q4_K_M** (4-bit, K-quant medium) — roughly quarter the size. The practical minimum for most tasks. This is where quality-vs-size tradeoffs start to bite.
|
| 26 |
+
|
| 27 |
+
The E4B (smallest model) runs unquantised at Q8 on the MacBook — no need to go lower. It's the "what if you don't compress at all but just use a smaller model?" baseline.
|
| 28 |
+
|
| 29 |
+
### Quantisation format
|
| 30 |
+
**GGUF** via llama.cpp / Ollama. Pre-quantised versions available from Unsloth on HuggingFace. No need to quantise ourselves.
|
| 31 |
+
|
| 32 |
+
This is **weight quantisation** — the model's learned parameters are stored at lower precision. This is NOT the same as:
|
| 33 |
+
- **KV cache quantisation** (TurboQuant, KIVI) — compresses the conversation memory at inference time, not the model itself
|
| 34 |
+
- **Activation quantisation** — compresses the intermediate computations during inference
|
| 35 |
+
|
| 36 |
+
Weight quantisation is permanent: you download a smaller file, it loads into less memory, and every inference uses the compressed weights. KV cache quantisation is dynamic: the model weights stay full precision, but the memory of the conversation is compressed on the fly. They solve different problems. Weight quantisation = "make the model smaller." KV cache quantisation = "make the conversation cheaper." They can be combined.
|
| 37 |
+
|
| 38 |
+
### Input format
|
| 39 |
+
The 200 existing synthetic invoices from article 06, rendered as PDF images. A rendering script will produce styled PNG/PDF versions with visual variation:
|
| 40 |
+
|
| 41 |
+
- Different visual templates (3-5 styles)
|
| 42 |
+
- Different fonts
|
| 43 |
+
- Table vs paragraph layout preserved from the original corpus
|
| 44 |
+
- German/Swiss/English number formatting preserved
|
| 45 |
+
- Some with slight rotation (simulating a scan)
|
| 46 |
+
- Some at lower resolution (simulating a phone photo)
|
| 47 |
+
- All with the same cent-perfect ground truth from article 06
|
| 48 |
+
|
| 49 |
+
### Evaluation conditions
|
| 50 |
+
Same two conditions as article 06:
|
| 51 |
+
- **Autopilot:** model sees the image, reports the total
|
| 52 |
+
- **Hybrid:** model sees the image, extracts structured fields, Python recomputes the total
|
| 53 |
+
|
| 54 |
+
### What we measure
|
| 55 |
+
- Exact match accuracy (vs ground truth)
|
| 56 |
+
- Parse rate (did the model produce useable output?)
|
| 57 |
+
- Error detection rate (did it flag the 40 deliberately broken invoices?)
|
| 58 |
+
- Worst single error
|
| 59 |
+
- Time per invoice
|
| 60 |
+
- GPU memory usage
|
| 61 |
+
- The German comma: accuracy breakdown by number format (English vs Swiss vs German)
|
| 62 |
+
- The discount trap: accuracy on percentage discounts in hybrid mode
|
| 63 |
+
|
| 64 |
+
### Hardware
|
| 65 |
+
- **FP16 runs:** Scaleway H100 at €2.73/hr (same as article 06)
|
| 66 |
+
- **Q8/Q4 runs:** MacBook Air M3, 24GB RAM (same laptop as article 06)
|
| 67 |
+
- E4B all runs on MacBook
|
| 68 |
+
|
| 69 |
+
### Run matrix
|
| 70 |
+
|
| 71 |
+
| # | Model | Precision | Hardware | Est. memory |
|
| 72 |
+
|---|-------|-----------|----------|-------------|
|
| 73 |
+
| 1 | Gemma 31B dense | FP16 | H100 | ~62GB |
|
| 74 |
+
| 2 | Gemma 31B dense | Q8 | H100 | ~32GB |
|
| 75 |
+
| 3 | Gemma 31B dense | Q4_K_M | MacBook | ~18GB |
|
| 76 |
+
| 4 | Gemma 26B MoE | FP16 | H100 | ~52GB |
|
| 77 |
+
| 5 | Gemma 26B MoE | Q8 | H100 or MacBook | ~28GB |
|
| 78 |
+
| 6 | Gemma 26B MoE | Q4_K_M | MacBook | ~15GB |
|
| 79 |
+
| 7 | Gemma E4B | FP16 | MacBook | ~9GB |
|
| 80 |
+
| 8 | Gemma E4B | Q4_K_M | MacBook | ~5GB |
|
| 81 |
+
|
| 82 |
+
8 runs × 200 invoices × 2 conditions = 3,200 inference calls.
|
| 83 |
+
MacBook runs estimated at 30-60s per image. Weekend project.
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## Article Content Requirements
|
| 88 |
+
|
| 89 |
+
### Must explain (for non-ML readers):
|
| 90 |
+
|
| 91 |
+
**How does a language model "see" an image? (LEAD WITH THIS)**
|
| 92 |
+
|
| 93 |
+
This is the central question the article must answer up front — before MoE, before quantisation, before results. The reader knows from article 06 that language models process text. Now we're feeding them pictures. The obvious question: how?
|
| 94 |
+
|
| 95 |
+
The answer, plainly:
|
| 96 |
+
|
| 97 |
+
1. **A language model cannot see.** It processes tokens — chunks of text. It has no eyes, no pixel processing, no concept of "looking at" anything. Left to its own devices, a language model receiving an image receives nothing.
|
| 98 |
+
|
| 99 |
+
2. **So you bolt on eyes.** A multimodal model like Gemma 4 has two systems bolted together:
|
| 100 |
+
- A **vision encoder** (typically a Vision Transformer, or ViT) — a separate neural network trained on images. This network takes a picture, chops it into a grid of patches (like cutting a photo into small squares), and converts each patch into a vector — a list of numbers that encodes "what's in this patch."
|
| 101 |
+
- A **projection layer** (the "connector" or "adapter") — a small neural network that translates the vision encoder's vectors into the same format as text tokens. It's a Rosetta Stone between the visual world and the language world.
|
| 102 |
+
|
| 103 |
+
3. **What the language model actually receives:** Not pixels. Not an image. A sequence of fake "tokens" that were generated by the vision encoder and translated by the projector. To the language model, an invoice image looks like a long sequence of tokens — just like a text prompt. It doesn't know they came from a picture. It just processes tokens the way it always does.
|
| 104 |
+
|
| 105 |
+
Analogy: imagine you're a book editor who only reads English. Someone hands you a Japanese document. You can't read it. But your colleague translates it into English and hands you the translation. You read the English version. You never learned Japanese — you're just trusting the translation. That's what a multimodal model does. The language model is the English-only editor. The vision encoder + projector is the translator.
|
| 106 |
+
|
| 107 |
+
4. **Why this matters for the experiment:**
|
| 108 |
+
- The vision encoder has its own quality ceiling. If it misreads a digit, the language model has no way to know — it received a confident-looking token, not a blurry pixel.
|
| 109 |
+
- Quantisation compresses the language model's weights. But the vision encoder (stored separately as the **mmproj** file in GGUF/Ollama) may or may not be compressed. If the projector is quantised, the "translation" degrades — the language model receives worse tokens.
|
| 110 |
+
- A text invoice is direct input — the model reads the actual characters. An image invoice is indirect — the model reads a *description* of the characters as interpreted by a separate neural network. Every error in article 06 still applies, plus a new category: translation errors from the vision pipeline.
|
| 111 |
+
|
| 112 |
+
5. **The punchline for the article:** In article 06, the model read the invoice. In article 07, the model reads a translation of a photograph of the invoice. We added two layers of indirection and asked whether the answer stays the same.
|
| 113 |
+
|
| 114 |
+
Style note: This should open the article, right after the premise. Before the reader sees any results, they need to understand that "multimodal" doesn't mean the model grew eyes. It means someone bolted a camera onto a typewriter and wrote a translator in between. The FT Alphaville voice should have fun with this — "the model doesn't see your invoice; it reads a hallucinated transcription of your invoice generated by a separate neural network that was never told what an invoice is."
|
| 115 |
+
|
| 116 |
+
**What is Mixture of Experts?**
|
| 117 |
+
- The concept: instead of one big brain, 128 small specialists. A router looks at each token and picks 8 experts to handle it.
|
| 118 |
+
- Why it matters: you get 26B worth of knowledge but only pay for 4B of compute per token.
|
| 119 |
+
- The risk: quantisation can corrupt the router. If the router sends tokens to the wrong experts, the model doesn't just get a bit worse — it gets unpredictably wrong.
|
| 120 |
+
- Needs a simple visual analogy. Hospital with 128 specialists vs one GP? Law firm with 128 specialists vs one generalist?
|
| 121 |
+
|
| 122 |
+
**What is quantisation?**
|
| 123 |
+
- The concept: storing numbers with less precision. A 16-bit number can represent 65,536 distinct values. A 4-bit number can represent 16. You're rounding every parameter in the model to the nearest value on a coarser grid.
|
| 124 |
+
- Simple example: imagine you have a ruler marked in millimetres (FP16). Now replace it with a ruler marked in centimetres (Q4). You can still measure things, but you lose the fine detail. A 7.3mm measurement becomes "1cm." Most of the time this doesn't matter. Sometimes it does — and you can't predict when.
|
| 125 |
+
- Why it works: most parameters in a neural network are close to zero. The information loss from rounding is small in aggregate. Until it isn't.
|
| 126 |
+
- What it is NOT: it's not lossy compression like JPEG. It's more like reducing the resolution of every number in the model permanently.
|
| 127 |
+
|
| 128 |
+
**Quantisation is not quantisation — the zoo of methods**
|
| 129 |
+
|
| 130 |
+
The article must make clear: "quantisation" is not one thing. It's a family of techniques that compress different parts of the system in different ways. The reader who googles "quantisation" will find a dozen acronyms. We need to map the territory before we pick our spot on it.
|
| 131 |
+
|
| 132 |
+
**A. What you're compressing (the target):**
|
| 133 |
+
|
| 134 |
+
| Target | What it does | When it happens | Analogy |
|
| 135 |
+
|--------|-------------|-----------------|---------|
|
| 136 |
+
| **Weight quantisation** | Compresses the model's learned parameters (the "brain") | Once, before inference. You download a smaller file. | Shrinking the textbook permanently — fewer pages, coarser print |
|
| 137 |
+
| **KV cache quantisation** | Compresses the conversation memory (what the model remembers about this chat) | Dynamically, during inference. Model weights stay full size. | Shorthand notes instead of full transcripts — written on the fly, discarded after |
|
| 138 |
+
| **Activation quantisation** | Compresses the intermediate calculations during a forward pass | Dynamically, during inference | Doing mental arithmetic in round numbers instead of exact decimals |
|
| 139 |
+
|
| 140 |
+
These solve **completely different problems:**
|
| 141 |
+
- Weight quantisation → "Can I fit this model on my laptop?" (article 07 — this experiment)
|
| 142 |
+
- KV cache quantisation → "Can I serve 10x more users on the same GPU?" (article 08 — Chipspotting / TurboQuant)
|
| 143 |
+
- Activation quantisation → "Can I make each inference faster on specialised hardware?" (not our problem)
|
| 144 |
+
|
| 145 |
+
They can be stacked. A Q4 weight-quantised model with TurboQuant KV cache compression and INT8 activations. Three layers of compression hitting three different targets. But for this experiment we're only touching the first one.
|
| 146 |
+
|
| 147 |
+
**B. How you compress the weights (the method):**
|
| 148 |
+
|
| 149 |
+
Even within weight quantisation, there are fundamentally different approaches:
|
| 150 |
+
|
| 151 |
+
| Method | Full name | How it works | Needs training data? | Quality |
|
| 152 |
+
|--------|-----------|-------------|---------------------|---------|
|
| 153 |
+
| **PTQ** | Post-Training Quantisation | Take a finished model, round the weights. No retraining. | No (or a small calibration set) | Good enough at 8-bit, degrades at 4-bit |
|
| 154 |
+
| **QAT** | Quantisation-Aware Training | Train the model knowing it will be quantised — the model learns to be robust to rounding | Yes (full training run) | Better at low bit-widths, but expensive |
|
| 155 |
+
| **GPTQ** | GPT-Quantisation | PTQ but smarter — uses a calibration dataset to find the rounding that minimises output error, layer by layer | Small calibration set (~128 examples) | Very good at 4-bit, the standard for GPU inference |
|
| 156 |
+
| **AWQ** | Activation-Aware Weight Quantisation | Like GPTQ but protects "important" weights — finds which weights matter most (based on activation patterns) and keeps those at higher precision | Small calibration set | Often better than GPTQ at 4-bit, especially for smaller models |
|
| 157 |
+
| **GGUF / llama.cpp quants** | K-quants (Q4_K_M, Q5_K_S, etc.) | PTQ with per-block scaling factors and mixed precision — different layers get different bit-widths based on importance | No | The CPU/Mac standard. What Ollama uses. What we're using. |
|
| 158 |
+
| **BnB** | BitsAndBytes | Dynamic quantisation at load time — quantise on the fly when moving from disk to GPU | No | Easy to use, slightly worse than GPTQ/AWQ |
|
| 159 |
+
|
| 160 |
+
**C. Why we're using GGUF K-quants (and why it probably doesn't matter much):**
|
| 161 |
+
|
| 162 |
+
Our choice: **GGUF format, K-quant method (Q8_0, Q4_K_M), via Ollama/llama.cpp.**
|
| 163 |
+
|
| 164 |
+
Why:
|
| 165 |
+
1. **Ollama uses GGUF.** We're running on a MacBook. Ollama is the inference engine. It only speaks GGUF. Decision made.
|
| 166 |
+
2. **Pre-quantised models exist.** Unsloth publishes GGUF quants for Gemma 4 on HuggingFace. No work required on our end.
|
| 167 |
+
3. **K-quants are state of the art for CPU inference.** They use mixed precision per block — "important" layers keep more bits, less important layers get fewer. It's not as sophisticated as AWQ/GPTQ (which use calibration data), but for the GGUF/CPU ecosystem, K-quants are the standard.
|
| 168 |
+
|
| 169 |
+
Does the method matter? **At Q8: almost certainly not.** All methods converge to near-lossless at 8-bit. The differences emerge at Q4 and below, where smarter methods (AWQ, GPTQ) can sometimes preserve quality that naive rounding destroys. But:
|
| 170 |
+
- We're comparing against an FP16 baseline on the same task, so any quality loss is visible regardless of method.
|
| 171 |
+
- We're using what a real user would use (Ollama + pre-built GGUF). The experiment tests the practical question ("if I download the Q4 model from HuggingFace and run it, do my invoices still work?"), not the theoretical question ("what's the optimal quantisation algorithm for invoice processing?").
|
| 172 |
+
- If Q4_K_M fails catastrophically on invoices, the article can note: "a fancier method (AWQ, GPTQ) might claw back some accuracy — but you'd need a GPU and a calibration dataset. On a MacBook, this is what you get."
|
| 173 |
+
|
| 174 |
+
**D. The TurboQuant distinction (what this is NOT):**
|
| 175 |
+
|
| 176 |
+
TurboQuant (Google, ICLR 2026) is **KV cache quantisation**, not weight quantisation. It compresses the conversation memory, not the model itself:
|
| 177 |
+
- The model weights stay at full precision (FP16 or BF16)
|
| 178 |
+
- The KV cache (the stored key/value pairs from previous tokens — essentially the model's short-term memory of the current conversation) gets compressed from 16-bit to 3-4 bits per element
|
| 179 |
+
- This means you can have longer conversations or serve more users on the same GPU
|
| 180 |
+
- The model itself doesn't get smaller — you can't run it on a laptop because of TurboQuant
|
| 181 |
+
|
| 182 |
+
To be precise about what KV cache IS: every time a transformer processes a token, it produces a "key" vector and a "value" vector for that token at every layer. These get stored so the model doesn't have to recompute them. For a 128K-token conversation, that's millions of vectors sitting in GPU memory. TurboQuant compresses those stored vectors. It's the difference between "make the model's brain smaller" (weight quantisation) and "make the model's notepad smaller" (KV cache quantisation).
|
| 183 |
+
|
| 184 |
+
Why this matters for the article: the reader who reads "quantisation makes AI cheaper" needs to know there are at least two completely different things being compressed. Samsung's stock didn't fall because of Q4_K_M. It fell because of TurboQuant. Different target, different implication, different article (→ Chipspotting, article 08).
|
| 185 |
+
|
| 186 |
+
**E. Summary for the article — the one-paragraph version:**
|
| 187 |
+
|
| 188 |
+
"When people say 'quantised model,' they usually mean weight quantisation — the brain got smaller. When Google published TurboQuant and Samsung's stock fell, that was KV cache quantisation — the notepad got smaller. When NVIDIA talks about INT8 inference, that's activation quantisation — the mental arithmetic got faster. This article tests weight quantisation only: we took the same model, crushed its brain from 16-bit to 4-bit, and asked whether it can still read an invoice. The other kinds of compression are someone else's article."
|
| 189 |
+
|
| 190 |
+
### Voice and style
|
| 191 |
+
- FT Alphaville dry humour throughout
|
| 192 |
+
- Self-Delusion Cycle restarts at Phase I ("it has eyes now")
|
| 193 |
+
- Direct callbacks to article 06 results (83% text baseline)
|
| 194 |
+
- Technical but not academic — explain everything, assume intelligence but not expertise
|
| 195 |
+
- Tables for results, not charts (matches previous articles)
|
| 196 |
+
- Bold takeaways in "What This Suggests"
|
| 197 |
+
- The narrative arc depends on results — framing TBD after experiments
|
| 198 |
+
|
| 199 |
+
---
|
| 200 |
+
|
| 201 |
+
## Open Questions
|
| 202 |
+
|
| 203 |
+
1. **Rendering script:** How to convert Markdown invoices to styled PDFs/PNGs? Options: WeasyPrint, Puppeteer, matplotlib. Need 3-5 visual templates with controlled variation.
|
| 204 |
+
2. **Ollama vision support:** Confirmed that Ollama supports Gemma 4 multimodal. Need to test: does `ollama run gemma4:31b` accept image input out of the box? What's the syntax?
|
| 205 |
+
3. **MoE quantisation quality:** Research says "expert-shift" can corrupt routing. Is this observable on invoices? The German comma disaster from article 06 could get worse if the routing sends German-formatted numbers to the wrong expert.
|
| 206 |
+
4. **Benchmark harness:** Can we adapt `run_benchmark.py` from article 06? Need to add image input path, keep everything else (scoring, CSV output, conditions B and C).
|
| 207 |
+
5. **Timeline:** Rendering script → test runs on 10 invoices → full runs → analysis → article. Two weekends?
|
| 208 |
+
|
| 209 |
+
---
|
| 210 |
+
|
| 211 |
+
## Connections to Previous Articles
|
| 212 |
+
|
| 213 |
+
- **Article 06:** Same invoices, same ground truth, same evaluation. Direct accuracy comparison: text vs vision, full precision vs quantised.
|
| 214 |
+
- **Article 05:** Same Scaleway H100 setup. "Our old friend the rented GPU."
|
| 215 |
+
- **Article 03:** Reasoning models underperformed. MoE is a different kind of "smart architecture" — does it also disappoint?
|
| 216 |
+
- **Article 04:** The TF-IDF word counter beat 70B LLMs. Will a 4-bit model on a laptop beat a full-precision model on an H100?
|
| 217 |
+
|
| 218 |
+
---
|
| 219 |
+
|
| 220 |
+
## HuggingFace Artifacts
|
| 221 |
+
|
| 222 |
+
### 1. Image dataset: `jngb-labs/InvoiceBenchmark-Vision`
|
| 223 |
+
|
| 224 |
+
The primary artifact. The 200 text invoices from article 06, rendered as styled images (PNG) with visual variation. Same ground truth JSONs, paired with images instead of Markdown.
|
| 225 |
+
|
| 226 |
+
Structure:
|
| 227 |
+
```
|
| 228 |
+
InvoiceBenchmark-Vision/
|
| 229 |
+
├── images/ # 200 rendered invoice PNGs
|
| 230 |
+
│ ├── INV-2026-0001.png
|
| 231 |
+
│ ├── INV-2026-0002.png
|
| 232 |
+
│ └── ...
|
| 233 |
+
├── ground_truth/ # Same JSONs from text dataset (symlinked or copied)
|
| 234 |
+
│ ├── INV-2026-0001.json
|
| 235 |
+
│ └── ...
|
| 236 |
+
├── manifest.csv # invoice_id, image_path, ground_truth_path, template, font, rotation, resolution
|
| 237 |
+
├── rendering_metadata.json # Which template, font, rotation, DPI was used per invoice
|
| 238 |
+
├── render_invoices.py # The rendering script (reproducible)
|
| 239 |
+
└── README.md # Dataset card
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
Dataset card should:
|
| 243 |
+
- Link back to text version (`jngb-labs/InvoiceBenchmark`)
|
| 244 |
+
- Explain that this is the same corpus, same ground truth, different modality
|
| 245 |
+
- Include baseline vision results from this experiment
|
| 246 |
+
- Tag: `image-to-text`, `document-understanding`, `ocr-benchmark`, `invoice-processing`
|
| 247 |
+
|
| 248 |
+
Why this matters: there is no existing controlled invoice vision benchmark on HuggingFace with cent-perfect ground truth and five controlled dimensions. OCR benchmarks exist, but they test character recognition — this tests *comprehension*. The model must read the number AND understand the invoice logic (VAT, discounts, number formats).
|
| 249 |
+
|
| 250 |
+
### 2. HuggingFace Space (after results)
|
| 251 |
+
|
| 252 |
+
Interactive leaderboard. Visitors pick model + quantisation level, see accuracy, worst error, example failures. Could include:
|
| 253 |
+
- Results table with filters (model, quant level, number format, layout)
|
| 254 |
+
- "Gallery of failures" — side-by-side: invoice image, model output, ground truth
|
| 255 |
+
- Comparison toggle: text results (article 06) vs vision results (article 07)
|
| 256 |
+
|
| 257 |
+
Tech: Gradio or static HTML. Free hosting on HF Spaces.
|
| 258 |
+
|
| 259 |
+
Build AFTER the experiment — needs results data.
|
| 260 |
+
|
| 261 |
+
### 3. Benchmark results on model cards (optional)
|
| 262 |
+
|
| 263 |
+
HuggingFace lets you attach evaluation results to model pages. Could add InvoiceBenchmark scores to the Gemma 4 model cards so they show up when people browse models. Lower priority but good visibility.
|
| 264 |
+
|
| 265 |
+
---
|
| 266 |
+
|
| 267 |
+
## Chipspotting (Article 08?)
|
| 268 |
+
The TurboQuant / KV cache / Samsung / Jevons paradox article is a separate piece. Different experiment, different framing, different thesis. Keep it for later — it doesn't connect to the invoice series arc. See `/chipspotting-outline.md` for the full plan.
|