Skip to main content

Text metrics

Project description

Docling metrics for document layout analysis

Overview

The following metrics are used:

  • Mean Average Precision.
  • pixel-wise multi-label confusion matrix.

Installation

uv sync --all-packages

Usage

import logging
from pathlib import Path

from docling_metrics_layout import (
    LayoutMetrics,
    LayoutMetricSample,
)
from docling_metrics_layout.layout_types import LayoutMetricDatasetEvaluation

# Data
DATA = {
    "id": "page_001",
    "page_width": 612,
    "page_height": 792,
    "page_resolution_a": [
        {"category_id": 1, "bbox": [50.0, 80.0, 300.0, 200.0], "score": 0.97},
        {"category_id": 2, "bbox": [310.0, 80.0, 560.0, 200.0], "score": 0.91},
        {"category_id": 1, "bbox": [50.0, 220.0, 560.0, 380.0], "score": 0.88},
        {"category_id": 3, "bbox": [50.0, 400.0, 300.0, 500.0], "score": 0.76},
    ],
    "page_resolution_b": [
        {"category_id": 1, "bbox": [52.0, 82.0, 298.0, 202.0], "score": 0.95},
        {"category_id": 2, "bbox": [312.0, 78.0, 558.0, 199.0], "score": 0.89},
        {"category_id": 1, "bbox": [48.0, 218.0, 562.0, 382.0], "score": 0.85},
    ],
}

CATEGORIES = {1: "red", 2: "orange", 3: "green", 4: "blue"}

REPORT_DIR = "reports/"


def setup_logging():
    log_format = "%(asctime)s - %(levelname)s - %(message)s"
    logging.basicConfig(level=logging.INFO, format=log_format)


def demo():
    # Load the data as list[LayoutMetricSample]
    samples = [LayoutMetricSample.model_validate(DATA)]

    # Evaluate
    lm = LayoutMetrics(CATEGORIES, save_root=Path(REPORT_DIR))
    evaluation: LayoutMetricDatasetEvaluation = lm.evaluate_dataset(samples)

    # mAP metrics
    map_eval = evaluation.dataset_map_layout_evaluation
    print(f"\nmAP:         {map_eval.map:.4f}")
    print(f"mAP per class: {map_eval.map_per_class}")

    # TORE metrics
    tore_matrix = evaluation.dataset_tore_evaluation.matrix_evaluation.detailed
    print(f"\nPrecision matrix:\n{tore_matrix.precision_matrix}")
    print(f"\nRecall matrix:\n{tore_matrix.recall_matrix}")

    # Report files
    print("\nReport files:")
    for f in evaluation.reports:
        print(f"  {f.name}")


if __name__ == "__main__":
    setup_logging()
    demo()

Links

Multi-Label Classifier Performance Evaluation with Confusion Matrix

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docling_metrics_layout-0.9.0.tar.gz (33.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docling_metrics_layout-0.9.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file docling_metrics_layout-0.9.0.tar.gz.

File metadata

  • Download URL: docling_metrics_layout-0.9.0.tar.gz
  • Upload date:
  • Size: 33.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for docling_metrics_layout-0.9.0.tar.gz
Algorithm Hash digest
SHA256 89b3e84d8e29c873f90a26845f19c6026bfd0141901de30fafa095774e1cbe65
MD5 2ab47187d84ead0f6f7879813e5a4a00
BLAKE2b-256 5cdd63f05c5aa3eb5255c39b534b56cbc7ac719bc17c262f812d2c70fb4ef6c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for docling_metrics_layout-0.9.0.tar.gz:

Publisher: pypi.yml on docling-project/docling-metrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docling_metrics_layout-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for docling_metrics_layout-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca60f68ce69d42e6a05d23439fd9e36c5005c082bdf348261b81a142b2c3175f
MD5 e52eb233e8d4ba7a433c0bb194b24098
BLAKE2b-256 8d23a8b753d51f217b176d82beae7dfc8e733c4a88eedf540c32cd7947e9f436

See more details on using hashes here.

Provenance

The following attestation bundles were made for docling_metrics_layout-0.9.0-py3-none-any.whl:

Publisher: pypi.yml on docling-project/docling-metrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page