Download src/postprocessing/answer_normalization.py from minhquang47/b: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/minhquang47/b/resolve/main/src/postprocessing/answer_normalization.py
- Command line
-
hf download hf://minhquang47/b/src/postprocessing/answer_normalization.py
-
curl -L -o answer_normalization.py https://huggingface.co/minhquang47/b/resolve/main/src/postprocessing/answer_normalization.py
1.46 kB
| """Minimal answer cleanup for Medico 2026 Task 1 submissions. | |
| Full-test rescoring showed that semantic or qtype-specific normalization can | |
| reduce the official text metrics. Keep this module intentionally conservative: | |
| only remove obvious formatting noise and never rewrite the medical meaning. | |
| """ | |
| from __future__ import annotations | |
| import re | |
| _SPACE_RE = re.compile(r"\s+") | |
| _LEADING_ANSWER_RE = re.compile(r"^\s*(?:answer\s*[:\-]\s*)+", re.IGNORECASE) | |
| def compact_spaces(text: str) -> str: | |
| return _SPACE_RE.sub(" ", str(text or "")).strip() | |
| def normalize_prediction(prediction: str, question: str = "") -> str: | |
| """Return a minimally cleaned prediction without semantic rewrites.""" | |
| del question # The final Task 1 normalizer is intentionally question-agnostic. | |
| text = compact_spaces(prediction) | |
| text = _LEADING_ANSWER_RE.sub("", text) | |
| text = re.sub(r"\s+([,.;:!?])", r"\1", text) | |
| return compact_spaces(text).strip() | |
| def infer_question_type_for_normalization(question: str) -> str: | |
| """Compatibility shim for older imports; not used for rewriting.""" | |
| q = str(question or "").lower() | |
| if any(marker in q for marker in ["how many", "number of", "count"]): | |
| return "numerical_count" | |
| if q.startswith(("is ", "are ", "was ", "were ", "do ", "does ", "did ", "can ", "has ", "have ")): | |
| return "yes_no" | |
| return "other" | |
| __all__ = ["normalize_prediction", "infer_question_type_for_normalization"] | |