0
votes

I am trying to find important name entities for a sentence as below:

import spacy

nlp = spacy.load('en')

sentences = "The machine learning is a field within computer science,\
it differs from traditional computational approaches. In traditional computing,\
algorithms are sets of explicitly programmed instructions used by computers to \
calculate or problem solve. The Machine learning algorithms instead allow for computers \
to train on data inputs and use statistical analysis in order to output values that fall\
within a specific range. Because of this, machine learning facilitates computers in building\
models from sample data in order to automate decision-making processes based on data inputs."

doc = nlp(sentences)

print('Name Entity:{0}'.format(doc.ents))

I am expecting to get the result "Machine learning","algorithms","decision-making" but i am getting an empty set as result. What am i doing wrong here.

3

3 Answers

1
votes

spacy en model gives you only Natural entity like Name, Place, Date, ORG, etc. If you want some custom entity tags then you have create your own custom model with training. For more information about custom model creation please follow My another post.

1
votes

There are no entities in those sentences.

Try

import spacy

nlp = spacy.load('en_core_web_sm')

sentences = "The machine learning is a field within computer science,\
it differs from traditional computational approaches. In traditional computing,\
algorithms are sets of explicitly programmed instructions used by computers to \
calculate or problem solve. The achine learning algorithms instead allow for computers \
to train on data inputs and use statistical analysis in order to output values that fall\
within a specific range. Because of this, at Apple, machine learning facilitates computers in building\
models from sample data in order to automate decision-making processes based on data inputs."

doc = nlp(sentences)

print('Name Entity:{0}'.format(doc.ents))
0
votes

when I ran the code this is the output I received

My Output on running your code

For output like "machine learning","algorithm" ,you need to customize spacy NER and train accordingly .You can use regex for it.