Natural Language Processing

14
November 2006 Semantics II 1 Natural Language Processing Semantics II • The Lambda Calculus • Semantic Representation • Encoding in Prolog

description

Natural Language Processing. Semantics II The Lambda Calculus Semantic Representation Encoding in Prolog. The Lambda Calculus. The λ -calculus allows us to write down the definition of a function without inventing a special name for it. - PowerPoint PPT Presentation

Transcript of Natural Language Processing

Page 1: Natural Language Processing

November 2006 Semantics II 1

Natural Language Processing

Semantics II• The Lambda Calculus• Semantic Representation• Encoding in Prolog

Page 2: Natural Language Processing

November 2006 Semantics II 2

The Lambda Calculus

• The λ-calculus allows us to write down the definition of a function without inventing a special name for it.

• We use the notation λx.ϕ where x is a variable marking the argument and ϕ is an expression defining the value of the function at that argument, e.g. λx.x+1. We allow the whole expression to stand in the place of a function symbol.

• So (λx.x+1)(3) is a well-formed term that denotes that function applied to the argument 3.

Page 3: Natural Language Processing

November 2006 Semantics II 3

β-Reduction

• The rule of β-reduction says that an expression of the form λx.ϕ(a) can be reduced to ϕ{x=a}, i.e. the expression ϕ with all occurrences of x replaced with a.

• In this case (λx.x+1)(3) = 3+1.• In the semantics we shall be developing, many

intermediate LFs will have the form of propositions with certain parts missing.

• These can be modelled as functions over propositions expressed with λ-expressions.

Page 4: Natural Language Processing

November 2006 Semantics II 4

λ-expressions asPartial Propositions

• to walk: λx.walk(x)• John: john; Fido: fido• λx.walk(x)(john) = walk(john)• to kick: λx.λy.kick(x,y).• λx.λy.kick(x,y)(john) = λy.kick(john,y)• λy.kick(john,y)(fido) = kick(john,fido)• λ-calculus can be used to model “semantic

operations”

Page 5: Natural Language Processing

November 2006 Semantics II 5

Rule to Rule Hypothesis:The Sentence Rule

• Syntactic Rule:S NP VP

• Semantic Rule:[S] = [VP]([NP])i.e. the LF of S is obtained by "applying" the LF of VP to the LF of NP.

• For this to be possible [VP] must be a function, and [NP] the argument to the function.

Page 6: Natural Language Processing

November 2006 Semantics II 6

Swrite(bertrand,principia)

NPbertrand

VPy.write(y,principia)

Vx.y.write(y,x)

NPprincipia

bertrand

writes principia

Parse Tree with Logical Forms

Page 7: Natural Language Processing

November 2006 Semantics II 7

Summary

• Leaves of the tree are words.

• Words (or lexical entries) are associated with “semantic forms” by the dictionary (or lexicon)

• Grammar determines how to combine words and phrases syntactically.

• Associated semantic rules determine how to combine respective semantic forms.

Page 8: Natural Language Processing

November 2006 Semantics II 8

Encoding the Semantic System

1. Devise an encoding for logical forms.

2. Associate an encoded λ expression with each constituent.

3. Encode process of β-reduction

This can all be done with Prolog!

Page 9: Natural Language Processing

November 2006 Semantics II 9

Encode Logical Forms

LF Prolog

x ϕ all(X,ϕ’)

x ϕ exist(X,ϕ’)

&, v, &, v, =>

λx. ϕ X^ϕ’

λx. λy. ϕ X^Y^ϕ’

Page 10: Natural Language Processing

November 2006 Semantics II 10

Associate an encoded λ expression with each constituent

• Reserve an argument position in a DCG rule to hold the logical form encoding.For example, ignoring the particular constraints governing the use of the rule, we might haves(S) --> np(NP), vp(VP).

• i.e. sentence with LF S can be formed by concatenating a noun phrase with LF NP and a verb phrase with LF VP.

Page 11: Natural Language Processing

November 2006 Semantics II 11

Encode Process of β-reduction

• This is done by means of the predicate reduce(Fn,Arg,Result), which is defined by means of a unit clause as follows:

reduce(X^F,X,F).• NB. This predicate only performs a single,

outermost reduction. It does not reduce to a canonical form.

Page 12: Natural Language Processing

November 2006 Semantics II 12

A Very Simple DCGthat computes Semantics

% grammars(S) --> np(NP), vp(VP), {reduce(VP,NP,S)}.vp(VP) --> v(V), np(NP), {reduce(V,NP,VP)}.vp(VP) --> v(VP).

% lexiconv(X^walk(X)) --> [walks].v(X^Y^hit(X,Y)) --> [hits].np(suzie) --> [suzie].np(fido) --> [fido].

Page 13: Natural Language Processing

November 2006 Semantics II 13

Demo

?- s(LF,[suzie,walks], [ ]).

LF = walk(suzie).

?- s(LF,[suzie,kicks,fido], [ ]).

LF = kick(suzie,fido).

Page 14: Natural Language Processing

November 2006 Semantics II 14

Execution Trace Call: (7) s(_G471, [suzie, walks], []) Call: (8) np(_L183, [suzie, walks], _L184) Exit: (8) np(suzie, [suzie, walks], [walks]) Call: (8) vp(_L185, [walks], _L186) Call: (9) v(_L224, [walks], _L225) Exit: (9) v(_G529^walk(_G529), [walks], []) Call: (9) np(_L226, [], _L227) Fail: (9) np(_L226, [], _L227) Redo: (9) v(_L224, [walks], _L225) Redo: (8) vp(_L185, [walks], _L186) Call: (9) v(_L185, [walks], _L186) Exit: (9) v(_G529^walk(_G529), [walks], []) Exit: (8) vp(_G529^walk(_G529), [walks], []) Call: (8) reduce(_G529^walk(_G529), suzie, _G471) Exit: (8) reduce(suzie^walk(suzie), suzie, walk(suzie)) Call: (8) []=[] Exit: (8) []=[] Exit: (7) s(walk(suzie), [suzie, walks], [])