Skip to content

katherinewu312/lp-lm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LP-LM: No Hallucinations in Question Answering with Logic Programming

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.

English sentence patterns

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:

1 functor + 1 argument

1. subject-verb → verb(subject)

ex. She talks → talk(she), The very gray cat sleeps → sleep(very(gray(cat)))

1 functor + 2 arguments

1. subject-verb-noun → verb(subject, noun)

ex. The student solved the problem → solve(student,problem), The small child is a genius → be(small(child),genius)

2. subject-verb-adjective → verb(subject, adj)

ex. The flowers are beautiful → be(flowers,beautiful), The very warm soup smells delicious → smell(very(warm(soup)),delicious)

3. subject-verb-adverb → verb(subject, adv)

ex. She speaks loudly → speak(she,loudly), The creative chef cooked methodically → cook(creative(chef),methodically)

4. subject-verb-preposition → verb(subject,prep)

ex. Tom lives nearby → live(Tom,nearby), The cat sat on the mat → sit(cat,on(mat))

1 functor + 3 arguments

1. subject-verb-noun-noun → verb(subject,noun,noun)

ex. They elected him president → elect(they,him,president), The family offered the guests some drinks → offer(family,guests,drinks)

2. subject-verb-noun-adjective → verb(subject,noun,adj)

ex. Ronny painted his car black → paint(Ronny,car,black), He called the situation strange → call(he,situation,strange)

3. subject-verb-noun-adverb → verb(subject,noun,adv)

ex. She painted the room aggressively → paint(she,room,aggressively), The black dog ate the food innocently → eat(black(dog),food,innocently)

4. subject-verb-noun-preposition → verb(subject,noun,prep)

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)))

1 functor + 4 arguments

1. subject-verb-noun-noun-adverb → verb(subject,noun,noun,adv)

ex. She gave me a present yesterday → give(she,me,present,yesterday), He showed the class his project bravely → show(he,class,project,bravely)

2. subject-verb-noun-noun-prep → verb(subject,noun,noun,prep)

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))

Notes:

  • 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

English question patterns

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.

1 functor + 1 argument: subject-verb

1. Query about subject: qw-verb → verb(X)

ex. Who talks → talk(X), What sleeps → sleep(X)

1 functor + 2 arguments: subject-verb-{noun,adj,adv,prep}

1. Query about subject: qw-verb-{noun,adj,adv,prep} → verb(X,{noun,adj,adv,prep})

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)

2. Query about {noun,adj,adv,prep}: qw-verb-subject, qw-aux verb-subject-verb → verb(subject,X)

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)

1 functor + 3 arguments: subject-verb-noun-{noun,adj,adv,prep}

1. Query about subject: qw-verb-noun-{noun,adj,adv,prep} → verb(X,noun,{noun,adj,adv,prep})

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))

3. Query about {noun,adj,adv,prep}: qw-aux verb-subject-verb-noun → verb(subject,noun,X)

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)

1 functor + 4 arguments: subject-verb-noun-noun-{adv,prep}

1. Query about subject: qw-verb-noun-noun-{adv,prep} → verb(X,noun,noun,{adv,prep})

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))

3. Query about {adv,prep}: qw-aux verb-subject-verb-noun-noun → verb(subject,noun,noun,X)

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)

Querying nested words

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)))

2. Query about noun inside preposition: qw-aux verb-subject-verb-...-prep

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))

Querying more than one argument

Coming soon.

Usage

Dependencies: XSB Prolog Version 5.0 (http://xsb.sourceforge.net/)

  1. Update part-of-speech files in postags/ to include any words of your choice.
  2. Open XSB and load the kb.pl file.
  3. Add facts via add_kb/1, remove facts via remove_kb/1, or query facts via query_kb/1. Punctuation marks are not necessary.

About

Question answering using DCG-enabled semantics parsing for PCFG

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published