Layout Prediction Data Structures#
Overview#
Docling's layout analysis pipeline converts page images into structured Cluster objects, which are the primary unit passed between layout detection, postprocessing, and document assembly stages. All data structures are defined in docling/datamodel/base_models.py and consumed by LayoutModel and the downstream assembler.
Core Data Structures#
Cluster#
Cluster is the central output of layout prediction. Fields:
| Field | Type | Description |
|---|---|---|
id | int | Sequential index within the page |
label | DocItemLabel | Structural label (e.g., TEXT, TABLE, PICTURE) |
bbox | BoundingBox | Normalized bounding box from docling-core |
confidence | float | Model confidence score (default 1.0) |
cells | list[TextCell] | PDF/OCR text cells assigned to this cluster |
children | list[Cluster] | Nested clusters (populated for wrapper types like TABLE, FORM, KEY_VALUE_REGION, DOCUMENT_INDEX) |
LayoutPrediction#
LayoutPrediction is a thin container holding a list of Cluster objects for a single page. It is stored in page.predictions.layout after the layout stage completes.
Page#
Page carries all per-page state through the pipeline:
| Field | Type | Description |
|---|---|---|
page_no | int | 1-indexed page number |
size | Size | None | Page dimensions |
parsed_page | SegmentedPdfPage | None | Raw parsed page from backend (contains textline_cells) |
predictions | PagePredictions | Slot for layout, table structure, figure, and VLM predictions |
assembled | AssembledUnit | None | Final assembled page elements (set after PageAssembleModel) |
page.cells is a property that returns parsed_page.textline_cells .
PagePredictions#
PagePredictions holds all model outputs for a page:
layout: LayoutPrediction | Nonetablestructure: TableStructurePrediction | Nonefigures_classification: FigureClassificationPrediction | Noneequations_prediction: EquationPrediction | Nonevlm_response: VlmPrediction | None
Page Element Types#
After assembly, clusters are converted into typed BasePageElement subclasses :
| Class | Used for |
|---|---|
TextElement | All TEXT_ELEM_LABELS (text, footnote, caption, headers, code, etc.) |
Table | TABLE, DOCUMENT_INDEX labels; carries table_cells, otsl_seq |
FigureElement | PICTURE; carries annotations, predicted_class, confidence |
ContainerElement | FORM, KEY_VALUE_REGION; wrapper with children |
The union type PageElement = Union[TextElement, Table, FigureElement, ContainerElement] is used throughout the assembler .
Raw Predictor Output → Cluster Conversion#
LayoutPredictor.predict_batch() (from docling-ibm-models) returns plain dicts with keys label, confidence, l, t, r, b (pixel coordinates, top-left origin) .
LayoutModel.predict_layout() converts each dict into a Cluster :
- Label normalization: The label string is lower-cased and spaces/hyphens replaced with underscores to match
DocItemLabelenum values (e.g.,"Section-header"→"section_header"). - BoundingBox construction:
BoundingBox.model_validate(pred_item)reads thel/t/r/bpixel fields directly. - Cluster instantiation:
id= sequential index within the page,cells = [](filled later by postprocessor).
After raw cluster construction, LayoutPostprocessor(page, clusters, self.options).postprocess() is called immediately, returning (processed_clusters, processed_cells) .
Label Sets Defined on LayoutModel#
LayoutModel defines label-group constants used downstream by PageAssembleModel :
| Constant | Labels |
|---|---|
TEXT_ELEM_LABELS | TEXT, FOOTNOTE, CAPTION, CHECKBOX_*, SECTION_HEADER, PAGE_HEADER/FOOTER, CODE, LIST_ITEM, FORMULA |
TABLE_LABELS | TABLE, DOCUMENT_INDEX |
FIGURE_LABEL | PICTURE |
CONTAINER_LABELS | FORM, KEY_VALUE_REGION |
Postprocessing Pipeline (Summary)#
See the Layout Postprocessor article for full details. Key transformations applied to raw clusters before they become LayoutPrediction.clusters:
- Confidence thresholding — per-label gates (0.45–0.5) filter low-confidence detections .
- Label remapping —
TITLE → SECTION_HEADER(soDocItemLabel.TITLEnever surfaces in the document) . - Cell assignment — text cells from
page.cellsare spatially matched to clusters via R-tree/interval-tree indexes; unmatched cells become newTEXTclusters ifcreate_orphan_clusters=True. - Overlap resolution — Union-Find groups overlapping clusters; one winner is selected per group using area/confidence thresholds, with separate parameters for regular, picture, and wrapper types .
- Wrapper containment — clusters ≥80% inside a
WRAPPER_TYPEbbox become itsCluster.childrenand are removed from the top-level list .
Key Source Files#
| File | Role |
|---|---|
docling/datamodel/base_models.py | Cluster, LayoutPrediction, Page, PagePredictions, all page element types |
docling/models/stages/layout/layout_model.py | Raw-dict → Cluster conversion; wires predictor → postprocessor; defines label-group constants |
docling/utils/layout_postprocessor.py | LayoutPostprocessor — all cluster filtering, cell assignment, overlap resolution |
docling_ibm_models/layoutmodel/layout_predictor.py | RT-DETR inference; emits raw {label, confidence, l, t, r, b} dicts |
docling/datamodel/pipeline_options.py | LayoutOptions, BaseLayoutOptions — controls keep_empty_clusters, skip_cell_assignment, create_orphan_clusters |