Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 581: Advanced Computational Linguistics Lecture Notes May 4th.

Similar presentations


Presentation on theme: "LING 581: Advanced Computational Linguistics Lecture Notes May 4th."— Presentation transcript:

1 LING 581: Advanced Computational Linguistics Lecture Notes May 4th

2 Last Time› g.pl

3 Semantics We want to obtain a semantic parse for our sentences that we can “run” (i.e. evaluate) against the Prolog database (i.e. situation or possible world). So the semantic parse should be valid Prolog code (that we can call) We’ll need (built-in) member/2 and setof/3 defined in the following 2 slides (a quick review)

4 setof/3 See – http://www.swi- prolog.org/pldoc/doc_for?object=section(2,'4.29',swi('/doc/Manual/al lsolutions.html')) http://www.swi- prolog.org/pldoc/doc_for?object=section(2,'4.29',swi('/doc/Manual/al lsolutions.html SWI Prolog built-in:

5 setof/3 Example:

6 member/2 See – http://www.swi- prolog.org/pldoc/man?predicate=member%2F2

7 Semantics fjpSlides4.pdf Slide 7

8 Semantics fjpSlides4.pdf Slide 8

9 Semantics fjpSlides4.pdf Slide 9

10 Semantics fjpSlides4.pdf Slide 10

11 Semantics: Implementation Desired implementation: The extra argument returns a Prolog query that can be evaluated against the database Note: we are bypassing the (explicit) construction of the syntax tree Imagine if the Penn Treebank was labeled using a semantic representation

12 Semantics: Implementation Let’s write the semantic grammar to handle “Jack is hungry” – first, let’s introduce a bit of notation (lambda calculus) – λ = function – λx.x+1 denotes a function that takes an argument x and computes value x+1 (a period separates the argument from the function body) – (λx.x+1)(5) means apply 5 to the lambda function substitute 5 in place of x and evaluate answer = 6

13 Semantics: Implementation setof(X,hungry(X),S)jack setof(X,hungry(X),S), member(jack,S) Syntax:

14 Semantics: Implementation Semantic grammar:

15 Semantics: Implementation Semantic grammar:

16 Semantics: Implementation More examples of computation: fjpSlides4.pdf Slide 10

17 Semantics: Implementation More examples of computation:

18 Semantics: Implementation More examples of computation:

19 Semantics fjpSlides4.pdf Slide 11

20 Semantics: Implementation Scope of negation: wide or narrow narrow wide

21 Grammar: revised g2.pl

22 Grammar: revised

23 Evaluation Check our computer implementation on… fjpSlides4.pdf Slide 12

24 Quantifiers Not all noun phrases (NPs) are (by nature) directly referential like names Quantifiers: “something to do with indicating the quantity of something” Examples: – every child – nobody – two dogs – several animals – most people nobody has seen a unicorn means roughly (Prolog-style): ?- setof(X,(person(X), seen(X,Y), unicorn(Y)),Set),cardinality(Set,0).

25 Quantifiers Database nobody has seen a unicorn means roughly (Prolog-style): ?- setof(X,(person(X), seen(X,Y), unicorn(Y)),Set),cardinality(Set,0). nobody has seen a unicorn means roughly (Prolog-style): ?- setof(X,(person(X), seen(X,Y), unicorn(Y)),Set),cardinality(Set,0). setof vs. findall (recall last lecture) Fix:

26 Quantifiers Semantic compositionality: – elements of a sentence combine in piecewise fashion to form an overall (propositional) meaning for the sentence Example: – (4) Every baby cried – WordMeaning – criedcried(X). – babybaby(X). – every? – every baby criedproposition (True/False) – that can be evaluated for a given situation

27 (6)every baby exactly one baby most babies cried ✓✓ jumped ✓ swam ✓ Quantifiers Scenario (Possible World): – suppose there are three babies... baby(noah). baby(merrill). baby(dani). – all three cried cried(noah). cried(merrill). cried(dani). – only Dani jumped jumped(dani). – Noah and Dani swam swam(noah). swam(dani). think of quantifiers as “properties-of- properties” every_baby(P) is a proposition P: property every_baby(P) true for P=cried every_baby(P) false for P=jumped and P=swam

28 Quantifiers think of quantifiers as “properties-of-properties” – every_baby(P) true for P=cried – every_baby(P) false for P=jumped and P=swam Generalized Quantifiers – the idea that quantified NPs represent sets of sets – this idea is not as wierd as it sounds – we know every_baby(P) is true for certain properties – view every_baby(P) = set of all properties P for which this is true – in our scenario every_baby(P) = {cried} – we know cried can also be view as a set itself cried = set of individuals who cried – in our scenario cried = {noah, merrill, dani}

29 Quantifiers how do we define the expression every_baby(P)? (Montague-style) every_baby(P) is shorthand for – for all individuals X, baby(X) -> P(X) – -> : if-then (implication : logic symbol) written another way (lambda calculus-style): – λP.[ ∀ X.[baby(X) -> P(X)]] – ∀ : for all (universal quantifier: logic symbol) Example: – every baby walks for all individuals X, baby(X) -> walks(X) more formally – [ NP every baby] [ VP walks] λP.[ ∀ X.[baby(X) -> P(X)]](walks) ∀ X.[baby(X) ->walks(X)]

30 Quantifiers how do we define this Prolog-style? Example: – every baby walks – [ NP every baby] [ VP walks] λP.[ ∀ X (baby(X) -> P(X))](walks) ∀ X (baby(X) ->walks(X)) Possible World (Prolog database): – :- dynamic baby/1.(allows us to modify the baby database online) – baby(a).baby(b). – walks(a).walks(b). walks(c). – individual(a).individual(b). individual(c). What kind of query would you write? One Possible Query (every means there are no exceptions): –?- \+ (baby(X), \+ walks(X)).(NOTE: may need a space between \+ and ( here) –Yes(TRUE) –?- baby(X), \+ walks(X). –No –?- assert(baby(d)). –?- baby(X), \+ walks(X). –X = d ; –Yes Using no exception idea that ∀ X P(X) is the same as ¬ ∃ X ¬P(X) ∃ = “there exists” (quantifier) (implicitly: all Prolog variables are existentially quantified variables) Using no exception idea that ∀ X P(X) is the same as ¬ ∃ X ¬P(X) ∃ = “there exists” (quantifier) (implicitly: all Prolog variables are existentially quantified variables)

31 Recall: Truth Tables De Morgan’s Rule ¬(P ∨ Q) = ¬P ∧ ¬Q PvQ TTT FTT FFF TTT ¬(PvQ) F F T F ¬P ∧ ¬Q FTF TFFFT TFT FTF ¬(PvQ)=T only when both P and Q are F ¬P ∧ ¬Q=T only when both P and Q are F Hence, ¬(PvQ) is equivalent to ¬P ∧ ¬Q

32 Conversion into Prolog Note: \+ (baby(X), \+walks(X)) is Prolog for ∀ X (baby(X) -> walks(X)) Steps: – ∀ X (baby(X) -> walks(X)) – ∀ X (¬baby(X) v walks(X)) (since P->Q = ¬PvQ, see truth tables from two lectures ago) – ¬ ∃ X ¬ (¬baby(X) v walks(X)) (since ∀ X P(X) = ¬ ∃ X ¬P(X), no exception idea) – ¬ ∃ X (baby(X) ∧ ¬walks(X)) (by De Morgan’s rule, see truth table from last slide) – ¬(baby(X) ∧ ¬walks(X)) (can drop ∃ X since all Prolog variables are basically existentially quantified variables) – \+ (baby(X) ∧ \+walks(X)) (\+ = Prolog negation symbol) – \+ (baby(X), \+walks(X)) (, = Prolog conjunction symbol)

33 Quantifiers how do we define this Prolog-style? Example: – every baby walks – [ NP every baby] [ VP walks] λP.[ ∀ X.[baby(X) -> P(X)]](walks) ∀ X.[baby(X) ->walks(X)] Another situation (Prolog database): –:- dynamic baby/1. –:- dynamic walks/1. Does ?- \+ (baby(X), \+ walks(X)). still work? Yes because –?- baby(X), \+ walks(X). –No cannot be satisfied

34 Quantifiers how do we define the expression every_baby(P)? (Montague-style) every_baby(P) is shorthand for – λP.[ ∀ X.baby(X) -> P(X)] (Barwise & Cooper-style) think directly in terms of sets leads to another way of expressing the Prolog query Example: every baby walks {X: baby(X)}set of all X such that baby(X) is true {X: walks(X)} set of all X such that walks(X) is true Subset relation ( ⊆ ) {X: baby(X)} ⊆ {X: walks(X)} the “baby” set must be a subset of the “walks” set

35 Quantifiers (Barwise & Cooper-style) think directly in terms of sets leads to another way of expressing the Prolog query Example: every baby walks {X: baby(X)} ⊆ {X: walks(X)} the “baby” set must be a subset of the “walks” set How to express this as a Prolog query? Queries: ?- setof(X,baby(X),L1).L1 is the set of all babies in the database ?- setof(X,walks(X),L2).L2 is the set of all individuals who walk Need a Prolog definition of the subset relation. This one, for example: subset([],_). subset([X|L1],L2) :- member(X,L2), subset(L1,L2). member(X,[X|_]). member(X,[_|L]) :- member(X,L).

36 Quantifiers Example: every baby walks {X: baby(X)} ⊆ {X: walks(X)} the “baby” set must be a subset of the “walks” set Assume the following definitions are part of the database: subset([],_). subset([X|_ ],L) :- member(X,L). member(X,[X|_ ]). member(X,[ _|L]) :- member(X,L). Prolog Query: ?- setof(X,baby(X),L1), setof(X,walks(X),L2), subset(L1,L2). True for world: –baby(a).baby(b). –walks(a).walks(b). walks(c). L1 = [a,b] L2 = [a,b,c] ?- subset(L1,L2) is true False for world: –baby(a).baby(b). baby(d). –walks(a).walks(b). walks(c). L1 = [a,b,d] L2 = [a,b,c] ?- subset(L1,L2) is false

37 Quantifiers Example: every baby walks (Montague-style) ∀ X (baby(X) -> walks(X)) (Barwise & Cooper-style) {X: baby(X)} ⊆ {X: walks(X)} how do we define every_baby(P)? (Montague-style) λP.[ ∀ X (baby(X) -> P(X))] (Barwise & Cooper-style) {X: baby(X)} ⊆ {X: P(X)} how do we define every? (Montague-style) λP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]] (Barwise & Cooper-style) {X: P 1 (X)} ⊆ {X: P 2 (X)}

38 Quantifiers how do we define the expression every? (Montague-style) λP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]] Let’s look at computation in the lambda calculus... Example: every man likes John – WordExpression – everyλP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]] – manman – likesλY.[λX.[ X likes Y]] – John John Syntax: [ S [ NP [ Q every][ N man]][ VP [ V likes][ NP John]]]

39 Quantifiers Example: [ S [ NP [ Q every][ N man]][ VP [ V likes][ NP John]]] – WordExpression – everyλP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]] – manman – likesλY.[λX.[ X likes Y]] – John John Logic steps: [ Q every][ N man]]λP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]](man) [ Q every][ N man]]λP 2.[ ∀ X (man(X) -> P 2 (X))] [ VP [ V likes][ NP John]]λY.[λX.[ X likes Y]](John) [ VP [ V likes][ NP John]]λX.[ X likes John] [ S [ NP [ Q every][ N man]][ VP [ V likes][ NP John]]] λP 2.[ ∀ X (man(X) -> P 2 (X))](λX.[ X likes John]) ∀ X (man(X) -> λX.[ X likes John](X)) ∀ X (man(X) -> [ X likes John])

40 Quantifiers Prolog is kinda first order logic … – no quantifier variables

41 Quantifiers Example: – λP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]] lambda(P1,lambda(P2,(\+ (P1(X), \+ P2(X))))) Example: – {X: P(X)} – setof(X,P(X),Set)

42 Quantifiers Example: – {X: P(X)} – Illegal: setof(X,P(X),Set) – Alternate: setof(X,call(P,X),Set) Database

43 Quantifiers Example: – λP 1.[λP 2.[ ∀ X (P 1 (X) -> P 2 (X))]] Illegal: lambda(P1,lambda(P2,(\+ (P1(X), \+ P2(X))))) Alternate: lambda(P1,lambda(P2,(\+ (call(P1,X),\+ call(P2,X)))))

44 Quantifiers Part 3: Coordination Extend the grammars to handle – Every man and every woman likes John

45 Other Quantifiers Other quantifiers can also be expressed using set relations between two predicates: Example: no: {X: P 1 (X)} ∩ {Y: P 2 (Y)} = ∅ ∩ = set intersection ∅ = empty set no man smokes {X: man(X)} ∩ {Y: smokes(Y)} = ∅ should evaluate to true for all possible worlds where there is no overlap between men and smokers men smokers

46 Other Quantifiers Other quantifiers can also be expressed using set relations between two predicates: Example: some: {X: P 1 (X)} ∩ {Y: P 2 (Y)} ≠ ∅ ∩ = set intersection ∅ = empty set some men smoke {X: man(X)} ∩ {Y: smokes(Y)} ≠ ∅ men smokers

47 Names as Generalized Quantifiers we’ve mentioned that names directly refer here is another idea… Conjunction – X and Y – both X and Y have to be of the same type – in particular, semantically... – we want them to have the same semantic type what is the semantic type of every baby? Example every baby and John likes ice cream [ NP [ NP every baby] and [ NP John]] likes ice cream every baby likes ice cream {X: baby(X)} ⊆ {Y: likes(Y,ice_cream)} John likes ice cream ??? ⊆ {Y: likes(Y,ice_cream)} John ∈ {Y: likes(Y,ice_cream)} want everything to be a set (to be consistent) i.e. want to state something like ({X: baby(X)} ∪ {X: john(X)}) ⊆ {Y: likes(Y,ice_cream)} note: set union ( ∪ ) is the translation of “and”

48 Downwards and Upwards Entailment (DE & UE) Quantifier every has semantics – {X: P 1 (X)} ⊆ {Y: P 2 (Y)} – e.g. every woman likes ice cream – {X: woman(X)} ⊆ {Y:likes(Y,ice_cream)} Every is DE for P 1 and UE for P 2 Examples: (25) a. Every dog barks b. Every Keeshond barks (valid) c. Every animal barks (invalid) – semantically, “Keeshond” is a sub-property or subset with respect to the set “dog” animal dog Keeshond animal dog Keeshond

49 Downwards and Upwards Entailment (DE & UE) Quantifier every has semantics – {X: P 1 (X)} ⊆ {Y: P 2 (Y)} – e.g. every woman likes ice cream – {X: woman(X)} ⊆ {Y:likes(Y,ice_cream)} Every is DE for P 1 and UE for P 2 Examples: (25) a. Every dog barks d. Every dog barks loudly (invalid) c. Every dog makes noise (valid) – semantically, “barks loudly” is a subset with respect to the set “barks”, which (in turn) is a subset of the set “makes noise” make noise barks barks loudly make noise barks loud


Download ppt "LING 581: Advanced Computational Linguistics Lecture Notes May 4th."

Similar presentations


Ads by Google