This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datasets import Dataset, ClassLabel, Value, load_dataset | |
| def convert_class_labels_to_str(examples: Dataset): | |
| """ | |
| Utility function to turn (shallow) ClassLabel indices to string labels. | |
| This is common for datasets hosted on the Hugging Face datasets hub with data loading scripts, where the label(s) | |
| are stored as ClassLabel or Sequence[ClassLabel] objects. | |
| Often times we are interested in the string labels rather than the indices. | |
| If any ClassLabel feature is embedded in a nested structure like a dict this will not work |