A Probabilistic Context-Free Grammar (PCFG) extends a standard context-free grammar by assigning probabilities to each production rule, where the probabilities for all expansion options of any non-terminal must sum to one; the probability of a parse tree is calculated as the product of the probabilities of its constituent rules, enabling the resolution of syntactic ambiguity by selecting the highest-probability parse tree for a given sentence.
Basics of Probabilistic Context-Free Grammars (PCFGs) | NLP
Added:so we'll first introduce the basic formalism PCF keys and then we'll talk about a crucial algorithm which is called the CKY algorithm and this is again actually a dynamic programming algorithm which will allow us to use PCF G's to path sentences so here is a pcfg and you'll see that it basically looks exactly the same as a context-free grammar but we now have probabilities assigned to each rule in the grammar so here I have a set of context free rules and will gain assume that s is the start symbol under the context-free grammar but now in red I've shown a probability for each rules so s goes to NPV P for example has probability 1 VP goes to VI has probability zero point four and so on and so on these probabilities have one critical property which is the following if I take any non-terminal in the grammar so let's take VP for example there are a number of possible ways of expanding that non-terminal so VP can be expanded in three different ways here it can be written as VI or VT NP or V PPP three possibilities and notice that the three probabilities associated with these three different options sum to one so zero point four plus zero point four plus zero point two is equal to one and this is the key constraint on the probabilities in a pcfg if I look at any non-terminal we must have these probabilities something to one here's another example it's NP can rewrite in two different ways either as a determiner followed by a noun or a noun phrase followed by prepositional phrase these two probabilities sum to one so these probabilities have a clear interpretation which is the following they are the conditional probability of conditioned on a particular non-terminal we have multiple different ways of rewriting that non-terminal we now have a distribution over those different options over those different ways of rewriting that particular non-terminal okay so then we can do the following so let me just illustrate this definition down here this text down here let's take a particular parse tree under this grammar very simple one so notice that every one of the rules I'm using here is in this grammar so that's a valid parse tree under the underlying context-free grammar we're now going to assign a probability to this entire paths tree which is simply a product of probabilities for these different rules so if I look at the first rule s goes to NP VP that has probability 1 and then NP goes to determinate and n that has probability zero point three terminal goes to the has probability one point zero and so to calculate the probability of an entire tree I just multiply together the probabilities of the different rules so V P goes to V I has probability 0.4 and VI goes to Sleeps has probability 1 okay so that's the final expression for the probability of this particular path string so more abstractly if a tree has rules alpha 1 goes to beta 1 alpha 2 goes to beta 2 up to alpha n goes to beta n this the left-hand side this is a non-terminal for each rule this is the sequence of non terminals on the right-hand side then the probability for the tree is the product of these parameters so I write Q so for example Q of V P goes to V T and P is equal to 0.4 in this grammar so each rule has a parameter Q of that rule which is some probability the probability for an entire tree is the product of these q terms just as is traded here so one useful intuition behind pcfg use is the following we can now think of top-down stochastic processes under which we can sample parse trees or derivations under a pcfg so recall that s is our start symbol so a derivation always starts with s now at each point in the derivation I'm again going to pick the leftmost non-terminal in my current duration s in this case and I'm going to use some rule to expand that symbol so let's say I pick this rule here s goes to NP VP and we can think of this as a probabilistic process where we choose this rule with the probability under the grammar so in fact there's only one way of expanding s as NP VP and so with probability 1 we're always going to rewrite this as NP VP under the grammar I showed you on the previous slide next step in the process we take the leftmost non-terminal again NP and you can again think of a stochastic process where we choose the rule expanding NP from the different possibilities using the distribution under the grammar so in this case we might choose NP goes to determine + n so notice NP is now replaced by these two words sorry these two symbols and that has probability point three now we pick DT we choose a rule from the grammar this actually rewrites us there with probability one and so on and so on so this probabilistic top-down process is going to terminate when I end up with a sequence of words so now at this point I have no non terminals left the parse tree underlying this of course is ESCOs NP VP it's me something like this and the probability is going to be the product of these different terms so you you can in fact once you have a problem stick context-free grammar sample derivation z' from that context-free grammar in this sort of top-down process so you can use a published at context-free grammar to generate pass trees okay so some crucial properties of PC FTS firstly as we've said they assign a probability to every possible parse tree allowed by the underlying context-free grammar so to calculate the probability of a pass tree I just look at the rules in that path tree and multiply together the different probabilities most crucially for our purposes we have the following so say I have a sentence s so let's say for example it's the dog or the man with the telescope so this is our sentence s the sentence may have several different path trees under the underlying context-free grammar so say we have a couple of different parse trees which I'll just sketch here under the CFG and as we said this is the ambiguity problem the problem is that our grammar is generating more than one parse tree so I'll call this entire set of path trees T of s okay so T of s is the set of possible parse trees for this input sentence now critically now I have probabilities on these rules in the grammar I can calculate the probability of each of these path trees so I might for example calculate the probability of this one is 0.01 and maybe this one is zero point zero zero zero five seven and so now I get this additional information where each pass tree in the grammar each parse tree for this particular sentence has a different probability and that gives a ranking on the different path trees in terms of their probability or likelihood and so given this ranking I can for example simply output from my model or from my parlor the highest probability tree out of the model so I now have a way of choosing between different paths trees and so the parsing methods we'll look at will first somehow learn the parameters of a pcfg from data and then given a new sentence they will search for the past tree that has the highest probability under the grammar and if the pcfg does a good job of modeling the probability of different possible parse trees we'll end up with an accurate parser that more often than not resolves the ambiguities that i just described to you in the previous lecture so one last definition if we have the sentence s then the most likely parse tree for that sentence is if we look at all trees and that set T of s from a T of s is the set of possible parse trees for s we now just choose the highest probability tree under our p gfg
Up Next

PCFGs: Inside-Outside Probabilities Explained | Lecture 25
@naturallanguageprocessing6035
14.2K views•2017-02-15

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science







![M0 | Probability theory | CIV8530 - Structural & System Reliability [English version]](https://i.ytimg.com/vi/4pay1YrXVuo/maxresdefault.jpg)
![[Fall-2022] Tutorial: Probability](https://i.ytimg.com/vi_webp/rcXeRCGCh4o/maxresdefault.webp)
























![How to Turn Words into Trees: Dependency Parsing [Lecture]](https://i.ytimg.com/vi/ZT1Et5wd1SQ/maxresdefault.jpg)







