Week 9: Probabilistische Grammatica's

Post on 04-Jan-2016

33 views 2 download

description

Remko Scha, ILLC Opleiding Kunstmatige Intelligentie. Taaltheorie en Taalverwerking. Week 9: Probabilistische Grammatica's. Jurafsky & Martin (ed. 1), Hoofdstuk 12: Lexicalized and Probabilistic Parsing). Ambiguïteit. Ambiguïteit. Ambiguïteit. Ambiguïteit. - PowerPoint PPT Presentation

Transcript of Week 9: Probabilistische Grammatica's

Week 9: Probabilistische Grammatica's

Jurafsky & Martin (ed. 1), Hoofdstuk 12:Lexicalized and Probabilistic Parsing)

Taaltheorie en Taalverwerking

Remko Scha, ILLCOpleiding Kunstmatige Intelligentie

Ambiguïteit

Ambiguïteit

Ambiguïteit

Ambiguïteit

Cf.: Can you book me a flight? Can you book Mr. Jones some flights?

Syntactische Ambiguïteit

Wat voor redenen zijn er om Can you [book [TWA flights]]? te verkiezen boven Can you [book TWA flights]?

1. Pragmatisch: Men vraagt niet vaak of je voor een specifiek iemand vluchten kunt boeken. Of: men vraagt niet vaak over vluchten zonder verdere specificaties.

2. Semantisch:Vluchten boeken voor een vliegmaatschappij is onzinnig in dit domein.

3. Syntactisch:Werkwoorden worden meestal zonder meewerkend voorwerp gebruikt;of: "to book" wordt meestal zonder meewerkend voorwerp gebruikt;of: "flights" wordt vaak met een modifier gebruikt; etc.

Syntactische Ambiguïteit

Disambiguërings-methodes:

1./2. Pragmatisch/Semantisch: Bepaal betekenis-representaties voor elk van de mogelijke interpretaties. Redeneer over wat iemand kan willen weten en over wat zinnig is in dit domein. [Ouderwetse symbolische A.I.]

Syntactische Ambiguïteit

Disambiguërings-methodes:

1./2. Pragmatisch/Semantisch: Bepaal betekenis-representaties voor elk van de mogelijke interpretaties. Redeneer over wat iemand kan willen weten en over wat zinnig is in dit domein.

2. Syntactisch:Doe statistiek over syntactische structuren.

Syntactische Ambiguïteit

Disambiguërings-methodes:

1./2. Pragmatisch/Semantisch: Bepaal betekenis-representaties voor elk van de mogelijke interpretaties. Redeneer over wat iemand kan willen weten en over wat zinnig is in dit domein.

2. Syntactisch:Doe statistiek over syntactische structuren.

Merk op: distributie van syntactische structuren kan correleren met pragmatisch/semantische regelmatigheden

Syntactische Ambiguïteit

Disambiguërings-methodes:

1./2. Pragmatisch/Semantisch: Bepaal betekenis-representaties voor elk van de mogelijke interpretaties. Redeneer over wat iemand kan willen weten en over wat zinnig is in dit domein.

2. Syntactisch:Doe statistiek over syntactische structuren.

Merk op: distributie van syntactische structuren correleert met pragmatisch/semantische regelmatigheden, vooral als we ook informatie over specifieke lexicale items meenemen.

Kansrekening: Basics. [Russell & Norvig, pp. 466-478.]

Kansrekening: Basics.

Het begrip kans veronderstelt een partitie van een ruimte van mogelijkheden.

Een kans beschrijft de relatieve grootte van een deel van die ruimte.

B.v.: een meting met k mogelijke uitkomsten:

P(1) + P(2) + . . . + P(k) = 1.

Kansrekening: Basics.

Joint probabilities.

Als A en B uitkomsten zijn van 2 verschillende onafhankelijke metingen, dan is de kans op A en B:

P(A & B) = P(A) P(B)

Kansrekening: Basics.

Conditionele waarschijnlijkheden.

De kans op A gegeven B schrijven we als: P(A|B)

Kansrekening: Basics.

Algemeen geldt:P(A & B) = P(A|B) P(B)P(A & B) = P(B|A) P(A)

Als A en B onafhankelijk zijn, dan is

P(A|B) = P(A)P(B|A) = P(B)

dus P(A & B) = P(A) P(B)

Statistische syntactische desambiguëring.

Statistische syntactische desambiguëring.

Eenvoudigste idee:

Probabilistische Contextvrije Grammatica (PCFG)

Probabilistische Contextvrije Grammatica (PCFG)

Voeg aan elke herschrijfregel (A ) een conditionele kans toe: P(A | A)

Probabilistische Contextvrije Grammatica (PCFG)

Voeg aan elke herschrijfregel (A ) een conditionele kans toe: P(A | A)

Eis: P(A ) = 1

CFG: 4-tupel <N, , P, S>

N: eindige verzameling non-terminale symbolen

(b.v.: {S, NP, VP, noun, article, ...})

: eindige verzameling terminale symbolen (b.v.: {the, a, boy, wumpus, ...})

N =

S: startsymbool; S N

P: eindige verzameling herschrijfregels { A, .....} A N, (N )*

Cf. Jurafsky & Martin: Hoofdstuk 9 (Context-Free Grammars for English), p. 331

PCFG: 5-tupel <N, , P, S, D>

N: eindige verzameling non-terminale symbolen

(b.v.: {S, NP, VP, noun, article, ...})

: eindige verzameling terminale symbolen (b.v.: {the, a, boy, wumpus, ...})

N =

S: startsymbool; S N

P: eindige verzameling herschrijfregels { A, .....} A N, (N )*D: functie die aan elke regel p P een getal tussen 0 en 1 toekent.

A N P(A ) = 1

Cf. Jurafsky & Martin: Hoofdstuk 12, pp. 448/449

PCFG

Kans op een parse-tree =

Product van de kansen van alle toegepaste regels

Example PCFG

P = .15 * .40 * .05 * .05 * .35* .75 * .40 * .40 *.40 *.30 * .40 *.50 = 1.5 * 10-6

P = .15 * .40 * .40 * .05 * .05* .75 * .40 * .40 *.40 *.30 * .40 *.50 = 1.7 * 10-6

Statistische Desambiguëring: Kies de boom met de hoogste waarschijnlijkheid

Kans op een zin =

Som van de kansen van de verschillende bomen van die zin.

(Toepassing: Spraakherkenning.)

Hoe bepaal je de kansen van de CFG-regels?

• Schatting op basis van de relatieve frequenties in een "treebank" (syntactisch geannoteerd corpus).

• "Expectation Maximization": Gegeven een "plat" corpus (collectie zinnen): stel de waarschijnlijkheden zodanig in, dat de kans om dat corpus te genereren zo groot mogelijk is.

Beperking van PCFG's:

De toepassingen van de herschrijfregels worden behandeld als statistisch onafhankelijk.

Een PCFG kent aan deze beide analysesaltijd dezelfde waarschijnlijkheid toe!

Oplossing:

• PCFG's met verrijkte labels die niet-locale informatie coderen

• Stochastic Tree Substitution Grammars

Lexicalized PCFG's: Head-features(Collins et al.)

Lexicalized PCFG's: Head-features

VP(dumped) VBD(dumped) NP(sacks) PP(into) waarschijnlijk

NP(sacks) NP(sacks) PP(into) onwaarschijnlijk

VP(dumped) VBD(dumped) NP(sacks) PP(with) niet heel waarschijnlijk

NP(sacks) NP(sacks) PP(with) heel waarschijnlijk

Data-Oriented Parsing (DOP)

(Scha, Bod, Sima'an)

Gebruik een geannoteerd corpus ("treebank").

Lees een Stochastic Tree Substitution Grammar

rechtstreeks af uit het corpus.

(PPT-presentatie van Guy De Pauw, Universiteit Antwerpen)

Data-Oriented Parsing (DOP)

Gebruik een geannoteerd corpus.

Gebruik een Stochastic Tree Substitution Grammar

Lees deze STSG rechtstreeks af uit het corpus

(PPT van Guy De Pauw, Universiteit Antwerpen)

Peter

NP

killed

a raccoon

NP

VP

S

Peter

NP

killed NP

VP

S

killed

a raccoon

NP

VP

Peter

NP VP

SNP

killed

a raccoon

NP

VP

S

a raccoon

NP

Peter

NP

NP VP

S

NP

killed NP

VP

S

the bear

NP

ate

honey

NP

VP

S

the bear

NP

ate NP

VP

S

the bear

NP VP

S

NP

ate

honey

NP

VP

S

ate

honey

NP

VP

NP VP

S

honey

NP

ate NP

VPthe bear

NP

NP

ate NP

VP

S

Treebank

honey

NP

the bear

NP

a raccoon

NP

Peter

NP

killed

a raccoon

NP

VP

ate

honey

NP

VP

ate NP

VP

killed NP

VP

Peter

NP

killed

a raccoon

NP

VP

S

NP

killed NP

VP

S

the bear

NP

ate NP

VP

S

the bear

NP VP

S

NP

ate

honey

NP

VP

S

NP VP

S

NP

ate NP

VP

S

Peter

NP

killed NP

VP

S

NP

killed

a raccoon

NP

VP

S

NP VP

S

Peter

NP VP

S

the bear

NP

ate

honey

NP

VP

S

Sentence to be parsed: Peter killed the bear

Peter

NP

killed NP

VP

S

the bear

NP Peter

NP VP

S

NP VP

S

NP

killed NP

VP

S

1 parse-tree; meerdere afleidingen

Data-Oriented Parsing

the bear

NPkilled NP

VP

Peter

NP

the bear

NP killed NP

VP

the bear

NPPeter

NP

An annotated corpus defines a Stochastic Tree Substitution Grammar

Probability of a Derivation:Product of the Probabilities of the Subtrees

Probability of a Derivation:Product of the Probabilities of the Subtrees

Probability of a Parse:Sum of the Probabilities of its Derivations

An annotated corpus defines a Stochastic Tree Substitution Grammar

Probability of a Derivation:Product of the Probabilities of the Subtrees

Probability of a Parse:Sum of the Probabilities of its Derivations

Disambiguation: Choose the Most Probable Parse

An annotated corpus defines a Stochastic Tree Substitution Grammar

Human parsing continued.

Human parsing continued.

• Center-embedding (J&M, § 13.4)

Human parsing continued.

• Center-embedding (J&M, § 13.4)

• Garden-path sentences (J&M, § 12.5)

Garden-path sentences

"The horse raced past the barn

Garden-path sentences

"The horse raced past the barn fell."

Garden-path sentences

"The complex houses

Garden-path sentences

"The complex houses graduate students."

Garden-path sentences

"The student forgot the solution

Garden-path sentences

"The student forgot the solution was in the back of the book."

Garden-path sentences

• Desambiguëring gebeurt incrementeel.• Desambiguëringsbeslissing kan te vroeg genomen

worden.

Opgave:

(1) Gebruik waarschijnlijkheden aan toe aan je CFG.

(2) Zorg dat je parser alle mogelijke analyses van de input-zin oplevert.

(3) Zorg dat je parser de waarschijnlijkheden van alle analyses berekent, en de meest waarschijnlijke boom als output geeft.

Spraak & Taal: "Language Modelling"

Spraak: Giswerk.

Corpus-gebaseerde aanpak: Sla heel veelgeluiden op en kijk waar het input-signaal het meest op lijkt.

Men doet dit met statistiek: Men schat dekans dat aan een stukje input-signaal een bepaald foneem ten grondslag ligt.

Spraak & Taal: "Language Modelling"

De spraakherkennings-technologie stelt ons in staat om voor elk kandidaat-woord W en elk input-signaal te schatten: de kans dat iemand W uitspreekt als S:

P(S | W)

Spraak & Taal: "Language Modelling"

De spraakherkennings-technologie stelt ons in staat om voor elk kandidaat-woord W en elk input-signaal te schatten: de kans dat iemand W uitspreekt als S:

P(S | W)

Wat we willen weten is: De kans dat aan het gegeven input-signaal S een kandidaat-woord W ten grondslag ligt:

P(W | S)

Spraak & Taal: "Language Modelling"

De spraakherkennings-technologie stelt ons in staat om voor elk kandidaat-woord W en elk input-signaal te schatten: de kans dat iemand W uitspreekt als S:

P(S | W)

Wat we willen weten is: De kans dat aan het gegeven input-signaal S een kandidaat-woord W ten grondslag ligt:

P(W | S)Wat nu?

Elementaire kansrekening:de regel van Bayes

Elementaire kansrekening:de regel van Bayes

P(W & S) = P(W|S) P(S)P(W & S) = P(S|W) P(W)

Elementaire kansrekening:de regel van Bayes

P(W & S) = P(W|S) P(S)P(W & S) = P(S|W) P(W)

P(W|S) P(S) = P(S|W) P(W)

Elementaire kansrekening:de regel van Bayes

P(W & S) = P(W|S) P(S)P(W & S) = P(S|W) P(W)

P(W|S) P(S) = P(S|W) P(W)

P(W|S) = P(S|W) P(W) / P(S)

Elementaire kansrekening:de regel van Bayes

P(W & S) = P(W|S) P(S)P(W & S) = P(S|W) P(W)

P(W|S) P(S) = P(S|W) P(W)

P(W|S) = P(S|W) P(W) / P(S)

P(W|S) ≈ P(S|W) P(W)

P(W) is de a priori kans op woord W

Spraak & Taal: "Language Modelling"

Voor de spraakherkenning willen we weten:

de a priori kansen op alle mogelijke woorden.

Spraak & Taal: "Language Modelling"

Voor de spraakherkenning willen we weten:

de a priori kansen op alle mogelijke woorden.

Hoe komen we daar achter?

Tellen in een representatief corpus.

Statistical Language Model

)|()|(

)|()()()(

121123

121321

WWWWPWWWP

WWPWPWWWWPWP

NN

N

LL

L

==

P(the cat is on the mat) =P(the | <s>) * P(cat | <s> the) *P(is | <s> the cat) *P(on | <s> the cat is) *P(the | <s> the cat is on) *P (mat | <s> the cat is on the) *P(</s> | <s> the cat is on the mat)

(P(w w ))n

n = 1

N

1, . . , Wn - 1∏ |

P(W1,…,WN) =

Bigram models

P(the cat is on the mat) =P(the | <s>) * P(cat | the) * P(is | cat) *P(on | is) * P(the | on) *P (mat | the) * P(</s> | mat)

)|()|()|()( 123121 −≈ NN WWPWWPWWPWP L

)|()( 1

11

−∏=

≈ kk wwPwPn

k

n

Example: Bigrams

Example: Bigrams (continued)

P(I want to eat British food) =P(I|<s>)P(want|I)P(to|want)P(eat|to)P(British|eat)P(food|British) = .25 * .32 * .65 * .26 * .002 * .60 = .000016

Trigram models

P(the cat is on the mat) =P(the | <s>) * P(cat | <s> the) *P(is | the cat) *P(on | cat is) *P(the | is on) *P (mat | on the) *P(</s> | the mat)

)|()|()|()( 21123121 −−≈ NNN WWWPWWWPWWPWP L

Estimating bigram probabilities

e.g. P (book | the) =C(the,book)

C(the)

)C(w

)w,C(w)w|P(w

1-n

n1-n

1-nn =