Get label to id / id to label mapping

I have been trouble finding where I can get label to id mapping after loading a dataset from the HuggingFace Hub. Is it already in the dataset object ? or is it done with the model ? Because I did not define the label2id configuration before training and I don’t know how to get back the corresponding label afterwards.

It is done within the dataset AFAIK.

dataset = load_dataset(...)
dataset.features["label"].feature.names  # All label names
dataset.features["label"].feature._int2str  # Same as `.names`
dataset.features["label"].feature._str2int  # Mapping from labels to integer
1 Like

Yes that’s what I was looking for thank you !