This repo contains the code for our paper, "LP-LM: No Hallucinations in Question Answering with Logic Programming", by Katherine Wu and Yanhong A. Liu.
LP-LM is a system designed to ground answers to questions in known facts contained in a knowledge base facilitated through semantic parsing in Prolog to produce answers that are always reliable and correct.
We outline the types of English sentences that LP-LM currently supports. Extending LP-LM to support other sentence types is straightforward.
There are four types of sentences: simple, compound, complex, and compound-complex. Currently, LP-LM does not support complex nor compound-complex sentences, but this is part of our future work.
There are declarative, interrogative, imperative, and exclamatory sentences. LP-LM is primarily designed to work on declarative and interrogative sentences, as its purpose is reliable and logical question answering.
An English sentence has two parts: a subject and a verb. Once parsed, the verb part of the sentence serves as the Prolog functor, with the remaining parts of the sentence serving as arguments of the functor.
LP-LM supports the following sentence patterns. These patterns encompass the prominent structures of simple declarative sentences in English:
ex. She talks → talk(she), The very gray cat sleeps → sleep(very(gray(cat)))
ex. The student solved the problem → solve(student,problem), The small child is a genius → be(small(child),genius)
ex. The flowers are beautiful → be(flowers,beautiful), The very warm soup smells delicious → smell(very(warm(soup)),delicious)
ex. She speaks loudly → speak(she,loudly), The creative chef cooked methodically → cook(creative(chef),methodically)
ex. Tom lives nearby → live(Tom,nearby), The cat sat on the mat → sit(cat,on(mat))
ex. They elected him president → elect(they,him,president), The family offered the guests some drinks → offer(family,guests,drinks)
ex. Ronny painted his car black → paint(Ronny,car,black), He called the situation strange → call(he,situation,strange)
ex. She painted the room aggressively → paint(she,room,aggressively), The black dog ate the food innocently → eat(black(dog),food,innocently)
ex. His parents bought a computer for him → buy(parents,computer,for(him)), She placed the vase on the tall table → place(she,vase,on(tall(table)))
ex. She gave me a present yesterday → give(she,me,present,yesterday), He showed the class his project bravely → show(he,class,project,bravely)
ex. He showed the class his project by the lake → show(he,class,project,by(lake)), My best friend sent me a long letter before sunset → send(best(friend),me,long(letter),before(sunset))
- Subject is a noun
- Nouns include pronouns
- Nouns can be prepended by one or more adjectives, adverbs, and/or a determiner
- Determiners are not included in the Prolog term
- Root form of verb is always used as Prolog functor
LP-LM supports both yes/no and wh- questions. Below are the types of question patterns that are currently suported, as well as their converstions to a Prolog term so that unification can be performed. The examples here correspond to the examples in the previous section.
ex. Who talks → talk(X), What sleeps → sleep(X)
ex. Who solved the problem → solve(X,problem), What are beautiful → be(X,beautiful), Who speaks loudly → speak(X,loudly), Who lives nearby → live(X,nearby)
ex. What is the small child → be(small(child),X), How are the flowers → be(flowers,X), How does she speak → speak(she,X), Where does Tom live → live(Tom,X)
ex. Who elected him president → elect(X,him,president), Who painted his car black → paint(X,car,black), What ate the food innocently → eat(X,food,innocently), Who bought a computer for him → buy(X,computer,for(him))
2. Query about noun: qw-aux verb-subject-verb-{noun/adj/adv/prep} → verb(subject,X,{noun,adj,adv,prep})
ex. Who did they elect president → elect(they,X,president), What did Ronny paint black → paint(Ronny,X,black), What did she paint aggresively → paint(she,X,aggressively), What did his parents buy for him → buy(parents,X,for(him))
ex. What did they elect him → elect(they,him,X), What did Ronny paint his car → paint(Ronny,car,X), How did she paint the room → paint(she,room,X), Why did his parents buy a computer → buy(parents,computer,X)
ex. Who gave me a present yesterday → give(X,me,present,yesterday), Who showed the class his project by the lake → show(X,class,project,by(lake))
2. Query about nouns: qw-aux verb-subject-verb-noun-{adv,prep} → verb(subject,X,noun,{adv,prep}), verb(subject,noun,X,{adv,prep})
ex. Who did she give a present yesterday → give(she,X,present,yesterday), What did she give me yesterday → give(she,me,X,yesterday), Who did he show his project by the lake → show(he,X,project,by(lake)), What did he show his class by the lake → show(he,class,X,by(lake))
ex. When did she give me the present → give(she,me,present,X), Where did he show the class his project → show(he,class,project,X)
1. Query about noun inside adjectives/adverbs: qw-be-{adj/adv}-and ..., ... and-be-{adj/adv}, ... that-be-{adj/adv}
ex. What is very gray and sleeps, What sleeps and is very gray, What sleeps that is very gray → sleep(very(gray(X)))
ex. What does the cat sit on → sit(cat,on(X)), Who did his parents buy a computer for → buy(parents,computer,for(X)), Where did he show the class his project by → show(he,class,project,by(X))
Coming soon.
Dependencies: XSB Prolog Version 5.0 (http://xsb.sourceforge.net/)
- Update part-of-speech files in
postags/
to include any words of your choice. - Open XSB and load the
kb.pl
file. - Add facts via
add_kb/1
, remove facts viaremove_kb/1
, or query facts viaquery_kb/1
. Punctuation marks are not necessary.