5 episodes · follows chapter 19 of the textbook
Context-Free Grammars and Constituency Parsing
Constituency from first principles. Constituency and Context-Free Grammars: Grammars as Programs treats grammars as programs: formal languages as sets, CFGs as recursive generators and recognizers, and the Chomsky hierarchy as a hierarchy of machines (regex, recursive descent, general programs). Treebanks, Ambiguity, and Chomsky Normal Form: Why Parses Explode counts ambiguity exactly (Catalan numbers via the recurrence and Raney's lemma) and builds Chomsky normal form. The CKY Algorithm: Parsing as Interval Dynamic Programming derives CKY as interval dynamic programming with backpointers, counts and an animated chart. Statistical and Neural Span Parsing: Probabilities, Heads, and PARSEVAL adds probabilities (PCFG, Viterbi and inside CKY in log space), heads, parent annotation, span-based neural parsing and PARSEVAL. Combinatory Categorial Grammar: Parsing as Type Checking recasts grammar as a type system with CCG.
Objectives
Language
- Identify constituents with substitution, movement, coordination and fragment tests
- Explain attachment and coordination ambiguity and why treebanks changed parsing research
- Explain the PCFG independence assumption and the parent-annotation and head-lexicalization fixes
- Describe span-based neural constituency parsing and evaluate parsers with PARSEVAL
- Explain how CCG handles non-constituent coordination and relative-clause gaps
Math & data structures
- Define formal languages and CFGs; prove with pigeonhole that finite automata cannot recognize a^n b^n
- Derive the Catalan recurrence and closed form (Raney's lemma) and their 4^n growth
- Derive CKY's recurrence, valid fill orders and O(n^3 |G|) cost; use semirings (bool, count, Viterbi, inside)
- Estimate PCFGs by MLE and compute tree and sentence probabilities in log space
- Read CCG categories as directional function types; apply application, composition and type raising
Code
- nlpcore.structure.cfg: Grammar, Tree, random generation, top-down recognizer with left-recursion curtailment, heads
- nlpcore.structure.cnf: grammar-level CNF (TERM/BIN/DEL/UNIT) with undo, and tree-level binarization/Markovization
- nlpcore.structure.cky: CKY with backpointers, counts, event log, fill orders; span-score decoding
- nlpcore.structure.pcfg: MLE, probabilistic CKY, inside algorithm, toy treebank generator
- nlpcore.structure.ccg: categories, combinators with semantics, CKY over categories
- nlpcore.eval.parseval: labeled bracketing P/R/F1 (evalb conventions), crossing brackets, exact match
Episodes
- Constituency and Context-Free Grammars: Grammars as Programs18 min · 32 cues
Constituents, CFG definition, derivations, Chomsky hierarchy, grammars as programs.
Penn Treebank, attachment ambiguity, Catalan numbers (Concrete Math), CNF conversion.
- The CKY Algorithm: Parsing as Interval Dynamic Programming17 min · 37 cues
Bottom-up chart parsing DP, O(n³|G|), backpointers.
PCFGs, probabilistic CKY, neural span scoring, evaluation (PARSEVAL), heads.
- Combinatory Categorial Grammar: Parsing as Type Checking17 min · 31 cues
Categories as types, function application/composition (a type-checker for language).
Exercises
| Exercise | Tier | Ladder | Time |
|---|---|---|---|
| A grammar as a dict: random generation, recursive-descent recognition, and the finite-state wall | browser | Predict · Scratch | 60 min |
| Why ambiguity explodes (Catalan numbers three ways) and a language-preserving CNF converter | browser | Predict · Scratch | 75 min |
| CKY as interval DP: chart, backpointers, parse counts and an animation event log | browser | Scratch · Compose | 75 min |
| PCFG from a treebank, Viterbi CKY in log space, and PARSEVAL, hardened | browser | Scratch · Harden | 90 min |
| Break CKY three ways: wrong fill order, no unary closure, probabilities without logs | browser | Break it · Predict | 60 min |
| Probe a claim: does parent annotation help a treebank PCFG? (paired seeds, data-size sweep) | browser | Probe a claim · Predict | 60 min |
| Port a minimal span-based neural constituency parser to PyTorch (NumPy reference included) | gpu | Port · Scratch | 120 min |
| A tiny CCG parser as a type checker: categories, application, composition, type raising, semantics | browser | Scratch · Compose · Predict | 90 min |
Labs
- Constituency and Context-Free Grammars: Grammars as Programs browser C19.01 · 60 min
- Treebanks, Ambiguity, and Chomsky Normal Form: Why Parses Explode browser C19.02 · 60 min
- The CKY Algorithm: Parsing as Interval Dynamic Programming browser C19.03 · 60 min
- Statistical and Neural Span Parsing: Probabilities, Heads, and PARSEVAL browser C19.04 · 90 min
- Combinatory Categorial Grammar: Parsing as Type Checking browser C19.05 · 60 min
Library contributions
Files in nlpcore this module teaches you to write.
nlpcore/structure/cfg.pynlpcore/structure/cnf.pynlpcore/structure/cky.pynlpcore/structure/pcfg.pynlpcore/structure/ccg.pynlpcore/eval/parseval.py
Sources
- A. Ades & M. Steedman. On the order of words. Linguistics and Philosophy 4(4):517-558, 1982
- K. Ajdukiewicz. Die syntaktische Konnexität. Studia Philosophica 1:1-27, 1935
- J. K. Baker. Trainable grammars for speech recognition. In Speech Communication Papers for the 97th Meeting of the Acoustical Society of America, 1979 (inside-outside algorithm)unverified
- Y. Bar-Hillel. A quasi-arithmetical notation for syntactic description. Language 29:47-58, 1953
- Berkeley Neural Parser (benepar), github.com/nikitakit/self-attentive-parser; spaCy plugin · link
- Black et al. A Procedure for Quantitatively Comparing the Syntactic Coverage of English Grammars. DARPA Speech and Natural Language Workshop, 1991 (PARSEVAL) · link
- Backus-Naur form history: Backus 1959 (IAL/ALGOL 58), Naur and the ALGOL 60 report, Knuth 1964 CACM letter, Ingerman 1967 'Panini-Backus form' · link
- N. Chomsky. Three models for the description of language. IRE Transactions on Information Theory IT-2(3):113-124, 1956
- N. Chomsky. Syntactic Structures. Mouton, 1957 ('colorless green ideas sleep furiously')
- N. Chomsky. On certain formal properties of grammars. Information and Control 2(2):137-167, 1959 (Chomsky normal form)
- Church & Patil. Coping with Syntactic Ambiguity or How to Put the Block in the Box on the Table. American Journal of Computational Linguistics 8(3-4):139-149, 1982 · link
- John Cocke, credited with an early version of the CKY algorithm (often cited as Cocke & Schwartz 1970)
- M. Collins. Three Generative, Lexicalised Models for Statistical Parsing. ACL 1997 · arXiv:cmp-lg/9706022
- M. Collins. Head-Driven Statistical Models for Natural Language Parsing. PhD thesis, University of Pennsylvania, 1999
- Graham, Knuth & Patashnik, Concrete Mathematics, 2nd ed., sec. 7.5 (convolution recurrence for parenthesizations; Catalan numbers; Raney's lemma; Fuss; Catalan 1830s)
- J. Earley. An efficient context-free parsing algorithm. Communications of the ACM 13(2):94-102, 1970 (n^3 general, n^2 unambiguous, linear on a large class)
- J. Eisner. Efficient Normal-Form Parsing for Combinatory Categorial Grammar. ACL 1996 · arXiv:cmp-lg/9605038
- Geng, Josifoski, Peyrard, West. Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning. EMNLP 2023 · arXiv:2305.13971
- Hewitt & Manning. A Structural Probe for Finding Syntax in Word Representations. NAACL 2019 · link
- J. Hockenmaier & M. Steedman. CCGbank: A Corpus of CCG Derivations and Dependency Structures Extracted from the Penn Treebank. Computational Linguistics 33(3):355-396, 2007 · link
- M. Johnson. PCFG models of linguistic tree representations. Computational Linguistics 24(4):613-632, 1998 (parent annotation)
- F. Karlsson. Constraints on multiple center-embedding of clauses. Journal of Linguistics 43(2), 2007 · link
- T. Kasami. An efficient recognition and syntax-analysis algorithm for context-free languages. Technical report, 1965 (DTIC AD0631692) · link
- Kim, Dyer & Rush. Compound Probabilistic Context-Free Grammars for Grammar Induction. ACL 2019 · arXiv:1906.10225
- Kitaev & Klein. Constituency Parsing with a Self-Attentive Encoder. ACL 2018 · arXiv:1805.01052
- N. Kitaev, S. Cao, D. Klein. Multilingual Constituency Parsing with Self-Attention and Pre-Training. ACL 2019unverified
- Klein & Manning. Accurate Unlexicalized Parsing. ACL 2003 · link
- J. Lambek. The mathematics of sentence structure. American Mathematical Monthly 65:134-170, 1958
- L. Lee. Fast context-free grammar parsing requires fast Boolean matrix multiplication. arXiv Dec 2001; JACM 49(1):1-15, 2002 · arXiv:cs/0112018
- D. Magerman. Statistical decision-tree models for parsing. ACL 1995 (head percolation)
- Marcus, Santorini & Marcinkiewicz. Building a Large Annotated Corpus of English: The Penn Treebank. Computational Linguistics 19(2), 1993 (J93-2004) · link
- G. van Rossum, P. Galindo Salgado, L. Nikolaou. PEP 617 - New PEG parser for CPython (default in 3.9; old LL(1) parser removed in 3.10) · link
- S. Petrov, L. Barrett, R. Thibaux, D. Klein. Learning Accurate, Compact, and Interpretable Tree Annotation. COLING-ACL 2006unverified
- G. N. Raney. Functional composition patterns and power series reversion. Transactions of the AMS 94:441-451, 1960 (Raney's cycle lemma) · link
- A. Rush. Torch-Struct: Deep Structured Prediction Library. arXiv, Feb 2020 · arXiv:2002.00876
- S. Sekine & M. Collins. evalb (1997), the reference PARSEVAL scorer
- S. M. Shieber. Evidence against the context-freeness of natural language. Linguistics and Philosophy 8(3):333-343, 1985 (Swiss German cross-serial dependencies)
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft (Aug 19, 2026), Ch. 19 Context-Free Grammars and Constituency Parsing; Appendices E, F, G · link · §19.1, 19.2, 19.3, 19.4, 19.5, 19.6, 19.7, 19.8, 19.9, 19.10, E, F, G
- M. Steedman. The Syntactic Process. MIT Press, 2000
- Stern, Andreas & Klein. A Minimal Span-Based Neural Constituency Parser. ACL 2017 · arXiv:1705.03919
- L. G. Valiant. General context-free recognition in less than cubic time. Journal of Computer and System Sciences 10(2):308-315, 1975
- K. Vijay-Shanker & D. Weir. The equivalence of four extensions of context-free grammars. Mathematical Systems Theory 27(6):511-546, 1994
- D. H. Younger. Recognition and parsing of context-free languages in time n^3. Information and Control 10(2):189-208, 1967
- L. Zettlemoyer & M. Collins. Learning to Map Sentences to Logical Form: Structured Classification with Probabilistic Categorial Grammars. UAI 2005 · arXiv:1207.1420