﻿# LayoutLMv3: align external OCR words, boxes, and the rendered page

Prepare LayoutLMv3 inputs with a consistent OCR source, normalized word boxes, and token alignment rather than mixing coordinate systems.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-layoutlmv3-external-ocr-coordinate-contract/
Language: en

## Preserve a shared document coordinate system

LayoutLMv3 combines document text, layout, and visual patches. Its [paper](https://arxiv.org/abs/2204.08387) includes word-patch alignment among the pretraining objectives. A downstream wrapper must therefore keep the recognized words and their spatial locations connected to the page image. A bounding-box array with the expected dimensions is not sufficient if the coordinates refer to a cropped or rotated page while the visual input represents the original document.

## Choose who performs OCR

The [Transformers processor documentation](https://huggingface.co/docs/transformers/model_doc/layoutlmv3) supports built-in OCR and externally supplied words and boxes. When supplying existing OCR results, disable the processor's OCR path with apply_ocr=False rather than allowing an unrelated second transcript to replace the intended evidence. Record the OCR engine and preprocessing used to produce those words. A change of recognizer can alter segmentation and ordering even when the visible document remains identical.

## Normalize word boxes using the correct page size

The documented word boxes use a normalized 0-1000 scale. Convert from the dimensions of the page representation in which those words were located, not from a later resized image or an unrelated crop. Preserve corner ordering and valid extents. Consider a form rotated before OCR but rendered unrotated for the model: normalization alone cannot repair the missing geometric transformation. The words must first be mapped into the same page coordinate frame as the visual evidence.

## Retain word-to-token associations

Text tokenization may split a recognized word into several subword pieces. Keep boxes and any token-classification labels aligned through the checkpoint's processor rather than zipping raw words directly against model output positions. Truncation also needs a visible policy, because a form's final fields may disappear from the textual input while their pixels remain on the page. The [official implementation](https://github.com/microsoft/unilm/tree/master/layoutlmv3) provides the original task and model context for validating a chosen downstream head.

## Inspect a form before scaling the pipeline

Overlay the prepared word boxes on the exact input page and compare a token-label sample with the original words. Use held-out document layouts and retain the source mapping for each prediction. Existing guides on [image coordinate transformations](/journal/data-guide-image-exif-box-coordinate/) and [document-level splits](/journal/document-level-data-split-leakage/) explain adjacent issues. LayoutLMv3's specific integration obligation is multimodal agreement: text, token positions, normalized geometry, and image patches must describe the same document evidence.
