I have a function that extracts basic parts-of-speech words (NN,NNP,JJ,VBS etc.) from about 2000 sentences. I want to understand if there is a way to optimize so I can bring down the execution time (from about 12 secs right now to single digits) if possible.
import re, nltk, html
def extract_entities(text_list):
entities=set()
for sentence in text_list:
try:
tokens = nltk.word_tokenize(sentence)
tagged = nltk.pos_tag(tokens)
[entities.add(word.lower()) for word,pos in tagged
if pos in ['NN','NNP','NNS','NNPS','JJ','VBS','VBN','VBG','VBD']]
except Exception as e:
print('stage 1',e)
return entities