1 / 26

LING 388: Language and Computers

LING 388: Language and Computers. Sandiway Fong Lecture 19: 10/31. Administrivia. Homework 4 graded and returned by email Computer Lab Class this Thursday usual place: Social Sciences 224 Homework 6. Today’s Topics. Homework 4 Review More on grammar writing. s. ize. ize. a-z.

Download Presentation

LING 388: Language and Computers

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 388: Language and Computers Sandiway Fong Lecture 19: 10/31

  2. Administrivia • Homework 4 • graded and returned by email • Computer Lab Class • this Thursday • usual place: Social Sciences 224 • Homework 6

  3. Today’s Topics • Homework 4 Review • More on grammar writing...

  4. s ize ize a-z Homework 4: Question 1 • Given Prolog code: ends_ize(Word) :- atom_chars(Word,List), s(List). s([_|L]) :- s(L). s([i,z,e|L]) :- ize(L). ize([]). s([_|L]) :- s(L). s([i,z,e]). s i i z a-z iz e ize

  5. Homework 4: Question 1 • Part 1: (8pts) • Modify your machine so that it accepts • formalize • modernize • summarize • concretize • sterilize • but rejects • *summaryize • *concreteize • *sterileize s([_|L]) :- s(L). s([X,i,z,e]) :- \+ vowel(X). vowel(e). vowel(y).

  6. Homework 4: Question 2 • (10pts) • Part 1: (8pts) • Transform the NDFSA shown on the right into a deterministic FSA • Give the Prolog implementation of the machine • Part 2: (2pts) • what does this machine do? • i.e. what is the language it accepts? > q4

  7. NDFSA Set-of-states construction a a a a b a b b b b Homework 4: Question 2 {q1 ,q2 ,q4 } {q1 ,q2 ,q4 } {q1 ,q2 } q4 { q1 } {q1 ,q3 ,q4 } {q1 ,q3 ,q4 } {q1 ,q3 } deterministic FSA

  8. Part 2: (2pts) what does this machine do? i.e. what is the language it accepts? anything with “aa” or “bb” in it a a a b b b Homework 4: Question 2 seen two “a”s seen one “a” { q1 } seen two “b”s seen one “b”

  9. Part 2: (2pts) what does this machine do? i.e. what is the language it accepts? anything with “aa” or “bb” in it a a a b a,b b b Homework 4: Question 2 seen two “a”s or two “b”s seen two “a”s or two “b”s seen one “a” { q1 } seen one “b”

  10. Last time VP → VP PP Problem left recursion (infinite loop) Idea: control/restrict how many times we can loop around... Lookahead: spot a preposition (by) in the input list Add a mark indicating how many prepositions we’ve seen Controlling Left Recursion

  11. Idea: have the lookahead check “mark” the preposition so 2nd time around the recursion, preposition is already marked and the recursion fails Implementation: modify the input list the ball was hit by me the ball was hit by mark me where mark is an artificial word introduced into the input list delete the extraneous mark when we parse the preposition Modified Prolog rule: L1 is the input list to VP vp(vp(A,B), L1, L2) :- append(Left,[by|Right],L1), \+ Right = [mark|_], append(Left,[by,mark|Right],L1p), vp(A, L1p, L3), pp(B, L3, L1). this succeeds if it finds by in L1 and mark is not already next to by and replaces it with by mark Modified preposition grammar rule: preposition(p(by)) --> [by,mark]. extra mark introduced into the input must be removed Controlling Left Recursion

  12. So far, we’ve been using Prolog DCG rules to implement natural language constraints such as: determiner-noun agreement the/*a men subject-verb number agreement the men were/*was also constructions such as: passives and progressives be V+en, be V+ing optional by-phrase So Far...

  13. Today’s Topic • with these properties in mind, • want to take a step back, • and look at the properties of certain constrained grammar rules called regular grammars

  14. Regular Grammars • regular grammars are a class of formal grammars with a special restriction • akaChomsky hierarchy type-3 grammars • production rules are constrained to have normal forms L or R • L: x --> y, [t].x --> [t]. (left recursive) or • R: x --> [t], y.x --> [t]. (right recursive) • where x and y represent non-terminals and • t represents a terminal. • note: • can’t have both left and right recursive rules at the same time • can’t have ternary branching, e.g. x --> y, [t], z. • can’t have a single nonterminal only, e.g. x --> y.

  15. FSA Regular Expressions Equivalence NDFSA FSA with -transitions Regular Grammars

  16. t x t x y x t A B A A a A b A a a b a Regular Grammars ➡ FSA • each regular grammar rule has a FSA analog (and vice versa) • example: right recursive form FSA • x --> [t]. • x --> [t], y. • x --> [t], x. • note: • we can transform a left recursive regular grammar into a weakly-equivalent right recursive regular grammar, and vice-versa

  17. a s x y b a > ! z FSA ➡ Regular Grammars • from lecture 8 • Prolog FSA implementation • regular expression: ba+! • query • ?- s([b,a,a,’!’]). • code • s([b|L]) :- x(L). • x([a|L]) :- y(L). • y([a|L]) :- y(L). • y([‘!’|L]) :- z(L). • z([]).

  18. a s x y b a > ! z FSA ➡ Regular Grammars • equivalent (right-recursive) regular grammar • s --> [b], x. • x --> [a], y. • y --> [!]. • y --> [a], y. • by construction • query • ?- s(L,[]). • is it really equivalent to the FSA? • s([b|L]) :- x(L). • x([a|L]) :- y(L). • y([a|L]) :- y(L). • y([‘!’|L]) :- z(L). • z([]). • query • ?- s(L).

  19. s b x y a a y ! Parse Tree • regular grammar • s --> [b], x. • x --> [a], y. • y --> [!]. • y --> [a], y. • parse tree version • add an extra argument • s(s(b,X)) --> [b], x(X). • x(x(a,Y)) --> [a], y(Y). • y(y(!)) --> [!]. • y(y(a,Y)) --> [a], y(Y). • query • ?- s(P,[b,a,a,!],[]). • X = s(b,x(a,y(a,y(!)))) ? ; • no

  20. s s b x x ! y a y a a y y a ! b Right and Left Recursive Regular Grammars • right recursive regular grammar • s(s(b,X)) --> [b], x(X). • x(x(a,Y)) --> [a], y(Y). • y(y(!)) --> [!]. • y(y(a,Y)) --> [a], y(Y). • left recursive regular grammar • s(s(X,!)) --> x(X),[!]. • x(x(Y,a)) --> y(Y),[a]. • y(y(b)) --> [b]. • y(y(Y,a)) --> y(Y),[a]. • same query • ?- s(P,[b,a,a,!],[]). • X = s(x(y(y(b),a),a),!) ? ; • [what happens?] are they equivalent?

  21. right recursive regular grammar s(s(b,X)) --> [b], x(X). x(x(a,Y)) --> [a], y(Y). y(y(!)) --> [!]. y(y(a,Y)) --> [a], y(Y). left recursive regular grammar s(s(X,!)) --> x(X),[!]. x(x(Y,a)) --> y(Y),[a]. y(y(b)) --> [b]. y(y(Y,a)) --> y(Y),[a]. same query ?- s(P,[b,a,a,!],[]). X = s(x(y(y(b),a),a),!) ? ; [what happens?] they are not equivalent wrt Prolog execution after hitting semicolon ; right recursive grammar terminates left recursive grammar goes into an infinite loop explanation recursive rule is the 4th rule shown in both grammar right recursive rule must match terminal a before recursing Right and Left Recursive Regular Grammars

  22. Determiner-Noun Agreement • idea • give determiners a number feature as well • and make it agree with the noun • rules • thecan combine with singular or plural nouns • a can combine only with singular nouns • from lecture 12 • data • the man/men • a man/*a men • grammar (NP section) • np(np(Y)) --> pronoun(Y). • np(np(D,N)) --> det(D,Number), common_noun(N,Number). • det(det(the),sg) --> [the]. • det(det(the),pl) --> [the]. • det(det(a),sg) --> [a]. • common_noun(n(ball),sg) --> [ball]. • common_noun(n(man),sg) --> [man]. • common_noun(n(men),pl) --> [men]. • pronoun(i) --> [i]. • pronoun(we) --> [we].

  23. questions is the determiner-noun system a regular grammar? can we write a regular grammar for it? determiner-noun grammar np(np(Y)) --> pronoun(Y). np(np(D,N)) --> det(D,Number), common_noun(N,Number). det(det(the),sg) --> [the]. det(det(the),pl) --> [the]. det(det(a),sg) --> [a]. common_noun(n(ball),sg) --> [ball]. common_noun(n(man),sg) --> [man]. common_noun(n(men),pl) --> [men]. pronoun(i) --> [i]. pronoun(we) --> [we]. Determiner-Noun Agreement

  24. question 1 is the determiner-noun system a regular grammar? No for example: rules highlighted in red aren’t in regular grammar form determiner-noun grammar np(np(Y)) --> pronoun(Y). np(np(D,N)) --> det(D,Number), common_noun(N,Number). det(det(the),sg) --> [the]. det(det(the),pl) --> [the]. det(det(a),sg) --> [a]. common_noun(n(ball),sg) --> [ball]. common_noun(n(man),sg) --> [man]. common_noun(n(men),pl) --> [men]. pronoun(i) --> [i]. pronoun(we) --> [we]. Determiner-Noun Agreement

  25. question 2 can we write a regular grammar for it? Yes regular grammar shown on right determiner-noun regular grammar np(np(i)) --> [i]. np(np(we)) --> [we]. np(np(the,N)) --> [the], common_nounsg(N). np(np(the,N)) --> [the], common_nounpl(N). np(np(a,N)) --> [a], common_nounsg(N). common_nounsg(n(ball)) --> [ball]. common_nounsg(n(man)) --> [man]. common_nounpl(n(men)) --> [men]. Determiner-Noun Agreement

  26. by extension this determiner-noun system also has a FSA encoding determiner-noun regular grammar np(np(i)) --> [i]. np(np(we)) --> [we]. np(np(the,N)) --> [the], common_nounsg(N). np(np(the,N)) --> [the], common_nounpl(N). np(np(a,N)) --> [a], common_nounsg(N). common_nounsg(n(ball)) --> [ball]. common_nounsg(n(man)) --> [man]. common_nounpl(n(men)) --> [men]. the np > a common_nounpl the common_nounsg i men we ball man Determiner-Noun Agreement note: machine is a NDFSA. can be transformed into a deterministic machine

More Related