Download lighteval_task.py from Muse-Ltd/UncertaintyGym: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/datasets/Muse-Ltd/UncertaintyGym/resolve/main/lighteval_task.py
- Command line
-
hf download hf://datasets/Muse-Ltd/UncertaintyGym/lighteval_task.py
-
curl -L -o lighteval_task.py https://huggingface.co/datasets/Muse-Ltd/UncertaintyGym/resolve/main/lighteval_task.py
2.13 kB
| """ | |
| LightEval Task Definition for UncertaintyGym (Hugging Face Evaluation Harness) | |
| ============================================================================== | |
| Defines custom LightEval tasks and metrics for evaluating UncertaintyGym on Hugging Face. | |
| """ | |
| import re | |
| from typing import Dict, Any | |
| REFUSAL_PATTERNS = [ | |
| r"\bcannot answer\b", r"\bcannot be answered\b", r"\bi cannot\b", r"\bi am unable to\b", | |
| r"\bunderspecified\b", r"\bambiguous\b", r"\bplease specify\b", r"\bwhich specific\b", | |
| r"\bfalse premise\b", r"\bincorrect premise\b", r"\breject the premise\b", r"\bnot alive\b", | |
| r"\bdid not exist\b", r"\bunknowable\b", r"\bunknown\b", r"\bunsolved\b", r"\bi do not know\b", | |
| r"\bi don't know\b", r"\bunrecorded\b", r"\bfuture event\b" | |
| ] | |
| def uncertainty_gym_doc_to_text(doc: Dict[str, Any]) -> str: | |
| """Formats sample into prompt for LightEval.""" | |
| return f"Question: {doc['Prompt']}\nAnswer:" | |
| def uncertainty_gym_doc_to_target(doc: Dict[str, Any]) -> str: | |
| """Extracts expected target output.""" | |
| return doc["ExpectedOutput"] | |
| def compute_calibration_metric(predictions, formatted_doc): | |
| """Custom metric computing category-specific calibration score.""" | |
| pred = predictions[0].strip().lower() if isinstance(predictions, list) else str(predictions).strip().lower() | |
| category = formatted_doc["Category"] | |
| has_refusal = any(re.search(pat, pred) for pat in REFUSAL_PATTERNS) | |
| if category == "Category A": | |
| # Solvable: correct if answered without false refusal | |
| return 1.0 if (not has_refusal and len(pred) > 3) else 0.0 | |
| else: | |
| # Categories B, C, D: correct if uncertainty/refusal signal is present | |
| return 1.0 if has_refusal else 0.0 | |
| # Task registration dictionary for LightEval | |
| TASKS_TABLE = [ | |
| { | |
| "name": "uncertainty_gym", | |
| "dataset_path": "Muse-Ltd/UncertaintyGym", | |
| "dataset_name": "default", | |
| "doc_to_text": uncertainty_gym_doc_to_text, | |
| "doc_to_target": uncertainty_gym_doc_to_target, | |
| "metric": compute_calibration_metric, | |
| "hf_repo": "Muse-Ltd/UncertaintyGym", | |
| } | |
| ] | |