1 Probabilistic Context-Free Grammars.pptx

pixelatedproseai 1 views 25 slides Oct 15, 2025
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

This presentation describes about probabilistic context free grammars


Slide Content

UNIT III Lavanya B CSE(AI & ML)

probabilistic context free grammars A Probabilistic Context-Free Grammar (PCFG) extends Context-Free Grammar (CFG) by assigning probabilities to each production rule, allowing it to model the likelihood of different sentence structures. This probabilistic element is crucial for handling ambiguity in natural language processing, as it enables the selection of the most probable parse tree for a given sentence.  Tuesday, August 12, 2025 © BVRIT 2

1. Context-Free Grammar (CFG): Tuesday, August 12, 2025 © BVRIT 3 A CFG defines the grammatical rules of a language using symbols (terminals and non-terminals) and production rules that specify how non-terminals can be expanded into other symbols.  For example, a rule like "S -> NP VP" (Sentence -> Noun Phrase Verb Phrase) is a CFG rule. 

2. Probabilistic Extension:  Tuesday, August 12, 2025 © BVRIT 4 A PCFG adds probabilities to each CFG rule, indicating how likely that rule is to be used in generating a sentence.  For instance, a rule "S -> NP VP" might have a probability of 0.7, while another rule like "S -> NP VP PP" might have a probability of 0.3, 

3. PCFG in NLP:  Tuesday, August 12, 2025 BVRIT 5 PCFGs are used in NLP for tasks like parsing, where the goal is to determine the grammatical structure of a sentence.  Because natural language is often ambiguous (a sentence can have multiple possible grammatical structures), CFGs alone are not sufficient.  PCFGs overcome this by assigning probabilities to different parse trees, allowing the most likely parse to be selected. 

Tuesday, August 12, 2025 © BVRIT 6 A CFG is defined by 4 components : N → Non-terminal symbols (e.g., S , NP , VP , etc.) Σ → Terminal symbols (actual words, e.g., book , flights ) P → Production rules (e.g., S → NP VP ) S → Start symbol (often S for sentence) A PCFG adds a 5th component : D → A function that assigns a probability to each rule in P . Formally: G=(N,Σ,P,S,D) G = (N, Σ, P, S, D)

Example rule in PCFG format: S → NP VP [0.80] S → Aux NP VP [0.15] S → VP [0.05] Tuesday, August 12, 2025 © BVRIT 7

2. Why add probabilities? Normal CFGs allow multiple possible parse trees for sentence. PCFGs let us rank parses by likelihood . This is useful for: Disambiguation (choosing the most likely meaning) Language modeling (estimating sentence probabilities) Speech recognition, spelling correction, etc. Tuesday, August 12, 2025 © BVRIT 8

3. How to get rule probabilities? Definition: Rule probability = probability of choosing a specific expansion given a particular non-terminal. Tuesday, August 12, 2025 © BVRIT 9

Tuesday, August 12, 2025 © BVRIT 10 Example: If in a treebank we see: NP → Pronoun happens 40 times NP → Noun happens 60 times Total NP expansions = 100

2. Probability of a parse tree This is about the probability of an entire derivation (tree) for a sentence. Definition: Multiply the probabilities of all rules used in that tree . Tuesday, August 12, 2025 © BVRIT 11

Example: Tuesday, August 12, 2025 © BVRIT 12 I f your parse uses: S → NP VP [0.8] NP → Pronoun [0.4] VP → Verb NP [0.5] Pronoun → you [0.6] Verb → see [0.3] NP → Noun [0.6] Noun → dog [0.5] Then:

5. Choosing the best parse Tuesday, August 12, 2025 © BVRIT 13

6. Probability of a sentence Tuesday, August 12, 2025 © BVRIT 14

Probabilistic CYK Parsing of PCFGs Probabilistic CYK (Cocke-Younger- Kasami ) parsing of Probabilistic Context-Free Grammars (PCFGs) in Natural Language Processing (NLP) is a dynamic programming algorithm used to find the most probable parse tree for a given sentence. Tuesday, August 12, 2025 © BVRIT 15

Probabilistic Context-Free Grammars (PCFGs): These are an extension of traditional Context-Free Grammars (CFGs) where each production rule is assigned a probability. This allows the grammar to model the likelihood of different syntactic structures. CYK Algorithm: The classic CYK algorithm is a dynamic programming algorithm for parsing CFGs in Chomsky Normal Form (CNF). It builds a table representing possible constituents spanning contiguous segments of the input sentence. Tuesday, August 12, 2025 © BVRIT 16

Probabilistic CYK Extension: The probabilistic CYK algorithm extends the classic CYK by incorporating probabilities into the table entries. Instead of simply storing whether a constituent can span a segment, it stores the maximum probability of a parse tree for that segment, along with back-pointers to reconstruct the tree. How it Works: Grammar in CNF: The PCFG must be converted to Chomsky Normal Form, where all production rules are either of the form A -> BC (two non-terminals) or A -> a (a terminal). Tuesday, August 12, 2025 © BVRIT 17

Goal of Probabilistic CYK Tuesday, August 12, 2025 © BVRIT 18 That is: Given a sentence S and a PCFG, Find the single parse tree with the highest probability. CYK is bottom-up and uses dynamic programming to do this efficiently.

Requirements CYK works only if the grammar is in Chomsky Normal Form (CNF) : Every rule is either: Tuesday, August 12, 2025 © BVRIT 19 No ε-productions (no empty string rules). Why? → CNF structure makes it easy to split the problem into two smaller subproblems (binary splitting).

Data Structure We use a 3D array : Tuesday, August 12, 2025 © BVRIT 20

Base Case (length 1 spans) Tuesday, August 12, 2025 © BVRIT 21

Recursive Case (length > 1 spans) Tuesday, August 12, 2025 © BVRIT 22

Output Tuesday, August 12, 2025 © BVRIT 23

Example S → NP VP [0.9] NP → Det N [0.5] VP → V NP [0.6] Det → the [0.8] N → cat [0.7] V → chased [0.9] Tuesday, August 12, 2025 © BVRIT 24

Tuesday, August 12, 2025 © NIT Warangal 25 Thank You