Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_flair_tagger(self):
# Download model beforehand
download_model('flair.ner', DEFAULT_CACHE_DIR, process_func=_unzip_process_func, verbose=True)
print("Downloaded the flair model")
# Load the NER tagger using the DaNLP wrapper
flair_model = load_flair_ner_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 hopper pΓ₯ en bil som er rΓΈd sammen med Jens-Peter E. Hansen "
self.assertEqual(sentence.to_tagged_string(), expected_string)
def test_flair_tagger(self):
# Download model beforehand
download_model('flair.ner', DEFAULT_CACHE_DIR, process_func=_unzip_process_func, verbose=True)
print("Downloaded the flair model")
# Load the NER tagger using the DaNLP wrapper
flair_model = load_flair_ner_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 hopper pΓ₯ en bil som er rΓΈd sammen med Jens-Peter E. Hansen "
self.assertEqual(sentence.to_tagged_string(), expected_string)
def benchmark_flair_mdl():
tagger = load_flair_ner_model()
start = time.time()
flair_sentences = []
for i, sentence in enumerate(sentences_tokens):
flair_sentence = Sentence()
for token_txt in sentence:
flair_sentence.add_token(Token(token_txt))
flair_sentences.append(flair_sentence)
tagger.predict(flair_sentences, verbose=True)
predictions = [[tok.tags['ner'].value for tok in fs] for fs in flair_sentences]
print("Made predictions on {} sentences and {} tokens in {}s".format(num_sentences, num_tokens, time.time() - start))