Grammars and Constituency Structure › Ambiguity

Michael BrenndoerferMay 4, 20256 min read
Language AI HandbookAll chapters
Part 7 of 67Linguistic Form: Morphology and Syntax
Chapter 46Grammars and Constituency Structure › Ambiguity
Reading section 5 of 11 · Ambiguity · 6 minSection 5 of 11 · 6 min

Section 5 of 11 · 6 min read

Grammars and Constituency Structure › AmbiguitySection view · Sections in this chapter5 / 11 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

Ambiguity is a central practical problem in parsing. A grammar can assign more than one parse tree to the same token sequence. When that happens, the grammar is ambiguous for that sentence. Ambiguity is a property of the mapping between strings and structures. A grammar designed to preserve distinct structural readings can license alternative trees. Preserving those analyses is stronger than simply covering the same set of strings: two grammars can generate the same language while assigning different trees.

There are two broad kinds of ambiguity.

Lexical category ambiguity occurs when a word can belong to more than one syntactic category. The word "duck" can be a noun or a verb. The financial-institution and river-side senses of "bank" illustrate word-sense ambiguity, another form of lexical ambiguity: both can have the same noun category, so a bare N-to-bank rule does not distinguish them. In a CFG, category ambiguity appears as multiple preterminal rules for the same terminal:

N→duck,V→duckN \to \text{duck}, \qquad V \to \text{duck}

A sentence like "I saw her duck" can then have multiple parses. In the noun reading, "duck" heads the noun phrase "her duck"; in the verb reading, it describes her action. This is closely related to the POS tagging problem from Part-of-Speech Tagging, but here the category analysis affects the larger phrase structure, not just the label of one token. Choosing a lexical category restricts which grammar rules and phrase structures the parser can use.

Structural ambiguity occurs when the same words and the same word categories can combine into different phrase structures. The classic example is prepositional phrase attachment:

the dog chased the cat with a telescope

The phrase "with a telescope" can attach to the object noun phrase "the cat":

Code
CollapseExpand
[S
  [NP [Det the] [N dog]]
  [VP
    [V chased]
    [NP
      [NP [Det the] [N cat]]
      [PP [P with] [NP [Det a] [N telescope]]]]]]

Or it can attach to the verb phrase "chased the cat":

Code
CollapseExpand
[S
  [NP [Det the] [N dog]]
  [VP
    [VP [V chased] [NP [Det the] [N cat]]]
    [PP [P with] [NP [Det a] [N telescope]]]]]

Both trees yield the same string. The first says the cat has a telescope. The second says the dog used a telescope to chase the cat. The grammar alone does not choose between them. Contextual information and plausibility judgments can guide a reader. To rank the alternatives, a parser can use a scoring model, a preference heuristic, or a probabilistic grammar. The structural difference is small in terms of the number of nodes, but it is large in terms of meaning. This is why attachment ambiguity is such a central test case for parsing models.

Coordination also creates structural ambiguity. The phrase "old men and women" can mean "old men and old women" or "old men and women who are not necessarily old". The string does not tell you which grouping is intended. A grammar can enumerate these structures, but it cannot decide which reading a speaker intends without extra information.

The number of possible structures can grow extremely quickly. For n≥1n \ge 1 tokens, the number of ordered full binary bracketings, before a grammar constrains which ones are licensed, is the Catalan number:

Cn−1=1n(2n−2n−1)C_{n-1} = \frac{1}{n}\binom{2n-2}{n-1}

Equivalently, using the standard indexing Cm=1m+1(2mm)C_m = \frac{1}{m+1}\binom{2m}{m}, the number of ordered full binary tree shapes with nn leaves is Cn−1C_{n-1}. This counts possible bracketings before grammar labels and productions restrict them; it is not the number of parses licensed by every binary grammar.

The growth is exponential with a power-law correction. For large Catalan index mm, the standard asymptotic estimate is

Cm∼4mπ m3/2,m→∞.C_m \sim \frac{4^m}{\sqrt{\pi}\,m^{3/2}}, \qquad m \to \infty.

Here m=n−1m=n-1 for a sentence with nn tokens, π\pi is the circle constant, and ∼\sim means that the ratio of the two expressions tends to one. The numerator supplies exponential growth; the denominator reduces it by a power of mm. This is an approximation for large mm, not an exact count for a finite sentence. In particular, the exact identity Cm+1/Cm=(4m+2)/(m+2)C_{m+1}/C_m=(4m+2)/(m+2) tends to 4 from below. Calling the counts faster than every exponential would therefore be wrong.

For n=20n = 20, that is already C19=1,767,263,190C_{19} = 1{,}767{,}263{,}190 possible binary bracketings. A grammar may rule out many of these shapes, but unrestricted enumeration still faces this worst-case growth. Chart parsers address it by sharing substructure. Pruning can further restrict which candidates are explored, although discarding candidates can lose a valid or best parse. Probabilistic ranking alone does not remove the need for efficient search: a parser that scores every complete tree still has to construct those trees.

The growth is easier to see on a log scale. The rising counts explain why chart parsers share subproblems: compact recognition avoids listing every complete tree, while explicit enumeration remains output-sensitive.

PythonIn [3]
CollapseExpand
import math

import numpy as np

span_sizes = np.arange(2, 21)
catalan_counts = np.array(
    [math.comb(2 * (n - 1), n - 1) // n for n in span_sizes]
)
VisualizationOut [4]
CollapseExpand
Line plot of Catalan numbers rising sharply on a log scale.
Number of ordered full binary bracketings for input lengths from 2 to 20 tokens, shown on a logarithmic vertical axis. The count increases from 1 at 2 tokens to 1,767,263,190 at 20 tokens. These are possible tree shapes before a grammar constrains their labels and combinations.

A probabilistic context-free grammar, or PCFG, adds probabilities to rules and gives each tree a probability. We will define PCFGs shortly. A probabilistic model can assign different weights to the permitted analyses. A probabilistic parser can return a highest-probability tree or represent the remaining uncertainty. This shifts the question from which structures are possible to how their probabilities compare.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy