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.13.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.13.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docling_metrics_layout-0.13.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.12

File hashes

Hashes for docling_metrics_layout-0.13.0.tar.gz
Algorithm Hash digest
SHA256 4e85f4bf2e47a630b284698dc4564d7f884a21efc1ce73ba10cf37432c4352ae
MD5 5f329819b74fba125226daafe093d9d1
BLAKE2b-256 a48018e3afa911ba7e8f1bab2655cf697497a98cce4e27e49011b7de87c2d5c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for docling_metrics_layout-0.13.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.13.0-py3-none-any.whl.

File metadata

File hashes

Hashes for docling_metrics_layout-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ceebb4dcca83632b81fefdfcc6f060d6d0f48f2eafa763301dabee0e97a8dd
MD5 bc3fda24040d436560bd2ebb5afb77ae
BLAKE2b-256 b811aeccdff0b060699d269d0ee8a7b17eb7734c393a3bc2e6c4ca76425a3baa

See more details on using hashes here.

Provenance

The following attestation bundles were made for docling_metrics_layout-0.13.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