Exercise 05: Named entity resolution

Doesn't work on Mac or Windows. Usually works well on Ubuntu

Often you want to identify the proper noun phrases within a text, for which we use named-entity resolution (NER). The following is based on polyglot, which may not work as well on MacOSX and Windows. If you've installed on a Linux system, then try:


In [ ]:
sent = "He'd been trained by the best, McCoy Pauley and Bobby Quine, legends in Memphis, and now Chiba City as well."

In [ ]:
from polyglot.text import Text

text = Text(sent)

for entity in Text(sent).entities:
  print(entity.tag, entity)

Though we didn't catch the issues mentioned above in time to message out to the course, there's another library called spaCy which also provides great NER capabilities. If you had problems installing or running polyglot, then install spaCy and try the following:


In [ ]:
import spacy
nlp = spacy.load('en')

In [ ]:
doc = nlp(sent)

for entity in doc.ents:
  print(entity.label_, entity.text)

Clearly these entities will enrich the key phrases extracted from a text.