How to create custom ClassLabels?

mariosasko
Wed, 19 Jan 2022 13:29:30 +0000

Hi! Use map to map the column to the new range and specify features to perform the cast:

features = dataset.features.copy()
features["basic_sentiment"] = ClassLabel(names=["negative", "neutral", "positive"])
def adjust_labels(batch):
    batch["basic_sentiment"] = [sentiment + 1 for sentiment in batch["basic_sentiment"]]
    return batch
dataset = dataset.map(adjust_labels, batched=True, features=features)