feature-based grammar ling 571 deep techniques for nlp february 2, 2001

50
Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Upload: mary-heath

Post on 28-Mar-2015

226 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Feature-based Grammar

Ling 571Deep Techniques for NLP

February 2, 2001

Page 2: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

RoadmapImplementing feature-based grammars

Features in NLTK

Designing feature grammarsA Complex Agreement Example

Semantic features

Page 3: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

SummaryFeatures defined

Modeling features:Attribute-Value Matrices (AVM)Directed Acyclic Graph (DAG)

Mechanisms for features:SubsumptionUnification

Parsing with features:Augmenting the Earley parser

Page 4: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Feature Grammar in NLTKNLTK supports feature-based grammars

Includes ways of associating features with CFG rules

Includes readers for feature grammars.fcfg files

Includes parsers Nltk.parse.FeatureEarleyChartParse

Page 5: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Creating and Accessing NLTK Feature Structures

Create with FeatStruct

Page 6: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Creating and Accessing NLTK Feature Structures

Create with FeatStruct

>>> fs1 = nltk.FeatStruct(NUMBER=‘pl’,PERSON=3)

>>>print fs1[ NUMBER = ‘pl’][ PERSON = 3 ]

>>> print fs1[‘NUMBER’]pl>> fs1[‘NUMBER’] = ‘sg’

Page 7: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Creating and Accessing NLTK Feature Structures

Create with FeatStruct

>>> fs1 = nltk.FeatStruct(NUMBER=‘pl’,PERSON=3)

Page 8: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Creating and Accessing NLTK Feature Structures

Create with FeatStruct

>>> fs1 = nltk.FeatStruct(NUMBER=‘pl’,PERSON=3)

>>>print fs1[ NUMBER = ‘pl’][ PERSON = 3 ]

Page 9: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Creating and Accessing NLTK Feature Structures

Create with FeatStruct

>>> fs1 = nltk.FeatStruct(NUMBER=‘pl’,PERSON=3)

>>>print fs1[ NUMBER = ‘pl’][ PERSON = 3 ]

>>> print fs1[‘NUMBER’]pl

Page 10: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Creating and Accessing NLTK Feature Structures

Create with FeatStruct

>>> fs1 = nltk.FeatStruct(NUMBER=‘pl’,PERSON=3)

>>>print fs1[ NUMBER = ‘pl’][ PERSON = 3 ]

>>> print fs1[‘NUMBER’]pl>> fs1[‘NUMBER’] = ‘sg’

Page 11: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Complex Feature Structures

>>>fs2 = nltk.FeatStruct(POS=‘N’,AGR=fs1)

Page 12: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Complex Feature Structures

>>>fs2 = nltk.FeatStruct(POS=‘N’,AGR=fs1)>>>print fs2[ POS = ‘N’ ][ [ NUMBER = ‘sg’ ] ][ AGR = [ PERSON = 3 ] ]

Page 13: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Complex Feature Structures

>>>fs2 = nltk.FeatStruct(POS=‘N’,AGR=fs1)>>>print fs2[ POS = ‘N’ ][ [ NUMBER = ‘sg’ ] ][ AGR = [ PERSON = 3 ] ]

Alternatively,>>> fs3 = nltk.FeatStruct(“[POS=‘N’,

AGR=[NUM=‘pl’,PER=3]]”)

Page 14: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Reentrant Feature Structures

First instanceParenthesized integer: (1)

Page 15: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Reentrant Feature Structures

First instanceParenthesized integer: (1)

Subsequent instances: ‘Pointer’: -> (1)

Page 16: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Reentrant Feature Structures

First instanceParenthesized integer: (1)

Subsequent instances: ‘Pointer’: -> (1)

>>> print nltk.FeatStruct("[A='a', B=(1)[C='c'], D->(1)]”

Page 17: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Reentrant Feature Structures

First instanceParenthesized integer: (1)

Subsequent instances: ‘Pointer’: -> (1)

>>> print nltk.FeatStruct("[A='a', B=(1)[C='c'], D->(1)]”

[ A = ‘a’ ][ B = (1) [ C = ‘c’]][ D -> (1) ]

Page 18: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Augmenting GrammarsAttach feature information to non-terminals, on

N[AGR=[NUM='pl']] -> 'students’N[AGR=[NUM=’sg']] -> 'student’

Page 19: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Augmenting GrammarsAttach feature information to non-terminals, on

N[AGR=[NUM='pl']] -> 'students’N[AGR=[NUM=’sg']] -> 'student’

So far, all values are literal or reentrant

Page 20: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Augmenting GrammarsAttach feature information to non-terminals, on

N[AGR=[NUM='pl']] -> 'students’N[AGR=[NUM=’sg']] -> 'student’

So far, all values are literal or reentrantVariables allow generalization: ?a

Allows underspecification, e.g. Det[GEN=?a]

Page 21: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Augmenting GrammarsAttach feature information to non-terminals, on

N[AGR=[NUM='pl']] -> 'students’N[AGR=[NUM=’sg']] -> 'student’

So far, all values are literal or reentrantVariables allow generalization: ?a

Allows underspecification, e.g. Det[GEN=?a]NP[AGR=?a] -> Det[AGR=?a] N[AGR=?a]

Page 22: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Mechanics>>> fs3 = nltk.FeatStruct(NUM=‘pl’,PER=3)

>>> fs4 = nltk.FeatStruct(NUM=‘pl’)

>>> print fs4.unify(fs3)

[NUM = ‘pl’]

[PER = 3 ]

Page 23: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Morphosyntactic FeaturesGrammatical feature that influences

morphological or syntactic behavior English:

Number: Dog, dogs

Person: Am; are; is

Case: I – me; he – him; etc

Countability:

Page 24: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

More Complex German Example

Subject – singular, mascder HundThe dog

Subject –plural, mascdie Hunde The dogs

Page 25: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

More Complex German Example

Objects – determined by verb

Dative – singular, mascdem HundThe dog

Accusative –plural, mascdie Hunde The dogs

Page 26: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ContrastSubject:

Die KatzeThe cat

Subject: pluralDie KatzeThe cats

Page 27: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ContrastObject:

Die KatzeThe cat

Object: Der KatzeThe cat

Page 28: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

AnalysisWhat are the key contrasts?

NumberSingular, plural

GenderMasc, Fem, ….

Case:Subject (nom), dative, accusative, ….

+ Interactions

Page 29: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Feature InteractionInteractions of German case, number, gender

Case Masc Fem Neut PL

Nom Der Die Das Die

Gen Des Der Des Den

Dat Dem Der Dem Den

Acc Den Die Das Die

Page 30: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Examples of InteractionDieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DenThe.Acc.Masc.sg

HundDog.3.Masc.sg

Page 31: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Examples of InteractionDieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DenThe.Acc.Masc.sg

HundDog.3.Masc.sg

*DieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DemThe.Dat.Masc.sg

HundDog.3.Masc.sg

Page 32: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Examples of InteractionDieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DenThe.Acc.Masc.sg

HundDog.3.Masc.sg

*DieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DemThe.Dat.Masc.sg

HundDog.3.Masc.sg

DieThe.Nom.Fem.sgThe cat helps the dog

KatzeCat.3.FEM.SG

hilft help.3.sg

DemThe.Dat.Masc.sg

HundDog.3.Masc.sg

Page 33: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Examples of Interaction

DieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DenThe.Acc.Masc.sg

HundDog.3.Masc.sg

*DieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

Sieht See.3.sg

DemThe.Dat.Masc.sg

HundDog.3.Masc.sg

DieThe.Nom.Fem.sgThe cat helps the dog

KatzeCat.3.FEM.SG

hilft help.3.sg

DemThe.Dat.Masc.sg

HundDog.3.Masc.sg

*DieThe.Nom.Fem.sgThe cat sees the dog

KatzeCat.3.FEM.SG

hilft help.3.sg

DemThe.Acc.Masc.sg

HundDog.3.Masc.sg

German verbs in, at least, 2 classes: assign diff’t object case

Page 34: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic FeaturesGrammatical features that influence

semantic(meaning) behavior of associated units

E.g.:

Page 35: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic FeaturesGrammatical features that influence

semantic(meaning) behavior of associated units

E.g.:?The rocks slept.

Page 36: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic FeaturesGrammatical features that influence

semantic(meaning) behavior of associated units

E.g.:?The rocks slept.

?Colorless green ideas sleep furiously.

Page 37: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic FeaturesMany proposed:

Animacy: +/-Natural gender: masculine, feminine, neuterHuman: +/-Adult: +/-Liquid: +/-Etc.The milk spilled.?The cat spilled.

Page 38: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ExamplesThe climber hiked for six hours.

Page 39: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ExamplesThe climber hiked for six hours.

The climber hiked on Saturday.

Page 40: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ExamplesThe climber hiked for six hours.

The climber hiked on Saturday.

The climber reached the summit on Saturday.

Page 41: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ExamplesThe climber hiked for six hours.

The climber hiked on Saturday.

The climber reached the summit on Saturday.

*The climber reached the summit for six hours.

Contrast:

Page 42: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

ExamplesThe climber hiked for six hours.

The climber hiked on Saturday.

The climber reached the summit on Saturday.

*The climber reached the summit for six hours.

Contrast:Achievement vs activity

Page 43: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.

Page 44: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.(Old men) and (women) slept.

Page 45: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.(Old men) and (women) slept.(Old (men and women)) slept.

Page 46: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.(Old men) and (women) slept.(Old (men and women)) slept.

Sleeping people and books lie flat.

Page 47: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.(Old men) and (women) slept.(Old (men and women)) slept.

Sleeping people and books lie flat.(Sleeping people) and (books) lie flat.

Page 48: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.(Old men) and (women) slept.(Old (men and women)) slept.

Sleeping people and books lie flat.(Sleeping people) and (books) lie flat.(Sleeping (people and books ))lie flat.

Page 49: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

Semantic features & Parsing

Can filter some classes of ambiguity

Old men and women slept.(Old men) and (women) slept.(Old (men and women)) slept.

Sleeping people and books lie flat.(Sleeping people) and (books) lie flat.*(Sleeping (people and books ))lie flat.

Page 50: Feature-based Grammar Ling 571 Deep Techniques for NLP February 2, 2001

SummaryFeatures

Enable compact representation of grammatical constraints

Capture basic linguistic patterns

UnificationCreates and maintains consistency over features

Integration with parsing allows filtering of ill-formed analyses