flairNLP / flair

A very simple framework for state-of-the-art Natural Language Processing (NLP)
https://flairnlp.github.io/flair/
Other
13.97k stars 2.1k forks source link

[Question]: MultiTagger cannot be loaded; the name cannot be imported #3196

Open dicleozturk opened 1 year ago

dicleozturk commented 1 year ago

Question

Hello, I've been using flair.MultiTagger until recently. But all of a sudden I receive the following error when I try to load the model to run multiple predictions for postagging, chunking and NER:

I run: from flair.models import MultiTagger

But I get: ImportError: cannot import name 'MultiTagger' from 'flair.models'

Any ideas? I couldn't find any change or any other bug report.

alanakbik commented 1 year ago

Hello @dicleozturk the new release removed the MultiTagger in favor of the more general MultitaskModel. (Sorry about that, we did not realize that people were using the MultiTagger.)

The MultitaskModel is initialized by passing a list of classifiers. You can use it like this:

from flair.data import Sentence
from flair.models import MultitaskModel
from flair.nn import Classifier

# instantiate a NER and POS tagger
ner_tagger = Classifier.load('ner-fast')
pos_tagger = Classifier.load('pos-fast')

# create multi-task model
model = MultitaskModel([ner_tagger, pos_tagger])

# make a sentence
sentence = Sentence("I love Berlin")

# predict everything
model.predict(sentence)

# print predictions
print(sentence)