Skip to content

Commit a515f28

Browse files
feat: Introduce the OcrMode.PDF_CLUSTER_OCR and sunset the PDF_BITMAPS_ONLY
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
1 parent 6efa217 commit a515f28

6 files changed

Lines changed: 264 additions & 115 deletions

File tree

docling/cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def convert( # noqa: C901
774774
...,
775775
help="Which document regions are fed to the OCR engine.",
776776
),
777-
] = OcrMode.PDF_BITMAPS_ONLY,
777+
] = OcrMode.PDF_CLUSTER_OCR,
778778
tables: Annotated[
779779
bool,
780780
typer.Option(

docling/datamodel/pipeline_options.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime
44
from enum import Enum
55
from pathlib import Path
6-
from typing import Annotated, Any, ClassVar, Literal, Optional, Union
6+
from typing import Annotated, Any, ClassVar, Literal
77

88
from docling_core.types.doc import PictureClassificationLabel
99
from pydantic import (
@@ -103,9 +103,12 @@ class OcrMode(str, Enum):
103103
# Layout detections only. No PDF information is needed/used.
104104
CLUSTER_OCR = "cluster_ocr"
105105

106+
# Eliminate those clusters that contain exclusively text PDF cells
107+
PDF_CLUSTER_OCR = "pdf_cluster_ocr"
108+
106109
# TODO: Sunset this mode
107110
# Only bitmaps embedded inside a programmatic PDF. No layout information is used.
108-
PDF_BITMAPS_ONLY = "pdf_bitmaps_only"
111+
# PDF_BITMAPS_ONLY = "pdf_bitmaps_only"
109112

110113

111114
class TableFormerMode(str, Enum):
@@ -199,11 +202,12 @@ class OcrOptions(BaseOptions):
199202
description="Which document regions to feed as input to the OCR",
200203
examples=[
201204
OcrMode.FULL_PAGE_OCR,
202-
OcrMode.PDF_BITMAPS_ONLY,
203205
OcrMode.CLUSTER_OCR,
206+
OcrMode.PDF_CLUSTER_OCR,
207+
# OcrMode.PDF_BITMAPS_ONLY,
204208
],
205209
),
206-
] = OcrMode.PDF_BITMAPS_ONLY
210+
] = OcrMode.PDF_CLUSTER_OCR
207211

208212
lang: Annotated[
209213
list[str],
@@ -226,16 +230,16 @@ class OcrOptions(BaseOptions):
226230
),
227231
),
228232
] = False
229-
bitmap_area_threshold: Annotated[
230-
float,
231-
Field(
232-
description=(
233-
"Percentage of the page area for a PDF bitmap to be processed with OCR."
234-
"It is used when OcrMode is PDF_BITMAPS_ONLY"
235-
),
236-
examples=[0.05, 0.1],
237-
),
238-
] = 0.05
233+
# bitmap_area_threshold: Annotated[
234+
# float,
235+
# Field(
236+
# description=(
237+
# "Percentage of the page area for a PDF bitmap to be processed with OCR."
238+
# "It is used when OcrMode is PDF_BITMAPS_ONLY"
239+
# ),
240+
# examples=[0.05, 0.1],
241+
# ),
242+
# ] = 0.05
239243

240244
@model_validator(mode="after")
241245
def _apply_force_full_page_ocr(self) -> "OcrOptions":
@@ -315,19 +319,19 @@ class RapidOcrOptions(OcrOptions):
315319
),
316320
] = 0.5
317321
use_det: Annotated[
318-
Optional[bool],
322+
bool | None,
319323
Field(
320324
description="Enable text detection stage. If None, uses RapidOCR default behavior."
321325
),
322326
] = None
323327
use_cls: Annotated[
324-
Optional[bool],
328+
bool | None,
325329
Field(
326330
description="Enable text direction classification stage. If None, uses RapidOCR default behavior."
327331
),
328332
] = None
329333
use_rec: Annotated[
330-
Optional[bool],
334+
bool | None,
331335
Field(
332336
description="Enable text recognition stage. If None, uses RapidOCR default behavior."
333337
),
@@ -339,38 +343,38 @@ class RapidOcrOptions(OcrOptions):
339343
),
340344
] = False
341345
det_model_path: Annotated[
342-
Optional[str],
346+
str | None,
343347
Field(
344348
description="Custom path to text detection model. If None, uses default RapidOCR model."
345349
),
346350
] = None
347351
cls_model_path: Annotated[
348-
Optional[str],
352+
str | None,
349353
Field(
350354
description="Custom path to text classification model. If None, uses default RapidOCR model."
351355
),
352356
] = None
353357
rec_model_path: Annotated[
354-
Optional[str],
358+
str | None,
355359
Field(
356360
description="Custom path to text recognition model. If None, uses default RapidOCR model."
357361
),
358362
] = None
359363
rec_keys_path: Annotated[
360-
Optional[str],
364+
str | None,
361365
Field(
362366
description="Custom path to recognition keys file. If None, uses default RapidOCR keys."
363367
),
364368
] = None
365369
rec_font_path: Annotated[
366-
Optional[str],
370+
str | None,
367371
Field(
368372
description="Deprecated. Use font_path instead.",
369373
deprecated=True,
370374
),
371375
] = None
372376
font_path: Annotated[
373-
Optional[str],
377+
str | None,
374378
Field(
375379
description="Custom path to font file for text rendering in visualization."
376380
),
@@ -442,7 +446,7 @@ class EasyOcrOptions(OcrOptions):
442446
),
443447
] = ["fr", "de", "es", "en"]
444448
use_gpu: Annotated[
445-
Optional[bool],
449+
bool | None,
446450
Field(
447451
description=(
448452
"Enable GPU acceleration for EasyOCR. If None, automatically detects and uses GPU if available. "
@@ -460,7 +464,7 @@ class EasyOcrOptions(OcrOptions):
460464
),
461465
] = 0.5
462466
model_storage_directory: Annotated[
463-
Optional[str],
467+
str | None,
464468
Field(
465469
description=(
466470
"Directory path for storing downloaded EasyOCR models. If None, uses default EasyOCR cache location. "
@@ -469,7 +473,7 @@ class EasyOcrOptions(OcrOptions):
469473
),
470474
] = None
471475
recog_network: Annotated[
472-
Optional[str],
476+
str | None,
473477
Field(
474478
description=(
475479
"Recognition network architecture to use. Options: `standard` (default, balanced), `craft` (higher "
@@ -524,7 +528,7 @@ class TesseractCliOcrOptions(OcrOptions):
524528
),
525529
] = "tesseract"
526530
path: Annotated[
527-
Optional[str],
531+
str | None,
528532
Field(
529533
description=(
530534
"Path to Tesseract data directory containing language files. If None, uses Tesseract's default "
@@ -533,7 +537,7 @@ class TesseractCliOcrOptions(OcrOptions):
533537
),
534538
] = None
535539
psm: Annotated[
536-
Optional[int],
540+
int | None,
537541
Field(
538542
description=(
539543
"Page Segmentation Mode for Tesseract. Values 0-13 control how Tesseract segments the page. "
@@ -560,7 +564,7 @@ class TesseractOcrOptions(OcrOptions):
560564
),
561565
] = ["fra", "deu", "spa", "eng"]
562566
path: Annotated[
563-
Optional[str],
567+
str | None,
564568
Field(
565569
description=(
566570
"Path to Tesseract data directory containing language files. If None, uses Tesseract's default "
@@ -569,7 +573,7 @@ class TesseractOcrOptions(OcrOptions):
569573
),
570574
] = None
571575
psm: Annotated[
572-
Optional[int],
576+
int | None,
573577
Field(
574578
description=(
575579
"Page Segmentation Mode for Tesseract. Values 0-13 control how Tesseract segments the page. "
@@ -718,7 +722,7 @@ class PictureDescriptionBaseOptions(BaseOptions):
718722
),
719723
] = 0.05
720724
classification_allow: Annotated[
721-
Optional[list[PictureClassificationLabel]],
725+
list[PictureClassificationLabel] | None,
722726
Field(
723727
description=(
724728
"List of picture classification labels to allow for description. Only pictures classified with these "
@@ -728,7 +732,7 @@ class PictureDescriptionBaseOptions(BaseOptions):
728732
),
729733
] = None
730734
classification_deny: Annotated[
731-
Optional[list[PictureClassificationLabel]],
735+
list[PictureClassificationLabel] | None,
732736
Field(
733737
description=(
734738
"List of picture classification labels to exclude from description. Pictures classified with these "
@@ -1004,7 +1008,7 @@ class VlmConvertOptions(StagePresetMixin, VlmEngineOptionsMixin, BaseModel):
10041008
default=2.0, description="Image scaling factor for preprocessing"
10051009
)
10061010

1007-
max_size: Optional[int] = Field(
1011+
max_size: int | None = Field(
10081012
default=None, description="Maximum image dimension (width or height)"
10091013
)
10101014

@@ -1040,7 +1044,7 @@ class CodeFormulaVlmOptions(StagePresetMixin, VlmEngineOptionsMixin, BaseModel):
10401044
default=2.0, description="Image scaling factor for preprocessing"
10411045
)
10421046

1043-
max_size: Optional[int] = Field(
1047+
max_size: int | None = Field(
10441048
default=None, description="Maximum image dimension (width or height)"
10451049
)
10461050

@@ -1222,7 +1226,7 @@ class PipelineOptions(BaseOptions):
12221226
"""
12231227

12241228
document_timeout: Annotated[
1225-
Optional[float],
1229+
float | None,
12261230
Field(
12271231
description=(
12281232
"Maximum processing time in seconds before aborting document conversion. When exceeded, the pipeline "
@@ -1264,7 +1268,7 @@ class PipelineOptions(BaseOptions):
12641268
),
12651269
] = False
12661270
artifacts_path: Annotated[
1267-
Optional[Union[Path, str]],
1271+
Path | str | None,
12681272
Field(
12691273
description=(
12701274
"Local directory containing pre-downloaded model artifacts (weights, configs). If None, models are "
@@ -1424,7 +1428,7 @@ class VlmPipelineOptions(PaginatedPipelineOptions):
14241428
),
14251429
] = False
14261430
vlm_options: Annotated[
1427-
Union[VlmConvertOptions, InlineVlmOptions, ApiVlmOptions],
1431+
VlmConvertOptions | InlineVlmOptions | ApiVlmOptions,
14281432
Field(
14291433
description=(
14301434
"Vision-Language Model configuration for document understanding. Uses new VlmConvertOptions "
@@ -1722,7 +1726,7 @@ class HeadingHierarchyOptions(BaseModel):
17221726
),
17231727
] = True
17241728
numbering_schemes: Annotated[
1725-
Optional[list[str]],
1729+
list[str] | None,
17261730
Field(
17271731
description=(
17281732
"Optional override of the numbering-scheme precedence (highest level first). "

0 commit comments

Comments
 (0)