Download inference/src/ax_doclayout/taxonomy.py from AutomatosX/AXDocLayout-M-v1.3-CUDA-TF32: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/AutomatosX/AXDocLayout-M-v1.3-CUDA-TF32/resolve/main/inference/src/ax_doclayout/taxonomy.py
- Command line
-
hf download hf://AutomatosX/AXDocLayout-M-v1.3-CUDA-TF32/inference/src/ax_doclayout/taxonomy.py
-
curl -L -o taxonomy.py https://huggingface.co/AutomatosX/AXDocLayout-M-v1.3-CUDA-TF32/resolve/main/inference/src/ax_doclayout/taxonomy.py
1.45 kB
| # Copyright 2026 AutomatosX | |
| # SPDX-License-Identifier: AGPL-3.0-only | |
| # Modified 2026-10-19 for v1.3; prior component notices are in NOTICE. | |
| """Canonical 11-class layout taxonomy.""" | |
| from __future__ import annotations | |
| from ax_doclayout.errors import TaxonomyError | |
| TAXONOMY_ID = "ax-doclayout-11/1" | |
| RESERVED_ID = 0 | |
| CLASS_NAMES: dict[int, str] = { | |
| 1: "caption", | |
| 2: "footnote", | |
| 3: "formula", | |
| 4: "list_item", | |
| 5: "page_footer", | |
| 6: "page_header", | |
| 7: "picture", | |
| 8: "section_header", | |
| 9: "table", | |
| 10: "text", | |
| 11: "title", | |
| } | |
| NAME_TO_ID: dict[str, int] = {name: class_id for class_id, name in CLASS_NAMES.items()} | |
| def public_name(class_id: int) -> str: | |
| if class_id == RESERVED_ID: | |
| raise TaxonomyError("class_id_reserved") | |
| try: | |
| return CLASS_NAMES[class_id] | |
| except KeyError as exc: | |
| raise TaxonomyError("class_id_unknown") from exc | |
| def public_id(class_name: str) -> int: | |
| try: | |
| return NAME_TO_ID[class_name] | |
| except KeyError as exc: | |
| raise TaxonomyError("class_name_unknown") from exc | |
| def to_internal(class_id: int) -> int: | |
| """Map public 1–11 to zero-based indices 0–10.""" | |
| if class_id not in CLASS_NAMES: | |
| raise TaxonomyError("class_id_unknown") | |
| return class_id - 1 | |
| def from_internal(index: int) -> int: | |
| class_id = index + 1 | |
| if class_id not in CLASS_NAMES: | |
| raise TaxonomyError("class_id_unknown") | |
| return class_id | |