# Re-Training with new number of classes

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fre-training-with-new-number-of-classes%2F13302%3E%5C
**Category:** 🤗Transformers\
**Created:** [January 2, 2022, 4:04pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fre-training-with-new-number-of-classes%2F13302 "2022-01-02T16:04:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakrianoo](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bakrianoo/32/3605_2.png) [@bakrianoo](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbakrianoo)%5C
**Post date:** [January 2, 2022, 4:04pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fre-training-with-new-number-of-classes%2F13302%2F1 "2022-01-02T16:04:25Z")

</div>

Hi All.

I already trained an NER (token classification) model on a custom training dataset with 19 classes. You can explore it here [marefa-nlp/marefa-ner](https://huggingface.co/marefa-nlp/marefa-ner)

The base model which I used to fine-tune my model was `xlm-roberta-large`

I have now a new dataset and need to use the last trained model `marefa-nlp/marefa-ner` as the base model this time.

The problem is that the last model was trained to predict the class out of 19 classes, while the new dataset is designed for just 6 classes.

I tried to load the model and reset the configurations to the `xlm-roberta-large` configuration like this

```auto
from transformers import AutoModelForTokenClassification, AutoConfig

base_model = "xlm-roberta-large"
ft_model = "marefa-nlp/marefa-ner"

config = AutoConfig.from_pretrained(base_model)

ner_model = AutoModelForTokenClassification.from_pretrained(ft_model, num_labels=19)
ner_model.config = config 

# THEN using the ner_model to train with the new dataset

```

but seems not working, as it still requires that the head size be 19

===

Does anyone know how to solve this?

Thanks

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [January 3, 2022, 9:50am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fre-training-with-new-number-of-classes%2F13302%2F2 "2022-01-03T09:50:13Z")

</div>

Hi,

This can be done by passing the additional argument `ignore_mismatched_sizes=True` to the `from_pretrained` method.

---

<div class="post-metadata">

**Author:** ![bakrianoo](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bakrianoo/32/3605_2.png) [@bakrianoo](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbakrianoo)%5C
**Post date:** [January 3, 2022, 8:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fre-training-with-new-number-of-classes%2F13302%2F3 "2022-01-03T20:07:24Z")

</div>

Thank you @nielsr . It works now.  
I think this must be highlighted more in the new documentation.
