language understanding and rete match content of this lecture: 1.demo of façade 2.language...

20
Language Understanding and Rete Match Content of this lecture: 1. Demo of Façade 2. Language Understanding in Façade 3. Efficiency of RA cycle 4. The Rete Algorithm

Upload: della-jenkins

Post on 19-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Language Understanding and Rete Match

Content of this lecture:1. Demo of Façade2. Language Understanding in Façade3. Efficiency of RA cycle4. The Rete Algorithm

Expert Systems 4 2

Façade: Interactive Plot Development

Properties of game:• Characters controlled by AI• Two computer, one human

player• Bots talk, human types

The story• Trip and Grace have wedding

anniversary• Relation is not very good• Human visitor influences

developments

DEMO:• Video 8 minutes (YouTube 5)• True interactive play• interactivestory.net

Michael Mateas, Andrew Stern: Natural Language Understanding in Façade: Surface Text processing, LNCS 3105, pp3-13.

Expert Systems 4 3

Language Understanding

Bert gaat naar de supermarkt.Bert vindt melk in in de koeling.Bert praat met Jolanda.Bert geeft Jolanda geld.

Questions about this text:• Why does Bert give the money?• Why is Jolanda there?• How much does Bert give?

Answers require large amount of background knowledge.

Expert Systems 4 4

Three levels of Language Processing

Syntax Level: structure• What sentences are well-

formed• What is the role of each word

in the sentence structure• Challenge:

Fruit flies like bananasTime flies like an arrow

Semantic Level: meaning• Assign a precise

meaning to each word and construct

• Synthesize meaning of sentence (story)

Pragmatic Level: goal• Map text to desire, opinion,

statement, question …• Discourse act• - Do you have a pen?

- Yes.

Expert Systems 4 5

Façade maps text to Discourse Acts

Discourse Acts with onecharacter attribute:• (DAAgree ?char)• (DADisagree ?char)• (DAThank ?char)• (DAFlirt ?char)• (DAGoodbye ?char)

More Discourse Acts:• (DASysDontUnd)• (DAExpress ?ch ?tp)• (DACriticize ?ch ?lev)• (DAAdvice ?par ?ch)

There exist 24 DA’s

Examples of sentences:• (DAFlirt ?ch): “You look gorgeous”, “Kiss me”. • (DADisagree ?ch): “Fat chance”, “I don’t think …”.• (DACriticize ?ch ?lev): “You’re weird”, “Kiss off”.• (DAReferTo ?ch ?obj): “When did you get the couch?”

Expert Systems 4 6

Between text and Discourse Acts

Intermediates group words into a meaning class• iIs fact generalizes am, are, is, seems, sounds• iPosDescr generalizes friend, good, big• iChar stands for a reference to a character

Intermediates map word combinations to meaning• iChar + iIs + iPosDesc iPraise

Combinations of intermediates form Discourse Acts• (iChar ?ch) + iGreet (DAGreet ?ch)

It will be very easy to fool Façade…… but natural utterances receive natural response!

Expert Systems 4 7

Storage in Façade: CLIPS/JESS

Store input sentence in word occurrence facts:

Ex: “Grace, kiss me”

Template per iNtermediate

wo

word startpos endpos

Grace 1 1

kiss 2 2

me 3 3

iFlirt

startpos endpos

2 3

iCharacter

char startpos endpos

Grace 1 1

Template per DA:

DAFlirt

char

Grace

Expert Systems 4 8

Recognize a flirt…

• You are gorgeous• I find you more than gorgeous• You have gorgeous eyes

(defrule rec-flirt (wo you ?s1 ?e1) (wo gorgeous ?s2 ?e2) (?e1 < ?s2) => (assert (iFlirt ?s1 ?e2)))

Problems with this?

• This is not how language HE thinks

• What if I find you all but gorgious…

Expert Systems 4 9

The template language

• (X Y): matches occurrence of X followed by Y• (X | Y): matches sentence with X or with Y• *: wildcard

• (template ( you * (gorgeous | brilliant)))

• Template conditions are automatically rewritten to true CLIPS conditions on wo and iNtermediate facts

• Recognized iFacts are stored with position:(template ( you * iPositivePersonDesc))

Higher-order description of conditions facilitates knowledge acquisition from language expert.

Expert Systems 4 10

Not and other idiomatic expressions

• Idiomatic rules match word combinations that change each other’s pragmatic meaning:

(template (not iPositivePersonDesc)) => (assert iNegativePersDesc)• The idiomatic rules remove the recognized terms (retract iPositivePersonDesc) (retract not)

• Gets rid of fruit fly problem…

… if combination is recognizedin time!!

Expert Systems 4 11

Organization of Façade NLU Rule Base

1. Patterns and synonymsExample: iIs, iGreet, …

2. Idiomatic expressions (1000 rules!)Example: pisses me off, kiss off (vs. kiss me!!).Use retraction!

3. Negative wordsExample: not bad

4. Combination rules recognize combinations as (sub-) discourse acts

• These classes are ordered by salience• The rule base reflects human (conscious) thinking

about language

• Anaphora resolution: store referent for it, he, she.

Expert Systems 4 12

Efficiency of Recognize-Act Cycle

• Actual work: Apply.• Interpreter spends >90% of

time in Match!

• Finds all matches to execute one rule:Partial matching

• Matching processes the same facts over and over again: Redundancy! Within-cycle Between-cycleRete algorithm

“Happy”rule

Fact baseConflict set

(CLIPS: Agenda)

1: Match

2: Choose3:

Apply

Expert Systems 4 13

Partial construction of conflict set

• Combine Match and Choose (into recognize)• Search for applicable rules and execute first found

• Look for instantiations of rules in order of decreasing salience

• For Recency: Match facts in order of decreasing time stamps.

• For Breadth: order of increasing time stamps.

Improvement may be significantPractical programs still run impractically ssslllooowww…

Need: RETE Algorithm (Forgy, 1982)

Expert Systems 4 14

Flirting by Database

• Recognize as iFlirt: (template (you * gorgeous))

• (wo (word you) (sp ?s1) (ep ?e1))(wo (word gorgeous) (sp ?s2) (ep ?e2))(?e1 < ?s2)

• Describe as select and conditional join operations:T1 = SEL (word = you) [wo]T2 = SEL (word = gorgeous) [wo]CS = CJOIN (le.ep < ri.sp)[T1,T2]

• Recognize as negation: (template (not gorgeous))

wo

word=you word=gorgeous

le.ep < ri.sp

Conflict setfor rec-flirt

T1 T2

Expert Systems 4 15

Eliminate within-cycle redundancy

• Build data flow network

• Combine common paths

• Each operation is executed only once

• Less within-cycle redundancy

• Some redundancy remains

• Compute only once from program

wo

word=you word=gorgeous

le.ep < ri.sp

Conflict setfor rec-flirt

T1 T2

word=not

le.sp = ri.ep+1

Conflict setfor rec-neg

T3T2

Expert Systems 4 16

Eliminate between-cycle redundancy

• Retain tables of partial matches

• Addition of fact:Propagate token through Rete graph

• Removal of fact:Propagate negative token through graph

wo

word=you word=gorgeous

le.ep < ri.sp

Conflict setfor rec-flirt

T1 T2

word=not

le.sp = ri.ep+1

Conflict setfor rec-neg

T3T2

Expert Systems 4 17

Rete in CLIPS: Pattern Network

• For each condition, CLIPS builds a pattern network

• Condition 1:(wo (word you) (sp ?s1&>3) (ep ?e1&<?s2))

• Condition 2:(wo (word you) (sp ?s1&>3) (len 4) )

• Share patterns for conditions if first parts are the same

wo

word = you

sp > 3

Alpha C1

len = 4

Alpha C2

Expert Systems 4 18

Rete in CLIPS: Join Network

• For each rule, CLIPS builds a JOIN network

• One JOIN per condition• Rule 1:(defrule donop (C1) (C2) (C3) => )

• Rule 2:(defrule nopdo (C1) (C2) (C4) => )

• Left, right memoryAlpha, Beta memory

• First Beta: dummy

J1

Alpha C1Beta 0

J2

Alpha C2Beta 1

J3

Alpha C3Beta 2

ConfSet 1J4

Alpha C4

ConfSet 2

Expert Systems 4 19

An eye on efficiency

• Compare: #Ai #Bi (neigh ?x ?y) n-1 n-1 (holds ?x ?a) n n-1 (holds ?y ?b) n n-1

• To: (holds ?x ?a) n n (holds ?y ?b) n n2

(neigh ?x ?y) n-1 n-1

• Put first: Conditions that rarely match facts• Put first: Conditions that restrict subsequent facts• Put last: Conditions matching volatile facts

Facts matching condition i

Fact combinations matching first i cond.

#Bi < #Ai * #Bi-1

Expert Systems 4 20

Summary and conclusions

• Language processing in Façade:Pragmatic language level is important for intelligent reaction

• Mapping to pragmatics is implemented with rules• Knowledge acquisition usually requires to represent

knowledge at a level higher than rules

• Interpreters spend their time in Matching• Rete Algorithm avoids within-cycle and between-cycle

redundancy• Know and use its properties to tune for efficiency