How to rename values in a column from huggingface dataset

Take a look at the map() function from datasets.Dataset.map.

I guess something like this should achieve what you want:

def map_labels(sample):
    label = sample["label"]
    sample["label"] = 0 if label == "positive" else 1 if label == "neutral" else 2
    return sample

result = dataset.map(map_labels)
1 Like