# How to create custom ClassLabels?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-custom-classlabels%2F13650%3E%5C
**Category:** 🤗Datasets\
**Created:** [January 13, 2022, 11:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-custom-classlabels%2F13650 "2022-01-13T11:56:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fogx](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fogx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffogx)%5C
**Post date:** [January 13, 2022, 11:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-custom-classlabels%2F13650%2F1 "2022-01-13T11:56:02Z")

</div>

I would like to turn a column in my dataset into [ClassLabels](https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.ClassLabel).  
For my use case, i have a column with three values and would like to map these to the class labels.  
Creating the labels and setting the column is fairly straightforward:

```auto
# "basic_sentiment holds values [-1,0,1]
feat_sentiment = ClassLabel(num_classes = 3,names=["negative", "neutral", "positive"])
dataset = dataset.cast_column("basic_sentiment", feat_sentiment)

```

Now ClassLabel has three labels: 0 - negative, 1 - neutral, 2-positive, while the data still has values -1 to 1.  
How can i set the `ClassLabels` to use the labels in the columns? Or do i have to set my column to fit the labels of the `ClassLabel` now?  
I couldn’t find an in-depth explanation on how to use this feature in huggingset dataface.

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [January 19, 2022, 1:29pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-custom-classlabels%2F13650%2F2 "2022-01-19T13:29:30Z")

</div>

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

```python
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)

```

---

<div class="post-metadata">

**Author:** ![fogx](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fogx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffogx)%5C
**Post date:** [January 20, 2022, 8:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-custom-classlabels%2F13650%2F3 "2022-01-20T08:56:48Z")

</div>

thanks for your reply!  
So it is not possible to change the internal labeling of the class labels then?  
 → i have to change my column to fit the ClassLabel ordering?

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [January 20, 2022, 2:53pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-custom-classlabels%2F13650%2F4 "2022-01-20T14:53:56Z")

</div>

Yes, currently only the `[0, ..., num_classes - 1]` range is supported when casting to `ClassLabel`.
