Explain Glancelot targets, training, and document routing
Browse files
README.md
CHANGED
|
@@ -18,20 +18,29 @@ inference: false
|
|
| 18 |
|
| 19 |
# Glancelot
|
| 20 |
|
| 21 |
-
Glancelot is the page-triage
|
| 22 |
|
| 23 |
The model has 1.53M parameters. Its job is focused: help the pipeline skip larger model calls on pages that can be handled by native-text extraction. The amount of work saved depends on the documents and the surrounding pipeline.
|
| 24 |
|
| 25 |
## How Chowder uses it
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
Layout analysis identifies page structure. OCR recovers text from images. Chowder determines OCR needs separately, so selecting hybrid extraction does not automatically mean running OCR.
|
| 33 |
|
| 34 |
-
You can use Glancelot in another PDF pipeline too. The model accepts thumbnails, not PDF files; your pipeline supplies page checks, rendering, and extraction.
|
| 35 |
|
| 36 |
## Model details
|
| 37 |
|
|
@@ -46,7 +55,37 @@ You can use Glancelot in another PDF pipeline too. The model accepts thumbnails,
|
|
| 46 |
| Operating threshold | `0.20900137722492218`, read from `config.json` |
|
| 47 |
| License | CC BY-SA 4.0 |
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
## Files
|
| 52 |
|
|
@@ -118,11 +157,27 @@ Different rendering or preprocessing can change scores, especially near the rout
|
|
| 118 |
|
| 119 |
## Training and labels
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
## Evaluation and limits
|
| 128 |
|
|
|
|
| 18 |
|
| 19 |
# Glancelot
|
| 20 |
|
| 21 |
+
Glancelot is the multi-label page-triage classifier used by Chowder's `read_documents()` table function to decide which PDF pages need layout analysis. It scores a 224×224 page thumbnail so Chowder can choose between fast native-text extraction and a richer extraction path.
|
| 22 |
|
| 23 |
The model has 1.53M parameters. Its job is focused: help the pipeline skip larger model calls on pages that can be handled by native-text extraction. The amount of work saved depends on the documents and the surrounding pipeline.
|
| 24 |
|
| 25 |
## How Chowder uses it
|
| 26 |
|
| 27 |
+
Within `read_documents()`, Chowder chooses a path for each PDF page:
|
| 28 |
|
| 29 |
+
```text
|
| 30 |
+
PDF page
|
| 31 |
+
→ Rule-based checks
|
| 32 |
+
→ Empty: return an empty page result
|
| 33 |
+
→ Scan or other non-empty page without extractable text: hybrid extraction
|
| 34 |
+
→ Remaining pages: Glancelot
|
| 35 |
+
→ sigmoid(output[8]) > threshold: hybrid extraction
|
| 36 |
+
→ sigmoid(output[8]) <= threshold: fast native-text extraction
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
**Fast native-text extraction** organizes text already stored in the PDF with geometric rules, skipping layout, text-recognition, and table models. **Hybrid extraction** combines native PDF extraction with layout analysis and other models where needed.
|
| 40 |
|
| 41 |
Layout analysis identifies page structure. OCR recovers text from images. Chowder determines OCR needs separately, so selecting hybrid extraction does not automatically mean running OCR.
|
| 42 |
|
| 43 |
+
You can use Glancelot in another PDF pipeline too. The model accepts thumbnails, not PDF files; your pipeline supplies page checks, rendering, and extraction. A low score is not sufficient to send a scan or another page without extractable text down a native-text-only path.
|
| 44 |
|
| 45 |
## Model details
|
| 46 |
|
|
|
|
| 55 |
| Operating threshold | `0.20900137722492218`, read from `config.json` |
|
| 56 |
| License | CC BY-SA 4.0 |
|
| 57 |
|
| 58 |
+
## What the nine outputs mean
|
| 59 |
+
|
| 60 |
+
Glancelot is **multi-label**, rather than a multiclass classifier that chooses one mutually exclusive category. A page can contain a table, a picture, and a formula at the same time. The model returns nine raw logits from one linear output layer. A sigmoid converts each logit to a score; the nine scores do not have to sum to one.
|
| 61 |
+
|
| 62 |
+
The first eight outputs are auxiliary structural predictions. Their binary training targets are derived from Heron's recorded detection counts:
|
| 63 |
+
|
| 64 |
+
| Output index | Target name | Target is 1 when Heron records… |
|
| 65 |
+
| --- | --- | --- |
|
| 66 |
+
| 0 | `has_table` | At least one `table` |
|
| 67 |
+
| 1 | `has_picture` | At least one `picture` |
|
| 68 |
+
| 2 | `has_formula` | At least one `formula` |
|
| 69 |
+
| 3 | `has_code` | At least one `code` |
|
| 70 |
+
| 4 | `has_doc_index` | At least one `document_index` |
|
| 71 |
+
| 5 | `has_checkbox` | At least one `checkbox_selected` **or** `checkbox_unselected` |
|
| 72 |
+
| 6 | `has_form` | At least one `form` |
|
| 73 |
+
| 7 | `has_kv_region` | At least one `key_value_region` |
|
| 74 |
+
| 8 | `has_any_interesting` | Any of targets 0–7 is 1 |
|
| 75 |
+
|
| 76 |
+
### How the routing target is defined
|
| 77 |
+
|
| 78 |
+
In the training code, an **“interesting” page** means a page labeled as needing layout analysis under this structural rule. It does not mean that the page is relevant to a user's query or contains important information in a broader sense.
|
| 79 |
+
|
| 80 |
+
For each page, the ninth target is constructed as `target[8] = int(any(target[:8]))`. It is **1** when Heron records at least one of the structures above, and **0** otherwise. The code checks whether each recorded detection count is greater than zero; it applies no additional confidence cutoff when constructing these targets.
|
| 81 |
+
|
| 82 |
+
Text, page headers, page footers, section headers, list items, footnotes, titles, and captions alone do not make the target positive. Pages with no recorded detections also receive a negative target. That teacher-derived label is a training policy, not proof that native-text extraction will preserve everything on the page.
|
| 83 |
+
|
| 84 |
+
### Training targets versus runtime predictions
|
| 85 |
+
|
| 86 |
+
The ninth **training target** is the OR of the eight auxiliary targets. The ninth **prediction** is a separately learned output. Its score is not calculated by combining the eight predicted scores, and the predictions need not agree exactly.
|
| 87 |
+
|
| 88 |
+
All nine outputs contribute to training through a shared backbone. Chowder uses only `sigmoid(logits[:, 8])` and the operating threshold for the CNN routing decision. It does not threshold or combine the auxiliary predictions to decide the route.
|
| 89 |
|
| 90 |
## Files
|
| 91 |
|
|
|
|
| 157 |
|
| 158 |
## Training and labels
|
| 159 |
|
| 160 |
+
The deployed model is the nine-output `cnn_v2` model. Its training recipe was:
|
| 161 |
+
|
| 162 |
+
1. Run Heron on the source pages and record its per-class detection counts. Build eight structural targets and the ninth routing target using the rule above. This is supervision from **hard binary labels**, not soft-logit or feature distillation.
|
| 163 |
+
2. Prepare RGB page thumbnails at 224×224. Normalize them with the ImageNet mean and standard deviation. Training adds light brightness/contrast jitter and random crops with eight-pixel edge padding, without flips or rotations.
|
| 164 |
+
3. Start from an ImageNet-pretrained MobileNetV3-Small backbone. Add dropout of 0.2 and a `Linear(1024, 9)` output layer. Fine-tune the backbone and output layer together.
|
| 165 |
+
4. Optimize binary cross-entropy with logits across all nine outputs. Each output uses a positive-class weight based on its training-split negative/positive count ratio, clipped to `[0.5, 50]`. The original run records specify AdamW, a learning rate of `0.002`, batch size 1,024, and a 25-epoch schedule. The implementation uses weight decay of `0.0001`, cosine learning-rate decay, and FP16 mixed precision on CUDA.
|
| 166 |
+
5. Select the checkpoint using validation recall on the routing output at a false-positive-rate budget of 30%. Then sweep the selected checkpoint's routing threshold to target 99% validation recall. Export the selected weights as a single FP32 ONNX file.
|
| 167 |
+
|
| 168 |
+
The combined source pool contains approximately 1.29M PDF page thumbnails, including pages reserved for evaluation. Sources include financial filings, investor-relations materials, research papers, clinical-trial documents, and slides. The original implementation assigns splits by hashing the source-path prefix, rather than randomly splitting individual pages. The source PDFs and training dataset are not included in this repository.
|
| 169 |
+
|
| 170 |
+
### Training source
|
| 171 |
+
|
| 172 |
+
The original implementation is in the private [`JohnsonKuan/chonk-triage-model`](https://github.com/JohnsonKuan/chonk-triage-model) repository. These links pin the inspected implementation at commit `7ff2365439f6c7ce9cc5b1f16c728300a0a868eb`:
|
| 173 |
|
| 174 |
+
- [`data.py`](https://github.com/JohnsonKuan/chonk-triage-model/blob/7ff2365439f6c7ce9cc5b1f16c728300a0a868eb/chonk_triage_model/cnn_v2/data.py): target construction, source-prefix splits, transforms, and class weights.
|
| 175 |
+
- [`model.py`](https://github.com/JohnsonKuan/chonk-triage-model/blob/7ff2365439f6c7ce9cc5b1f16c728300a0a868eb/chonk_triage_model/cnn_v2/model.py): backbone and nine-output layer.
|
| 176 |
+
- [`train.py`](https://github.com/JohnsonKuan/chonk-triage-model/blob/7ff2365439f6c7ce9cc5b1f16c728300a0a868eb/chonk_triage_model/cnn_v2/train.py): optimization, validation, and checkpoint selection.
|
| 177 |
+
- [`eval_threshold.py`](https://github.com/JohnsonKuan/chonk-triage-model/blob/7ff2365439f6c7ce9cc5b1f16c728300a0a868eb/chonk_triage_model/cnn_v2/eval_threshold.py): operating-threshold selection.
|
| 178 |
+
- [`export_onnx.py`](https://github.com/JohnsonKuan/chonk-triage-model/blob/7ff2365439f6c7ce9cc5b1f16c728300a0a868eb/chonk_triage_model/cnn_v2/export_onnx.py): FP32 ONNX export.
|
| 179 |
|
| 180 |
+
These sources document the deployed model's training implementation. They are not a complete public reproduction bundle: the training data and exact historical environment are not included here. Later experiments in the separately named `glancer` repository are not the weights hosted in this model repo.
|
| 181 |
|
| 182 |
## Evaluation and limits
|
| 183 |
|