Skip to content

API Reference parrot_loaders.ocr.layoutlm

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_loaders.ocr.layoutlm

View source

LayoutLMv3 semantic layout analyzer for parrot_loaders.

Uses Microsoft's layoutlmv3-base model to classify OCR tokens into semantic categories: title, paragraph, table, list, figure, and caption.

All heavy dependencies (transformers, torch) are guarded with try/except both at module level and inside __init__. If either dependency is absent the class can still be imported; only instantiation will raise ImportError.

Class LayoutLMv3Analyzer

Semantic layout analyzer using LayoutLMv3 token classification.

Loads microsoft/layoutlmv3-base with apply_ocr=False (we supply our own OCR results) and classifies each word token into one of the semantic label categories defined in :attr:LABEL_MAP.

All model-related imports are deferred to __init__ so the class is importable even when transformers / torch are not installed.

Parameter Type Default Description
model_name str 'microsoft/layoutlmv3-base' HuggingFace model identifier.

Attributes:

Attribute Type Description
LABEL_MAP Mapping from integer prediction index to semantic label string.

Method LayoutLMv3Analyzer.analyze

Classify OCR blocks into semantic regions using LayoutLMv3.

analyze(blocks: List[OCRBlock], image: Image.Image) -> LayoutResult

Parameter Type Default Description
blocks List[OCRBlock] OCR blocks containing text and bounding boxes.
image Image.Image The PIL image corresponding to the OCR blocks (used by the LayoutLMv3 processor for visual features).

Returns: LayoutResult — class:LayoutResult with lines labelled by semantic type.

Alias LayoutLine

Re-exported from parrot_loaders.ocr.models.LayoutLine.

Alias LayoutResult

Re-exported from parrot_loaders.ocr.models.LayoutResult.

Alias OCRBlock

Re-exported from parrot_loaders.ocr.models.OCRBlock.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally