Semantic Ambiguity CS 181: Natural Language Processing Some ambiguities arise at semantic level Lecture 17: Computational Semantics have same parse trees, but different meanings Kim Bruce Every student read a book. Pomona College They each picked their own. Spring 2008 Some liked it, while others did not.
Disclaimer: Slide contents borrowed from many sources on web!
What about other “Obvious” Semantics meaning?
[[Every student read a book]] = [[Every student]] ([[read a book]]) Montague [1973]: Rewrite sentence: A book, every student read it. [[Every student]] = !Q.!x(student(x)"Q(x)) “It” creates a hole to be filled: [[read a book]] = !s:D. #y(book(y) $ read(s,y)) [[every student read it]] = !!!! !z:D.!x.(student(x) " read(x,z)) [[Every student]] ([[read a book]]) [[a book]] = !P.#y.(book(y) $ P(y)) with type = !x(student(x)"(!s:D. #y(book(y) $ read(s,y)))(x)) VPType % Form. = !x(student(x)"#y(book(y) $ read(x,y)))
Putting it Together Other Solutions
Cooper Storage: “Freeze” meanings for quantifiers, pull out when [[A book, every student read it]] needed. (See book for similar idea) = (!P.#y.(book(y) $ P(y))) !!! (!z:D.!x.(student(x) " read(x,z))) Results in saving multiple meanings. = #y.(book(y) $ (!z:D.!x.(student(x) " Doesn’t work with nested noun phrases !!!!!!!!! read(x,z)))(y))) “Jane read every book of a teacher.” = #y.(book(y) $!x.(student(x) " read(x,y))) Keller suggested an improvement Seems like a trick! !!! Hole semantics incorporates constraints Graphical representation representing constraints. Semantic Ambiguity
More attempted solutions: Quasi-Logical Form, Underspecified Logical Form, Underspecified Discourse Representation Theory, Minimal Recursion Semantics, Ontological Promiscuity, Hole Semantics, the Logic in NLTK Constraint Language for Lambda Structures, and Normal Dominance Constraints Sentences w/N quantifiers have up to N! meanings. Desirable to return probability weightings
Formulas Building formulas
Examples: >>> lp.parse('(and p q)') >>> lp = nltk.sem.LogicParser() ApplicationExpression('(and p)', 'q') >>> lp.parse(r'(walk x)') Allows infix ApplicationExpression('walk', 'x') >>> lp.parse('(p and q)') >>> lp.parse(r'\x.(walk x)') ApplicationExpression('(and p)', 'q') LambdaExpression('x', '(walk x)') >>> e = lp.parse('(p and (not q))') >>> e ApplicationExpression('(and p)', '(not q)')
Formatting Using Lambda Calculus
Examples Examples: >>> e = lp.parse(r'(\x.((walk x) and (talk x)) john)') >>> print e >>> e (and p (not q)) ApplicationExpression('\x.(and (walk x) (talk x))', 'john') >>> print e.infixify() >>> e.simplify() (p and (not q)) ApplicationExpression('(and (walk john))', '(talk john)') Embedding FOL Characteristic Functions Build characteristic functions from dicts: >>> called = nltk.sem.CharFun( !!{'bob': nltk.sem.CharFun({'mary':True}), Examples: ... 'jane': nltk.sem.CharFun({'mary':True})}) >>> lp = nltk.sem.LogicParser(constants= !!!!!!!!! ['dog', 'walk', 'see']) >>> called['bob'] {'mary': True} >>> lp.parse(r'dog') >>> called['bob']['mary'] ConstantExpression('dog') True >>> lp.parse('x') >>> called['bob']['jane'] IndVariableExpression('x') Traceback (most recent call last): File "
Building Characteristic Functions Building a Model
Build from relations: Valuations interpret non-logical symbols: >>> val = >>> cd = set([('bob','mary'),('jane','sally')]) nltk.sem.Valuation({'JJ':'jane','Tiger':'bob','Mare':'mary', >>> cf = nltk.sem.CharFun() ..., 'boy':{'bob':True}, 'called':called}) >>> cf.read(cd) >>> val['JJ'] 'jane' >>> cf >>> val['called'] {'sally': {'jane': True}, 'mary': {'bob': True}} {'jane': {'mary': True}, 'bob': {'mary': True}}
Building a Model Building a Model
Assignments: domain of model >>> g = nltk.sem.Assignment(['jane','bob','mary','sally'],!!! Model: !!!!!!! {'x':'bob','y':'mary'}) m = nltk.sem.Model(set(['jane','bob','mary','sally']),val) >>> g m.evaluate('some x.((boy x) and (called x Mare))',g) {'y': 'mary', 'x': 'bob'} True >>> print g Searches over domain of model for satisfying assignment -- slow, as keeps going even after it finds it! g[mary/y][bob/x] Warning: Tracing evaluate w/existentials raises exception at runtime! >>> g.add('sally','z') {'y': 'mary', 'x': 'bob', 'z': 'sally'} Adding Semantic Features
Before associated non-CFG rules to Unification productions: NP % Det Nominal Based
Two Representations Example
[[Jane walked]] IVerb % walked !!!!! = #e.Walked(e) $ Walker(e,jane)
Example Put it all together ...
VP % IVerb =
Handle declaratives, interrogatives, and Semantics for imperatives. Fragment of S % NP VP {DCL(NP.Sem(VP.sem))} S % VP {IMP(VP.sem(DummyYou))} English S % Aux NP VP {YNQ(NP.Sem(VP.sem))} DCL, IMP, YNQ are operators resulting in actions.
Operators Wh-Questions
Who ate the candy? DCL S % WhWord VP add to knowledge base {WHQ(WhWord.sem.var,VP.sem)} YNQ !z:NP. z(VP.Sem) is function taking a NP. determine if prop can be inferred from Meaning is set of f in NP making fcn true. knowledge base - meaning is correct answer What did John eat? IMP S % WhWord Aux NP VP speech act - discussed later on dialog {WHQ(!o:NP(NP.sem((!x:NP: VP.sem(x))(o))} or {WHQ(o,NP.sem,VP.sem(x))}
Noun Phrases Adjective Phrases
Try: Already seen NPType = VPType % Form Nominal % Adj Nominal {!x. Nominal.sem(x) $ IsA(x,Adj.sem)} Nominal % Noun Nominal Adj % red {!P:NounType.!x.P(x) $ IsA(x,red)} ! {!x. Nominal.sem(x) NN(Noun.sem, x)} $ Adj % small {!P:NounType.!x.P(x) $ IsA(x,small)} " summer vacation, head start, elephant gun, ... [[small mouse]] = !x. mouse(x) $ IsA(x,small) Note that an elephant gun is not an elephant! [[small elephant]] = !x. elephant(x) $ IsA(x,small) Others: former friend, fake gun, ... Genitive Noun Phrases Prepositional Phrases
Mary’s bike, Mary’s friend, Ontario’s airport. Generalize from possessives: Meaning determined more by noun, not possessive! Mary’s bike & the bike of Mary NP % ComplexDet Nominal [[house on a hill]]: NounType = D % Form ComplexDet % NP’s {NP.sem} P % on {!P:NPType.!Q:NounType. !x:D. !!!!!!!! P(!y. Q(x) $ on(x,y))} {!Q:VPType. #x. Nominal.sem(x) $ PP % P NP {P.sem(NP.sem)} !!!!!GN(x, ComplexDet.sem) $ Q(x)} Nom % Nom PP {PP.sem(Nom.sem)} [[Mary’s bike]] = !Q:VPType. (#x. bike(x) $ !!!!!!!belongsTo(bike,Mary) $ Q(x)) Different from text!
Semantics & Earley Parser Idioms
Hard - don’t make literal sense. Just like other features Tip of the iceberg, Achilles’ heel, .. No extra problems! Generally not compositional. Must recognize and treat separately
Summary of Semantics
Principle of Compositionality key Syntax-driven semantic analysis Any Questions? Use !-expressions (and other cheats) Quantifiers require lambda lifting.