880 likes | 992 Views
CS460/626 : Natural Language Processing/Speech, NLP and the Web Lecture 19, 24: Algorithmics of Probabilistic Parsing; HMM-PCFG correspondence. Pushpak Bhattacharyya CSE Dept., IIT Bombay 1 st and 11 th Oct, 2012. Shared Sub-Problems: Example. CKY Parsing: CNF.
E N D
CS460/626 : Natural Language Processing/Speech, NLP and the WebLecture 19, 24:Algorithmics of Probabilistic Parsing; HMM-PCFG correspondence Pushpak BhattacharyyaCSE Dept., IIT Bombay 1st and 11th Oct, 2012
CKY Parsing: CNF • CKY parsing requires that the grammar consist of ε-free, binary rules = Chomsky Normal Form • All rules of the form: • A BC or Aa • What does the tree look like? • What if my CFG isn’t in CNF? A → B C D → w
Illustrating CYK [Cocke, Younger, Kashmi] Algo • DT the 1.0 • NN gunman 0.5 • NN building 0.5 • VBD sprayed 1.0 • NNS bullets 1.0 • S NP VP 1.0 • NP DT NN 0.5 • NP NNS 0.3 • NP NP PP 0.2 • PP P NP 1.0 • VP VP PP 0.6 • VP VBD NP 0.4
CYK: Start with (0,1) 0The1 gunman 2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Keep filling diagonals 0The 1gunman2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Try getting higher level structures 0The1gunman2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Diagonal continues 0The 1 gunman 2sprayed3 the 4 building 5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3the4 building 5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4building5 with 6 bullets 7.
CYK: starts filling the 5th column 0The 1 gunman 2 sprayed 3the4building5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2sprayed3the4building5 with 6 bullets 7.
CYK (cont…) 0The 1gunman2sprayed3the4building5 with 6 bullets 7.
CYK: S found, but NO termination! 0The1gunman2sprayed3the4building5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5with6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Control moves to last column 0The 1 gunman 2 sprayed 3 the 4 building 5 with 6bullets7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5with6bullets7.
CYK (cont…) 0The 1 gunman 2 sprayed 3the4building5with6bullets7.
CYK (cont…) 0The 1 gunman 2sprayed3the4building5with6bullets7.
CYK: filling the last column 0The 1 gunman 2sprayed3the4building5with6bullets7.
CYK: terminates with S in (0,7) 0The1gunman2sprayed3the4building5with6bullets7.
CYK: Start with (0,1) 0The1 gunman 2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Keep filling diagonals 0The 1gunman2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Try getting higher level structures 0The1gunman2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Diagonal continues 0The 1 gunman 2sprayed3 the 4 building 5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3the4 building 5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4building5 with 6 bullets 7.
CYK: starts filling the 5th column 0The 1 gunman 2 sprayed 3the4building5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2sprayed3the4building5 with 6 bullets 7.
CYK (cont…) 0The 1gunman2sprayed3the4building5 with 6 bullets 7.
CYK: S found, but NO termination! 0The1gunman2sprayed3the4building5 with 6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5with6 bullets 7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5 with 6 bullets 7.
CYK: Control moves to last column 0The 1 gunman 2 sprayed 3 the 4 building 5 with 6bullets7.
CYK (cont…) 0The 1 gunman 2 sprayed 3 the 4 building 5with6bullets7.
CYK (cont…) 0The 1 gunman 2 sprayed 3the4building5with6bullets7.
CYK (cont…) 0The 1 gunman 2sprayed3the4building5with6bullets7.
CYK: filling the last column 0The 1 gunman 2sprayed3the4building5with6bullets7.
CYK: terminates with S in (0,7) 0The1gunman2sprayed3the4building5with6bullets7.
CYK: Extracting the Parse Tree • The parse tree is obtained by keeping back pointers. S (0-7) NP (0-2) VP (2-7) DT (0-1) NN (1-2) NP (3-7) VBD (2-3) NP (3-5) PP (5-7) gunman The DT (3-4) NN (4-5) P (5-6) NP (6-7) sprayed NNS (6-7) with the building bullets
Probabilistic Context Free Grammars • DT the 1.0 • NN gunman 0.5 • NN building 0.5 • VBD sprayed 1.0 • NNS bullets 1.0 • S NP VP 1.0 • NP DT NN 0.5 • NP NNS 0.3 • NP NP PP 0.2 • PP P NP 1.0 • VP VP PP 0.6 • VP VBD NP 0.4
Another Parse t2 S1.0 • The gunman sprayed the building with bullets. P (t2) = 1.0 * 0.5 * 1.0 * 0.5 * 0.4 * 1.0 * 0.2 * 0.5 * 1.0 * 0.5 * 1.0 * 1.0 * 0.3 * 1.0 = 0.0015 NP0.5 VP0.4 NN0.5 DT1.0 VBD1.0 NP0.2 The gunman sprayed NP0.5 PP1.0 DT1.0 NN0.5 P1.0 NP0.3 NNS1.0 the building with bullets
Example Parse t1` S1.0 P (t1) = 1.0 * 0.5 * 1.0 * 0.5 * 0.6 * 0.4 * 1.0 * 0.5 * 1.0 * 0.5 * 1.0 * 1.0 * 0.3 * 1.0 = 0.00225 • The gunman sprayed the building with bullets. NP0.5 VP0.6 NN0.5 DT1.0 PP1.0 VP0.4 P1.0 NP0.3 NP0.5 VBD1.0 The gunman DT1.0 NN0.5 with NNS1.0 sprayed the building bullets
Interesting Probabilities N1 What is the probability of having a NP at this position such that it will derive “the building” ? - Inside Probabilities NP The gunman sprayed the building with bullets 1 2 3 4 5 6 7 Outside Probabilities What is the probability of starting from N1 and deriving “The gunman sprayed”, a NP and “with bullets” ? -
Interesting Probabilities • Random variables to be considered • The non-terminal being expanded. E.g., NP • The word-span covered by the non-terminal. E.g., (4,5) refers to words “the building” • While calculating probabilities, consider: • The rule to be used for expansion : E.g., NP DT NN • The probabilities associated with the RHS non-terminals : E.g., DT subtree’s inside/outside probabilities & NN subtree’s inside/outside probabilities