32
Lecture 20a Feature Based Grammars Topics Topics Description Logic III Overview of Meaning Readings: Readings: Text Chapter 18 NLTK book Chapter 10 March 28, 2013 CSCE 771 Natural Language Processing

Lecture 20a Feature Based Grammars Topics Description Logic III Overview of MeaningReadings: Text Chapter 18 NLTK book Chapter 10 March 28, 2013 CSCE 771

Embed Size (px)

Citation preview

Lecture 20aFeature Based Grammars

Lecture 20aFeature Based Grammars

Topics Topics Description Logic III Overview of Meaning

Readings:Readings: Text Chapter 18

NLTK book Chapter 10

March 28, 2013

CSCE 771 Natural Language Processing

– 2 – CSCE 771 Spring 2013

OverviewOverviewLast Time (Programming)Last Time (Programming)

Computational Semantics

TodayToday Computational Semantics Feature based grammars

Readings: Readings: Text 18.3-18.5 NLTK Book: Chapters 9 and 10

Next Time: Computational Lexical SemanticsNext Time: Computational Lexical Semantics

– 3 – CSCE 771 Spring 2013

Automated Reasoning ServicesAutomated Reasoning Services

• • Satisfiability: A concept C is satisfiable with respect to Satisfiability: A concept C is satisfiable with respect to T if there exists a model I of T such that CT if there exists a model I of T such that CII ≠ . We ∅ ≠ . We ∅also say that I is a model of C.also say that I is a model of C.

• • Subsumption: A concept CSubsumption: A concept C11 is subsumed by a concept is subsumed by a concept CC22 with respect to T if CI CI for every model I of T . ⊆ with respect to T if CI CI for every model I of T . ⊆We also write CWe also write C11 T C⊑ T C⊑ 22 or T |= C or T |= C11 C⊑ C⊑ 22..

• • Equivalence: Two concepts CEquivalence: Two concepts C11 and C and C22 are equivalent are equivalent with respect to T if Cwith respect to T if C11

II = C = C22I I for every model I of T . We for every model I of T . We

also write Calso write C11 ≡T C ≡T C22 or T |= C or T |= C11 ≡ C ≡ C22..

• • Disjointness: Two concepts CDisjointness: Two concepts C11 and C and C22 are disjoint with are disjoint with respect to T if Crespect to T if C11

II C⊓ C⊓ 22II = for every model I of T ∅ = for every model I of T ∅

Chuming Chen’s Dissertation 2008

– 4 – CSCE 771 Spring 2013

Abox ReasoningAbox Reasoning

ABox consistency checking: An ABox A is consistent ABox consistency checking: An ABox A is consistent with respect to a TBox T if there exists an with respect to a TBox T if there exists an interpretation I that is a model of both T and A.interpretation I that is a model of both T and A.

• • Instance checking: An individual a is an instance of Instance checking: An individual a is an instance of concept C with respect to T and A if aI CI for every ⊆concept C with respect to T and A if aI CI for every ⊆model of T and A.model of T and A.

• • Retrieval problem: Given an ABox A and a concept C, Retrieval problem: Given an ABox A and a concept C, to find all individuals a such that A |= a : C.to find all individuals a such that A |= a : C.

• • Realization problem: Given an individual a and a set of Realization problem: Given an individual a and a set of concepts, find the most specific concepts C from the concepts, find the most specific concepts C from the set such that A |= a : C. Note, the most specific set such that A |= a : C. Note, the most specific concepts are those that are minimal with respect to concepts are those that are minimal with respect to the subsumption ordering .⊑the subsumption ordering .⊑

Chuming Chen’s Dissertation 2008

– 5 – CSCE 771 Spring 2013

Figure 18.5 Quantifier Scope and AmbiguityFigure 18.5 Quantifier Scope and Ambiguity

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

Every Restaurant has a menu.Every Restaurant has a menu.

Two possible meaningsTwo possible meanings

))),(),()(()(()((Re)(

))),(),()(()(()(Re

yeHadxeHavereHavingeyMenuyxstaurantxyyMenu

yeHadxeHavereHavingeyMenuyxstaurantx

– 6 – CSCE 771 Spring 2013

UnderSpecificationUnderSpecification

Underspecification is supporting “ambiguous” Underspecification is supporting “ambiguous” meanings by leaving unspecified aspects meanings by leaving unspecified aspects unspecifiedunspecified

So we need to be able toSo we need to be able to

• ““Create underspecified representations that embody Create underspecified representations that embody all possible readings without explicitly enumerating all possible readings without explicitly enumerating them”them”

• Extract the readings if necessaryExtract the readings if necessary

• Choose amongst those readingsChoose amongst those readings

Haver(e,Restaurant) ^ had(e, Menu) Haver(e,Restaurant) ^ had(e, Menu) • “it should remain agonstic about the placement of

qualifiers”

– 7 – CSCE 771 Spring 2013

StoresStores

Cooper storage (1983)Cooper storage (1983)

For meanings of nodes of parse tree we have been For meanings of nodes of parse tree we have been using predicate calculus (FOL) formulaeusing predicate calculus (FOL) formulae

In Cooper’s approach we replace the single formula In Cooper’s approach we replace the single formula with a “store” consisting of a list of quantified with a “store” consisting of a list of quantified expressions gathered from belowexpressions gathered from below

– 8 – CSCE 771 Spring 2013

Figure 18.6 Semantic Stores for VPFigure 18.6 Semantic Stores for VP

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 9 – CSCE 771 Spring 2013

Hole SemanticsHole Semantics

Hole semantics (Bos 1996)Hole semantics (Bos 1996)

λλ - reductions - reductions

replacereplace λ λ--variables with “holes” variables with “holes” • Instead of using λ – reductions we just create labels

(“holes”)

Dominance constraintsDominance constraints

Plugging the holesPlugging the holes

– 10 – CSCE 771 Spring 2013

Figure 18.7 Hole Semantic Repr. forEvery Restaurant has a menu.Figure 18.7 Hole Semantic Repr. forEvery Restaurant has a menu.

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 11 – CSCE 771 Spring 2013

Figure 18.8Figure 18.8

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 12 – CSCE 771 Spring 2013

Feature and Unification based approachesFeature and Unification based approaches

Feature structures associated with nodes of the parse Feature structures associated with nodes of the parse tree and performing unifications tree and performing unifications

– 13 – CSCE 771 Spring 2013

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

Exists e Closing(e) ^ Closed(e, Rhumba)Exists e Closing(e) ^ Closed(e, Rhumba)

– 14 – CSCE 771 Spring 2013

Figure 18.9 DAG for Semantic FeaturesFigure 18.9 DAG for Semantic Features

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 15 – CSCE 771 Spring 2013

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 16 – CSCE 771 Spring 2013

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 17 – CSCE 771 Spring 2013

Figure 18.10 Earley + SemanticsFigure 18.10 Earley + Semantics

Copyright ©2009 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458

All rights reserved.

Speech and Language Processing, Second EditionDaniel Jurafsky and James H. Martin

– 18 – CSCE 771 Spring 2013

Problem with SQL and AgentsProblem with SQL and Agents

– 19 – CSCE 771 Spring 2013

Consistency of StatementsConsistency of Statements

(5)(5)

a.Sylvania is to the north of Freedonia. a.Sylvania is to the north of Freedonia.

b.Freedonia is a republic. b.Freedonia is a republic.

(6)(6)

a.The capital of Freedonia has a population of 9,000. a.The capital of Freedonia has a population of 9,000.

b.No city in Freedonia has a population of 9,000. b.No city in Freedonia has a population of 9,000.

(7)(7)

a.Sylvania is to the north of Freedonia. a.Sylvania is to the north of Freedonia.

b.Freedonia is to the north of Sylvania.b.Freedonia is to the north of Sylvania.

NLTK Book Chapter 10

– 20 – CSCE 771 Spring 2013

Models againModels again

““A model for a set A model for a set WW of sentences is a formal of sentences is a formal representation of a situation in which all the representation of a situation in which all the sentences in sentences in WW are true.” are true.”

NLTK Book Chapter 10

– 21 – CSCE 771 Spring 2013

Logic and the NLTKLogic and the NLTK

>>> nltk.boolean_ops()>>> nltk.boolean_ops()

negation -negation -

conjunction &conjunction &

disjunction |disjunction |

implication ->implication ->

equivalence <->equivalence <->

>>> lp = nltk.LogicParser()>>> lp = nltk.LogicParser()

>>> lp.parse('-(P & Q)')>>> lp.parse('-(P & Q)')

<NegatedExpression -(P & Q)><NegatedExpression -(P & Q)>

>>> lp.parse('P & Q')>>> lp.parse('P & Q')

<AndExpression (P & Q)><AndExpression (P & Q)>

>>> lp.parse('P | (R -> Q)')>>> lp.parse('P | (R -> Q)')

<OrExpression (P | (R -> Q))><OrExpression (P | (R -> Q))>

>>> lp.parse('P <-> -- P')>>> lp.parse('P <-> -- P')

<IffExpression (P <-> --P)><IffExpression (P <-> --P)>

NLTK Book Chapter 10

– 22 – CSCE 771 Spring 2013

Theorem Prover 9Theorem Prover 9

>>> NotFnS = lp.parse('-north_of(f, s)') >>> NotFnS = lp.parse('-north_of(f, s)')

>>> SnF = lp.parse('north_of(s, f)') >>> SnF = lp.parse('north_of(s, f)')

>>> R = lp.parse('all x. all y. (north_of(x, y) -> -north_of(y, x))') >>> R = lp.parse('all x. all y. (north_of(x, y) -> -north_of(y, x))')

>>> prover = nltk.Prover9() >>> prover = nltk.Prover9()

>>> prover.prove(NotFnS, [SnF, R]) >>> prover.prove(NotFnS, [SnF, R])

TrueTrue

>>> lp = nltk.LogicParser()>>> lp = nltk.LogicParser()

>>> SnF = lp.parse('SnF')>>> SnF = lp.parse('SnF')

>>> NotFnS = lp.parse('-FnS')>>> NotFnS = lp.parse('-FnS')

>>> R = lp.parse('SnF -> -FnS')>>> R = lp.parse('SnF -> -FnS')

>>> prover = nltk.Prover9()>>> prover = nltk.Prover9()

>>> prover.prove(NotFnS, [SnF, R])>>> prover.prove(NotFnS, [SnF, R])

TrueTrue

NLTK Book Chapter 10

– 23 – CSCE 771 Spring 2013

Models and ValuesModels and Values

>>> val = nltk.Valuation([('P', True), ('Q', True), ('R', False)]) >>> val = nltk.Valuation([('P', True), ('Q', True), ('R', False)])

>>> val['P']>>> val['P']

TrueTrue

>>> dom = set([])>>> dom = set([])

>>> g = nltk.Assignment(dom)>>> g = nltk.Assignment(dom)

>>> m = nltk.Model(dom, val)>>> m = nltk.Model(dom, val)

>>> print m.evaluate('(P & Q)', g)>>> print m.evaluate('(P & Q)', g)

TrueTrue

>>> print m.evaluate('-(P & Q)', g)>>> print m.evaluate('-(P & Q)', g)

FalseFalse

>>> print m.evaluate('(P & R)', g)>>> print m.evaluate('(P & R)', g)

FalseFalseNLTK Book Chapter 10

– 24 – CSCE 771 Spring 2013

First Order Logic and the NLTKFirst Order Logic and the NLTK

>>> tlp = nltk.LogicParser(type_check=True)>>> tlp = nltk.LogicParser(type_check=True)

>>> parsed = tlp.parse('walk(angus)')>>> parsed = tlp.parse('walk(angus)')

>>> parsed.argument>>> parsed.argument

<ConstantExpression angus><ConstantExpression angus>

>>> parsed.argument.type>>> parsed.argument.type

ee

>>> parsed.function>>> parsed.function

<ConstantExpression walk><ConstantExpression walk>

>>> parsed.function.type>>> parsed.function.type

<e,?><e,?>NLTK Book Chapter 10

– 25 – CSCE 771 Spring 2013

Free VariablesFree Variables

>>> lp = nltk.LogicParser()>>> lp = nltk.LogicParser()

>>> lp.parse('dog(cyril)').free()>>> lp.parse('dog(cyril)').free()

set([])set([])

>>> lp.parse('dog(x)').free()>>> lp.parse('dog(x)').free()

set([Variable('x')])set([Variable('x')])

>>> lp.parse('own(angus, cyril)').free()>>> lp.parse('own(angus, cyril)').free()

set([])set([])

>>> lp.parse('exists x.dog(x)').free()>>> lp.parse('exists x.dog(x)').free()

set([])set([])

>>> lp.parse('((some x. walk(x)) -> sing(x))').free()>>> lp.parse('((some x. walk(x)) -> sing(x))').free()

set([Variable('x')])set([Variable('x')])

>>> lp.parse('exists x.own(y, x)').free()>>> lp.parse('exists x.own(y, x)').free()

set([Variable('y')])set([Variable('y')])NLTK Book Chapter 10

– 26 – CSCE 771 Spring 2013

>>> NotFnS = lp.parse('-north_of(f, s)') >>> NotFnS = lp.parse('-north_of(f, s)')

>>> SnF = lp.parse('north_of(s, f)') >>> SnF = lp.parse('north_of(s, f)')

>>> R = lp.parse('all x. all y. (north_of(x, y) -> ->>> R = lp.parse('all x. all y. (north_of(x, y) -> -north_of(y, x))') north_of(y, x))')

>>> prover = nltk.Prover9() >>> prover = nltk.Prover9()

>>> prover.prove(NotFnS, [SnF, R]) >>> prover.prove(NotFnS, [SnF, R])

TrueTrue

>>> FnS = lp.parse('north_of(f, s)') >>> FnS = lp.parse('north_of(f, s)')

>>> prover.prove(FnS, [SnF, R]) >>> prover.prove(FnS, [SnF, R])

FalseFalse

NLTK Book Chapter 10

– 27 – CSCE 771 Spring 2013

>>> v = """>>> v = """

... bertie => b... bertie => b

... olive => o... olive => o

... cyril => c... cyril => c

... boy => {b}... boy => {b}

... girl => {o}... girl => {o}

... dog => {c}... dog => {c}

... walk => {o, c}... walk => {o, c}

... see => {(b, o), (c, b), (o, c)}... see => {(b, o), (c, b), (o, c)}

... """... """

>>> val = >>> val = nltk.parse_valuation(v)nltk.parse_valuation(v)

>>> print val>>> print val

{'bertie': 'b',{'bertie': 'b',

'boy': set([('b',)]),'boy': set([('b',)]),

'cyril': 'c','cyril': 'c',

'dog': set([('c',)]),'dog': set([('c',)]),

'girl': set([('o',)]),'girl': set([('o',)]),

'olive': 'o','olive': 'o',

'see': set([('o', 'c'), ('c', 'b'), ('b', 'see': set([('o', 'c'), ('c', 'b'), ('b', 'o')]),'o')]),

'walk': set([('c',), ('o',)])}'walk': set([('c',), ('o',)])}

NLTK Book Chapter 10

– 28 – CSCE 771 Spring 2013

>>> fmla1 = lp.parse('girl(x) | boy(x)')>>> fmla1 = lp.parse('girl(x) | boy(x)')

>>> m.satisfiers(fmla1, 'x', g)>>> m.satisfiers(fmla1, 'x', g)

set(['b', 'o'])set(['b', 'o'])

>>> fmla2 = lp.parse('girl(x) -> walk(x)')>>> fmla2 = lp.parse('girl(x) -> walk(x)')

>>> m.satisfiers(fmla2, 'x', g)>>> m.satisfiers(fmla2, 'x', g)

set(['c', 'b', 'o'])set(['c', 'b', 'o'])

>>> fmla3 = lp.parse('walk(x) -> girl(x)')>>> fmla3 = lp.parse('walk(x) -> girl(x)')

>>> m.satisfiers(fmla3, 'x', g)>>> m.satisfiers(fmla3, 'x', g)

set(['b', 'o'])set(['b', 'o'])

NLTK Book Chapter 10

– 29 – CSCE 771 Spring 2013

Admire RelationAdmire Relation

>>> v2 = """>>> v2 = """

... bruce => b... bruce => b

... cyril => c... cyril => c

... elspeth => e... elspeth => e

... julia => j... julia => j

... matthew => m... matthew => m

... person => {b, e, j, m}... person => {b, e, j, m}

... admire => {(j, b), (b, b), (m, e), (e, m), (c, a)}... admire => {(j, b), (b, b), (m, e), (e, m), (c, a)}

... """... """

>>> val2 = nltk.parse_valuation(v2)>>> val2 = nltk.parse_valuation(v2)NLTK Book Chapter 10

– 30 – CSCE 771 Spring 2013

>>> dom2 = val2.domain>>> dom2 = val2.domain

>>> m2 = nltk.Model(dom2, val2)>>> m2 = nltk.Model(dom2, val2)

>>> g2 = nltk.Assignment(dom2)>>> g2 = nltk.Assignment(dom2)

>>> fmla4 = lp.parse('(person(x) -> exists y.(person(y) & >>> fmla4 = lp.parse('(person(x) -> exists y.(person(y) & admire(x, y)))')admire(x, y)))')

>>> m2.satisfiers(fmla4, 'x', g2)>>> m2.satisfiers(fmla4, 'x', g2)

set(['a', 'c', 'b', 'e', 'j', 'm'])set(['a', 'c', 'b', 'e', 'j', 'm'])

>>> fmla5 = lp.parse('(person(y) & all x.(person(x) -> >>> fmla5 = lp.parse('(person(y) & all x.(person(x) -> admire(x, y)))') admire(x, y)))')

>>> m2.satisfiers(fmla5, 'y', g2) >>> m2.satisfiers(fmla5, 'y', g2)

set([])set([])NLTK Book Chapter 10

– 31 – CSCE 771 Spring 2013

Theorem9 proverTheorem9 prover

arguments = [ arguments = [

('(man(x) <-> (not (not man(x))))', []), ('(man(x) <-> (not (not man(x))))', []),

('(not (man(x) & (not man(x))))', []), ('(not (man(x) & (not man(x))))', []),

('(man(x) | (not man(x)))', []), ('(man(x) | (not man(x)))', []),

('(man(x) & (not man(x)))', []), ('(man(x) & (not man(x)))', []),

('(man(x) -> man(x))', []), ('(man(x) -> man(x))', []),

('(not (man(x) & (not man(x))))', []), ('(not (man(x) & (not man(x))))', []),

('(man(x) | (not man(x)))', []), ('(man(x) | (not man(x)))', []),

('(man(x) -> man(x))', []), ('(man(x) -> man(x))', []),

('(man(x) <-> man(x))', []), ('(man(x) <-> man(x))', []),

('(not (man(x) <-> (not man(x))))', []), ('(not (man(x) <-> (not man(x))))', []),

('mortal(Socrates)', ['all x.(man(x) -> mortal(x))', 'man(Socrates)']), ('mortal(Socrates)', ['all x.(man(x) -> mortal(x))', 'man(Socrates)']),

('((all x.(man(x) -> walks(x)) & man(Socrates)) -> some y.walks(y))', ('((all x.(man(x) -> walks(x)) & man(Socrates)) -> some y.walks(y))', []), []),

– 32 – CSCE 771 Spring 2013

('(all x.man(x) -> all x.man(x))', []), ('(all x.man(x) -> all x.man(x))', []),

('some x.all y.sees(x,y)', []), ('some x.all y.sees(x,y)', []),

('some e3.(walk(e3) & subj(e3, mary))', ['some e1.('some e3.(walk(e3) & subj(e3, mary))', ['some e1.(see(e1) & subj(e1, john) & some e2.(pred(e1, e2) & (see(e1) & subj(e1, john) & some e2.(pred(e1, e2) & walk(e2) & subj(e2, mary)))']), walk(e2) & subj(e2, mary)))']),

('some x e1.(see(e1) & subj(e1, x) & some e2.(pred(e1, ('some x e1.(see(e1) & subj(e1, x) & some e2.(pred(e1, e2) & walk(e2) & subj(e2, mary)))', ['some e1.(see(e1) e2) & walk(e2) & subj(e2, mary)))', ['some e1.(see(e1) & subj(e1, john) & some e2.(pred(e1, e2) & walk(e2) & & subj(e1, john) & some e2.(pred(e1, e2) & walk(e2) & subj(e2, mary)))']) ]subj(e2, mary)))']) ]