Skip to content
zohrix

Fine-tuning and evaluation pipeline for document classification

A repeatable pipeline that labels documents, fine-tunes a classifier and tests it before it reaches production.

Concept projects are detailed approaches to typical briefs. They are not client deliveries.

Overview

A repeatable pipeline that labels documents, fine-tunes a classifier and tests it before it reaches production, with people reviewing what the model is unsure about.

The challenge

Finance operations teams sort large volumes of incoming documents before anyone can act on them. General-purpose models handle common types reasonably well but struggle with an organization's own forms, and without a test set nobody can say how often they're wrong.

Our approach

The steps in the order we would take them.

  1. Agree document types, edge cases and the cost of a wrong label with the operations team.

  2. Set up labeling with written guidelines, a second review and a held-out test set.

  3. Fine-tune a compact classification model on the labeled set.

  4. Compare it with a prompted general-purpose model, type by type.

  5. Route low-confidence predictions to people and feed corrections into the next round.

What the solution includes

  • Labeling guidelines and a labeled dataset
  • A training and evaluation pipeline
  • An evaluation report by document type
  • A classification API with confidence scores
  • A retraining runbook

Technical implementation

How we would build it, in the order information moves through the system. Final choices depend on the tools a client already uses.

Documents land in object storage; OCR extracts text and layout, and personal data is masked before labeling. A versioned pipeline (Python, PyTorch, Hugging Face Transformers, MLflow) records each run's data, settings and scores. The approved model runs behind a FastAPI service.

  1. Ingestion

    Documents land in object storage. OCR extracts text and layout, and personal data is masked before labeling.

  2. Labeling

    An annotation tool holds the guidelines, records who labeled what and flags disagreements between reviewers.

  3. Training

    A versioned pipeline splits the data, fine-tunes the model and records each run's data, settings and scores.

  4. Evaluation

    A fixed test set produces precision and recall for every document type. A new model ships only if it beats the current one.

  5. Serving

    The approved model runs behind an internal API that returns a label and a confidence score, and low-confidence documents go to a review queue.

Proposed technologies

Plain tool names, not partnerships. Where a client already uses something that does the job, we use that instead.

  • Python
  • PyTorch
  • Hugging Face Transformers
  • Label Studio
  • OCR engine
  • MLflow
  • FastAPI
  • Docker

Important decisions

The trade-offs that shape the rest of the design, and why.

  • A model ships only if it beats the current one on the fixed test set.

  • Personal data is masked before anyone labels a document.

Outcome

This is a concept project. It hasn't been delivered for a client, so there are no results to report. It shows how we would approach this kind of brief.

Facing a similar problem?

Tell us about the problem you're solving. We'll reply with questions, a suggested approach and a clear next step.