flowchart LR
IN[PDF / images / text] --> S1[1 · Document Processing]
S1 --> S2[2 · Classification]
S2 --> S3[3 · Information Extraction]
S3 --> OUT[4 · Aggregate + respond]DICIE Pipeline
Paper Fig. 1 — process → classify → extract → respond
DICIE
Implements the Document Image Classification and Information Extraction chain from Raj, Dickinson & Fung, Document Classification and Information Extraction framework for Insurance Applications.
This module (src/docie/) is image-first and application-scoped. It complements the existing markdown → classify → extract → vision → summarize chain in src/pipeline/, which remains the general ACORD intake / memo path.
Applications (paper §III)
| Application | Classes | Extracted fields | Taxonomy |
|---|---|---|---|
medical_bills |
hcfa, ub04, other |
claim_id, name, dob, patient_id, address | taxonomy/medical_bills.yaml |
salvage_claims |
log, sales, other |
claim_id, vin, year, make, model | taxonomy/salvage_claims.yaml |
acord |
ACORD intake taxonomy | claim / policy / loss fields | taxonomy/acord_form_categories.yaml |
Each taxonomy may define:
categories— labels + aliases used by Stage 2 heuristicsextraction_fields— Stage 3 field setbusiness_rules.prefer_non_other— prefer non-otheron classification tiesbusiness_rules.review_confidence_threshold— human-review gate (default0.55)
Stages
1. Document Processing (src/docie/processing.py)
- PDF → page images via PyMuPDF at configurable DPI (default 300)
- Image preprocessing: grayscale conversion, retain dimensions
- OCR via PyTesseract when installed (
pip install -e ".[ocr]"), with PDF text-layer fallback; produces word tokens + 0–1000 normalized boxes for LayoutLM-style extractors - Plain text inputs are rendered to a page image so the image-first chain stays intact
- Cached page images under
data/pipeline/cache/docie/<application>/pages/
2. Document Classification (src/docie/classify.py)
- Per-page scoring (keyword / alias heuristics; optional ViT when weights match)
- Document-level aggregation: confidence-weighted majority vote
- Business rule: prefer non-
otheron ties (paper medical / salvage setups)
3. Information Extraction (src/docie/extract.py)
- Field extraction conditioned on the predicted document type
- LayoutLM / token-classifier weights when present under
models/extractor* - Regex heuristics covering medical + salvage field patterns otherwise
- Missing expected fields (e.g. LOG without VIN) lower confidence and flag review
4. Output aggregation (src/docie/aggregate.py)
- Merge classification + extraction
- Route low-confidence / OCR-empty / missing-field cases to human review
- Compact
response_payload()for REST / claim-center downstream updates - Optional
downstream_sinkcallback for webhooks / queue publishers
Evaluation (paper Table I / Table II)
Classification reports accuracy + AUC (OVR/OVO); extraction reports per-field precision / recall / F1 (harmonic mean (2PR/(P+R))).
python -m src.docie.eval --all
python -m src.docie.eval --application salvage_claims
# Writes evaluation/reports/docie_{application}_{metrics.json,report.md}Gold set: data/eval/docie_eval_set.jsonl.
For a larger regenerable sample house (claim bundles, richer skeletons, train/val/test splits), use the SQLite corpus in src/storage/ — see Sample Document Corpus. Export DICIE JSONL with python -m src.storage export --format docie.
Usage
# Salvage Letter of Guarantee (text demo)
python -m src.docie \
--application salvage_claims \
--text "LETTER OF GUARANTEE
Claim Number: CLM-2024-100200
VIN: 1HGCM82633A004352
Year: 2018
Make: Honda
Model: Accord" \
--response-only
# Medical HCFA PDF / image
python -m src.docie --application medical_bills --pdf path/to/bill.pdf
python -m src.docie --application medical_bills --image path/to/page.png
# Batch JSONL
python -m src.docie \
--application salvage_claims \
--in tests/fixtures/sample_docie_documents.jsonl \
--out data/pipeline/docie/salvage_demo.jsonlBatch outputs:
| Artifact | Description |
|---|---|
*.jsonl |
Full prediction rows (DociePrediction.to_dict()) |
*.summary.json |
Counts, label histogram, mean confidences |
*.human_review.jsonl |
Compact payloads with needs_human_review=true |
data/provenance_log.jsonl |
Provenance row (stage=docie_pipeline) |
Optional FastAPI server (paper §VI ECS/FastAPI serving shape):
pip install -e ".[serve]"
python -m src.docie.serve --application salvage_claims --port 8080
# GET /health
# POST /v1/predict (multipart file)
# POST /v1/predict/text (JSON {text, application, record_id})Python entry points:
from src.docie import DociePipeline, process_document
process_document(application="salvage_claims", text="LETTER OF GUARANTEE\n...")
pipe = DociePipeline(application="medical_bills")
prediction = pipe.process(record_id="x", pdf_path="bill.pdf")See src/docie/README.md for the full CLI flag list, prediction schema, and REST contract.
Relation to the chained analysis orchestrator
| Concern | src/docie/ (this module) |
src/pipeline/ |
|---|---|---|
| Ordering | process → classify → extract → respond | markdown → classify → extract → vision → summarize |
| Primary signal | page images + OCR | structured markdown for LLM context |
| Applications | medical bills, salvage claims | ACORD intake + adjuster memo |
| Output | classification + fields (+ review flag) | classification + fields + memo |
| Front-ends | CLI + optional FastAPI | CLI + Discord (/analyze) |
Use DICIE when matching the paper flowchart / insurance workflow apps; use the chained orchestrator when you need markdown-first LLM memos.
Testing & fixtures
pytest tests/test_docie_pipeline.py -qSynthetic fixtures (no real insurer data): tests/fixtures/sample_docie_documents.jsonl.
Optional extras
| Extra | Purpose |
|---|---|
.[ocr] |
PyTesseract OCR for scanned pages |
.[serve] |
FastAPI + uvicorn REST server |
.[dev] |
pytest + ruff for local development |
Trained ViT / LayoutLM weights are optional; heuristic backends keep the chain runnable without them.
See also
Pipeline hub · Architecture · Sample corpus · DICIE notebook · Data Provenance