November 2016
Beginner to intermediate
687 pages
15h 31m
English
In Probabilistic Context-free Grammar (PCFG), probabilities are attached to all the production rules present in CFG. The sum of these probabilities is 1. It generates the same parse structures as CFG, but it also assigns a probability to each parse tree. The probability of a parsed tree is obtained by taking the product of probabilities of all the production rules used in building the tree.
Let's see the following code in NLTK, that illustrates the formation of rules in PCFG:
>>> import nltk >>> from nltk.corpus import treebank >>> from itertools import islice >>> from nltk.grammar import PCFG, induce_pcfg, toy_pcfg1, toy_pcfg2 >>> gram2 = PCFG.from string(""" A -> B B [.3] | C B C [.7] B -> ...Read now
Unlock full access