Skip to content

Commit 684f59f

Browse files
chore: add deprecation flag for annotations (#3001)
* chore: add deprecation flag for annotations Signed-off-by: Peter Staar <taa@zurich.ibm.com> * propagated the flag Signed-off-by: Peter Staar <taa@zurich.ibm.com> * moved keep_deprecated_annotations to _keep_deprecated_annotations Signed-off-by: Peter Staar <taa@zurich.ibm.com> --------- Signed-off-by: Peter Staar <taa@zurich.ibm.com>
1 parent 0353293 commit 684f59f

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

docling/datamodel/picture_classification_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class DocumentPictureClassifierOptions(
2525

2626
kind: ClassVar[str] = "document_picture_classifier"
2727

28+
# TODO: default should become False in a future release, and this field
29+
# may be removed entirely once docling-core drops the deprecated
30+
# `annotations` attribute from DoclingDocument items.
31+
_keep_deprecated_annotations: bool = True
32+
2833
model_spec: ImageClassificationModelSpec = Field(
2934
default_factory=lambda: stage_model_specs.IMAGE_CLASSIFICATION_DOCUMENT_FIGURE.model_spec.model_copy(
3035
deep=True

docling/datamodel/pipeline_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ class OcrMacOptions(OcrOptions):
464464
class PictureDescriptionBaseOptions(BaseOptions):
465465
"""Base configuration for picture description models."""
466466

467+
# TODO: default should become False in a future release, and this field
468+
# may be removed entirely once docling-core drops the deprecated
469+
# `annotations` attribute from DoclingDocument items.
470+
_keep_deprecated_annotations: bool = True
471+
467472
batch_size: Annotated[
468473
int,
469474
Field(

docling/models/picture_description_base_model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ def __call__(
8989

9090
for item, output in zip(elements, outputs):
9191
# FIXME: annotations is deprecated, remove once all consumers use meta.classification
92-
item.annotations.append(
93-
PictureDescriptionData(text=output, provenance=self.provenance)
94-
)
92+
if self.options._keep_deprecated_annotations:
93+
item.annotations.append(
94+
PictureDescriptionData(text=output, provenance=self.provenance)
95+
)
9596

9697
# Store classification in the new meta field
9798
if item.meta is None:

docling/models/stages/picture_classifier/document_picture_classifier.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,13 @@ def __call__(
181181
]
182182

183183
# FIXME: annotations is deprecated, remove once all consumers use meta.classification
184-
item.annotations.append(
185-
PictureClassificationData(
186-
provenance="DocumentPictureClassifier",
187-
predicted_classes=predicted_classes,
184+
if self.options._keep_deprecated_annotations:
185+
item.annotations.append(
186+
PictureClassificationData(
187+
provenance="DocumentPictureClassifier",
188+
predicted_classes=predicted_classes,
189+
)
188190
)
189-
)
190191

191192
# Store classification in the new meta field
192193
predictions = [

0 commit comments

Comments
 (0)