Is there a way to get a specific entity based on the context where it is found? For example:

The temperature today is 35°C.

Store risperidone tablet at 20°C.

Both are talking about temperature. For the first sentence, I would want the temperature to be a "WeatherTemperature" entity. In the second sentence, I would want the temperature to be "DrugTemperature". What model could I use to train for this behavior?

  • $\begingroup$ This is related to the tasks of topic modeling and/or word sense disambiguation. But it completely depends on what kind of data you can use for training. $\endgroup$
    – Erwan
    Jun 19 '19 at 14:37
  • $\begingroup$ @Erwan How should I first proceed? Is there a particular tool I can use? I have a lots of lines of text that are like this. "Store X at Y°C, Keep X at Y°C, Freeze X at Y°C" and I would like distinct entities for them. $\endgroup$ Jun 19 '19 at 15:43
  • $\begingroup$ If you don't have any annotated data, it's Word Sense Discrimination (WSD): the idea is to clusterize occurrences of "Y°C" based on the context words represented as a vector. There are probably existing tools but I don't have any specific recommendation. $\endgroup$
    – Erwan
    Jun 19 '19 at 16:07
  • $\begingroup$ @Erwan Thank you! I have some researching to do now. $\endgroup$ Jun 19 '19 at 16:44

With Wolfram Language you may use TextCases or TextContents from the Text Analysis guide. These are both experimental functions so may change a bit before they are finalised in a future version. Both have the TargetDevice option so you can run them on one or more GPUs if you have them.

Reference the Text Content Types guide for the list of entities these functions have been trained on.

I think TextContents is an optimised call to TextCases for multiple cases so I will only use TextContents below.

Use TextContents to locate all trained entities in your sentences.

res1 = TextContents["The temperature today is 35°C.", TargetDevice -> "GPU"]

Mathematica graphics

res2 = TextContents["Store risperidone tablet at 20°C.", TargetDevice -> "GPU"]

Mathematica graphics

TextContents returns a Dataset object that can be Query'ed for specific cases.

For example for your "DrugTemperature"

res2[ContainsAll[{"Chemical", "Quantity"}], "Type"]

and the quantity units

  SelectFirst[#["Type"] == "Quantity" &], 
  "String" /* SemanticInterpretation /* QuantityUnit]

An Entity of type "Chemical" has a wealth of properties so additional information can be obtained if needed. For example,

 SelectFirst[#["Type"] == "Chemical" &], 
 "String" /* Interpreter["Chemical"] /* (#["MoleculePlot"] &)]

enter image description here

Hope this helps.

  • $\begingroup$ This looks rather promising. What are you using to do this? I tried the Wolfram Client Library for Python but I can't seem to find any of the things (TextContents, TextCases) I need. Are they still in preview? $\endgroup$ Jun 27 '19 at 21:01
  • $\begingroup$ @AvinashPrabhakar The above is in a Wolfram notebook as you didn't specify a platform. For Wolfram Client for Python you need to download the Free Wolfram Engine here. Then you'll be able to use Wolfram Language in Python. You won't have the dynamic interactivity of a Wolfram notebook but you will have access to all the functions. I have a few recent answers here on SE.DS that demonstrate Wolfram Language in Python. $\endgroup$
    – Edmund
    Jun 27 '19 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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