Entity recognition with context/relation

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?

Topic named-entity-recognition

Category Data Science


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"]
True

and the quantity units

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

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

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

enter image description here

Hope this helps.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.