|
Download docs/TRAINING_AND_EVALUATION.md from chowderai/Glancelot: direct link, hf CLI and curl.
- Browser
- Download file 7.6 kB
-
https://huggingface.co/chowderai/Glancelot/resolve/main/docs/TRAINING_AND_EVALUATION.md
- Command line
-
hf download hf://chowderai/Glancelot/docs/TRAINING_AND_EVALUATION.md
-
curl -L -o TRAINING_AND_EVALUATION.md https://huggingface.co/chowderai/Glancelot/resolve/main/docs/TRAINING_AND_EVALUATION.md
7.6 kB
| # Glancelot training and evaluation | |
| ## What the nine outputs mean | |
| 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. | |
| The first eight outputs are auxiliary structural predictions. Their binary training targets are derived from Heron's recorded detection counts: | |
| | Output index | Target name | Target is 1 when Heron records… | | |
| | --- | --- | --- | | |
| | 0 | `has_table` | At least one `table` | | |
| | 1 | `has_picture` | At least one `picture` | | |
| | 2 | `has_formula` | At least one `formula` | | |
| | 3 | `has_code` | At least one `code` | | |
| | 4 | `has_doc_index` | At least one `document_index` | | |
| | 5 | `has_checkbox` | At least one `checkbox_selected` **or** `checkbox_unselected` | | |
| | 6 | `has_form` | At least one `form` | | |
| | 7 | `has_kv_region` | At least one `key_value_region` | | |
| | 8 | `needs_layout_analysis` | Any of targets 0–7 is 1 | | |
| ### How the routing target is defined | |
| The **`needs_layout_analysis`** target flags pages using Heron's recorded structural detections. This target is a training policy, not an independent assessment of whether layout analysis will improve extraction. | |
| 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. | |
| 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. | |
| ### Why these categories define the routing target | |
| Using every Heron category as a positive trigger would send many ordinary text pages to layout analysis because headers, footers, and other text elements are common. The routing rule selects structures that may justify the additional processing. | |
| The rule was revised after an earlier model's false-negative audit. Titles, captions, and footnotes accounted for 52% of that model's false negatives at its 99%-recall operating point. At 224×224 resolution, a footnote can resemble a page footer and a title can resemble a section heading. Assigning opposite routing labels to visually similar text roles made the thumbnail-classification task harder. The rule was changed so those three categories no longer trigger a positive routing label. The 52% figure describes the earlier audit, not the current model's validation errors or a measured extraction-quality improvement. | |
| Structural presence is a proxy for the benefit of layout analysis. A missed Heron detection can produce an incorrect negative training label; complicated text-only pages may still benefit from layout analysis, while a decorative picture can trigger processing that adds little value. Validate the routing policy by comparing extraction quality and full-pipeline processing time with an always-run-layout baseline on fresh documents. | |
| ### Training targets versus runtime predictions | |
| The ninth **training target** is 1 when any of the eight structural targets at indices 0–7 is 1, and 0 otherwise. The ninth **prediction** is a separately learned output. Compute its score from logit 8, rather than combining the eight structural predictions; the routing and structural predictions can disagree. | |
| All nine outputs contribute to training through a shared backbone. For page routing, use `sigmoid(logits[:, 8])` and the operating threshold. The routing score is the ninth learned prediction; it does not require thresholding or combining the auxiliary predictions. | |
| ## Training and labels | |
| Glancelot was trained with eight structural outputs and one routing output: | |
| 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. | |
| 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. | |
| 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. | |
| 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 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. | |
| 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. | |
| 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. Training splits are assigned by hashing the source-path prefix, rather than randomly splitting individual pages. The source PDFs and training dataset are not included in this repository. | |
| ## Evaluation and limits | |
| These results use Heron-generated labels on the validation split used for checkpoint and threshold selection. They describe agreement with those labels, rather than an independent held-out test of extraction quality. | |
| | Validation metric | Value | | |
| | --- | --- | | |
| | Pages | 36,605 | | |
| | Pages labeled as needing layout | 29,565 | | |
| | Recall on those pages | 99.002% | | |
| | False-positive rate on pages labeled as not needing layout | 32.074% | | |
| | Pages correctly routed to skip layout | 4,782 | | |
| | Layout-positive pages incorrectly routed to skip layout | 295 | | |
| The threshold favors recall: missing an important table can damage extraction, while an unnecessary layout call adds computation. At this operating point, about 32% of pages labeled as not needing layout still run through layout analysis. | |
| Teacher labels can contain errors. The routing score is a sigmoid output; its probability calibration has not been established. Evaluate routing and downstream extraction quality on representative documents before choosing a threshold for another pipeline. The auxiliary predictions indicate possible content types, not their locations on a page. | |
| ### CPU inference time | |
| The recorded model-only measurement is **39.2 ms for 32 thumbnails**, or about **1.22 ms per page when batched**, on a Mac mini with an M2 Pro (10-core CPU, 16 GB memory). This is the median of 15 warm ONNX Runtime 1.26 runs. It excludes model loading, PDF parsing, thumbnail rendering, layout analysis, OCR, and assembly. | |
| This measurement does not establish an end-to-end speedup. Savings depend on the document mix, the cost of preparing thumbnails, and the work skipped downstream. Time the full pipeline and check extraction quality on your workload. | |