-2

I need to identify some given words using NLP. As an example,

Mary Lives in France

If we consider in here the given words are Australia, Germany,France. But in this sentence it include only France.

So Among the above 3 given words I need to identify the sentence is include only France

user11100340
  • 53
  • 1
  • 8
  • 1
    Here is the rule of thumb I use. If the data set is [closed world](https://en.wikipedia.org/wiki/Closed-world_assumption) then do NOT use a neural network. Based on the way you are asking the question, it appears your data is closed world. – Guy Coder Jun 23 '19 at 20:22
  • 1
    If you're just looking for some specific words, you can [do a simple string search](https://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method). No need for NLP or ML. Does that answer your question or are there additional details which would require a more complex approach? – Bernhard Barker Jun 24 '19 at 08:27

1 Answers1

0

I would comment but I don't have enough reputation. It's a bit unclear exactly what you are trying to achieve here and how representative your example is - please edit your question to make it clearer.

Anyhow, like Guy Coder says, if you know exactly the words you are looking for, you don't really need machine learning or NLP libraries at all. However, if this is not the case, and you don't know have every example of what you are looking for, the below might help:

It seems like what you are trying to do is perform Named Entity Recognition (NER) i.e. identify the named entities (e.g. countries) in your sentences. If so, the short answer is: you don't need to use any machine learning algorithms. You can just use a python library such as spaCy which comes out of the box with a pretrained language model that can already perform a bunch of tasks, for instance NER, to high degree of performance. The following snippet should get you started:

import spacy
nlp = spacy.load('en')

doc = nlp("Mary Lives in France")
for entity in doc.ents:
    if (entity.label_ == "GPE"):
        print(entity.text)

The output of the above snippet is "France". Named entities cover a wide range of possible things. In the snippet above I have filtered for Geopolitical entities (GPE).

Learn more about spaCy here: https://spacy.io/usage/spacy-101

amin_nejad
  • 989
  • 10
  • 22