Search code examples
pythonpython-3.xnlpnltk

How to Identify People in Text | NLP | Python


I'm looking to leverage NLP python packages to identify people's names in a string of text.

mystring = 'Elon R. Musk (245)436-7956 [email protected] Jeff Bezos (235)231-3432 [email protected] Tim Apple apple.chickadee.org 432-455-5467'

Expected output would be a list of the names ['Elon R. Musk', Jeff Bezos', 'Tim Apple']

Unsure if regex or NLP would be best for this. This is just an example, but I'd like to apply the solution to more text in the future.


Solution

  • This is a popular task called Named Entity Recognition (NER), and there are a lot of models available online to do this.

    Here is a tutorial on how to do this with the well adopted library spacy.io https://www.analyticsvidhya.com/blog/2021/06/nlp-application-named-entity-recognition-ner-in-python-with-spacy/#:~:text=Spacy%20is%20an%20open%2Dsource,very%20easily%20for%20NER%20tasks.