# idtoLabel argument in "text-classification" pipeline

**URL:** <https://discuss.huggingface.co/t/idtolabel-argument-in-text-classification-pipeline/24331>\
**Category:** Beginners\
**Created:** [October 12, 2022, 12:52pm UTC](https://discuss.huggingface.co/t/idtolabel-argument-in-text-classification-pipeline/24331 "2022-10-12T12:52:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sridharnlp](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@sridharnlp](https://discuss.huggingface.co/u/sridharnlp)\
**Post date:** [October 12, 2022, 12:52pm UTC](https://discuss.huggingface.co/t/idtolabel-argument-in-text-classification-pipeline/24331/1 "2022-10-12T12:52:38Z")

</div>

I am using the text classification pipeline of huggingface to generate the emotions.

```auto
from transformers import pipeline
classifier = pipeline("text-classification",model='distilbert-base-uncased-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)

```

`but this gives result as [[{'label': 'LABEL_0', 'score': 0.005389929749071598}, {'label': 'LABEL_1', 'score': 0.0026532604824751616}, {'label': 'LABEL_2', 'score': 0.03011970967054367}, {'label': 'LABEL_3', 'score': 0.25675541162490845}, {'label': 'LABEL_4', 'score': 0.06454580277204514}, {'label': 'LABEL_5', 'score': 0.017099281772971153}]]`

I want to change the label according to the data I trained the model with, I know I can change that in models config file but I want to change that programatically, we have the parameter for idtolabel to change the label with our own data while loading the model from pretrained. can anybody help with me how can I change that, also how to restrict the result, is there any parameter like top\_n or top\_k to return only that number of results?

@bhadresh-savani you also used this, can you help with the arguments for the pipeline?

---

<div class="post-metadata">

**Author:** ![bhadresh-savani](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bhadresh-savani/32/30594_2.png) [@bhadresh-savani](https://discuss.huggingface.co/u/bhadresh-savani)\
**Post date:** [October 12, 2022, 2:59pm UTC](https://discuss.huggingface.co/t/idtolabel-argument-in-text-classification-pipeline/24331/2 "2022-10-12T14:59:44Z")

</div>

Hi @sridharnlp,

There is an argument in the classifier `top_k` for selecting top k predictions,

```auto
prediction = classifier("I love using transformers. The best part is wide 
range of support and its easy to use", top_k=2)
print(prediction)

```

and for changing label2id programmatically, first you need to load model like this,

```auto
from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained("bhadresh-savani/distilbert-base-uncased-finetuned-emotion")

```

Once you load the model you can access model config and properties, ex,

```auto
model.config.id2label
"""output: {'sadness': 0, 'joy': 1, 'love': 2, 'anger': 3, 'fear': 4, 'surprise': 5}
"""

```

you can change it with simple assigning new dictionary,

```auto
model.config.id2label = {'s': 0, 'j': 1, 'l': 2, 'a': 3, 'f': 4, 's': 5}
model.config.id2label
""" output: {'s': 5, 'j': 1, 'l': 2, 'a': 3, 'f': 4}
"""

```

similarly, label2id can be reassigned and the updated model can be saved and reused.

I hope this will help you.

Regards,  
Bhadresh

```auto

```
