1 / 51

Taaltheorie en Taalverwerking Remko Scha

Taaltheorie en Taalverwerking Remko Scha. Bachelor-opleiding Kunstmatige Intelligentie. Taaltheorie en Taalverwerking Week 2: Herschrijfgrammatica's De Chomsky-hiërarchie.

jera
Download Presentation

Taaltheorie en Taalverwerking Remko Scha

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Taaltheorie en TaalverwerkingRemko Scha Bachelor-opleiding Kunstmatige Intelligentie

  2. Taaltheorie en TaalverwerkingWeek 2:Herschrijfgrammatica'sDe Chomsky-hiërarchie

  3. Het formalistisch perspectief op taal: Mathematische methodes voor het definiëren van verzamelingen strings. Vorige week:Reguliere Expressies & Eindige Automaten

  4. Het formalistisch perspectief op taal: Mathematische methodes voor het definiëren van verzamelingen strings. Vorige week:Reguliere Expressies ≈ Eindige AutomatenDeze week:Herschrijfgrammatica's

  5. Herschrijfgrammatica's Jurafsky & Martin: Context-Free/Formal Grammars for English (Ed. 1: Ch. 9. Ed. 2: Ch. 12) Language and Complexity (Ed. 1: Ch. 12. Ed. 2: Ch. 16)

  6. S NP VP article the noun wumpus copula is adjective dead Engelse zin met woordsoorten en "oppervlakte-structuur"

  7. Herschrijfgrammatica die deze zin genereert S  NP VP NP  article nounVP  copula adjective article the noun wumpus copula is adjective dead S NP VP article the noun wumpus copula is adjective dead

  8. Herschrijfgrammatica die nog meer zinnen genereert S  NP VP NP  article nounNP John VP  copula adjectiveVP  verb verb walks article thearticle a noun  wumpusnoun  boy copula iscopula was adjective deadadjective happy S NP VP article the noun wumpus copula is adjective dead a boy was happy John walks

  9. Generatie-proces S

  10. Generatie-proces S S  NP VP

  11. S S  NP VP NP VP

  12. S S  NP VPNP  article noun NP VP

  13. S S  NP VP NP  article noun NP VP article noun

  14. S  NP VP NP  article noun article  the S NP VP article the noun

  15. S  NP VP NP  article noun article thenoun boy S NP VP article the noun boy

  16. S  NP VP NP  article noun article thenoun boyVP  verb S NP VP article the noun boy

  17. S  NP VP NP  article noun article thenoun boyVP  verb verb walks S NP VP article the noun boy verb walks

  18. S  NP VP NP  article noun article thenoun boyVP walks S NP VP article the noun boy verb walks Dit generatie-proces kan beschouwd worden als een seriestring-herschrijvingen beginnend met S.

  19. S  NP VP NP  article noun article thenoun boyVP walks herschrijf-proces: (1)S (2) NP VP(3) article noun VP(4) the noun VP (5) the boy VP(6) the boy walks

  20. Een verzameling herschrijfregels is een formele grammatica (een “herschrijfgrammatica”).De taal gedefinieerd door zo'n grammatica is de verzameling van woordsequenties die d.m.v. van een serie van opeenvolgende herschrijvingen afgeleid kunnen worden uit het startsymbool S.

  21. Herschrijfgrammatica: 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 { , .....}  (N )*,  (N )* [Notatie: A* = de verzameling van strings die uitsluitend bestaan uit elementen van A = de monoïde gegenereerd door A ]

  22. Herschrijfgrammatica's in soorten:de Chomsky-hiërarchie

  23. Herschrijfgrammatica's in soorten A N; x ; ,,  (N )* Type 0: Onbeperkte herschrijfgrammatica Herschrijfregels  met  ≠ .Type 1: Contextgevoelige Grammatica Herschrijfregels: A met  ≠  . Type 2: Contextvrije Grammatica Herschrijfregels: A . Type 3: Reguliere Grammatica Herschrijfregels: A  x B of A  x .

  24. Herschrijfgrammatica's in soorten A N; x ; ,,  (N )* Type 0: Onbeperkte herschrijfgrammatica Herschrijfregels  met  ≠ .Type 1: Contextgevoelige Grammatica Herschrijfregels: A met  ≠  .Type 2: Contextvrije Grammatica Herschrijfregels: A . Type 3: Reguliere Grammatica Herschrijfregels: A  x B of A  x .

  25. Herschrijfgrammatica's in soorten A N; x ; ,,  (N )* Type 0: Onbeperkte herschrijfgrammatica Herschrijfregels  met  ≠ .Type 1: Contextgevoelige Grammatica Herschrijfregels: A met  ≠  .Oftewel: Herschrijfregels  met || ≤ ||. Type 2: Contextvrije Grammatica Herschrijfregels: A . Type 3: Reguliere Grammatica Herschrijfregels: A  x B of A  x .

  26. Herschrijfgrammatica's in soorten A N; x ; ,,  (N )* Type 0: Onbeperkte herschrijfgrammatica Herschrijfregels  met  ≠ .Type 1: Contextgevoelige Grammatica Herschrijfregels: A met  ≠  . Oftewel: Herschrijfregels  met || ≤ || . Type 2: Contextvrije Grammatica Herschrijfregels: A . Type 3: Reguliere Grammatica Herschrijfregels: A  x B of A  x .

  27. Herschrijfgrammatica's in soorten A N; x ; ,,  (N )* Type 0: Onbeperkte herschrijfgrammatica Herschrijfregels  met  ≠ .Type 1: Contextgevoelige Grammatica Herschrijfregels: A met  ≠  .Oftewel: Herschrijfregels  met || ≤ || . Type 2: Contextvrije Grammatica Herschrijfregels: A . Type 3: Reguliere Grammatica Herschrijfregels: A  x B of A  x . (Rechts-lineair)Of:Herschrijfregels: A  Bx of A  x . (Links-lineair)

  28. De Chomsky-hiërarchie Type 0: Recursief Opsombare Talen ("Turing-Equivalent"). Type 1: Contextgevoelige Talen. Type 2: Contextvrije Talen. Type 3: Reguliere Talen.

  29. De Chomsky-hiërarchie Type 0: Recursief Opsombare Talen ("Turing-Equivalent"). Type 1: Contextgevoelige Talen. Type 2: Contextvrije Talen. Type 3: Reguliere Talen. Dit is een subsumptie-hiërarchie: Type 0 omvat Type 1 omvat Type 2 omvat Type 3.

  30. The Chomsky Hierarchy Type 0: Recursively enumerable(Turing-equivalent) Type 1: Context-Sensitive Type 2: Context-Free Type 3: Regular Grammar / FSA / Reg. Expr.

  31. FSA≈ Reguliere grammatica J & M: "Schapentaal": baa(a)*! Rechts-lineaire grammatica: S Q0Q0 bQ1Q1 aQ2Q2 aQ3 Q3 aQ3Q3 !

  32. Niet-Reguliere Talen • Sommige talen kunnen niet herkend/gegenereerd • worden door een eindige-toestands-automaat. • Voorbeeld: L = { anbn | n N } • = { , ab, aabb, aaabbb, ...} • Intuïtie: de FSA kan niet "onthouden" hoeveel a's   hij gegenereerd heeft.

  33. Niet-Reguliere Talen • Sommige talen kunnen niet herkend/gegenereerd • worden door een eindige-toestands-automaat. • Voorbeeld: L = { anbn | n N } • = { , ab, aabb, aaabbb, ...} • Intuïtie: de FSA kan niet "onthouden" hoeveel a's   hij gegenereerd heeft. • Formeel bewijs: m.b.v. de "pompstelling"

  34. qj q1 qk Het idee achter de Pompstelling Beschouw een accepterende FSA met k toestanden. Om een string ter lengte pk te accepteren, moet er een j zijn die meer dan 1 keer bezocht wordt(pad: q1,…,qj,…,qj,…, qk).

  35. qj q1 qk Het idee achter de Pompstelling Het pad van qj naar qj kun je net zo vaak doorlopen als je wilt.

  36. Pompstelling (Pumping Lemma)voor oneindige reguliere talen • Voor elke oneindige reguliere taal L is er ‘n integer N, • zodanig dat voor elke string w  L met lengte |w| ≥ N • geldt dat w = xyz, zodanig dat • y ≠  • |xy| ≤ N, en • x yn z  L voor elke n ≥ 0 Intuïtie: Gegeven een FSA met N+1 toestanden en een string w die langer is dan N; dan is er een niet-lege cyclus (“loop”) nodig voor het genereren van de eerste N elementen van w.

  37. Pompstelling (Pumping Lemma)voor oneindige reguliere talen • Voor elke oneindige reguliere taal L is er ‘n integer N, • zodanig dat voor elke string w  L met lengte |w| ≥ N • geldt dat w = xyz, zodanig dat • y ≠  • |xy| ≤ N, en • x yn z  L voor elke n ≥ 0 Pompstelling – Zwakkere VersieJurafsky & Martin Voor elke oneindige reguliere taal L is er ‘n string w  L, zodanig dat w = xyz, y ≠  en x yn z  L voor elke n ≥ 0

  38. Pompstelling voor oneindige reguliere talen De sterkere versie van de pompstelling is nuttig omdat je er meer mee kunt bewijzen. Maar voor sommige eenvoudige gevallen volstaat de zwakke versie die Jurafsky & Martin presenteren. B.v. de vraag: is de taal L = {anbn | n0} een reguliere taal?

  39. anbn Stel dat L = {anbn | n0} een reguliere taal is.

  40. anbn Stel dat L = {anbn | n0} een reguliere taal is. Dan is er een string apbp die geschreven kan worden als xyz (met y ≠ ), zodanig dat xyiz  L voor alle i0 .

  41. anbn Stel dat L = {anbn | n0} een reguliere taal is. Dan is er een string apbp die geschreven kan worden als xyz (met y ≠ ), zodanig dat xyiz  L voor alle i0 . Wat is y voor 'n string?Drie mogelijkheden: 1) y = ak, dus xyyz = ap+kbp L; klopt niet! 2) y = bk, dus xyyz = apbk+p L; klopt niet! 3) y bevat a's en b's, dus in xyyz komen a's na b's voor; klopt niet!

  42. anbn Stel dat L = {anbn | n0} een reguliere taal is. Dan is er een string apbp die geschreven kan worden als xyz (met y ≠ ), zodanig dat xyiz  L voor alle i0 . Wat is y voor 'n string?Drie mogelijkheden: 1) y = ak, dus xyyz = ap+kbp L; klopt niet! 2) y = bk, dus xyyz = apbk+p L; klopt niet! 3) y bevat a's en b's, dus in xyyz komen a's na b's voor; klopt niet! Contradictie.Dus: anbn is niet regulier

  43. anbn L = {anbn | n0} kan wel gegenereerd worden door eencontextvrije grammatica: S  a S bS 

  44. Opgaven van deze week: Reguliere talen en contextvrije talen. • Gegeven een contextvrij grammaticaatje, beschrijfwelke verzameling strings erdoor gegenereerd wordt. • Gegeven een karakterisering van een verzameling strings,bewijs dat het wel of niet een reguliere taal is.

  45. http://iaaa.nl/TTTV/

  46. Line of Reasoning • Proof by contradiction: • Assume that L is regular • Hence, there is a DFA M that recognizes L • For strings of length  |Q| the DFA M has to ‘repeat itself’ • Show that M will accept strings outside L • Conclude that the assumption was wrong Note that we use the simple DFA, not the more elaborate (but equivalent) NFA or GNFA

  47. Formal Proof of Pumping Lemma Let M = (Q,,,q1,F) with Q = {q1,…,qp} Let s = s1…snL(M) with |s| = n  p Computational path of M on s is thesequence r1,…,rn+1  Qn+1 withr1 = q1, rn+1F and rt+1= (rt,st) for 1tn Because n+1  p+1, there are two statessuch that rj = rk (with j<k and k  p+1) Let x = s1…sj–1, y = sj…sk–1, and z = sk…sn+1 x takes M from q1=r1 to rj, y takes M from rj to rj, and z takes M from rj to rn+1F As a result: xyiz takes M from q1 to rn+1F (i  0)

  48. Formal Proof of Pumping Lemma Let M = (Q,,,q1,F) with Q = {q1,…,qp} Let s = s1…snL(M) with |s| = n  p Computational path of M on s is thesequence r1,…,rn+1  Qn+1 withr1 = q1, rn+1F and rt+1= (rt,st) for 1tn Because n+1  p+1, there are two termssuch that rj = rk (with j<k and k  p+1) Let x = s1…sj–1, y = sj…sk–1, and z = sk…sn+1 x takes M from q1=r1 to rj, y takes M from rj to rj, and z takes M from rj to rn+1F As a result: xyiz takes M from q1 to rn+1F (i  0) |y|  1 and |xy|  p x yi z  L(M) for every i{0,1,2,…}

  49. F = { ww | w{0,1}* } (Ex. 1.40) Let p be the pumping length, and take s = 0p10p1 Let s = xyz = 0p10p1 with condition 3) |xy|p Only one option: y=0k, with xyyz = 0p+k10p1  F Without 3) this would have been a pain.

  50. Intersecting Regular Languages Let C = { w | # of 0s in w equals # of 1s in w} Problem: If xyzC with yC, then xyizC Idea: If C is regular and F is regular, then the intersection CF has to be regular as well Solution: Assume that C is regular Take the regular F = { 0n1m | n,mN}, then for the intersection: CF = { 0n1n | nN } But we know that CF is not regular Conclusion: C is not regular

More Related