1 / 28

LING/C SC/PSYC 438/538

LING/C SC/PSYC 438/538. Lecture 18 Sandiway Fong. Adminstrivia. Homework 5 o ut today d ue next Thursday by midnight (usual rules). Homework 5. On Finite State Automata and Perl … Three questions One extra credit question. Homework 5. Question 1 Part 1:

dezso
Download Presentation

LING/C SC/PSYC 438/538

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. LING/C SC/PSYC 438/538 Lecture 18 Sandiway Fong

  2. Adminstrivia • Homework 5 • out today • due next Thursday by midnight • (usual rules)

  3. Homework 5 • On Finite State Automata and Perl … • Three questions • One extra credit question

  4. Homework 5 • Question 1 • Part 1: give a deterministic FSA for the non-deterministic FSA shown on the right • (submit a diagram/picture) • Part 2: implement your machinein Perl. • give sample runs as well as your code • (ND)FSA: 1 1 > 0 1 2 1 1 0 3 1

  5. Homework 5 • Question 2 • Give a FSA machine that accepts strings of a’s and b’s (in any order) such that the total number of a’s in the string must be odd and the total number of b’s in string must be even. • (even numbers: 2,4,6… • odd numbers: 1,3,5…) e.g. • bbabbbbbaabaabab • *b *ab*aabb*aaa (* indicates a string not in the language)

  6. Homework 3 • Question 3 • Implement your machine for Question 2 in Perl • give sample runs as well as the code

  7. Homework 3 • Extra Credit Question 4 • Give a regular expression for the odd number of a’s and even number of b’s language from Question 2 • Implement your regular expression in Perl • Give example runs

  8. Today’s Topics • Continue with grammars in Prolog • definite clause grammar (DCG) facility • Concept: adding extra argument(s) to nonterminals allow us to: • 1. produce parse trees • 2. increase expressive power and implement constraints

  9. s b a a ! a a a Last Time We can systematically transform a grammar into one that produces a parse tree • Example grammar: • s --> [b], [a], a, [!]. • a --> [a].(base case) • a --> [a], a.(right recursive case) • base and recursive cases • a(a(a)) --> [a]. • a(a(a,A)) --> [a], a(A). s(b,a,a(a,a(a)),!) • start symbol case • s --> [b], [a], a, [!]. • s(tree) --> [b], a(subtree), [!]. • s(s(b,a,A,!)) --> [b], [a], a(A), [!].

  10. Natural Language Parsing • Syntax trees are a big deal in NLP • Stanford Parser • http://nlp.stanford.edu:8080/parser/index.jsp • Uses probabilistic rules learnt from a Treebank corpus We do a lot with Treebanksin the follow-on course to this one (LING 581, Spring)

  11. Natural Language Parsing • Penn Treebank (WSJ section): • parsed by human annotators • Efforts by the Hong Kong Futures Exchange to introduce a new interest-rate futures contract continue to hit snags despite the support the proposed instrument enjoys in the colony’s financial community.

  12. Natural Language Parsing • Penn Treebank (WSJ section): • parsed by human annotators • Efforts by the Hong Kong Futures Exchange to introduce a new interest-rate futures contract continue to hit snags despite the support the proposed instrument enjoys in the colony’s financial community.

  13. Natural Language Parsing

  14. Natural Language Parsing • Comparison between human parse and machine parse: • empty categories not recovered by parsing, otherwise a good match

  15. Natural Language Parsing

  16. Extra Arguments: Expressive Power • General Question: • can the extra argument change the system? • Answer: • Yes • Example: • We can write an otherwise regular-looking DCG for the non-regular language Lab = { anbn | n ≥ 1 } (which cannot be encoded by any regular grammar)

  17. s --> [a],b. b --> [a],b. b --> [b],c. b --> [b]. c --> [b],c. c --> [b].  Extra Arguments: Expressive Power s(X) --> [a],b(a(X)). b(X) --> [a],b(a(X)). b(a(X)) --> [b],c(X). b(a(0)) --> [b]. c(a(X)) --> [b],c(X). c(a(0)) --> [b]. Query:?- s(0,L,[]). a+b+ a regular grammar regular grammar + extra argument

  18. Extra Arguments: Expressive Power • Computation tree: • ?- s(0,[a,a,b,b],[]). • ?- b(a(0),[a,b,b],[]). • ?- b(a(a(0)),[b,b],[]). • ?- c(a(0),[b],[]). • Yes s(X) --> [a],b(a(X)). b(X) --> [a],b(a(X)). b(a(X)) --> [b],c(X). b(a(0)) --> [b]. c(a(X)) --> [b],c(X). c(a(0)) --> [b].

  19. Extra Arguments: Expressive Power • ?- s(0,[a,a,a,b,b,b],[]). • true • [trace] ?- s(0,[a,a,a,b,b,b],[]). • Call: (6) s(0, [a, a, a, b, b, b], []) ? • Call: (7) b(a(0), [a, a, b, b, b], []) ? • Call: (8) b(a(a(0)), [a, b, b, b], []) ? • Call: (9) b(a(a(a(0))), [b, b, b], []) ? • Call: (10) c(a(a(0)), [b, b], []) ? • Call: (11) c(a(0), [b], []) ? • Call: (12) c(0, [], []) ? • Fail: (12) c(0, [], []) ? • Redo: (11) c(a(0), [b], []) ? • Exit: (11) c(a(0), [b], []) ? • Exit: (10) c(a(a(0)), [b, b], []) ? • Exit: (9) b(a(a(a(0))), [b, b, b], []) ? • Exit: (8) b(a(a(0)), [a, b, b, b], []) ? • Exit: (7) b(a(0), [a, a, b, b, b], []) ? • Exit: (6) s(0, [a, a, a, b, b, b], []) ? • true • [trace] ?- s(0,[a,a,b],[]). • Call: (6) s(0, [a, a, b], []) ? • Call: (7) b(a(0), [a, b], []) ? • Call: (8) b(a(a(0)), [b], []) ? • Call: (9) c(a(0), [], []) ? • Fail: (9) c(a(0), [], []) ? • Redo: (8) b(a(a(0)), [b], []) ? • Fail: (8) b(a(a(0)), [b], []) ? • Redo: (7) b(a(0), [a, b], []) ? • Fail: (7) b(a(0), [a, b], []) ? • Fail: (6) s(0, [a, a, b], []) ? • false. • [trace] ?- s(0,[a,b,b],[]). • Call: (6) s(0, [a, b, b], []) ? • Call: (7) b(a(0), [b, b], []) ? • Call: (8) c(0, [b], []) ? • Fail: (8) c(0, [b], []) ? • Redo: (7) b(a(0), [b, b], []) ? • Fail: (7) b(a(0), [b, b], []) ? • Fail: (6) s(0, [a, b, b], []) ? • false.

  20. FSA Regular Expressions Regular Grammars Recall: Chomsky Hierarchy Type-1 = Context-sensitive Type-3 Type-2 = Context-free DCG = Type-0

  21. Context-free Definite Clause Grammars • Basically (in DCG format): • LHS --> RHS. • LHS = single non-terminal (context-free restriction) • RHS = a sequence of zero or more terminal or non-terminals (possibly mixed) • cf. the limited possibilities on the RHS for regular grammars • In DCGs • non-terminals may contain extra arguments e.g. np np(NP,Case,Number,Person) • these extra arguments can be to enforce constraints, e.g. agreement, or simply return desired values, e.g. fragment of a parse tree • mechanism can be used to implement grammars more general than type-2

  22. Examples • Type-3 (Regular) • a+b+ • Type-2 (Context-free) not in Type-3 • {anbn|n≥1} • Type-1 (Context-sensitive) not in Type-2 • {anbncn|n≥1}

  23. Grammar for {anbncn|n≥1} • Basic grammar for a+b+c+ • s --> a, b, c. • a --> [a]. • a --> [a], a. • b --> [b]. • b --> [b], b. • c --> [c]. • c --> [c], c.

  24. Grammar for {anbncn|n≥1} • a definite clause grammar for {anbncn|n≥1} Basic grammar generates a+b+c+ Extra argument imposes equal number restriction parse a(a(..a..)) nests as many a’s as seen in the input i.e. it counts the number of a’s parse is then passed to the b’s and c’s, counting off the same number of b’s and c’s as a’s

  25. Another Grammar for {anbncn|n≥1} • Explicit computation of number of a’s using arithmetic. • { … } embeds Prolog code inside grammar rules

  26. Another Grammar for {anbncn|n≥1} Parsing the a’s

  27. Another Grammar for {anbncn|n≥1} • Computing the b’s

  28. Another Grammar for {anbncn|n≥1} • Computing the c’s

More Related