Probabilistic context-free grammars #
A probabilistic context-free grammar (PCFG) over G is a weight on the rules of G that sums
to one over the rules expanding each nonterminal. The probability of a derivation tree is the
product of the weights of the rules it applies, and the probability of a corpus, a multiset of
derivation trees, is the product over its trees, so the corpus probability factorises over
disjoint sub-corpora. Over licensed trees it also collects into a product over the grammar's rules
of the rule weight raised to the corpus count of that rule.
Main definitions #
PCFG G: aWeightedCFG G ℝ≥0∞vanishing off the grammar and normalised at each nonterminal the grammar expands.PCFG.derivProb,PCFG.corpusProb: the probability of a derivation tree, aRoseTree (Symbol T G.NT), and of a corpus.PCFG.uniform: the uniform rule distribution at every nonterminal.
Main results #
PCFG.corpusProb_add: corpus probability is multiplicative over disjoint corpora.PCFG.corpusProb_eq_prod_pow_count: over licensed trees, corpus probability is the product of rule weights raised to corpus rule counts.
Implementation notes #
Weights are ℝ≥0∞, the scalar of MeasureTheory.Measure, and a rule outside the grammar has
weight 0, so a tree applying such a rule has probability 0. derivProb is a weight on
trees; the measure it is the singleton mass of, and tightness in the sense of
[BT73] and [Chi99], are in
Linglib.Core.Computability.ContextFreeGrammar.Measure.
References #
A probabilistic context-free grammar over G is a rule weight that vanishes off the grammar
and sums to one over the rules with each left-hand side the grammar expands.
- weight : ContextFreeRule T G.NT → ENNReal
- weight_eq_zero_of_not_mem (r : ContextFreeRule T G.NT) : r ∉ G.rules → self.weight r = 0
Rules outside the grammar have weight
0. - sum_weight (a : G.NT) : a ∈ Finset.image (fun (x : ContextFreeRule T G.NT) => x.input) G.rules → ∑ r ∈ G.rules with r.input = a, self.weight r = 1
Weights sum to one over the rules with each left-hand side the grammar expands.
Instances For
The weight of a node, read from its symbol and the symbols of its children, is the rule
weight at a nonterminal, 1 at a childless terminal and 0 at a terminal with children.
Equations
- W.symbolWeight (Symbol.nonterminal A) x✝ = W.weight { input := A, output := x✝ }
- W.symbolWeight (Symbol.terminal t) [] = 1
- W.symbolWeight (Symbol.terminal t) (head :: tail) = 0
Instances For
The probability of a derivation tree is the product over its nodes of the weight of the rule applied there.
Equations
- W.derivProb t = (List.map (fun (p : Symbol T G.NT × List (Symbol T G.NT)) => W.symbolWeight p.1 p.2) t.localTrees).prod
Instances For
The probability of a corpus is the product of the probabilities of its derivation trees.
Equations
- W.corpusProb D = (Multiset.map W.derivProb D).prod
Instances For
Corpus probability is multiplicative over disjoint corpora, since derivation trees are
independent under a PCFG, in contrast to DirichletPCFG.corpusProb.
The probability of a licensed derivation tree is the product over the grammar's rules of the rule weight raised to the number of applications of that rule in the tree.
Over licensed derivation trees, corpus probability is the product over the grammar's rules of the rule weight raised to the corpus count of that rule.
The uniform PCFG puts the uniform distribution over its rules at every nonterminal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- PCFG.instInhabited = { default := PCFG.uniform }