Parsing — From Ambiguity to Parse Trees
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Ambiguity in natural language — covered in Lecture 1 (Why Language Is Hard: Ambiguity Everywhere)
- Precision, recall, and F1 — covered in Lecture 1 (Classification Metrics: Accuracy, Precision, Recall, F1)
- Part-of-speech tags and tagsets — covered in Lecture 6 (POS Tagging Fundamentals, Closed vs. Open Word Classes)
- Conditional probability and n-gram language models — covered in Lecture 4 (Conditional Probability, Independence, and the Chain Rule; The Markov Assumption)
9.1 Ambiguity in Natural Language
9.1.1 Why Language Is Hard: Multiple Interpretations
Hook: How many ways can one sentence mean? The same string of words can carry several different meanings, and this single fact is why parsing exists.
Every natural language — English, Indian languages, French, German, any language used for communication — carries the same open challenge: ambiguity. Ambiguity means the same sentence can be read in multiple interpretations, and this is the source of a lot of misunderstanding and miscommunication between people. The whole field of parsing exists to attack this problem, because in life-critical applications — airline systems and similar safety-sensitive settings — ambiguity has to be minimal. Every sentence has to carry a clear meaning.
A useful framing: no matter how advanced the technology stack gets, the core concepts of NLP remain the same. Ready-made coding agents can generate a complete application from a natural-language prompt, but you should understand what is going on inside — what the APIs do, and what purpose each step of the generated code serves. That fear — "is what I am teaching relevant in industry?" — is always there, especially because NLP grows at an exponential rate. Yet certain fundamental concepts stay useful no matter how advanced the stack becomes. Parsing is one of those: it is no longer done explicitly by modern systems, but it is done implicitly, and it is used by every NLP application. Evaluation is another one: unless the performance and accuracy of an NLP product are good, nobody will use it.
9.1.2 Worked Examples of Ambiguity
Worked example: the telescope sentence. Take the simple sentence "I saw the man with the telescope." This has two interpretations — in technical terms, two parses. The difference comes from the phrase "with the telescope" and where it attaches.
- Parse one: the man has the telescope, and I saw that man — "with the telescope" attaches to the man.
- Parse two: I used the telescope to see the man — "with the telescope" attaches to the seeing.
Both readings are grammatically flawless; that is exactly why this is called structural ambiguity — the grammar allows both, and only meaning decides. For this sentence the ambiguity is harmless, but the same phenomenon in a critical application has to be resolved.
Add a bit more information — "I saw the man on the hill with the telescope" — and the sentence has five parses, five interpretations, depending on which words attach to which. Enumerated, the interpretations include: (1) I am seeing with a telescope, and the man is on the hill; (2) the man is with the telescope and on the hill, and I am seeing that man; (3) I am on the hill, and the man is with the telescope; (4) I am seeing the man on the hill with the telescope (the telescope does the seeing); with a fifth interpretation implied on top of these. Ambiguity is explosive: each extra prepositional phrase multiplies the possibilities, and the count follows the Catalan numbers — two parses for the telescope sentence, five for the hill sentence, fourteen once "in Texas" is added, and for longer sentences the ambiguity can climb to 132 or more interpretations of the same sentence. Parsing is what tells you which words or phrases attach to which other words in the sentence.
Pitfall: treating ambiguity as a curiosity. Ambiguity is not just wordplay. A human uses common sense to pick the intended reading, but a computer has no common sense — it sees every grammatically allowed reading at once. In a flight-booking system, the same attachment decisions decide whether the passenger, the flight, or the time is being modified, and an unresolved attachment can change the answer a system gives. Jokes and puns are the same phenomenon in a lighter costume: "We are looking for a thief with a bicycle" is fine if "with a bicycle" attaches to the thief — it is the correct sense — but the phrase can also attach elsewhere and change the meaning entirely. "Why don't you do it with the eyes?" gets its humor exactly from the ambiguous attachment, and puns like "why is the teacher wearing sunglasses? Because…" work the same way. All of these ambiguities have to be dealt with, and parsing is one of the techniques that finds the relations among the different words in a sentence.
9.1.3 How Parsing Fits In
So parsing is the tool that answers: which words go together, and how do they relate? The upcoming sessions use that machinery to explain what modern transformers do internally. One of the session participants works as a QA professional evaluating LLM responses (using tools like Ragas and DeepEval) rather than creating them — a reminder that evaluation is becoming as important as generation as AI evolves.
Real-world: ambiguity resolution is required in airline and other life-critical applications; sentiment analysis, machine translation, speech recognition, and conversational AI all depend on the relations parsing uncovers. In the NLP applications course next semester, each of these systems is built on the assumption that the machine can first decide how the words of a sentence attach to one another.
Recap: ambiguity means one sentence, many interpretations, and the count grows fast with sentence length — 2, 5, 14, then 132 parses. Parsing is the technique that decides which words attach to which, and its concepts still run, implicitly, inside every modern NLP application.
9.2 Grammar and Context-Free Grammar
9.2.1 Grammar: The Structure of Every Language
Hook: Every language hides a rulebook. If you can write that rulebook down as symbols, a machine can follow it — and that rulebook is called a grammar.
Every language has a definite set of grammatical structure, a set of grammar rules. English follows subject-verb-object order: "I eat mango" is subject, verb, object. Indian languages typically follow subject-object-verb order: "me amba khati" / "mein am khata hun" — the verb comes at the end of the sentence. There are many more rules: past tense, present tense, how the verb form changes, and so on. This definite structure is what the language is built on — just like programming languages. If you want to write or communicate well, you need a proper grammatical structure.
Parsing helps in grammar checking: it analyses the structure of a sentence and makes sure it follows the grammar rules. Tools like Grammarly implicitly use parsing to check grammar, because writing correct English is critical in industry — a single misattached modifier can change the meaning of a contract clause or a product description.
What makes a grammar good? It has to be generic: a standard set of rules applied across all words, all domains, all applications. Over time, well-designed grammatical structures have been developed for multiple languages, and these can be tapped and used effectively in parsing. Knowing the grammar of a domain matters for the same reason domain expertise matters: whether the domain is finance or medical, you can only build a good system if you understand the domain — and to build good NLP applications you should know what the language consists of.
9.2.2 Phrases and Head Words
Every language consists of a certain group of words called phrases. English has the concept of noun phrase, verb phrase, and so on — each phrase is nothing but a group of words. Every phrase has a head word, its starting word: a noun phrase always starts with a noun, a verb phrase always starts with a verb.
- Prepositional phrase: "to the market" — starts with the preposition "to".
- Adverb phrase: "running fast" — starts with an adverb.
- Adjective phrase: "intelligent girl" — "intelligent" is an adjective.
Any sentence, in English or in Indian languages, follows a certain set of rules built from these phrases. A typical English sentence is a combination of noun phrase and verb phrase. In "NLP is very interesting": "NLP" is the noun phrase (it can even be the three compound nouns "natural language processing"), and "is very interesting" is the verb phrase, because it starts with a verb. A noun phrase can start with a noun, with an article, or with an adjective — "the beautiful girl", "beautiful girl", or just "girl" are all noun phrases built from combinations of articles, adjectives, and nouns.
Worked example: decomposing "NLP is very interesting" into phrases. Start from the sentence and split it left to right:
- Sentence: "NLP is very interesting"
- Noun phrase: "NLP" — a single noun.
- Verb phrase: "is very interesting" — starts with the verb "is".
- Inside the verb phrase, "very interesting" is an adjective phrase: "very" is an adverb strengthening the adjective "interesting".
So the sentence breaks as noun phrase + verb phrase, and both pieces are the phrase types you will see again when the grammar rules are written down.
9.2.3 Context-Free Grammar: Terminals, Non-Terminals, and Rules
Any grammar can be represented mathematically with symbols. A context-free grammar (CFG) is a concept borrowed from theory of computer science (TCS), where it was used for parsing programming languages; now the same concept applies to natural languages. The grammar is represented using two kinds of symbols:
- Nonterminals — symbols like your phrases (e.g., "with the telescope" is a nonterminal).
- Terminals — the actual words or the part-of-speech tags.
Formal definition of a CFG. A context-free grammar is a 4-tuple :
- — the set of nonterminals: abstract structural labels such as S, NP, VP.
- — the set of terminals: the actual words of the language, such as "dog", "saw", "the".
- — the set of rules (also called productions): instructions that rewrite one symbol into a sequence of symbols.
- — the start symbol: the designated root of the grammar, usually representing a full sentence.
Every rule has the form
where is a single nonterminal on the left, and is a string of terminals and nonterminals on the right, for example ("a sentence goes to a noun phrase followed by a verb phrase"). The name "context-free" comes from the fact that we are not looking at the previous word or the next word when we apply a rule — the rules apply without context.
Part-of-speech tags are also called lexicons — a technical word NLP uses for the words of the language. Every word has a part-of-speech tag associated with it, and when you combine these groups of words to form phrases, you get the grammar structure.
Scope: the head-word rule as taught here. In this lecture, a phrase's head word is described as its starting word, and for the examples used — noun phrases starting with a noun, verb phrases starting with a verb — the two descriptions agree. In the fuller linguistic definition, the head is the word that decides the phrase's type: "with the telescope" is a prepositional phrase because "with" is its head, wherever that word sits. For the exam problems, the starting-word view is the one to apply.
Recap: a grammar is a generic rulebook of the language; phrases are groups of words with a head word; a context-free grammar writes the rulebook as symbols — nonterminals, terminals, and rules — applied without looking at neighboring words. This grammar knowledge is not something to memorise — it is not an English grammar test — but you should understand the domain: what the language is made of, so you can develop better NLP applications.
9.3 Parse Trees and Applications of Parsing
9.3.1 What a Parse Tree Shows
The structure built by grammar rules is called a parse tree. Every sentence can be broken into sub-parts with relations among them: the noun phrase relates to the verb phrase, and both together constitute a sentence. A parse tree makes these relations explicit. Getting the parse tree is what parsing algorithms do — several of them are covered in the next sections.
Think of a parse tree as an upside-down family tree for the sentence. The root at the top is the sentence symbol S. Its children are the phrases: an NP on the left and a VP on the right. Each phrase, in turn, has children: the NP may branch into a noun, the VP into a verb and another NP. The leaves at the bottom are the actual words. The tree shows, at one glance, which words belong to the same phrase and how the phrases combine — the horizontal order of the leaves is the sentence itself, and every vertical path is a grammar rule.
For the sentence "NLP is very interesting", the tree looks like this:
S
/ \
NP VP
| / \
N V NP
| | / \
NLP is Adj Adj
| |
very interesting
Every relation between the words is a pair of points connected by a path: "very" modifies "interesting" because they are siblings under the adjective phrase; the adjective phrase belongs to the verb phrase; the verb phrase combines with the noun phrase to form the sentence.
9.3.2 Applications of Parsing
Parsing is required for all the interesting NLP applications, several of which are taken up in the NLP applications course next semester.
- Sentiment analysis — a very commonly used application across business domains: market trend analysis, which mobile phones and which phone features people like, movies, politics — everywhere. Adjectives and adjective phrases typically constitute the sentiment. But the relations decide the meaning.
- Relation extraction — important in conversational AI systems. When a user says "give me topics about a particular NLP area", there is a relation: the topic is within that NLP area, and the user wants information about that topic. These relations play a critical role in understanding what the user wants — and also in generating output in a proper grammatical structure.
- Question answering — finding relations like "who refers to what". In a phrase like "the first man in space", the relative pronoun refers to the man, not to space — a coreference decision. Both "man" and "space" are nouns, but only the man is a referent the pronoun can pick, and the structure says so. Such interpretation is what parsing provides.
- Speech recognition — converting speech to text also relies on the relations among words.
- Machine translation — an extremely important area of NLP. When translating from one language to another, you have to know the grammar of the source language and the grammar of the target language. Parsing plays an important role here. Many researchers and practitioners are involved in this area, including work on AI for Indian languages — the AI4Bharat initiative, which builds open language models and datasets for many Indian languages.
- Grammar checking — already discussed; parsing is very important there.
Worked example: "I like frozen" vs "I like frozen yogurt" — attachment decides sentiment. The same word "frozen" plays two different roles depending on what it attaches to.
- "I like frozen" — here "frozen" stands alone as the object. It could be a named entity, like the movie name Frozen. The sentiment is about the movie itself.
- "I like frozen yogurt" — here "frozen" is an adjective describing the food dish yogurt. The sentiment is about the yogurt, not about a movie.
The interpretations differ based on which words are attached and what their part-of-speech tags are. Sentiment analysis uses these relations implicitly; you will see later in the course that all this information about relations among words is captured implicitly by modern transformer models.
9.3.3 Parsing in the Transformer Era
All of the relations parsing extracts are now captured implicitly by the attention mechanism in transformers, and the upcoming sessions on contextual word embeddings will cover the internals of GPT and BERT. Still, the parsing concepts matter because they show how language is understood and generated. Modern systems do the same logic — probabilities, relations, part-of-speech information — but implicitly and as a black box: you get the output without knowing how the system arrived at it. Explicit parsing was more explainable; the implicit version is not, but the relations among words still have to be found, because you cannot interpret a language without them.
Recap: a parse tree is the explicit map of a sentence — which words form phrases and how the phrases combine — and every major NLP application (sentiment, question answering, translation, speech, grammar checking) depends on those relations. Modern transformers find the same relations implicitly through attention, at the cost of explainability.
9.4 Parsing Algorithms: Top-Down and Bottom-Up
9.4.1 Top-Down Parsing
Hook: How does a machine actually build the parse tree? The two classical recipes — top-down and bottom-up — are no longer used in production, but every modern parser still reasons in their direction.
How do we come up with the parse tree? The simple classical algorithms are top-down and bottom-up. These are no longer used in production, but they matter because they capture the relationships among words, and because today's dependency parsing and neural network parsing build on the same idea. The treatment here stays conceptual.
Top-down parsing starts with the top node — the root node is generally the sentence — applies the context-free grammar rules, and works down to the leaf nodes, which are the actual part-of-speech tags or words. All parsing algorithms follow a grammar structure; for learning, we use toy grammars rather than the complete exhaustive grammatical rules of English. The typical topmost rule is the sentence rule
About 90% of English sentences follow this noun-phrase-verb-phrase structure. There are exceptions, though: sentences that consist only of a verb phrase, like short conversational fragments. "Book the flight" is such an example — it has no noun phrase of its own at the top level, and it acts as a complete sentence. Starting from the root, the algorithm works left to right, applying the topmost rule first and continuing in serial order, using the part-of-speech tags of the words — the tags are available because pre-processing has already tagged every word. The result is the parse tree connecting the root to the leaves.
Intuition — the architect: top-down parsing is like an architect drawing the blueprint before the ground is touched. You start with the grand vision — "I need to build a sentence S" — and you know a sentence is an NP followed by a VP. You break that down into smaller and smaller pieces, making guesses, until the guesses finally match the actual words on the ground. The upside: the parser never explores an illegal sentence structure, because it only follows rules that exist. The downside: it can spend time expanding structures that never match the real words, and when a guess fails, it has to backtrack.
Worked example: top-down parse of "book the flight". The tags come from pre-processing: book = verb, the = article, flight = noun. The toy grammar has three rules: , , . Applying the rules top-down, left to right:
- Start at the root with the rule — the sentence is a verb phrase.
- Expand the VP with — a verb followed by a noun phrase.
- Match the first leaf: the verb position is filled by "book" (tag V). ✓
- Expand the NP with — an article followed by a noun.
- Match the next leaves: "the" (tag Art) ✓ and "flight" (tag N) ✓.
The tree is complete: , with (book + the flight) and (the + flight). Every leaf is covered by a part-of-speech tag, so the parse succeeds. The example is special only because the top rule is instead of the usual — imperative sentences like "book the flight" (an instruction: you, the listener, are to book it) are exactly the exception to the 90% rule.
Sense-check: the words on the leaves read "book the flight" from left to right, and the tree explains why the sentence works with no subject noun phrase at the top.
One terminology note: some tools, notably the Stanford parser, use the label "nominal" for nouns, and different APIs have slightly different conventions within nouns, adjectives, and so on. So you may find small variations between tools, but a nominal is almost the same as a noun.
9.4.2 Bottom-Up Parsing
Bottom-up parsing, as the name suggests, starts from the leaf nodes — the words — and builds the tree upward to the final parse tree. Where top-down started with the sentence, bottom-up starts with the words themselves. Both approaches ultimately produce the same parse tree, which is the relations among the words and phrases in the sentence.
Intuition — the builder: bottom-up parsing is like a builder working from the materials on the ground. Look at the words "the", "large", "can": see that "the" and "large" and "can" can be grouped into an NP; group "hold" and its object into a VP; finally combine the NP and the VP into the complete house, the sentence. The upside: the parser is data-driven — it only builds what is actually there. The downside: it can construct large sub-structures that never fit into the final sentence, wasting the same kind of work the top-down parser wastes on doomed guesses.
9.4.3 Status of These Algorithms Today
Top-down and bottom-up — and even chart parsing — are no longer used extensively in production. They are taught because they make the parsing concept concrete. Dependency parsing, covered in the next session, is definitely used in industry, and there are also neural network algorithms that come up with the relations among words.
Pitfall: blind guessing and backtracking. Both basic directions share one flaw: when a parser guesses the wrong rule, it throws away all its work and starts over. In a highly ambiguous sentence, the same phrases get re-evaluated hundreds of times, and the duplicate work grows quickly with sentence length — this is the explosion that chart parsing, the next topic, is built to stop.
Recap: top-down starts at the root and expands rules down to the words; bottom-up starts at the words and combines them into phrases up to the root; both produce the same tree, and both are taught today as the foundations of the parsers industry actually deploys.
9.5 Chart Parsing
9.5.1 The Idea: Cache the Partial Results
Hook: Why redo work you have already done? Chart parsing's whole trick is to remember — every partial result is stored once and reused everywhere.
Chart parsing exists in two flavours — bottom-up chart parsing and top-down chart parsing. The core idea of the chart is to store in memory whatever partial results the algorithm has computed so far, so they can be reused instead of recomputed.
Intuition — the cache picture: the chart behaves like the KV cache in transformers (the key, query, value machinery of the attention mechanism), and it is the same idea as dynamic programming — think of the Fibonacci series, where you temporarily store the in-between computations so the next step can reuse them. The chart is exactly that temporary store for whatever has been processed so far in the parsing steps. Whenever you hear "chart parsing", think cache memory: an NP proved to cover "the large can" is saved once, and no later step ever parses it from scratch again.
The working vocabulary of chart parsing:
- Chart — the place where the recorded, processed content is stored.
- Key — whatever you are currently processing.
- Active arc — the grammar rule you are applying for the set of words.
- Agenda — what you need to process further in your parsing.
Dot notation: marking progress inside a rule. A dot says "up till this point, the processing is done", and the symbols after the dot are still pending. For example means the article has been processed and the adjective and noun are still expected. Three states of the same rule:
- — nothing found yet; the rule is opened and waiting.
- — article found; waiting for adjective and noun.
- — everything found; the rule is complete and the finished constituent goes to the agenda.
9.5.2 Worked Example: "the large can hold the water"
Start with a simple English sentence and mark the positions of the words. The six words sit between seven positions: position 1 to 2 holds the first word, 2 to 3 the second, and so on up to 6 to 7 for "water" (some parsers start counting at 0 instead of 1 — the same idea). The relations to find are between the words that sit between these positions.
Given the part-of-speech tags for the input words — the tagging was done beforehand with the taggers learned earlier in the course. The sentence "the large can hold the water" has five unique words: the, large, can, hold, water. Their possible tags show exactly where ambiguity lives:
- "the" — article (unique).
- "large" — adjective (unique).
- "can" — three possible tags: noun (a milk can), verb ("I can go"), or auxiliary (a supporting verb associated with another word, as in "can hold").
- "hold" — noun or verb.
- "water" — noun or verb ("water the plants" vs "I want to drink water").
Closed-class words, as seen in part-of-speech tagging, typically have a single tag — which is why "the" and "large" are unambiguous here.
The grammar rules used:
Worked example: bottom-up chart parse of "the large can hold the water". Walk the sentence bottom-up, always looking at the words first and applying only the rules that can start with what is there.
Word 1, positions 1–2: "the" — tag is article. Of the three NP rules, two start with an article (rule 2, , and rule 3, ); the rule starting with an adjective is ignored because "the" is not an adjective. Both applicable rules are opened between positions 1 and 2, with the dot after the article: and .
Word 2, positions 2–3: "large" — tag is adjective. Between positions 2 and 3, only the rule that expects an adjective after the article survives: . The rule is discarded, because "large" is not a noun. The dot advances past the adjective, and the rule now expects a noun after position 3.
Word 3, positions 3–4: "can" — three possible tags. For the noun phrase, "can" is substituted as a noun, which finishes rule 3 and completes the NP: "the large can" (positions 1–4). But the parse is not done — the whole sentence still has to be covered. The sentence rule has processed its NP; the VP still has to be built from position 4 onward. Now "can" also has to serve the VP: looking at the VP rules, two can start from here — (starts with auxiliary) and (starts with verb). The noun reading cannot start a VP. Both remaining rules are opened from position 4, because "can" is ambiguous between auxiliary and verb.
Word 4, positions 4–5: "hold" — noun or verb. Both open rules need checking. The rule expects a noun phrase after the verb; but the NP rules all start with article or adjective, and "hold" is neither article nor adjective. So the NP continuation (the sixth rule) is discarded, and the parse proceeds with rule 5, , substituting "can" as an auxiliary. The dot shifts: . Now the inner VP has to be filled: the VP rules are (recursive) and . "Hold" is not an auxiliary, so the auxiliary continuation is discarded and is applied — hold is a verb, not a noun.
Words 5–6, positions 5–7: "the water" — the remaining NP. "the" is an article — and here the chart earns its keep: the article was already processed once, and that recorded result is reused from the chart instead of being recomputed. The two article-starting NP rules apply again; then "water" (noun or verb) is taken as a noun, because water is not an adjective, so only completes. The full sentence is now covered.
The finished tree, span by span: with the NP covering positions 1–4 and the VP covering 4–7; — the large can; — can + verb phrase; — hold + noun phrase; — the water.
Sense-check: every word sits inside exactly one completed span, every span is licensed by a rule, and the reading produced is "the large can (the container) can (auxiliary) hold the water" — the reading the tags support.
The frozen tag choices along the way: the = article, large = adjective, can = noun (in the NP) and simultaneously auxiliary (in the VP), hold = verb, the = article, water = noun. The walkthrough used 1-based positions; a 0-based parser would write the same spans shifted by one, and the tree itself does not change.
Exam note: in an exam you will not have to derive any of this from scratch — the sentence, the rules, and the part-of-speech tags will be given to you, and you only apply the rules to produce the parse tree. And the exam problems will not be more complex than this example; they might be much simpler.
9.5.3 Student Questions and Answers
Q: Can you re-explain how we discarded the sixth rule? A: Sure. Look at the word "hold": its part-of-speech tag is either a verb or a noun. To implement that rule you would have to go ahead with the NP, and all the rules of NP start with either article or adjective. Hold is neither an article nor an adjective. So that rule cannot continue, and we proceed with the fifth rule, , taking "can" as an auxiliary verb.
Q: For every sentence, do we have to identify which word is a noun and which is a verb ourselves? Is there a table we have to predict from? A: No — the part-of-speech tags are given to you, this information is given already. You don't have to determine it; you just have to apply the rules. That's it.
Q: I am a bit lost in between — can you once give a summary of this entire chart parsing idea? A: It is not such a difficult concept — it feels overwhelming only because you are doing it the first time. The summary: you have a set of rules and a set of lexicons (the part-of-speech tags). Using both, you try to come up with a parse tree, which means the relations among the words — here, "the large can" hangs together as one phrase and relates to the other phrase "can hold the water". The parse shows that "large" is an adjective for the word "can". English is funny: "can" can be a milk can (noun), "can I go" (auxiliary), or "I can hold the water" (verb), and the parse tells you which reading the sentence takes. Whenever you hear "chart parsing", think cache memory: it temporarily stores whatever you have processed so far, like the in-between computations in a dynamic programming algorithm such as Fibonacci. We computed the article once; when the next "the" appears, we just extract that from the chart and apply the rule along with its tag. That is the advantage of the chart. Then the procedure: look at the part-of-speech tags of the words one by one, start with the first word, and apply only those rules that are relevant for that tag — article means only the article-starting rules. Finish one span, move to the next position, and repeat: "large" is an adjective, so keep only the rule that expects an adjective after the article. Between positions 1 and 4 you have applied rule 2 (article, adjective, noun) and the NP is done; the sentence still needs its VP. At "can" there is ambiguity between auxiliary and verb, so both VP rules are opened. At "hold", the NP continuation dies because hold is not an article or an adjective, and the auxiliary-verb reading survives. That is how the tree gets built word by word.
Q: Will this set of rules be given in the exam? It will change with each problem statement, right? A: Correct. In general, these sets of rules are already defined in the libraries — this walkthrough only shows what happens behind the scenes, and you don't have to implement it from scratch. But you should know the reasoning: your strength as an AI/ML student is understanding what these processes do behind the scenes. Anyone who does an online course can call an API; understanding the core fundamental concepts is what lets you apply them in your own applications. From the exam point of view: don't worry, the rules and the part-of-speech tags will be given, and you just have to come up with the parse tree. The statement, the rules, and the part-of-speech tags — everything will be given.
Q: When we discussed part-of-speech tagging, we saw different libraries use different tags. Is it the same for these rules? A: Yes, there are libraries here as well. If you use a different library, the rules would change — the conventions shown here are the Penn Treebank style. These algorithms are like your training algorithms: everything from OpenAI and others is based on a training corpus, everybody uses a web corpus, and the result is training dependent. A nice part of understanding this is that you can supply your own domain data: the bio domain may have its own kind of lexical vocabulary as well as rules, and you can give those for parsing too.
Q: For the real-world web corpus — it is not feasible to map each and every sentence by hand, so how did they train it? Did they reverse-engineer it? A: At the web level, they don't use these statistical algorithms anymore; earlier they used to. Number crunching is not a big deal for machines — once you give them the algorithm, they can easily do all this processing. But today most of this is done via the attention mechanism, which finds the relations among words. Deep learning algorithms do it implicitly, but they are a black box: you don't know how the algorithm comes up with a particular result. Implicitly, what it is doing is finding all these relations via the attention mechanism. The contextual word embeddings sessions will cover the internals of GPT, BERT, and so on — there you will see that the attention mechanism is actually capturing the relations among the words, including parsing and part-of-speech tags. So implicitly it is doing parsing. Earlier this used to happen explicitly, which was more explainable; now it is not explainable, but the relations still have to be found. The logic is the same — they do apply the probabilities, everything remains the same, it is all implicitly done. You don't have to write anything from scratch these days, but you should understand it.
9.6 Probabilistic Context-Free Grammar (PCFG)
9.6.1 Why Probabilities?
Hook: A plain parser hands you every legal tree. When there are five — or 132 — which one did the speaker mean? Probability is how the machine chooses.
The problem with plain parsing: it produces individual parse trees, but you may not always get the best parse tree — there is a possibility of multiple parse trees based on the rules within your domain or application. How do you decide which is the best one? This is where probability enters — the same concept neural network algorithms use: softmax is nothing but a probabilistic function that tells you the best probability, the argmax value, and you select that. Here we use the same concept: compute probability values for the different parse trees and select the one with the maximum probability. That is the idea behind statistical or probabilistic parsing. Probabilistic parsing still uses the chart parsing algorithm — the difference is that along with the rules you also have probability values attached to each rule.
9.6.2 Learning Rule Probabilities from a Treebank
Where do the probabilities come from? From counting, in a corpus. Every algorithm — deep learning, advanced algorithms, machine learning, statistical — needs training data, and labeled data at that. Academic institutes develop gold standard data — labeled benchmark datasets used in research papers and industrial applications — from which the probability values are available ready-made; you don't have to compute them on the fly.
The classic example is the Penn Treebank: a bank of Wall Street Journal news sentences, roughly 50,000 sentences manually labeled with all the annotations (NP, VP, and so on). From it, the probabilities of rules and tags are counted:
For a word: in the training data the word "flies" occurs 44 times, and out of them 21 times as a noun — so . (Part-of-speech tagging itself is already done by the taggers; the same counting logic applies to the grammar rules.)
For rules: suppose you have 300 training sentences. If all 300 sentences follow the rule , its probability is . Another rule, appearing 300 times in the corpus with 116 of those times applicable, gets . The specific rule behind the 116 count is not named in the lecture — the point is the method, and the method is the same counting rule you use on exam problems:
where the numerator counts how often the expansion appears in the treebank, and the denominator counts how often the left-hand symbol is expanded in any way. This is the standard maximum-likelihood estimate from a labeled corpus — count, then normalize.
Even at phrasal level there can be choices: the phrase "a flower wilted" has three possible interconnections, three possible rules that could apply. Looking at the probability values, you filter out whichever has the argmax probability — that will be the correct parse for this phrase in your domain. Typically this is done at sentence level, but it works at phrasal level too. The probabilities come from the corpus of your domain or application, so whichever parse tree gets more probability in your domain is the more correct one for your domain — that is the intuition behind the probabilistic parse tree.
9.6.3 Mathematical Formulation
Don't get overwhelmed by symbols — as the story goes, a PhD guide once told a nervous student: it is all about symbols; once you know the symbols, you know the language, and these formulations are pretty simple.
- — the grammar.
- — the terminals, the set of words indicating all the words in the vocabulary .
- Non-terminals — the phrase symbols like NP, VP, etc.
- — together with the terminals, the set of rules: and so on. (Psi, , is the set of rules.)
Each rule has a probability. A standard probability rule applies: all the rules that have the same left-hand-side symbol must have probabilities summing to 1 — for example, all rules with on the left-hand side sum to 1:
There is also a probability of a sentence, needed shortly.
9.6.4 Probability of a Tree vs Probability of a Sentence
Probability of a tree: with the rule probabilities from the training corpus in hand, you apply the rules along the parse tree and multiply. The computation is pretty simple because of the independence assumption: this particular rule is independent of that one. Assuming independence makes the calculation very easy — you simply multiply all of the individual probabilities, the product of every rule used, to get the probability of the parse tree:
Probability of a sentence: the addition of all the probabilities of its parse trees:
where is the set of all parse trees for the sentence . A sentence that cannot be parsed contributes nothing, and every tree for contributes its own probability.
Why do we need the probability of a sentence? Suppose the sentence is gibberish — "astronomers saw stars with ears" doesn't make any sense at all. The sentence probability can guide you on whether the sentence is valid: keep a threshold (for example, if the probability is less than , treat the sentence as invalid) and ignore the output. Speech-to-text and text-to-speech systems use this concept of sentence probability. For parsing itself it is not so important — the probability of a parse tree is enough there.
9.6.5 Worked Example: Comparing Two Parse Trees
Given a sentence, the chart parsing algorithm produces a candidate parse tree; substitute the probability values of every rule used along that tree. To compute the probability of parse tree one, simply multiply all of the individual probabilities — the independence assumption lets you multiply them all. Do the same for the second parse tree. Now compare which is more.
Worked example: "astronomers saw stars with ears". This is the ambiguity of section 9.1 again, in probability form. The sentence has two natural parses, and they differ in where the prepositional phrase "with ears" attaches.
Tree one — "with ears" attaches to the noun phrase "stars" (the stars have ears). The tree uses the rules , , , , , , , , . With the rule probabilities from the training corpus:
Tree two — "with ears" attaches to the verb phrase (the astronomers used ears to see). The tree replaces the choice with a choice at the top of the verb phrase:
Comparing the two: , so the parser picks tree one — the reading where the stars have ears. The numbers are tiny because nine probabilities below 1 are multiplied together; in the real world you might get , , and so on — but you can still figure out which is larger.
Sense-check: the two trees share every rule except the attachment decision, and that decision swings the score by a factor of about 1.3 — exactly the kind of small difference that probabilities can rank.
From here, the tree with the higher value is the correct parse tree for this particular sentence. The best parse tree is simply the argmax over all trees:
With legal parses — recall the ambiguity example with 132 parses — the probabilistic approach easily finds the most relevant one. That is why neural networks use probability everywhere: there are so many possibilities, and you need to figure out the best. It is all data dependent. You can also optimise the search: filter out branches that have lower probability at the top level itself — if one rule has more probability, proceed with that rule instead of the other — some optimisation of the searchable space, but ultimately it is finding the probability of a parse tree.
9.6.6 Limitations of PCFG and Student Questions
Q: What is the advantage of probabilistic PCFG over chart parsing? Do we see any benefit? A: In chart parsing we did not have the probability values, so we could not disambiguate: we could get multiple parse trees and we would not be able to figure out which is better. With PCFG we can, using the probability values. So particularly for an ambiguous sentence with multiple parse trees, PCFG is useful. If it is a unique parse tree, then maybe PCFG will not play an important role.
Q: Going back to the previous models — in bigram, the probability of the sentence is defined as the probability of each and every word given the previous word has happened; it is a chain of conditional probabilities we calculate. In what way is this approach more context-free compared to a bigram approach? There, the words are the context; here the words are not relevant, the phrases are. Is that the only difference? A: Very good point. Here, in fact, it is context free: if you look at the probability, it is not a conditional probability like in the case of a bigram. In bigram you look at the context, and the context plays an important role. In fact, that is a problem with this blind PCFG approach — it makes the independence assumption. We are assuming none of the words are related: the probabilities are independent of each other, taken from the corpus itself, and you are just multiplying them. In fact, if you incorporate bigram and trigram here, this might be much better — and that is exactly what is used in the further dependency parsing and neural parsers. Here we are making a completely independence assumption.
Q: Where do we set these probabilities? Is it a part of any corpus? How do we get to know that these probabilities are associated with this rule? A: These are precomputed offline — offline from the labeled training corpus, precomputed for the different rules. Along with the rules, the training data also has these probability values. For the tree, you use these values to find the tree probability. You are not computing this during inference time or runtime; they are computed during the earlier training, offline.
PCFG's weakness: it is context-free. The relations in most communication languages need dependencies, and PCFG cannot capture them. The next session covers dependency parsing, which is more popularly used in industry — slightly complex, but once the parsing concept is understood, it comes easily. Dependency parsing captures the context and the structure; it solves all the problems PCFG has. Because of this lack of context, PCFG is not commonly used these days — dependency parsers or neural parsers are used instead.
Assumptions & scope of PCFGs. Two things have to be true for the product formula to be meaningful, and both are often false in real language:
- No lexicalization — the model treats all words equally through their tags. is scored the same whether the verb is "give" ("give him a book" works) or "sleep" ("sleep him a book" does not). The word-level choice never enters the rule probability.
- No structural context — rules are truly context-free. In real text, an NP in subject position is more likely to expand to a pronoun than an NP in object position; a PCFG cannot see the position, so it cannot exploit that clue.
Recap: PCFG attaches a probability to every grammar rule; the tree probability is the product of its rules under the independence assumption, the sentence probability is the sum over its trees, and the best parse is the argmax. The same counting, product, and argmax ideas drive the neural parsers used today.
9.7 CKY Parsing and Chomsky Normal Form
9.7.1 Chomsky Normal Form Conditions
CKY parsing (also written CYK) is an extension to the dynamic chart parsing algorithm — a bottom-up dynamic programming algorithm named after the initials of the PhD researchers who came up with it (Cocke, Kasami, and Younger). The only difference from chart parsing: the grammar rules have to be in Chomsky normal form (CNF). That is how research happens — new work builds on the problems and challenges of earlier work (the same way the MCP protocol and the recent wave of papers all build on earlier challenges): CKY is exactly the chart parsing algorithm with rules restricted to CNF.
Chomsky normal form. The CNF conditions on a rule :
- The left-hand-side symbol must be a single non-terminal (this condition holds for context-free grammar rules generally).
- The right-hand side must be either exactly one terminal (a word), or at most two non-terminals. You cannot have more than two non-terminals on the right-hand side.
So every rule is one of two shapes:
Not permissible in CNF: a single non-terminal on the right-hand side, a combination of a terminal and a non-terminal on the right-hand side, or more than two non-terminals.
9.7.2 Converting Rules to CNF
If some rules are not in CNF, they can be converted — pretty simply.
- Terminal mixed with non-terminal: a rule like has one terminal and one non-terminal, not permissible. Add an extra rule that says "the" is a determiner: . Then replace "the" with the new non-terminal in the original rule: . Now the rule is in CNF. (Nominal, by the way, is nothing but a noun or a noun phrase — the convention the Stanford parsers use.)
- Single non-terminal on the right-hand side (a unit production): a rule like is a unary rule, not allowed in CNF. Substitute the target's expansion directly — if , rewrite the rule as . If the target itself has several expansions, repeat the substitution for each of them.
- More than two non-terminals: combine them — a rule with three non-terminals becomes plus via a newly added rule, leaving only two non-terminals per right-hand side.
Worked example: converting each violation. Take three bad rules and fix them:
- (terminal + non-terminal) → add , rewrite as . ✓
- (single non-terminal) → if exists, rewrite as . ✓
- (three non-terminals) → introduce : and . ✓
Once all rules are in CNF, you are good to go with CKY parsing.
9.7.3 Why CNF?
Converting everything into CNF optimises the algorithm: all the rules in your parsing are of a standard format, which makes processing easier. Computationally, it becomes faster if all rules are in CNF — that is the reason for the conversion: to reduce the time complexity. A probabilistic CKY is then just chart parsing with a probability associated with every rule.
9.7.4 Worked Example: "the flight includes a meal"
This easier walkthrough of bottom-up chart parsing — the same algorithm, now with probability values — follows the textbook explanation in Jurafsky and Martin, and the arcs representation appears in the James Allen book (both openly available; the Jurafsky and Martin latest edition is available online as a PDF).
Sentence: "the flight includes a meal". Mark the positions — here starting from 0: 0, 1, 2, 3, 4, 5. The chart will fill only the upper triangle (a pyramid, as Jurafsky draws it): all the rules lie in the upper triangle portion and there is nothing in the lower one, because English forms words and sentences from left to right, so all combinations sit on the right-hand side.
The tags (determiner is the same as article — some APIs use determiner/DET, others use article/ART; both mean the same):
- "the" — determiner, probability from the training data.
- "flight" — noun, probability .
- "includes" — verb, probability from the training data.
- "a" — determiner, probability from the training data.
- "meal" — noun, probability from the training data.
The rules with their probabilities from the training corpus:
Worked example: probabilistic CKY chart for "the flight includes a meal". Fill the chart bottom-up (positions on the left, positions on the right):
- Position 0 to 1: "the" is a determiner. Only rules starting with a determiner apply — a single one, . Note the dot: determiner processed, noun pending.
- Position 1 to 2: "flight" is a noun, probability 0.02.
- Position 0 to 2: determiner (0–1) followed by noun (1–2) completes — probability 0.3. This NP cell gets 0.3.
- Position 2 to 3: "includes" is a verb.
- Position 2 to 3 crossed with the next span: is there a rule or plus anything? No rule with V and determiner on the right-hand side exists — so those cells stay dash. A single non-terminal cannot be a right-hand side in CNF, so single-tag combinations produce no rule.
- Position 3 to 4: "a" is a determiner. No rule with V-determiner, so dash again.
- Position 4 to 5: "meal" is a noun.
- Position 3 to 5: determiner (3–4) plus noun (4–5) completes again — probability 0.3.
- Position 2 to 5: verb (2–3) plus NP (3–5) completes — probability 0.8.
- Position 0 to 5: NP (0–2) plus VP (2–5) completes — the whole sentence.
Sense-check: every cell was filled by combining exactly two smaller spans, never three — that is the CNF restriction doing its job, and the pyramid's top-right corner (position 0 to 5) holds the sentence S.
Always remember: the rules must follow left to right, because English words go left to right — the rule is not the same as , and the order of the part-of-speech tags or non-terminals in a rule is very important.
Pitfall: rule order is not reversible. licenses "hold the water", but would license "the water hold" — a different, ungrammatical order. When you combine two cells in the chart, the left cell must satisfy the left symbol of the rule and the right cell the right symbol; in an NP the determiner must come first and the noun second. If you swap them, the rule is not applied and the cell stays a dash.
The sentence probability (the probability of this parse tree) is the multiplication of all of these individual probabilities — 0.8 for the VP rule, 0.3 for each of the two NP rules, 0.4 for the determiner value, 0.02 for "flight" as noun, and the remaining values from the training data:
The three remaining factors come from the same training corpus — the lecture's walkthrough did not display them, and the reference treatment gives , , and . The lecture's walkthrough assigns the VP rule probability 0.8; the reference grammar instead assigns and — either convention keeps the same tree, and the exam problem will state which probabilities to use.
The final parse tree: ; ; (for "the flight"); (for "a meal"); with leaves the, flight, includes, a, meal. In the exam, drawing this tree makes the answer easier to follow — the tree plus the multiplied probability is the complete answer.
9.7.5 Student Questions and Answers
Q: In the chart diagram, row number 3 and column number 5 — how did this value 0.3 for NP come? A: This comes from the rule , combining the noun in row 4 and the determiner in row 3 — exactly two non-terminals, so the triangle closes there. You have to see where the right-hand-side symbols sit: it has to start with the determiner first. You cannot apply it in reverse — determiner must come first, then noun, because English is left to right. Noun first is not permissible.
Q: Where did this value come from — the V and NP together forming this rule? A: The NP is actually a combination of the determiner and the noun, and you have the NP rule for it — that is why we combine the verb and that NP into a VP at this point. At every point we try combining: if there is a rule for combining, we use it; if there is no rule, we just write it as dash. A good strategy is to fill the diagonal part-of-speech tags first and start from the bottom — then just try combining two of them, because as per CNF the maximum you can combine is 2. You cannot do it for three.
Q: So the probability of the sentence is all these values multiplied, plus that point? A: Very correct — one, two, three, four, five, six values multiplied. This is the probability of a parse tree — the parse tree which is formed using these rules. Finally the parse tree will be this one: , where the VP is and both NPs are determiner and noun. The probability of this parse tree will be the multiplication of all of these values.
Recap: CKY is chart parsing with the grammar restricted to Chomsky normal form ( or ); any context-free rule can be converted to CNF; and the probabilistic CKY chart, filled bottom-up cell by cell, scores every tree so the best one can be read off the top-right corner.
9.8 Evaluating Parsers
9.8.1 Precision, Recall, and F1 with Positions
Hook: Anyone can build a parser that returns a tree. How do you know the tree is right? You compare it, rule by rule and position by position, against a human-made answer.
Evaluating parsers is required whether they are neural parsers or dependency parsers. Evaluation is a very important aspect of any NLP application — unless the performance is good, the accuracy is good, and the quality of the product is good, nobody is going to use it. Precision and recall are the simplest and easiest measures for evaluating parsers, and implementing them for parsers is not difficult.
One important thing to note: the positions of the words — the position order of the words — matters a lot when evaluating parsers. English is written from left to right, so the order of the words is critical for knowing the relations among the words, and for making sure the sentence is grammatically correct and fluent. So the positions play a very important role in evaluation.
You also need gold data: the actual labeled data with which you compare whatever your system has predicted or generated — a benchmark dataset. The comparison counts a rule as correct only when both the rule label and the positions (span) match.
Labeled precision and recall. A constituent such as an NP is identified by its label and its span, written — the label NP over positions 0 to 2. Evaluation compares the candidate's constituents against the gold standard's:
- Labeled precision (LP) — out of all the constituents the machine predicted, the share that are actually correct:
- Labeled recall (LR) — out of all the constituents in the gold standard, the share the machine found:
Precision punishes a parser for guessing too many spans; recall punishes it for missing spans that exist. Matching only the rule label is not enough — the span must match too.
9.8.2 Worked Example: "Sales executives were examining the figures with great care yesterday."
The gold data is the labeled tree from the treebank: the sentence "Sales executives were examining the figures with great care yesterday" with positions from 0 to 11, including the full stop. The gold annotation has a sentence rule spanning positions 0 to 11, a noun phrase between 0 and 2, and so on — 8 rules in total. The candidate parse — the tree an automatic parser generated for the same sentence — has 7 rules.
Worked example: precision, recall, and F1 for the sales executives sentence. Compare rule by rule, and count a rule correct only when both its label and its positions match the gold data.
- Candidate rules: 7.
- Gold rules: 8.
- Rules with the correct label and the correct positions: 3.
The key mismatch: although the candidate has the same VP rule coming after the NP, the positions are different — in the gold data the VP ends at position 9, while the candidate has folded "yesterday" into a different span (the candidate's VP runs from position 3 to 10 instead of 3 to 9). The rule labels agree; the spans disagree; so the VP is not counted as correct.
Precision — out of the total rules the candidate system generated (7), how many are correct, correct meaning not just the rules but also the positions? Three rules have correct positions, so:
Recall — out of the total rules the gold data has (8), how many did the candidate system generate correctly?
Recall is lower than precision: the candidate missed more of the gold spans than it invented wrong ones. F1 score is simple: you just compute the aggregate of both, balancing precision and recall:
so the F1 score is 40%. This is not very good, but this is how the F1 score is computed for the candidate parse.
Sense-check: the F1 of 0.40 sits between precision (0.429) and recall (0.375), pulled toward the lower value — the harmonic mean is never above the smaller of the two, which is exactly what "balancing" means.
These are called labeled precision (LP) and labeled recall (LR), because the data you are comparing with is labeled. The positions matter because they show whether you are precisely able to capture the correct relations among the phrases — just matching the rule labels is not enough.
Pitfall: why both measures are needed. A parser that wildly guesses 100 phrases for a short sentence might accidentally cover all 6 true gold constituents — its recall would be 100%, but its precision would be a terrible 6%. The F1 measure forces the parser to be both accurate and comprehensive, because it combines the two into one number.
One related measure: tagging accuracy — the part-of-speech tagging accuracy, which is correct for all the words. That is not required for parsers; those are the evaluation measures for part-of-speech taggers.
9.8.3 Scope and Practice
This same evaluation applies to dependency parsing, statistical parsing, and neural parsers — all of them are evaluated in the same manner, with attention to the positions of the rules. For a simple measure, you just take precision and recall, aggregate and balance them — the F1 score — and this is the measure used the majority of the time. There was also a second example sentence to try, left as homework to validate in the next session. The upcoming sessions start with the implementation walkthrough (code snippets exist in the extra reading) and then move to dependency parsers — a complex topic, and problems may be expected from it, so it is worth attending.
Recap: a parser is judged by labeled precision, labeled recall, and their F1 aggregate — a rule counts only when its label and its positions both match the gold tree. The same yardstick measures dependency parsers and neural parsers today.
Exam Guidance Summary
- The exam is open book. The purpose of an open book exam is that formulas and such don't need to be memorised — there will be no direct theory questions. In an open book exam, you apply whatever you have learned to the problems given.
- Expect application-oriented or mathematical problems, not theory questions. You will not be asked to write out the chart parsing algorithm itself — you should understand that it keeps processed content in memory, but writing the algorithm will not be tested.
- For parsing problems: the statement (sentence), the grammar rules, and the part-of-speech tags will all be given. You just apply the rules and produce the parse tree. Drawing the tree in the exam makes the answer easier to grade and follow. The exam problem will likely be simpler than the lecture examples.
- Problems may be expected on the upcoming dependency parsers topic — it is a little complex, so attend that session.
- Sample problems will be shared wherever mathematical problems are expected, and the regular and makeup paper solutions will be shared so you can learn the type of questions.
- For evaluation problems: precision, recall, and F1 (the aggregate/balanced measure) is the majority measure used — know how to compute , , and the 40% F1 style computation, including word positions.
- The grammar symbols do not need to be memorised, and this is not an English grammar test — but understanding the domain structure of the language helps you build better NLP systems.
- A high-level overview of the session content and a recap at the end will be given each session, so you always know where the current topic fits in the overall picture.
- Printed (watermarked) slides will be shared about two weeks before the exam for revision; the content is the same as the session slides.
- Mid-sem feedback from the batch: the exam was time-consuming (five-sentence problems versus the two-to-three word problems of previous papers), but balanced — more conceptual and implementation-focused than theoretical. That feedback will be passed on for the end-sem paper.
Key Industry Applications
- Grammar checking: tools like Grammarly implicitly use parsing to check the grammar of sentences — critical for writing correct English.
- Sentiment analysis: used across business domains — market trend analysis, which mobile phones and features people like, movies, politics. Adjective and adjective-phrase relations drive the sentiment, and attachment decides meaning ("I like frozen" — the movie — vs "I like frozen yogurt").
- Relation extraction in conversational AI: relations like "a topic is within an NLP area" are critical to understand user intent and to generate grammatically structured responses.
- Question answering and coreference: resolving which word a pronoun refers to ("the first man in space" — the pronoun refers to the man, not space).
- Speech recognition and speech-to-text, plus text-to-speech: relations among words matter for transcription, and the probability-of-a-sentence concept (e.g., a threshold like ) detects invalid sentences in speech outputs.
- Machine translation: requires the grammar of both the source and the target language; a large community works on Indian-language machine translation, notably the AI4Bharat initiative.
- Modern transformers (GPT, BERT): the attention mechanism implicitly captures the relations among words — including parsing and part-of-speech information — as a black box. The KV cache used in attention is the same caching idea as the chart in chart parsing. Softmax/argmax is the same probability-selection concept used to pick the best parse tree.
- Penn Treebank: the Wall Street Journal corpus with roughly 50,000 manually labeled sentences — the gold standard benchmark from which rule probabilities and parser evaluations are derived; used across research papers and industrial applications.
- Ready-made parser APIs: Stanford parser and other libraries implement chart parsing and CKY so you do not write the rules from scratch; different libraries use slightly different conventions (e.g., "nominal" for nouns, determiner vs article).
- PCFG in production: no longer commonly used because it is context-free; industry has moved to dependency parsers and neural parsers.
- LLM evaluation: QA professionals now evaluate LLM responses with tools like Ragas and DeepEval rather than only creating models — evaluation is becoming as important as generation.
- Course roadmap connections: retrieval augmented generation (RAG), the Ragas evaluation tool, and agentic AI are covered in the later sessions and in the NLP applications and conversational AI courses — all built on the fundamental parsing concepts.
- A practitioner project shared in the session: a risk-story prediction tool at a global bank combining CNN, computer vision, OCR, and NLP — a concrete example of NLP fundamentals being applied in industry.
- NLTK: students often first meet NLP through NLTK and Google blog tutorials; formal course study connects those pieces.
- CKY parsing itself is an example of research lineage: a dynamic chart parsing extension named after the initials of its three inventors, in the same spirit as newer protocols like the MCP protocol building on earlier work.
NLP Lecture 9 notes · Parsing — From Ambiguity to Parse Trees
Sections Breakdown
One sentence, many parses: structural ambiguity, the telescope and on-the-hill examples, and why parsing exists.
Grammatical structure, phrases and head words, and the formal 4-tuple definition of a context-free grammar.
What a parse tree shows, the NLP applications that depend on parsing, and parsing in the transformer era.
Top-down and bottom-up parsing with worked examples and their status in modern production.
Caching partial results, dot notation, the worked chart parse of 'the large can hold the water', and student Q&A.
Rule probabilities from a treebank, tree vs sentence probability, the argmax choice, and limitations.
CNF conditions, converting rules to CNF, and the probabilistic CKY chart for 'the flight includes a meal'.
Labeled precision, recall, and F1 with positions, with the sales executives worked example.
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
Ambiguity in Natural Language
Must-know: Ambiguity means one sentence can have many parses; counts grow fast (2, 5, 14, 132) and parsing resolves which words attach to which.
⚠️ Top pitfall: Treating ambiguity as a curiosity — in critical applications (airlines) an unresolved attachment changes the meaning of a sentence.
Self-check: How many parses does 'I saw the man with the telescope' have?
Connects to: 9.2, 9.6
Grammar and Context-Free Grammar
Must-know: A CFG is (N, Sigma, R, S); every rule is A -> beta with a single nonterminal left-hand side, and rules apply without looking at neighboring words.
⚠️ Top pitfall: The head word is described as the phrase's starting word in this lecture; the fuller definition says the head decides the phrase type.
Self-check: In 'NLP is very interesting', which phrase is the noun phrase and why?
Connects to: 9.1, 9.3
Parse Trees and Applications of Parsing
Must-know: A parse tree shows which words form phrases and how phrases combine; sentiment, QA (coreference), translation, speech, and grammar checking all rely on these relations.
⚠️ Top pitfall: Matching rule labels is not enough — attachment (e.g., 'frozen' as movie vs adjective) decides meaning.
Self-check: In 'the first man in space', what does the pronoun refer to?
Connects to: 9.2, 9.4
Parsing Algorithms: Top-Down and Bottom-Up
Must-know: Top-down starts at the root and expands rules to the leaves; bottom-up starts at the words and combines them upward; about 90% of English sentences are S -> NP VP.
⚠️ Top pitfall: Blind guessing and backtracking re-evaluate the same phrases repeatedly and slow the parser down quickly on ambiguous sentences.
Self-check: Why does 'book the flight' need S -> VP instead of S -> NP VP?
Connects to: 9.2, 9.5
Chart Parsing
Must-know: The chart stores processed spans so they are reused; apply only the rules that match each word's part-of-speech tag, left to right, and the parse tree falls out.
⚠️ Top pitfall: Discarding a rule too early or too late: an NP rule dies when the next word is neither article nor adjective; a rule must match tag order exactly.
Self-check: Why is the VP -> V NP rule discarded when the next word after the verb is 'hold'?
Connects to: 9.4, 9.6
Probabilistic Context-Free Grammar (PCFG)
Must-know: P(T) is the product of rule probabilities (independence assumption); P(S) is the sum over its parse trees; the best parse is the argmax over trees.
⚠️ Top pitfall: Confusing PCFG with bigram models: PCFG multiplies independent rule probabilities with no context; bigram uses conditional probabilities with context.
Self-check: If tree one scores 0.0009 and tree two scores 0.00068, which parse wins and why?
Connects to: 9.5, 9.7
CKY Parsing and Chomsky Normal Form
Must-know: CNF rules are A -> B C (two nonterminals) or A -> a (one terminal); CKY fills the upper triangle of the chart, combining two spans at a time, and the tree probability is the product of rule probabilities.
⚠️ Top pitfall: Rule order is not reversible: VP -> V NP is not VP -> NP V; the determiner must come first in an NP because English is left to right.
Self-check: How does the NP value 0.3 in the chart cell over 'a meal' arise?
Connects to: 9.5, 9.6
Evaluating Parsers
Must-know: Precision = 3/7 = 42.9%, recall = 3/8 = 37.5%, F1 = 2PR/(P+R) = 0.40; positions matter as much as rule labels.
⚠️ Top pitfall: Counting a rule as correct on label alone — the span must match the gold data too.
Self-check: Why is recall (37.5%) lower than precision (42.9%) in the sales executives example?
Connects to: 9.6, 9.7
Exam Guidance Summary
Must-know: The exam is open book with application problems; the sentence, rules, and part-of-speech tags are given for parsing problems; know the 3/7, 3/8, 40% F1 style computation.
⚠️ Top pitfall: Assuming theory questions or algorithm writing will be asked — the chart parsing algorithm itself will not be tested.
Self-check: What is given in a parsing exam problem?
Connects to: 9.5, 9.6, 9.7, 9.8
Key Industry Applications
Must-know: Attention in GPT/BERT implicitly captures the same relations parsing makes explicit; the KV cache is the same caching idea as the chart.
⚠️ Top pitfall: Believing parsing is obsolete — it is no longer explicit, but the relations still have to be found.
Self-check: What tool does Grammarly implicitly use to check grammar?
Connects to: 9.1, 9.3, 9.5, 9.6
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.