flair icon indicating copy to clipboard operation
flair copied to clipboard

[Question]: Combining two different Models?

Open Tinnnitus opened this issue 5 months ago • 1 comments

Question

Hello,

I am a complete freshman in the whole NLP/NER topic and unfortunately don't have much knowledge of python. I am experimenting with NER with Flair and was happy to get the NER with Flair up and running (with good results using the NER-German-large model). Now there are a few entities like dates or even languages in the english model or the 18-Entities Ontonotes model I want to extract as well. I was wondering if it is possible to combine the german model and for example the english one and extract certain entities of both models? Due to my lacking knowledge of Python I am hesitant to training a new model and would rather rely on already existing models.

How could a code could look like? I would highly apreciate if someone could help and enlighten me! Thanks in advance.

Here is my code so far:

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

tagger = Classifier.load("flair/ner-german-large")

txt_file_path = …

with open(txt_file_path, 'r', encoding='utf-8') as file: text_content = file.read()

sentence = Sentence(text_content)

tagger.predict(sentence)

for label in sentence.get_labels('ner'): print(label)

Tinnnitus avatar Mar 01 '24 11:03 Tinnnitus

Hi @Tinnitus to run multiple models, you can just use multiple predictions:

model_a.predict(sentence)
model_b.predict(sentence)

helpmefindaname avatar Mar 01 '24 17:03 helpmefindaname