Spatial Coordinate Embedding Methods for Invoice Document Extraction
Spatial coordinate embeddings integrate two-dimensional bounding box locations into multi-modal transformer attention layers to extract tabular invoice fields.

Geometry
Document understanding models read structured paper inputs by mapping text position signals into vectors alongside raw optical character tokens. Standard language models process text as a linear stream, but financial documents like invoices require precise two-dimensional locations. Visual extraction engines produce bounding boxes with four cardinal coordinates: starting horizontal position, starting vertical position, ending horizontal position, and ending vertical position.
From these absolute coordinates, models learn spatial proximity between fields like invoice numbers, line item descriptions, and total amounts.
Converting raw pixel coordinates into spatial embeddings relies on fixed scaling ranges. Most architectures project bounding box coordinates onto a normalized grid running from 0 to 1000 on both horizontal and vertical axes. Normalizing coordinates this way preserves the relative layout topology whether the source image is a 72 dots per inch mobile photo or a 300 dots per inch flatbed scan.
Each normalized integer coordinate then indexes into a trainable look-up table or feeds a continuous sinusoidal projection layer, generating coordinate embedding vectors for horizontal and vertical boundaries.
| Schema Format | Resolution Scale | Token Overhead per Word | Bounding Box Quantization Error |
|---|---|---|---|
| Absolute Integer Buckets | 0 to 1000 Integer Grid | 4 Discrete Tokens | 0.10 Percent |
| Normalized Floating Vectors | 0.0 to 1.0 Continuous | 4 Dense Values | 0.00 Percent |
| Sinusoidal Spatial Encodings | Continuous Waveform | 1 Combined Vector | 0.05 Percent |
| Relative Offset Coordinates | Local Neighborhood Bounding | 2 Pairwise Offset Vectors | 0.15 Percent |
Quantization comes with practical trade-offs for layout parsing. Binning continuous image coordinates into fixed integer buckets reduces model complexity and keeps training gradients stable. But overly coarse buckets degrade spatial precision, sometimes merging distinct table rows into single visual tokens.
High-resolution bucket grids preserve fine alignment boundaries, though they expand embedding tables and memory footprints during inference.
Physical coordinate values quantized below 1,000 bins introduce alignment jitter across multi-line table structures.
Combining four coordinate values into a single token representation relies on concatenation or element-wise summation. Concatenation appends the four sub-embeddings into one wide vector, keeping each coordinate identity separate. Summation merges horizontal start, vertical start, horizontal end, vertical end, width, and height embeddings into a vector that matches the visual text token dimension.
A linear layer then projects these spatial features before they blend with visual pixel features and textual word embeddings.
Whether continuous coordinate regression can replace discrete spatial token buckets entirely remains an open question in multi-modal transformer design.

Grid
Physical scanning artifacts distort spatial coordinates before embeddings are ever calculated. Paper moving through document scanners suffers angular tilt, stretching, and edge compression. When an optical character recognition engine processes an invoice, these physical distortions shift coordinates off horizontal baselines.
A line item row skewed by just two degrees causes vertical coordinate values to drift steadily across the page width.
Bounding box normalization assumes clean horizontal and vertical alignment. In practice, invoice processing pipelines receive pages with rotational skew, uneven margins, and variable pixel density. Spatial coordinate algorithms have to preserve layout relationships across all these capture variations.
- Bounding box drift occurs when low-resolution extraction engines output shifted coordinates, misaligning adjacent word tokens across neighboring fields.
- Skew distortion rotates table rows relative to horizontal axes, giving identical row items inconsistent vertical spatial embeddings.
- Non-linear warp from mobile device cameras bends vertical alignment lines, breaking columnar relationships in line item tables.
- Sub-pixel overlap causes adjacent key-value pairs to share spatial tokens, confusing field boundaries during sequence labeling.
Spatial preprocessing adjusts coordinate matrices to clean up capture anomalies before embedding layers run. Deskewing algorithms calculate dominant text line angles across the page, rotating coordinates back to horizontal. Recalculating bounding box coordinates after deskewing provides clean, consistent inputs to embedding tables, preventing line item values from being misclassified.
Multi-page invoices introduce additional coordinate challenges across page boundaries. Page numbers, sub-totals, and header fields shift position from page to page. Normalizing on a per-page basis keeps local physical coordinates consistent, but tracking spatial relationships across multiple pages requires appending explicit page index offsets to the primary two-dimensional coordinates.
Applying skew compensation before computing coordinate embeddings consistently improves extraction accuracy over correcting raw bounding boxes downstream.

Attention
Multi-modal transformers process spatial coordinate embeddings alongside visual and textual tokens inside self-attention layers. Standard self-attention measures token interactions based strictly on content similarity and linear position. Adding spatial coordinate embeddings introduces two-dimensional geometric context, allowing tokens to evaluate physical distance and orientation across invoice pages.
Two-dimensional relative position embeddings compute pairwise distance vectors between every word token in a document. Instead of depending exclusively on absolute coordinates measured from the page origin, relative spatial mechanisms evaluate the horizontal and vertical distances separating token pairs. Tokens on the same horizontal line receive stronger positional affinity scores, reinforcing row groupings regardless of where the table sits vertically on the page.

Do Relative Spatial Embeddings Outperform Absolute Coordinates?
Absolute coordinate embeddings provide global context for field positioning, pointing out fixed locations like top-right invoice dates or bottom-right totals. Relative spatial embeddings capture local geometric structure, such as labels sitting directly to the left of or above their values. Modern layout parsing models combine both: absolute bounding box embeddings feed into sequence inputs, while relative spatial bias matrices project directly into multi-head attention weights.
Take two bounding boxes on an invoice page normalized to a 1000-by-1000 point grid. Box A holds a field label spanning from (100, 200) to (180, 215). Box B holds a candidate value spanning from (200, 200) to (260, 215).
The horizontal distance vector is 200 minus 180, or 20 points, while the vertical distance vector is 200 minus 200, or 0 points. Lookup functions map these delta values into dedicated horizontal and vertical bias matrices, giving these tokens higher spatial attention weights and signaling horizontal alignment to the transformer heads.
| Model Architecture | Spatial Embedding Technique | Line-Item F1 Score | Processing Latency per Page (ms) | GPU VRAM Usage (MB) |
|---|---|---|---|---|
| LayoutLMv1 | 1D Sequence + Absolute 2D BBoxes | 83.4 Percent | 45 | 1,240 |
| LayoutLMv2 | 2D Relative Spatial Bias + Patches | 89.1 Percent | 110 | 2,450 |
| LayoutLMv3 | Segmented 2D Relative + Visual Tokens | 92.7 Percent | 85 | 1,820 |
| Donut (End-to-End) | Implicit Visual Patch Coordinates | 86.2 Percent | 140 | 3,100 |
| PickApp Architecture | Graph-based Pairwise Coordinate Offsets | 91.5 Percent | 95 | 2,100 |
Fusing visual features adds another spatial dimension to model attention heads. Vision-language models divide document images into uniform visual patches and calculate spatial embeddings for each patch position. Mapping text bounding boxes onto these visual patch coordinates allows cross-attention layers to align pixel features directly with text tokens.
If textual coordinate grids fail to align with visual patch grids, performance drops on documents with dense tabular layouts.
- Absolute spatial embedding indexes fixed coordinate positions to identify structured form regions across standard layouts.
- Relative spatial bias modifies attention scores based on pairwise token distances, maintaining table row linkage across flexible documents.
- Visual patch embedding discretizes raw page pixels into spatial regions, capturing background structural lines and logo geometries.
- Graph edge encoding models directional spatial vectors between nearest-neighbor tokens, linking isolated label-value pairs.
Service level agreements specifying a 99 percent extraction accuracy threshold on tabular invoice line items necessitate sub-character spatial bounding box resolution.
Graph neural networks represent document fields as nodes linked by spatial edges. Nodes hold textual and local coordinate embeddings, while directional edges encode distance vectors, geometric angles, and bounding box overlap ratios. Message passing along these spatial edges lets models pass context through tabular structures, resolving complex key-value relationships even when visual spacing varies across line items.
Vision transformer encoders operate directly on patch grids to bypass the requirement for explicit bounding box coordinate embeddings.

Discrepancy
Field assignment failures usually happen when spatial embeddings cannot distinguish closely spaced elements. Invoices group numerical figures tightly ~ unit prices, quantities, net amounts, tax values, and line totals sit right next to each other. When bounding box embeddings lack fine granularity, neighboring numerical fields bleed into each other’s representations, causing models to misread tax values as net totals.
Tabular line items complicate coordinate extraction because row heights vary and column structures repeat. Multi-line descriptions create vertical coordinate gaps inside a single row, pushing models with rigid spatial thresholds to split one description into multiple line items. Multi-page tables make this coordinate drift worse whenever column header alignments shift across page breaks.
- Calculate the spatial overlap ratio between candidate bounding boxes and extracted text segments across horizontal axes.
- Map vertical distance offsets between field labels and candidate value tokens within a local neighborhood radius.
- Compute pairwise directional vectors to group multi-line descriptions into unified invoice row entities.
- Filter candidate pairings using spatial probability thresholds to eliminate cross-column line item association errors.
An horizontal alignment offset exceeding 12 pixels across multi-page invoice tables reduces header-to-line-item linkage precision from 94 percent to 67 percent.
Evaluating spatial embedding performance requires careful metric selection. Standard string-matching metrics like exact match or Levenshtein distance miss layout errors entirely. Practical extraction evaluation combines bounding box overlap metrics with semantic classification accuracy.
Models often parse text strings correctly but assign them to the wrong field because coordinate embeddings failed to capture the layout.
Misidentifying invoice totals because of spatial coordinate drift pushes wrong payment figures into enterprise resource planning systems, creating downstream reconciliation delays and audit risks.

Outlay
Embedding four spatial coordinate bounds per word token increases sequence dimensions and compute overhead during inference. Processing thousands of financial documents daily means balancing extraction accuracy against hardware capital expenditure. Adding spatial coordinate tables increases overall parameter counts, driving up graphics processing unit memory requirements during batch predictions.
| Embedding Variant | Token Multiplier | Inference Cost per 10k Pages (USD) | Throughput (Pages per Sec) | Infrastructure Memory Ceiling (GB) |
|---|---|---|---|---|
| Text Only (Baseline) | 1.00x | 4.20 | 45.0 | 8.0 |
| 1D Position + 2D BBox | 1.40x | 6.80 | 32.0 | 12.0 |
| 2D Relative + Visual Patches | 2.15x | 11.50 | 18.0 | 24.0 |
| Graph Spatial Edge Dense | 2.80x | 16.20 | 12.0 | 32.0 |
Operational trade-offs dictate which spatial coordinate scheme fits a given enterprise processing pipeline. Lightweight models using simple integer bucket embeddings run quickly on standard central processing units, keeping infrastructure costs down for basic single-page invoice templates. Complex multi-page invoices with varied tabular layouts require two-dimensional relative spatial bias models running on dedicated accelerator hardware.
Doubling spatial embedding quantization resolution increases positional token sequences by forty percent across standard commercial invoice formats.
Under standard enterprise software procurement terms, document extraction vendors cap inference resource escalation clauses at fifteen percent above baseline per-page processing charges.

