{"id":912,"date":"2018-04-22T09:11:15","date_gmt":"2018-04-22T03:41:15","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=912"},"modified":"2018-04-22T11:09:31","modified_gmt":"2018-04-22T05:39:31","slug":"question-answering-using-dependency-trees","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/","title":{"rendered":"Question Answering\u00a0Using Dependency Trees"},"content":{"rendered":"<p>A few weeks ago I had written about my brief experiment with <a href=\"http:\/\/www.rangakrish.com\/index.php\/2018\/03\/25\/question-answering-in-mathematica\/\" target=\"_blank\" rel=\"noopener\">Mathematica&#8217;s new feature<\/a>, which provides answers to questions based on given text. After that post, I spent some time thinking about how to implement something similar. In today&#8217;s post, I want to show you what I have been able to do in the last two weeks.<\/p>\n<p>Here is what the QA system (a bit naive for now) will attempt to do:<\/p>\n<p style=\"padding-left: 30px;\">(1) Given a piece of text, it will build an internal representation of the text<\/p>\n<p style=\"padding-left: 30px;\">(2) When asked a <em><strong>direct<\/strong><\/em> question, it will find the sentences in the text, which match the question, and print the complete sentences<\/p>\n<p>Let me elaborate item (2) further. A <em><strong>direct<\/strong><\/em> question is one that does not require inferencing, or looking beyond the given text for an answer. Suppose the text is <em><strong>Peter eats a lot of sweets even though he is diabetic<\/strong><\/em>, a direct question could be <em><strong>What does Peter eat?<\/strong><\/em>, but not <em><strong>What is diabetes?<\/strong><\/em><\/p>\n<p>Also, the system will print the complete matching sentence(s) even though the answer is contained in a part of the sentence. Thus, when asked the question <em><strong>What does Peter eat?<\/strong><\/em>, the system will respond <em><strong>Peter eats a lot of sweets even though he is diabetic, <\/strong><\/em>and not just<strong>\u00a0<em>Peter eats a lot of sweets.<\/em><\/strong><\/p>\n<p>Clearly, these are limitations, but we can live with these for now.<\/p>\n<p>Dependency trees are used widely in NLP these days. Efficient parsers and 3rd party libraries are available for this purpose. Here is an example dependency tree for the sentence <em><strong>Peter likes salad.<\/strong><\/em><\/p>\n<figure id=\"attachment_919\" aria-describedby=\"caption-attachment-919\" style=\"width: 432px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"919\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/deptree-example\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png\" data-orig-size=\"432,198\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Dependency Tree\" data-image-description=\"&lt;p&gt;Dependency Tree&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Dependency Tree&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png\" class=\"size-full wp-image-919\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png?resize=432%2C198\" alt=\"Dependency Tree\" width=\"432\" height=\"198\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png?w=432&amp;ssl=1 432w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png?resize=300%2C138&amp;ssl=1 300w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/a><figcaption id=\"caption-attachment-919\" class=\"wp-caption-text\"><strong>Dependency Tree<\/strong><\/figcaption><\/figure>\n<p>Here is one more example. The sentence <em><strong>Vicky is my pet dog<\/strong><\/em> will have the following representation:<\/p>\n<figure id=\"attachment_920\" aria-describedby=\"caption-attachment-920\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example2.png\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"920\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/deptree-example2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example2.png\" data-orig-size=\"753,365\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Another Dependency Tree Example\" data-image-description=\"&lt;p&gt;Another Dependency Tree Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another Dependency Tree Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example2.png\" class=\"wp-image-920\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example2.png?resize=650%2C315\" alt=\"Another Dependency Tree Example\" width=\"650\" height=\"315\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example2.png?w=753&amp;ssl=1 753w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example2.png?resize=300%2C145&amp;ssl=1 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-920\" class=\"wp-caption-text\"><strong>Another Dependency Tree Example<\/strong><\/figcaption><\/figure>\n<p>My strategy is the following:<\/p>\n<p style=\"padding-left: 30px;\">1) Parse the given text into dependency trees and prepare N-tuples of the form:<\/p>\n<p style=\"padding-left: 90px;\"><span style=\"color: #0000ff;\"><strong>&lt;sentence-id, dependency-label, head-word, tail-word&gt;<\/strong><\/span><\/p>\n<p style=\"padding-left: 30px;\">2) Parse the question into a dependency tree and prepare N-tuples of the form:<\/p>\n<p style=\"padding-left: 90px;\"><span style=\"color: #0000ff;\"><strong>&lt;question-id, dependency-label, head-word, tail-word&gt;<\/strong><\/span><\/p>\n<p style=\"padding-left: 30px;\">3) Convert all N-tuples to logical clauses for efficient matching\/unification. I will be using LispWorks Lisp, which includes a Prolog engine.<\/p>\n<p>Parsing the text and question into corresponding dependency trees can be done using <a href=\"https:\/\/spacy.io\" target=\"_blank\" rel=\"noopener\"><em><strong>spaCy<\/strong><\/em><\/a>\u00a0or using commercial APIs such as <em><strong><a href=\"https:\/\/www.textrazor.com\" target=\"_blank\" rel=\"noopener\">TextRazor<\/a><\/strong><\/em>. I decided to use <em><strong>spaCy<\/strong><\/em>. This posed a minor challenge because it is a Python library, but my implementation is in Lisp. To facilitate the interaction, I wrote a Python REST server (using <a href=\"http:\/\/flask.pocoo.org\/docs\/0.12\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Flask framework<\/strong><\/em><\/a>) that would parse the submitted text using <em><strong>spaCy<\/strong><\/em> and send back N-tuples as result. This way, my Lisp program can easily communicate with the local REST server to parse the text.<\/p>\n<p>For example, the sentence <em><strong>Vicky is my pet dog.<\/strong><\/em>, when sent to the REST server, returns the following structure:<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\"><strong>(DEFSENT S1 &#8220;Vicky is my pet dog.&#8221;<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #0000ff;\"><strong>(NSUBJ &#8220;is&#8221; &#8220;vicky&#8221;)<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #0000ff;\"><strong>(ROOT &#8220;is&#8221; &#8220;is&#8221;)<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #0000ff;\"><strong>(POSS &#8220;dog&#8221; &#8220;my&#8221;)<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #0000ff;\"><strong>(AMOD &#8220;dog&#8221; &#8220;pet&#8221;)<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #0000ff;\"><strong>(ATTR &#8220;is&#8221; &#8220;dog&#8221;)<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #0000ff;\"><strong>(PUNCT &#8220;is&#8221; &#8220;.&#8221;))<\/strong><\/span><\/p>\n<p>This structure will be evaluated by the Lisp client to build the Prolog-compatible clauses for further processing. In the same manner, all sentences of the given text as well as the questions will be converted to the above format.<\/p>\n<p>OK, let us look at an actual interaction to understand how well the system performs.<\/p>\n<p>First, we give the whole text (5 sentences in this example) and ask the system to build a model:<\/p>\n<figure id=\"attachment_913\" aria-describedby=\"caption-attachment-913\" style=\"width: 651px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"913\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/example1-9\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png\" data-orig-size=\"680,71\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Building a Model from Text\" data-image-description=\"&lt;p&gt;Building a Model from Text&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Building a Model from Text&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png\" class=\"wp-image-913\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png?resize=651%2C68\" alt=\"Building a Model from Text\" width=\"651\" height=\"68\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png?resize=300%2C31&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example1.png?resize=675%2C71&amp;ssl=1 675w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><\/a><figcaption id=\"caption-attachment-913\" class=\"wp-caption-text\"><strong>Building a Model from Text<\/strong><\/figcaption><\/figure>\n<p>The function <em><strong>parse-text<\/strong><\/em> sends the text to the <em><strong>spaCy<\/strong><\/em> server running on the same machine and evaluates the returned N-tuples to build a model.<\/p>\n<p>Let us ask a question:<\/p>\n<figure id=\"attachment_914\" aria-describedby=\"caption-attachment-914\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example2.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"914\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/example2-6\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example2.png\" data-orig-size=\"414,41\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Question-1\" data-image-description=\"&lt;p&gt;Question-1&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Question-1&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example2.png\" class=\"wp-image-914\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example2.png?resize=600%2C59\" alt=\"Question-1\" width=\"600\" height=\"59\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example2.png?w=414&amp;ssl=1 414w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example2.png?resize=300%2C30&amp;ssl=1 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-914\" class=\"wp-caption-text\"><strong>Question-1<\/strong><\/figcaption><\/figure>\n<p>The function <em><strong>answer-the-question<\/strong><\/em> takes a model and a question. It sends the question to the server and gets an N-tuple of the question, and then passes it to the model to find a match for the question. If there is a valid match (multiple sentences could match a question), the result is returned.<\/p>\n<p>Here are some more examples:<\/p>\n<figure id=\"attachment_915\" aria-describedby=\"caption-attachment-915\" style=\"width: 653px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example3.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"915\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/example3-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example3.png\" data-orig-size=\"540,43\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Question-2\" data-image-description=\"&lt;p&gt;Question-2&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Question-2&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example3.png\" class=\"wp-image-915\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example3.png?resize=653%2C52\" alt=\"Question-2\" width=\"653\" height=\"52\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example3.png?w=540&amp;ssl=1 540w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example3.png?resize=300%2C24&amp;ssl=1 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/a><figcaption id=\"caption-attachment-915\" class=\"wp-caption-text\"><strong>Question-2<\/strong><\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_916\" aria-describedby=\"caption-attachment-916\" style=\"width: 599px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example4.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"916\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/example4-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example4.png\" data-orig-size=\"477,43\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Question-3\" data-image-description=\"&lt;p&gt;Question-3&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Question-3&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example4.png\" class=\"wp-image-916\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example4.png?resize=599%2C54\" alt=\"Question-3\" width=\"599\" height=\"54\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example4.png?w=477&amp;ssl=1 477w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example4.png?resize=300%2C27&amp;ssl=1 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/a><figcaption id=\"caption-attachment-916\" class=\"wp-caption-text\"><strong>Question-3<\/strong><\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_917\" aria-describedby=\"caption-attachment-917\" style=\"width: 604px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example5.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"917\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/example5-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example5.png\" data-orig-size=\"426,48\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Question-4\" data-image-description=\"&lt;p&gt;Question-4&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Question-4&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example5.png\" class=\"wp-image-917\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example5.png?resize=604%2C68\" alt=\"Question-4\" width=\"604\" height=\"68\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example5.png?w=426&amp;ssl=1 426w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example5.png?resize=300%2C34&amp;ssl=1 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/a><figcaption id=\"caption-attachment-917\" class=\"wp-caption-text\"><strong>Question-4<\/strong><\/figcaption><\/figure>\n<p>Notice how, for the last question, the system gives the complete sentence as reply although the best answer would be\u00a0<em><strong>He is 5 years old.<\/strong><\/em><\/p>\n<p>Looks promising, isn&#8217;t it? Does it mean it is perfect? Of course not. Here is a simple question that the system is not able to handle:<\/p>\n<figure id=\"attachment_918\" aria-describedby=\"caption-attachment-918\" style=\"width: 601px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example6.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"918\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/example6-4\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example6.png\" data-orig-size=\"451,42\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"This Question Fails\" data-image-description=\"&lt;p&gt;This Question Fails&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;This Question Fails&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example6.png\" class=\"wp-image-918\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example6.png?resize=601%2C56\" alt=\"This Question Fails\" width=\"601\" height=\"56\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example6.png?w=451&amp;ssl=1 451w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Example6.png?resize=300%2C28&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><figcaption id=\"caption-attachment-918\" class=\"wp-caption-text\"><strong>This Question Fails<\/strong><\/figcaption><\/figure>\n<p>What happened? Easy to guess. Whereas the actual text contains the pronoun <em><strong>He<\/strong><\/em>, the question uses the word <em><strong>Vicky<\/strong><\/em>, and hence the subject of the question and that of the potentially short-listed sentence do not match. This happens because we have not performed\u00a0<a href=\"https:\/\/nlp.stanford.edu\/projects\/coref.shtml\" target=\"_blank\" rel=\"noopener\"><em><strong>coreference resolution<\/strong><\/em><\/a>. This is a common requirement in any text understanding system.<\/p>\n<p>For now, this is a good start. In the next post, I will discuss how we can address this problem.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I had written about my brief experiment with Mathematica&#8217;s new feature, which provides answers to questions based on given text. After that post, I spent some time thinking about how to implement something similar. In today&#8217;s post, I want to show you what I have been able to do in the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,107,17],"tags":[140,138],"class_list":["post-912","post","type-post","status-publish","format-standard","hentry","category-lisp","category-natural-language-processing","category-programming","tag-dependency-tree","tag-question-answering"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-eI","jetpack-related-posts":[{"id":870,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/03\/25\/question-answering-in-mathematica\/","url_meta":{"origin":912,"position":0},"title":"Question Answering in Mathematica","author":"admin","date":"March 25, 2018","format":false,"excerpt":"About 10 days ago, I received an update for Mathematica. The latest version is 11.3.0. As usual, I looked through the list of new features\u00a0in this release. There are several new features, but one of them attracted my attention immediately: There is a new function FindTextualAnswer\u00a0that, given a piece of\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Example 1","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/03\/Example1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/03\/Example1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/03\/Example1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1068,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/09\/16\/dependency-graph-to-rdf\/","url_meta":{"origin":912,"position":1},"title":"Dependency Graph to RDF","author":"admin","date":"September 16, 2018","format":false,"excerpt":"Dependency parsing is widely used these days, and many NLP tools give a dependency graph as the parsed representation of the input text. See for example, SpacY and TextRazor.\u00a0 The following is the dependency tree corresponding to the sentence Mary is drinking cold water: The above tree was generated using\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Dependency Graph","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/09\/DepGraph.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/09\/DepGraph.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/09\/DepGraph.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1863,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/01\/02\/book-review-automatic-text-simplification\/","url_meta":{"origin":912,"position":2},"title":"Book Review &#8211; Automatic Text Simplification","author":"admin","date":"January 2, 2020","format":false,"excerpt":"Title: Automatic Text Simplification Author: Horacio Saggino Publisher: Morgan & Claypool Publishers Year: 2017 Automatic Text Simplification is an active area of research in NLP and has been going on for over 20 years. The idea is to transform a given text T1 into text T2 such that T2 is\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"Automatic Text Simplification","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/01\/IMG_1496-edited-225x300.jpeg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1870,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/01\/19\/experimenting-with-text-simplification\/","url_meta":{"origin":912,"position":3},"title":"Experimenting with Text Simplification","author":"admin","date":"January 19, 2020","format":false,"excerpt":"After my last book review, I decided to check out a few websites that claim to simplify English text and\/or help compute the measure of readability. In today\u2019s post, I am sharing the results of my experiment. www.simplish.org This site has some interesting functionality. It does spelling check, grammar check,\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1541,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/04\/21\/textcontents-function-in-mathematica-12\/","url_meta":{"origin":912,"position":4},"title":"TextContents[ ] Function in Mathematica 12","author":"admin","date":"April 21, 2019","format":false,"excerpt":"Mathematica 12 was released a few days ago.\u00a0 It has been over a year since version 11.3 came out in March 2018. The long wait appears justified since the new release boasts of numerous improvements and new features across several areas. You may want to read this blog post\u00a0by Stephen\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Importing Text File","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/04\/FileImport.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/04\/FileImport.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/04\/FileImport.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2131,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/09\/13\/mathematica-using-textcases-to-extract-information-from-natural-language-text\/","url_meta":{"origin":912,"position":5},"title":"Mathematica: Using TextCases to Extract Information from Natural Language Text\u00a0","author":"admin","date":"September 13, 2020","format":false,"excerpt":"Extracting meaningful information from unstructured, human readable text is a hot topic of research today and has important applications in many domains. I have written a few blogs related to this topic, for example, see this\u00a0and this. In today\u2019s article, I would like to show how Mathematica can be a\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Extracting Sentences","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/09\/ex1-2-300x106.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=912"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/912\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}