Self-Scaling Shipping Document RPA
Multilingual Classification & Field Extraction without Retraining
My Role
- Embeddings plus kNN so new types need no retraining
- Fine-tune only a small head, not full XLM-R
Approach at a Glance
Details- 1Document Separation and OCR
- 2Multilingual Document Classification
- 3Scalability Module: New Types without Retraining
- 4Field Extraction
- 5Signature and QR Code Detection
Executive Summary
An RPA solution that automated document processing for a worldwide shipping and logistics company, covering transportation, warehousing, distribution, customs brokerage and logistics management. Incoming paperwork arrived as scanned documents in English and French. The system does the work people used to do by hand:
- separate the incoming documents,
- determine each one-page document's type,
- extract text from the fields that matter for that type,
- detect signatures and read QR codes.
The key feature was a scalability module: the client's staff could add new document types simply by adding sample documents, without a developer and without retraining the model. New types are recognised from XLM-RoBERTa embeddings with nearest-neighbour matching against those samples, and only a small head on top of the encoder was fine-tuned.
Across a corpus of about 250,000 documents, the system classified document types at 0.87 F1 and extracted fields at 0.90 F1 on correctly classified documents. It cut manual processing time by 8–10%. I worked hands-on as an NLP engineer in a team of 4–8 people, from July to November 2021.
Client Profile
The client is a global shipping and logistics company headquartered in Canada. Every shipment generates paperwork: bills of lading, invoices, customs forms, delivery confirmations and many other document types, in English and French and arriving as scans of uneven quality. Operators sorted these documents, recognised their types, typed key fields into systems and checked for signatures, all by hand.
Two things made automation hard. First, scanned documents are noisy, and document types often look alike. Second, and more important, the set of document types kept growing. A classifier that needs ML engineers and a full retraining cycle for every new document type would never keep up with the business.
Technical Approach
-
Document Separation and OCR – Incoming batches are split into individual one-page documents and passed through OCR (Tesseract), which turns each scan into text with its position on the page.
-
Multilingual Document Classification – An XLM-RoBERTa encoder turns each document's text into an embedding, so English and French documents of the same type land close together. We did not fine-tune the full transformer: only a small head on top of the encoder was trained to produce embeddings that separate document types well. That kept training cheap and the representation stable.
-
Scalability Module: New Types without Retraining – Classification is done by k-nearest neighbours over the embeddings of labeled sample documents. Adding a new document type therefore means adding a few sample documents of that type, with no developer and no model retraining. As soon as the samples are in the index, new documents of that type are recognised. t-SNE projections of the embedding space were used to check that document types form clean, well-separated clusters.
-
Field Extraction – For each document type, the system extracts the text of predefined fields from the OCR output and classifies which field each piece of text belongs to, at 0.90 F1 on correctly classified documents.
-
Signature and QR Code Detection – The pipeline also detects whether a document is signed and reads QR codes, two checks operators previously did by eye.
Business Outcome
The shipping company replaced a large share of manual document handling with an automated pipeline that classifies, extracts and checks documents in English and French. Across about 250,000 documents, it classified document types at 0.87 F1 and extracted fields at 0.90 F1, and it saved 8–10% of manual processing time.
The lasting value was the scalability module. Because new document types could be added by the business itself, just by providing samples, the system kept up as the document landscape changed, without an ML engineer in the loop. This was a few-shot design in 2021, well before such approaches became mainstream.
Technologies
Planning something similar?
Tell me about it on a short call. New projects can start within 2 weeks