5

I am using Spacy and trying to detect names in the text. For example, text = 'Keras is a good package. Adam Smith uses a car of black colour. I hope Katrina is doing well in her job.'

The answer should like this: Adam Smith and Katrina.

Can anyone recommend

2
  • What have you attempted so far? And have you had a look at the docs for pipelines?
    – C.Nivs
    Commented Jul 6, 2018 at 16:51
  • 1
    I had to face a similar task recently and the other answers are right: SpaCy's NER is a good starting point. If you are interested here are a couple of repositories that may help you with the next steps: github.com/philipperemy/name-dataset github.com/leoli51/Names-Oracle
    – Leonardo
    Commented Nov 16, 2021 at 18:55

2 Answers 2

7

spacy has an label_ called person. you have several options for the model: small, medium or large. large uses more resources to run

def find_persons(text):
    # Create Doc object
    doc2 = nlp(text)

    # Identify the persons
    persons = [ent.text for ent in doc2.ents if ent.label_ == 'PERSON']

    # Return persons
    return persons

Try nltk to find the Nouns and then pattern match the nouns for valid names:

tokenized_sent = nltk.word_tokenize(sentence)
tagged_sent = nltk.pos_tag(tokenized_sent)
nouns
pronouns
adjectives
verbs

NNP - proper noun singular
PRP - proper noun
VB - verb
DT - determinant

NNP - proper noun singular
PRP - proper noun
VB - verb
DT - determinant
1
  • It fails on this example: Hi Mori, thank you for your response. Please get back to us if you have any other issues. Stay safe. - Syed Azeem
    – MAC
    Commented Jul 6, 2021 at 7:03
6

This is a typical Named Entity Recognition problem. Spacy has a pre-trained model to enable this, which should be accurate to detect person names.

Take a look at this code sample.

According to Spacy's annotation scheme, names are marked as PERSON.

1
  • 1
    Thanks, Pradip. I suppose NLTK can also solve the purpose. I found a solution. I will post it soon. Commented Jul 10, 2018 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.