Spaces:
Configuration error
Configuration error
Download axis_numeric/decision.py from serety95/axis-numeric: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/serety95/axis-numeric/resolve/main/axis_numeric/decision.py
- Command line
-
hf download hf://spaces/serety95/axis-numeric/axis_numeric/decision.py
-
curl -L -o decision.py https://huggingface.co/spaces/serety95/axis-numeric/resolve/main/axis_numeric/decision.py
1.5 kB
| """Conservative field-specific accept/retry/abstain policy.""" | |
| from .contracts import RankedCandidate, SemanticClass | |
| from .reliability import AGREEMENT_CLASSES, CHECKSUM_CLASSES, MIN_RELIABILITY | |
| BEAM_MARGIN_FLOOR = 0.05 | |
| RECOVERY_MARK = "nid_recovery" | |
| # Character floors stay as a second screen after the reliability bound. | |
| # They are not calibration. | |
| THRESHOLDS: dict[SemanticClass, float] = { | |
| "nid": 97.0, | |
| "pan": 97.0, | |
| "registration_number": 94.0, | |
| "tax_id": 94.0, | |
| "account_number": 94.0, | |
| "date": 92.0, | |
| "amount": 92.0, | |
| "percentage": 90.0, | |
| "generic_numeric": 92.0, | |
| } | |
| def decide( | |
| candidate: RankedCandidate | None, | |
| semantic_class: SemanticClass, | |
| *, | |
| agreement: bool = False, | |
| reliability_lower_bound: float = 0.0, | |
| ) -> str: | |
| if candidate is None or not candidate.schema_valid or candidate.checksum_valid is False: | |
| return "abstain" | |
| if candidate.beam_margin < BEAM_MARGIN_FLOOR: | |
| return "retry" | |
| if RECOVERY_MARK in candidate.preprocessing_variant: | |
| return "retry" | |
| if reliability_lower_bound < MIN_RELIABILITY: | |
| return "retry" | |
| if candidate.min_character_confidence < THRESHOLDS[semantic_class]: | |
| return "retry" | |
| if semantic_class in CHECKSUM_CLASSES: | |
| return "accepted" if candidate.checksum_valid is True else "retry" | |
| if semantic_class in AGREEMENT_CLASSES: | |
| return "accepted" if agreement else "retry" | |
| return "retry" | |