Download utils.py from unitxt/data: direct link, hf CLI and curl.
- Browser
- Download file 668 Bytes
-
https://huggingface.co/datasets/unitxt/data/resolve/8a7741b76fa2d41e5a9873ec0b927e8963f4ea51/utils.py
- Command line
-
hf download hf://datasets/unitxt/data@8a7741b76fa2d41e5a9873ec0b927e8963f4ea51/utils.py
-
curl -L -o utils.py https://huggingface.co/datasets/unitxt/data/resolve/8a7741b76fa2d41e5a9873ec0b927e8963f4ea51/utils.py
668 Bytes
| from queue import Queue | |
| from typing import Any, Dict | |
| class Singleton(type): | |
| _instances = {} | |
| def __call__(cls, *args, **kwargs): | |
| if cls not in cls._instances: | |
| cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | |
| return cls._instances[cls] | |
| def flatten_dict(d: Dict[str, Any], parent_key: str = "", sep: str = "_") -> Dict[str, Any]: | |
| items = [] | |
| for k, v in d.items(): | |
| new_key = parent_key + sep + k if parent_key else k | |
| if isinstance(v, dict): | |
| items.extend(flatten_dict(v, new_key, sep=sep).items()) | |
| else: | |
| items.append((new_key, v)) | |
| return dict(items) | |