Project 5: The CKY parsing algorithm

The goal of this project is to understand grammars and syntactic parsing by implementing the CKY algorithm. A secondary goal is to gain experience in dynamic programming. The CKY at its heart is not a complicated algorithm, but since it is an "iterate through the diagonals" dynamic programming algorithm, it does require careful thinking about indices in the table and has deep nesting structure of its loops.

This project description will be brief because your task is straightforward: finish the given implementation of a parser by providing bodies for the loops of the CYK algorithm. Moreover, we have looked at the algorithm carefully in class, and the details of this implementation are described in the code documentation.

Get the given code for this project from

/homes/tvandrun/Public/cs384/proj5

All of your work will be done in the file parser/cky_parser.py. It won't involve a large amount of code---I removed a mere 28 lines of code from my solution in preparing the given code. However, that code will be very dense; my solution include nested loops seven levels deep (the outer two of which are still in the given code).

The grammar for the language, which already is embedded into the given code, is found on the handout given in class Nov 13 (or thereabouts), or here:

proj5-grammar.pdf

When the program is complete, it should produce parsed sentences like these:

$ python parser/cky_parser.py "the cat chased the dog in the kitchen"

(Sentence (NounPhrase (ConcNP (CNPA (Det the) (Nominal (Noun cat))))) (VerbPhrase (VPA (VPB (Verb chased) (NounPhrase (ConcNP (CNPA (Det the) (Nominal (Noun dog)))))) (PrepPhrase (Prep in) (NounPhrase (ConcNP (CNPA (Det the) (Nominal (Noun kitchen)))))))))

$ python parser/cky_parser.py "she knew that he knew that she knew that he knew that she knew that he knew that she knew that he loved her"

(Sentence (NounPhrase (ConcNP (CNPA (Pronoun she)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun he)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun she)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun he)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun she)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun he)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun she)))) (VerbPhrase (VPA (VPB (Verb knew) (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun he)))) (VerbPhrase (VPA (VPB (Verb loved) (NounPhrase (ConcNP (CNPA (Pronoun her))))))))))))))))))))))))))))))))))))))))))))))))))

$ python parser/cky_parser.py "that he loved her troubled her"

(Sentence (NounPhrase (AbsNP (That that) (Sentence (NounPhrase (ConcNP (CNPA (Pronoun he)))) (VerbPhrase (VPA (VPB (Verb loved) (NounPhrase (ConcNP (CNPA (Pronoun her)))))))))) (VerbPhrase (VPA (VPB (Verb troubled) (NounPhrase (ConcNP (CNPA (Pronoun her))))))))

Turn in your code (I don't think any write-up would be necessary since there are no decisions to be made) by copying your cky_parser.py to

/cslab.all/ubuntu/cs384/(your login id)/proj5

DUE: Open. Absolute deadline is midnight between Friday, Dec 11 and Saturday, Dec 12 (ie, the last day of classes). I recommend you turn it in earlier than that, and I will (try to) grade these on a continual basis as they come in.


Thomas VanDrunen
Last modified: Thu Nov 19 15:28:13 CST 2015