150 likes | 261 Views
LING 388: Language and Computers. Sandiway Fong Lecture 18: 10/26. Administrivia. homework 5 due tonight. s. s. vp. np. np. vp. aux. v. det. n. det. n. vp. pp. ball. the. was. hit. ball. the. aux. v. p. np. simple tree: no movement or empty object. was. hit. by.
E N D
LING 388: Language and Computers Sandiway Fong Lecture 18: 10/26
Administrivia • homework 5 • due tonight
s s vp np np vp aux v det n det n vp pp ball the was hit ball the aux v p np simple tree: no movement or empty object was hit by me Last Time • case study • How to implement the passive construction • verb inflection • constraints between auxiliary and main verbs • subcategorization and adjuncts • Example • I hit the ball (active) • the ball was hit (by me) (passive) optional prepositional phrase (PP) is adjoined to the verb phrase (VP)
s(s(Y,Z)) --> np(Y), vp(Z). np(np(Y)) --> pronoun(Y). np(np(D,N)) --> det(D,Number), common_noun(N,Number). det(det(the),_) --> [the]. det(det(a),sg) --> [a]. common_noun(n(ball),sg) --> [ball]. common_noun(n(balls),pl) --> [balls]. common_noun(n(man),sg) --> [man]. common_noun(n(men),pl) --> [men]. pronoun(i) --> [i]. pronoun(we) --> [we]. pronoun(me) --> [me]. pp(pp(P,NP)) --> preposition(P), np(NP). preposition(p(by)) --> [by]. vp(vp(A,V)) --> aux(A), transitive(V,en). vp(vp(Y)) --> unergative(Y). vp(vp(Y,Z)) --> transitive(Y,_), np(Z). vp(vp(VP,PP)) --> vp(VP), pp(PP). unergative(v(ran)) --> [ran]. transitive(v(hit),_) --> [hit]. transitive(v(eat),root) --> [eat]. transitive(v(eats),s) --> [eats]. transitive(v(ate),ed) --> [ate]. transitive(v(eaten),en) --> [eaten]. aux(aux(was)) --> [was]. aux(aux(were)) --> [were]. Grammar so far
Load the grammar Run sentences: I hit the ball *I hit the ball was hit the ball was hit by me Questions How many answer(s)? Why? Exercise 1
Let’s solve the VP recursion problem Idea: the VP-PP grammar rule vp(vp(VP,PP)) --> vp(VP), pp(PP). should only be tried by Prolog if there is actually a PP that follows the VP Examples: in the ball [VP was hit [VP marks the point at which we’re considering applying the VP-PP rule there is no point in using the VP-PP rule since there is no prepositional phrase that follows in the ball [VP was hit by me the VP-PP rule can be applied if we can see the preposition “by” will follow the VP Exercise 2
Underlying Prolog as we’ve discussed in earlier lectures.. the VP-PP grammar rule vp(vp(VP,PP)) --> vp(VP), pp(PP). is translated into the underlying Prolog rule (variables names may be changed) vp(vp(A,B), L1, L2) :- vp(A, L1, L3), pp(B, L3, L1). L1 here is the part of the input sentence that starts the VP Idea: the VP-PP grammar rule vp(vp(VP,PP)) --> vp(VP), pp(PP). should only be tried by Prolog if there is actually a PP that follows the VP Implementation of the Idea: check to see if L1 contains a preposition! before the recursive call Exercise 2
Idea: the VP-PP grammar rule vp(vp(VP,PP)) --> vp(VP), pp(PP). should only be tried by Prolog if there is actually a PP that follows the VP Implementation Idea: check to see if L1 contains a preposition! before the recursive call Modify the underlying Prolog rule as follows: vp(vp(A,B), L1, L2) :- vp(A, L1, L3), pp(B, L3, L1). becomes vp(vp(A,B), L1, L2) :- member(by,L1), vp(A, L1, L3), pp(B, L3, L2). Note: recall goal ?- member(X,L). asks “is X a member of the list L” Exercise 2
Add the Prolog rule: vp(vp(A,B), L1, L2) :- member(by,L1), vp(A, L1, L3), pp(B, L3, L1). to your grammar Since we are handling the underlying Prolog rule directly, we need to comment out the original grammar rule as follows (so we don’t end up with two copies) %vp(vp(VP,PP)) --> vp(VP), pp(PP). Note: % is the comment character anything that follows % on the line is treated as a comment and ignored by the Prolog processor Re-run the sentences from Exercise 1: I hit the ball *I hit the ball was hit the ball was hit by me see the difference in behavior? Exercise 2
Adding the Prolog rule: vp(vp(A,B), L1, L2) :- member(by,L1), vp(A, L1, L3), pp(B, L3, L1). The membership check is known as doing “lookahead” i.e. we’re inspecting the rest of the input in L1, looking ahead to see if it’s relevant for triggering the PP part of the grammar rule the relevance check in this case is whether we can find the word “by” in L1 Exercise 2: Summary if the membership check fails, the entire rule fails and the rest of the rule: VP and PP are not tried
It’s not perfect though... Example: *the ball was hit by me still recurses indefinitely (ask for other answers) To do it right, we have to impose the restriction of one preposition per PP adjunct optional here! VP → VP PP VP → member VP PP Derivation (... expands to): VP VP PP VP PP PP (need two PPs) Exercise 2: Summary
Idea: have the membership 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: vp(vp(A,B), L1, L2) :- append(Left,[by|Right],L1), \+ Right = [mark|_], append(Left,[by,mark|Right],L1), vp(A, L1, 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 Exercise 2: Optional
s vp np aux v det n ball balls the was were hit Exercise 3 • examples • I hit the ball (active) • the ball was hit (passive) • the ball was hit by me (passive + by-phrase) • *the ball were hit by me • *the balls was hit by me • the balls were hit by me • Subject-Verb Agreement Rule • subject must agree with the verb for number • np(np(D,N)) --> det(D,Number), common_noun(N,Number). • common_noun(n(ball),sg) --> [ball]. • common_noun(n(balls),pl) --> [balls]. • np(np(D,N),Number) --> det(D,Number), common_noun(N,Number).
s Number vp np Number Number number aux v det n ball balls the was were hit Exercise 3 • examples • the ball was hit by me (passive + by-phrase) • *the ball were hit by me • *the balls was hit by me • the balls were hit by me • Subject-Verb Agreement Rule • subject must agree with the verb for number • must propagate number feature up the tree! • np(np(D,N),Number) --> det(D,Number),common_noun(N,Number). • common_noun(n(ball),sg) --> [ball]. • common_noun(n(balls),pl) --> [balls]. • s(s(Y,Z)) --> np(Y,Number), vp(Z). Number • s(s(Y,Z)) --> np(Y,Number), vp(Z,Number).
Implement the Subject-Verb Number agreement rule propagate the Number feature up the rule system Feature propagation is used a lot in many grammar formalisms: e.g. unification grammar/GPSG/HPSG Note: if you add an extra argument for a nonterminal rule you have to make sure all references to that nonterminal have theextra argument as well make sure your grammar works for the examples referenced previously Examples the ball was hit by me *the ball were hit by me *the balls was hit by me the balls were hit by me Exercise 3