Toward Natural Language Understanding:
FindTextualAnswer and TextCases

Etienne Bernard, Jérôme Louradour
Advanced Research Group, Wolfram Research

Join the Conversation #WolframTechConf

Natural Language Understanding

Tasks

Entity recognition

Parsing to a symbolic representation

TextStructure["The cat is on the mat"]

Question answering

{"The mayer of ...", "What is the name of ... ?"} -> "John"

Summarization

Language modeling

Translation

Dialogue generation

....

At Wolfram Research....

Wolfram | Alpha

Interpreter

Interpreter["City"]["NYC"]

Free-form input (Control + =)

LinguisticAssistant

LinguisticAssistant

GrammarApply

addition=CloudDeploy[GrammarRules[{FixedOrder["add", a:GrammarToken["SemanticNumber"], "and", b:GrammarToken["SemanticNumber"]] :> a + b}]]

GrammarApply[addition, "add six and seven"]

Next step: Learning

Better data

More computing power

Neural networks

FindTextualAnswer

Question answering

text="Even thermometers can't keep up with the plunging temperatures in Russia's remote Yakutia region, which hit minus 88.6 degrees Fahrenheit in some areas Tuesday. In Yakutia - a region of 1 million people about 3,300 miles east of Moscow - students routinely go to school even in minus 40 degrees. But school was cancelled Tuesday throughout the region and police ordered parents to keep their children inside.
In the village of Oymyakon, one of the coldest inhabited places on earth, state-owned Russian television showed the mercury falling to the bottom of a thermometer that was only set up to measure down to minus 50 degrees. In 2013, Oymyakon recorded an all-time low of minus 98 Fahrenheit.";

questions={
"What is the temperature in Yakutia?",
"Name one of the coldest places on earth",
"When was the lowest temperature recorded in Oymyakon?",
"Where is Yakutia?",
"How many live in Yakutia?",
"How far is Yakutia from Moscow?"};

Thread[questions->FindTextualAnswer[text,questions]]//Column

question="Who is Raoul?";
context=ResourceData["The Phantom of the Opera"];
FindTextualAnswer[context,question,1,"HighlightedSentence"]//First

Technology behind:

TF-IDF filtering-based selection of a few paragraphs (if the input text is big)

Neural Network to point the segment that best answer the question

NetModel["Wolfram FindTextualAnswer Net for WL 11.3"]

(for more, see http://blog.wolfram.com/2018/02/15/new-in-the-wolfram-language-findtextualanswer/)

Training dataset

V1: Mainly SQUAD 1.1

Coming soon: Unanswerable questions, SQUAD 2.0

TextCases

~ 3 years old... big update in 12!

Simple query:

TextCases[WikipediaData["Champaign, IL"],"Person"]

Interpreted result:

TextCases[WikipediaData["Champaign, IL"],"Person"->"Interpretation"]

TextCases[WikipediaData["Champaign, IL"],"Person"->"Interpretation",VerifyInterpretation->True]

Several output properties:

TextCases[WikipediaData["Champaign, IL"],"Person"->{"Position","String","Interpretation"},VerifyInterpretation->True]

Several types:

TextCases[WikipediaData["Champaign, IL"],{"Person","Country"}->{"Position","String","Interpretation"},VerifyInterpretation->True]

Containing

TextCases[WikipediaData["Champaign, IL"],Containing["Sentence","Person"]] // TableForm

TextCases[WikipediaData["Champaign, IL"],Containing["Person",Containing["Surname",Verbatim["ck"]]]]

TextContents

New in 12

TextContents[
"Champaign is a city in Champaign County, Illinois, United States. The city is 135 miles (217 km) south of Chicago, 124 miles (200 km) west of Indianapolis, Indiana, and 178 mi (286 km) northeast of St. Louis, Missouri. The United States Census Bureau estimates the city was home to 87,432 people as of July 1, 2017. Champaign is the tenth-most populous city in Illinois, and the state's fourth-most populous city outside the Chicago metropolitan area. It is included in the Champaign–Urbana metropolitan area. Champaign is notable for sharing the campus of the University of Illinois at Urbana–Champaign with its sister city of Urbana."]

~ 350 types... and more!

New guide TextContentTypes

Disambiguation

TextContents["I have a dog. I ate an hot dog."]

Entities

Entities of a given type:

TextCases[StringTake[WikipediaData["Planets"],10000],"Planet"]

A given entities:

TextCases[StringTake[WikipediaData["Planets"],10000],(Entity["Mars", Entity["Planet","Mars"], "Entity[\"Planet\", \"Mars\"]", "planet"])->"HighlightedSnippet"]

Locations

champagne=StringTake[WikipediaData["Champagne"],10000];

locations=TextCases[champagne,"Location"->{"String","Interpretation"},VerifyInterpretation->True]

GeoBubbleChart[Counts[Last/@locations]]

TextCases[champagne,{"City","Country"}]

Dates

dates=TextCases[champagne,"Date"->{"String","Interpretation"}]

TimelinePlot[Last/@dates]

Quantities & currency amounts

TextContents["The population of Illinois in 2018 is estimated at twelve million seven hundred thousand (12,770,000)","Number",All]

textVarietyStore="The variety stores in the world:
In Malaysia: RM 2 stores (2 ringgit)
In Spain there are Todo a 100 shops (\"everything for 100 pesetas\" (€0.60)), although due to the introduction of the euro and inflation, most products cost a multiple of €0.60 or €1. Most of these shops maintain their name in pesetas, and most of them have been renamed as Casi todo a 100 (\"almost everything for 100 [pesetas]\"), Todo a 100, 300, 500 y más (\"everything for 100, 300, 500 or more\") or Todo a un euro. Colloquially, the expression todo a 100 implies that something is either cheap, kitsch or low quality.In Portugal, there were Trezentos shops (300 escudos, €1.50)
In Greece: 300 (300 drachmas, €0.90)
In Norway: Tier´n, a colloquialism for ten kroner, US$1.75.
In Norway: Tier´n, a colloquialism for ten kroner, US$1.75.
In Hungary, there are 100 forintos bolt stores
In Portugal: Eupoupo - Tudo a €0,99 ou €1,49
In Sweden: Bubbeltian, a colloquialism for ten kronor, US$1.20. Another chain that has been spreading in Sweden during the last seven years is Dollarstore, where everything costs either 10, 20, 30, 40, 50 and steps of 50 up to 500 kr.
In Russia: Fixprice (50 rubles)
In Argentina, variety stores are called todo por dos pesos (2 pesos).
In Brazil, these stores are called um e noventa e nove (one and ninety-nine, meaning BRL1.99, about US$1.20) usually written as 1,99.";

TextContents[textVarietyStore,"CurrencyAmount"]

TextCases[textVarietyStore,"CurrencyAmount"->(#String->CurrencyConvert[#Interpretation,"USDollars"]&)]

Identification element

TextContents[
"Stephen Wolfram
email: sw@wolfram.com
Phones: 123-456-7890
100 Trade Center Dr, Champaign, IL 61820
https://resources.wolframcloud.com/NeuralNetRepository
local host 127.0.0.1",
{"Person","EmailAddress","IPAddress","PhoneNumber","URL","ZIPCode"},All]

Passage of homogeneous text: Topics, Languages...

TextCases["I play piano.
I eat carrot sometimes.
After eating carrot I like to play guitar.","MusicTopic"]

TextCases["What is this Language? Quelle est cette langue? It was english. C'était du français.","French"]

Grammatical units

TextCases["Champaign is a city in Champaign County, Illinois, United States. The city is 135 miles (217 km) south of Chicago, 124 miles (200 km) west of Indianapolis, Indiana, and 178 mi (286 km) northeast of St. Louis, Missouri. The United States Census Bureau estimates the city was home to 87,432 people as of July 1, 2017.",{"Verb","ProperNoun"}]

TextCases["Champaign is a city in Champaign County, Illinois, United States. The city is 135 miles (217 km) south of Chicago, 124 miles (200 km) west of Indianapolis, Indiana, and 178 mi (286 km) northeast of St. Louis, Missouri. The United States Census Bureau estimates the city was home to 87,432 people as of July 1, 2017.","VerbPhrase"]//Column

Structural elements

TextCases["Champaign is a city in Champaign County, Illinois, United States. The city is 135 miles (217 km) south of Chicago, 124 miles (200 km) west of Indianapolis, Indiana, and 178 mi (286 km) northeast of St. Louis, Missouri. The United States Census Bureau estimates the city was home to 87,432 people as of July 1, 2017.","Sentence"] // TableForm

TextCases["Champaign is a city in Champaign County, Illinois, United States. The city is 135 miles (217 km) south of Chicago, 124 miles (200 km) west of Indianapolis, Indiana, and 178 mi (286 km) northeast of St. Louis, Missouri. The United States Census Bureau estimates the city was home to 87,432 people as of July 1, 2017.","Word"|"Punctuation"]//TextElement

Under the hood of TextCases

Built-in Classifiers: "Profanity", "Sentiment", "FacebookTopic", "Language", "ProgrammingLanguage"

Neural Networks

NetModel["ELMo Contextual Word Representations Trained on 1B Word Benchmark"]

NetModel["Wolfram Entity Recognition Net for TextCases WL 12.0 V2"]

Training dataset:

Transfer knowledge from WA

Links in Wikipedia

...

Conclusion

FindTextualAnswer

TextCases & TextContents

Neural network solution: good start

Next steps

Improvement for FindTextualAnswer

Improvement for TextCases & TextContents

Summarization

Translation

Multi-language!

Join the Conversation #WolframTechConf