def benchmark_flair_mdl(): tagger = load_flair_pos_model() start = time.time() tagger.predict(corpus_flair.test) tags_pred = [[tok.tags['upos'].value for tok in fs] for fs in corpus_flair.test] print('**Flair model** ') print_speed_performance(start, num_sentences, num_tokens) assert len(tags_pred)==num_sentences assert sum([len(s) for s in tags_pred])==num_tokens print(accuracy_report(tags_true, tags_pred), end="\n\n")
def benchmark_flair_mdl(): tagger = load_flair_pos_model() start = time.time() tagger.predict(corpus_flair.test) tags_pred = [[tok.tags['upos'].value for tok in fs] for fs in corpus_flair.test] print('**Flair model** ') print("Made predictions on {} sentences and {} tokens in {}s".format( num_sentences, num_tokens, time.time() - start)) assert len(tags_pred) == num_sentences assert sum([len(s) for s in tags_pred]) == num_tokens print(classification_report(tags_true, tags_pred, digits=4))
def test_flair_tagger(self): # Download model beforehand download_model('flair.pos', DEFAULT_CACHE_DIR, process_func=_unzip_process_func, verbose=True) print("Downloaded the flair model") # Load the POS tagger using the DaNLP wrapper flair_model = load_flair_pos_model() # Using the flair POS tagger sentence = Sentence( 'jeg hopper på en bil som er rød sammen med Jens-Peter E. Hansen') flair_model.predict(sentence) expected_string = "jeg <PRON> hopper <VERB> på <ADP> en <DET> bil <NOUN> som <ADP> er " \ "<AUX> rød <ADJ> sammen <ADV> med <ADP> Jens-Peter <PROPN> E. <PROPN> Hansen <PROPN>" self.assertEqual(sentence.to_tagged_string(), expected_string)