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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e85f4bf2e47a630b284698dc4564d7f884a21efc1ce73ba10cf37432c4352ae
|
|
| MD5 |
5f329819b74fba125226daafe093d9d1
|
|
| BLAKE2b-256 |
a48018e3afa911ba7e8f1bab2655cf697497a98cce4e27e49011b7de87c2d5c1
|
Provenance
The following attestation bundles were made for docling_metrics_layout-0.13.0.tar.gz:
Publisher:
pypi.yml on docling-project/docling-metrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docling_metrics_layout-0.13.0.tar.gz -
Subject digest:
4e85f4bf2e47a630b284698dc4564d7f884a21efc1ce73ba10cf37432c4352ae - Sigstore transparency entry: 1368716077
- Sigstore integration time:
-
Permalink:
docling-project/docling-metrics@81236e43d459d5b1249a437eb88b3e80cf91c8c0 -
Branch / Tag:
refs/tags/docling-metrics-layout-v0.13.0 - Owner: https://github.com/docling-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@81236e43d459d5b1249a437eb88b3e80cf91c8c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file docling_metrics_layout-0.13.0-py3-none-any.whl.
File metadata
- Download URL: docling_metrics_layout-0.13.0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6ceebb4dcca83632b81fefdfcc6f060d6d0f48f2eafa763301dabee0e97a8dd
|
|
| MD5 |
bc3fda24040d436560bd2ebb5afb77ae
|
|
| BLAKE2b-256 |
b811aeccdff0b060699d269d0ee8a7b17eb7734c393a3bc2e6c4ca76425a3baa
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docling_metrics_layout-0.13.0-py3-none-any.whl -
Subject digest:
f6ceebb4dcca83632b81fefdfcc6f060d6d0f48f2eafa763301dabee0e97a8dd - Sigstore transparency entry: 1368716172
- Sigstore integration time:
-
Permalink:
docling-project/docling-metrics@81236e43d459d5b1249a437eb88b3e80cf91c8c0 -
Branch / Tag:
refs/tags/docling-metrics-layout-v0.13.0 - Owner: https://github.com/docling-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@81236e43d459d5b1249a437eb88b3e80cf91c8c0 -
Trigger Event:
release
-
Statement type: