# Problems in deployment when I configure my own labels

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%3E%5C
**Category:** Amazon SageMaker\
**Created:** [August 27, 2021, 2:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529 "2021-08-27T14:32:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oigres](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@Oigres](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FOigres)%5C
**Post date:** [August 27, 2021, 2:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F1 "2021-08-27T14:32:34Z")

</div>

Hi.

I am training a binary classification model based on this model checkpoint: `dccuchile/bert-base-spanish-wwm-cased`

When deployment, it uses by default these labels: LABEL\_0, LABEL\_1.  
My goal is to deploy it with my own labels. Browsing the forum I came across this thread, and it seems that resolve a similiar problem.

> [@Change label names on inference API](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fchange-label-names-on-inference-api%2F3063)%3A
>
> Hi there, I recently uploaded my [first model](https://huggingface.co/MoritzLaurer/policy-distilbert-7d?text=70-85%25+of+the+population+needs+to+get+vaccinated+against+the+novel+coronavirus+to+achieve+herd+immunity.) to the model hub and I’m wondering how I can change the label names that are returned by the inference API. Right now, the API returns “LABEL\_0”, “LABEL\_1”, etc. with the predictions and I would like it to be something like “Economy”, “Welfare”, etc. I looked at the files of other hosted models and I saw that others changed the id2label and label2id in the config.json file, so I also did that [here](https://huggingface.co/MoritzLaurer/policy-distilbert-7d/blob/main/config.json), but the inference API still returns “LABEL\_0”. Do I…

After read this thread, my code looks like:

```auto
label2id = {
        "0": "goodUser",
        "1": "badUserFraud"
    }
    
    id2label = {
        "goodUser": 0,
        "badUserFraud": 1
    }

    # download model from model hub
    config = AutoConfig.from_pretrained(args.model_name, label2id=label2id, id2label=id2label)
    model = AutoModelForSequenceClassification.from_pretrained(args.model_name, config=config)
    tokenizer = AutoTokenizer.from_pretrained(args.model_name)

```

The training step going well, but when deployment step I find this error:

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/8/80784e02f358a4a0d0acf319c96cbdf2b219f740.png)

Thanks in advance

---

<div class="post-metadata">

**Author:** ![moma1820](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/moma1820/32/4141_2.png) [@moma1820](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmoma1820)%5C
**Post date:** [August 28, 2021, 7:19am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F2 "2021-08-28T07:19:33Z")

</div>

I would like to know this aswell

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fphilschmid)%5C
**Post date:** [August 30, 2021, 7:41am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F3 "2021-08-30T07:41:18Z")

</div>

Hey @Oigres,

Your configuration is vice-versa.  
If you take a look at [config.json · distilbert-base-uncased-finetuned-sst-2-english at main](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/blob/main/config.json)  
So the `id2label` needs to have as key the `id` and as value the `string`.  
And the `label2id` needs to have as key the `string` and as value the `id` .

```python
id2label = {
        "0": "goodUser",
        "1": "badUserFraud"
    }

label2id = {
        "goodUser": 0,
        "badUserFraud": 1
    }

```

Easy to remember is the name is always `key2Value`.

---

<div class="post-metadata">

**Author:** ![Oigres](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@Oigres](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FOigres)%5C
**Post date:** [August 30, 2021, 10:48am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F4 "2021-08-30T10:48:04Z")

</div>

Ohh! Seems true that the best debugging technique is taking a rest 😅

Thank you very much

---

<div class="post-metadata">

**Author:** ![jackyjoy123](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jackyjoy123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjackyjoy123)%5C
**Post date:** [September 2, 2021, 12:21pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F5 "2021-09-02T12:21:31Z")

</div>

> [@philschmid](#):
>
> So the `id2label` needs to have as key the `id` and as value the `string` .  
> And the `label2id` needs to have as key the `string` and as value the `id` .
> 
> ```auto
> id2label = {
> "0": "goodUser",
> "1": "badUserFraud"
> }
> 
> label2id = {
> "goodUser": 0,
> "badUserFraud": 1
> }
> 
> ```
> 
> Easy to remember is the name is always `key2Value` .

thanks for the awesome information.

---

<div class="post-metadata">

**Author:** ![jackyjoy123](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jackyjoy123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjackyjoy123)%5C
**Post date:** [March 24, 2022, 10:45am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F6 "2022-03-24T10:45:46Z")

</div>

> [@jackyjoy123](#):
>
> > [@philschmid](#):
> >
> > So the `id2label` needs to have as key the `id` and as value the `string` .
> > 
> > > And the `label2id` needs to have as key the `string` and as value the `id` .  
> > > [https://talktosonic.onl](https://talktosonic.onl) [https://talktowendys.vip](https://talktowendys.vip)
> > > 
> > > ```auto
> > > id2label = {
> > > 
> > > ```
> > 
> > ```
> > "0": "goodUser",
> > "1": "badUserFraud"
> > }
> > 
> > ```
> > 
> > label2id = {  
> > “goodUser”: 0,  
> > “badUserFraud”: 1  
> > }
> > 
> > > ```auto
> > > 
> > > Easy to remember is the name is always `key2Value` .
> > > 
> > > ```
> 
> thanks for the awesome information.

thanks my issue has been fixed.

---

<div class="post-metadata">

**Author:** ![lathashree01](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lathashree01/32/20640_2.png) [@lathashree01](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flathashree01)%5C
**Post date:** [July 12, 2023, 10:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fproblems-in-deployment-when-i-configure-my-own-labels%2F9529%2F7 "2023-07-12T22:07:33Z")

</div>

Hi, I have a doubt here.

If I have already converted my labels to numbers and want to use the same, should I still create label2id and id2label?

I am trying to perform sequence classification in binary and multi-class settings.

Any discussion to help me understand this is greatly appreciated.

Thanks
