Skip to content

Repository files navigation

CART-Doc

CART-Doc is a compact document key information extraction (KIE) framework that selectively applies local visual processing to OCR regions. The model combines a DistilBERT text path, normalized OCR geometry, a preliminary BIO classifier, confidence-based top-K routing, MobileNetV3 crop encoding, and gated visual fusion.

cart_doc

Repository structure

cart_doc/ Python package
config/ Default experiment configuration
data/ Dataset loading and normalization
models/ CART-Doc and baseline models
scripts/ Single-run training/evaluation entry point
train/ Training, inference, metrics, and routing diagnostics
utils/ Logging and memory utilities
scripts/ Experiment orchestration and analysis
configs/ Dataset-format documentation
external/ Reference baseline helpers
tests/ Unit tests

Installation

Python 3.10 or newer is recommended.

python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .
pytest -q

For GPU training, install a PyTorch build compatible with the local CUDA driver before installing the remaining dependencies if required by your system.

Datasets

CORD v2

CORD v2 is loaded from naver-clova-ix/cord-v2 through Hugging Face Datasets. Images, OCR words, semantic categories, and bounding boxes are converted into the BIO representation used by the models.

BuDDIE

BuDDIE visual/layout experiments require a multimodal manifest containing page images, OCR tokens, bounding boxes, BIO labels, entity dictionaries, and document classes. See configs/buddie_manifest.md for the required JSONL format.

Quick start

Run the complete CORD v2 experiment suite:

./run_experiments.sh cord_v2 results/experiments

Run BuDDIE using a prepared manifest:

./run_experiments.sh buddie results/experiments \
--buddie-manifest-dir /path/to/buddie_manifest

The default experiment seeds are 42, 7, and 123. Routing budgets are selected on validation data from 64, 96, 128, and 192 before test evaluation.

Run individual stages

python scripts/run_experiments.py --dataset cord_v2 --results-root results/experiments --stage audit
python scripts/run_experiments.py --dataset cord_v2 --results-root results/experiments --stage baselines
python scripts/run_experiments.py --dataset cord_v2 --results-root results/experiments --stage routing_train
python scripts/run_experiments.py --dataset cord_v2 --results-root results/experiments --stage routing_test
python scripts/run_experiments.py --dataset cord_v2 --results-root results/experiments --stage router_ablations
python scripts/run_experiments.py --dataset cord_v2 --results-root results/experiments --stage postprocess

A single model can be trained directly, for example:

python -m cart_doc.scripts.train_model \
--model cart_doc \
--dataset cord_v2 \
--seed 42 \
--output-dir results/experiments \
--run-name confidence_k96 \
--route-k 96 \
--router-mode confidence

Supported model keys are distilbert, lilt, layoutlmv3, ltrf_doc, and cart_doc.

Supported CART-Doc router modes are confidence, learned, and hybrid.

Experiment protocol

The experiment runner separates model selection from test evaluation:

  1. audit dataset integrity and label coverage;
  2. train baseline models across the configured seeds;
  3. train routing-budget candidates using validation data;
  4. select and lock the routing budget;
  5. evaluate the routing sweep on the test split;
  6. train the selected CART-Doc configuration across the configured seeds;
  7. run text-layout, learned-router, and hybrid-router ablations;
  8. aggregate metrics, routing diagnostics, bootstrap comparisons, and qualitative examples.

The label vocabulary is constructed from training data. For CART-Doc, routing operates only over valid first-subtoken OCR units and uses K_d = min(K, n_d) for each document.

Outputs

Each run writes to:

results/experiments/<dataset>/<model>/<run_name>/seed_<seed>/

Typical files include:

manifest.json
checkpoints/
logs/
metrics/
predictions/
artifacts/

Dataset-level summaries are written to:

results/experiments/<dataset>/reports/

They include multi-seed mean/standard-deviation tables, routing diagnostics, routing-budget sensitivity, paired bootstrap comparisons, per-document-type summaries, and qualitative routed examples.

Main analysis scripts

  • scripts/audit_dataset.py — dataset integrity and label-space audit
  • scripts/select_routing_budget.py — validation-based routing-budget selection
  • scripts/evaluate_routing_sweep.py — evaluate saved routing-budget candidates
  • scripts/aggregate_multiseed.py — aggregate metrics across seeds
  • scripts/paired_bootstrap.py — document-paired bootstrap comparisons
  • scripts/generate_qualitative_cases.py — select routed correction and failure cases
  • scripts/generate_latex_tables.py — export compact LaTeX table rows
  • scripts/verify_outputs.py — verify required experiment outputs

Reference LayoutLMv3 run

external/layoutlmv3_reference/ contains a helper for running Microsoft's LayoutLMv3 CORD example in a separate environment. The upstream implementation uses its own preprocessing and evaluation protocol, so those results should be interpreted separately from the common CART-Doc evaluator.

Citation

If you use this codebase, please cite the associated manuscript:

@inproceedings{oladele2026_cart_doc,
title = {CART-Doc: A Compact Design Space for Confidence-Routed Document Key Information Extraction},
author = {Daniel Ayo, Oladele and Malusi Sibiya},
booktitle = {The 19th International Conference on Multi-disciplinary Trends in Artificial Intelligence (MIWAI) 2026},
series = {Lecture Notes in Artificial Intelligence},
publisher = {Springer},
year = {2026}
}

Citation metadata is provided in CITATION.cff.

About

Official implementation of CART-Doc accepted at MIWAI2026

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages