Stochastische Attribut-Wert-Grammatiken

28
Stochastische Attribut-Wert- Grammatiken Universität Potsdam – Institut für Linguistik Hauptseminar Stochastische Lernalgorithmen Gerhard Jäger – Referent: Rainer Ludwig

description

Stochastische Attribut-Wert-Grammatiken. Universität Potsdam – Institut für Linguistik Hauptseminar Stochastische Lernalgorithmen Gerhard Jäger – Referent: Rainer Ludwig. Überblick. Stochastische kontextfreie Grammatiken Empirical Relative Frequency Übergang von (S)CFG zu (S)AVG - PowerPoint PPT Presentation

Transcript of Stochastische Attribut-Wert-Grammatiken

Page 1: Stochastische Attribut-Wert-Grammatiken

Stochastische Attribut-Wert-Grammatiken

Universität Potsdam – Institut für Linguistik

Hauptseminar Stochastische Lernalgorithmen

Gerhard Jäger – Referent: Rainer Ludwig

Page 2: Stochastische Attribut-Wert-Grammatiken

Überblick

• Stochastische kontextfreie Grammatiken– Empirical Relative Frequency

• Übergang von (S)CFG zu (S)AVG

• Stochastische AVG– Random Fields– Improved Iterative Scaling

Page 3: Stochastische Attribut-Wert-Grammatiken

Stochastische CFG

1. S A A 1 = 1/22. S B 2 = 1/23. A a 3 = 2/34. A b 4 = 1/35. B a a 5 = 1/26. B b b 6 = 1/2

1

3 3

9

2

3

2

3

2

2

1)( 3311 xq

S

A A

a a

x =

Page 4: Stochastische Attribut-Wert-Grammatiken

• Bestimmung der Werte der Gewichte i

• Diese sollen das Trainingskorpus bestmöglich reflektieren

Parameterabschätzung

• D. h.: Die Distribution q(x), die durch die i bestimmt wird, soll der Distribution im Trainingskorpus möglichst nahe kommen

(x)p~

Page 5: Stochastische Attribut-Wert-Grammatiken

Empirische Distribution in einem Korpus

S

A A

a a

S

A A

b b

S

B

a a

S

B

b b

x1 x2 x3 x4

c = 4x 2x 3x 3x

p~ 4/12 2/12 3/12 3/12

2/9 1/18 1/4 1/4q1 =

Page 6: Stochastische Attribut-Wert-Grammatiken

Kullback-Leibler-Divergenz

• Maß für die Unähnlichkeit zwischen Distributionen (≙ relative Entropie)

x xq

xpxpqpD

)(

)(~ln)(~)||~(

Page 7: Stochastische Attribut-Wert-Grammatiken

Empirical Relative Frequency (ERF)

• Jede Regel i der Grammatik bekommt eine Häufigkeitsfunktion fi(x) zugewiesen

• p[f]: Erwartungswert von f unter Wahrscheinlichkeitsverteilung p, d. h.

x

xfxpfp )()(

i werden so gewählt, dass sie proportional zu sind ifp~

Page 8: Stochastische Attribut-Wert-Grammatiken

Empirical Relative Frequency (ERF)

• ERF ermittelt die besten Gewichte für eine gegebene CFG bei einer gegebenen empirischen Distribution

S -> AA S ->B A -> a A -> b B -> aa B -> bbp pf1 pf2 pf3 pf4 pf5 pf6

x1 1/3 1/3 0 2/3 0 0 0x2 1/6 1/6 0 0 1/3 0 0x3 1/4 0 1/4 0 0 1/4 0x4 1/4 0 1/4 0 0 0 1/4

p[f] = 1/2 1/2 2/3 1/3 1/4 1/4beta = 1/2 1/2 2/3 1/3 1/2 1/2

Page 9: Stochastische Attribut-Wert-Grammatiken

Empirische Distribution in einem Korpus

S

A A

a a

S

A A

b b

S

B

a a

S

B

b b

x1 x2 x3 x4

c = 4x 2x 3x 3x

p~ 4/12 2/12 3/12 3/12

2/9 1/18 1/4 1/4q1 =

197)(

4

11

iixq

Page 10: Stochastische Attribut-Wert-Grammatiken

1. S 1:A 2:A <1 1> = <2 1>2. S 1:B3. A 1:a4. A 1:b5. B 1:a6. B 1:b

Attribut-Wert-Grammatiken und DAGs

S

a

1

AA

1 2

1

Page 11: Stochastische Attribut-Wert-Grammatiken

Attribut-Wert-Grammatiken und DAGs

S

A A

a

S

A A

b

S

B

a

S

B

b

x1 x2 x3 x4

S 1:A 2:A <1 1> = <2 1> S 1:BA 1:a A 1:bB 1:a B 1:b

Page 12: Stochastische Attribut-Wert-Grammatiken

1. S 1:A 2:A <1 1> = <2 1> 1 = 1/22. S 1:B 2 = 1/23. A 1:a 3 = 2/34. A 1:b 4 = 1/35. B 1:a 5 = 1/26. B 1:b 6 = 1/2

Stochastische AVG

S

a

1

AA

1 2

1

1

3 3

9

2

3

2

3

2

2

1)( 3312 x

n

i

xfi

ix1

)()( Allgemein:

Page 13: Stochastische Attribut-Wert-Grammatiken

Empirische Distribution in einem Korpus

S

A A

a

S

A A

b

S

B

a

S

B

b

x1 x2 x3 x4

c = 4x 2x 3x 3x

p~ 4/12 2/12 3/12 3/12

2/9 1/18 1/4 1/42 = Σ = 7/9

2/7 1/14 9/28 9/28q2 = Σ = 1

Page 14: Stochastische Attribut-Wert-Grammatiken

1. S 1:A 2:A <1 1> = <2 1>

2. S 1:B

3. A 1:a

4. A 1:b

5. B 1:a

6. B 1:b

Alternative Regelgewichte

226223

1

2263

2

212

3

211

4

21

5

21

6

Page 15: Stochastische Attribut-Wert-Grammatiken

Wahrscheinlichkeitsverteilung mit den neuen Gewichten

S

A A

a

S

A A

b

S

B

a

S

B

b

x1 x2 x3 x4

c = 4x 2x 3x 3x

p~ 4/12 2/12 3/12 3/12

1/3 1/6 1/4 1/4q =

=7

23 14

23 28

239 28

239 23

3

Page 16: Stochastische Attribut-Wert-Grammatiken

• Wahrscheinlichkeitsverteilung über Konfigurationen (hier DAGs)

• Gewicht einer Konfiguration ist das Produkt der Gewichte bestimmter Merkmale dieser Konfiguration

Random Fields

i

xfi

ix )()(

• Wahrscheinlichkeit einer Konfiguration ergibt sich aus der Normalisierung des Gewichts

Page 17: Stochastische Attribut-Wert-Grammatiken

Merkmale in Random Fields

• Merkmale können lokale Bäume (Regelanwendungen) sein, müssen aber nicht

• Keine Beschränkung für die Summe der Gewichte von Regeln mit gleicher LHS (vorher: =1)

Page 18: Stochastische Attribut-Wert-Grammatiken

Ein Beispiel für Merkmale

S

A A

a

S

A A

b

S

B

a

S

B

b

f1 = 2 0 0 0

2 1 3/2 3/2 =

0 0 1 1f2 =

1/3 1/6 1/4 1/4q =

3/22

Merkmale:

=

A

aB1

2

p~q

Page 19: Stochastische Attribut-Wert-Grammatiken

• Es müssen nicht mehr nur die Werte der Gewichte i bestimmt werden, sondern auch die Merkmale fi ausgewählt werden

• Ziel weiterhin: Minimierung der Kullback-Leibler-Divergenz

Parameterabschätzung

)||~( qpD

• Lösung: Improved Iterative Scaling

Page 20: Stochastische Attribut-Wert-Grammatiken

Improved Iterative Scaling (IIS)

1. Beginne mit dem Nullfeld, i. e. ohne Merkmale

2. Merkmalsauswahl. Wähle das beste Merkmal und füge es dem Feld hinzu.

3. Anpassen der Gewichte. Passe für alle Merkmale die Gewichte an.

4. Iteriere, bis das Feld nicht mehr besser wird.

Page 21: Stochastische Attribut-Wert-Grammatiken

Das Nullfeld

S

A A

a

S

A A

b

S

B

a

S

B

b

1 1 1 1 =

1/4 1/4 1/4 1/4q =

03,0)||~( qpD

p~ 1/3 1/6 1/4 1/4

Page 22: Stochastische Attribut-Wert-Grammatiken

Bestandteile eines Modells

1. Eine AVG G

2. Eine Menge von Initialgewichten θ für die Regeln in G Initialdistribution p0

3. Eine Menge von Merkmalen f1,..., fn mit Gewichten β1,..., βn

Felddistribution q

i

xfi

ixpZ

xq )(0 )(

1)(

Page 23: Stochastische Attribut-Wert-Grammatiken

Merkmalsauswahl

• Merkmale sind in unserem Beispiel Sub-DAGs• Diese werden aus atomaren Merkmalen (=

einzelnen DAG-Knoten) zusammengebaut• In Schritt 2 von IIS werden alle möglichen neuen

Merkmale mit ihrem jeweils besten Gewicht betrachtet

• Es wird dasjenige Merkmal ausgewählt, das die größte Reduktion der KLD bringt

Page 24: Stochastische Attribut-Wert-Grammatiken

Merkmalsauswahl – BeispielS

A A

a

S

A A

b

S

B

a

S

B

b

p~ 1/3 1/6 1/4 1/47/5 1 7/5 1a =

7/24 5/24 7/24 5/24qa =

1 1 1 1B =

1/4 1/4 1/4 1/4qB =

D = 0,01aq

p~lnp~ 0,04 0,05– 0,04– 0,04

D = 0,03Bq

p~lnp~ 0,10 00– 0,07

Page 25: Stochastische Attribut-Wert-Grammatiken

Auswahl des Gewichts für ein gewähltes Merkmal

• Das neue Gewicht β soll so gewählt werden, dass der Erwartungswert von f dem empirischen entspricht, also fpfq ~

• Wenn L(G) sehr groß (unendlich) ist, lässt sich die Gleichung nicht ohne weiteres lösen Random Sampling

Page 26: Stochastische Attribut-Wert-Grammatiken

Anpassen der Gewichte

• Nach dem Hinzufügen eines neuen Merkmals mit einem bestimmten Gewicht ist es i. a. nötig, die Gewichte (β1,..., βn) aller Merkmale anzupassen (Schritt 3 von IIS)

• D. h. gesucht sind Faktoren (δ1,...,δn), um die neuen Gewichte (δ1β1,...,δnβn) zu ermitteln

Page 27: Stochastische Attribut-Wert-Grammatiken

Anpassen der Gewichte

• Auch hier soll gelten:

j

xfjj

jxpZ

xq )(0neu )(

1)(

ii fpfq ~neu

• Für qneu gilt:

j

xfj

jxqZ

)(alt )(

1

Annäherung: j

xfi

jxqxq )(altneu )()(

)(#alt )( xf

ixq

Page 28: Stochastische Attribut-Wert-Grammatiken

Anpassen der Gewichte

• Annäherungsformel für die Faktoren δi:

iif

i fpfq ~#alt

• Iterieren, um die besten Gewichte zu erhalten

• Auch hier muss eventuell auf Sampling zurückgegriffen werden