1

I am trying to fine tune flair ner model using these lines of code:

embedding_types = [WordEmbeddings('glove'),
    WordEmbeddings('extvec'),
    WordEmbeddings('crawl'),]


embeddings = StackedEmbeddings(embeddings=embedding_types)



pretrained_model = SequenceTagger.load('ner')

trainer : ModelTrainer = ModelTrainer(pretrained_model, corpus)

trainer.train('resources/taggers/example-ner',
              learning_rate=0.1,
              mini_batch_size=32,
              max_epochs=3)

but I get this error message when I execute:

RuntimeError: Error(s) in loading state_dict for SequenceTagger:
        Missing key(s) in state_dict: "embeddings.list_embedding_0.embedding.weight".

I have already tried to change embedding types but I get the same issue. How can I solve it?

khelwood
  • 55,782
  • 14
  • 81
  • 108

1 Answers1

1

The error you are getting should be solved just by upgrading flair

pip install --upgrade flair

However, there is an error in the concept on how you are doing this. First, you are not passing the embeddings nor to the trainer nor to the tagger. This makes sense if what you want to do is finetune a pretrained model. A pretrained model has already its own embeddings.

If what you want to do is finetune that pretrained model you only have to do:

pretrained_model = SequenceTagger.load('ner')

trainer : ModelTrainer = ModelTrainer(pretrained_model, corpus)

trainer.fine_tune('resources/taggers/example-ner',
                  learning_rate=0.1,
                  mini_batch_size=32,
                  max_epochs=3)
aando21
  • 11
  • 1