2
$\begingroup$

Please pardon me as the title might not be very accurate

I am trying to create a model that learns the word representation and then is able to predict word representation in another piece of text. An example will make it more clear. Please see below for the example:

Model Training Text:

I lived in *Munich last summer. *Germany has a relaxing, slow summer lifestyle. One night, I got food poisoning and couldn't find !Tylenol to make the pain go away, they insisted I take !aspirin instead.

Model Predicts:

['Munich','Germany','Tylenol','aspirin']

Evaluation Text:

When I lived in Paris last year, France was experiencing a recession. The nightlife was too fun, I developed an addiction to Adderall and Ritalin.

Output:

['Paris','France','Adderall','Ritalin']

The question is that what sort of NLP technique will be helpful in such a case. I don't even know what are these kind of problems called. Can you please tell what are these problems called?

One approach I can think of is to train the RNN with Embedding Layer to predict the position of * and ! since * will be prefixed to the name of the country and ! will be prefixed to the name of the drug but my challenge is that how can I structure my data for such training. Is it a feasible approach?

Is there any resource/material I can refer to and draw the inspiration from?

I would very much appreciate any help or suggestions. Thanks a lot in advance.

$\endgroup$

1 Answer 1

1
$\begingroup$

I think the aspect of NLP you're looking for is Named Entity Recognition (NER). It's already built into Python libraries like NLTK and SpaCy. Some videos that might be of interest:

How to train a new 'DRUGS' entity type: https://prodi.gy/docs/video-new-entity-type Practical example: https://towardsdatascience.com/named-entity-recognition-with-nltk-and-spacy-8c4a7d88e7da

The great thing for you is that out-of-the-box models are probably going to be extremely accurate in detecting place names (either LOC or GPE entity tags). They may even be able to detect drugs as a 'PRODUCT' tag. If you need to be more specific, the first video shows you how you would go about training a model for a new tag. For instance, in spaCy:

import spacy
nlp = spacy.load("en_core_web_lg")
doc = nlp("""When I lived in Paris last year, France was experiencing arecession. The nightlife was too fun, I developed an addiction to Adderall and Ritalin.""")
print([(e.text, e.label_) for e in doc.ents])

will print something like this: [('Paris', 'GPE'), ('last year', 'DATE'), ('France', 'GPE'), ('Adderall', 'PRODUCT'), ('Ritalin', 'PRODUCT')]

$\endgroup$
3
  • $\begingroup$ Hi! thanks for the answer. I see how this problem looks like a NER but it actually is not. The model needs to train to identify the prefixed words instead of tagging all "Named Entity" based on POS. $\endgroup$ Commented Jul 18, 2019 at 5:05
  • $\begingroup$ Do you mean that in your evaluation / test data, the terms you're interested in will be prefixed? That would be interesting. If that's the case though, couldn't you just use something like a regex or tokenizer to grab them out of the text, then do lookups for them in a dictionary? $\endgroup$ Commented Jul 19, 2019 at 18:27
  • $\begingroup$ No, in the evaluation/test data the country names and the drug names won't be prefixed but the model needs to identify them names. You're right to use regex if the evaluation/test data had the prefix. $\endgroup$ Commented Jul 20, 2019 at 3:13

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.