[BUG]FreshWiki/wikipage_extractor.py this python needs a little bit of improvement.
vignesh1507 opened this issue · 1 comments
vignesh1507 commented
Flair Model Loading:
The Classifier.load('ner') line inside extract_entities_flair() loads the model every time the function is called. It would be more efficient to load the model once, outside the function or globally.
Fixed code snippet:
'tagger = Classifier.load('ner')
def extract_entities_flair(text):
sentences = re.split(r'(?<!\w.\w.)(?<![A-Z][a-z].)(?<=.|?)\s', text)
entities = []
for sentence in sentences:
if len(sentence) == 0:
continue
sentence = Sentence(sentence)
tagger.predict(sentence)
entities.extend([entity.text for entity in sentence.get_spans('ner')])
entities = list(set([e.lower() for e in entities]))
return [entities']
shaoyijia commented
Thank you @vignesh1507