# Num\_labels creates an error for some models

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnum-labels-creates-an-error-for-some-models%2F8937%3E%5C
**Category:** 🤗Transformers\
**Created:** [August 3, 2021, 1:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnum-labels-creates-an-error-for-some-models%2F8937 "2021-08-03T13:10:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olaffson](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/olaffson/32/2416_2.png) [@olaffson](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Folaffson)%5C
**Post date:** [August 3, 2021, 1:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnum-labels-creates-an-error-for-some-models%2F8937%2F1 "2021-08-03T13:10:09Z")

</div>

Hello,

I am training a classifier for three classes `(bad, medium, good)` using `distilbert-base-uncased-finetuned-sst-2-english` but after saving the model to disk and re-loading it I am getting a strange error

```auto
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
  
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
model = TFAutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")

tokenizer.save_pretrained('finetuned')
model.save_pretrained('finetuned')
model.from_pretrained('finetuned', num_labels = 3)

ValueError: cannot reshape array of size 1536 into shape (768,3)

```

This approach worked with `bert-base-uncased`. Am I doing something wrong here?  
Thanks!

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsgugger)%5C
**Post date:** [August 3, 2021, 4:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnum-labels-creates-an-error-for-some-models%2F8937%2F2 "2021-08-03T16:08:33Z")

</div>

With the latest version installed, you need to add `ignore_mismatched_sizes=True` to your `from_pretrained` call for this to work.  
Otherwise, you try to load a model with 2 labels inside a model with 3 labels, and you get mismatched sizes like that.

---

<div class="post-metadata">

**Author:** ![olaffson](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/olaffson/32/2416_2.png) [@olaffson](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Folaffson)%5C
**Post date:** [August 3, 2021, 4:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnum-labels-creates-an-error-for-some-models%2F8937%2F3 "2021-08-03T16:12:29Z")

</div>

thanks @sgugger, life saving tip! 🙏
