Download CODE/evaluation/eval/eval_geometric044.py from QLU-LLM/CAD: direct link, hf CLI and curl.
- Browser
- Download file 3.2 kB
-
https://huggingface.co/datasets/QLU-LLM/CAD/resolve/main/CODE/evaluation/eval/eval_geometric044.py
- Command line
-
hf download hf://datasets/QLU-LLM/CAD/CODE/evaluation/eval/eval_geometric044.py
-
curl -L -o eval_geometric044.py https://huggingface.co/datasets/QLU-LLM/CAD/resolve/main/CODE/evaluation/eval/eval_geometric044.py
3.2 kB
| #!/usr/bin/env python3 | |
| """Frozen metric-v4.4 helpers for the DISK pilot. | |
| This final pilot revision keeps v4.3 geometry/dimension behaviour and adds | |
| explicit semantic validity plus interpretable T/D relative-error thresholds. | |
| """ | |
| from __future__ import annotations | |
| import math | |
| from typing import Any | |
| import numpy as np | |
| try: | |
| from . import eval_geometric04 as DISK | |
| from . import eval_geometric043 as BASE | |
| except ImportError: | |
| import eval_geometric04 as DISK | |
| import eval_geometric043 as BASE | |
| canonicalize_entities = BASE.canonicalize_entities | |
| extract_entities = BASE.extract_entities | |
| legacy_dimension_entities = BASE.legacy_dimension_entities | |
| representation_quality = BASE.representation_quality | |
| score_dimension_consistency = BASE.score_dimension_consistency | |
| def score_disk_semantics( | |
| predicted: dict[str, Any], target: dict[str, Any] | |
| ) -> dict[str, Any]: | |
| result = DISK.score_disk_semantics(predicted, target) | |
| if not result.get("applicable"): | |
| result.update( | |
| { | |
| "relative_thickness_error": None, | |
| "thickness_within_1pct": False, | |
| "thickness_within_5pct": False, | |
| "thickness_within_10pct": False, | |
| } | |
| ) | |
| return result | |
| target_features = result.get("target_features") or {} | |
| circle_diameter = target_features.get("circle_diameter") | |
| diameter_sides = target_features.get("diameter_sides") or [] | |
| thickness_ratios = target_features.get("thickness_ratios") or [] | |
| diameter_consistent = bool( | |
| circle_diameter | |
| and len(diameter_sides) == 2 | |
| and all( | |
| abs(float(value) / float(circle_diameter) - 1.0) <= 0.01 | |
| for value in diameter_sides | |
| ) | |
| ) | |
| thickness_consistent = bool( | |
| len(thickness_ratios) == 2 | |
| and min(thickness_ratios) > 0 | |
| and abs(float(thickness_ratios[0]) / float(thickness_ratios[1]) - 1.0) | |
| <= 0.01 | |
| ) | |
| result["data_valid"] = bool( | |
| result.get("data_valid") and diameter_consistent and thickness_consistent | |
| ) | |
| predicted_ratio = result.get("predicted_thickness_ratio") | |
| target_ratio = result.get("target_thickness_ratio") | |
| relative_error = ( | |
| abs(float(predicted_ratio) / float(target_ratio) - 1.0) | |
| if predicted_ratio is not None and target_ratio not in (None, 0) | |
| else None | |
| ) | |
| result.update( | |
| { | |
| "target_diameter_consistent": diameter_consistent, | |
| "target_thickness_consistent": thickness_consistent, | |
| "relative_thickness_error": ( | |
| round(float(relative_error), 8) if relative_error is not None else None | |
| ), | |
| "thickness_within_1pct": bool(relative_error is not None and relative_error <= 0.01), | |
| "thickness_within_5pct": bool(relative_error is not None and relative_error <= 0.05), | |
| "thickness_within_10pct": bool(relative_error is not None and relative_error <= 0.10), | |
| } | |
| ) | |
| return result | |
| __all__ = [ | |
| "canonicalize_entities", | |
| "extract_entities", | |
| "legacy_dimension_entities", | |
| "representation_quality", | |
| "score_dimension_consistency", | |
| "score_disk_semantics", | |
| ] | |