The CKY algorithm is a dynamic programming approach for constituency parsing that requires context-free grammars to be in Chomsky Normal Form (CNF), which restricts production rules to either two non-terminals or one terminal; the algorithm uses a matrix where each cell stores non-terminals spanning input positions i-j, filled bottom-up from the diagonal, to efficiently determine whether a sentence can be parsed according to a specified grammar and optionally return all possible parse trees.
CKY Algorithm Explained: Parsing with Chomsky Normal Form
Added:this video covers the cky algorithm i'll provide an overview and then discuss how to convert context-free grammars to chomsky normal form which is a requirement in the cky algorithm after that i'll move towards a deeper discussion of the algorithm itself followed by a case example the cky algorithm is one of the earliest algorithms for constituency parsing it's a data-driven bottom-up approach and it's a dynamic programming algorithm the standard version of cky which is the version we'll be covering in this course expects cfgs to be provided in a format called chomsky normal form chomsky normal form restricts production rules so that they can only produce either two non-terminals or one terminal node fortunately any cfg that isn't already in chomsky normal form can easily be converted to that format without any changes to the set of strings that the grammar accepts when we convert from a non-cnf grammar to chomsky normal form there are three situations we need to address first we need to handle cases where the production rule mixes terminals and non-terminals on the right-hand side because chomsky normal form doesn't allow it there must either be exactly two non-terminals or exactly one terminal node second we need to address cases where the production rule has a single non-terminal on the right hand side because again chomsky normal form doesn't allow it non-terminals need to be in pairs and third we need to address cases where the production rule has more than two non-terminals on the right hand side because as we've seen there need to be exactly two non-terminals so to address situation number one we can just introduce a numbing terminal variable that would have its own production rule in which it would accept a single terminal node matching the one occurring in the original rule to address situation number two we can replace the non-terminals with the production rules to which they eventually lead in many cases this would lead directly to a single terminal node or in some cases it might lead to a new production rule that could then be handled accordingly and to address situation number three we can introduce new non-terminals that allow us to split production rules into multiple rules and this means that if we had an original context-free grammar like the one you see on the left here you can convert its first reproduction rules to something like what you see on the right once we have our grammar in chomsky normal form we can be assured that every non-terminal node in our parse tree until we get to the point where we're assigning part of speech tags will have exactly two children this means that we can encode our tree using a two-dimensional matrix with that matrix we'll really only be concerned with half of it the upper triangular part each cell in the matrix will contain the set of non-terminals that represent constituents spanning positions i through j of the input with the final parts residing in the top right corner when filling cells we'll consider that for each constituent belonging to a given cell at position i j there must be some point at which it can be split into two parts the first part we need to lie to the left of the cell somewhere along the same row and the second part would need to lie beneath the cell somewhere in the same column to fill the table we just start from the metaphorical bottom so the cells along the diagonal and move our way up so we're filling a cell based on the parts that have already been filled before it i'll illustrate this more concretely with an example because it can be difficult to visualize some theoretical terms so let's say we have a sentence book the flight through chicago we have our context free grammar and then we have our lexicon as well we'll start off with our matrix completely empty and only the upper triangular half is shown here since that's the part we're interested in the first thing we need to do is convert our grammar to chomsky normal form so we go ahead and do that and now we can go ahead and begin filling in our table we start with the first row in first column which just represents the single word span book it looks like we can match that in our lexicon as a noun or a verb and next we'll move forward so remember we're working from the bottom up so we're moving onwards along the diagonal so our next cell will represent the single word span the we'll check our lexicon and find a match as a determiner we'll move onwards to the next cell representing the single word span flight and find a match is a noun we'll find a match as a preposition for the word through and finally for the single word spanish chicago we'll find a match as a proper noun so we filled in our entire diagonal now so we have one or more part of speech labels for each word it might be the case though that there are entire constituents that span only one word so now that we have these part of speech labels we'll quickly check back through and see if that's the case it turns out it actually is for the first word book we find that a noun is also automatically a nominal due to our c and f conversion we also find that a verb is automatically a verb phrase which is automatically a full sentence as well this means that flight is also a nominal and finally it looks like proper nouns are also automatically noun phrases so now we've also found all the single word constituents and we can finally move to two word constituents to figure out whether book the is a constituent we need to determine whether there are any production rules that would match noun verb sentence nominal or verb phrase followed by determiner it doesn't look like there are so book that must not be a valid constituent and then we'll check the flight so we're looking for a determiner followed by a noun or nominal we do find a match here a noun phrase now we're looking at flight through so we want a noun or a nominal followed by a preposition but it doesn't look like we find a match and finally we'll check through chicago so we want a preposition followed by a proper noun or noun phrase and we do find a match there a prepositional phrase next we'll move on to three word constituents we'll start with book the flight so we could look for either a noun verb sentence nominal or verb phrase followed by a noun phrase or the impossible case of nothing followed by a noun or nominal we find that a sentence matches the verb phrase and a verb phrase matches the combination of verb followed by noun phrase we'll move onward to the flight through so we're looking for either a determiner followed by nothing or a noun phrase followed by a preposition unfortunately it doesn't look like there are any matches for either of those we'll move on to flight through chicago so we're looking for a noun or a nominal followed by a prepositional phrase or nothing followed by a proper noun or a noun phrase and we find that a nominal is a match so we'll move onward to forward constituents now we'll start off by looking for a noun verb sentence nominal or verb phrase followed by nothing so an impossible case or nothing followed by nothing another impossible case or a sentence or verb phrase followed by a preposition we don't find any matches so book the flight through isn't a valid constituent we'll try the flight through chicago next so we'll look for a determiner followed by a nominal or a noun phrase followed by a prepositional phrase or an impossible case of nothing followed by a proper noun or noun phrase we find that a noun phrase is a match so at long last we've finally made it for the full constituent book the flight through chicago we're looking for a noun verb sentence nominal or verb phrase followed by a noun phrase or the impossible case of nothing followed by a nominal or a sentence or verb phrase followed by a prepositional phrase or the impossible case of nothing followed by a proper noun or noun phrase we find two matches a sentence or a verb phrase and technically since we already know that a verb phrase can directly map to a sentence that means we reach the sentence node in two different ways so that means we could return two different grammatically correct parses for the sentence so we made it all the way through our cky case example in the example we just worked with we were focusing on recognizing whether the sentence fit into the specified grammar so all we really wanted at the end was to know whether s was in the top right cell if we instead wanted to return all the possible parses we would make two little changes first we'd add back pointers just like we've seen in other dynamic programming algorithms so we could see from where each non-terminal was derived then we'd also permit multiple versions of the same non-terminal to be entered into the table for cases when it was reached in multiple different ways once we made those changes we could just choose one of our potentially multiple s's from the top price cell and recursively retrieve its component constituents from the table in the case of the example we were working with that would look like this cky does have a fairly high time and space complexity however overall it's a nice simple dynamic programming approach to find constituency parses according to a specified grammar
Up Next

Earley Parsing Algorithm in Natural Language Processing
@NatalieParde_NLP
15.1K views•2020-12-27

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science






























![[ФЯиТ] Формальные языки и трансляции 9. Алгоритм Эрли](https://i.ytimg.com/vi/X3JQS1k0c2U/maxresdefault.jpg)

![Scott Vokes on An Efficient Context-Free Parsing Algorithm [PWL SF] 5/2018](https://i.ytimg.com/vi_webp/kVxGe_uGM8g/maxresdefault.webp)




