Spaces:
Running
Running
Download utils.py from NbAiLab/goldenswag: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/spaces/NbAiLab/goldenswag/resolve/main/utils.py
- Command line
-
hf download hf://spaces/NbAiLab/goldenswag/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/NbAiLab/goldenswag/resolve/main/utils.py
664 Bytes
| import re | |
| import datasets | |
| def preprocess(text): | |
| text = text.strip() | |
| # NOTE: Brackets are artifacts of the WikiHow dataset portion of HellaSwag. | |
| text = text.replace(" [tittel]", ". ") | |
| text = re.sub("\\[.*?\\]", "", text) | |
| text = text.replace(" ", " ") | |
| return text | |
| def process_docs(dataset: datasets.Dataset) -> datasets.Dataset: | |
| def _process_doc(doc): | |
| out_doc = { | |
| "query": preprocess(doc["activity_label"] + ": " + doc["ctx"]), | |
| "choices": [preprocess(ending) for ending in doc["endings"]], | |
| "gold": int(doc["label"]), | |
| } | |
| return out_doc | |
| return dataset.map(_process_doc) | |