{"edition":"nlp-2026-10-10","routes":{"m2":{"read":[{"id":"foundations","title":"Start here · language & probability","unit":0,"sections":[{"id":"language","title":"What NLP is doing","html":"<p><strong>Natural Language Processing (NLP)</strong> is the study of computational methods for analysing, interpreting and producing human language. An NLP system receives text or speech and produces an output such as a tag, a meaning, a translation or a probability.</p><p>For M2, the central question is often: <strong>how do counts from a training corpus become probabilities, and how do those probabilities help choose a sentence, a tag or a word sense?</strong> You will learn the vocabulary first, then do the arithmetic with complete working.</p><div class=\"flow\"><div class=\"node\">Training text<small>examples already observed</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Counts<small>how often things occur</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Probabilities<small>counts divided by totals</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Decision<small>compare possible answers</small></div></div><table><thead><tr><th>Term</th><th>Meaning</th><th>Concrete example</th></tr></thead><tbody><tr><td>Corpus</td><td>A collection of language data. The plural is corpora.</td><td>Three sentences saved together form a tiny corpus.</td></tr><tr><td>Document</td><td>One text item within a collection.</td><td>One review or one article.</td></tr><tr><td>Token</td><td>One occurrence produced by tokenization.</td><td>“cats like cats” has 3 word tokens.</td></tr><tr><td>Type</td><td>A distinct token value.</td><td>The same text has 2 types: cats and like.</td></tr><tr><td>Vocabulary</td><td>The set of token types recognised by the model.</td><td>V = {cats, like}; vocabulary size is 2.</td></tr><tr><td>Training</td><td>Estimating rules or numbers using examples.</td><td>Count how often like follows cats.</td></tr><tr><td>Test</td><td>Applying the learned model to a new example.</td><td>Calculate a probability for a sentence not used to build the counts.</td></tr></tbody></table><h3>Three levels you will repeatedly see</h3><table><thead><tr><th>Level</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>Word sequence</td><td>Which word is likely next?</td><td>After “drink”, is “water” likely?</td></tr><tr><td>Syntax</td><td>What role or structure does the word have?</td><td>“book” is a noun in “a book” and a verb in “book tickets”.</td></tr><tr><td>Semantics</td><td>Which meaning is intended?</td><td>“bank” near “deposit” means a financial institution.</td></tr></tbody></table><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka order = language model; word ka role = POS; word ka matlab = sense.</p><h3>Your M2 route</h3><p>Read the probability refresher below, then <strong>N-grams and smoothing → POS/HMM → parsing/chunking/NER → word relations and WSD</strong>. Answers sit directly below their questions. The separate Formulas tab is for revision after learning the methods. Both 2-mark questions are compulsory; attempt any two of the three 3-mark questions. Total attempted = 10 marks in one hour.</p><p>M2 scope: Unit 3 slides 62–160; Unit 4 slides 1–128; Unit 5 slides 1–57. Earlier-unit material in this short opening chapter is included only to supply prerequisites.</p>"},{"id":"notation","title":"Tokens, counts and symbols","html":"<p>A formula is a short way of stating a calculation. First name the quantities; only then insert the numbers. In this guide, C means a count and P means a probability.</p><table><thead><tr><th>Notation</th><th>Read it as</th><th>What to do</th></tr></thead><tbody><tr><td><span class=\"math-inline\"><img src=\"math/53df638c65412b2e.svg\" alt=\"C(\\text{cat})=3\" style=\"width:10.644ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Count of cat is three</td><td>Count every occurrence, including repeats.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/f74362866e81db35.svg\" alt=\"P(\\text{cat})\" style=\"width:6.475ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Probability of cat</td><td>A number from 0 to 1.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/c19161969f7b5db0.svg\" alt=\"P(\\text{cat}\\mid\\text{the})\" style=\"width:11.504ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Probability of cat given the</td><td>Restrict attention to occasions where the history is “the”.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/e1e73674daae58eb.svg\" alt=\"\\sum_i x_i\" style=\"width:5.54ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Sum of the x values</td><td>Add the terms: x₁ + x₂ + …</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/9213d2b315baaeb2.svg\" alt=\"\\prod_i x_i\" style=\"width:5.286ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Product of the x values</td><td>Multiply the terms: x₁ × x₂ × …</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/d6495ab774b17309.svg\" alt=\"\\arg\\max_c s(c)\" style=\"width:12.795ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>The choice c with the largest score</td><td>Return a label, not the numeric score.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/b75d6d79f6931032.svg\" alt=\"\\max_c s(c)\" style=\"width:9.269ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Largest score</td><td>Return a number.</td></tr></tbody></table><section class=\"example\"><h3>Example 1 · tokens and types</h3><p class=\"question\">For the corpus “we study nlp” and “we like nlp”, find the token count, vocabulary and count of “we”.</p><div class=\"given\"><strong>Given</strong><p>Two lowercase sentences. Ignore punctuation; do not add boundary markers.</p><strong>To find</strong><p>Token count N, vocabulary V, vocabulary size |V| and C(we).</p></div><h3>Formula and why it applies</h3><p>A token is an occurrence; a type is a distinct word. Add sentence lengths to count tokens; remove duplicates only when finding the vocabulary.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. List every occurrence</h4><p>we, study, nlp, we, like, nlp.</p></div><div class=\"step\"><h4>Step 2. Count tokens</h4><div class=\"math-display\"><img src=\"math/ece835ece0dea071.svg\" alt=\"N=3+3=6\" style=\"width:14.203ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Keep one copy of each type</h4><p>V = {we, study, nlp, like}; |V| = 4.</p></div><div class=\"step\"><h4>Step 4. Count the requested word</h4><p>“we” appears once in each sentence, hence C(we) = 2.</p></div><div class=\"answer\">N = 6; |V| = 4; C(we) = 2.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Token mein repeat gin; type mein duplicate hata.</p></section><section class=\"example\"><h3>Example 2 · sum and product</h3><p class=\"question\">Given probabilities 0.5, 0.2 and 0.1, compute their sum and their product.</p><div class=\"given\"><strong>Given</strong><p>Three numbers: 0.5, 0.2, 0.1.</p><strong>To find</strong><p>Sum and product; recognise that these are different operations.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/63e5285ab6522f55.svg\" alt=\"\\sum_{i=1}^{3}p_i=p_1+p_2+p_3\" style=\"width:20.447ex;height:6.711ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/62eff7a248154cbf.svg\" alt=\"\\prod_{i=1}^{3}p_i=p_1p_2p_3\" style=\"width:14.54ex;height:6.711ex\" loading=\"lazy\" decoding=\"async\"></div><p>Add for a sum. Multiply for a product. A sentence-chain calculation normally uses the product of its conditional probabilities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Add the first two numbers</h4><div class=\"math-display\"><img src=\"math/7759ec5773e64d72.svg\" alt=\"0.5+0.2=0.7\" style=\"width:14.457ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Complete the sum</h4><div class=\"math-display\"><img src=\"math/5f21379b0e25bf90.svg\" alt=\"0.7+0.1=0.8\" style=\"width:14.457ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Multiply the first two numbers</h4><div class=\"math-display\"><img src=\"math/3666eec3c2831548.svg\" alt=\"0.5\\times0.2=0.1\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Complete the product</h4><div class=\"math-display\"><img src=\"math/3b2af630e6ad1d43.svg\" alt=\"0.1\\times0.1=0.01\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Sum = 0.8; product = 0.01.</div></section>"},{"id":"probability","title":"Probability, without skipped steps","html":"<p><strong>Empirical probability</strong> estimates how likely an event is from its observed frequency. Divide the number of relevant observations by the total number of observations in the selected group. For a conditional probability, the denominator is the count of the condition, not the size of the entire corpus.</p><div class=\"math-display\"><img src=\"math/cde1f475268fa5b4.svg\" alt=\"P(A)=\\frac{C(A)}{N}\" style=\"width:14.345ex;height:4.855ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/650cfba7e65676b7.svg\" alt=\"P(B\\mid A)=\\frac{C(A,B)}{C(A)}\" style=\"width:20.671ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Here A is the conditioning event, B is the event being predicted, C(A,B) counts observations containing both in the required relationship, and N is the total number of observations. “Given A” tells you which denominator to use.</p><div class=\"flow\"><div class=\"node\">Select the condition<small>“given A”</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Count matching outcomes<small>C(A,B)</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Divide by condition count<small>C(A)</small></div></div><section class=\"example\"><h3>Example 1 · word probability</h3><p class=\"question\">A corpus contains 20 tokens; “rain” occurs 5 times. Find the unigram probability of “rain”.</p><div class=\"given\"><strong>Given</strong><p>N = 20 and C(rain) = 5.</p><strong>To find</strong><p>P(rain).</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/2711f5706c9dc86b.svg\" alt=\"P(w)=\\frac{C(w)}{N}\" style=\"width:14.191ex;height:4.855ex\" loading=\"lazy\" decoding=\"async\"></div><p>Unigram probability ignores neighbouring words. Every token in the corpus is one observation.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Insert the count and total</h4><div class=\"math-display\"><img src=\"math/24d2e511eeadd9c0.svg\" alt=\"P(\\text{rain})=\\frac{5}{20}\" style=\"width:13.639ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Divide</h4><div class=\"math-display\"><img src=\"math/07337f908c856c5a.svg\" alt=\"\\frac{5}{20}=0.25\" style=\"width:10.298ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">P(rain) = 0.25, or 25%.</div></section><section class=\"example\"><h3>Example 2 · conditional probability</h3><p class=\"question\">In a corpus, “drink” is followed by another word 8 times. It is followed by “water” 6 times. Find P(water | drink).</p><div class=\"given\"><strong>Given</strong><p>C(drink as a history) = 8; C(drink, water) = 6.</p><strong>To find</strong><p>Probability that the next word is water, given drink.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/b16537e98cb2aea8.svg\" alt=\"P(\\text{water}\\mid\\text{drink})=\\frac{C(\\text{drink water})}{C(\\text{drink})}\" style=\"width:34.928ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>The condition is drink, so use the 8 drink-histories as the denominator.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the favourable continuations</h4><p>Six of the eight continuations are water.</p></div><div class=\"step\"><h4>Step 2. Divide</h4><div class=\"math-display\"><img src=\"math/c4bcc480ea0098b5.svg\" alt=\"P(\\text{water}\\mid\\text{drink})=\\frac68=0.75\" style=\"width:28.291ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">P(water | drink) = 0.75.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Bar ke right mein jo hai, denominator uska count.</p></section><section class=\"example\"><h3>Example 3 · multiply a sequence</h3><p class=\"question\">A model gives P(a | start) = 0.4, P(cat | a) = 0.5 and P(end | cat) = 0.2. Find the probability of the complete sentence “a cat”.</p><div class=\"given\"><strong>Given</strong><p>Start → a = 0.4; a → cat = 0.5; cat → end = 0.2.</p><strong>To find</strong><p>Probability of the three-transition path.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/20d792a0426e11b9.svg\" alt=\"P(\\text{a cat, end})=P(\\text{a}\\mid\\text{start})P(\\text{cat}\\mid\\text{a})P(\\text{end}\\mid\\text{cat})\" style=\"width:48.424ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Every transition must happen in sequence, so multiply the model’s conditional probabilities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Write the three factors in order</h4><div class=\"math-display\"><img src=\"math/aacb5800d20f6f86.svg\" alt=\"P=0.4\\times0.5\\times0.2\" style=\"width:18.922ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Multiply the first pair</h4><div class=\"math-display\"><img src=\"math/4528e6e7a97bb8e8.svg\" alt=\"0.4\\times0.5=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Multiply by the last factor</h4><div class=\"math-display\"><img src=\"math/45c99ba534e1771d.svg\" alt=\"0.2\\times0.2=0.04\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Complete-sentence probability = 0.04.</div></section><section class=\"example\"><h3>Example 4 · compare labels</h3><p class=\"question\">Two tag candidates have scores noun = 0.036 and verb = 0.048. Which tag does argmax return? If these are the only candidates, find the normalised noun probability.</p><div class=\"given\"><strong>Given</strong><p>s(noun) = 0.036 and s(verb) = 0.048.</p><strong>To find</strong><p>Winning label and normalised noun probability.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/d264cbc0f9fb7e13.svg\" alt=\"\\hat c=\\arg\\max_c s(c)\" style=\"width:15.912ex;height:3.459ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0cbb12db950a8417.svg\" alt=\"P(c)=\\frac{s(c)}{\\sum_j s(j)}\" style=\"width:15.818ex;height:5.881ex\" loading=\"lazy\" decoding=\"async\"></div><p>A score need not sum to 1. Dividing each score by the sum gives a distribution over the candidates.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compare scores</h4><p>0.048 > 0.036, so verb wins.</p></div><div class=\"step\"><h4>Step 2. Find their total</h4><div class=\"math-display\"><img src=\"math/884e5c8a756ca87a.svg\" alt=\"0.036+0.048=0.084\" style=\"width:21.244ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Divide the noun score by the total</h4><div class=\"math-display\"><img src=\"math/58bb63e903487b21.svg\" alt=\"P(\\text{noun})=\\frac{0.036}{0.084}=\\frac37\\approx0.428571\" style=\"width:34.239ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">argmax returns “verb”. The normalised noun probability is approximately 0.428571.</div></section>"},{"id":"bayes","title":"Bayes’ rule: prior, evidence and answer","html":"<p><strong>Bayes’ rule</strong> reverses a conditional probability. A word-sense classifier asks “which sense is most likely given these context words?” Training data more easily supplies “how likely are these words when this sense is used?” Bayes connects the two.</p><div class=\"math-display\"><img src=\"math/9afdb53fbf7886dd.svg\" alt=\"P(c\\mid x)=\\frac{P(x\\mid c)P(c)}{P(x)}\" style=\"width:23.689ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>c</td><td>A candidate class, tag or word sense.</td></tr><tr><td>x</td><td>The observed evidence, such as a context word.</td></tr><tr><td>P(c)</td><td>Prior: how common the class is before seeing the evidence.</td></tr><tr><td>P(x | c)</td><td>Likelihood: how compatible the evidence is with that class.</td></tr><tr><td>P(c | x)</td><td>Posterior: probability of the class after observing the evidence.</td></tr><tr><td>P(x)</td><td>Evidence normaliser, shared by all classes for the same observation.</td></tr></tbody></table><p>For ranking classes, calculate <strong>prior × likelihood</strong>. The common denominator does not affect which class is largest. For an actual posterior probability, divide by the sum of all class scores.</p><section class=\"example\"><h3>A complete Bayes calculation</h3><p class=\"question\">A word has two senses: financial bank and river bank. Priors are 0.6 and 0.4. The probability of observing “loan” is 0.5 under the financial sense and 0.1 under the river sense. Find the most likely sense and its posterior.</p><div class=\"given\"><strong>Given</strong><p>P(F) = 0.6; P(R) = 0.4; P(loan | F) = 0.5; P(loan | R) = 0.1. These two senses are exhaustive.</p><strong>To find</strong><p>Scores and P(F | loan).</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/c8e3aa7e814574bf.svg\" alt=\"s(c)=P(c)P(\\text{loan}\\mid c)\" style=\"width:21.731ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/1414aff0cfb8fbd2.svg\" alt=\"P(F\\mid\\text{loan})=\\frac{s(F)}{s(F)+s(R)}\" style=\"width:27.022ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply prior and likelihood to reverse the conditioning. Then normalise because a posterior was requested.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Score the financial sense</h4><div class=\"math-display\"><img src=\"math/72319d32a8913027.svg\" alt=\"s(F)=0.6\\times0.5=0.30\" style=\"width:23.121ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Score the river sense</h4><div class=\"math-display\"><img src=\"math/adf5b8b758b9a296.svg\" alt=\"s(R)=0.4\\times0.1=0.04\" style=\"width:23.144ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Add the scores</h4><div class=\"math-display\"><img src=\"math/d526374c15c8e154.svg\" alt=\"P(\\text{loan})=0.30+0.04=0.34\" style=\"width:28.476ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Normalise the financial score</h4><div class=\"math-display\"><img src=\"math/99c028fbba7fd3e1.svg\" alt=\"P(F\\mid\\text{loan})=\\frac{0.30}{0.34}=\\frac{15}{17}\\approx0.882353\" style=\"width:37.064ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Financial bank wins; its posterior probability is about 0.882353.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Pehle se kitna common × evidence kitna suit karta = score.</p></section>"},{"id":"calculator","title":"Small probabilities, logs and calculator use","html":"<p>Repeated multiplication of probabilities produces small numbers. A calculator may show 0.0000125 as <strong>1.25 × 10⁻⁵</strong>; they are the same value. A logarithm turns a product into a sum. Log probabilities are often negative because probabilities between 0 and 1 have negative logs.</p><div class=\"math-display\"><img src=\"math/aa22afa6e5e6a3ea.svg\" alt=\"\\log(ab)=\\log a+\\log b\" style=\"width:21.306ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/7a41936887c316a1.svg\" alt=\"\\log_b x=y\\quad\\Longleftrightarrow\\quad b^y=x\" style=\"width:25.801ex;height:2.205ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use the log base specified in the question. Natural log is ln (base e); ordinary calculator log is usually base 10. Perplexity is simplest to evaluate using the direct power formula. Do not mix bases in the same calculation.</p><section class=\"example\"><h3>Calculator example · roots in perplexity</h3><p class=\"question\">A model assigns probability 1/16 to a test sequence with 4 predicted tokens. Calculate perplexity.</p><div class=\"given\"><strong>Given</strong><p>P = 1/16; N = 4 predicted tokens.</p><strong>To find</strong><p>Perplexity PP.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/8263823864a08bf0.svg\" alt=\"PP=P^{-1/N}=\\left(\\frac1P\\right)^{1/N}\" style=\"width:24.943ex;height:6.01ex\" loading=\"lazy\" decoding=\"async\"></div><p>Perplexity takes the reciprocal probability and then its Nth root. N must match the number of predicted events in the product.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Take the reciprocal</h4><div class=\"math-display\"><img src=\"math/58b85b07a845828b.svg\" alt=\"\\frac{1}{1/16}=16\" style=\"width:10.8ex;height:5.208ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Take the fourth root</h4><div class=\"math-display\"><img src=\"math/fcf353f0637dd633.svg\" alt=\"PP=16^{1/4}=2\" style=\"width:15.414ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Interpret</h4><p>A perplexity of 2 means an effective average uncertainty comparable to two equally likely alternatives. It is not 2% error.</p></div><div class=\"answer\">PP = 2.</div></section><h3>Calculator entry order</h3><p>Enter the full product with parentheses. For the Nth root enter <strong>(1 ÷ P)^(1 ÷ N)</strong>. Keep at least 6 significant digits while working; round the final answer. If your calculator offers Ans, reuse the stored value instead of typing a heavily rounded result.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Probability ke factors multiply; log mein add; perplexity mein ulta karke root.</p>"}],"scope":"Prerequisites for M2 · no earlier NLP knowledge assumed"},{"id":"m2-language-models","title":"N-grams and language models","unit":3,"scope":"Unit 3, pages 62–108; essential probability revision","sections":[{"id":"words-counts-probability","title":"Words, counts and probabilities: the notation you need","html":"<p><strong>A token</strong> is one occurrence of a word. A <strong>type</strong> is one distinct word. A <strong>corpus</strong> is a collection of texts used for analysis or training. In “cats chase cats”, there are three word tokens but only two word types: cats and chase. A language model learns regularities from such a corpus to assign probabilities to word sequences. It does not simply count whether a sentence is grammatically correct.</p><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Read it as</th><th>Concrete meaning</th></tr></thead><tbody><tr><td>C(cat)</td><td>count of cat</td><td>Number of times cat occurs.</td></tr><tr><td>C(the, cat)</td><td>count of the followed by cat</td><td>Count adjacent ordered pairs; cat the is different.</td></tr><tr><td>P(cat)</td><td>probability of cat</td><td>A number from 0 to 1.</td></tr><tr><td>P(cat | the)</td><td>probability of cat given the</td><td>Among contexts ending in the, how often cat follows.</td></tr><tr><td>V</td><td>vocabulary size</td><td>Number of distinct outcomes the model may predict.</td></tr><tr><td>N</td><td>number of tokens or predictions</td><td>Its exact meaning must be stated for the calculation.</td></tr></tbody></table></div><p>The vertical bar <strong>| means “given”</strong>. The condition is on its right. In P(cat | the), the model has already seen “the” and is predicting “cat”. This direction matters: P(cat | the) and P(the | cat) usually have different denominators.</p><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains 20 word tokens. The word cat occurs 5 times. Find the maximum-likelihood unigram probability of cat.</strong></p><div class=\"given\"><h4>Given</h4><p>Total tokens N = 20; count C(cat) = 5.</p><h4>To find</h4><p>P(cat).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2711f5706c9dc86b.svg\" alt=\"P(w)=\\frac{C(w)}{N}\" style=\"width:14.191ex;height:4.855ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Relative frequency estimates the probability of drawing this word from the corpus. The denominator includes every token, not just distinct words.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Select the matching count</h5><p>The required outcome is cat, which occurs 5 times.</p></div><div class=\"step\"><h5>Step 2. Divide by the total number of trials</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4e5251cd8736de84.svg\" alt=\"P(\\text{cat})=\\frac{5}{20}=0.25\" style=\"width:19.79ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Interpret the result</h5><p>Under this unigram model, cat receives probability 0.25, or 25%.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(cat) = 0.25.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Jo chahiye uska count upar; total possible trials neeche.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. The word the has 10 outgoing occurrences in a corpus. It is followed by cat on 4 occasions and dog on 6. Find P(cat | the) and P(dog | the).</strong></p><div class=\"given\"><h4>Given</h4><p>C(the, cat) = 4; C(the, dog) = 6; C(the) = 10 outgoing contexts.</p><h4>To find</h4><p>Both next-word probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1f5e1649537aa36.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{C(h)}\" style=\"width:19.69ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The condition h = the restricts attention to its 10 continuations. We do not divide by the total corpus size.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Use the cat continuation</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3bf149513726477a.svg\" alt=\"P(\\text{cat}\\mid\\text{the})=\\frac{4}{10}=0.4\" style=\"width:23.687ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the dog continuation</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75de664b10c4bbcd.svg\" alt=\"P(\\text{dog}\\mid\\text{the})=\\frac{6}{10}=0.6\" style=\"width:24.192ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Check the complete row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b7387cc7f2626c50.svg\" alt=\"0.4+0.6=1\" style=\"width:12.697ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(cat | the) = 0.4 and P(dog | the) = 0.6.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Given waala word denominator choose karata hai.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. A collection has 8 sentences; 6 start with I and 2 start with we. Estimate each starting-word probability.</strong></p><div class=\"given\"><h4>Given</h4><p>Each sentence receives a start marker &lt;s&gt;. C(&lt;s&gt;) = 8; C(&lt;s&gt;, I) = 6; C(&lt;s&gt;, we) = 2.</p><h4>To find</h4><p>P(I | &lt;s&gt;) and P(we | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d997b6731cad785.svg\" alt=\"P(w_1\\mid\\langle s\\rangle)=\\frac{C(\\langle s\\rangle,w_1)}{C(\\langle s\\rangle)}\" style=\"width:24.701ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The start marker supplies the context for the first word; one start context is available per sentence.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate the first option</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f61ebf6be6e02d19.svg\" alt=\"P(I\\mid\\langle s\\rangle)=6/8=0.75\" style=\"width:22.757ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the second option</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e61e15f5786a3aaa.svg\" alt=\"P(we\\mid\\langle s\\rangle)=2/8=0.25\" style=\"width:24.291ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The estimated probabilities are 0.75 and 0.25.</div></section>"},{"id":"n-grams-construction","title":"Unigrams, bigrams and trigrams: construct them correctly","html":"<p><strong>Definition.</strong> An n-gram is a contiguous sequence of n items. For word n-grams, the items are consecutive word tokens. A unigram contains one word; a bigram contains two; a trigram contains three. Character n-grams use characters instead, so always identify the unit being counted.</p><div class=\"flow\"><div class=\"node\">Tokens: we | study | natural | language</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Move a window one token at a time</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Bigrams: we study / study natural / natural language</div></div><p>For m tokens without padding, the number of n-gram <em>positions</em> is max(0, m−n+1). Repeated positions may contain the same n-gram type. A bag-of-n-grams representation counts each n-gram type and loses the overall sentence order beyond the local order inside each n-gram.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9097807b6ad98d38.svg\" alt=\"\\text{Number of unpadded n-gram positions}=\\max(0,m-n+1)\" style=\"width:58.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. List all word unigrams, bigrams and trigrams for “the prime minister of our country”. Do not add boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Six tokens: the, prime, minister, of, our, country. n = 1, 2 and 3.</p><h4>To find</h4><p>All three lists and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad44404e3f41cdd.svg\" alt=\"\\#\\text{positions}=m-n+1\" style=\"width:23.607ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each window must contain consecutive words and move one position. No wraparound or invented final word is allowed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take one word at a time</h5><p>Unigrams: (the), (prime), (minister), (of), (our), (country). Count = 6−1+1 = 6.</p></div><div class=\"step\"><h5>Step 2. Take two consecutive words</h5><p>Bigrams: (the, prime), (prime, minister), (minister, of), (of, our), (our, country). Count = 6−2+1 = 5.</p></div><div class=\"step\"><h5>Step 3. Take three consecutive words</h5><p>Trigrams: (the, prime, minister), (prime, minister, of), (minister, of, our), (of, our, country). Count = 6−3+1 = 4.</p></div><div class=\"answer\"><strong>Final answer.</strong> 6 unigrams, 5 bigrams and 4 trigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct bigrams for “I like tea” using one start and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original tokens: I, like, tea. Add &lt;s&gt; and &lt;/s&gt; once each.</p><h4>To find</h4><p>The boundary-aware bigram sequence.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1b167f71a6a973b4.svg\" alt=\"\\#\\text{bigrams}=(m+2)-1=m+1\" style=\"width:33.155ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The start context predicts the first word, and the last word predicts that the sentence ends.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write the padded sequence</h5><p>&lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Move a two-token window</h5><p>(&lt;s&gt;, I), (I, like), (like, tea), (tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count the windows</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c37463b701447787.svg\" alt=\"3+1=4\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> There are four boundary-aware bigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct trigrams for “I like tea” using two start markers and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original sentence has three words. For a trigram model each predicted token needs two prior context tokens.</p><h4>To find</h4><p>All trigram prediction events.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/12c99aed7b535ad6.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:17.519ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Two start markers provide a complete context even for the first word.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Pad with two starts</h5><p>&lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Slide a three-token window</h5><p>(&lt;s&gt;, &lt;s&gt;, I), (&lt;s&gt;, I, like), (I, like, tea), (like, tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count predicted events</h5><p>The model predicts I, like, tea and the end marker: four predictions.</p></div><div class=\"answer\"><strong>Final answer.</strong> Four trigrams. Start markers are context; they are not ordinary predicted words.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Give the bag-of-bigrams counts for “a b a b” without padding.</strong></p><div class=\"given\"><h4>Given</h4><p>Four tokens in their given order.</p><h4>To find</h4><p>Bigram positions, distinct bigram types and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8326144ada817e2c.svg\" alt=\"\\#\\text{positions}=4-2+1=3\" style=\"width:26.674ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A bag stores frequencies; repeated bigrams must not be discarded.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Enumerate all positions</h5><p>(a,b), (b,a), (a,b).</p></div><div class=\"step\"><h5>Step 2. Group identical pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Bigram type</th><th>Count</th></tr></thead><tbody><tr><td>a b</td><td>2</td></tr><tr><td>b a</td><td>1</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> Three bigram positions but two distinct bigram types.</div><p class=\"cue\"><strong>Yaad rakho:</strong> n-gram mein n words; context mein n−1 words.</p></section>"},{"id":"collocations-and-lm","title":"Collocations and the purpose of a language model","html":"<p><strong>A collocation</strong> is a conventional word combination whose words occur together more strongly than ordinary chance or independent frequencies would suggest. Examples include “strong tea”, “heavy rain” and “red wine”. A bigram is merely two consecutive items; it need not be a collocation. “of the” can be frequent because both words are frequent, while a collocation expresses a particularly strong association.</p><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>What it represents</th><th>Example</th></tr></thead><tbody><tr><td>Bigram</td><td>Any adjacent two-token sequence</td><td>the book</td></tr><tr><td>Collocation</td><td>A characteristic strongly associated expression</td><td>heavy rain</td></tr><tr><td>Language model</td><td>A distribution used to score or predict sequences</td><td>P(rain | heavy)</td></tr></tbody></table></div><p><strong>Definition.</strong> A statistical language model assigns a probability to a sequence of words, or equivalently predicts the next word from preceding context. It is useful for autocomplete, speech recognition, machine translation, spelling correction, assistive communication and ranking candidate text. High probability reflects patterns learned from its training distribution; it is not a guarantee of truth or grammatical correctness.</p><div class=\"flow\"><div class=\"node\">Previous words: please turn your homework</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Candidate: in / over / elephant</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Language model gives each candidate a probability</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Application selects or ranks candidates</div></div><p><strong>Noisy-channel connection.</strong> Suppose x is the observed noisy text or speech and y is a candidate intended message. The noisy-channel approach chooses the y that maximizes P(x | y)P(y). The channel model P(x | y) asks how y could produce x; the language model P(y) asks whether y is a plausible message. P(x) is the same for all candidate y and therefore can be omitted when ranking.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d214e55148d91eec.svg\" alt=\"\\hat y=\\arg\\max_y P(y\\mid x)=\\arg\\max_y P(x\\mid y)P(y)\" style=\"width:43.434ex;height:3.769ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A spelling-correction system considers “flowers” and “flours”. For the observed input, the channel likelihoods are 0.2 and 0.4, and the respective language-model probabilities in context are 0.08 and 0.01. Which candidate does the noisy-channel rule choose?</strong></p><div class=\"given\"><h4>Given</h4><p>Candidate flowers: P(x|flowers)=0.2, P(flowers)=0.08. Candidate flours: P(x|flours)=0.4, P(flours)=0.01.</p><h4>To find</h4><p>The larger unnormalized candidate score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ad804659d9b93edc.svg\" alt=\"\\operatorname{score}(y)=P(x\\mid y)P(y)\" style=\"width:23.12ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both the error mechanism and the language context matter. The same denominator would normalize both candidates.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score flowers</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8f15b3cdfefd2ca8.svg\" alt=\"0.2\\times0.08=0.016\" style=\"width:17.851ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Score flours</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0c266d4a40683c9b.svg\" alt=\"0.4\\times0.01=0.004\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c236ae69fa45b6c2.svg\" alt=\"0.016&gt;0.004\" style=\"width:13.325ex;height:1.622ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Choose flowers. The scores are not yet posterior probabilities.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Har word-pair bigram hai; har frequent pair meaningful collocation nahi.</p>"},{"id":"chain-rule-markov","title":"Probability chain rule and the Markov assumption","html":"<p><strong>The probability chain rule</strong> decomposes the probability of a complete sequence into successive conditional probabilities. It is different from the derivative chain rule used in deep learning. Here we multiply probabilities, not derivatives.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5c8b1d21b7b346a9.svg\" alt=\"P(w_1,w_2,w_3)=P(w_1)P(w_2\\mid w_1)P(w_3\\mid w_1,w_2)\" style=\"width:47.112ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read left to right: probability of the first word; then probability of the second after the first; then probability of the third after both previous words. For a longer sentence, continue the same pattern. The product symbol ∏ simply means “multiply all of these terms”.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/430725f0e531e2f7.svg\" alt=\"P(w_1,\\ldots,w_m)=\\prod_{i=1}^{m}P(w_i\\mid w_1,\\ldots,w_{i-1})\" style=\"width:40.363ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><p><strong>The Markov assumption</strong> approximates long history by a limited recent context. A unigram model ignores preceding words. A bigram model keeps the previous word. A trigram model keeps the previous two words. This reduces the number of counts needed, but loses longer-range dependencies.</p><div class=\"table-wrap\"><table><thead><tr><th>Model</th><th>Prediction rule</th><th>For the next word country after the prime minister of our</th></tr></thead><tbody><tr><td>Unigram</td><td>P(wᵢ)</td><td>P(country)</td></tr><tr><td>Bigram</td><td>P(wᵢ | wᵢ₋₁)</td><td>P(country | our)</td></tr><tr><td>Trigram</td><td>P(wᵢ | wᵢ₋₂,wᵢ₋₁)</td><td>P(country | of, our)</td></tr><tr><td>Full chain rule</td><td>P(wᵢ | all previous words)</td><td>P(country | the, prime, minister, of, our)</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. For the three-word sentence “I like tea”, P(I)=0.2, P(like|I)=0.5 and P(tea|I,like)=0.4. Find its probability using the full chain rule.</strong></p><div class=\"given\"><h4>Given</h4><p>Three conditional factors are given, including the full two-word history for tea. No end probability is requested.</p><h4>To find</h4><p>P(I, like, tea).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/51a05236a3c51a81.svg\" alt=\"P(I,like,tea)=P(I)P(like\\mid I)P(tea\\mid I,like)\" style=\"width:45.404ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The chain rule supplies one factor per word in the specified sequence.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the three supplied factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6ed38d660fa17e1d.svg\" alt=\"P=0.2\\times0.5\\times0.4\" style=\"width:18.922ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply the first two</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5574a2d8fcf3abb3.svg\" alt=\"0.2\\times0.5=0.1\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Multiply by the third</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d17f98269b12c97d.svg\" alt=\"0.1\\times0.4=0.04\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The sentence probability is 0.04.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A bigram model gives P(I|&lt;s&gt;)=0.5, P(like|I)=0.6, P(tea|like)=0.25 and P(&lt;/s&gt;|tea)=0.8. Find the full sentence probability.</strong></p><div class=\"given\"><h4>Given</h4><p>All four conditional probabilities, including the end event, are supplied.</p><h4>To find</h4><p>P(I like tea &lt;/s&gt; | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7363c7dc5cab171f.svg\" alt=\"P=P(I\\mid\\langle s\\rangle)P(like\\mid I)P(tea\\mid like)P(\\langle/s\\rangle\\mid tea)\" style=\"width:48.662ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Under the bigram assumption, every factor uses one preceding token.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the factors in sentence order</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e3c41e56b889ac9f.svg\" alt=\"P=0.5\\times0.6\\times0.25\\times0.8\" style=\"width:25.71ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Start and second word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/389d6af9cfa7b052.svg\" alt=\"0.5\\times0.6=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Third word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bdfb9291e6974dcf.svg\" alt=\"0.3\\times0.25=0.075\" style=\"width:17.851ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/98c43f5a93d1dcf9.svg\" alt=\"0.075\\times0.8=0.06\" style=\"width:17.851ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The complete sentence probability is 0.06.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Sequence probability = saare required transitions ka product.</p></section><p><strong>Typical 2-mark answer.</strong> An n-gram language model predicts a word from its previous n−1 words using a Markov approximation. For example, a bigram model uses P(wᵢ | wᵢ₋₁). It estimates these probabilities from corpus counts and multiplies the appropriate factors to score a sentence.</p>"}]},{"id":"m2-count-to-probability","title":"From a corpus to sentence probabilities","unit":3,"scope":"Unit 3, pages 97–120 and appendix","sections":[{"id":"unigram-estimation","title":"Unigram estimation and complete worked examples","html":"<p><strong>Maximum likelihood estimation (MLE)</strong> chooses probabilities equal to observed relative frequencies. In a unigram model, every word is predicted independently of its surrounding words. If a word occurs c times in N training tokens, its estimate is c/N. To score m specified words, multiply their m unigram probabilities.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/151df11dd9b4e4ca.svg\" alt=\"P_{\\mathrm{MLE}}(w)=\\frac{C(w)}{N}\\qquad P(w_1,\\ldots,w_m)\\approx\\prod_{i=1}^{m}P(w_i)\" style=\"width:48.638ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Choose a tokenization convention before counting. Lowercasing, punctuation handling and boundary markers can change the vocabulary and counts. Never count words with one convention and form the denominator with another. A unigram model gives the same product to rearrangements of the same word multiset; that is one of its limitations.</p><section class=\"example\"><p class=\"question\"><strong>Question. Train an unpadded, case-insensitive unigram model on “I like tea” and “I like coffee”. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Training sentences: I like tea; I like coffee. Use lowercase words; exclude punctuation and sentence boundaries.</p><h4>To find</h4><p>The vocabulary, word probabilities and test-sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92c670591895f879.svg\" alt=\"P(w)=C(w)/N,\\qquad P(I\\ like\\ tea)=P(I)P(like)P(tea)\" style=\"width:55.644ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The unigram approximation ignores order and uses total token count for every denominator.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count every training token</h5><p>Each sentence contains three words, so N = 3+3 = 6.</p></div><div class=\"step\"><h5>Step 2. Count types and frequencies</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th><th>MLE probability</th></tr></thead><tbody><tr><td>i</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>like</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>tea</td><td>1</td><td>1/6</td></tr><tr><td>coffee</td><td>1</td><td>1/6</td></tr></tbody></table></div><p>Vocabulary size V = 4.</p></div><div class=\"step\"><h5>Step 3. Write one factor per test word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8823227ec8a6a1a.svg\" alt=\"P=\\frac{2}{6}\\times\\frac{2}{6}\\times\\frac{1}{6}\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply the fractions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3a5496aef6f0526.svg\" alt=\"P=\\frac{4}{216}=\\frac{1}{54}\\approx0.018519\" style=\"width:26.945ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The unigram sentence probability is approximately 0.018519.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains counts a: 4, b: 3 and c: 1. Find the unigram probability of “a b a”.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=4, C(b)=3, C(c)=1. No boundary markers.</p><h4>To find</h4><p>P(a b a).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/97d27988b1cff86a.svg\" alt=\"P(a\\,b\\,a)=P(a)P(b)P(a)\" style=\"width:24.338ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A repeated test word contributes a probability factor at every occurrence; do not include it just once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/489d9ca17e456579.svg\" alt=\"N=4+3+1=8\" style=\"width:18.1ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the required probabilities</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c986ed6d03f3c421.svg\" alt=\"P(a)=4/8=1/2,\\qquad P(b)=3/8\" style=\"width:33.849ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Use both occurrences of a</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a46bf6ca459b44e0.svg\" alt=\"P=\\frac12\\times\\frac38\\times\\frac12\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Simplify</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c91fa325852e9b20.svg\" alt=\"P=\\frac3{32}=0.09375\" style=\"width:18.407ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(a b a) = 0.09375.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Repeated word ka probability bhi repeat multiply hoga.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. An unsmoothed unigram model is trained on “red blue red”. Find the probability of “red green”.</strong></p><div class=\"given\"><h4>Given</h4><p>N=3. Counts: red=2, blue=1, green=0. The test contains red and green.</p><h4>To find</h4><p>The unsmoothed test probability and the reason for its value.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ad862e46bb0787a.svg\" alt=\"P(red\\ green)=P(red)P(green)\" style=\"width:31.594ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>MLE assigns zero to an unseen outcome. Smoothing is needed if an unseen in-vocabulary item must receive probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Estimate red</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4e4dbe2f8003f7d7.svg\" alt=\"P(red)=2/3\" style=\"width:13.121ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the unseen word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5ae67848fc965273.svg\" alt=\"P(green)=0/3=0\" style=\"width:19.584ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c86e2ed24bee6fb.svg\" alt=\"(2/3)\\times0=0\" style=\"width:13.199ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed probability = 0. This reflects missing training evidence, not proof that the phrase is impossible.</div></section>"},{"id":"bigram-count-table","title":"Bigram counts: build the table before multiplying","html":"<p>A <strong>bigram probability table</strong> uses the previous word as its row and the next word as its column. Divide each cell count by its row's total outgoing count. With one end marker on every sentence, each ordinary training word has a continuation, so its outgoing count equals its token frequency. Do not create a bigram that crosses from one sentence into the next.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/16ee67bf50a203c3.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{\\sum_{v\\in V}C(h,v)}=\\frac{C(h,w)}{C(h)}\" style=\"width:36.615ex;height:5.619ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"flow\"><div class=\"node\">Add boundaries to each sentence separately</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">List adjacent pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Count repeated pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Divide each row by its total</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Follow the test sentence through the table</div></div><section class=\"example\"><p class=\"question\"><strong>Question. Train a bigram model on “I like tea”, “I like coffee” and “you like tea”. Use one start and one end marker. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: &lt;s&gt; I like tea &lt;/s&gt;; &lt;s&gt; I like coffee &lt;/s&gt;; &lt;s&gt; you like tea &lt;/s&gt;. Preserve these tokens.</p><h4>To find</h4><p>All nonzero bigram estimates and the test probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every sentence starts and ends independently. Four probability factors are required for the three test words plus end.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. List the training pairs</h5><p>Sentence 1: (&lt;s&gt;,I), (I,like), (like,tea), (tea,&lt;/s&gt;).<br>Sentence 2: (&lt;s&gt;,I), (I,like), (like,coffee), (coffee,&lt;/s&gt;).<br>Sentence 3: (&lt;s&gt;,you), (you,like), (like,tea), (tea,&lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 2. Create the nonzero count table</h5><div class=\"table-wrap\"><table><thead><tr><th>History → next</th><th>Pair count</th><th>History count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → I</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>&lt;s&gt; → you</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>I → like</td><td>2</td><td>2</td><td>1</td></tr><tr><td>you → like</td><td>1</td><td>1</td><td>1</td></tr><tr><td>like → tea</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>like → coffee</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>tea → &lt;/s&gt;</td><td>2</td><td>2</td><td>1</td></tr><tr><td>coffee → &lt;/s&gt;</td><td>1</td><td>1</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the test path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7363c7dc5cab171f.svg\" alt=\"P=P(I\\mid\\langle s\\rangle)P(like\\mid I)P(tea\\mid like)P(\\langle/s\\rangle\\mid tea)\" style=\"width:48.662ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Substitute each matching row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2c319bafd1386357.svg\" alt=\"P=\\frac23\\times1\\times\\frac23\\times1\" style=\"width:19.529ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d5107e2738f0177f.svg\" alt=\"P=\\frac49\\approx0.444444\" style=\"width:18.407ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(I like tea) = 4/9 ≈ 0.444444.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using the same three-sentence corpus given here—“I like tea”, “I like coffee”, “you like tea”—find the bigram probabilities of “you like coffee” and “tea like I”. Include boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus with one start/end marker per sentence. Counts: start→you=1/3; you→like=1; like→coffee=1/3; coffee→end=1. No training sentence starts with tea.</p><h4>To find</h4><p>The two test probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92e554afbd43b835.svg\" alt=\"P(\\text{sentence})=\\prod P(\\text{next token}\\mid\\text{previous token})\" style=\"width:48.054ex;height:3.167ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A model can assign a nonzero probability to a sentence it never saw if all of its local bigrams were seen.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score you like coffee</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bccffa0a6f23966a.svg\" alt=\"P=\\frac13\\times1\\times\\frac13\\times1=\\frac19\\approx0.111111\" style=\"width:36.238ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Inspect tea like I</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c17c8267050aec19.svg\" alt=\"P(tea\\mid\\langle s\\rangle)=0/3=0\" style=\"width:21.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply the zero factor</h5><p>The full product is zero, regardless of the remaining factors.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(you like coffee) = 1/9; P(tea like I) = 0. A new sentence is not necessarily a zero-probability sentence.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Obtain the unsmoothed bigram probability of “students are from Vellore” from this corpus: “I am from Vellore”; “I am a teacher”; “students are good and are from various cities”; “students from Vellore do engineering”. Use sentence boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Four training sentences, each padded with one &lt;s&gt; and &lt;/s&gt;. Test sequence: &lt;s&gt; students are from Vellore &lt;/s&gt;.</p><h4>To find</h4><p>The five required conditional probabilities and their product.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Count all occurrences in the entire corpus. In particular, are occurs twice inside the third sentence, and Vellore is followed by end once and do once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the histories</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Occurrences with continuation</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>4</td></tr><tr><td>students</td><td>2</td></tr><tr><td>are</td><td>2</td></tr><tr><td>from</td><td>3</td></tr><tr><td>Vellore</td><td>2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count the required pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Required pair</th><th>Count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; students</td><td>2</td><td>2/4</td></tr><tr><td>students are</td><td>1</td><td>1/2</td></tr><tr><td>are from</td><td>1</td><td>1/2</td></tr><tr><td>from Vellore</td><td>2</td><td>2/3</td></tr><tr><td>Vellore &lt;/s&gt;</td><td>1</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the complete product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6420e3d4b5982a43.svg\" alt=\"P=\\frac24\\times\\frac12\\times\\frac12\\times\\frac23\\times\\frac12\" style=\"width:26.413ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply progressively</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6c021a4ae77c326e.svg\" alt=\"\\frac24\\times\\frac12=\\frac14,\\quad \\frac14\\times\\frac12=\\frac18\" style=\"width:27.594ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e9b12d6d627642db.svg\" alt=\"\\frac18\\times\\frac23=\\frac1{12},\\quad \\frac1{12}\\times\\frac12=\\frac1{24}\" style=\"width:30.988ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 1/24 ≈ 0.0416667.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Same sentence mein word do baar aaye toh count bhi do.</p></section>"},{"id":"trigram-estimation","title":"Trigram estimates: two-word history, not two denominators","html":"<p>A trigram model predicts the next word from the two preceding words. The numerator is the count of a triple. The denominator is the count of its two-word history with an available next token. Do not multiply two independent bigram probabilities and call that a trigram probability.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ca97d5e894e09b1.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=\\frac{C(w_{i-2},w_{i-1},w_i)}{C(w_{i-2},w_{i-1})}\" style=\"width:38.191ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains 12 occurrences of “prime minister”. Eight are followed by “of”, three by “said”, and one by “visited”. Estimate the three trigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>History h = (prime, minister). Count of this history = 12. Triple counts for of, said, visited are 8, 3, 1.</p><h4>To find</h4><p>The conditional distribution of the next word.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8ba899fcd0d6112.svg\" alt=\"P(w\\mid prime,minister)=C(prime,minister,w)/12\" style=\"width:51.168ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All three candidates share one two-word history, so they share denominator 12.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate of</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69d53078e2ba6e25.svg\" alt=\"P(of\\mid prime,minister)=8/12=2/3\" style=\"width:37.483ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate said</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a742b6dcdf3bfef5.svg\" alt=\"P(said\\mid prime,minister)=3/12=1/4\" style=\"width:39.356ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate visited</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/170c0f0886c42082.svg\" alt=\"P(visited\\mid prime,minister)=1/12\" style=\"width:35.497ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Confirm normalization</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8a19e47f93490280.svg\" alt=\"8/12+3/12+1/12=12/12=1\" style=\"width:31.928ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The probabilities are 2/3, 1/4 and 1/12.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Train a trigram model on “I like tea”, “I like coffee” and “you like tea”. Use two start markers and one end marker. Score “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences. Padded first sentence is &lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;; pad the other two in the same way.</p><h4>To find</h4><p>Four trigram prediction probabilities and the sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0b4f2f8e9cf3fc17.svg\" alt=\"P=\\prod_i P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:25.504ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each prediction uses a two-token context; the two start markers supply the first history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the first-word event</h5><p>The history (&lt;s&gt;,&lt;s&gt;) occurs three times, and two are followed by I.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/88a613de059c9165.svg\" alt=\"P(I\\mid\\langle s\\rangle,\\langle s\\rangle)=2/3\" style=\"width:19.545ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Count the second-word event</h5><p>(&lt;s&gt;,I) occurs twice; both are followed by like.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99919b0a3770ff5c.svg\" alt=\"P(like\\mid\\langle s\\rangle,I)=2/2=1\" style=\"width:24.56ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count the third-word event</h5><p>(I,like) occurs twice; one is followed by tea.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/22c4756e3a5a9146.svg\" alt=\"P(tea\\mid I,like)=1/2\" style=\"width:20.658ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Count the end event</h5><p>(like,tea) occurs twice; both are followed by end.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/221a8d0201199a49.svg\" alt=\"P(\\langle/s\\rangle\\mid like,tea)=2/2=1\" style=\"width:27.618ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply all four</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15f0c8914a694355.svg\" alt=\"P=\\frac23\\times1\\times\\frac12\\times1=\\frac13\" style=\"width:24.673ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Trigram P(I like tea) = 1/3. It differs from the bigram estimate because the context and denominator changed.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A trigram model supplies P(we|&lt;s&gt;,&lt;s&gt;)=0.4, P(study|&lt;s&gt;,we)=0.5, P(NLP|we,study)=0.8 and P(&lt;/s&gt;|study,NLP)=0.25. Score “we study NLP”.</strong></p><div class=\"given\"><h4>Given</h4><p>Four trigram conditional factors. The end marker is included.</p><h4>To find</h4><p>The complete sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f7ce4e6b173900c6.svg\" alt=\"P=P(we\\mid s,s)P(study\\mid s,we)P(NLP\\mid we,study)P(end\\mid study,NLP)\" style=\"width:71.784ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use each supplied two-word history exactly; do not swap its word order.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the values</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7e1f0a0c2ffc974b.svg\" alt=\"P=0.4\\times0.5\\times0.8\\times0.25\" style=\"width:25.71ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply the first pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4528e6e7a97bb8e8.svg\" alt=\"0.4\\times0.5=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Include NLP</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd4748e690ad03d9.svg\" alt=\"0.2\\times0.8=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Include the end</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5bbc9c588899b389.svg\" alt=\"0.16\\times0.25=0.04\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 0.04.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Trigram: teen-word count upar, pehle do-word count neeche.</p></section><p><strong>Why larger n is not automatically better.</strong> More context can capture local order more precisely, but each longer history occurs less often. Parameter count, storage and sparsity grow. A model trained on Shakespeare may assign poor probabilities to financial news because training and test distributions differ. Keep a held-out test set; do not evaluate only on memorized training sentences.</p>"},{"id":"class-count-table-questions","title":"Class-style count-table questions and partial-table traps","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Train a bigram model on “I am Sam”, “Sam I am”, and “I do not like green eggs and ham”. Include sentence boundaries. Find P(I|&lt;s&gt;), P(Sam|&lt;s&gt;), P(am|I), P(do|I), P(Sam|am) and P(&lt;/s&gt;|Sam).</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences; one &lt;s&gt; and &lt;/s&gt; per sentence; preserve capital I and Sam.</p><h4>To find</h4><p>Six bigram estimates.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Count all matching histories, including repeated words in different sentence positions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the histories</h5><p>START occurs 3 times; I occurs 3 times; am occurs 2 times; Sam occurs 2 times.</p></div><div class=\"step\"><h5>Step 2. Count the requested pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Pair count</th><th>History count</th></tr></thead><tbody><tr><td>START I</td><td>2</td><td>3</td></tr><tr><td>START Sam</td><td>1</td><td>3</td></tr><tr><td>I am</td><td>2</td><td>3</td></tr><tr><td>I do</td><td>1</td><td>3</td></tr><tr><td>am Sam</td><td>1</td><td>2</td></tr><tr><td>Sam END</td><td>1</td><td>2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Divide pair by history</h5><div class=\"table-wrap\"><table><thead><tr><th>Requested probability</th><th>Result</th></tr></thead><tbody><tr><td>P(I|START)</td><td>2/3</td></tr><tr><td>P(Sam|START)</td><td>1/3</td></tr><tr><td>P(am|I)</td><td>2/3</td></tr><tr><td>P(do|I)</td><td>1/3</td></tr><tr><td>P(Sam|am)</td><td>1/2</td></tr><tr><td>P(END|Sam)</td><td>1/2</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> The six estimates are 2/3,1/3,2/3,1/3,1/2,1/2 in the requested order.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A bigram table gives P(i|&lt;s&gt;)=0.25, P(want|i)=0.33, P(english|want)=0.0011, P(food|english)=0.5 and P(&lt;/s&gt;|food)=0.68. Score “i want english food” using these supplied rounded values.</strong></p><div class=\"given\"><h4>Given</h4><p>All five transition probabilities are explicitly given. Include the end marker.</p><h4>To find</h4><p>The sentence probability from the supplied table.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c573bb6be6835221.svg\" alt=\"P=P(i\\mid START)P(want\\mid i)P(english\\mid want)P(food\\mid english)P(END\\mid food)\" style=\"width:80.505ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A table-based question uses the provided values; slight differences can arise if exact corpus fractions are used instead.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. First two events</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/536a06c85da5d9e1.svg\" alt=\"0.25(0.33)=0.0825\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add english</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cc8c5266050b1825.svg\" alt=\"0.0825(0.0011)=0.00009075\" style=\"width:28.157ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add food</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/55d45996875f92e6.svg\" alt=\"0.00009075(0.5)=0.000045375\" style=\"width:30.42ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69c2e9e932b1b959.svg\" alt=\"0.000045375(0.68)=0.000030855\" style=\"width:32.682ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P≈0.000030855 using the supplied rounded probabilities.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A corpus has vocabulary size 1446, C(i)=2533 and C(i,want)=827. Compute the unsmoothed and add-one-smoothed P(want|i). The displayed bigram table contains only eight vocabulary columns.</strong></p><div class=\"given\"><h4>Given</h4><p>Full history count C(i)=2533; pair count 827; complete vocabulary size V=1446. The displayed table is only a subset.</p><h4>To find</h4><p>Both conditional probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ccfa3c73248a102f.svg\" alt=\"P(want\\mid i)=827/2533,\\qquad P_L(want\\mid i)=\\frac{827+1}{2533+1446}\" style=\"width:56.69ex;height:4.796ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use the supplied full history total. Summing only the eight displayed columns would wrongly ignore all other possible continuations.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate the unsmoothed ratio</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a38462b5efb9f1e3.svg\" alt=\"P=827/2533\\approx0.326490\" style=\"width:25.331ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add one to the pair count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/02a3d76972ac332b.svg\" alt=\"827+1=828\" style=\"width:13.701ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add V to the history count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/56cd165dd5075aa7.svg\" alt=\"2533+1446=3979\" style=\"width:19.357ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ca005fa10935e238.svg\" alt=\"P_L=828/3979\\approx0.208092\" style=\"width:26.361ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed≈0.326490; smoothed≈0.208092.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Partial table ka visible row-sum, full history total nahi hota.</p></section>"}]},{"id":"m2-evaluation-smoothing","title":"Perplexity, log probabilities and smoothing","unit":3,"scope":"Unit 3, pages 121–156","sections":[{"id":"evaluation-perplexity","title":"Perplexity: meaning, formula and four complete examples","html":"<p><strong>Intrinsic evaluation</strong> evaluates a model directly on a held-out test corpus, for example using perplexity. <strong>Extrinsic evaluation</strong> places it inside a downstream application, such as a speech recognizer or translation system, and measures the application's performance. Extrinsic testing is closer to actual use but often slower and more expensive. A lower perplexity is not a guarantee of improvement on every downstream task.</p><p><strong>Perplexity</strong> is the inverse probability of a test sequence, normalized by the number of prediction events. Intuitively, it is the model's effective average number of equally plausible choices. A model that always gives the correct next word probability 1/4 has perplexity 4. Lower is better when the models are tested on the same data, vocabulary, tokenization and boundary convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dab12face5c56858.svg\" alt=\"\\operatorname{PP}(W)=P(W)^{-1/N}=\\sqrt[N]{\\frac1{P(W)}}\" style=\"width:32.663ex;height:6.923ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>W</td><td>The complete test sequence.</td></tr><tr><td>P(W)</td><td>Product of the probabilities assigned to the actual next tokens.</td></tr><tr><td>N</td><td>Number of scored prediction events under the stated convention.</td></tr><tr><td>Exponent −1/N</td><td>Take the reciprocal, then the Nth root.</td></tr></tbody></table></div><p>For calculator entry, use parentheses: P raised to (−1 ÷ N), or (1 ÷ P) raised to (1 ÷ N). Retain several digits in intermediate products. The ordinary start marker is usually given context, not a predicted event; the end marker counts if its probability is included.</p><section class=\"example\"><p class=\"question\"><strong>Question. A model assigns probability 0.0625 to a test sequence containing four scored tokens. Compute its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>P(W)=0.0625=1/16; N=4.</p><h4>To find</h4><p>PP(W).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7873b84adddec337.svg\" alt=\"\\operatorname{PP}(W)=\\left(\\frac1{P(W)}\\right)^{1/N}\" style=\"width:23.594ex;height:6.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The root removes the effect of sequence length; the reciprocal makes lower surprise correspond to lower perplexity.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/31c8e928444ef07c.svg\" alt=\"1/P(W)=1/0.0625=16\" style=\"width:24.937ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the fourth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/560b6664723185b3.svg\" alt=\"\\operatorname{PP}=16^{1/4}\" style=\"width:10.948ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c15dbdf7cfc85ea8.svg\" alt=\"2^4=16\\quad\\Rightarrow\\quad\\operatorname{PP}=2\" style=\"width:22.672ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 2.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Two language models score the same three-token test sequence. Model A gives next-token probabilities 0.5, 0.5, 0.5. Model B gives 0.5, 0.25, 0.25. Compute their perplexities and select the better intrinsic result.</strong></p><div class=\"given\"><h4>Given</h4><p>Same sequence and N=3 for both models. A factors: 0.5,0.5,0.5. B factors: 0.5,0.25,0.25.</p><h4>To find</h4><p>Both sequence probabilities and perplexities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3f347a2e35262f3f.svg\" alt=\"P(W)=\\prod_i p_i,\\qquad\\operatorname{PP}=P(W)^{-1/3}\" style=\"width:35.285ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A fair comparison uses identical test tokens and scoring conventions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate A's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/072e354cb1ef7f5e.svg\" alt=\"P_A=0.5\\times0.5\\times0.5=0.125=1/8\" style=\"width:34.645ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate A's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/eaa36684164a8ec6.svg\" alt=\"\\operatorname{PP}_A=8^{1/3}=2\" style=\"width:15.353ex;height:2.48ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate B's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e4c44123baab46cd.svg\" alt=\"P_B=0.5\\times0.25\\times0.25=0.03125=1/32\" style=\"width:40.315ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate B's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7cad7e80704e87a9.svg\" alt=\"\\operatorname{PP}_B=32^{1/3}\\approx3.174802\" style=\"width:23.915ex;height:2.474ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Compare</h5><p>2 is lower than 3.174802; A places more probability on the observed sequence.</p></div><div class=\"answer\"><strong>Final answer.</strong> Model A is better by perplexity on this test: 2 versus about 3.174802.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The bigram training corpus is “This is a dog”, “This is a cat”, “I love my cat”, “This is my name”. Score “This is my cat”, including an end marker, and compute perplexity using five predicted events.</strong></p><div class=\"given\"><h4>Given</h4><p>Each training sentence has one start and end marker. Test predictions: This, is, my, cat, &lt;/s&gt;. Thus N=5.</p><h4>To find</h4><p>Bigram sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cdcbde9621e0e24d.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h),\\qquad\\operatorname{PP}=P(W)^{-1/5}\" style=\"width:45.9ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start is given context. Four words plus the end marker produce five probability factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the required transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Transition</th><th>Pair count / history count</th></tr></thead><tbody><tr><td>&lt;s&gt;→This</td><td>3/4</td></tr><tr><td>This→is</td><td>3/3</td></tr><tr><td>is→my</td><td>1/3</td></tr><tr><td>my→cat</td><td>1/2</td></tr><tr><td>cat→&lt;/s&gt;</td><td>2/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Form the product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9c8a03a484dfb763.svg\" alt=\"P=\\frac34\\times1\\times\\frac13\\times\\frac12\\times1=\\frac18\" style=\"width:29.565ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/063b3931740c7830.svg\" alt=\"1/P=8\" style=\"width:8.11ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c0fbb6bb85c1b79f.svg\" alt=\"\\operatorname{PP}=8^{1/5}\\approx1.515717\" style=\"width:21.382ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(W)=1/8 and perplexity≈1.515717 using five predicted events.</div></section><p><strong>If the question explicitly states N = 6:</strong> use that supplied convention and report PP = 8<sup>1/6</sup> ≈ 1.414214. The class slide counts both boundary markers in N. Write the chosen N beside the formula; do not silently switch between 5 and 6. Also, This occurs three times and is follows it three times, so P(is|This)=3/3, not 3/4.</p><section class=\"example\"><p class=\"question\"><strong>Question. A uniform model assigns probability 1/10 to each actual next word in a five-token test. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Five scored tokens, each with assigned probability 0.1. N=5.</p><h4>To find</h4><p>The sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/245311d6fb2b9841.svg\" alt=\"P(W)=(1/10)^5,\\qquad \\operatorname{PP}=P(W)^{-1/5}\" style=\"width:37.412ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Uniform equal probabilities make the effective number of choices especially clear.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Multiply the five factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dbea309801bb43da.svg\" alt=\"P(W)=0.1^5=0.00001=10^{-5}\" style=\"width:30.672ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Invert</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a7f36a9eff1f3a2c.svg\" alt=\"1/P(W)=10^5\" style=\"width:14.36ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a14770a9a80e5984.svg\" alt=\"\\operatorname{PP}=(10^5)^{1/5}=10\" style=\"width:18.976ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 10.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Probability high → surprise low → perplexity low.</p></section>"},{"id":"log-probabilities","title":"Log probabilities: replace long products with sums","html":"<p>Probabilities are at most 1, so multiplying many of them produces very small numbers. Computers can round extremely small positive products to zero: <strong>numerical underflow</strong>. Log probabilities convert multiplication into addition and are more stable for long sequences. Natural logs use base e; log₂ uses base 2. Choose one base consistently.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cbf31ffd35c5c322.svg\" alt=\"\\ln P(W)=\\sum_{i=1}^{N}\\ln p_i\" style=\"width:18.897ex;height:6.74ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab927afa9cd05bef.svg\" alt=\"P(W)=e^{\\ln P(W)},\\qquad \\operatorname{PP}(W)=\\exp\\left(-\\frac1N\\sum_i\\ln p_i\\right)\" style=\"width:51.919ex;height:6.785ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The log of a probability below 1 is negative. A value closer to zero means a larger probability: ln(0.5) ≈ −0.693 is larger than ln(0.1) ≈ −2.303. A zero probability has log −∞; taking logs does not solve the unseen-event problem. Smoothing handles that separate problem.</p><section class=\"example\"><p class=\"question\"><strong>Question. The next-word probabilities are 0.5, 0.25 and 0.5. Calculate the natural log probability, ordinary probability and perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>p₁=0.5; p₂=0.25; p₃=0.5; N=3.</p><h4>To find</h4><p>ln P(W), P(W), and PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9bced9ebe87e44c7.svg\" alt=\"\\ln P=\\sum_i\\ln p_i,\\quad P=e^{\\ln P},\\quad\\operatorname{PP}=e^{-\\ln P/N}\" style=\"width:43.938ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Logarithms preserve products as sums and the exponent converts the result back.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute individual logs</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8fc9ba50109d8156.svg\" alt=\"\\ln0.5\\approx-0.693147,\\quad\\ln0.25\\approx-1.386294\" style=\"width:41.36ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add all three terms</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fcdc8edcec916f1f.svg\" alt=\"\\ln P=-0.693147-1.386294-0.693147\\approx-2.772589\" style=\"width:53.239ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Recover the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b886c03a804cf5a4.svg\" alt=\"P=e^{-2.772589}\\approx0.0625\" style=\"width:22.549ex;height:2.201ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find average negative log probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4d6cc3cf68cb5127.svg\" alt=\"-\\ln P/3\\approx2.772589/3=0.924196\" style=\"width:33.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Exponentiate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d34de424885d00e.svg\" alt=\"\\operatorname{PP}=e^{0.924196}\\approx2.519842\" style=\"width:24.949ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> ln P≈−2.772589, P=0.0625, PP≈2.519842.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A model has a total natural log probability −12 over six scored tokens. Calculate its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>ln P(W)=−12; N=6.</p><h4>To find</h4><p>PP without forming the tiny ordinary probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f166d1cce0943ce3.svg\" alt=\"\\operatorname{PP}=\\exp(-\\ln P(W)/N)\" style=\"width:24.688ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The logarithmic formula directly uses the supplied log score.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Negate the log score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/90abe91c0eba5423.svg\" alt=\"-\\ln P=12\" style=\"width:11.38ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Divide by token count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9d8a38c0a5d6d98a.svg\" alt=\"12/6=2\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply exponential</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d421123292e12a1.svg\" alt=\"\\operatorname{PP}=e^2\\approx7.389056\" style=\"width:19.705ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity≈7.389056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A language model's average negative log₂ probability is 3 bits per token. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Cross-entropy H=3 bits/token. Log base is 2.</p><h4>To find</h4><p>PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50941856f700d45e.svg\" alt=\"\\operatorname{PP}=2^H\" style=\"width:8.838ex;height:2.213ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The inverse operation of log₂ is raising 2 to that power; use e only for natural logs.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the log base</h5><p>Bits mean base 2.</p></div><div class=\"step\"><h5>Step 2. Raise the base to H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ffdeccced5f3a45.svg\" alt=\"\\operatorname{PP}=2^3=8\" style=\"width:12.366ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 8.</div><p class=\"cue\"><strong>Yaad rakho:</strong> ln use kiya toh e se wapas; log₂ use kiya toh 2 se wapas.</p></section>"},{"id":"laplace-basics","title":"Laplace smoothing: why both numerator and denominator change","html":"<p><strong>Smoothing</strong> reallocates some probability mass to events that received zero or unreliable estimates from finite training data. <strong>Laplace, or add-one, smoothing</strong> adds one pseudo-count to every possible next outcome. If there are V possible outcomes, the total added count is V, so adding 1 only to the numerator would produce probabilities that do not sum to 1.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0d44559007b7dea6.svg\" alt=\"P_{\\mathrm{Laplace}}(w)=\\frac{C(w)+1}{N+V}\" style=\"width:23.384ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e38a73cc66cdd3f1.svg\" alt=\"P_{\\mathrm{Laplace}}(w\\mid h)=\\frac{C(h,w)+1}{C(h)+V}\" style=\"width:28.882ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For unigram smoothing, N is the total training token count. For bigram smoothing, C(h) is the count of the particular history. In both cases V is the number of outcomes being predicted, not the number of training sentences and not the number of distinct bigrams. When end is a possible prediction, include it in V; the start marker is usually context only.</p><div class=\"flow\"><div class=\"node\">Observed counts: 3, 1, 0</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Add one to every outcome: 4, 2, 1</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New total: 7</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Smoothed probabilities: 4/7, 2/7, 1/7</div></div><section class=\"example\"><p class=\"question\"><strong>Question. A fixed unigram vocabulary is {a,b,c}. The training counts are 3,1,0. Compute unsmoothed and Laplace-smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=3, C(b)=1, C(c)=0; N=4; V=3.</p><h4>To find</h4><p>The complete distributions.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/80d7161647b260e8.svg\" alt=\"P(w)=C(w)/N,\\qquad P_L(w)=(C(w)+1)/(N+V)\" style=\"width:51.157ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The zero-count c is still in the fixed vocabulary, so it must receive one pseudo-count and contribute to V.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute unsmoothed values</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Unsmoothed</th></tr></thead><tbody><tr><td>a</td><td>3/4 = 0.75</td></tr><tr><td>b</td><td>1/4 = 0.25</td></tr><tr><td>c</td><td>0/4 = 0</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Calculate the new denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1918c0a9ceaec186.svg\" alt=\"N+V=4+3=7\" style=\"width:18.708ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add one to each numerator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/345a4b4f00828435.svg\" alt=\"C(a)+1=4,\\quad C(b)+1=2,\\quad C(c)+1=1\" style=\"width:44.259ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Divide</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Smoothed</th></tr></thead><tbody><tr><td>a</td><td>4/7 ≈ 0.571429</td></tr><tr><td>b</td><td>2/7 ≈ 0.285714</td></tr><tr><td>c</td><td>1/7 ≈ 0.142857</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Confirm the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/172a91eacd7bcf59.svg\" alt=\"4/7+2/7+1/7=1\" style=\"width:19.861ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Smoothed probabilities: a=4/7, b=2/7, c=1/7. Common a loses mass; unseen c gains mass.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. After history I, a corpus records like three times, study once and sleep zero times. The allowed next vocabulary is {like,study,sleep}. Compute all Laplace-smoothed bigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(I,like)=3; C(I,study)=1; C(I,sleep)=0. History count C(I)=4. V=3.</p><h4>To find</h4><p>P_L(like|I), P_L(study|I), P_L(sleep|I).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a1c0980897f9361.svg\" alt=\"P_L(w\\mid I)=\\frac{C(I,w)+1}{C(I)+V}\" style=\"width:24.291ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>This is smoothing within the I row; use its total 4, not the global corpus token count.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the common denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d3c1688373da86b2.svg\" alt=\"C(I)+V=4+3=7\" style=\"width:21.319ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate like</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/848e1d743f230579.svg\" alt=\"P_L(like\\mid I)=(3+1)/7=4/7\" style=\"width:29.682ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate study</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ed5edd3a14936914.svg\" alt=\"P_L(study\\mid I)=(1+1)/7=2/7\" style=\"width:31.452ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate sleep</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e0b14bd8e108207.svg\" alt=\"P_L(sleep\\mid I)=(0+1)/7=1/7\" style=\"width:30.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The row is (4/7, 2/7, 1/7). An unseen bigram is no longer forced to zero.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A fixed vocabulary has five possible next tokens. A history h is unseen in training. What is its add-one probability for each next token?</strong></p><div class=\"given\"><h4>Given</h4><p>C(h)=0; C(h,w)=0 for each outcome; V=5.</p><h4>To find</h4><p>P_L(w|h) for each token.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e1f42d7a9537f57.svg\" alt=\"P_L(w\\mid h)=\\frac{0+1}{0+V}\" style=\"width:18.948ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All outcomes receive equal pseudo-counts because the training data gives no preference for this history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Add the pseudo-count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dd66590db88ae5fa.svg\" alt=\"0+1=1\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Form the denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/190ddc58c7516f91.svg\" alt=\"0+5=5\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Divide and sum</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/39038359834be22e.svg\" alt=\"P_L(w\\mid h)=1/5=0.2,\\qquad5(0.2)=1\" style=\"width:37.08ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Every outcome gets 0.2 under this fixed-vocabulary model.</div></section><p><strong>Vocabulary warning.</strong> Add-one does not automatically define probabilities for every word in the world. Unknown words require a declared vocabulary/UNK convention. If a question supplies V, use that stated V rather than inventing additional tokens.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Add-one: upar +1, neeche +V; bigram mein neeche history ka count.</p>"},{"id":"smoothed-sentence","title":"A complete unseen-bigram question from corpus to final answer","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Consider the corpus “I love to code in Python. I love to learn new things. I code every day.” Obtain the bigram probabilities needed for “I love Python”. Explain the zero-probability issue, then use Laplace smoothing to score it. Treat each sentence separately, preserve case, remove punctuation, and include an end token among predicted outcomes.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences padded with one start/end marker. Distinct words: I, love, to, code, in, Python, learn, new, things, every, day. With &lt;/s&gt;, V=12. Start is context only.</p><h4>To find</h4><p>Unsmoothed and smoothed P(I love Python &lt;/s&gt; | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a627bcb8a0b3808.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{C(h)},\\qquad P_L(w\\mid h)=\\frac{C(h,w)+1}{C(h)+12}\" style=\"width:49.838ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The test contains an unseen transition love→Python. Smoothing assigns probability to that transition and renormalizes every required history row.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the contexts</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>3</td></tr><tr><td>I</td><td>3</td></tr><tr><td>love</td><td>2</td></tr><tr><td>Python</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count each required pair</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt; I</td><td>3</td></tr><tr><td>I love</td><td>2</td></tr><tr><td>love Python</td><td>0</td></tr><tr><td>Python &lt;/s&gt;</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Compute the unsmoothed product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/420a50ccd335ade1.svg\" alt=\"P=\\frac33\\times\\frac23\\times\\frac02\\times\\frac11=0\" style=\"width:25.668ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both words love and Python were seen, but their adjacent pair was not. This is an unseen bigram, not an unknown-word case.</p></div><div class=\"step\"><h5>Step 4. Smooth the first event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f16fc85077f5670b.svg\" alt=\"P_L(I\\mid\\langle s\\rangle)=\\frac{3+1}{3+12}=\\frac4{15}\" style=\"width:26.784ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Smooth the second event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a94897ddface7219.svg\" alt=\"P_L(love\\mid I)=\\frac{2+1}{3+12}=\\frac3{15}\" style=\"width:27.886ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Smooth the unseen event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f023b28c09df9a1a.svg\" alt=\"P_L(Python\\mid love)=\\frac{0+1}{2+12}=\\frac1{14}\" style=\"width:34.128ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 7. Smooth the end event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cfdc24dda127984e.svg\" alt=\"P_L(\\langle/s\\rangle\\mid Python)=\\frac{1+1}{1+12}=\\frac2{13}\" style=\"width:34.158ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 8. Multiply the smoothed factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8b4c9f0eec18e2b4.svg\" alt=\"P_L=\\frac4{15}\\times\\frac3{15}\\times\\frac1{14}\\times\\frac2{13}\" style=\"width:27.076ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be31ee9de701fcab.svg\" alt=\"P_L=\\frac{24}{40950}=\\frac4{6825}\\approx0.000586081\" style=\"width:35.894ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed P=0. With the stated V=12 and boundaries, Laplace-smoothed P≈0.000586081.</div></section><p>If an exam states a different convention—for example excluding boundary tokens from the entire calculation—recompute both V and the set of probability factors consistently. Do not combine a boundary-aware numerator with a boundary-free denominator.</p>"},{"id":"adjusted-count-discount","title":"Adjusted counts and relative discounting","html":"<p>The slides also express smoothing through an <strong>adjusted count</strong> c*. Instead of writing the smoothed probability with denominator N+V, they rescale its numerator so the denominator can remain N. Algebraically these are equivalent:</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/70d92382a6cc1e9c.svg\" alt=\"c^*=(c+1)\\frac{N}{N+V},\\qquad P_L(w)=\\frac{c^*}{N}\" style=\"width:36.794ex;height:4.832ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6597274c03aa7f00.svg\" alt=\"d=\\frac{c^*}{c}\\quad(c&gt;0)\" style=\"width:16.307ex;height:4.672ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The relative discount d compares adjusted and original counts. It is undefined when c=0 because division by zero is undefined. Add-one smoothing moves the distribution toward uniformity: frequent events are reduced, but some rare seen events may increase. It is not correct to claim that every nonzero count must decrease under Laplace smoothing.</p><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, a word has original count c=10. Find its adjusted count, smoothed probability and relative discount.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=10.</p><h4>To find</h4><p>c*, P_L and d.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/63cfdcd2de177903.svg\" alt=\"c^*=(c+1)N/(N+V),\\quad P_L=c^*/N,\\quad d=c^*/c\" style=\"width:48.699ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>These expressions rewrite add-one smoothing without changing its probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the new total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/749a0f4867a4b3db.svg\" alt=\"N+V=20+5=25\" style=\"width:20.971ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Find the adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/866c6ee174b3d21b.svg\" alt=\"c^*=(10+1)\\frac{20}{25}=11(0.8)=8.8\" style=\"width:32.002ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Find the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5fb26f5353edaa9.svg\" alt=\"P_L=8.8/20=0.44\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find the relative discount</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be28007774d8c2d5.svg\" alt=\"d=8.8/10=0.88\" style=\"width:17.518ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=8.8, P_L=0.44, d=0.88. The original probability 0.5 is reduced.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Under N=20, V=5, a rare word occurs once. Compute its adjusted count and compare the original and smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=1.</p><h4>To find</h4><p>c*, original P and smoothed P_L.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/509478366d59c2ce.svg\" alt=\"c^*=(c+1)N/(N+V)\" style=\"width:23.036ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same smoothing rule may increase a rare event's probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Original probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3fc24a506f12b888.svg\" alt=\"P=1/20=0.05\" style=\"width:16.281ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/13803fe6f5045ef1.svg\" alt=\"c^*=(1+1)(20/25)=1.6\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0fd3e6bc0e9d2f40.svg\" alt=\"P_L=1.6/20=0.08\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=1.6 and P_L=0.08, which exceeds the original 0.05.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, an in-vocabulary word has count zero. Find its adjusted count and smoothed probability. Can a relative discount be calculated?</strong></p><div class=\"given\"><h4>Given</h4><p>c=0; N=20; V=5.</p><h4>To find</h4><p>c*, P_L and whether d exists.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dc6d3ca40a034b28.svg\" alt=\"c^*=(c+1)N/(N+V),\\qquad P_L=c^*/N\" style=\"width:39.422ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The pseudo-count creates positive mass for the unseen vocabulary item.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e073545bb6c88eb4.svg\" alt=\"c^*=(0+1)(20/25)=0.8\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5e8f939253d4321b.svg\" alt=\"P_L=0.8/20=0.04\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Relative discount</h5><p>d would be 0.8/0. That is undefined, so do not report a finite discount.</p></div><div class=\"answer\"><strong>Final answer.</strong> c*=0.8 and P_L=0.04; relative discount is undefined for c=0.</div></section>"},{"id":"class-perplexity-characters","title":"Character-model perplexity: keep exact probabilities","html":"<section class=\"example\"><p class=\"question\"><strong>Question. A unigram character model gives P(A)=0.25, P(B)=0.50, P(C)=0.25. Find the perplexity of AAA and ABC. Then find both perplexities when the three characters are equally likely.</strong></p><div class=\"given\"><h4>Given</h4><p>Each test string contains 3 scored characters, so N=3. Initial distribution 0.25,0.50,0.25; comparison distribution 1/3,1/3,1/3.</p><h4>To find</h4><p>Both sequence probabilities and perplexities under each distribution.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e9f6c28675d3dd90.svg\" alt=\"P(c_1c_2c_3)=P(c_1)P(c_2)P(c_3),\\qquad PP=P(W)^{-1/3}\" style=\"width:50.267ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Characters, not words, are the model's prediction units in this question. Use exact 1/3 for uniform probabilities, rather than rounded 0.33.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score AAA</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/227b8a572c539a9c.svg\" alt=\"P(AAA)=0.25^3=\\frac1{64}=0.015625\" style=\"width:34.417ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Find AAA perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ced7ad162e418ee6.svg\" alt=\"PP(AAA)=64^{1/3}=4\" style=\"width:22.264ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Score ABC</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9b87b238251977b6.svg\" alt=\"P(ABC)=0.25(0.5)(0.25)=\\frac1{32}=0.03125\" style=\"width:42.775ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find ABC perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f1633e91cb3db49f.svg\" alt=\"PP(ABC)=32^{1/3}\\approx3.174802\" style=\"width:29.723ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Change to an exactly uniform model</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6366e364bc9f8ccd.svg\" alt=\"P(AAA)=P(ABC)=(1/3)^3=1/27\" style=\"width:36.86ex;height:2.564ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Find both uniform-model perplexities</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c2e12c89ac512fd3.svg\" alt=\"PP=27^{1/3}=3\" style=\"width:15.414ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Original model: AAA→4, ABC→3.174802. Uniform model: both→3. These values follow the stated formulas without intermediate rounding.</div></section>"}]},{"id":"m2-pos-tagging","title":"POS tagging and its learning approaches","unit":4,"scope":"Unit 4, pages 3–46","sections":[{"id":"word-classes-pos","title":"Parts of speech and contextual ambiguity","html":"<p><strong>Part-of-speech (POS) tagging</strong> assigns a grammatical category to every word token in context, such as noun, verb, adjective or determiner. It is a sequence-labeling task: the input is a sequence of words, and the output is a tag for each word. A tag describes the word's role in this sentence, not its meaning in every possible sentence.</p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Role</th><th>Example in context</th></tr></thead><tbody><tr><td>NN / NNS</td><td>Singular / plural common noun</td><td>a book / two books</td></tr><tr><td>NNP</td><td>Proper noun</td><td>Mary, Mumbai</td></tr><tr><td>VB / VBD / VBZ</td><td>Base / past / third-person singular verb</td><td>read / read / reads</td></tr><tr><td>JJ</td><td>Adjective</td><td>the red book</td></tr><tr><td>RB</td><td>Adverb</td><td>runs quickly</td></tr><tr><td>DT</td><td>Determiner</td><td>the, a, this</td></tr><tr><td>IN</td><td>Preposition or subordinating conjunction</td><td>on the table</td></tr><tr><td>PRP</td><td>Personal pronoun</td><td>she, they</td></tr><tr><td>MD</td><td>Modal auxiliary</td><td>can, will, should</td></tr></tbody></table></div><p><strong>Open classes</strong> readily accept new content words: nouns, verbs, adjectives and adverbs. Examples include chatbot and livestream. <strong>Closed classes</strong> contain comparatively stable grammatical/function words: determiners, pronouns, prepositions and conjunctions. These are tendencies, not a claim that language never changes.</p><div class=\"flow\"><div class=\"node\">Input: Book that flight</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context: an imperative request</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Output: Book/VB that/DT flight/NN</div></div><p>Compare “hand me that <strong>book</strong>”: book is a noun here. Similarly, “I <strong>can</strong> swim” has can/MD, while “the <strong>can</strong> is empty” has can/NN. The spelling stays the same; neighboring words and sentence structure change the correct tag. This is <strong>POS ambiguity</strong>.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged interpretation</th><th>Reason</th></tr></thead><tbody><tr><td>They watch birds.</td><td>They/PRP watch/VBP birds/NNS</td><td>watch is the action.</td></tr><tr><td>The watch stopped.</td><td>The/DT watch/NN stopped/VBD</td><td>watch is the object that stopped.</td></tr><tr><td>She has a light bag.</td><td>She/PRP has/VBZ a/DT light/JJ bag/NN</td><td>light describes bag.</td></tr><tr><td>Light the lamp.</td><td>Light/VB the/DT lamp/NN</td><td>Light is an imperative verb.</td></tr></tbody></table></div><p>POS tags support parsing, named entity recognition, question answering, sentiment analysis and word-sense disambiguation. They do not by themselves identify every entity or fully resolve meaning.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka naam same ho sakta hai; sentence mein uska kaam tag decide karta hai.</p>"},{"id":"tagger-methods","title":"Lexical, rule-based, stochastic, Brill and neural taggers","html":"<p><strong>A lexical baseline</strong> gives each known word its most frequent training tag. It is simple and often useful, but ignores context. A <strong>rule-based tagger</strong> uses a lexicon of possible tags plus manually designed contextual or morphological rules to resolve ambiguity. For example, after a determiner, a noun reading of “can” may be preferred in “the can”.</p><p>Rules are usually heuristics with exceptions. “A red car” shows that the word immediately after an article is not always a noun. The suffix -ed does not make “red” a past-tense verb. A robust rule system uses multiple linguistic constraints instead of treating such shortcuts as universal laws.</p><div class=\"table-wrap\"><table><thead><tr><th>Method</th><th>How it chooses tags</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>Most frequent / lexical</td><td>Most common training tag for the word</td><td>Simple baseline</td><td>Misses contextual changes and unknown words</td></tr><tr><td>Rule-based</td><td>Lexicon plus handwritten rules</td><td>Readable, controllable linguistic decisions</td><td>Expert effort; rules may conflict or need updates</td></tr><tr><td>Stochastic</td><td>Scores tag sequences using estimated probabilities</td><td>Uses corpus evidence and context</td><td>Sparse/unseen events; depends on training domain</td></tr><tr><td>Transformation-based / Brill</td><td>Start with baseline, then apply learned correction rules</td><td>Readable learned corrections</td><td>Needs tagged training data and suitable rule templates</td></tr><tr><td>Neural</td><td>Learns contextual representations and sequence predictions</td><td>Can exploit richer context</td><td>Needs training resources and data; less directly interpretable</td></tr></tbody></table></div><p><strong>Transformation-based error-driven learning (Brill tagging)</strong> combines a simple starting assignment with learned correction rules. First tag the training corpus with a baseline. Compare against the gold tags. Generate candidate correction rules from templates, such as “change MD to NN after DT”. Apply the rule that fixes the most errors net of newly introduced errors; repeat until further improvement is too small. At test time apply the learned ordered rule list.</p><div class=\"flow\"><div class=\"node\">Baseline: The/DT can/MD was/VBD crushed/VBN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context rule: change can from MD to NN after DT</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Result: The/DT can/NN was/VBD crushed/VBN</div></div><p><strong>Rule-based versus Brill:</strong> a purely rule-based system depends on linguists specifying its rules; a Brill tagger learns which transformations improve a labeled corpus. A <strong>stochastic tagger</strong> such as an HMM finds a high-probability tag sequence using transition and emission probabilities. CRFs and neural sequence taggers are other learning approaches; they do not have to make the same HMM independence assumptions.</p><p><strong>Exam-ready answer.</strong> POS tagging assigns a grammatical tag to each word in context. A rule-based tagger uses lexicons and linguistic rules, whereas a stochastic tagger chooses tags through probabilities estimated from a corpus. For example, can is MD in “I can swim” but NN in “the can”; context resolves the ambiguity.</p>"},{"id":"generative-discriminative","title":"Generative versus discriminative models and Bayes' rule","html":"<p>Let x be the observed words and y be the desired tag sequence. A <strong>generative model</strong> describes their joint distribution P(x,y), often as P(y)P(x|y). A <strong>discriminative model</strong> learns P(y|x) directly or learns a decision boundary that separates possible labels. Both kinds can be trained with labeled data; “generative” does not mean “always unsupervised”.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/279bb8404538a591.svg\" alt=\"P(y\\mid x)=\\frac{P(x\\mid y)P(y)}{P(x)}\" style=\"width:24.076ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Quantity</th><th>Meaning</th><th>POS interpretation</th></tr></thead><tbody><tr><td>P(y)</td><td>Prior</td><td>How plausible is this tag or tag sequence before seeing the words?</td></tr><tr><td>P(x|y)</td><td>Likelihood</td><td>How plausible are these words under that tag sequence?</td></tr><tr><td>P(x)</td><td>Evidence</td><td>Total probability of the observed words across possible labels.</td></tr><tr><td>P(y|x)</td><td>Posterior</td><td>Probability of the tags after seeing the words.</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Generative</th><th>Discriminative</th></tr></thead><tbody><tr><td>Models</td><td>Joint P(x,y), or prior × likelihood</td><td>Conditional P(y|x) or decision boundary</td></tr><tr><td>Classification examples</td><td>Naive Bayes</td><td>Logistic regression, SVM</td></tr><tr><td>Sequence-labeling examples</td><td>HMM</td><td>Linear-chain CRF</td></tr><tr><td>Intuition</td><td>Model how a label could generate the observation</td><td>Model which label fits the observation</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. A token has two possible tags, noun N and verb V. P(N)=0.6, P(V)=0.4, P(book|N)=0.2 and P(book|V)=0.5. Calculate P(N|book) and P(V|book).</strong></p><div class=\"given\"><h4>Given</h4><p>Two tags are exhaustive. Priors: 0.6,0.4. Word likelihoods: 0.2,0.5.</p><h4>To find</h4><p>Normalized posterior probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1b37c73f9aa13957.svg\" alt=\"P(t\\mid w)=\\frac{P(w\\mid t)P(t)}{\\sum_{u}P(w\\mid u)P(u)}\" style=\"width:28.676ex;height:5.573ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Bayes' rule combines prior and likelihood. Normalization is needed to convert scores into posterior probabilities.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate the noun score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bef5ede62cecaa67.svg\" alt=\"0.2\\times0.6=0.12\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the verb score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7510fe35c0e59838.svg\" alt=\"0.5\\times0.4=0.20\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Find the evidence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f24842cc6cea4777.svg\" alt=\"P(book)=0.12+0.20=0.32\" style=\"width:28.671ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Normalize the noun score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/886a6346c0609831.svg\" alt=\"P(N\\mid book)=0.12/0.32=0.375\" style=\"width:32.063ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Normalize the verb score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a4c885afdd1366d5.svg\" alt=\"P(V\\mid book)=0.20/0.32=0.625\" style=\"width:31.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Verb is more probable in this simplified model: 0.625 versus 0.375.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Two candidate tags have prior-likelihood products 0.06 and 0.14. Find their normalized probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Unnormalized scores s₁=0.06 and s₂=0.14; these are the only candidates.</p><h4>To find</h4><p>The two posterior probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3f5210a24ca75d45.svg\" alt=\"P_i=s_i/(s_1+s_2)\" style=\"width:16.765ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A common denominator converts the candidate scores to a distribution summing to one.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Add scores</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/67c63d0fb7e2a504.svg\" alt=\"0.06+0.14=0.20\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Normalize first</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8d4386c048d353e.svg\" alt=\"0.06/0.20=0.3\" style=\"width:15.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Normalize second</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/593a5443e39d17c3.svg\" alt=\"0.14/0.20=0.7\" style=\"width:15.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Posterior probabilities are 0.3 and 0.7.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Generative: tag se word ka model. Discriminative: word se tag ka decision.</p>"}]},{"id":"m2-hmm","title":"Markov chains and Hidden Markov Models","unit":4,"scope":"Unit 4, pages 47–73","sections":[{"id":"markov-chain","title":"Markov chains: read a transition table and multiply a path","html":"<p><strong>A Markov chain</strong> is a probabilistic model of a sequence of states. Under the first-order Markov assumption, the next state's probability depends on the current state rather than the complete previous history. The <strong>initial probability</strong> tells us how likely each first state is. A <strong>transition probability</strong> tells us how likely a move from one state to another is.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c9611ed107ec9047.svg\" alt=\"P(s_t\\mid s_1,\\ldots,s_{t-1})=P(s_t\\mid s_{t-1})\" style=\"width:32.192ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e50f813caaa8d825.svg\" alt=\"P(s_1,\\ldots,s_T)=P(s_1)\\prod_{t=2}^{T}P(s_t\\mid s_{t-1})\" style=\"width:36.137ex;height:6.73ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For T states in a path, use one initial factor and T−1 transition factors. A row-oriented transition matrix must have each complete row sum to 1. Always read the row/column labels; some exam diagrams use a transposed arrangement.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><section class=\"example\"><p class=\"question\"><strong>Question. For the Rain/Dry Markov chain with initial P(Rain)=0.4 and P(Dry)=0.6, and transitions Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8, find the probability of Dry, Dry, Rain, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Dry,Dry,Rain,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d6fc24a22e2f64d.svg\" alt=\"P(D,D,R,R)=P(D)P(D\\mid D)P(R\\mid D)P(R\\mid R)\" style=\"width:48.815ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each step conditions on the immediately preceding state. The sequence contains four states, so it needs one initial plus three transition factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start in Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cf847b7db44f5fad.svg\" alt=\"P(D)=0.6\" style=\"width:11.241ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move Dry to Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5e47f480eb58213.svg\" alt=\"0.6\\times0.8=0.48\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move Dry to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0e4bbd812b1ba4d.svg\" alt=\"0.48\\times0.2=0.096\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Rain to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/da540845c4cc326e.svg\" alt=\"0.096\\times0.3=0.0288\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.0288.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For initial probabilities Rain=0.4, Dry=0.6 and transition rows Rain=(0.3,0.7), Dry=(0.2,0.8) in column order Rain,Dry, find the probability of Rain, Dry, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Rain,Dry,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c4b2bba9bbf4c148.svg\" alt=\"P(R,D,R)=P(R)P(D\\mid R)P(R\\mid D)\" style=\"width:36.844ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Do not replace Dry→Rain with Rain→Dry: the two directional probabilities differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/634e8d0183974542.svg\" alt=\"P(R)=0.4\" style=\"width:11.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ff067547e9b897f.svg\" alt=\"P(D\\mid R)=0.7,\\quad0.4(0.7)=0.28\" style=\"width:32.695ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Second transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ca3a09e7de1ba004.svg\" alt=\"P(R\\mid D)=0.2,\\quad0.28(0.2)=0.056\" style=\"width:34.958ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same fully specified chain—initial Rain=0.4, Dry=0.6; Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8—find P(Dry,Dry). Also find the conditional probability of next Dry given current Dry.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>The two-state joint probability and the one-step conditional probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83080c3651cd8fc6.svg\" alt=\"P(D,D)=P(D)P(D\\mid D)\" style=\"width:25.653ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The joint path includes an uncertain initial state. The conditional transition assumes the current state is already Dry.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Read the conditional transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1cf8b238b738730b.svg\" alt=\"P(D\\mid D)=0.8\" style=\"width:15ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Include the initial state for the joint path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/21b9a2b02a067056.svg\" alt=\"P(D,D)=0.6\\times0.8=0.48\" style=\"width:26.817ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(Dry,Dry)=0.48; P(next Dry|current Dry)=0.8. These answer different questions.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Path: pehle start probability, phir har arrow ki probability.</p></section>"},{"id":"hmm-components","title":"Hidden states, observations, transitions and emissions","html":"<p><strong>A Hidden Markov Model (HMM)</strong> is a probabilistic sequence model in which the underlying state sequence is unobserved, while each state emits an observed item. For POS tagging, words are observed and their grammatical tags are hidden. The task is to infer a suitable tag sequence from the words.</p><div class=\"flow\"><div class=\"node\">Hidden: Noun</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Hidden: Verb</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Hidden: Noun</div></div><div class=\"flow\"><div class=\"node\">Observed: birds</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Observed: eat</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Observed: seeds</div></div><p>Horizontal state-to-state links are <strong>transitions</strong>. The relation from each hidden state to its observed word is an <strong>emission</strong>. A transition P(V|N) asks how often a verb tag follows a noun tag. An emission P(eat|V) asks how often the observed word eat appears among verb-tagged tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Component</th><th>Notation</th><th>Meaning</th></tr></thead><tbody><tr><td>State set</td><td>S={N,V,…}</td><td>Possible hidden tags.</td></tr><tr><td>Observation vocabulary</td><td>O={birds,eat,seeds,…}</td><td>Visible word tokens.</td></tr><tr><td>Initial distribution</td><td>πⱼ=P(t₁=j)</td><td>Probability of starting in tag j.</td></tr><tr><td>Transition matrix</td><td>aᵢⱼ=P(tₖ=j|tₖ₋₁=i)</td><td>Probability of next tag j after i.</td></tr><tr><td>Emission matrix</td><td>bⱼ(w)=P(w|tag j)</td><td>Probability that state j emits word w.</td></tr></tbody></table></div><p>Two basic assumptions are used: the current hidden state depends only on the previous hidden state, and the current observation depends only on the current hidden state. A standard first-order HMM therefore does not explicitly condition an emitted word on the whole sentence.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8849ce22bc4d03e.svg\" alt=\"P(t_{1:T},w_{1:T})=\\pi_{t_1}b_{t_1}(w_1)\\prod_{k=2}^{T}a_{t_{k-1},t_k}b_{t_k}(w_k)\" style=\"width:40.971ex;height:6.775ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read the formula as <strong>start × first emission × transition × emission × transition × emission…</strong>. There are T emission factors and T−1 transitions, plus one initial factor. If the question supplies an explicit end-state probability, multiply that too. Do not invent an end factor when the model has none.</p><p><strong>Three different questions.</strong> (1) Scoring a specified tag path uses the joint product above. (2) Finding the probability of the observed words sums scores over all possible tag paths. (3) Finding the best tag path maximizes the path score, typically using Viterbi. A joint path score is not a normalized posterior P(tags|words).</p><p class=\"cue\"><strong>Yaad rakho:</strong> Transition = tag se agla tag. Emission = tag se visible word.</p>"},{"id":"transition-emission-estimation","title":"Estimate transition and emission probabilities from tagged data","html":"<div class=\"equation\"><div class=\"math-display\"><img src=\"math/2145c612575540f3.svg\" alt=\"P(t&#39;\\mid t)=\\frac{C(t,t&#39;)}{C(t)\\text{ with a following tag/end event}}\" style=\"width:46.275ex;height:5.495ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a89d9641a3681129.svg\" alt=\"P(w\\mid t)=\\frac{C(w,t)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>In a transition denominator, count the previous tag's outgoing events. In an emission denominator, count all tokens bearing that tag. With explicit end transitions the totals align conveniently. Keep the two numerator types separate: tag→tag counts are not word→tag counts.</p><section class=\"example\"><p class=\"question\"><strong>Question. A tagged corpus contains 116454 determiner tags DT, each counted with an outgoing event. DT is followed by NN 56509 times. Estimate P(NN|DT).</strong></p><div class=\"given\"><h4>Given</h4><p>C(DT)=116454; C(DT,NN)=56509.</p><h4>To find</h4><p>The DT→NN transition probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5163e6a68004bc8.svg\" alt=\"P(NN\\mid DT)=C(DT,NN)/C(DT)\" style=\"width:35.893ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The denominator is the number of previous DT contexts because DT is the condition.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the transition count</h5><p>DT followed by NN occurs 56509 times.</p></div><div class=\"step\"><h5>Step 2. Identify the conditional total</h5><p>There are 116454 DT contexts.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/47e9bc9d8bc16788.svg\" alt=\"P(NN\\mid DT)=\\frac{56509}{116454}\\approx0.485247\" style=\"width:35.194ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(NN|DT)≈0.485247.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The tag VBZ occurs 21627 times, and 10073 of those tokens are the word “is”. Estimate P(is|VBZ).</strong></p><div class=\"given\"><h4>Given</h4><p>C(VBZ)=21627; C(is,VBZ)=10073.</p><h4>To find</h4><p>The emission probability of is from VBZ.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ec13ac6a8a9bdae.svg\" alt=\"P(is\\mid VBZ)=C(is,VBZ)/C(VBZ)\" style=\"width:36.42ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The condition is the tag VBZ; we ask which word it emits.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Choose the word-tag count</h5><p>The required word is is with tag VBZ: count 10073.</p></div><div class=\"step\"><h5>Step 2. Choose the tag total</h5><p>All VBZ-tagged word tokens: count 21627.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/481557575db95324.svg\" alt=\"P(is\\mid VBZ)=\\frac{10073}{21627}\\approx0.465760\" style=\"width:33.513ex;height:4.661ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(is|VBZ)≈0.465760. This is different from P(VBZ|is).</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use the tagged sentences “dogs/N chase/V cats/N” and “cats/N sleep/V”. Estimate the initial tag probabilities, all nonzero transitions including END, and emissions.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: START dogs/N chase/V cats/N END; START cats/N sleep/V END.</p><h4>To find</h4><p>Initial distribution, transition rows and emission rows.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/46d6d50083ab5629.svg\" alt=\"\\pi_t=C(START,t)/2,\\quad a_{tu}=C(t,u)/C(t),\\quad b_t(w)=C(w,t)/C(t)\" style=\"width:65.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The corpus explicitly tells us the tags, so we can count training frequencies directly.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count tag tokens</h5><p>N occurs 3 times: dogs, cats, cats. V occurs 2 times: chase, sleep.</p></div><div class=\"step\"><h5>Step 2. Count sentence starts</h5><p>Both sentences start with N.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a5ae0d0edad4515.svg\" alt=\"\\pi_N=2/2=1,\\quad \\pi_V=0/2=0\" style=\"width:29.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>N→V</td><td>2</td></tr><tr><td>N→END</td><td>1</td></tr><tr><td>V→N</td><td>1</td></tr><tr><td>V→END</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 4. Normalize transition rows</h5><div class=\"table-wrap\"><table><thead><tr><th>Current</th><th>To N</th><th>To V</th><th>To END</th></tr></thead><tbody><tr><td>N</td><td>0</td><td>2/3</td><td>1/3</td></tr><tr><td>V</td><td>1/2</td><td>0</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Count and normalize emissions</h5><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>dogs</th><th>cats</th><th>chase</th><th>sleep</th></tr></thead><tbody><tr><td>N</td><td>1/3</td><td>2/3</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/2</td><td>1/2</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> π=(1,0); transitions and emissions are given in the completed tables. Each complete probability row sums to 1.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Tag→tag table aur tag→word table ko mix mat karna.</p>"},{"id":"hot-cold-paths","title":"HMM path probabilities: three complete numerical examples","html":"<p>The following model uses hidden weather states Hot (H) and Cold (C). Observations are numbers 1, 2 and 3. These numbers are observation labels, not quantities to multiply directly. Their emission probabilities come from the table.</p><div class=\"table-wrap\"><table><thead><tr><th>Initial state</th><th>Probability</th></tr></thead><tbody><tr><td>H</td><td>0.8</td></tr><tr><td>C</td><td>0.2</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>From → to</th><th>H</th><th>C</th></tr></thead><tbody><tr><td>H</td><td>0.7</td><td>0.3</td></tr><tr><td>C</td><td>0.4</td><td>0.6</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Emission state</th><th>Observation 1</th><th>Observation 2</th><th>Observation 3</th></tr></thead><tbody><tr><td>H</td><td>0.2</td><td>0.4</td><td>0.4</td></tr><tr><td>C</td><td>0.5</td><td>0.4</td><td>0.1</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for observations (1,2,3) are H:(0.2,0.4,0.4) and C:(0.5,0.4,0.1). Find the joint probability of hidden path H,C,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path H→C→H. Observations 1→3→1. Model probabilities are specified in the question. There is no END factor.</p><h4>To find</h4><p>P(H,C,H; 1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d9c99617b5e16c0.svg\" alt=\"P=\\pi_H b_H(1)a_{HC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.863ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>There are three hidden states and observations: three emissions, two transitions, and one initial probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Hot and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/78369e147be76567.svg\" alt=\"0.8\\times0.2=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Transition Hot to Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/24d6c09c3069c91f.svg\" alt=\"0.16\\times0.3=0.048\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Cold emits 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/59bb445235ff63a6.svg\" alt=\"0.048\\times0.1=0.0048\" style=\"width:20.113ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Transition Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1146803e8605f2e.svg\" alt=\"0.0048\\times0.4=0.00192\" style=\"width:22.376ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Hot emits the last 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e3b740dc0fd787f.svg\" alt=\"0.00192\\times0.2=0.000384\" style=\"width:24.638ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.000384 = 3.84×10⁻⁴.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels (1,2,3), find the joint probability of path H,H,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>State path H→H→H, observations 1→3→1; no END factor.</p><h4>To find</h4><p>P(H,H,H;1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83f5cb754dc77195.svg\" alt=\"P=\\pi_H b_H(1)a_{HH}b_H(3)a_{HH}b_H(1)\" style=\"width:32.477ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The state remains Hot; each transition still contributes its probability 0.7.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial state and first emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/806228a802bab106.svg\" alt=\"0.8(0.2)=0.16\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f1106c30e00cc2ce.svg\" alt=\"0.16(0.7)=0.112\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/359ae9ea2534c8f2.svg\" alt=\"0.112(0.4)=0.0448\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Second self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d2be9254f3d2eee1.svg\" alt=\"0.0448(0.7)=0.03136\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit final observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/af971b25ad6922c0.svg\" alt=\"0.03136(0.2)=0.006272\" style=\"width:23.632ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.006272. A self-transition is not automatically probability 1.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6) in next-state order H,C; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3, find the score of path C,C,H with observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path C→C→H. Observation sequence 1→3→1. No end-state factor.</p><h4>To find</h4><p>The joint path-and-observation probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c39dbc8fa9b14a01.svg\" alt=\"P=\\pi_C b_C(1)a_{CC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.248ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The initial state is Cold, so use π(C), not π(H). Each emission is selected from the state at the same position.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Cold and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ea1ebd665b713576.svg\" alt=\"0.2(0.5)=0.1\" style=\"width:13.451ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Stay Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3af50c5661f75952.svg\" alt=\"0.1(0.6)=0.06\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit 3 from Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2039ca068efac123.svg\" alt=\"0.06(0.1)=0.006\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99539fe7f4612c73.svg\" alt=\"0.006(0.4)=0.0024\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit 1 from Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/315780f838015183.svg\" alt=\"0.0024(0.2)=0.00048\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.00048.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har column par: state ka emission. Columns ke beech: transition.</p></section>"},{"id":"tagging-corpus-case","title":"POS HMM worked corpus: Mary, Jane, can, will and spot","html":"<p>The class example contains words that can be either names or ordinary verbs/modal auxiliaries. The term is <strong>modal</strong> (M), not “model”. To avoid guessing tags from spelling, the training corpus below supplies them explicitly and lowercases words for the emission vocabulary.</p><div class=\"table-wrap\"><table><thead><tr><th>Training sentence</th><th>Gold tags</th></tr></thead><tbody><tr><td>mary jane can see will</td><td>N N M V N</td></tr><tr><td>spot will see mary</td><td>N M V N</td></tr><tr><td>will jane spot mary</td><td>M N V N</td></tr><tr><td>mary will pat spot</td><td>N M V N</td></tr></tbody></table></div><p>There are 9 noun tokens, 4 modal tokens and 4 verb tokens. Each sentence includes a start and end transition. For nouns, the next event can be another noun, modal, verb or END.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>N</th><th>M</th><th>V</th><th>END</th></tr></thead><tbody><tr><td>START</td><td>3/4</td><td>1/4</td><td>0</td><td>0</td></tr><tr><td>N</td><td>1/9</td><td>3/9</td><td>1/9</td><td>4/9</td></tr><tr><td>M</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td></tr><tr><td>V</td><td>4/4</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Tag → word</th><th>mary</th><th>jane</th><th>can</th><th>see</th><th>will</th><th>spot</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>4/9</td><td>2/9</td><td>0</td><td>0</td><td>1/9</td><td>2/9</td><td>0</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>0</td><td>2/4</td><td>0</td><td>1/4</td><td>1/4</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Using the fully tagged four-sentence corpus above, calculate the joint score of “will jane spot mary” assigned tags M,N,V,N, including END.</strong></p><div class=\"given\"><h4>Given</h4><p>Required factors from the tables: START→M=1/4; emit will|M=3/4; M→N=1/4; jane|N=2/9; N→V=1/9; spot|V=1/4; V→N=1; mary|N=4/9; N→END=4/9.</p><h4>To find</h4><p>The specified tag-path score, including words and sentence end.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/23c70e8086b83a3b.svg\" alt=\"P=\\pi_M b_M(will)a_{MN}b_N(jane)a_{NV}b_V(spot)a_{VN}b_N(mary)a_{N,END}\" style=\"width:62.792ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both transitions and emissions are needed. A tag transition alone cannot tell us whether a particular word is plausible.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start and emit will</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a7d30f8cd240d72.svg\" alt=\"\\frac14\\times\\frac34=\\frac3{16}\" style=\"width:13.294ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move to N and emit jane</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/934eaa8bf4f9d42a.svg\" alt=\"\\frac3{16}\\times\\frac14\\times\\frac29=\\frac1{96}\" style=\"width:19.318ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move to V and emit spot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/40b213c06ef8b7d2.svg\" alt=\"\\frac1{96}\\times\\frac19\\times\\frac14=\\frac1{3456}\" style=\"width:21.58ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move to N and emit mary</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a0e9571f3b95594c.svg\" alt=\"\\frac1{3456}\\times1\\times\\frac49=\\frac1{7776}\" style=\"width:22.847ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/171a6c8b22e17d35.svg\" alt=\"\\frac1{7776}\\times\\frac49=\\frac1{17496}\\approx0.0000571559\" style=\"width:36.171ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The joint score is 1/17496 ≈ 0.0000571559.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same tagged corpus and tables, explain the unsmoothed score of “will can spot mary” assigned tags M,V,N,N.</strong></p><div class=\"given\"><h4>Given</h4><p>The proposed second word is can with hidden tag V. In the training corpus, can occurs only with M, so b_V(can)=0.</p><h4>To find</h4><p>Whether the complete path score is zero and what this means.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0957b6ab0a1aa0cc.svg\" alt=\"P(\\text{path,words})=(\\text{other required factors})\\times b_V(can)\" style=\"width:50.674ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A product containing one zero factor is zero even if every other factor is positive.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the critical emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fdca0f8e7f8d838a.svg\" alt=\"b_V(can)=C(can,V)/C(V)=0/4=0\" style=\"width:37.369ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the full-product consequence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e316f36777dd5.svg\" alt=\"P(\\text{path,words})=0\" style=\"width:18.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Interpret correctly</h5><p>This unsmoothed corpus model has no evidence for can as a verb. It does not prove that a verb usage of can is impossible in English.</p></div><div class=\"answer\"><strong>Final answer.</strong> The unsmoothed path score is zero.</div></section>"}]},{"id":"m2-hmm-decoding","title":"Choosing the most likely tag sequence","unit":4,"scope":"Unit 4 page 73: Viterbi motivation, explained with small worked extensions","sections":[{"id":"sequence-count","title":"Why exhaustive search grows exponentially","html":"<p>If each of T observed words can receive any of N tags, there are N choices at each position. Thus the total number of complete tag sequences is N multiplied by itself T times. This counts possible assignments before grammar rules or zero probabilities eliminate any.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/014ed66c3c0df2b1.svg\" alt=\"\\text{Number of tag sequences}=N^T\" style=\"width:30.626ex;height:2.484ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A four-word sentence is tagged using three possible POS tags per word. How many complete tag sequences are possible?</strong></p><div class=\"given\"><h4>Given</h4><p>N=3 possible tags per position; T=4 word positions.</p><h4>To find</h4><p>The number of tag sequences.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every independent position contributes a factor of three choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write one factor per position</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d7b06b7e39ae0a5.svg\" alt=\"M=3\\times3\\times3\\times3\" style=\"width:18.217ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6570633fef12ecb5.svg\" alt=\"3\\times3=9,\\quad9\\times3=27,\\quad27\\times3=81\" style=\"width:37.46ex;height:1.968ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 81 possible tag sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A five-word sentence has two candidate tags per word. Count its tag sequences.</strong></p><div class=\"given\"><h4>Given</h4><p>N=2; T=5.</p><h4>To find</h4><p>M.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The length is the exponent, not a multiplier.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Substitute</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e0b25a2374d09c2d.svg\" alt=\"M=2^5\" style=\"width:7.514ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/85ec03497588b6d5.svg\" alt=\"2\\times2\\times2\\times2\\times2=32\" style=\"width:21.998ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 32 possible sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using 45 possible tags, compare the number of tag sequences for sentences of length 2 and 3.</strong></p><div class=\"given\"><h4>Given</h4><p>N=45. First T=2, then T=3.</p><h4>To find</h4><p>Both counts and the growth factor.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0806abcd5d0a43e.svg\" alt=\"M_2=45^2,\\quad M_3=45^3\" style=\"width:22.167ex;height:2.439ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Adding one position multiplies the possibilities by the number of tag choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Two words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/672617aa8909800b.svg\" alt=\"45^2=2025\" style=\"width:10.792ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Three words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/96a0c5c55e4f8048.svg\" alt=\"45^3=2025\\times45=91125\" style=\"width:24.493ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3daee8fcfcc1adea.svg\" alt=\"91125/2025=45\" style=\"width:16.592ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 2 words: 2025 paths. 3 words: 91125 paths. One additional word multiplies the count by 45.</div></section><p>The slides introduce Viterbi to avoid enumerating every path. It reuses the best prefix score for each ending state. For a dense first-order HMM, it needs O(TN²) recurrence work instead of enumerating N<sup>T</sup> complete paths.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Choices per word ki power = sentence length.</p>"},{"id":"viterbi-explained","title":"Viterbi decoding: compare incoming paths, keep the best, trace back","html":"<p><strong>The Viterbi algorithm</strong> finds the most likely hidden-state sequence for a fixed observation sequence. At each position, it keeps the best path ending in each state. This is safe because, under the HMM assumptions, future extensions depend on that ending state, not the discarded details of the prefix.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3fa79f3d8232431.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1)\" style=\"width:15.501ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50951d9d0cf5dcf6.svg\" alt=\"\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:27.716ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3935aac800940d84.svg\" alt=\"\\psi_t(j)=\\arg\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:25.893ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning in ordinary words</th></tr></thead><tbody><tr><td>δₜ(j)</td><td>Score of the best prefix that ends in state j at position t.</td></tr><tr><td>ψₜ(j)</td><td>Previous state that supplied that best prefix; keep it as a backpointer.</td></tr><tr><td>max</td><td>Choose the larger candidate score; do not add.</td></tr><tr><td>argmax</td><td>Remember which previous state won, rather than only its value.</td></tr></tbody></table></div><div class=\"flow\"><div class=\"node\">Initialize: start × first emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">For each next state: compare incoming scores</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Multiply winner by this state's emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Keep score + winning predecessor</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose best final state and trace arrows backward</div></div><p>Do not choose the best state independently at each word. The best last state can come from a different best predecessor than a local guess. Backpointers recover one consistent complete path. If scores tie, either tied path is optimal under the model; state the tie.</p><section class=\"example\"><p class=\"question\"><strong>Question. Use an HMM with π(H)=0.8, π(C)=0.2, transitions H:(0.7,0.3), C:(0.4,0.6) in H,C order, and emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3. Find the most likely hidden path for observations 1,3,1 using Viterbi.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>The best hidden-state sequence and its joint score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/712c98f9c4966f84.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1),\\quad\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:46.485ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Viterbi keeps two best prefix scores per column, one ending H and one ending C.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize at observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/44fc29f14406bbca.svg\" alt=\"\\delta_1(H)=0.8(0.2)=0.16\" style=\"width:23.361ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1500f80244db39b.svg\" alt=\"\\delta_1(C)=0.2(0.5)=0.10\" style=\"width:23.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. At observation 3, calculate the H cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/61623e2cd024bab3.svg\" alt=\"H\\to H:\\ 0.16(0.7)=0.112\" style=\"width:26.834ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/256055f1b5c81a60.svg\" alt=\"C\\to H:\\ 0.10(0.4)=0.040\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ee04f7fda3bf226b.svg\" alt=\"\\delta_2(H)=\\max(0.112,0.040)(0.4)=0.0448\" style=\"width:40.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this H cell: H.</p></div><div class=\"step\"><h5>Step 3. At observation 3, calculate the C cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e9c32ed85546537.svg\" alt=\"H\\to C:\\ 0.16(0.3)=0.048\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c0863275b12a91e.svg\" alt=\"C\\to C:\\ 0.10(0.6)=0.060\" style=\"width:26.255ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a8ea78adb0cc4576.svg\" alt=\"\\delta_2(C)=\\max(0.048,0.060)(0.1)=0.006\" style=\"width:38.596ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this C cell: C.</p></div><div class=\"step\"><h5>Step 4. At final observation 1, calculate H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e2373be2aa769a8.svg\" alt=\"H\\to H:\\ 0.0448(0.7)=0.03136\" style=\"width:31.359ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/286832c2c26620dd.svg\" alt=\"C\\to H:\\ 0.006(0.4)=0.0024\" style=\"width:28.807ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/48b05bab6b13e38a.svg\" alt=\"\\delta_3(H)=0.03136(0.2)=0.006272\" style=\"width:32.411ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 5. At final observation 1, calculate C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5f431d2a23d6fe1.svg\" alt=\"H\\to C:\\ 0.0448(0.3)=0.01344\" style=\"width:31.069ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b69919a26d75a560.svg\" alt=\"C\\to C:\\ 0.006(0.6)=0.0036\" style=\"width:28.517ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/709ea0da7f36d663.svg\" alt=\"\\delta_3(C)=0.01344(0.5)=0.00672\" style=\"width:30.99ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 6. Select the final state</h5><p>0.00672 > 0.006272, so the best final state is C.</p></div><div class=\"step\"><h5>Step 7. Trace back</h5><p>Final C came from H at position2. That H came from H at position1. Reading forward gives H,H,C.</p></div><div class=\"step\"><h5>Step 8. Verify the recovered complete path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5aa4b0fd88f37247.svg\" alt=\"0.8(0.2)(0.7)(0.4)(0.3)(0.5)=0.00672\" style=\"width:36.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H→C with joint score 0.00672.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best two-state hidden path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/801327bb8fdbd394.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(3),\\quad\\delta_2(j)=b_j(1)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same recurrence applies even though the observation order changed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2e38d10b83c569f4.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.1)=0.02\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1716d45167a355a0.svg\" alt=\"\\max(0.32(0.7),0.02(0.4))(0.2)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4db3393304c21c23.svg\" alt=\"=\\max(0.224,0.008)(0.2)=0.0448\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 3. Calculate the final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bd4ebf48e761f108.svg\" alt=\"\\max(0.32(0.3),0.02(0.6))(0.5)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15d2f168f4fe9604.svg\" alt=\"=\\max(0.096,0.012)(0.5)=0.048\" style=\"width:32.495ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>Final C wins with 0.048 and came from H. The path is H,C.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→C, score 0.048.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 2,2.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a478f4924f42dec2.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(2),\\quad\\delta_2(j)=b_j(2)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both states emit2 with probability 0.4, but their initial and transition probabilities still differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/56ea5abfdb65b387.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.4)=0.08\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75472da37ba442a1.svg\" alt=\"\\max(0.32(0.7),0.08(0.4))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f9a0610a246e0ed0.svg\" alt=\"=\\max(0.224,0.032)(0.4)=0.0896\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 3. Final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/87b9dd83765528d1.svg\" alt=\"\\max(0.32(0.3),0.08(0.6))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/088fd26aaafea320.svg\" alt=\"=\\max(0.096,0.048)(0.4)=0.0384\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>The final H score 0.0896 is larger. Its predecessor is H.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H with score 0.0896.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har destination ke liye incoming paths compare; winner ka arrow yaad.</p></section>"},{"id":"joint-vs-posterior","title":"A path score is not the probability of the observed sentence","html":"<section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3. For observations 1,3, calculate the probability of the observations by summing all four two-state paths.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>P(observations 1,3), not just the best-path score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e591ebf359dce.svg\" alt=\"P(o_1,o_2)=\\sum_{s_1,s_2}\\pi_{s_1}b_{s_1}(o_1)a_{s_1s_2}b_{s_2}(o_2)\" style=\"width:35.484ex;height:5.061ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The hidden path is unspecified, so its mutually exclusive alternatives must be summed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score H,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c316d3e7d10ea4e8.svg\" alt=\"0.8(0.2)(0.7)(0.4)=0.0448\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Score H,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/076745077c7c6109.svg\" alt=\"0.8(0.2)(0.3)(0.1)=0.0048\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Score C,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2dbad158b7e2df38.svg\" alt=\"0.2(0.5)(0.4)(0.4)=0.016\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Score C,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/595d09221813b65c.svg\" alt=\"0.2(0.5)(0.6)(0.1)=0.006\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Add all paths</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2b05babdadbfdf90.svg\" alt=\"P(1,3)=0.0448+0.0048+0.016+0.006=0.0716\" style=\"width:50.222ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Observation probability =0.0716. The best single-path score 0.0448 is a different quantity.</div></section><p>If asked for the posterior of path H,H given observations 1,3, normalize: 0.0448/0.0716 ≈0.625698. Viterbi chooses the best path using joint scores because the observation denominator is common to every candidate. It does not compute that denominator by taking a maximum.</p>"}]},{"id":"m2-chunks-grammar","title":"Chunking, chinking and context-free grammar","unit":4,"scope":"Unit 4, pages 14–19, 74–97","sections":[{"id":"chunking-chinking","title":"Chunking groups words; chinking removes words from a candidate chunk","html":"<p><strong>Chunking</strong>, also called shallow parsing, groups adjacent tagged words into meaningful non-overlapping units, commonly noun phrases. It usually identifies local phrase boundaries without producing the complete hierarchical structure of a sentence. <strong>Chinking</strong> removes specified tokens from an existing candidate chunk, splitting or trimming it.</p><div class=\"flow\"><div class=\"node\">The/DT small/JJ cat/NN sat/VBD on/IN the/DT mat/NN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [The small cat]</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Outside: sat on</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [the mat]</div></div><p>A POS tagger labels individual words. A chunker groups words into phrases. A full parser shows how phrases relate recursively to form the entire sentence. These are related tasks with different outputs.</p><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>POS tagging</td><td>The small cat</td><td>The/DT small/JJ cat/NN</td></tr><tr><td>NP chunking</td><td>Tagged tokens</td><td>[NP The small cat]</td></tr><tr><td>Chinking</td><td>A broad candidate chunk</td><td>Remove verbs/prepositions, keep noun-phrase segments</td></tr><tr><td>Full parsing</td><td>Sentence + grammar</td><td>A nested tree with sentence, noun phrase and verb phrase nodes</td></tr></tbody></table></div><p><strong>Rule-based chunking</strong> uses tag patterns. Statistical or learned chunkers infer boundaries from labeled examples. A useful NP rule is an optional determiner, followed by zero or more adjectives, followed by a noun. In NLTK-style notation: <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;}</code>. Here ? means zero or one occurrence; * means zero or more; + means one or more when used. The braces mean “form a chunk around the matched sequence”.</p><section class=\"example\"><p class=\"question\"><strong>Question. Apply the NP rule optional DT, zero or more JJ, then one NN to “The/DT quick/JJ brown/JJ fox/NN jumps/VBZ over/IN the/DT lazy/JJ dog/NN”.</strong></p><div class=\"given\"><h4>Given</h4><p>Tagged input is supplied. Rule: DT? JJ* NN.</p><h4>To find</h4><p>All noun-phrase chunks.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The rule groups a noun with its preceding determiner and adjectives; a verb or preposition does not match this NP pattern.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start at The</h5><p>The matches optional DT; quick and brown both match JJ*; fox matches NN.</p></div><div class=\"step\"><h5>Step 2. Form the first NP</h5><p><strong>[NP The quick brown fox]</strong></p></div><div class=\"step\"><h5>Step 3. Skip nonmatching tokens</h5><p>jumps/VBZ and over/IN do not satisfy the NP pattern.</p></div><div class=\"step\"><h5>Step 4. Match the second NP</h5><p>the is DT, lazy is JJ, dog is NN: <strong>[NP the lazy dog]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> [NP The quick brown fox] jumps over [NP the lazy dog].</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using NP → DT? JJ* NN, identify the chunks in “bright/JJ stars/NN shine/VBP and/CC a/DT moon/NN glows/VBZ”. Use the supplied tags exactly.</strong></p><div class=\"given\"><h4>Given</h4><p>Input tags label stars as NN for this exercise. Rule requires optional DT, zero or more JJ, then NN.</p><h4>To find</h4><p>The matched NP spans.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The optional determiner may be absent and the adjective repetition may be empty.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Match bright stars</h5><p>No determiner is present, which DT? permits. bright matches JJ; stars matches NN.</p></div><div class=\"step\"><h5>Step 2. Inspect shine and and</h5><p>VBP and CC fall outside the NP rule.</p></div><div class=\"step\"><h5>Step 3. Match a moon</h5><p>a matches DT; no adjective is present; moon matches NN.</p></div><div class=\"answer\"><strong>Final answer.</strong> Chunks are [NP bright stars] and [NP a moon]. With ordinary Penn tagging, stars is usually NNS; broaden the noun pattern to include NNS when that tag is used.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Begin with one candidate chunk containing “The/DT cat/NN sat/VBD on/IN the/DT mat/NN”. Chink out verbs and prepositions. Show the remaining chunks.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial candidate: [The cat sat on the mat]. Remove tags VBD and IN.</p><h4>To find</h4><p>The chunk segments after exclusion.</p></div><h4>Formula and why it applies</h4><p>Chinking removes matched tokens from the existing chunk.</p><p>Removing the middle verb/preposition region divides the original candidate into two remaining contiguous spans.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the tokens to remove</h5><p>sat is VBD and on is IN.</p></div><div class=\"step\"><h5>Step 2. Remove those tokens from chunk membership</h5><p>The remaining token groups are “The cat” and “the mat”. sat and on still exist in the sentence; they are simply outside these chunks.</p></div><div class=\"step\"><h5>Step 3. Write the final chunked sentence</h5><p><strong>[The cat]</strong> sat on <strong>[the mat]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> Two chunks remain: The cat; the mat.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Chunking = andar group karo; chinking = unwanted tokens ko group se bahar karo.</p></section>"},{"id":"cfg-foundation","title":"CFG: terminals, nonterminals, production rules and parse trees","html":"<p><strong>A context-free grammar (CFG)</strong> specifies a language using production rules whose left side is a single nonterminal. Formally, G=(N,Σ,R,S): N is the set of nonterminals, Σ the terminal vocabulary, R the production rules, and S the start symbol. A rule can expand its nonterminal regardless of the neighboring symbols; that is the meaning of “context-free”.</p><div class=\"table-wrap\"><table><thead><tr><th>Concept</th><th>Plain explanation</th><th>Example</th></tr></thead><tbody><tr><td>Terminal</td><td>A word at a leaf; it is not expanded further</td><td>the, girl, read</td></tr><tr><td>Nonterminal</td><td>A grammatical category that can be expanded</td><td>S, NP, VP, Det, N, V</td></tr><tr><td>Production</td><td>A permitted replacement</td><td>S → NP VP</td></tr><tr><td>Start symbol</td><td>Category for a complete sentence</td><td>S</td></tr><tr><td>Lexicon</td><td>Word-to-category rules</td><td>N → girl | paper</td></tr><tr><td>Derivation</td><td>Sequence of rule applications</td><td>S ⇒ NP VP ⇒ Det N VP ⇒ …</td></tr><tr><td>Parse tree</td><td>Hierarchical picture of those expansions</td><td>Root S, internal phrases, word leaves</td></tr></tbody></table></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/08274dbc564789d5.svg\" alt=\"S\\to NP\\ VP,\\quad NP\\to Det\\ N,\\quad VP\\to V\\ NP\" style=\"width:45.747ex;height:2.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read S→NP VP as “a sentence can contain a noun phrase followed by a verb phrase”. It does not mean subtraction or multiplication. A vertical bar in a grammar rule means alternatives: Det→the | a allows either the or a. This is different from the probability bar meaning “given”.</p><div class=\"flow\"><div class=\"node\">S: the whole sentence</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: the girl  +  VP: read the paper</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP→Det N; VP→V NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Leaves in order: the / girl / read / the / paper</div></div><p><strong>A constituent</strong> is a group of words that acts as a grammatical unit, such as “the girl”. <strong>Syntactic parsing</strong> assigns a grammatical structure to an input sentence using a grammar. It can support grammar checking, information extraction, translation and later semantic analysis. Failure under one restricted grammar means that grammar could not derive the sentence; it does not necessarily prove the sentence is invalid English.</p><p><strong>A treebank</strong> is a corpus annotated with parse trees. It supplies training/evaluation structures for parsers and lets linguists study recurring syntactic patterns. A tagged corpus gives word tags; a treebank additionally records relationships among phrases.</p><div class=\"table-wrap\"><table><thead><tr><th>Representation</th><th>Example information retained</th></tr></thead><tbody><tr><td>Bag of words</td><td>Words occur, but word order/grammar is lost</td></tr><tr><td>POS tags</td><td>Each word's local grammatical category</td></tr><tr><td>Chunks</td><td>Short phrase boundaries</td></tr><tr><td>Parse tree</td><td>Nested constituent structure of the whole sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Grammar rule ek expansion instruction hai: S ko NP aur VP mein kholo.</p>"},{"id":"structural-ambiguity","title":"Ambiguity and grammar coverage","html":"<p><strong>Structural ambiguity</strong> occurs when a sentence has more than one valid parse tree. In “I saw the man with a telescope”, the prepositional phrase “with a telescope” can attach to saw (the instrument I used) or to the man (the man possessing the telescope). The words and their order stay the same, but the grouping changes.</p><div class=\"table-wrap\"><table><thead><tr><th>Reading</th><th>Attachment</th><th>Meaning</th></tr></thead><tbody><tr><td>I [saw the man] [with a telescope]</td><td>PP modifies VP</td><td>I used a telescope to see the man.</td></tr><tr><td>I saw [the man with a telescope]</td><td>PP modifies NP</td><td>The man had a telescope.</td></tr></tbody></table></div><p>A parser may need context, probabilities or semantic constraints to choose between trees. A plain CFG describes permitted structures but does not itself assign a probability to each tree. Do not invent rule probabilities for an ordinary CFG question.</p><p>Lexical ambiguity also matters: book can be a noun or verb. In “Book the flight”, the imperative analysis begins S→VP, followed by VP→V NP. A parser that initially chooses book as a noun may reach a dead end and must try another permitted analysis.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Same words, alag grouping → alag meaning.</p>"}]},{"id":"m2-parsing","title":"Top-down and bottom-up parsing: complete traces","unit":4,"scope":"Unit 4, pages 98–116","sections":[{"id":"top-down-theory","title":"Recursive-descent top-down parsing","html":"<p><strong>Top-down parsing</strong> starts at the grammar's start symbol S and expands nonterminals until the leaves match the input words in order. <strong>Recursive descent</strong> commonly implements each nonterminal as a procedure that tries its productions. It builds from the root toward the leaves.</p><div class=\"flow\"><div class=\"node\">Start with S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose an allowed S production</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Expand its next nonterminal</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match the resulting terminal to the input</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Continue, or backtrack if the choice fails</div></div><p><strong>Algorithm.</strong> Start with S as the current goal. Choose a production for the leftmost unexpanded nonterminal. Replace that nonterminal by the production's right side. If a terminal appears, compare it with the next input token. If it matches, consume the token; if it does not, reject that branch and try another production. Accept only when the complete input is consumed and all grammar goals are satisfied.</p><p>A <strong>leftmost derivation</strong> always expands the leftmost remaining nonterminal first. Top-down parsing can make guesses that the actual words cannot support, so it may need backtracking. A naive recursive-descent parser can loop on left-recursive rules such as NP→NP PP unless the grammar or algorithm is changed. Predictive LL(1) parsing chooses productions using one lookahead token when the grammar permits; not every English CFG is LL(1).</p><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>Begins with</th><th>Direction</th><th>Common difficulty</th></tr></thead><tbody><tr><td>Top-down</td><td>Start symbol S</td><td>Root to word leaves</td><td>Predictions that do not match input; left recursion</td></tr><tr><td>Bottom-up</td><td>Actual input tokens</td><td>Leaves to root S</td><td>Reductions that cannot contribute to a complete sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Top-down: sentence ka structure pehle, words tak neeche aao.</p>"},{"id":"top-down-examples","title":"Three full top-down derivations with parse trees","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Using S→NP VP, NP→Det N, VP→V NP, Det→the, N→girl|paper and V→read, give a leftmost top-down derivation and parse tree for “the girl read the paper”.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Rule type</th><th>Rules</th></tr></thead><tbody><tr><td>Structure</td><td>S → NP VP; NP → Det N; VP → V NP</td></tr><tr><td>Lexicon</td><td>Det → the; N → girl | paper; V → read</td></tr></tbody></table></div><h4>To find</h4><p>A successful derivation and tree whose leaves equal the input.</p></div><h4>Formula and why it applies</h4><p>At every stage expand the leftmost nonterminal using a supplied production.</p><p>A top-down derivation begins at S; the input determines which terminal alternatives can succeed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Begin at the sentence symbol</h5><p>S</p></div><div class=\"step\"><h5>Step 2. Expand the sentence</h5><p>S ⇒ NP VP</p></div><div class=\"step\"><h5>Step 3. Expand its first noun phrase</h5><p>⇒ Det N VP</p></div><div class=\"step\"><h5>Step 4. Match the first determiner</h5><p>⇒ the N VP</p></div><div class=\"step\"><h5>Step 5. Match the subject noun</h5><p>⇒ the girl VP</p></div><div class=\"step\"><h5>Step 6. Expand the verb phrase</h5><p>⇒ the girl V NP</p></div><div class=\"step\"><h5>Step 7. Match the verb</h5><p>⇒ the girl read NP</p></div><div class=\"step\"><h5>Step 8. Expand the object noun phrase</h5><p>⇒ the girl read Det N</p></div><div class=\"step\"><h5>Step 9. Match its determiner</h5><p>⇒ the girl read the N</p></div><div class=\"step\"><h5>Step 10. Match the last noun</h5><p>⇒ the girl read the paper</p></div><div class=\"step\"><h5>Step 11. Draw the tree</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Parse tree: the girl read the paper\" viewBox=\"0 0 560 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Parse tree: the girl read the paper</title><line x1=\"238.75\" y1=\"40\" x2=\"115\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"170\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"238.75\" y1=\"40\" x2=\"362.5\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"362.5\" y1=\"104\" x2=\"280\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"362.5\" y1=\"104\" x2=\"445\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"445\" y1=\"168\" x2=\"390\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"232\" x2=\"390\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"445\" y1=\"168\" x2=\"500\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"500\" y1=\"232\" x2=\"500\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"238.75\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"115\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">the</text><text x=\"170\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">girl</text><text x=\"362.5\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"280\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">read</text><text x=\"445\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"390\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"390\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">the</text><text x=\"500\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"500\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">paper</text></svg></div><figcaption>Parse tree: the girl read the paper</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> The grammar derives the complete sentence. The subject NP is “the girl”; the object NP is “the paper”.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use S→NP VP, NP→Det N|N, VP→V NP, Det→A, N→restaurant|Dosas and V→serves to parse “A restaurant serves Dosas” by a leftmost top-down derivation.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Rule type</th><th>Rules</th></tr></thead><tbody><tr><td>Structure</td><td>S → NP VP; NP → Det N | N; VP → V NP</td></tr><tr><td>Lexicon</td><td>Det → A; N → restaurant | Dosas; V → serves</td></tr></tbody></table></div><h4>To find</h4><p>A derivation and parse tree.</p></div><h4>Formula and why it applies</h4><p>Expand the leftmost nonterminal; choose NP→Det N for the subject and NP→N for the object.</p><p>The object has no determiner, so forcing NP→Det N there would fail.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start and expand S</h5><p>S ⇒ NP VP</p></div><div class=\"step\"><h5>Step 2. Choose the subject NP</h5><p>⇒ Det N VP</p></div><div class=\"step\"><h5>Step 3. Match A</h5><p>⇒ A N VP</p></div><div class=\"step\"><h5>Step 4. Match restaurant</h5><p>⇒ A restaurant VP</p></div><div class=\"step\"><h5>Step 5. Expand the VP</h5><p>⇒ A restaurant V NP</p></div><div class=\"step\"><h5>Step 6. Match serves</h5><p>⇒ A restaurant serves NP</p></div><div class=\"step\"><h5>Step 7. Choose the object NP rule</h5><p>⇒ A restaurant serves N</p></div><div class=\"step\"><h5>Step 8. Match Dosas</h5><p>⇒ A restaurant serves Dosas</p></div><div class=\"step\"><h5>Step 9. Draw the successful tree</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Parse tree: A restaurant serves Dosas\" viewBox=\"0 0 450 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Parse tree: A restaurant serves Dosas</title><line x1=\"225\" y1=\"40\" x2=\"115\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"170\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"225\" y1=\"40\" x2=\"335\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"335\" y1=\"104\" x2=\"280\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"335\" y1=\"104\" x2=\"390\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"168\" x2=\"390\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"232\" x2=\"390\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"225\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"115\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">A</text><text x=\"170\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">restaurant</text><text x=\"335\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"280\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">serves</text><text x=\"390\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"390\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"390\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">Dosas</text></svg></div><figcaption>Parse tree: A restaurant serves Dosas</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> The parse succeeds with subject NP→Det N and object NP→N.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using S→NP VP|VP, NP→Det N, VP→V NP, Det→that, N→book|flight and V→book, derive the imperative “book that flight” and explain the role of book.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Rule type</th><th>Rules</th></tr></thead><tbody><tr><td>Structure</td><td>S → NP VP | VP; NP → Det N; VP → V NP</td></tr><tr><td>Lexicon</td><td>Det → that; N → book | flight; V → book</td></tr></tbody></table></div><h4>To find</h4><p>The successful derivation, tree and POS of book.</p></div><h4>Formula and why it applies</h4><p>Choose a production for S that can derive the actual input; an imperative may consist of VP.</p><p>The grammar allows book as both noun and verb, but this imperative needs the verb reading.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Choose the imperative sentence rule</h5><p>S ⇒ VP</p></div><div class=\"step\"><h5>Step 2. Expand the verb phrase</h5><p>⇒ V NP</p></div><div class=\"step\"><h5>Step 3. Choose the verb book</h5><p>⇒ book NP</p></div><div class=\"step\"><h5>Step 4. Expand the object</h5><p>⇒ book Det N</p></div><div class=\"step\"><h5>Step 5. Match that</h5><p>⇒ book that N</p></div><div class=\"step\"><h5>Step 6. Match flight</h5><p>⇒ book that flight</p></div><div class=\"step\"><h5>Step 7. Draw the tree</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Imperative parse: book that flight\" viewBox=\"0 0 360 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Imperative parse: book that flight</title><line x1=\"142.5\" y1=\"40\" x2=\"142.5\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"142.5\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"142.5\" y1=\"104\" x2=\"225\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"225\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"232\" x2=\"170\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"225\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"232\" x2=\"280\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"142.5\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"142.5\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">book</text><text x=\"225\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"170\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">that</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"280\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">flight</text></svg></div><figcaption>Imperative parse: book that flight</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> book is V; that flight is NP; S→VP derives the imperative.</div></section>"},{"id":"shift-reduce-theory","title":"Shift-reduce bottom-up parsing: stack, input and actions","html":"<p><strong>Bottom-up parsing</strong> starts from the input tokens and combines them into larger constituents until the start symbol is reached. A <strong>shift-reduce parser</strong> maintains a stack of recognized material and a list of remaining input tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Action</th><th>Exact operation</th><th>Example</th></tr></thead><tbody><tr><td>Shift</td><td>Move the next input token onto the stack</td><td>Stack: the; remaining input: dog runs</td></tr><tr><td>Reduce</td><td>Replace a suffix of the stack matching a rule's RHS with its LHS</td><td>Det N becomes NP using NP→Det N</td></tr><tr><td>Accept</td><td>Stack is S and input is exhausted</td><td>Stack: S; input: empty</td></tr><tr><td>Fail/backtrack</td><td>Chosen reductions cannot complete a parse</td><td>A noun reading of book blocks an imperative parse</td></tr></tbody></table></div><p>Reduction uses a production in reverse: the grammar NP→Det N expands an NP top-down, but reduces Det N into NP bottom-up. The stack's <strong>rightmost item is its top</strong> in the traces below. Each row shows the state <strong>after</strong> the listed action, avoiding an off-by-one mismatch between actions and stack contents.</p><p>A lexical reduction such as N→dog still counts as a reduction. Do not skip the sequence from word to category to phrase when the question asks for a complete trace. Backtracking means returning to an earlier choice and trying another applicable rule, not changing the original input.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Shift = input se stack. Reduce = chhote pieces se bada grammatical unit.</p>"},{"id":"shift-reduce-examples","title":"Three full shift-reduce traces","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Show a complete shift-reduce parse of “the big dog sees the cat” using S→NP VP, NP→Det N|Det Adj N, VP→V NP, Det→the, Adj→big, N→dog|cat and V→sees.</strong></p><div class=\"given\"><h4>Given</h4><p>Grammar is as specified. Stack starts empty; input is the big dog sees the cat. Top of stack is on the right.</p><h4>To find</h4><p>The stack, remaining input and action at every step.</p></div><h4>Formula and why it applies</h4><p>Shift tokens; reduce matched right-hand sides to their left-hand nonterminals.</p><p>The first noun phrase includes an adjective and must use NP→Det Adj N.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Trace each action</h5><div class=\"table-wrap\"><table><thead><tr><th>Step / action</th><th>Stack after action</th><th>Remaining input</th></tr></thead><tbody><tr><td>0. Start</td><td>∅</td><td>the big dog sees the cat</td></tr><tr><td>1. Shift the</td><td>the</td><td>big dog sees the cat</td></tr><tr><td>2. Reduce Det→the</td><td>Det</td><td>big dog sees the cat</td></tr><tr><td>3. Shift big</td><td>Det big</td><td>dog sees the cat</td></tr><tr><td>4. Reduce Adj→big</td><td>Det Adj</td><td>dog sees the cat</td></tr><tr><td>5. Shift dog</td><td>Det Adj dog</td><td>sees the cat</td></tr><tr><td>6. Reduce N→dog</td><td>Det Adj N</td><td>sees the cat</td></tr><tr><td>7. Reduce NP→Det Adj N</td><td>NP</td><td>sees the cat</td></tr><tr><td>8. Shift sees</td><td>NP sees</td><td>the cat</td></tr><tr><td>9. Reduce V→sees</td><td>NP V</td><td>the cat</td></tr><tr><td>10. Shift the</td><td>NP V the</td><td>cat</td></tr><tr><td>11. Reduce Det→the</td><td>NP V Det</td><td>cat</td></tr><tr><td>12. Shift cat</td><td>NP V Det cat</td><td>∅</td></tr><tr><td>13. Reduce N→cat</td><td>NP V Det N</td><td>∅</td></tr><tr><td>14. Reduce NP→Det N</td><td>NP V NP</td><td>∅</td></tr><tr><td>15. Reduce VP→V NP</td><td>NP VP</td><td>∅</td></tr><tr><td>16. Reduce S→NP VP</td><td>S</td><td>∅</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Check acceptance</h5><p>Input is empty and stack is exactly S; therefore accept.</p></div><div class=\"step\"><h5>Step 3. Draw the resulting structure</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Parse tree: the big dog sees the cat\" viewBox=\"0 0 670 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Parse tree: the big dog sees the cat</title><line x1=\"321.25\" y1=\"40\" x2=\"170\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"104\" x2=\"170\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"104\" x2=\"280\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"321.25\" y1=\"40\" x2=\"472.5\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"472.5\" y1=\"104\" x2=\"390\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"168\" x2=\"390\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"472.5\" y1=\"104\" x2=\"555\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"555\" y1=\"168\" x2=\"500\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"500\" y1=\"232\" x2=\"500\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"555\" y1=\"168\" x2=\"610\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"610\" y1=\"232\" x2=\"610\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"321.25\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"170\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">the</text><text x=\"170\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Adj</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">big</text><text x=\"280\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">dog</text><text x=\"472.5\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"390\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"390\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">sees</text><text x=\"555\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"500\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"500\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">the</text><text x=\"610\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"610\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">cat</text></svg></div><figcaption>Parse tree: the big dog sees the cat</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> Accepted. The parser builds both noun phrases, then VP, then S.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use S→NP VP, NP→Det N, VP→V NP, Det→the|this, N→man|book and V→read to give a shift-reduce trace for “the man read this book”.</strong></p><div class=\"given\"><h4>Given</h4><p>The input has five tokens. Stack is empty initially. The lexical verb read is supplied by V→read.</p><h4>To find</h4><p>A complete bottom-up trace.</p></div><h4>Formula and why it applies</h4><p>Reduce only when the top stack sequence matches a supplied production's right side.</p><p>Both noun phrases follow Det N, and the verb phrase follows V NP.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Trace all operations</h5><div class=\"table-wrap\"><table><thead><tr><th>Step / action</th><th>Stack after action</th><th>Remaining input</th></tr></thead><tbody><tr><td>0. Start</td><td>∅</td><td>the man read this book</td></tr><tr><td>1. Shift the</td><td>the</td><td>man read this book</td></tr><tr><td>2. Reduce Det→the</td><td>Det</td><td>man read this book</td></tr><tr><td>3. Shift man</td><td>Det man</td><td>read this book</td></tr><tr><td>4. Reduce N→man</td><td>Det N</td><td>read this book</td></tr><tr><td>5. Reduce NP→Det N</td><td>NP</td><td>read this book</td></tr><tr><td>6. Shift read</td><td>NP read</td><td>this book</td></tr><tr><td>7. Reduce V→read</td><td>NP V</td><td>this book</td></tr><tr><td>8. Shift this</td><td>NP V this</td><td>book</td></tr><tr><td>9. Reduce Det→this</td><td>NP V Det</td><td>book</td></tr><tr><td>10. Shift book</td><td>NP V Det book</td><td>∅</td></tr><tr><td>11. Reduce N→book</td><td>NP V Det N</td><td>∅</td></tr><tr><td>12. Reduce NP→Det N</td><td>NP V NP</td><td>∅</td></tr><tr><td>13. Reduce VP→V NP</td><td>NP VP</td><td>∅</td></tr><tr><td>14. Reduce S→NP VP</td><td>S</td><td>∅</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Verify the final state</h5><p>The complete sentence has reduced to S with no input left.</p></div><div class=\"answer\"><strong>Final answer.</strong> Accepted. Subject: the man. Predicate: read this book. Object: this book.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Parse “book the flight” bottom-up using S→NP VP|VP, NP→Det N, VP→V NP, Det→the, N→book|flight, V→book. Explain why choosing the noun reading first can fail and show the successful alternative.</strong></p><div class=\"given\"><h4>Given</h4><p>book has two lexical categories N and V. The input is an imperative. Stack starts empty.</p><h4>To find</h4><p>The failed choice and a complete successful trace with backtracking.</p></div><h4>Formula and why it applies</h4><p>Try lexical reductions allowed by the grammar; on a dead end, return to the ambiguous choice and try another.</p><p>Grammar ambiguity requires a search choice. The noun reading cannot supply the required imperative verb.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Show the noun-first dead end</h5><p>Shift book and reduce it to N. Continue shifting/reducing the flight to Det N. Reducing Det N→NP leaves stack N NP and empty input. No supplied rule reduces N NP into S, so this branch fails.</p></div><div class=\"step\"><h5>Step 2. Return to the lexical choice</h5><p>Restore the state just after shifting book, then choose V→book instead of N→book.</p></div><div class=\"step\"><h5>Step 3. Trace the successful branch</h5><div class=\"table-wrap\"><table><thead><tr><th>Step / action</th><th>Stack after action</th><th>Remaining input</th></tr></thead><tbody><tr><td>0. Restored after shifting book</td><td>book</td><td>the flight</td></tr><tr><td>1. Reduce V→book</td><td>V</td><td>the flight</td></tr><tr><td>2. Shift the</td><td>V the</td><td>flight</td></tr><tr><td>3. Reduce Det→the</td><td>V Det</td><td>flight</td></tr><tr><td>4. Shift flight</td><td>V Det flight</td><td>∅</td></tr><tr><td>5. Reduce N→flight</td><td>V Det N</td><td>∅</td></tr><tr><td>6. Reduce NP→Det N</td><td>V NP</td><td>∅</td></tr><tr><td>7. Reduce VP→V NP</td><td>VP</td><td>∅</td></tr><tr><td>8. Reduce S→VP</td><td>S</td><td>∅</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 4. Accept the alternative</h5><p>The verb reading produces S and consumes all tokens.</p></div><div class=\"answer\"><strong>Final answer.</strong> The noun-first branch fails; backtracking to book/V yields the successful imperative parse.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Wrong branch fail hua toh sentence wrong nahi; next legal rule try karo.</p></section>"}]},{"id":"m2-ner","title":"Named Entity Recognition","unit":4,"scope":"Unit 4, pages 117–128","sections":[{"id":"ner-definition","title":"Entity spans, categories and context","html":"<p><strong>Named Entity Recognition (NER)</strong> identifies text spans referring to entities and assigns their types, such as PERSON, ORGANIZATION and LOCATION. Many practical schemas also include DATE, TIME, MONEY or domain-specific types. The exact allowed labels depend on the application's annotation scheme.</p><p>NER has two parts: <strong>boundary detection</strong> finds where the entity starts and ends; <strong>classification</strong> assigns the appropriate type. A multiword name should normally be one entity span: “New York” is a location span, not two unrelated location decisions.</p><div class=\"flow\"><div class=\"node\">Text: Mary joined Google in New York on Monday.</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Mary → PERSON</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Google → ORGANIZATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New York → LOCATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Monday → DATE</div></div><p>Not every noun is a named entity. In “a developer works at Google”, developer is an ordinary job description while Google is a named organization. A specialized HR system may define a JOB_TITLE category, but it must state that schema explicitly. NER identifies mentions; entity linking is the separate task of connecting a mention to a unique database identity.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>POS</td><td>What grammatical role does this token have?</td><td>Google/NNP</td></tr><tr><td>Chunking</td><td>Which adjacent words form a phrase?</td><td>[NP a skilled developer]</td></tr><tr><td>NER</td><td>Which span names an entity, and of what type?</td><td>[Google] ORGANIZATION</td></tr><tr><td>Entity linking</td><td>Which real entity does this mention denote?</td><td>Connect Paris to the intended city or person record</td></tr></tbody></table></div><p><strong>Applications.</strong> NER structures search results and documents, extracts organizations/people from news, routes support tickets by product or organization, supports recommendation, and extracts specialized entities from healthcare or legal text. Context is essential: “Apple released a laptop” names an organization, while “she ate an apple” describes fruit.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER mein do kaam: naam kahan se kahan tak, aur kis category ka.</p>"},{"id":"ner-approaches","title":"Dictionary, rules, machine learning and deep learning","html":"<div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>How it works</th><th>Example</th><th>Main limitation</th></tr></thead><tbody><tr><td>Dictionary / gazetteer</td><td>Match text against lists of known names</td><td>A city list includes Mumbai and Pune</td><td>New names, spelling variants and ambiguous names are missed</td></tr><tr><td>Rule-based</td><td>Use word shapes, regular expressions and context</td><td>A title such as Dr. followed by a name-like span suggests PERSON</td><td>Manual maintenance; exceptions and domain/language dependence</td></tr><tr><td>Machine learning</td><td>Learn a labeling rule from annotated examples using features</td><td>Capitalization, suffixes, POS and surrounding words help a classifier/CRF</td><td>Requires labeled data and useful features</td></tr><tr><td>Deep learning</td><td>Learn contextual word/character representations and predict labels</td><td>A contextual sequence encoder labels multiword entity spans</td><td>Training/domain dependence and resource demands</td></tr></tbody></table></div><p>A <strong>pattern-based rule</strong> examines the form of text, such as an email pattern or a date format. A <strong>context-based rule</strong> examines neighboring words: “Dr.” can support a following PERSON span, while “headquartered in” can support a following LOCATION span. Capitalization alone is insufficient because sentence-initial common nouns are also capitalized.</p><p>A dictionary may find “May” as a person's name, but “in May” may refer to a month. A learned model uses surrounding evidence to disambiguate. Hybrid systems can combine dictionaries, rules and learned models; these categories are practical tools rather than mutually exclusive restrictions.</p><p><strong>Preprocessing for NER.</strong> Tokenize while preserving token offsets and useful capitalization. Blindly removing capital letters or stopwords before recognition can damage names such as “Bank of India”. NER output should preserve the original span so the reader can locate it in the input.</p><p><strong>Exam-ready 3-mark answer.</strong> NER locates named-entity spans and classifies them into categories such as person, organization and location. A dictionary-based approach matches known name lists; a rule-based approach uses patterns or context; machine-learning and deep-learning approaches learn entity decisions from labeled data and representations. For example, in “Mary works at Google in Mumbai”, Mary is PERSON, Google is ORGANIZATION and Mumbai is LOCATION.</p>"},{"id":"ner-worked-examples","title":"Three complete entity-recognition examples","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Identify PERSON, ORGANIZATION and LOCATION entities in “Asha Rao joined Infosys in Bengaluru.”</strong></p><div class=\"given\"><h4>Given</h4><p>Sentence: Asha Rao joined Infosys in Bengaluru. Allowed entity types: PERSON, ORGANIZATION, LOCATION.</p><h4>To find</h4><p>Complete entity spans and labels.</p></div><h4>Formula and why it applies</h4><p>Find the span first, then assign its type from context.</p><p>A multiword personal name is a single entity; the verb and preposition remain outside entities.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the person span</h5><p>Asha Rao names the person who joined, so take both words together.</p></div><div class=\"step\"><h5>Step 2. Identify the organization</h5><p>Infosys is the organization joined.</p></div><div class=\"step\"><h5>Step 3. Identify the location</h5><p>Bengaluru names the city.</p></div><div class=\"step\"><h5>Step 4. Write the output</h5><div class=\"table-wrap\"><table><thead><tr><th>Span</th><th>Label</th></tr></thead><tbody><tr><td>Asha Rao</td><td>PERSON</td></tr><tr><td>Infosys</td><td>ORGANIZATION</td></tr><tr><td>Bengaluru</td><td>LOCATION</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> [Asha Rao]PERSON joined [Infosys]ORGANIZATION in [Bengaluru]LOCATION.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using PERSON, ORGANIZATION, LOCATION and DATE, identify entities in “Dr. Meera Shah visited New Delhi on 5 October 2026.” Treat professional titles as outside the PERSON span for this exercise.</strong></p><div class=\"given\"><h4>Given</h4><p>Allowed types and title-boundary convention are specified. Tokens include a multiword name, city and date.</p><h4>To find</h4><p>Entity boundaries and types.</p></div><h4>Formula and why it applies</h4><p>Boundary rules come from the annotation schema; use the stated title convention.</p><p>Dr. supplies context for a person but is excluded from that span here.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the person</h5><p>Meera Shah is the PERSON span; Dr. is outside by instruction.</p></div><div class=\"step\"><h5>Step 2. Locate the location</h5><p>New Delhi is one LOCATION span.</p></div><div class=\"step\"><h5>Step 3. Locate the date</h5><p>5 October 2026 is one DATE span.</p></div><div class=\"step\"><h5>Step 4. Check organization mentions</h5><p>No organization is named in this sentence.</p></div><div class=\"answer\"><strong>Final answer.</strong> Meera Shah→PERSON; New Delhi→LOCATION; 5 October 2026→DATE.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Explain the entity label of Apple in “Apple opened an office in Mumbai” and apple in “Ravi ate an apple”. Use PERSON, ORGANIZATION and LOCATION only.</strong></p><div class=\"given\"><h4>Given</h4><p>Two contexts contain the same surface word apart from capitalization. The schema contains no FOOD category.</p><h4>To find</h4><p>Contextual labels and the ordinary noun case.</p></div><h4>Formula and why it applies</h4><p>NER labels a mention in context, not every occurrence of a dictionary string identically.</p><p>A company can open an office; the object eaten in the second sentence is a fruit.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Analyze the first sentence</h5><p>Apple refers to the company, so label it ORGANIZATION. Mumbai is LOCATION.</p></div><div class=\"step\"><h5>Step 2. Analyze the second sentence</h5><p>Ravi is PERSON. apple is an ordinary fruit noun and receives no entity label under this schema.</p></div><div class=\"step\"><h5>Step 3. State the dictionary limitation</h5><p>Blindly labeling every apple as an organization would produce a false positive.</p></div><div class=\"answer\"><strong>Final answer.</strong> First: Apple→ORGANIZATION, Mumbai→LOCATION. Second: Ravi→PERSON; apple is outside the entity types.</div></section>"}]},{"id":"u5-meaning","title":"Word meaning, lexical relations and WordNet","unit":5,"mode":"both","scope":"Unit 5 · PDF pages 1–22","sections":[{"id":"u5-words","title":"Lexeme, lemma, sense and context","html":"<p><strong>Semantics is the study of meaning in language.</strong> Lexical semantics studies meanings of words and relationships between their meanings. Sentence semantics studies how word meanings and sentence structure combine.</p><p>A <strong>word form</strong> is what appears in the sentence. A <strong>lexeme</strong> is the underlying vocabulary item whose grammatical forms belong together. A <strong>lemma</strong> is the dictionary form used to name it. A <strong>sense</strong> is one particular meaning.</p><table><thead><tr><th>Term</th><th>Example</th><th>What to understand</th></tr></thead><tbody><tr><td>Word forms</td><td>run, runs, ran, running</td><td>Different grammatical forms</td></tr><tr><td>Lexeme</td><td>RUN</td><td>The shared underlying vocabulary item</td></tr><tr><td>Lemma</td><td>run</td><td>Dictionary heading</td></tr><tr><td>Sense</td><td>run a race / run a business</td><td>Different meanings need context</td></tr><tr><td>Lexicon</td><td>A language's vocabulary resource</td><td>Stores lexical items and information about them</td></tr></tbody></table><p>The four forms <em>run, ran, runs, running</em> belong to the same lexeme. They are not four unrelated lexemes. “I deposited cash in the bank” and “We sat by the bank of the river” contain the same written form but different senses.</p><div class=\"flow\"><div class=\"node\">word: bank</div><span aria-hidden=\"true\">→</span><div class=\"node\">context: cash, deposit</div><span aria-hidden=\"true\">→</span><div class=\"node\">sense: financial institution</div></div><p><strong>Syntax</strong> asks how words are arranged. <strong>Semantics</strong> asks what the expression means. <strong>Pragmatics</strong> uses situation and speaker intention: “Can you open the window?” is grammatically a question about ability but is normally a request.</p><p class=\"cue\">Form = jo likha; lemma = dictionary naam; sense = iss sentence mein matlab.</p>"},{"id":"u5-relations","title":"Every lexical relation with examples","html":"<p><strong>A lexical relation connects words or senses by a meaning relationship.</strong> State the relation and its direction before giving the example.</p><table><thead><tr><th>Relation</th><th>Exam definition</th><th>Examples and direction</th></tr></thead><tbody><tr><td>Homonymy</td><td>The same form has unrelated meanings.</td><td>bank: financial institution / river edge; bat: animal / sports implement</td></tr><tr><td>Polysemy</td><td>One lexical item has multiple related senses.</td><td>head: body part / head of a department; paper: material / article</td></tr><tr><td>Synonymy</td><td>Different words have identical or closely similar meanings in a specified sense.</td><td>sofa / couch; automobile / car</td></tr><tr><td>Antonymy</td><td>Words have opposite meanings.</td><td>hot / cold; alive / dead; buy / sell</td></tr><tr><td>Hyponymy</td><td>A more specific concept is a type of a more general one.</td><td>rose is a flower; car is a vehicle</td></tr><tr><td>Hypernymy</td><td>A broader concept includes a more specific one.</td><td>flower is a hypernym of rose</td></tr><tr><td>Meronymy</td><td>A concept is a part of another concept.</td><td>wheel is part of car; finger is part of hand</td></tr><tr><td>Holonymy</td><td>A concept is the whole containing a part.</td><td>car is a holonym of wheel</td></tr></tbody></table><h3>How to distinguish the commonly confused pairs</h3><p>For homonymy versus polysemy, ask whether the senses share an identifiable meaning. A river bank and a financial bank are unrelated. A financial bank and a blood bank share a repository/storage idea, illustrating polysemy in the supplied notes.</p><p>For hyponymy versus meronymy, use the sentence test: <strong>“X is a kind of Y”</strong> indicates hyponymy; <strong>“X is part of Y”</strong> indicates meronymy. A wheel is not a type of car.</p><table><thead><tr><th>Expression</th><th>Correct relation</th><th>Reason</th></tr></thead><tbody><tr><td>sparrow → bird</td><td>Hyponymy</td><td>A sparrow is a kind of bird</td></tr><tr><td>bird → sparrow</td><td>Hypernymy</td><td>Bird is the broader category</td></tr><tr><td>keyboard → computer</td><td>Meronymy</td><td>Keyboard is a component</td></tr><tr><td>computer → keyboard</td><td>Holonymy</td><td>Computer is the containing whole</td></tr><tr><td>mouth of a person / mouth of a river</td><td>Polysemy</td><td>Both senses share the idea of an opening; the river use is a related extension</td></tr></tbody></table><p>Synonyms are not always interchangeable in every context or register. “Big mistake” and “large mistake” can sound different even though big and large overlap in meaning. Antonyms can be gradable (hot/cold), complementary (alive/dead) or relational converses (buy/sell).</p><p class=\"cue\">HYPO = specific type; HYPER = bigger category. MERO = part; HOLO = whole.</p>"},{"id":"u5-wordnet","title":"WordNet: synsets, glosses and hierarchy","html":"<p><strong>WordNet is a lexical database that groups word senses into synonym sets called synsets and links them through semantic and lexical relations.</strong> It is a network of meanings, not merely a list of similar spellings.</p><p>A synset represents one concept. Its <strong>lemmas</strong> are the words that can express that concept. A <strong>gloss</strong> is a short definition, often accompanied by an example. An ambiguous word can occur in several synsets.</p><div class=\"flow\"><div class=\"node\">vehicle (general)</div><span aria-hidden=\"true\">→</span><div class=\"node\">car / automobile (same concept)</div><span aria-hidden=\"true\">→</span><div class=\"node\">sports car (specific)</div></div><p>This is a simplified teaching hierarchy, not a claim about every intermediate WordNet node. Going upward reaches hypernyms; going downward reaches hyponyms. Multiple parents can exist, so the structure need not be a single simple tree.</p><table><thead><tr><th>Operation</th><th>Meaning</th><th>Illustration</th></tr></thead><tbody><tr><td>Get senses of a word</td><td>Find candidate synsets</td><td>bank → financial sense, river-edge sense, …</td></tr><tr><td>Get lemmas</td><td>Find synonyms within one synset</td><td>car, automobile, motorcar</td></tr><tr><td>Get definition/examples</td><td>Read the gloss and uses</td><td>Choose the intended concept</td></tr><tr><td>Get hypernyms</td><td>Move to broader categories</td><td>car → vehicle</td></tr><tr><td>Get hyponyms</td><td>Move to narrower categories</td><td>vehicle → particular vehicle categories</td></tr><tr><td>Get meronyms/holonyms</td><td>Find part/whole links</td><td>car ↔ wheel</td></tr></tbody></table><h3>WordNet versus a thesaurus</h3><p>A thesaurus mainly groups related expressions for vocabulary lookup. WordNet explicitly distinguishes senses and labels relations such as hypernymy, hyponymy and meronymy. This supports WSD, query expansion, lexical similarity and semantic search.</p><h3>Three uses explained</h3><ol><li><strong>Search expansion:</strong> a query for “automobile” can retrieve relevant documents using “car”. Expansion should use the right sense.</li><li><strong>WSD:</strong> definitions of the senses of “bank” provide words that can be compared with the sentence context.</li><li><strong>Similarity:</strong> concepts near one another in an “is-a” hierarchy tend to be semantically related. Path-based measures depend on which senses were selected.</li></ol><p class=\"cue\">WordNet mein spelling ka group nahi—meaning ka synset, aur meanings ke beech labelled links.</p>"}]},{"id":"u5-wsd","title":"Word sense disambiguation: Lesk, Walker and graph methods","unit":5,"mode":"both","scope":"Unit 5 · PDF pages 23–48","sections":[{"id":"u5-wsd-basics","title":"What WSD solves and how approaches differ","html":"<p><strong>Word sense disambiguation (WSD) is the task of selecting the intended sense of an ambiguous word in its context from a set of possible senses.</strong> The output is a sense label, not a different replacement word.</p><div class=\"flow\"><div class=\"node\">Input: “He grilled the bass.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">Candidate senses: fish / low sound</div><span aria-hidden=\"true\">→</span><div class=\"node\">Context: grilled</div><span aria-hidden=\"true\">→</span><div class=\"node\">Output: fish sense</div></div><p>The <strong>target word</strong> is the ambiguous word. The <strong>context</strong> is the surrounding evidence. The <strong>sense inventory</strong> lists candidate meanings, often using WordNet. A <strong>feature</strong> is a usable clue: nearby word, position, part-of-speech tag or a phrase.</p><table><thead><tr><th>Approach</th><th>What it needs</th><th>How it decides</th><th>Limitation</th></tr></thead><tbody><tr><td>Knowledge based</td><td>Dictionary, thesaurus or semantic graph</td><td>Definition overlap, category evidence or graph scores</td><td>Short definitions and missing knowledge</td></tr><tr><td>Supervised</td><td>Examples already labelled with senses</td><td>Learns context → sense mapping</td><td>Labelling cost, limited rare-sense examples</td></tr><tr><td>Semi-supervised</td><td>Small labelled set plus unlabelled data</td><td>Bootstraps from reliable seed examples</td><td>Early errors can spread</td></tr><tr><td>Unsupervised sense induction</td><td>Unlabelled contextual occurrences</td><td>Clusters similar contexts</td><td>Clusters are not automatically named dictionary senses</td></tr><tr><td>Neural/contextual</td><td>Learned word/context representations</td><td>Predicts or compares a context representation</td><td>Needs suitable data/model and evaluation</td></tr></tbody></table><p><strong>Bag-of-words features</strong> record nearby words while ignoring exact positions. <strong>Collocational features</strong> preserve a positional phrase such as “river bank”, “bank account”, “chocolate bar” or “bar exam”.</p><h3>Why WSD matters</h3><p>Machine translation needs the correct target-language meaning; information retrieval should distinguish river-bank travel from banking services; text-to-speech may need different pronunciations for “bass”; information extraction should avoid connecting entities through the wrong relation.</p><p class=\"cue\">WSD: same spelling ke options mein context dekh ke sahi meaning select.</p>"},{"id":"u5-lesk","title":"Lesk algorithm, from words to overlap scores","html":"<p><strong>Lesk is a knowledge-based WSD method that chooses senses whose dictionary descriptions have the greatest overlap with contextual evidence.</strong> Original Lesk compares definitions of neighbouring words' senses. A common simplified version compares each target-sense gloss directly with the sentence context. State which version you use.</p><h3>Simplified Lesk procedure</h3><ol><li>Remove the target word from the context; tokenize and normalize the remaining content words.</li><li>Obtain the gloss for each candidate sense and apply the same normalization.</li><li>Count shared words between the context and each gloss.</li><li>Select the sense with maximum overlap. If scores tie, report the tie or use a specified tie-break rule.</li></ol><div class=\"math-display\"><img src=\"math/691fb54513999f0d.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|,\\qquad s^*=\\arg\\max_s\\operatorname{score}(s)\" style=\"width:45.416ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b5a9729b8c25c0f7.svg\" alt=\"C\" style=\"width:1.719ex;height:1.645ex\" loading=\"lazy\" decoding=\"async\"></span> is the set of context words, <span class=\"math-inline\"><img src=\"math/a5684e27b28daffa.svg\" alt=\"G_s\" style=\"width:2.716ex;height:1.95ex\" loading=\"lazy\" decoding=\"async\"></span> the set of words in sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>'s gloss, <span class=\"math-inline\"><img src=\"math/c7de95563fc530c3.svg\" alt=\"\\cap\" style=\"width:1.509ex;height:1.403ex\" loading=\"lazy\" decoding=\"async\"></span> means common elements, <span class=\"math-inline\"><img src=\"math/468f3b6d2f1b95a0.svg\" alt=\"|\\cdot|\" style=\"width:2.892ex;height:2.26ex\" loading=\"lazy\" decoding=\"async\"></span> means count, and <span class=\"math-inline\"><img src=\"math/dfccac0c4f581832.svg\" alt=\"\\arg\\max\" style=\"width:7.737ex;height:1.491ex\" loading=\"lazy\" decoding=\"async\"></span> means “the sense giving the largest score”. This version counts unique matching words once.</p><div class=\"example\"><p><strong>Question. Use simplified Lesk to disambiguate “bank” in “The river water rose near the bank.” Use C = {river, water, rose, near}; financial gloss = {institution, money, deposit}; river gloss = {land, river, water, edge}.</strong></p><div class=\"given\"><h4>Given</h4><p>The normalized context and two gloss sets are given. Count exact shared words.</p><h4>To find</h4><p>The score of each sense and the selected meaning.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because the task specifies context–gloss overlap.</p><div class=\"step\"><h4>Step 1. Compare the financial sense</h4><p>No word occurs in both {river, water, rose, near} and {institution, money, deposit}. Overlap = {}.</p></div><div class=\"step\"><h4>Step 2. Count the financial score</h4><p><span class=\"math-inline\"><img src=\"math/bdc75dbcd361db69.svg\" alt=\"\\operatorname{score}(F)=0\" style=\"width:12.522ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare the river sense</h4><p>Shared words are {river, water}. “Rose” and “near” are not in the gloss.</p></div><div class=\"step\"><h4>Step 4. Count and select</h4><p><span class=\"math-inline\"><img src=\"math/384740febd8dd4b0.svg\" alt=\"\\operatorname{score}(R)=2\" style=\"width:12.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Since <span class=\"math-inline\"><img src=\"math/6e25b81ec200909a.svg\" alt=\"2&gt;0\" style=\"width:5.28ex;height:1.597ex\" loading=\"lazy\" decoding=\"async\"></span>, choose the river-edge sense.</p></div><p class=\"answer\"><strong>Answer.</strong> Bank means land beside a river.</p></div><div class=\"example\"><p><strong>Question. Use simplified Lesk for “The dog barked loudly.” Treat barked as bark. Context C = {dog, loudly}; sound gloss = {sharp, cry, dog}; tree gloss = {outer, covering, tree}; ship gloss = {sailing, ship}.</strong></p><div class=\"given\"><h4>Given</h4><p>Three glosses and normalized context {dog, loudly}.</p><h4>To find</h4><p>Select the sense of bark.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Lemmatization lets barked match the target lemma bark; it does not create additional overlap words.</p><div class=\"step\"><h4>Step 1. Sound sense</h4><p>Intersection = {dog}; score = 1.</p></div><div class=\"step\"><h4>Step 2. Tree sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 3. Ship sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>The sound sense has the unique maximum: 1 &gt; 0.</p></div><p class=\"answer\"><strong>Answer.</strong> Bark is the dog's cry.</p></div><div class=\"example\"><p><strong>Question. Apply definition–definition Lesk to “pine cone”. Pine senses: P1 = {evergreen, tree, needle, leaf}; P2 = {waste, sorrow, illness}. Cone senses: C1 = {solid, shape, circular}; C2 = {fruit, evergreen, tree}.</strong></p><div class=\"given\"><h4>Given</h4><p>Two candidate senses for each word. Tokens are already normalized; tree and trees would be reduced to the same form if necessary.</p><h4>To find</h4><p>The most compatible pair of senses.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/bb2259d0f8a3b048.svg\" alt=\"|G_{P_i}\\cap G_{C_j}|\" style=\"width:10.997ex;height:2.506ex\" loading=\"lazy\" decoding=\"async\"></span> for every pair because this is original-style gloss–gloss comparison.</p><div class=\"step\"><h4>Step 1. P1 with C1</h4><p>No shared word → 0.</p></div><div class=\"step\"><h4>Step 2. P1 with C2</h4><p>Shared {evergreen, tree} → 2.</p></div><div class=\"step\"><h4>Step 3. P2 with each cone sense</h4><p>P2–C1 has no overlap → 0; P2–C2 has no overlap → 0.</p></div><div class=\"step\"><h4>Step 4. Choose the best pair</h4><p>The four scores are 0, 2, 0, 0. Maximum 2 belongs to P1–C2.</p></div><p class=\"answer\"><strong>Answer.</strong> Pine is the evergreen tree; cone is its fruit-like reproductive structure.</p></div><p><strong>Limitations:</strong> exact overlap misses synonyms, short glosses may produce zeros, and different preprocessing choices change the score. Extended Lesk may include related synset definitions or longer phrase overlaps; do not silently substitute it for a simple question.</p><p class=\"cue\">Lesk: context aur dictionary mein common words gino; sabse bada overlap jeeta.</p>"},{"id":"u5-walker","title":"Thesaurus / Walker approach, with three complete examples","html":"<p><strong>The Walker approach uses thesaurus categories as semantic evidence.</strong> Associate each candidate sense with a category. Count or weight context words that support that category. Choose the largest total.</p><div class=\"math-display\"><img src=\"math/9d7b8384c080650b.svg\" alt=\"\\operatorname{score}(s)=\\sum_{w\\in C} I(w,\\operatorname{category}(s))\" style=\"width:31.274ex;height:4.963ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b186266d0d476166.svg\" alt=\"I=1\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> if the supplied category mapping says the context word supports the sense, otherwise <span class=\"math-inline\"><img src=\"math/5fd951e2f99cd39c.svg\" alt=\"I=0\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>. The summation symbol means add all those contributions. Weighted questions may replace 1 with a supplied weight. Category membership must be supplied or justified; it is not guessed from word frequency.</p><div class=\"example\"><p><strong>Question. Disambiguate bank using Walker scoring. Context words are money, interest, annum, fetch. The finance category supports money, interest and annum; the location category supports none of these words.</strong></p><div class=\"given\"><h4>Given</h4><p>Two categories: Finance and Location. Each supported word contributes 1.</p><h4>To find</h4><p>The two totals and selected bank sense.</p></div><h4>Formula and why it applies</h4><p>Sum the category indicators for each sense.</p><div class=\"step\"><h4>Step 1. Make a contribution table</h4><table><thead><tr><th>Word</th><th>Finance</th><th>Location</th></tr></thead><tbody><tr><td>money</td><td>1</td><td>0</td></tr><tr><td>interest</td><td>1</td><td>0</td></tr><tr><td>annum</td><td>1</td><td>0</td></tr><tr><td>fetch</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Add Finance</h4><p><span class=\"math-inline\"><img src=\"math/6a517f05661478a7.svg\" alt=\"1+1+1+0=3\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Location</h4><p><span class=\"math-inline\"><img src=\"math/79d13a087a88c477.svg\" alt=\"0+0+0+0=0\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Select</h4><p>3 &gt; 0, so select the financial institution.</p></div><p class=\"answer\"><strong>Answer.</strong> Finance, with score 3 versus 0.</p></div><div class=\"example\"><p><strong>Question. Use Walker scoring for “The fisherman caught bass beside the lake.” Context {fisherman,caught,lake}. The Fish category contains all three clues; the Music category contains none.</strong></p><div class=\"given\"><h4>Given</h4><p>Fish and Music senses, binary category membership given.</p><h4>To find</h4><p>The correct bass sense.</p></div><h4>Formula and why it applies</h4><p>Score = sum of context-category matches.</p><div class=\"step\"><h4>Step 1. Record Fish matches</h4><p>fisherman → 1; caught → 1; lake → 1.</p></div><div class=\"step\"><h4>Step 2. Add Fish score</h4><p><span class=\"math-inline\"><img src=\"math/7e22dbf6b1c68d2b.svg\" alt=\"1+1+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Music score</h4><p><span class=\"math-inline\"><img src=\"math/f4ccd7a1f1f516c9.svg\" alt=\"0+0+0=0\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Choose</h4><p>Fish has the larger score.</p></div><p class=\"answer\"><strong>Answer.</strong> Bass refers to a fish.</p></div><div class=\"example\"><p><strong>Question. Score “The player used a bat in the match.” Context {player,match}. Sport supports both words with weights 2 and 1; Animal supports neither. Use the supplied weighted Walker scheme.</strong></p><div class=\"given\"><h4>Given</h4><p>Sport weights {player:2, match:1}; Animal weights {player:0, match:0}.</p><h4>To find</h4><p>Weighted sense scores.</p></div><h4>Formula and why it applies</h4><p>Use the sum of supplied weights, not an unweighted count, because the question explicitly gives weights.</p><div class=\"step\"><h4>Step 1. Sport contribution of player</h4><p>Add 2.</p></div><div class=\"step\"><h4>Step 2. Sport contribution of match</h4><p>Add 1. Sport total = 2 + 1 = 3.</p></div><div class=\"step\"><h4>Step 3. Animal total</h4><p>0 + 0 = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>3 &gt; 0 selects the sporting implement.</p></div><p class=\"answer\"><strong>Answer.</strong> Bat is the sports implement.</p></div><p class=\"cue\">Walker: dictionary ke exact words nahi, context kis topic/category ko support karta hai woh count.</p>"},{"id":"u5-graph","title":"Random-walk WSD and supervised alternatives","html":"<p><strong>Graph-based WSD represents candidate senses as vertices and semantic relationships as weighted edges.</strong> A random walk repeatedly transfers score along these edges. Senses supported by other strongly connected context senses tend to obtain higher ranks.</p><ol><li>Create a vertex for every candidate sense of every relevant word.</li><li>Connect semantically related senses; similarity or gloss overlap can set edge weights.</li><li>Normalize outgoing edge weights into transition probabilities.</li><li>Run a graph-ranking method such as PageRank.</li><li>For each target word, choose its highest-ranked candidate sense.</li></ol><div class=\"flow\"><div class=\"node\">church context</div><span aria-hidden=\"true\">→</span><div class=\"node\">bell: instrument sense ↔ ring: sound sense</div><span aria-hidden=\"true\">→</span><div class=\"node\">mutually supported senses receive rank</div></div><p>One common rank update is</p><div class=\"math-display\"><img src=\"math/58c328eed762e371.svg\" alt=\"r_{t+1}(j)=\\frac{1-d}{N}+d\\sum_i r_t(i)P(i\\rightarrow j).\" style=\"width:37.218ex;height:5.797ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/d0ac5d68953e63fb.svg\" alt=\"r_t(i)\" style=\"width:4.326ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is current score of vertex <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/2e580e2c56ce5fb8.svg\" alt=\"P(i\\to j)\" style=\"width:8.691ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is its outgoing probability to <span class=\"math-inline\"><img src=\"math/7a5268d94266eaaf.svg\" alt=\"j\" style=\"width:0.932ex;height:1.957ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/284cee6629b09719.svg\" alt=\"N\" style=\"width:2.009ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of vertices, and <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span> is the probability of following a graph edge. The remaining probability <span class=\"math-inline\"><img src=\"math/03ba8413969b1f03.svg\" alt=\"1-d\" style=\"width:5.073ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span> gives a uniform restart here. A personalized variant uses a nonuniform restart. The course requires the graph method concept; numerical details depend on supplied ranking rules.</p><div class=\"example\"><p><strong>Question. A two-vertex toy sense graph has transition matrix rows A:[0.2,0.8], B:[0.4,0.6]. Starting scores are A=0.5, B=0.5. Find one random-walk update with no restart.</strong></p><div class=\"given\"><h4>Given</h4><p>Rows denote source vertices, columns destination vertices. d = 1.</p><h4>To find</h4><p>New scores at A and B.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/1f9486c13badc4b9.svg\" alt=\"r_{t+1}(j)=\\sum_i r_t(i)P(i\\to j)\" style=\"width:26.063ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>: incoming contributions are added.</p><div class=\"step\"><h4>Step 1. Contribution to A from A</h4><p><span class=\"math-inline\"><img src=\"math/f5b0bcf0ed9035b5.svg\" alt=\"0.5\\times0.2=0.1\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Contribution to A from B</h4><p><span class=\"math-inline\"><img src=\"math/0a2405c4d5291b52.svg\" alt=\"0.5\\times0.4=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>, hence <span class=\"math-inline\"><img src=\"math/b3f4e8d5ae51ab54.svg\" alt=\"r_1(A)=0.1+0.2=0.3\" style=\"width:22.939ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Contribution to B from A and B</h4><p><span class=\"math-inline\"><img src=\"math/ce0a35fc09c4be55.svg\" alt=\"0.5\\times0.8=0.4\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ec4de7a9661ab386.svg\" alt=\"0.5\\times0.6=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Add B and verify total</h4><p><span class=\"math-inline\"><img src=\"math/4a0be788a6cd2a62.svg\" alt=\"r_1(B)=0.4+0.3=0.7\" style=\"width:22.96ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/76cecf94aaf6078d.svg\" alt=\"0.3+0.7=1\" style=\"width:12.697ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> A=0.3, B=0.7 after one update. This is one iteration, not a converged PageRank result.</p></div><h3>Other approaches explained without assuming ML knowledge</h3><p><strong>A supervised classifier</strong> learns from examples such as “cash … bank” labelled FINANCE and “river … bank” labelled RIVER. A decision list applies ranked context rules; a decision tree branches on clues; an SVM separates feature representations; a neural model learns contextual patterns. Naive Bayes, developed next, multiplies class-specific context probabilities.</p><p><strong>Semi-supervised bootstrapping</strong> begins with a few labelled examples or high-confidence rules, labels suitable unlabelled cases, and retrains. <strong>Unsupervised clustering</strong> groups usages by context similarity without gold sense labels; an additional mapping is needed to name the discovered groups.</p><p class=\"cue\">Graph WSD: meanings ko jodo; jo meaning context ke strong meanings se supported hai uska rank badhega.</p>"}]},{"id":"u5-naive-bayes","title":"Naive Bayes WSD: probabilities to a complete numerical","unit":5,"mode":"both","scope":"Unit 5 · PDF pages 49–57","sections":[{"id":"u5-bayes-meaning","title":"Prior, likelihood and posterior—before the formula","html":"<p><strong>A probability is a number from 0 to 1 measuring how likely an event is under a stated model.</strong> A class probability of <span class=\"math-inline\"><img src=\"math/ebc0c6fa20ed6a98.svg\" alt=\"3/6=0.5\" style=\"width:9.302ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> means 3 of 6 training examples belong to that class.</p><p><strong>Conditional probability</strong> means probability inside a restricted group. <span class=\"math-inline\"><img src=\"math/3e3b57b2d1341cd6.svg\" alt=\"P(\\text{loan}\\mid F)\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> reads “probability of the word loan given the finance sense”. The vertical bar means “given”; it is not division.</p><table><thead><tr><th>Symbol</th><th>Name</th><th>Plain meaning</th></tr></thead><tbody><tr><td><span class=\"math-inline\"><img src=\"math/b22ff6e7eb0a8abb.svg\" alt=\"P(F)\" style=\"width:5.154ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Prior</td><td>How common finance is before reading the new context</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/5d8f091329836633.svg\" alt=\"P(C\\mid F)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Likelihood</td><td>How compatible the observed context is with finance</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/6d368ab85d9177c5.svg\" alt=\"P(F\\mid C)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Posterior</td><td>How likely finance is after seeing the context</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/57aab4348bb4d572.svg\" alt=\"P(C)\" style=\"width:5.179ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Evidence</td><td>Total probability of this context under all senses</td></tr></tbody></table><div class=\"math-display\"><img src=\"math/d2028c752e4c5347.svg\" alt=\"P(F\\mid C)=\\frac{P(C\\mid F)P(F)}{P(C)}.\" style=\"width:27.314ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Bayes' theorem reverses a conditional direction using the prior. Do not swap <span class=\"math-inline\"><img src=\"math/6d368ab85d9177c5.svg\" alt=\"P(F\\mid C)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> and <span class=\"math-inline\"><img src=\"math/5d8f091329836633.svg\" alt=\"P(C\\mid F)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>: one asks about the sense, the other about the evidence.</p><p>The <strong>naive conditional independence assumption</strong> says that, once the sense is fixed, the context-word features can be multiplied as if they were independent. It is an approximation: natural-language words are not actually independent in general.</p><div class=\"flow\"><div class=\"node\">Training examples → count classes</div><span aria-hidden=\"true\">→</span><div class=\"node\">Prior per sense</div><span aria-hidden=\"true\">→</span><div class=\"node\">Count words within each sense</div><span aria-hidden=\"true\">→</span><div class=\"node\">Likelihood of query clues</div><span aria-hidden=\"true\">→</span><div class=\"node\">Multiply → compare → normalize if asked</div></div><p class=\"cue\">Prior = pehle kitna common; likelihood = clue kitna fit; posterior = clue dekhne ke baad meaning ki chance.</p>"},{"id":"u5-bayes-steps","title":"Multinomial Naive Bayes: the exact solving method","html":"<p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><h3>Always keep these counts separate</h3><p>Class priors use <strong>number of examples</strong>. Word likelihoods in this multinomial model use <strong>number of word occurrences</strong>. The vocabulary counts <strong>unique words across all classes</strong>.</p><ol><li>List the class examples and calculate priors.</li><li>Write one shared vocabulary and count its size.</li><li>Count total word occurrences in each class.</li><li>Count each query word in each class.</li><li>Apply the given smoothing rule.</li><li>Multiply each prior by all its query likelihoods.</li><li>Compare scores; divide each score by their sum only if a normalized posterior is requested.</li></ol><div class=\"math-display\"><img src=\"math/0fd59effd2bb7926.svg\" alt=\"P(s\\mid C)=\\frac{\\operatorname{score}(s)}{\\sum_{s&#39;}\\operatorname{score}(s&#39;)}.\" style=\"width:25.283ex;height:5.571ex\" loading=\"lazy\" decoding=\"async\"></div><p><strong>Why smoothing is needed:</strong> an unseen clue gives <span class=\"math-inline\"><img src=\"math/5d29fa66aa3ef2ee.svg\" alt=\"0/N_s=0\" style=\"width:9.166ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; one zero makes the whole product zero. Add-one smoothing redistributes probability across every vocabulary word and prevents these zero factors. Use it only when requested, taught for the task, or state the assumption.</p><p><strong>Different model warning:</strong> a Bernoulli Naive Bayes question counts presence/absence per document and may include absence factors. Do not use its denominator in a multinomial word-count question.</p><p class=\"cue\">Pehle sentences se prior; phir words se likelihood; dono counts mix mat kar.</p>"},{"id":"u5-bayes-mam","title":"Mam's bank numerical—every count and every multiplication","html":"<div class=\"example\"><p><strong>Question. Classify the sense of “bank” using the training table below. The sentence is: “As the stream flowed gently past the shore, we set up camp by the bank of the river, discussing the possibility of borrowing a loan to buy a boat for future trips.” Use only the highlighted feature words stream, shore and loan, and add-one multinomial smoothing.</strong></p><div class=\"given\"><h4>Given</h4><table><thead><tr><th>Training row</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>money, deposit, loan</td><td>Finance</td></tr><tr><td>2</td><td>river, water, shore</td><td>Riverbank</td></tr><tr><td>3</td><td>account, savings, investment</td><td>Finance</td></tr><tr><td>4</td><td>boat, river, stream</td><td>Riverbank</td></tr><tr><td>5</td><td>branch, deposit, check</td><td>Finance</td></tr><tr><td>6</td><td>fishing, shore, river</td><td>Riverbank</td></tr></tbody></table><p>Query feature set: {stream, shore, loan}. Other sentence words are not included as features in this supplied example.</p><h4>To find</h4><p>The most probable bank sense and normalized posteriors.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Calculate priors</h4><p>Finance appears in 3 of the 6 rows; Riverbank appears in 3 of 6.</p><div class=\"math-display\"><img src=\"math/2f05aa3a89468f5e.svg\" alt=\"P(F)=\\frac36=\\frac12,\\qquad P(R)=\\frac36=\\frac12.\" style=\"width:37.065ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Construct the vocabulary</h4><p>{money, deposit, loan, river, water, shore, account, savings, investment, boat, stream, fishing, branch, check}. Thus V=14. Repeated deposit or river is counted once in vocabulary.</p></div><div class=\"step\"><h4>Step 3. Count word occurrences per class</h4><p>There are 3 finance rows × 3 words = 9 word occurrences. There are 3 river rows × 3 words = 9. Thus <span class=\"math-inline\"><img src=\"math/2fe9227521f0d9d8.svg\" alt=\"N_F=N_R=9\" style=\"width:13.587ex;height:1.918ex\" loading=\"lazy\" decoding=\"async\"></span>, and each smoothed denominator is <span class=\"math-inline\"><img src=\"math/989b4387cd367e7a.svg\" alt=\"9+14=23\" style=\"width:11.439ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Count the three query words</h4><table><thead><tr><th>Word</th><th>Finance count</th><th>Riverbank count</th></tr></thead><tbody><tr><td>stream</td><td>0</td><td>1</td></tr><tr><td>shore</td><td>0</td><td>2</td></tr><tr><td>loan</td><td>1</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 5. Calculate finance likelihoods</h4><div class=\"math-display\"><img src=\"math/dece6048e91d14ee.svg\" alt=\"P(\\text{stream}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:29.034ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/48b17e3adf6f62bb.svg\" alt=\"P(\\text{shore}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:27.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/622a2e615b1ad17f.svg\" alt=\"P(\\text{loan}\\mid F)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:26.505ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Multiply the finance score</h4><div class=\"math-display\"><img src=\"math/ca9dd31ae9d5dc12.svg\" alt=\"\\operatorname{score}(F)=\\frac12\\times\\frac1{23}\\times\\frac1{23}\\times\\frac2{23}=\\frac1{23^3}=\\frac1{12167}\\approx0.00008219.\" style=\"width:62.975ex;height:4.949ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 7. Calculate river likelihoods</h4><div class=\"math-display\"><img src=\"math/0612a35cf28c3394.svg\" alt=\"P(\\text{stream}\\mid R)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:29.057ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c71632f8b691648b.svg\" alt=\"P(\\text{shore}\\mid R)=\\frac{2+1}{23}=\\frac3{23}\" style=\"width:27.55ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/bff44b72ce8cc8e7.svg\" alt=\"P(\\text{loan}\\mid R)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:26.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 8. Multiply the river score</h4><div class=\"math-display\"><img src=\"math/665624fd363dd007.svg\" alt=\"\\operatorname{score}(R)=\\frac12\\times\\frac2{23}\\times\\frac3{23}\\times\\frac1{23}=\\frac3{12167}\\approx0.00024657.\" style=\"width:55.735ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 9. Compare scores</h4><p>3/12167 is larger than 1/12167. Riverbank wins even though “loan” is financial evidence: the combined clues matter.</p></div><div class=\"step\"><h4>Step 10. Normalize if a posterior is requested</h4><div class=\"math-display\"><img src=\"math/4b082736e405b96c.svg\" alt=\"P(F\\mid C)=\\frac{1/12167}{4/12167}=\\frac14=0.25\" style=\"width:32.874ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/371000172a7d5f5f.svg\" alt=\"P(R\\mid C)=\\frac{3/12167}{4/12167}=\\frac34=0.75.\" style=\"width:33.525ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Bank is the riverbank sense. Scores are 1/12167 and 3/12167; normalized model posteriors are 0.25 and 0.75.</p></div><p><strong>Without smoothing:</strong> stream and shore are absent in Finance; loan is absent in Riverbank. Both unsmoothed scores become zero, so there is no valid winning class from those products. Also, unnormalized scores should not be labelled as final posterior probabilities.</p><p class=\"cue\">Zero word? Add-one: count+1 upar, total words+vocabulary neeche. Last mein score bada wala sense.</p>"},{"id":"u5-bayes-practice","title":"More WSD numericals: given likelihoods, unequal priors and repeated clues","html":"<div class=\"example\"><p><strong>Question. For bass, let P(Fish)=0.6 and P(Music)=0.4. Given Fish likelihoods P(caught|Fish)=0.5, P(lake|Fish)=0.4 and Music likelihoods P(caught|Music)=0.05, P(lake|Music)=0.1, classify context {caught,lake} and normalize.</strong></p><div class=\"given\"><h4>Given</h4><p>Priors and likelihoods are provided directly; no smoothing or training-count estimation is requested.</p><h4>To find</h4><p>The winning sense and its posterior.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/8414ab183de734ec.svg\" alt=\"\\operatorname{score}(s)=P(s)P(\\text{caught}\\mid s)P(\\text{lake}\\mid s)\" style=\"width:38.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, because the two features are treated as conditionally independent.</p><div class=\"step\"><h4>Step 1. Fish multiplication</h4><p><span class=\"math-inline\"><img src=\"math/115f9e8e47cda84d.svg\" alt=\"0.6\\times0.5=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/99bd356c706eee9f.svg\" alt=\"0.3\\times0.4=0.12\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Music multiplication</h4><p><span class=\"math-inline\"><img src=\"math/b1d1c4fd715bfbf9.svg\" alt=\"0.4\\times0.05=0.02\" style=\"width:16.719ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/6ea85a9a0fdfcde1.svg\" alt=\"0.02\\times0.1=0.002\" style=\"width:17.851ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Total evidence</h4><p><span class=\"math-inline\"><img src=\"math/908f94107aa11373.svg\" alt=\"0.12+0.002=0.122\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><div class=\"math-display\"><img src=\"math/957c68e55d605895.svg\" alt=\"P(Fish\\mid C)=0.12/0.122\\approx0.983607\" style=\"width:36.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/d8a1b99447a84030.svg\" alt=\"P(Music\\mid C)=0.002/0.122\\approx0.016393.\" style=\"width:40.207ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Fish, with model posterior approximately 0.983607.</p></div><div class=\"example\"><p><strong>Question. Disambiguate bank from the repeated context tokens {loan, loan, river}. Priors are Finance=2/3 and River=1/3. Vocabulary V=4. Finance has N=8 total tokens, loan count 3 and river count 0; River has N=4, loan count 0 and river count 2. Apply add-one smoothing.</strong></p><div class=\"given\"><h4>Given</h4><p>Multinomial counts are supplied. The two appearances of loan must both contribute.</p><h4>To find</h4><p>Scores and normalized Finance posterior.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Finance denominator</h4><p><span class=\"math-inline\"><img src=\"math/4dcd6d36e73676fe.svg\" alt=\"8+4=12\" style=\"width:10.308ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/c83ba89d49bb7c55.svg\" alt=\"P(loan\\mid F)=(3+1)/12=1/3\" style=\"width:30.975ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ed4e2c4c1b9881ea.svg\" alt=\"P(river\\mid F)=(0+1)/12=1/12\" style=\"width:32.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. River denominator</h4><p><span class=\"math-inline\"><img src=\"math/34a0153bb137796a.svg\" alt=\"4+4=8\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/739f9e9752ebca3d.svg\" alt=\"P(loan\\mid R)=(0+1)/8=1/8\" style=\"width:29.867ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/cb1959ca98dd60bb.svg\" alt=\"P(river\\mid R)=(2+1)/8=3/8\" style=\"width:30.514ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Finance product</h4><div class=\"math-display\"><img src=\"math/94333571a54ef7df.svg\" alt=\"\\operatorname{score}(F)=\\frac23\\times\\frac13\\times\\frac13\\times\\frac1{12}=\\frac1{162}\\approx0.00617284.\" style=\"width:51.188ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. River product</h4><div class=\"math-display\"><img src=\"math/ffa63ee974248624.svg\" alt=\"\\operatorname{score}(R)=\\frac13\\times\\frac18\\times\\frac18\\times\\frac38=\\frac1{512}\\approx0.001953125.\" style=\"width:51.21ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Compare and normalize</h4><div class=\"math-display\"><img src=\"math/6e05aa52a40b6b55.svg\" alt=\"P(F\\mid C)=\\frac{1/162}{1/162+1/512}=\\frac{512}{674}=\\frac{256}{337}\\approx0.759644.\" style=\"width:53.856ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Finance wins. Repeated loan contributes a squared likelihood; do not reduce the query to a unique-word set.</p></div><h3>Answer-writing order in an exam</h3><p>Write the class priors, vocabulary size, class token totals, a likelihood table, both score products and the final class. Keep fractions until the comparison where possible. If the question only asks classification, normalization is optional; if it asks posterior probabilities, normalization is required.</p><p class=\"cue\">Repeated word aaye toh factor bhi repeat. Sirf word-set bana diya toh multinomial answer badal jayega.</p>"}]}],"formulas":[{"id":"formula-index","title":"All M2 formulas","unit":0,"sections":[{"id":"all","title":"The M2 formula sheet","html":"<p>Read each formula with its meaning. The remaining lessons in this tab contain the complete worked examples for these methods. Use the same vocabulary, boundary, case and token-count conventions throughout one solution.</p><h3>N-gram count</h3><div class=\"math-display\"><img src=\"math/c6f5691757b3dce9.svg\" alt=\"\\max(T-n+1,0)\" style=\"width:17.721ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Unpadded sequence of T tokens. Count only valid contiguous windows.</p><h3>Unigram MLE</h3><div class=\"math-display\"><img src=\"math/6ce6bece84751874.svg\" alt=\"P(w)=C(w)/N\" style=\"width:16.336ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>N is the training-token total under the stated boundary convention.</p><h3>Bigram MLE</h3><div class=\"math-display\"><img src=\"math/7a356598298a4b8a.svg\" alt=\"P(w_i\\mid w_{i-1})=C(w_{i-1},w_i)/C(w_{i-1})\" style=\"width:35.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Denominator = history count.</p><h3>Trigram MLE</h3><div class=\"math-display\"><img src=\"math/d95e106d3b255b6a.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=C(w_{i-2},w_{i-1},w_i)/C(w_{i-2},w_{i-1})\" style=\"width:51.621ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Denominator = two-word history count.</p><h3>Add-one / Laplace</h3><div class=\"math-display\"><img src=\"math/f6db957bd553fd41.svg\" alt=\"P(w\\mid h)=\\frac{C(hw)+1}{C(h)+|V|}\" style=\"width:22.827ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Add one to every possible vocabulary continuation.</p><h3>Sentence probability</h3><div class=\"math-display\"><img src=\"math/1bb8f8f2c685b8c8.svg\" alt=\"P(W)\\approx\\prod_iP(w_i\\mid w_{i-1})\" style=\"width:24.225ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply in order; include an end factor if specified.</p><h3>Perplexity</h3><div class=\"math-display\"><img src=\"math/be3b71a436d652a8.svg\" alt=\"PP=P(W)^{-1/N}\" style=\"width:16.698ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div><p>N is the number of predicted tokens/events used by the question.</p><h3>Emission</h3><div class=\"math-display\"><img src=\"math/597b97fa150cfb9b.svg\" alt=\"P(w\\mid t)=C(w,t)/C(t)\" style=\"width:23.149ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Word given tag; count tokens with that tag.</p><h3>Transition</h3><div class=\"math-display\"><img src=\"math/a89cf52a2261bb02.svg\" alt=\"P(t_j\\mid t_i)=C(t_i\\to t_j)/\\sum_k C(t_i\\to t_k)\" style=\"width:37.347ex;height:4.899ex\" loading=\"lazy\" decoding=\"async\"></div><p>Next tag given previous tag; count outgoing transitions.</p><h3>HMM joint path</h3><div class=\"math-display\"><img src=\"math/aed9bbaaf2578ce2.svg\" alt=\"P(W,T)=\\pi_{t_1}b_{t_1}(w_1)\\prod_{i=2}^{n}a_{t_{i-1},t_i}b_{t_i}(w_i)\" style=\"width:36.502ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply initial, emission and transition factors; add end probability if used.</p><h3>Tag sequences</h3><div class=\"math-display\"><img src=\"math/ed1eadf4591c422c.svg\" alt=\"K^T\" style=\"width:3.443ex;height:2.017ex\" loading=\"lazy\" decoding=\"async\"></div><p>K tags, T word positions; count before constraints.</p><h3>Viterbi</h3><div class=\"math-display\"><img src=\"math/bb085669dbdb35d4.svg\" alt=\"\\delta_i(t)=b_t(w_i)\\max_s[\\delta_{i-1}(s)a_{s,t}]\" style=\"width:28.807ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p>Choose the largest predecessor score; store a backpointer.</p><h3>Lesk</h3><div class=\"math-display\"><img src=\"math/28ab6543e5b805ca.svg\" alt=\"score(s)=|context\\cap gloss(s)|\" style=\"width:30.034ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use the specified normalisation and overlap convention.</p><h3>Naive Bayes class prior</h3><div class=\"math-display\"><img src=\"math/b91d8ff6433f1da4.svg\" alt=\"P(c)=D_c/D\" style=\"width:13.214ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>D counts labelled examples; this is not the word-token total.</p><h3>Smoothed NB likelihood</h3><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>N_c counts training tokens in class c.</p><h3>NB decision</h3><div class=\"math-display\"><img src=\"math/d28d2ec54104fe0c.svg\" alt=\"\\hat c=\\arg\\max_c P(c)\\prod_iP(w_i\\mid c)\" style=\"width:28.879ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Select label with largest score; normalise only for posterior values.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Condition jis par hai, denominator usi ka; sequence mein multiply; options mein maximum.</p>"}],"scope":"M2 · formulas with meaning · full examples follow"},{"id":"f-counts","title":"N-grams & probability","unit":0,"sections":[{"id":"n-grams-construction","title":"Unigrams, bigrams and trigrams: construct them correctly","html":"<p><strong>Definition.</strong> An n-gram is a contiguous sequence of n items. For word n-grams, the items are consecutive word tokens. A unigram contains one word; a bigram contains two; a trigram contains three. Character n-grams use characters instead, so always identify the unit being counted.</p><div class=\"flow\"><div class=\"node\">Tokens: we | study | natural | language</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Move a window one token at a time</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Bigrams: we study / study natural / natural language</div></div><p>For m tokens without padding, the number of n-gram <em>positions</em> is max(0, m−n+1). Repeated positions may contain the same n-gram type. A bag-of-n-grams representation counts each n-gram type and loses the overall sentence order beyond the local order inside each n-gram.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9097807b6ad98d38.svg\" alt=\"\\text{Number of unpadded n-gram positions}=\\max(0,m-n+1)\" style=\"width:58.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. List all word unigrams, bigrams and trigrams for “the prime minister of our country”. Do not add boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Six tokens: the, prime, minister, of, our, country. n = 1, 2 and 3.</p><h4>To find</h4><p>All three lists and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad44404e3f41cdd.svg\" alt=\"\\#\\text{positions}=m-n+1\" style=\"width:23.607ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each window must contain consecutive words and move one position. No wraparound or invented final word is allowed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take one word at a time</h5><p>Unigrams: (the), (prime), (minister), (of), (our), (country). Count = 6−1+1 = 6.</p></div><div class=\"step\"><h5>Step 2. Take two consecutive words</h5><p>Bigrams: (the, prime), (prime, minister), (minister, of), (of, our), (our, country). Count = 6−2+1 = 5.</p></div><div class=\"step\"><h5>Step 3. Take three consecutive words</h5><p>Trigrams: (the, prime, minister), (prime, minister, of), (minister, of, our), (of, our, country). Count = 6−3+1 = 4.</p></div><div class=\"answer\"><strong>Final answer.</strong> 6 unigrams, 5 bigrams and 4 trigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct bigrams for “I like tea” using one start and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original tokens: I, like, tea. Add &lt;s&gt; and &lt;/s&gt; once each.</p><h4>To find</h4><p>The boundary-aware bigram sequence.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1b167f71a6a973b4.svg\" alt=\"\\#\\text{bigrams}=(m+2)-1=m+1\" style=\"width:33.155ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The start context predicts the first word, and the last word predicts that the sentence ends.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write the padded sequence</h5><p>&lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Move a two-token window</h5><p>(&lt;s&gt;, I), (I, like), (like, tea), (tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count the windows</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c37463b701447787.svg\" alt=\"3+1=4\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> There are four boundary-aware bigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct trigrams for “I like tea” using two start markers and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original sentence has three words. For a trigram model each predicted token needs two prior context tokens.</p><h4>To find</h4><p>All trigram prediction events.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/12c99aed7b535ad6.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:17.519ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Two start markers provide a complete context even for the first word.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Pad with two starts</h5><p>&lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Slide a three-token window</h5><p>(&lt;s&gt;, &lt;s&gt;, I), (&lt;s&gt;, I, like), (I, like, tea), (like, tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count predicted events</h5><p>The model predicts I, like, tea and the end marker: four predictions.</p></div><div class=\"answer\"><strong>Final answer.</strong> Four trigrams. Start markers are context; they are not ordinary predicted words.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Give the bag-of-bigrams counts for “a b a b” without padding.</strong></p><div class=\"given\"><h4>Given</h4><p>Four tokens in their given order.</p><h4>To find</h4><p>Bigram positions, distinct bigram types and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8326144ada817e2c.svg\" alt=\"\\#\\text{positions}=4-2+1=3\" style=\"width:26.674ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A bag stores frequencies; repeated bigrams must not be discarded.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Enumerate all positions</h5><p>(a,b), (b,a), (a,b).</p></div><div class=\"step\"><h5>Step 2. Group identical pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Bigram type</th><th>Count</th></tr></thead><tbody><tr><td>a b</td><td>2</td></tr><tr><td>b a</td><td>1</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> Three bigram positions but two distinct bigram types.</div><p class=\"cue\"><strong>Yaad rakho:</strong> n-gram mein n words; context mein n−1 words.</p></section>"},{"id":"unigram-estimation","title":"Unigram estimation and complete worked examples","html":"<p><strong>Maximum likelihood estimation (MLE)</strong> chooses probabilities equal to observed relative frequencies. In a unigram model, every word is predicted independently of its surrounding words. If a word occurs c times in N training tokens, its estimate is c/N. To score m specified words, multiply their m unigram probabilities.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/151df11dd9b4e4ca.svg\" alt=\"P_{\\mathrm{MLE}}(w)=\\frac{C(w)}{N}\\qquad P(w_1,\\ldots,w_m)\\approx\\prod_{i=1}^{m}P(w_i)\" style=\"width:48.638ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Choose a tokenization convention before counting. Lowercasing, punctuation handling and boundary markers can change the vocabulary and counts. Never count words with one convention and form the denominator with another. A unigram model gives the same product to rearrangements of the same word multiset; that is one of its limitations.</p><section class=\"example\"><p class=\"question\"><strong>Question. Train an unpadded, case-insensitive unigram model on “I like tea” and “I like coffee”. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Training sentences: I like tea; I like coffee. Use lowercase words; exclude punctuation and sentence boundaries.</p><h4>To find</h4><p>The vocabulary, word probabilities and test-sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92c670591895f879.svg\" alt=\"P(w)=C(w)/N,\\qquad P(I\\ like\\ tea)=P(I)P(like)P(tea)\" style=\"width:55.644ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The unigram approximation ignores order and uses total token count for every denominator.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count every training token</h5><p>Each sentence contains three words, so N = 3+3 = 6.</p></div><div class=\"step\"><h5>Step 2. Count types and frequencies</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th><th>MLE probability</th></tr></thead><tbody><tr><td>i</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>like</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>tea</td><td>1</td><td>1/6</td></tr><tr><td>coffee</td><td>1</td><td>1/6</td></tr></tbody></table></div><p>Vocabulary size V = 4.</p></div><div class=\"step\"><h5>Step 3. Write one factor per test word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8823227ec8a6a1a.svg\" alt=\"P=\\frac{2}{6}\\times\\frac{2}{6}\\times\\frac{1}{6}\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply the fractions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3a5496aef6f0526.svg\" alt=\"P=\\frac{4}{216}=\\frac{1}{54}\\approx0.018519\" style=\"width:26.945ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The unigram sentence probability is approximately 0.018519.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains counts a: 4, b: 3 and c: 1. Find the unigram probability of “a b a”.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=4, C(b)=3, C(c)=1. No boundary markers.</p><h4>To find</h4><p>P(a b a).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/97d27988b1cff86a.svg\" alt=\"P(a\\,b\\,a)=P(a)P(b)P(a)\" style=\"width:24.338ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A repeated test word contributes a probability factor at every occurrence; do not include it just once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/489d9ca17e456579.svg\" alt=\"N=4+3+1=8\" style=\"width:18.1ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the required probabilities</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c986ed6d03f3c421.svg\" alt=\"P(a)=4/8=1/2,\\qquad P(b)=3/8\" style=\"width:33.849ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Use both occurrences of a</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a46bf6ca459b44e0.svg\" alt=\"P=\\frac12\\times\\frac38\\times\\frac12\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Simplify</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c91fa325852e9b20.svg\" alt=\"P=\\frac3{32}=0.09375\" style=\"width:18.407ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(a b a) = 0.09375.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Repeated word ka probability bhi repeat multiply hoga.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. An unsmoothed unigram model is trained on “red blue red”. Find the probability of “red green”.</strong></p><div class=\"given\"><h4>Given</h4><p>N=3. Counts: red=2, blue=1, green=0. The test contains red and green.</p><h4>To find</h4><p>The unsmoothed test probability and the reason for its value.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ad862e46bb0787a.svg\" alt=\"P(red\\ green)=P(red)P(green)\" style=\"width:31.594ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>MLE assigns zero to an unseen outcome. Smoothing is needed if an unseen in-vocabulary item must receive probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Estimate red</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4e4dbe2f8003f7d7.svg\" alt=\"P(red)=2/3\" style=\"width:13.121ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the unseen word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5ae67848fc965273.svg\" alt=\"P(green)=0/3=0\" style=\"width:19.584ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c86e2ed24bee6fb.svg\" alt=\"(2/3)\\times0=0\" style=\"width:13.199ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed probability = 0. This reflects missing training evidence, not proof that the phrase is impossible.</div></section>"},{"id":"bigram-count-table","title":"Bigram counts: build the table before multiplying","html":"<p>A <strong>bigram probability table</strong> uses the previous word as its row and the next word as its column. Divide each cell count by its row's total outgoing count. With one end marker on every sentence, each ordinary training word has a continuation, so its outgoing count equals its token frequency. Do not create a bigram that crosses from one sentence into the next.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/16ee67bf50a203c3.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{\\sum_{v\\in V}C(h,v)}=\\frac{C(h,w)}{C(h)}\" style=\"width:36.615ex;height:5.619ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"flow\"><div class=\"node\">Add boundaries to each sentence separately</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">List adjacent pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Count repeated pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Divide each row by its total</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Follow the test sentence through the table</div></div><section class=\"example\"><p class=\"question\"><strong>Question. Train a bigram model on “I like tea”, “I like coffee” and “you like tea”. Use one start and one end marker. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: &lt;s&gt; I like tea &lt;/s&gt;; &lt;s&gt; I like coffee &lt;/s&gt;; &lt;s&gt; you like tea &lt;/s&gt;. Preserve these tokens.</p><h4>To find</h4><p>All nonzero bigram estimates and the test probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every sentence starts and ends independently. Four probability factors are required for the three test words plus end.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. List the training pairs</h5><p>Sentence 1: (&lt;s&gt;,I), (I,like), (like,tea), (tea,&lt;/s&gt;).<br>Sentence 2: (&lt;s&gt;,I), (I,like), (like,coffee), (coffee,&lt;/s&gt;).<br>Sentence 3: (&lt;s&gt;,you), (you,like), (like,tea), (tea,&lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 2. Create the nonzero count table</h5><div class=\"table-wrap\"><table><thead><tr><th>History → next</th><th>Pair count</th><th>History count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → I</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>&lt;s&gt; → you</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>I → like</td><td>2</td><td>2</td><td>1</td></tr><tr><td>you → like</td><td>1</td><td>1</td><td>1</td></tr><tr><td>like → tea</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>like → coffee</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>tea → &lt;/s&gt;</td><td>2</td><td>2</td><td>1</td></tr><tr><td>coffee → &lt;/s&gt;</td><td>1</td><td>1</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the test path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7363c7dc5cab171f.svg\" alt=\"P=P(I\\mid\\langle s\\rangle)P(like\\mid I)P(tea\\mid like)P(\\langle/s\\rangle\\mid tea)\" style=\"width:48.662ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Substitute each matching row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2c319bafd1386357.svg\" alt=\"P=\\frac23\\times1\\times\\frac23\\times1\" style=\"width:19.529ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d5107e2738f0177f.svg\" alt=\"P=\\frac49\\approx0.444444\" style=\"width:18.407ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(I like tea) = 4/9 ≈ 0.444444.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using the same three-sentence corpus given here—“I like tea”, “I like coffee”, “you like tea”—find the bigram probabilities of “you like coffee” and “tea like I”. Include boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus with one start/end marker per sentence. Counts: start→you=1/3; you→like=1; like→coffee=1/3; coffee→end=1. No training sentence starts with tea.</p><h4>To find</h4><p>The two test probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92e554afbd43b835.svg\" alt=\"P(\\text{sentence})=\\prod P(\\text{next token}\\mid\\text{previous token})\" style=\"width:48.054ex;height:3.167ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A model can assign a nonzero probability to a sentence it never saw if all of its local bigrams were seen.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score you like coffee</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bccffa0a6f23966a.svg\" alt=\"P=\\frac13\\times1\\times\\frac13\\times1=\\frac19\\approx0.111111\" style=\"width:36.238ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Inspect tea like I</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c17c8267050aec19.svg\" alt=\"P(tea\\mid\\langle s\\rangle)=0/3=0\" style=\"width:21.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply the zero factor</h5><p>The full product is zero, regardless of the remaining factors.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(you like coffee) = 1/9; P(tea like I) = 0. A new sentence is not necessarily a zero-probability sentence.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Obtain the unsmoothed bigram probability of “students are from Vellore” from this corpus: “I am from Vellore”; “I am a teacher”; “students are good and are from various cities”; “students from Vellore do engineering”. Use sentence boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Four training sentences, each padded with one &lt;s&gt; and &lt;/s&gt;. Test sequence: &lt;s&gt; students are from Vellore &lt;/s&gt;.</p><h4>To find</h4><p>The five required conditional probabilities and their product.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Count all occurrences in the entire corpus. In particular, are occurs twice inside the third sentence, and Vellore is followed by end once and do once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the histories</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Occurrences with continuation</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>4</td></tr><tr><td>students</td><td>2</td></tr><tr><td>are</td><td>2</td></tr><tr><td>from</td><td>3</td></tr><tr><td>Vellore</td><td>2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count the required pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Required pair</th><th>Count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; students</td><td>2</td><td>2/4</td></tr><tr><td>students are</td><td>1</td><td>1/2</td></tr><tr><td>are from</td><td>1</td><td>1/2</td></tr><tr><td>from Vellore</td><td>2</td><td>2/3</td></tr><tr><td>Vellore &lt;/s&gt;</td><td>1</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the complete product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6420e3d4b5982a43.svg\" alt=\"P=\\frac24\\times\\frac12\\times\\frac12\\times\\frac23\\times\\frac12\" style=\"width:26.413ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply progressively</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6c021a4ae77c326e.svg\" alt=\"\\frac24\\times\\frac12=\\frac14,\\quad \\frac14\\times\\frac12=\\frac18\" style=\"width:27.594ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e9b12d6d627642db.svg\" alt=\"\\frac18\\times\\frac23=\\frac1{12},\\quad \\frac1{12}\\times\\frac12=\\frac1{24}\" style=\"width:30.988ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 1/24 ≈ 0.0416667.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Same sentence mein word do baar aaye toh count bhi do.</p></section>"},{"id":"trigram-estimation","title":"Trigram estimates: two-word history, not two denominators","html":"<p>A trigram model predicts the next word from the two preceding words. The numerator is the count of a triple. The denominator is the count of its two-word history with an available next token. Do not multiply two independent bigram probabilities and call that a trigram probability.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ca97d5e894e09b1.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=\\frac{C(w_{i-2},w_{i-1},w_i)}{C(w_{i-2},w_{i-1})}\" style=\"width:38.191ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains 12 occurrences of “prime minister”. Eight are followed by “of”, three by “said”, and one by “visited”. Estimate the three trigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>History h = (prime, minister). Count of this history = 12. Triple counts for of, said, visited are 8, 3, 1.</p><h4>To find</h4><p>The conditional distribution of the next word.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8ba899fcd0d6112.svg\" alt=\"P(w\\mid prime,minister)=C(prime,minister,w)/12\" style=\"width:51.168ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All three candidates share one two-word history, so they share denominator 12.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate of</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69d53078e2ba6e25.svg\" alt=\"P(of\\mid prime,minister)=8/12=2/3\" style=\"width:37.483ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate said</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a742b6dcdf3bfef5.svg\" alt=\"P(said\\mid prime,minister)=3/12=1/4\" style=\"width:39.356ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate visited</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/170c0f0886c42082.svg\" alt=\"P(visited\\mid prime,minister)=1/12\" style=\"width:35.497ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Confirm normalization</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8a19e47f93490280.svg\" alt=\"8/12+3/12+1/12=12/12=1\" style=\"width:31.928ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The probabilities are 2/3, 1/4 and 1/12.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Train a trigram model on “I like tea”, “I like coffee” and “you like tea”. Use two start markers and one end marker. Score “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences. Padded first sentence is &lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;; pad the other two in the same way.</p><h4>To find</h4><p>Four trigram prediction probabilities and the sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0b4f2f8e9cf3fc17.svg\" alt=\"P=\\prod_i P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:25.504ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each prediction uses a two-token context; the two start markers supply the first history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the first-word event</h5><p>The history (&lt;s&gt;,&lt;s&gt;) occurs three times, and two are followed by I.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/88a613de059c9165.svg\" alt=\"P(I\\mid\\langle s\\rangle,\\langle s\\rangle)=2/3\" style=\"width:19.545ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Count the second-word event</h5><p>(&lt;s&gt;,I) occurs twice; both are followed by like.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99919b0a3770ff5c.svg\" alt=\"P(like\\mid\\langle s\\rangle,I)=2/2=1\" style=\"width:24.56ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count the third-word event</h5><p>(I,like) occurs twice; one is followed by tea.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/22c4756e3a5a9146.svg\" alt=\"P(tea\\mid I,like)=1/2\" style=\"width:20.658ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Count the end event</h5><p>(like,tea) occurs twice; both are followed by end.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/221a8d0201199a49.svg\" alt=\"P(\\langle/s\\rangle\\mid like,tea)=2/2=1\" style=\"width:27.618ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply all four</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15f0c8914a694355.svg\" alt=\"P=\\frac23\\times1\\times\\frac12\\times1=\\frac13\" style=\"width:24.673ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Trigram P(I like tea) = 1/3. It differs from the bigram estimate because the context and denominator changed.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A trigram model supplies P(we|&lt;s&gt;,&lt;s&gt;)=0.4, P(study|&lt;s&gt;,we)=0.5, P(NLP|we,study)=0.8 and P(&lt;/s&gt;|study,NLP)=0.25. Score “we study NLP”.</strong></p><div class=\"given\"><h4>Given</h4><p>Four trigram conditional factors. The end marker is included.</p><h4>To find</h4><p>The complete sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f7ce4e6b173900c6.svg\" alt=\"P=P(we\\mid s,s)P(study\\mid s,we)P(NLP\\mid we,study)P(end\\mid study,NLP)\" style=\"width:71.784ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use each supplied two-word history exactly; do not swap its word order.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the values</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7e1f0a0c2ffc974b.svg\" alt=\"P=0.4\\times0.5\\times0.8\\times0.25\" style=\"width:25.71ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply the first pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4528e6e7a97bb8e8.svg\" alt=\"0.4\\times0.5=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Include NLP</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd4748e690ad03d9.svg\" alt=\"0.2\\times0.8=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Include the end</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5bbc9c588899b389.svg\" alt=\"0.16\\times0.25=0.04\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 0.04.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Trigram: teen-word count upar, pehle do-word count neeche.</p></section><p><strong>Why larger n is not automatically better.</strong> More context can capture local order more precisely, but each longer history occurs less often. Parameter count, storage and sparsity grow. A model trained on Shakespeare may assign poor probabilities to financial news because training and test distributions differ. Keep a held-out test set; do not evaluate only on memorized training sentences.</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-smoothing","title":"Smoothing & perplexity","unit":0,"sections":[{"id":"laplace-basics","title":"Laplace smoothing: why both numerator and denominator change","html":"<p><strong>Smoothing</strong> reallocates some probability mass to events that received zero or unreliable estimates from finite training data. <strong>Laplace, or add-one, smoothing</strong> adds one pseudo-count to every possible next outcome. If there are V possible outcomes, the total added count is V, so adding 1 only to the numerator would produce probabilities that do not sum to 1.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0d44559007b7dea6.svg\" alt=\"P_{\\mathrm{Laplace}}(w)=\\frac{C(w)+1}{N+V}\" style=\"width:23.384ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e38a73cc66cdd3f1.svg\" alt=\"P_{\\mathrm{Laplace}}(w\\mid h)=\\frac{C(h,w)+1}{C(h)+V}\" style=\"width:28.882ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For unigram smoothing, N is the total training token count. For bigram smoothing, C(h) is the count of the particular history. In both cases V is the number of outcomes being predicted, not the number of training sentences and not the number of distinct bigrams. When end is a possible prediction, include it in V; the start marker is usually context only.</p><div class=\"flow\"><div class=\"node\">Observed counts: 3, 1, 0</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Add one to every outcome: 4, 2, 1</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New total: 7</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Smoothed probabilities: 4/7, 2/7, 1/7</div></div><section class=\"example\"><p class=\"question\"><strong>Question. A fixed unigram vocabulary is {a,b,c}. The training counts are 3,1,0. Compute unsmoothed and Laplace-smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=3, C(b)=1, C(c)=0; N=4; V=3.</p><h4>To find</h4><p>The complete distributions.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/80d7161647b260e8.svg\" alt=\"P(w)=C(w)/N,\\qquad P_L(w)=(C(w)+1)/(N+V)\" style=\"width:51.157ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The zero-count c is still in the fixed vocabulary, so it must receive one pseudo-count and contribute to V.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute unsmoothed values</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Unsmoothed</th></tr></thead><tbody><tr><td>a</td><td>3/4 = 0.75</td></tr><tr><td>b</td><td>1/4 = 0.25</td></tr><tr><td>c</td><td>0/4 = 0</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Calculate the new denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1918c0a9ceaec186.svg\" alt=\"N+V=4+3=7\" style=\"width:18.708ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add one to each numerator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/345a4b4f00828435.svg\" alt=\"C(a)+1=4,\\quad C(b)+1=2,\\quad C(c)+1=1\" style=\"width:44.259ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Divide</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Smoothed</th></tr></thead><tbody><tr><td>a</td><td>4/7 ≈ 0.571429</td></tr><tr><td>b</td><td>2/7 ≈ 0.285714</td></tr><tr><td>c</td><td>1/7 ≈ 0.142857</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Confirm the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/172a91eacd7bcf59.svg\" alt=\"4/7+2/7+1/7=1\" style=\"width:19.861ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Smoothed probabilities: a=4/7, b=2/7, c=1/7. Common a loses mass; unseen c gains mass.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. After history I, a corpus records like three times, study once and sleep zero times. The allowed next vocabulary is {like,study,sleep}. Compute all Laplace-smoothed bigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(I,like)=3; C(I,study)=1; C(I,sleep)=0. History count C(I)=4. V=3.</p><h4>To find</h4><p>P_L(like|I), P_L(study|I), P_L(sleep|I).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a1c0980897f9361.svg\" alt=\"P_L(w\\mid I)=\\frac{C(I,w)+1}{C(I)+V}\" style=\"width:24.291ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>This is smoothing within the I row; use its total 4, not the global corpus token count.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the common denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d3c1688373da86b2.svg\" alt=\"C(I)+V=4+3=7\" style=\"width:21.319ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate like</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/848e1d743f230579.svg\" alt=\"P_L(like\\mid I)=(3+1)/7=4/7\" style=\"width:29.682ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate study</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ed5edd3a14936914.svg\" alt=\"P_L(study\\mid I)=(1+1)/7=2/7\" style=\"width:31.452ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate sleep</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e0b14bd8e108207.svg\" alt=\"P_L(sleep\\mid I)=(0+1)/7=1/7\" style=\"width:30.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The row is (4/7, 2/7, 1/7). An unseen bigram is no longer forced to zero.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A fixed vocabulary has five possible next tokens. A history h is unseen in training. What is its add-one probability for each next token?</strong></p><div class=\"given\"><h4>Given</h4><p>C(h)=0; C(h,w)=0 for each outcome; V=5.</p><h4>To find</h4><p>P_L(w|h) for each token.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e1f42d7a9537f57.svg\" alt=\"P_L(w\\mid h)=\\frac{0+1}{0+V}\" style=\"width:18.948ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All outcomes receive equal pseudo-counts because the training data gives no preference for this history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Add the pseudo-count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dd66590db88ae5fa.svg\" alt=\"0+1=1\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Form the denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/190ddc58c7516f91.svg\" alt=\"0+5=5\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Divide and sum</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/39038359834be22e.svg\" alt=\"P_L(w\\mid h)=1/5=0.2,\\qquad5(0.2)=1\" style=\"width:37.08ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Every outcome gets 0.2 under this fixed-vocabulary model.</div></section><p><strong>Vocabulary warning.</strong> Add-one does not automatically define probabilities for every word in the world. Unknown words require a declared vocabulary/UNK convention. If a question supplies V, use that stated V rather than inventing additional tokens.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Add-one: upar +1, neeche +V; bigram mein neeche history ka count.</p>"},{"id":"smoothed-sentence","title":"A complete unseen-bigram question from corpus to final answer","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Consider the corpus “I love to code in Python. I love to learn new things. I code every day.” Obtain the bigram probabilities needed for “I love Python”. Explain the zero-probability issue, then use Laplace smoothing to score it. Treat each sentence separately, preserve case, remove punctuation, and include an end token among predicted outcomes.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences padded with one start/end marker. Distinct words: I, love, to, code, in, Python, learn, new, things, every, day. With &lt;/s&gt;, V=12. Start is context only.</p><h4>To find</h4><p>Unsmoothed and smoothed P(I love Python &lt;/s&gt; | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a627bcb8a0b3808.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{C(h)},\\qquad P_L(w\\mid h)=\\frac{C(h,w)+1}{C(h)+12}\" style=\"width:49.838ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The test contains an unseen transition love→Python. Smoothing assigns probability to that transition and renormalizes every required history row.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the contexts</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>3</td></tr><tr><td>I</td><td>3</td></tr><tr><td>love</td><td>2</td></tr><tr><td>Python</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count each required pair</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt; I</td><td>3</td></tr><tr><td>I love</td><td>2</td></tr><tr><td>love Python</td><td>0</td></tr><tr><td>Python &lt;/s&gt;</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Compute the unsmoothed product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/420a50ccd335ade1.svg\" alt=\"P=\\frac33\\times\\frac23\\times\\frac02\\times\\frac11=0\" style=\"width:25.668ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both words love and Python were seen, but their adjacent pair was not. This is an unseen bigram, not an unknown-word case.</p></div><div class=\"step\"><h5>Step 4. Smooth the first event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f16fc85077f5670b.svg\" alt=\"P_L(I\\mid\\langle s\\rangle)=\\frac{3+1}{3+12}=\\frac4{15}\" style=\"width:26.784ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Smooth the second event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a94897ddface7219.svg\" alt=\"P_L(love\\mid I)=\\frac{2+1}{3+12}=\\frac3{15}\" style=\"width:27.886ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Smooth the unseen event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f023b28c09df9a1a.svg\" alt=\"P_L(Python\\mid love)=\\frac{0+1}{2+12}=\\frac1{14}\" style=\"width:34.128ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 7. Smooth the end event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cfdc24dda127984e.svg\" alt=\"P_L(\\langle/s\\rangle\\mid Python)=\\frac{1+1}{1+12}=\\frac2{13}\" style=\"width:34.158ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 8. Multiply the smoothed factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8b4c9f0eec18e2b4.svg\" alt=\"P_L=\\frac4{15}\\times\\frac3{15}\\times\\frac1{14}\\times\\frac2{13}\" style=\"width:27.076ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be31ee9de701fcab.svg\" alt=\"P_L=\\frac{24}{40950}=\\frac4{6825}\\approx0.000586081\" style=\"width:35.894ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed P=0. With the stated V=12 and boundaries, Laplace-smoothed P≈0.000586081.</div></section><p>If an exam states a different convention—for example excluding boundary tokens from the entire calculation—recompute both V and the set of probability factors consistently. Do not combine a boundary-aware numerator with a boundary-free denominator.</p>"},{"id":"adjusted-count-discount","title":"Adjusted counts and relative discounting","html":"<p>The slides also express smoothing through an <strong>adjusted count</strong> c*. Instead of writing the smoothed probability with denominator N+V, they rescale its numerator so the denominator can remain N. Algebraically these are equivalent:</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/70d92382a6cc1e9c.svg\" alt=\"c^*=(c+1)\\frac{N}{N+V},\\qquad P_L(w)=\\frac{c^*}{N}\" style=\"width:36.794ex;height:4.832ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6597274c03aa7f00.svg\" alt=\"d=\\frac{c^*}{c}\\quad(c&gt;0)\" style=\"width:16.307ex;height:4.672ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The relative discount d compares adjusted and original counts. It is undefined when c=0 because division by zero is undefined. Add-one smoothing moves the distribution toward uniformity: frequent events are reduced, but some rare seen events may increase. It is not correct to claim that every nonzero count must decrease under Laplace smoothing.</p><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, a word has original count c=10. Find its adjusted count, smoothed probability and relative discount.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=10.</p><h4>To find</h4><p>c*, P_L and d.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/63cfdcd2de177903.svg\" alt=\"c^*=(c+1)N/(N+V),\\quad P_L=c^*/N,\\quad d=c^*/c\" style=\"width:48.699ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>These expressions rewrite add-one smoothing without changing its probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the new total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/749a0f4867a4b3db.svg\" alt=\"N+V=20+5=25\" style=\"width:20.971ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Find the adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/866c6ee174b3d21b.svg\" alt=\"c^*=(10+1)\\frac{20}{25}=11(0.8)=8.8\" style=\"width:32.002ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Find the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5fb26f5353edaa9.svg\" alt=\"P_L=8.8/20=0.44\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find the relative discount</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be28007774d8c2d5.svg\" alt=\"d=8.8/10=0.88\" style=\"width:17.518ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=8.8, P_L=0.44, d=0.88. The original probability 0.5 is reduced.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Under N=20, V=5, a rare word occurs once. Compute its adjusted count and compare the original and smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=1.</p><h4>To find</h4><p>c*, original P and smoothed P_L.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/509478366d59c2ce.svg\" alt=\"c^*=(c+1)N/(N+V)\" style=\"width:23.036ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same smoothing rule may increase a rare event's probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Original probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3fc24a506f12b888.svg\" alt=\"P=1/20=0.05\" style=\"width:16.281ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/13803fe6f5045ef1.svg\" alt=\"c^*=(1+1)(20/25)=1.6\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0fd3e6bc0e9d2f40.svg\" alt=\"P_L=1.6/20=0.08\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=1.6 and P_L=0.08, which exceeds the original 0.05.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, an in-vocabulary word has count zero. Find its adjusted count and smoothed probability. Can a relative discount be calculated?</strong></p><div class=\"given\"><h4>Given</h4><p>c=0; N=20; V=5.</p><h4>To find</h4><p>c*, P_L and whether d exists.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dc6d3ca40a034b28.svg\" alt=\"c^*=(c+1)N/(N+V),\\qquad P_L=c^*/N\" style=\"width:39.422ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The pseudo-count creates positive mass for the unseen vocabulary item.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e073545bb6c88eb4.svg\" alt=\"c^*=(0+1)(20/25)=0.8\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5e8f939253d4321b.svg\" alt=\"P_L=0.8/20=0.04\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Relative discount</h5><p>d would be 0.8/0. That is undefined, so do not report a finite discount.</p></div><div class=\"answer\"><strong>Final answer.</strong> c*=0.8 and P_L=0.04; relative discount is undefined for c=0.</div></section>"},{"id":"evaluation-perplexity","title":"Perplexity: meaning, formula and four complete examples","html":"<p><strong>Intrinsic evaluation</strong> evaluates a model directly on a held-out test corpus, for example using perplexity. <strong>Extrinsic evaluation</strong> places it inside a downstream application, such as a speech recognizer or translation system, and measures the application's performance. Extrinsic testing is closer to actual use but often slower and more expensive. A lower perplexity is not a guarantee of improvement on every downstream task.</p><p><strong>Perplexity</strong> is the inverse probability of a test sequence, normalized by the number of prediction events. Intuitively, it is the model's effective average number of equally plausible choices. A model that always gives the correct next word probability 1/4 has perplexity 4. Lower is better when the models are tested on the same data, vocabulary, tokenization and boundary convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dab12face5c56858.svg\" alt=\"\\operatorname{PP}(W)=P(W)^{-1/N}=\\sqrt[N]{\\frac1{P(W)}}\" style=\"width:32.663ex;height:6.923ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>W</td><td>The complete test sequence.</td></tr><tr><td>P(W)</td><td>Product of the probabilities assigned to the actual next tokens.</td></tr><tr><td>N</td><td>Number of scored prediction events under the stated convention.</td></tr><tr><td>Exponent −1/N</td><td>Take the reciprocal, then the Nth root.</td></tr></tbody></table></div><p>For calculator entry, use parentheses: P raised to (−1 ÷ N), or (1 ÷ P) raised to (1 ÷ N). Retain several digits in intermediate products. The ordinary start marker is usually given context, not a predicted event; the end marker counts if its probability is included.</p><section class=\"example\"><p class=\"question\"><strong>Question. A model assigns probability 0.0625 to a test sequence containing four scored tokens. Compute its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>P(W)=0.0625=1/16; N=4.</p><h4>To find</h4><p>PP(W).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7873b84adddec337.svg\" alt=\"\\operatorname{PP}(W)=\\left(\\frac1{P(W)}\\right)^{1/N}\" style=\"width:23.594ex;height:6.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The root removes the effect of sequence length; the reciprocal makes lower surprise correspond to lower perplexity.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/31c8e928444ef07c.svg\" alt=\"1/P(W)=1/0.0625=16\" style=\"width:24.937ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the fourth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/560b6664723185b3.svg\" alt=\"\\operatorname{PP}=16^{1/4}\" style=\"width:10.948ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c15dbdf7cfc85ea8.svg\" alt=\"2^4=16\\quad\\Rightarrow\\quad\\operatorname{PP}=2\" style=\"width:22.672ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 2.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Two language models score the same three-token test sequence. Model A gives next-token probabilities 0.5, 0.5, 0.5. Model B gives 0.5, 0.25, 0.25. Compute their perplexities and select the better intrinsic result.</strong></p><div class=\"given\"><h4>Given</h4><p>Same sequence and N=3 for both models. A factors: 0.5,0.5,0.5. B factors: 0.5,0.25,0.25.</p><h4>To find</h4><p>Both sequence probabilities and perplexities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3f347a2e35262f3f.svg\" alt=\"P(W)=\\prod_i p_i,\\qquad\\operatorname{PP}=P(W)^{-1/3}\" style=\"width:35.285ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A fair comparison uses identical test tokens and scoring conventions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate A's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/072e354cb1ef7f5e.svg\" alt=\"P_A=0.5\\times0.5\\times0.5=0.125=1/8\" style=\"width:34.645ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate A's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/eaa36684164a8ec6.svg\" alt=\"\\operatorname{PP}_A=8^{1/3}=2\" style=\"width:15.353ex;height:2.48ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate B's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e4c44123baab46cd.svg\" alt=\"P_B=0.5\\times0.25\\times0.25=0.03125=1/32\" style=\"width:40.315ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate B's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7cad7e80704e87a9.svg\" alt=\"\\operatorname{PP}_B=32^{1/3}\\approx3.174802\" style=\"width:23.915ex;height:2.474ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Compare</h5><p>2 is lower than 3.174802; A places more probability on the observed sequence.</p></div><div class=\"answer\"><strong>Final answer.</strong> Model A is better by perplexity on this test: 2 versus about 3.174802.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The bigram training corpus is “This is a dog”, “This is a cat”, “I love my cat”, “This is my name”. Score “This is my cat”, including an end marker, and compute perplexity using five predicted events.</strong></p><div class=\"given\"><h4>Given</h4><p>Each training sentence has one start and end marker. Test predictions: This, is, my, cat, &lt;/s&gt;. Thus N=5.</p><h4>To find</h4><p>Bigram sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cdcbde9621e0e24d.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h),\\qquad\\operatorname{PP}=P(W)^{-1/5}\" style=\"width:45.9ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start is given context. Four words plus the end marker produce five probability factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the required transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Transition</th><th>Pair count / history count</th></tr></thead><tbody><tr><td>&lt;s&gt;→This</td><td>3/4</td></tr><tr><td>This→is</td><td>3/3</td></tr><tr><td>is→my</td><td>1/3</td></tr><tr><td>my→cat</td><td>1/2</td></tr><tr><td>cat→&lt;/s&gt;</td><td>2/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Form the product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9c8a03a484dfb763.svg\" alt=\"P=\\frac34\\times1\\times\\frac13\\times\\frac12\\times1=\\frac18\" style=\"width:29.565ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/063b3931740c7830.svg\" alt=\"1/P=8\" style=\"width:8.11ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c0fbb6bb85c1b79f.svg\" alt=\"\\operatorname{PP}=8^{1/5}\\approx1.515717\" style=\"width:21.382ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(W)=1/8 and perplexity≈1.515717 using five predicted events.</div></section><p><strong>If the question explicitly states N = 6:</strong> use that supplied convention and report PP = 8<sup>1/6</sup> ≈ 1.414214. The class slide counts both boundary markers in N. Write the chosen N beside the formula; do not silently switch between 5 and 6. Also, This occurs three times and is follows it three times, so P(is|This)=3/3, not 3/4.</p><section class=\"example\"><p class=\"question\"><strong>Question. A uniform model assigns probability 1/10 to each actual next word in a five-token test. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Five scored tokens, each with assigned probability 0.1. N=5.</p><h4>To find</h4><p>The sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/245311d6fb2b9841.svg\" alt=\"P(W)=(1/10)^5,\\qquad \\operatorname{PP}=P(W)^{-1/5}\" style=\"width:37.412ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Uniform equal probabilities make the effective number of choices especially clear.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Multiply the five factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dbea309801bb43da.svg\" alt=\"P(W)=0.1^5=0.00001=10^{-5}\" style=\"width:30.672ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Invert</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a7f36a9eff1f3a2c.svg\" alt=\"1/P(W)=10^5\" style=\"width:14.36ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a14770a9a80e5984.svg\" alt=\"\\operatorname{PP}=(10^5)^{1/5}=10\" style=\"width:18.976ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 10.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Probability high → surprise low → perplexity low.</p></section>"},{"id":"log-probabilities","title":"Log probabilities: replace long products with sums","html":"<p>Probabilities are at most 1, so multiplying many of them produces very small numbers. Computers can round extremely small positive products to zero: <strong>numerical underflow</strong>. Log probabilities convert multiplication into addition and are more stable for long sequences. Natural logs use base e; log₂ uses base 2. Choose one base consistently.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cbf31ffd35c5c322.svg\" alt=\"\\ln P(W)=\\sum_{i=1}^{N}\\ln p_i\" style=\"width:18.897ex;height:6.74ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab927afa9cd05bef.svg\" alt=\"P(W)=e^{\\ln P(W)},\\qquad \\operatorname{PP}(W)=\\exp\\left(-\\frac1N\\sum_i\\ln p_i\\right)\" style=\"width:51.919ex;height:6.785ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The log of a probability below 1 is negative. A value closer to zero means a larger probability: ln(0.5) ≈ −0.693 is larger than ln(0.1) ≈ −2.303. A zero probability has log −∞; taking logs does not solve the unseen-event problem. Smoothing handles that separate problem.</p><section class=\"example\"><p class=\"question\"><strong>Question. The next-word probabilities are 0.5, 0.25 and 0.5. Calculate the natural log probability, ordinary probability and perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>p₁=0.5; p₂=0.25; p₃=0.5; N=3.</p><h4>To find</h4><p>ln P(W), P(W), and PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9bced9ebe87e44c7.svg\" alt=\"\\ln P=\\sum_i\\ln p_i,\\quad P=e^{\\ln P},\\quad\\operatorname{PP}=e^{-\\ln P/N}\" style=\"width:43.938ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Logarithms preserve products as sums and the exponent converts the result back.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute individual logs</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8fc9ba50109d8156.svg\" alt=\"\\ln0.5\\approx-0.693147,\\quad\\ln0.25\\approx-1.386294\" style=\"width:41.36ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add all three terms</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fcdc8edcec916f1f.svg\" alt=\"\\ln P=-0.693147-1.386294-0.693147\\approx-2.772589\" style=\"width:53.239ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Recover the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b886c03a804cf5a4.svg\" alt=\"P=e^{-2.772589}\\approx0.0625\" style=\"width:22.549ex;height:2.201ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find average negative log probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4d6cc3cf68cb5127.svg\" alt=\"-\\ln P/3\\approx2.772589/3=0.924196\" style=\"width:33.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Exponentiate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d34de424885d00e.svg\" alt=\"\\operatorname{PP}=e^{0.924196}\\approx2.519842\" style=\"width:24.949ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> ln P≈−2.772589, P=0.0625, PP≈2.519842.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A model has a total natural log probability −12 over six scored tokens. Calculate its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>ln P(W)=−12; N=6.</p><h4>To find</h4><p>PP without forming the tiny ordinary probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f166d1cce0943ce3.svg\" alt=\"\\operatorname{PP}=\\exp(-\\ln P(W)/N)\" style=\"width:24.688ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The logarithmic formula directly uses the supplied log score.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Negate the log score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/90abe91c0eba5423.svg\" alt=\"-\\ln P=12\" style=\"width:11.38ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Divide by token count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9d8a38c0a5d6d98a.svg\" alt=\"12/6=2\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply exponential</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d421123292e12a1.svg\" alt=\"\\operatorname{PP}=e^2\\approx7.389056\" style=\"width:19.705ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity≈7.389056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A language model's average negative log₂ probability is 3 bits per token. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Cross-entropy H=3 bits/token. Log base is 2.</p><h4>To find</h4><p>PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50941856f700d45e.svg\" alt=\"\\operatorname{PP}=2^H\" style=\"width:8.838ex;height:2.213ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The inverse operation of log₂ is raising 2 to that power; use e only for natural logs.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the log base</h5><p>Bits mean base 2.</p></div><div class=\"step\"><h5>Step 2. Raise the base to H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ffdeccced5f3a45.svg\" alt=\"\\operatorname{PP}=2^3=8\" style=\"width:12.366ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 8.</div><p class=\"cue\"><strong>Yaad rakho:</strong> ln use kiya toh e se wapas; log₂ use kiya toh 2 se wapas.</p></section>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-hmm","title":"HMM & decoding","unit":0,"sections":[{"id":"markov-chain","title":"Markov chains: read a transition table and multiply a path","html":"<p><strong>A Markov chain</strong> is a probabilistic model of a sequence of states. Under the first-order Markov assumption, the next state's probability depends on the current state rather than the complete previous history. The <strong>initial probability</strong> tells us how likely each first state is. A <strong>transition probability</strong> tells us how likely a move from one state to another is.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c9611ed107ec9047.svg\" alt=\"P(s_t\\mid s_1,\\ldots,s_{t-1})=P(s_t\\mid s_{t-1})\" style=\"width:32.192ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e50f813caaa8d825.svg\" alt=\"P(s_1,\\ldots,s_T)=P(s_1)\\prod_{t=2}^{T}P(s_t\\mid s_{t-1})\" style=\"width:36.137ex;height:6.73ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For T states in a path, use one initial factor and T−1 transition factors. A row-oriented transition matrix must have each complete row sum to 1. Always read the row/column labels; some exam diagrams use a transposed arrangement.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><section class=\"example\"><p class=\"question\"><strong>Question. For the Rain/Dry Markov chain with initial P(Rain)=0.4 and P(Dry)=0.6, and transitions Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8, find the probability of Dry, Dry, Rain, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Dry,Dry,Rain,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d6fc24a22e2f64d.svg\" alt=\"P(D,D,R,R)=P(D)P(D\\mid D)P(R\\mid D)P(R\\mid R)\" style=\"width:48.815ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each step conditions on the immediately preceding state. The sequence contains four states, so it needs one initial plus three transition factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start in Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cf847b7db44f5fad.svg\" alt=\"P(D)=0.6\" style=\"width:11.241ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move Dry to Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5e47f480eb58213.svg\" alt=\"0.6\\times0.8=0.48\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move Dry to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0e4bbd812b1ba4d.svg\" alt=\"0.48\\times0.2=0.096\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Rain to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/da540845c4cc326e.svg\" alt=\"0.096\\times0.3=0.0288\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.0288.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For initial probabilities Rain=0.4, Dry=0.6 and transition rows Rain=(0.3,0.7), Dry=(0.2,0.8) in column order Rain,Dry, find the probability of Rain, Dry, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Rain,Dry,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c4b2bba9bbf4c148.svg\" alt=\"P(R,D,R)=P(R)P(D\\mid R)P(R\\mid D)\" style=\"width:36.844ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Do not replace Dry→Rain with Rain→Dry: the two directional probabilities differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/634e8d0183974542.svg\" alt=\"P(R)=0.4\" style=\"width:11.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ff067547e9b897f.svg\" alt=\"P(D\\mid R)=0.7,\\quad0.4(0.7)=0.28\" style=\"width:32.695ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Second transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ca3a09e7de1ba004.svg\" alt=\"P(R\\mid D)=0.2,\\quad0.28(0.2)=0.056\" style=\"width:34.958ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same fully specified chain—initial Rain=0.4, Dry=0.6; Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8—find P(Dry,Dry). Also find the conditional probability of next Dry given current Dry.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>The two-state joint probability and the one-step conditional probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83080c3651cd8fc6.svg\" alt=\"P(D,D)=P(D)P(D\\mid D)\" style=\"width:25.653ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The joint path includes an uncertain initial state. The conditional transition assumes the current state is already Dry.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Read the conditional transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1cf8b238b738730b.svg\" alt=\"P(D\\mid D)=0.8\" style=\"width:15ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Include the initial state for the joint path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/21b9a2b02a067056.svg\" alt=\"P(D,D)=0.6\\times0.8=0.48\" style=\"width:26.817ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(Dry,Dry)=0.48; P(next Dry|current Dry)=0.8. These answer different questions.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Path: pehle start probability, phir har arrow ki probability.</p></section>"},{"id":"transition-emission-estimation","title":"Estimate transition and emission probabilities from tagged data","html":"<div class=\"equation\"><div class=\"math-display\"><img src=\"math/2145c612575540f3.svg\" alt=\"P(t&#39;\\mid t)=\\frac{C(t,t&#39;)}{C(t)\\text{ with a following tag/end event}}\" style=\"width:46.275ex;height:5.495ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a89d9641a3681129.svg\" alt=\"P(w\\mid t)=\\frac{C(w,t)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>In a transition denominator, count the previous tag's outgoing events. In an emission denominator, count all tokens bearing that tag. With explicit end transitions the totals align conveniently. Keep the two numerator types separate: tag→tag counts are not word→tag counts.</p><section class=\"example\"><p class=\"question\"><strong>Question. A tagged corpus contains 116454 determiner tags DT, each counted with an outgoing event. DT is followed by NN 56509 times. Estimate P(NN|DT).</strong></p><div class=\"given\"><h4>Given</h4><p>C(DT)=116454; C(DT,NN)=56509.</p><h4>To find</h4><p>The DT→NN transition probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5163e6a68004bc8.svg\" alt=\"P(NN\\mid DT)=C(DT,NN)/C(DT)\" style=\"width:35.893ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The denominator is the number of previous DT contexts because DT is the condition.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the transition count</h5><p>DT followed by NN occurs 56509 times.</p></div><div class=\"step\"><h5>Step 2. Identify the conditional total</h5><p>There are 116454 DT contexts.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/47e9bc9d8bc16788.svg\" alt=\"P(NN\\mid DT)=\\frac{56509}{116454}\\approx0.485247\" style=\"width:35.194ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(NN|DT)≈0.485247.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The tag VBZ occurs 21627 times, and 10073 of those tokens are the word “is”. Estimate P(is|VBZ).</strong></p><div class=\"given\"><h4>Given</h4><p>C(VBZ)=21627; C(is,VBZ)=10073.</p><h4>To find</h4><p>The emission probability of is from VBZ.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ec13ac6a8a9bdae.svg\" alt=\"P(is\\mid VBZ)=C(is,VBZ)/C(VBZ)\" style=\"width:36.42ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The condition is the tag VBZ; we ask which word it emits.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Choose the word-tag count</h5><p>The required word is is with tag VBZ: count 10073.</p></div><div class=\"step\"><h5>Step 2. Choose the tag total</h5><p>All VBZ-tagged word tokens: count 21627.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/481557575db95324.svg\" alt=\"P(is\\mid VBZ)=\\frac{10073}{21627}\\approx0.465760\" style=\"width:33.513ex;height:4.661ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(is|VBZ)≈0.465760. This is different from P(VBZ|is).</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use the tagged sentences “dogs/N chase/V cats/N” and “cats/N sleep/V”. Estimate the initial tag probabilities, all nonzero transitions including END, and emissions.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: START dogs/N chase/V cats/N END; START cats/N sleep/V END.</p><h4>To find</h4><p>Initial distribution, transition rows and emission rows.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/46d6d50083ab5629.svg\" alt=\"\\pi_t=C(START,t)/2,\\quad a_{tu}=C(t,u)/C(t),\\quad b_t(w)=C(w,t)/C(t)\" style=\"width:65.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The corpus explicitly tells us the tags, so we can count training frequencies directly.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count tag tokens</h5><p>N occurs 3 times: dogs, cats, cats. V occurs 2 times: chase, sleep.</p></div><div class=\"step\"><h5>Step 2. Count sentence starts</h5><p>Both sentences start with N.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a5ae0d0edad4515.svg\" alt=\"\\pi_N=2/2=1,\\quad \\pi_V=0/2=0\" style=\"width:29.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>N→V</td><td>2</td></tr><tr><td>N→END</td><td>1</td></tr><tr><td>V→N</td><td>1</td></tr><tr><td>V→END</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 4. Normalize transition rows</h5><div class=\"table-wrap\"><table><thead><tr><th>Current</th><th>To N</th><th>To V</th><th>To END</th></tr></thead><tbody><tr><td>N</td><td>0</td><td>2/3</td><td>1/3</td></tr><tr><td>V</td><td>1/2</td><td>0</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Count and normalize emissions</h5><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>dogs</th><th>cats</th><th>chase</th><th>sleep</th></tr></thead><tbody><tr><td>N</td><td>1/3</td><td>2/3</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/2</td><td>1/2</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> π=(1,0); transitions and emissions are given in the completed tables. Each complete probability row sums to 1.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Tag→tag table aur tag→word table ko mix mat karna.</p>"},{"id":"hot-cold-paths","title":"HMM path probabilities: three complete numerical examples","html":"<p>The following model uses hidden weather states Hot (H) and Cold (C). Observations are numbers 1, 2 and 3. These numbers are observation labels, not quantities to multiply directly. Their emission probabilities come from the table.</p><div class=\"table-wrap\"><table><thead><tr><th>Initial state</th><th>Probability</th></tr></thead><tbody><tr><td>H</td><td>0.8</td></tr><tr><td>C</td><td>0.2</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>From → to</th><th>H</th><th>C</th></tr></thead><tbody><tr><td>H</td><td>0.7</td><td>0.3</td></tr><tr><td>C</td><td>0.4</td><td>0.6</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Emission state</th><th>Observation 1</th><th>Observation 2</th><th>Observation 3</th></tr></thead><tbody><tr><td>H</td><td>0.2</td><td>0.4</td><td>0.4</td></tr><tr><td>C</td><td>0.5</td><td>0.4</td><td>0.1</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for observations (1,2,3) are H:(0.2,0.4,0.4) and C:(0.5,0.4,0.1). Find the joint probability of hidden path H,C,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path H→C→H. Observations 1→3→1. Model probabilities are specified in the question. There is no END factor.</p><h4>To find</h4><p>P(H,C,H; 1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d9c99617b5e16c0.svg\" alt=\"P=\\pi_H b_H(1)a_{HC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.863ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>There are three hidden states and observations: three emissions, two transitions, and one initial probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Hot and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/78369e147be76567.svg\" alt=\"0.8\\times0.2=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Transition Hot to Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/24d6c09c3069c91f.svg\" alt=\"0.16\\times0.3=0.048\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Cold emits 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/59bb445235ff63a6.svg\" alt=\"0.048\\times0.1=0.0048\" style=\"width:20.113ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Transition Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1146803e8605f2e.svg\" alt=\"0.0048\\times0.4=0.00192\" style=\"width:22.376ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Hot emits the last 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e3b740dc0fd787f.svg\" alt=\"0.00192\\times0.2=0.000384\" style=\"width:24.638ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.000384 = 3.84×10⁻⁴.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels (1,2,3), find the joint probability of path H,H,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>State path H→H→H, observations 1→3→1; no END factor.</p><h4>To find</h4><p>P(H,H,H;1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83f5cb754dc77195.svg\" alt=\"P=\\pi_H b_H(1)a_{HH}b_H(3)a_{HH}b_H(1)\" style=\"width:32.477ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The state remains Hot; each transition still contributes its probability 0.7.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial state and first emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/806228a802bab106.svg\" alt=\"0.8(0.2)=0.16\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f1106c30e00cc2ce.svg\" alt=\"0.16(0.7)=0.112\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/359ae9ea2534c8f2.svg\" alt=\"0.112(0.4)=0.0448\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Second self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d2be9254f3d2eee1.svg\" alt=\"0.0448(0.7)=0.03136\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit final observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/af971b25ad6922c0.svg\" alt=\"0.03136(0.2)=0.006272\" style=\"width:23.632ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.006272. A self-transition is not automatically probability 1.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6) in next-state order H,C; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3, find the score of path C,C,H with observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path C→C→H. Observation sequence 1→3→1. No end-state factor.</p><h4>To find</h4><p>The joint path-and-observation probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c39dbc8fa9b14a01.svg\" alt=\"P=\\pi_C b_C(1)a_{CC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.248ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The initial state is Cold, so use π(C), not π(H). Each emission is selected from the state at the same position.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Cold and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ea1ebd665b713576.svg\" alt=\"0.2(0.5)=0.1\" style=\"width:13.451ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Stay Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3af50c5661f75952.svg\" alt=\"0.1(0.6)=0.06\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit 3 from Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2039ca068efac123.svg\" alt=\"0.06(0.1)=0.006\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99539fe7f4612c73.svg\" alt=\"0.006(0.4)=0.0024\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit 1 from Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/315780f838015183.svg\" alt=\"0.0024(0.2)=0.00048\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.00048.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har column par: state ka emission. Columns ke beech: transition.</p></section>"},{"id":"tagging-corpus-case","title":"POS HMM worked corpus: Mary, Jane, can, will and spot","html":"<p>The class example contains words that can be either names or ordinary verbs/modal auxiliaries. The term is <strong>modal</strong> (M), not “model”. To avoid guessing tags from spelling, the training corpus below supplies them explicitly and lowercases words for the emission vocabulary.</p><div class=\"table-wrap\"><table><thead><tr><th>Training sentence</th><th>Gold tags</th></tr></thead><tbody><tr><td>mary jane can see will</td><td>N N M V N</td></tr><tr><td>spot will see mary</td><td>N M V N</td></tr><tr><td>will jane spot mary</td><td>M N V N</td></tr><tr><td>mary will pat spot</td><td>N M V N</td></tr></tbody></table></div><p>There are 9 noun tokens, 4 modal tokens and 4 verb tokens. Each sentence includes a start and end transition. For nouns, the next event can be another noun, modal, verb or END.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>N</th><th>M</th><th>V</th><th>END</th></tr></thead><tbody><tr><td>START</td><td>3/4</td><td>1/4</td><td>0</td><td>0</td></tr><tr><td>N</td><td>1/9</td><td>3/9</td><td>1/9</td><td>4/9</td></tr><tr><td>M</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td></tr><tr><td>V</td><td>4/4</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Tag → word</th><th>mary</th><th>jane</th><th>can</th><th>see</th><th>will</th><th>spot</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>4/9</td><td>2/9</td><td>0</td><td>0</td><td>1/9</td><td>2/9</td><td>0</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>0</td><td>2/4</td><td>0</td><td>1/4</td><td>1/4</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Using the fully tagged four-sentence corpus above, calculate the joint score of “will jane spot mary” assigned tags M,N,V,N, including END.</strong></p><div class=\"given\"><h4>Given</h4><p>Required factors from the tables: START→M=1/4; emit will|M=3/4; M→N=1/4; jane|N=2/9; N→V=1/9; spot|V=1/4; V→N=1; mary|N=4/9; N→END=4/9.</p><h4>To find</h4><p>The specified tag-path score, including words and sentence end.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/23c70e8086b83a3b.svg\" alt=\"P=\\pi_M b_M(will)a_{MN}b_N(jane)a_{NV}b_V(spot)a_{VN}b_N(mary)a_{N,END}\" style=\"width:62.792ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both transitions and emissions are needed. A tag transition alone cannot tell us whether a particular word is plausible.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start and emit will</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a7d30f8cd240d72.svg\" alt=\"\\frac14\\times\\frac34=\\frac3{16}\" style=\"width:13.294ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move to N and emit jane</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/934eaa8bf4f9d42a.svg\" alt=\"\\frac3{16}\\times\\frac14\\times\\frac29=\\frac1{96}\" style=\"width:19.318ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move to V and emit spot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/40b213c06ef8b7d2.svg\" alt=\"\\frac1{96}\\times\\frac19\\times\\frac14=\\frac1{3456}\" style=\"width:21.58ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move to N and emit mary</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a0e9571f3b95594c.svg\" alt=\"\\frac1{3456}\\times1\\times\\frac49=\\frac1{7776}\" style=\"width:22.847ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/171a6c8b22e17d35.svg\" alt=\"\\frac1{7776}\\times\\frac49=\\frac1{17496}\\approx0.0000571559\" style=\"width:36.171ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The joint score is 1/17496 ≈ 0.0000571559.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same tagged corpus and tables, explain the unsmoothed score of “will can spot mary” assigned tags M,V,N,N.</strong></p><div class=\"given\"><h4>Given</h4><p>The proposed second word is can with hidden tag V. In the training corpus, can occurs only with M, so b_V(can)=0.</p><h4>To find</h4><p>Whether the complete path score is zero and what this means.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0957b6ab0a1aa0cc.svg\" alt=\"P(\\text{path,words})=(\\text{other required factors})\\times b_V(can)\" style=\"width:50.674ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A product containing one zero factor is zero even if every other factor is positive.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the critical emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fdca0f8e7f8d838a.svg\" alt=\"b_V(can)=C(can,V)/C(V)=0/4=0\" style=\"width:37.369ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the full-product consequence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e316f36777dd5.svg\" alt=\"P(\\text{path,words})=0\" style=\"width:18.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Interpret correctly</h5><p>This unsmoothed corpus model has no evidence for can as a verb. It does not prove that a verb usage of can is impossible in English.</p></div><div class=\"answer\"><strong>Final answer.</strong> The unsmoothed path score is zero.</div></section>"},{"id":"sequence-count","title":"Why exhaustive search grows exponentially","html":"<p>If each of T observed words can receive any of N tags, there are N choices at each position. Thus the total number of complete tag sequences is N multiplied by itself T times. This counts possible assignments before grammar rules or zero probabilities eliminate any.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/014ed66c3c0df2b1.svg\" alt=\"\\text{Number of tag sequences}=N^T\" style=\"width:30.626ex;height:2.484ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A four-word sentence is tagged using three possible POS tags per word. How many complete tag sequences are possible?</strong></p><div class=\"given\"><h4>Given</h4><p>N=3 possible tags per position; T=4 word positions.</p><h4>To find</h4><p>The number of tag sequences.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every independent position contributes a factor of three choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write one factor per position</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d7b06b7e39ae0a5.svg\" alt=\"M=3\\times3\\times3\\times3\" style=\"width:18.217ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6570633fef12ecb5.svg\" alt=\"3\\times3=9,\\quad9\\times3=27,\\quad27\\times3=81\" style=\"width:37.46ex;height:1.968ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 81 possible tag sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A five-word sentence has two candidate tags per word. Count its tag sequences.</strong></p><div class=\"given\"><h4>Given</h4><p>N=2; T=5.</p><h4>To find</h4><p>M.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The length is the exponent, not a multiplier.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Substitute</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e0b25a2374d09c2d.svg\" alt=\"M=2^5\" style=\"width:7.514ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/85ec03497588b6d5.svg\" alt=\"2\\times2\\times2\\times2\\times2=32\" style=\"width:21.998ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 32 possible sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using 45 possible tags, compare the number of tag sequences for sentences of length 2 and 3.</strong></p><div class=\"given\"><h4>Given</h4><p>N=45. First T=2, then T=3.</p><h4>To find</h4><p>Both counts and the growth factor.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0806abcd5d0a43e.svg\" alt=\"M_2=45^2,\\quad M_3=45^3\" style=\"width:22.167ex;height:2.439ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Adding one position multiplies the possibilities by the number of tag choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Two words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/672617aa8909800b.svg\" alt=\"45^2=2025\" style=\"width:10.792ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Three words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/96a0c5c55e4f8048.svg\" alt=\"45^3=2025\\times45=91125\" style=\"width:24.493ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3daee8fcfcc1adea.svg\" alt=\"91125/2025=45\" style=\"width:16.592ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 2 words: 2025 paths. 3 words: 91125 paths. One additional word multiplies the count by 45.</div></section><p>The slides introduce Viterbi to avoid enumerating every path. It reuses the best prefix score for each ending state. For a dense first-order HMM, it needs O(TN²) recurrence work instead of enumerating N<sup>T</sup> complete paths.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Choices per word ki power = sentence length.</p>"},{"id":"viterbi-explained","title":"Viterbi decoding: compare incoming paths, keep the best, trace back","html":"<p><strong>The Viterbi algorithm</strong> finds the most likely hidden-state sequence for a fixed observation sequence. At each position, it keeps the best path ending in each state. This is safe because, under the HMM assumptions, future extensions depend on that ending state, not the discarded details of the prefix.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3fa79f3d8232431.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1)\" style=\"width:15.501ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50951d9d0cf5dcf6.svg\" alt=\"\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:27.716ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3935aac800940d84.svg\" alt=\"\\psi_t(j)=\\arg\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:25.893ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning in ordinary words</th></tr></thead><tbody><tr><td>δₜ(j)</td><td>Score of the best prefix that ends in state j at position t.</td></tr><tr><td>ψₜ(j)</td><td>Previous state that supplied that best prefix; keep it as a backpointer.</td></tr><tr><td>max</td><td>Choose the larger candidate score; do not add.</td></tr><tr><td>argmax</td><td>Remember which previous state won, rather than only its value.</td></tr></tbody></table></div><div class=\"flow\"><div class=\"node\">Initialize: start × first emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">For each next state: compare incoming scores</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Multiply winner by this state's emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Keep score + winning predecessor</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose best final state and trace arrows backward</div></div><p>Do not choose the best state independently at each word. The best last state can come from a different best predecessor than a local guess. Backpointers recover one consistent complete path. If scores tie, either tied path is optimal under the model; state the tie.</p><section class=\"example\"><p class=\"question\"><strong>Question. Use an HMM with π(H)=0.8, π(C)=0.2, transitions H:(0.7,0.3), C:(0.4,0.6) in H,C order, and emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3. Find the most likely hidden path for observations 1,3,1 using Viterbi.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>The best hidden-state sequence and its joint score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/712c98f9c4966f84.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1),\\quad\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:46.485ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Viterbi keeps two best prefix scores per column, one ending H and one ending C.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize at observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/44fc29f14406bbca.svg\" alt=\"\\delta_1(H)=0.8(0.2)=0.16\" style=\"width:23.361ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1500f80244db39b.svg\" alt=\"\\delta_1(C)=0.2(0.5)=0.10\" style=\"width:23.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. At observation 3, calculate the H cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/61623e2cd024bab3.svg\" alt=\"H\\to H:\\ 0.16(0.7)=0.112\" style=\"width:26.834ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/256055f1b5c81a60.svg\" alt=\"C\\to H:\\ 0.10(0.4)=0.040\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ee04f7fda3bf226b.svg\" alt=\"\\delta_2(H)=\\max(0.112,0.040)(0.4)=0.0448\" style=\"width:40.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this H cell: H.</p></div><div class=\"step\"><h5>Step 3. At observation 3, calculate the C cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e9c32ed85546537.svg\" alt=\"H\\to C:\\ 0.16(0.3)=0.048\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c0863275b12a91e.svg\" alt=\"C\\to C:\\ 0.10(0.6)=0.060\" style=\"width:26.255ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a8ea78adb0cc4576.svg\" alt=\"\\delta_2(C)=\\max(0.048,0.060)(0.1)=0.006\" style=\"width:38.596ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this C cell: C.</p></div><div class=\"step\"><h5>Step 4. At final observation 1, calculate H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e2373be2aa769a8.svg\" alt=\"H\\to H:\\ 0.0448(0.7)=0.03136\" style=\"width:31.359ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/286832c2c26620dd.svg\" alt=\"C\\to H:\\ 0.006(0.4)=0.0024\" style=\"width:28.807ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/48b05bab6b13e38a.svg\" alt=\"\\delta_3(H)=0.03136(0.2)=0.006272\" style=\"width:32.411ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 5. At final observation 1, calculate C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5f431d2a23d6fe1.svg\" alt=\"H\\to C:\\ 0.0448(0.3)=0.01344\" style=\"width:31.069ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b69919a26d75a560.svg\" alt=\"C\\to C:\\ 0.006(0.6)=0.0036\" style=\"width:28.517ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/709ea0da7f36d663.svg\" alt=\"\\delta_3(C)=0.01344(0.5)=0.00672\" style=\"width:30.99ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 6. Select the final state</h5><p>0.00672 > 0.006272, so the best final state is C.</p></div><div class=\"step\"><h5>Step 7. Trace back</h5><p>Final C came from H at position2. That H came from H at position1. Reading forward gives H,H,C.</p></div><div class=\"step\"><h5>Step 8. Verify the recovered complete path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5aa4b0fd88f37247.svg\" alt=\"0.8(0.2)(0.7)(0.4)(0.3)(0.5)=0.00672\" style=\"width:36.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H→C with joint score 0.00672.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best two-state hidden path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/801327bb8fdbd394.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(3),\\quad\\delta_2(j)=b_j(1)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same recurrence applies even though the observation order changed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2e38d10b83c569f4.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.1)=0.02\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1716d45167a355a0.svg\" alt=\"\\max(0.32(0.7),0.02(0.4))(0.2)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4db3393304c21c23.svg\" alt=\"=\\max(0.224,0.008)(0.2)=0.0448\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 3. Calculate the final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bd4ebf48e761f108.svg\" alt=\"\\max(0.32(0.3),0.02(0.6))(0.5)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15d2f168f4fe9604.svg\" alt=\"=\\max(0.096,0.012)(0.5)=0.048\" style=\"width:32.495ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>Final C wins with 0.048 and came from H. The path is H,C.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→C, score 0.048.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 2,2.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a478f4924f42dec2.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(2),\\quad\\delta_2(j)=b_j(2)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both states emit2 with probability 0.4, but their initial and transition probabilities still differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/56ea5abfdb65b387.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.4)=0.08\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75472da37ba442a1.svg\" alt=\"\\max(0.32(0.7),0.08(0.4))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f9a0610a246e0ed0.svg\" alt=\"=\\max(0.224,0.032)(0.4)=0.0896\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 3. Final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/87b9dd83765528d1.svg\" alt=\"\\max(0.32(0.3),0.08(0.6))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/088fd26aaafea320.svg\" alt=\"=\\max(0.096,0.048)(0.4)=0.0384\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>The final H score 0.0896 is larger. Its predecessor is H.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H with score 0.0896.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har destination ke liye incoming paths compare; winner ka arrow yaad.</p></section>"},{"id":"joint-vs-posterior","title":"A path score is not the probability of the observed sentence","html":"<section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3. For observations 1,3, calculate the probability of the observations by summing all four two-state paths.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>P(observations 1,3), not just the best-path score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e591ebf359dce.svg\" alt=\"P(o_1,o_2)=\\sum_{s_1,s_2}\\pi_{s_1}b_{s_1}(o_1)a_{s_1s_2}b_{s_2}(o_2)\" style=\"width:35.484ex;height:5.061ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The hidden path is unspecified, so its mutually exclusive alternatives must be summed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score H,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c316d3e7d10ea4e8.svg\" alt=\"0.8(0.2)(0.7)(0.4)=0.0448\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Score H,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/076745077c7c6109.svg\" alt=\"0.8(0.2)(0.3)(0.1)=0.0048\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Score C,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2dbad158b7e2df38.svg\" alt=\"0.2(0.5)(0.4)(0.4)=0.016\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Score C,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/595d09221813b65c.svg\" alt=\"0.2(0.5)(0.6)(0.1)=0.006\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Add all paths</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2b05babdadbfdf90.svg\" alt=\"P(1,3)=0.0448+0.0048+0.016+0.006=0.0716\" style=\"width:50.222ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Observation probability =0.0716. The best single-path score 0.0448 is a different quantity.</div></section><p>If asked for the posterior of path H,H given observations 1,3, normalize: 0.0448/0.0716 ≈0.625698. Viterbi chooses the best path using joint scores because the observation denominator is common to every candidate. It does not compute that denominator by taking a maximum.</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-wsd","title":"WSD: Lesk & Naive Bayes","unit":0,"sections":[{"id":"u5-lesk","title":"Lesk algorithm, from words to overlap scores","html":"<p><strong>Lesk is a knowledge-based WSD method that chooses senses whose dictionary descriptions have the greatest overlap with contextual evidence.</strong> Original Lesk compares definitions of neighbouring words' senses. A common simplified version compares each target-sense gloss directly with the sentence context. State which version you use.</p><h3>Simplified Lesk procedure</h3><ol><li>Remove the target word from the context; tokenize and normalize the remaining content words.</li><li>Obtain the gloss for each candidate sense and apply the same normalization.</li><li>Count shared words between the context and each gloss.</li><li>Select the sense with maximum overlap. If scores tie, report the tie or use a specified tie-break rule.</li></ol><div class=\"math-display\"><img src=\"math/691fb54513999f0d.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|,\\qquad s^*=\\arg\\max_s\\operatorname{score}(s)\" style=\"width:45.416ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b5a9729b8c25c0f7.svg\" alt=\"C\" style=\"width:1.719ex;height:1.645ex\" loading=\"lazy\" decoding=\"async\"></span> is the set of context words, <span class=\"math-inline\"><img src=\"math/a5684e27b28daffa.svg\" alt=\"G_s\" style=\"width:2.716ex;height:1.95ex\" loading=\"lazy\" decoding=\"async\"></span> the set of words in sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>'s gloss, <span class=\"math-inline\"><img src=\"math/c7de95563fc530c3.svg\" alt=\"\\cap\" style=\"width:1.509ex;height:1.403ex\" loading=\"lazy\" decoding=\"async\"></span> means common elements, <span class=\"math-inline\"><img src=\"math/468f3b6d2f1b95a0.svg\" alt=\"|\\cdot|\" style=\"width:2.892ex;height:2.26ex\" loading=\"lazy\" decoding=\"async\"></span> means count, and <span class=\"math-inline\"><img src=\"math/dfccac0c4f581832.svg\" alt=\"\\arg\\max\" style=\"width:7.737ex;height:1.491ex\" loading=\"lazy\" decoding=\"async\"></span> means “the sense giving the largest score”. This version counts unique matching words once.</p><div class=\"example\"><p><strong>Question. Use simplified Lesk to disambiguate “bank” in “The river water rose near the bank.” Use C = {river, water, rose, near}; financial gloss = {institution, money, deposit}; river gloss = {land, river, water, edge}.</strong></p><div class=\"given\"><h4>Given</h4><p>The normalized context and two gloss sets are given. Count exact shared words.</p><h4>To find</h4><p>The score of each sense and the selected meaning.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because the task specifies context–gloss overlap.</p><div class=\"step\"><h4>Step 1. Compare the financial sense</h4><p>No word occurs in both {river, water, rose, near} and {institution, money, deposit}. Overlap = {}.</p></div><div class=\"step\"><h4>Step 2. Count the financial score</h4><p><span class=\"math-inline\"><img src=\"math/bdc75dbcd361db69.svg\" alt=\"\\operatorname{score}(F)=0\" style=\"width:12.522ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare the river sense</h4><p>Shared words are {river, water}. “Rose” and “near” are not in the gloss.</p></div><div class=\"step\"><h4>Step 4. Count and select</h4><p><span class=\"math-inline\"><img src=\"math/384740febd8dd4b0.svg\" alt=\"\\operatorname{score}(R)=2\" style=\"width:12.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Since <span class=\"math-inline\"><img src=\"math/6e25b81ec200909a.svg\" alt=\"2&gt;0\" style=\"width:5.28ex;height:1.597ex\" loading=\"lazy\" decoding=\"async\"></span>, choose the river-edge sense.</p></div><p class=\"answer\"><strong>Answer.</strong> Bank means land beside a river.</p></div><div class=\"example\"><p><strong>Question. Use simplified Lesk for “The dog barked loudly.” Treat barked as bark. Context C = {dog, loudly}; sound gloss = {sharp, cry, dog}; tree gloss = {outer, covering, tree}; ship gloss = {sailing, ship}.</strong></p><div class=\"given\"><h4>Given</h4><p>Three glosses and normalized context {dog, loudly}.</p><h4>To find</h4><p>Select the sense of bark.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Lemmatization lets barked match the target lemma bark; it does not create additional overlap words.</p><div class=\"step\"><h4>Step 1. Sound sense</h4><p>Intersection = {dog}; score = 1.</p></div><div class=\"step\"><h4>Step 2. Tree sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 3. Ship sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>The sound sense has the unique maximum: 1 &gt; 0.</p></div><p class=\"answer\"><strong>Answer.</strong> Bark is the dog's cry.</p></div><div class=\"example\"><p><strong>Question. Apply definition–definition Lesk to “pine cone”. Pine senses: P1 = {evergreen, tree, needle, leaf}; P2 = {waste, sorrow, illness}. Cone senses: C1 = {solid, shape, circular}; C2 = {fruit, evergreen, tree}.</strong></p><div class=\"given\"><h4>Given</h4><p>Two candidate senses for each word. Tokens are already normalized; tree and trees would be reduced to the same form if necessary.</p><h4>To find</h4><p>The most compatible pair of senses.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/bb2259d0f8a3b048.svg\" alt=\"|G_{P_i}\\cap G_{C_j}|\" style=\"width:10.997ex;height:2.506ex\" loading=\"lazy\" decoding=\"async\"></span> for every pair because this is original-style gloss–gloss comparison.</p><div class=\"step\"><h4>Step 1. P1 with C1</h4><p>No shared word → 0.</p></div><div class=\"step\"><h4>Step 2. P1 with C2</h4><p>Shared {evergreen, tree} → 2.</p></div><div class=\"step\"><h4>Step 3. P2 with each cone sense</h4><p>P2–C1 has no overlap → 0; P2–C2 has no overlap → 0.</p></div><div class=\"step\"><h4>Step 4. Choose the best pair</h4><p>The four scores are 0, 2, 0, 0. Maximum 2 belongs to P1–C2.</p></div><p class=\"answer\"><strong>Answer.</strong> Pine is the evergreen tree; cone is its fruit-like reproductive structure.</p></div><p><strong>Limitations:</strong> exact overlap misses synonyms, short glosses may produce zeros, and different preprocessing choices change the score. Extended Lesk may include related synset definitions or longer phrase overlaps; do not silently substitute it for a simple question.</p><p class=\"cue\">Lesk: context aur dictionary mein common words gino; sabse bada overlap jeeta.</p>"},{"id":"u5-walker","title":"Thesaurus / Walker approach, with three complete examples","html":"<p><strong>The Walker approach uses thesaurus categories as semantic evidence.</strong> Associate each candidate sense with a category. Count or weight context words that support that category. Choose the largest total.</p><div class=\"math-display\"><img src=\"math/9d7b8384c080650b.svg\" alt=\"\\operatorname{score}(s)=\\sum_{w\\in C} I(w,\\operatorname{category}(s))\" style=\"width:31.274ex;height:4.963ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b186266d0d476166.svg\" alt=\"I=1\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> if the supplied category mapping says the context word supports the sense, otherwise <span class=\"math-inline\"><img src=\"math/5fd951e2f99cd39c.svg\" alt=\"I=0\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>. The summation symbol means add all those contributions. Weighted questions may replace 1 with a supplied weight. Category membership must be supplied or justified; it is not guessed from word frequency.</p><div class=\"example\"><p><strong>Question. Disambiguate bank using Walker scoring. Context words are money, interest, annum, fetch. The finance category supports money, interest and annum; the location category supports none of these words.</strong></p><div class=\"given\"><h4>Given</h4><p>Two categories: Finance and Location. Each supported word contributes 1.</p><h4>To find</h4><p>The two totals and selected bank sense.</p></div><h4>Formula and why it applies</h4><p>Sum the category indicators for each sense.</p><div class=\"step\"><h4>Step 1. Make a contribution table</h4><table><thead><tr><th>Word</th><th>Finance</th><th>Location</th></tr></thead><tbody><tr><td>money</td><td>1</td><td>0</td></tr><tr><td>interest</td><td>1</td><td>0</td></tr><tr><td>annum</td><td>1</td><td>0</td></tr><tr><td>fetch</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Add Finance</h4><p><span class=\"math-inline\"><img src=\"math/6a517f05661478a7.svg\" alt=\"1+1+1+0=3\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Location</h4><p><span class=\"math-inline\"><img src=\"math/79d13a087a88c477.svg\" alt=\"0+0+0+0=0\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Select</h4><p>3 &gt; 0, so select the financial institution.</p></div><p class=\"answer\"><strong>Answer.</strong> Finance, with score 3 versus 0.</p></div><div class=\"example\"><p><strong>Question. Use Walker scoring for “The fisherman caught bass beside the lake.” Context {fisherman,caught,lake}. The Fish category contains all three clues; the Music category contains none.</strong></p><div class=\"given\"><h4>Given</h4><p>Fish and Music senses, binary category membership given.</p><h4>To find</h4><p>The correct bass sense.</p></div><h4>Formula and why it applies</h4><p>Score = sum of context-category matches.</p><div class=\"step\"><h4>Step 1. Record Fish matches</h4><p>fisherman → 1; caught → 1; lake → 1.</p></div><div class=\"step\"><h4>Step 2. Add Fish score</h4><p><span class=\"math-inline\"><img src=\"math/7e22dbf6b1c68d2b.svg\" alt=\"1+1+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Music score</h4><p><span class=\"math-inline\"><img src=\"math/f4ccd7a1f1f516c9.svg\" alt=\"0+0+0=0\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Choose</h4><p>Fish has the larger score.</p></div><p class=\"answer\"><strong>Answer.</strong> Bass refers to a fish.</p></div><div class=\"example\"><p><strong>Question. Score “The player used a bat in the match.” Context {player,match}. Sport supports both words with weights 2 and 1; Animal supports neither. Use the supplied weighted Walker scheme.</strong></p><div class=\"given\"><h4>Given</h4><p>Sport weights {player:2, match:1}; Animal weights {player:0, match:0}.</p><h4>To find</h4><p>Weighted sense scores.</p></div><h4>Formula and why it applies</h4><p>Use the sum of supplied weights, not an unweighted count, because the question explicitly gives weights.</p><div class=\"step\"><h4>Step 1. Sport contribution of player</h4><p>Add 2.</p></div><div class=\"step\"><h4>Step 2. Sport contribution of match</h4><p>Add 1. Sport total = 2 + 1 = 3.</p></div><div class=\"step\"><h4>Step 3. Animal total</h4><p>0 + 0 = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>3 &gt; 0 selects the sporting implement.</p></div><p class=\"answer\"><strong>Answer.</strong> Bat is the sports implement.</p></div><p class=\"cue\">Walker: dictionary ke exact words nahi, context kis topic/category ko support karta hai woh count.</p>"},{"id":"u5-bayes-steps","title":"Multinomial Naive Bayes: the exact solving method","html":"<p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><h3>Always keep these counts separate</h3><p>Class priors use <strong>number of examples</strong>. Word likelihoods in this multinomial model use <strong>number of word occurrences</strong>. The vocabulary counts <strong>unique words across all classes</strong>.</p><ol><li>List the class examples and calculate priors.</li><li>Write one shared vocabulary and count its size.</li><li>Count total word occurrences in each class.</li><li>Count each query word in each class.</li><li>Apply the given smoothing rule.</li><li>Multiply each prior by all its query likelihoods.</li><li>Compare scores; divide each score by their sum only if a normalized posterior is requested.</li></ol><div class=\"math-display\"><img src=\"math/0fd59effd2bb7926.svg\" alt=\"P(s\\mid C)=\\frac{\\operatorname{score}(s)}{\\sum_{s&#39;}\\operatorname{score}(s&#39;)}.\" style=\"width:25.283ex;height:5.571ex\" loading=\"lazy\" decoding=\"async\"></div><p><strong>Why smoothing is needed:</strong> an unseen clue gives <span class=\"math-inline\"><img src=\"math/5d29fa66aa3ef2ee.svg\" alt=\"0/N_s=0\" style=\"width:9.166ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; one zero makes the whole product zero. Add-one smoothing redistributes probability across every vocabulary word and prevents these zero factors. Use it only when requested, taught for the task, or state the assumption.</p><p><strong>Different model warning:</strong> a Bernoulli Naive Bayes question counts presence/absence per document and may include absence factors. Do not use its denominator in a multinomial word-count question.</p><p class=\"cue\">Pehle sentences se prior; phir words se likelihood; dono counts mix mat kar.</p>"},{"id":"u5-bayes-mam","title":"Mam's bank numerical—every count and every multiplication","html":"<div class=\"example\"><p><strong>Question. Classify the sense of “bank” using the training table below. The sentence is: “As the stream flowed gently past the shore, we set up camp by the bank of the river, discussing the possibility of borrowing a loan to buy a boat for future trips.” Use only the highlighted feature words stream, shore and loan, and add-one multinomial smoothing.</strong></p><div class=\"given\"><h4>Given</h4><table><thead><tr><th>Training row</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>money, deposit, loan</td><td>Finance</td></tr><tr><td>2</td><td>river, water, shore</td><td>Riverbank</td></tr><tr><td>3</td><td>account, savings, investment</td><td>Finance</td></tr><tr><td>4</td><td>boat, river, stream</td><td>Riverbank</td></tr><tr><td>5</td><td>branch, deposit, check</td><td>Finance</td></tr><tr><td>6</td><td>fishing, shore, river</td><td>Riverbank</td></tr></tbody></table><p>Query feature set: {stream, shore, loan}. Other sentence words are not included as features in this supplied example.</p><h4>To find</h4><p>The most probable bank sense and normalized posteriors.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Calculate priors</h4><p>Finance appears in 3 of the 6 rows; Riverbank appears in 3 of 6.</p><div class=\"math-display\"><img src=\"math/2f05aa3a89468f5e.svg\" alt=\"P(F)=\\frac36=\\frac12,\\qquad P(R)=\\frac36=\\frac12.\" style=\"width:37.065ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Construct the vocabulary</h4><p>{money, deposit, loan, river, water, shore, account, savings, investment, boat, stream, fishing, branch, check}. Thus V=14. Repeated deposit or river is counted once in vocabulary.</p></div><div class=\"step\"><h4>Step 3. Count word occurrences per class</h4><p>There are 3 finance rows × 3 words = 9 word occurrences. There are 3 river rows × 3 words = 9. Thus <span class=\"math-inline\"><img src=\"math/2fe9227521f0d9d8.svg\" alt=\"N_F=N_R=9\" style=\"width:13.587ex;height:1.918ex\" loading=\"lazy\" decoding=\"async\"></span>, and each smoothed denominator is <span class=\"math-inline\"><img src=\"math/989b4387cd367e7a.svg\" alt=\"9+14=23\" style=\"width:11.439ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Count the three query words</h4><table><thead><tr><th>Word</th><th>Finance count</th><th>Riverbank count</th></tr></thead><tbody><tr><td>stream</td><td>0</td><td>1</td></tr><tr><td>shore</td><td>0</td><td>2</td></tr><tr><td>loan</td><td>1</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 5. Calculate finance likelihoods</h4><div class=\"math-display\"><img src=\"math/dece6048e91d14ee.svg\" alt=\"P(\\text{stream}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:29.034ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/48b17e3adf6f62bb.svg\" alt=\"P(\\text{shore}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:27.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/622a2e615b1ad17f.svg\" alt=\"P(\\text{loan}\\mid F)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:26.505ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Multiply the finance score</h4><div class=\"math-display\"><img src=\"math/ca9dd31ae9d5dc12.svg\" alt=\"\\operatorname{score}(F)=\\frac12\\times\\frac1{23}\\times\\frac1{23}\\times\\frac2{23}=\\frac1{23^3}=\\frac1{12167}\\approx0.00008219.\" style=\"width:62.975ex;height:4.949ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 7. Calculate river likelihoods</h4><div class=\"math-display\"><img src=\"math/0612a35cf28c3394.svg\" alt=\"P(\\text{stream}\\mid R)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:29.057ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c71632f8b691648b.svg\" alt=\"P(\\text{shore}\\mid R)=\\frac{2+1}{23}=\\frac3{23}\" style=\"width:27.55ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/bff44b72ce8cc8e7.svg\" alt=\"P(\\text{loan}\\mid R)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:26.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 8. Multiply the river score</h4><div class=\"math-display\"><img src=\"math/665624fd363dd007.svg\" alt=\"\\operatorname{score}(R)=\\frac12\\times\\frac2{23}\\times\\frac3{23}\\times\\frac1{23}=\\frac3{12167}\\approx0.00024657.\" style=\"width:55.735ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 9. Compare scores</h4><p>3/12167 is larger than 1/12167. Riverbank wins even though “loan” is financial evidence: the combined clues matter.</p></div><div class=\"step\"><h4>Step 10. Normalize if a posterior is requested</h4><div class=\"math-display\"><img src=\"math/4b082736e405b96c.svg\" alt=\"P(F\\mid C)=\\frac{1/12167}{4/12167}=\\frac14=0.25\" style=\"width:32.874ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/371000172a7d5f5f.svg\" alt=\"P(R\\mid C)=\\frac{3/12167}{4/12167}=\\frac34=0.75.\" style=\"width:33.525ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Bank is the riverbank sense. Scores are 1/12167 and 3/12167; normalized model posteriors are 0.25 and 0.75.</p></div><p><strong>Without smoothing:</strong> stream and shore are absent in Finance; loan is absent in Riverbank. Both unsmoothed scores become zero, so there is no valid winning class from those products. Also, unnormalized scores should not be labelled as final posterior probabilities.</p><p class=\"cue\">Zero word? Add-one: count+1 upar, total words+vocabulary neeche. Last mein score bada wala sense.</p>"},{"id":"u5-bayes-practice","title":"More WSD numericals: given likelihoods, unequal priors and repeated clues","html":"<div class=\"example\"><p><strong>Question. For bass, let P(Fish)=0.6 and P(Music)=0.4. Given Fish likelihoods P(caught|Fish)=0.5, P(lake|Fish)=0.4 and Music likelihoods P(caught|Music)=0.05, P(lake|Music)=0.1, classify context {caught,lake} and normalize.</strong></p><div class=\"given\"><h4>Given</h4><p>Priors and likelihoods are provided directly; no smoothing or training-count estimation is requested.</p><h4>To find</h4><p>The winning sense and its posterior.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/8414ab183de734ec.svg\" alt=\"\\operatorname{score}(s)=P(s)P(\\text{caught}\\mid s)P(\\text{lake}\\mid s)\" style=\"width:38.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, because the two features are treated as conditionally independent.</p><div class=\"step\"><h4>Step 1. Fish multiplication</h4><p><span class=\"math-inline\"><img src=\"math/115f9e8e47cda84d.svg\" alt=\"0.6\\times0.5=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/99bd356c706eee9f.svg\" alt=\"0.3\\times0.4=0.12\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Music multiplication</h4><p><span class=\"math-inline\"><img src=\"math/b1d1c4fd715bfbf9.svg\" alt=\"0.4\\times0.05=0.02\" style=\"width:16.719ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/6ea85a9a0fdfcde1.svg\" alt=\"0.02\\times0.1=0.002\" style=\"width:17.851ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Total evidence</h4><p><span class=\"math-inline\"><img src=\"math/908f94107aa11373.svg\" alt=\"0.12+0.002=0.122\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><div class=\"math-display\"><img src=\"math/957c68e55d605895.svg\" alt=\"P(Fish\\mid C)=0.12/0.122\\approx0.983607\" style=\"width:36.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/d8a1b99447a84030.svg\" alt=\"P(Music\\mid C)=0.002/0.122\\approx0.016393.\" style=\"width:40.207ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Fish, with model posterior approximately 0.983607.</p></div><div class=\"example\"><p><strong>Question. Disambiguate bank from the repeated context tokens {loan, loan, river}. Priors are Finance=2/3 and River=1/3. Vocabulary V=4. Finance has N=8 total tokens, loan count 3 and river count 0; River has N=4, loan count 0 and river count 2. Apply add-one smoothing.</strong></p><div class=\"given\"><h4>Given</h4><p>Multinomial counts are supplied. The two appearances of loan must both contribute.</p><h4>To find</h4><p>Scores and normalized Finance posterior.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Finance denominator</h4><p><span class=\"math-inline\"><img src=\"math/4dcd6d36e73676fe.svg\" alt=\"8+4=12\" style=\"width:10.308ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/c83ba89d49bb7c55.svg\" alt=\"P(loan\\mid F)=(3+1)/12=1/3\" style=\"width:30.975ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ed4e2c4c1b9881ea.svg\" alt=\"P(river\\mid F)=(0+1)/12=1/12\" style=\"width:32.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. River denominator</h4><p><span class=\"math-inline\"><img src=\"math/34a0153bb137796a.svg\" alt=\"4+4=8\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/739f9e9752ebca3d.svg\" alt=\"P(loan\\mid R)=(0+1)/8=1/8\" style=\"width:29.867ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/cb1959ca98dd60bb.svg\" alt=\"P(river\\mid R)=(2+1)/8=3/8\" style=\"width:30.514ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Finance product</h4><div class=\"math-display\"><img src=\"math/94333571a54ef7df.svg\" alt=\"\\operatorname{score}(F)=\\frac23\\times\\frac13\\times\\frac13\\times\\frac1{12}=\\frac1{162}\\approx0.00617284.\" style=\"width:51.188ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. River product</h4><div class=\"math-display\"><img src=\"math/ffa63ee974248624.svg\" alt=\"\\operatorname{score}(R)=\\frac13\\times\\frac18\\times\\frac18\\times\\frac38=\\frac1{512}\\approx0.001953125.\" style=\"width:51.21ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Compare and normalize</h4><div class=\"math-display\"><img src=\"math/6e05aa52a40b6b55.svg\" alt=\"P(F\\mid C)=\\frac{1/162}{1/162+1/512}=\\frac{512}{674}=\\frac{256}{337}\\approx0.759644.\" style=\"width:53.856ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Finance wins. Repeated loan contributes a squared likelihood; do not reduce the query to a unique-word set.</p></div><h3>Answer-writing order in an exam</h3><p>Write the class priors, vocabulary size, class token totals, a likelihood table, both score products and the final class. Keep fractions until the comparison where possible. If the question only asks classification, normalization is optional; if it asks posterior probabilities, normalization is required.</p><p class=\"cue\">Repeated word aaye toh factor bhi repeat. Sirf word-set bana diya toh multinomial answer badal jayega.</p>"}],"scope":"Formulas explained through full worked examples"}],"papers":[{"id":"final-2025","title":"Solved final paper · December 2025","unit":"PYQ","scope":"M2-relevant questions from an actual TEE paper · original marks retained for longer practice","sections":[{"id":"final-2025-q1b","title":"Q1B · Chunking and chinking","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain the concepts of chunking and chinking in Natural Language Processing (NLP). Discuss how Part-of-Speech (POS) tagging supports these processes, and illustrate your explanation with a suitable example. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Chunking</strong> groups adjacent tagged words into shallow phrases, such as noun phrases, without building a complete sentence parse. <strong>Chinking</strong> removes a specified sequence of tags or words from a chunk, splitting a larger candidate chunk when required.</p><h3>POS tags provide the pattern</h3><p>A POS tag describes a grammatical category: DT = determiner, JJ = adjective, NN = singular noun, VBD = past-tense verb and IN = preposition. A noun-phrase rule can be written as <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;+}</code>: an optional determiner, zero or more adjectives, followed by one or more nouns.</p><h3>Worked example</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>The</th><th>small</th><th>cat</th><th>sat</th><th>on</th><th>the</th><th>mat</th></tr></thead><tbody><tr><td>Tag</td><td>DT</td><td>JJ</td><td>NN</td><td>VBD</td><td>IN</td><td>DT</td><td>NN</td></tr></tbody></table></div><p>Applying the NP rule gives <strong>[The small cat] sat on [the mat]</strong>. The first chunk contains DT–JJ–NN; the second contains DT–NN. “sat on” is not included because it does not match the noun-phrase rule.</p><p>For chinking, begin with one broad chunk: <strong>[The small cat sat on the mat]</strong>. Remove the VBD and IN sequence “sat on”, for example with <code>}&lt;VBD|IN&gt;+{</code>. The result is <strong>[The small cat] sat on [the mat]</strong>.</p><p>POS tagging therefore supplies grammatical labels; chunking uses labels to select phrases, while chinking uses labels to exclude unwanted material. Incorrect tags can lead to incorrect chunks.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Chunking = phrase ko jodo; chinking = beech ka unwanted part nikalo.</p>","m2":true,"units":"4","marks":5},{"id":"final-2025-q1c","title":"Q1C · Hyponymy, hypernymy and WSD","html":"<div class=\"question\" style=\"font-weight:700\">Question. Define hyponymy and hypernymy with suitable linguistic examples. How can hypernymy be applied in Word Sense Disambiguation (WSD) to resolve the correct meaning of polysemous words? Provide an example? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Hyponymy</strong> is the “is-a-kind-of” relation from a specific concept to a broader concept. <strong>Hypernymy</strong> is the inverse relation from the broader concept to the specific one. “Rose” is a hyponym of “flower”; “flower” is a hypernym of “rose”.</p><div class=\"flow\"><span class=\"flow-box\">rose / tulip</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">flower</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">plant</span></div><p>The arrow points towards a broader category. Hyponymy is not a part–whole relation: a wheel is part of a car, but it is not a kind of car.</p><h3>Using the hierarchy for WSD</h3><p>WSD selects the intended sense of a word from its context. Obtain candidate senses from a lexical resource such as WordNet, inspect their hypernym chains, and favour the chain most compatible with nearby words.</p><ol><li>Sentence: “The mouse clicked the icon.”</li><li>Candidate 1: mouse → rodent → mammal → animal. Candidate 2: mouse → pointing device → computer peripheral.</li><li>The context words “clicked” and “icon” belong to the computer-use domain. They support the device hierarchy, rather than the animal hierarchy.</li><li>Select the computer-pointing-device sense. In “The mouse ate cheese,” the animal hierarchy is more compatible.</li></ol><p>Hypernym evidence supplies semantic generalisation; it is a useful signal rather than a guarantee, because short or unusual contexts may still be ambiguous.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Hyponym specific hai; hypernym uska bada category hai.</p>","m2":true,"units":"5","marks":5},{"id":"final-2025-q2b","title":"Q2B · Laplace-smoothed bigram probability","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following training corpus:<br>1. artists paint murals in city<br>2. musicians play songs in city<br>3. painters paint murals on walls<br>4. signs are near city<br>Using a bigram language model with Laplace smoothing, evaluate the probability of the test sentence: “artists paint murals near city”. Assume the &lt;s&gt; and &lt;/s&gt; for each sentence. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><ul><li>artists paint murals in city</li><li>musicians play songs in city</li><li>painters paint murals on walls</li><li>signs are near city</li></ul><p>Test: artists paint murals near city. Add one start token &lt;s&gt; and one end token &lt;/s&gt; to every training and test sentence.</p><h3>To find</h3><p>The Laplace-smoothed bigram probability of the complete test sentence, including its end token.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0167293b8abe1cce.svg\" alt=\"P_{+1}(w_i\\mid w_{i-1})=\\frac{C(w_{i-1},w_i)+1}{C(w_{i-1})+V}\" style=\"width:33.254ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(previous,current) counts that adjacent pair in the training corpus. C(previous) counts its occurrences as a history. V is the vocabulary size. Add-one smoothing is necessary because an unseen pair must not force the whole sentence probability to zero.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/09cc94e28baa5a90.svg\" alt=\"P(w_1,\\ldots,w_n,\\langle/s\\rangle\\mid\\langle s\\rangle)=\\prod_{i=1}^{n+1}P(w_i\\mid w_{i-1})\" style=\"width:42.048ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Fix the token and vocabulary convention</h3><p>Lowercase words and remove the final punctuation. The supplied course key counts both boundary tokens in V. Following that convention: are, artists, city, in, murals, musicians, near, on, paint, painters, play, signs, songs, walls, &lt;s&gt;, &lt;/s&gt; gives <strong>V = 16</strong>. The start marker supplies history; it is not an extra probability factor before the first word.</p><h3>Step 2. List every required transition</h3><p>The complete test chain is &lt;s&gt; → artists → paint → murals → near → city → &lt;/s&gt;.</p><h3>Step 3. Count first, then add one</h3><div class=\"table-wrap\"><table><thead><tr><th>Required bigram</th><th>History count</th><th>Pair count</th><th>Smoothed probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → artists</td><td>4</td><td>1</td><td>(1+1)/(4+16) = 1/10</td></tr><tr><td>artists → paint</td><td>1</td><td>1</td><td>(1+1)/(1+16) = 2/17</td></tr><tr><td>paint → murals</td><td>2</td><td>2</td><td>(2+1)/(2+16) = 1/6</td></tr><tr><td>murals → near</td><td>2</td><td>0</td><td>(0+1)/(2+16) = 1/18</td></tr><tr><td>near → city</td><td>1</td><td>1</td><td>(1+1)/(1+16) = 2/17</td></tr><tr><td>city → &lt;/s&gt;</td><td>3</td><td>3</td><td>(3+1)/(3+16) = 4/19</td></tr></tbody></table></div><p>Count only adjacent words, never words that merely appear in the same sentence. The unseen pairs have count zero, so their numerator becomes one.</p><h3>Step 4. Multiply all six probabilities</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/62ad7b9fcca8c7b7.svg\" alt=\"P=\\frac{2}{20}\\times\\frac{2}{17}\\times\\frac{3}{18}\\times\\frac{1}{18}\\times\\frac{2}{17}\\times\\frac{4}{19}\" style=\"width:38.092ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. &lt;s&gt; → artists</td><td><span class=\"math-inline\"><img src=\"math/8fc51cfa0d4d18ef.svg\" alt=\"1\\times\\frac{1}{10}=\\frac{1}{10}\" style=\"width:12.105ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. artists → paint</td><td><span class=\"math-inline\"><img src=\"math/11b6a388c4744fa9.svg\" alt=\"\\frac{1}{10}\\times\\frac{2}{17}=\\frac{1}{85}\" style=\"width:13.569ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. paint → murals</td><td><span class=\"math-inline\"><img src=\"math/3123e759352a19f6.svg\" alt=\"\\frac{1}{85}\\times\\frac{1}{6}=\\frac{1}{510}\" style=\"width:13.569ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. murals → near</td><td><span class=\"math-inline\"><img src=\"math/8396eb2fae42ff25.svg\" alt=\"\\frac{1}{510}\\times\\frac{1}{18}=\\frac{1}{9180}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. near → city</td><td><span class=\"math-inline\"><img src=\"math/6b756a42abed1715.svg\" alt=\"\\frac{1}{9180}\\times\\frac{2}{17}=\\frac{1}{78030}\" style=\"width:17.568ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. city → &lt;/s&gt;</td><td><span class=\"math-inline\"><img src=\"math/c4371974205f854f.svg\" alt=\"\\frac{1}{78030}\\times\\frac{4}{19}=\\frac{2}{741285}\" style=\"width:19.168ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8bf61abdfc6b7956.svg\" alt=\"P=\\frac{2}{741285}\\approx 2.69801763\\times10^{-6}\" style=\"width:33.587ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Interpret the result</h3><p>This is a joint sentence probability, so a small value is normal. Do not add transition probabilities; each word must occur in sequence, so the chain multiplies them.</p><h3>Final answer</h3><p><strong>P ≈ 2.69801763 × 10<sup>-6</sup></strong> with the stated course vocabulary convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pair count mein 1 jodo, previous-word count mein V; phir saare fractions multiply karo.</p><p><strong>Convention note:</strong> Some implementations exclude &lt;s&gt; from the predicted vocabulary. Their V is one smaller and their numerical probability differs. In an exam, state V explicitly and follow the convention specified in the question or class solution.</p>","m2":true,"units":"3","marks":10},{"id":"final-2025-q4b","title":"Q4B · HMM emission, transition and sequence","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following POS tagged corpus. Apply Hidden Markov Model (HMM) approach to:<br>1. Cat/Noun chase/Verb mice/Noun<br>2. The/Det dog/Noun runs/Verb<br>3. A/Det cat/Noun eats/Verb cheese/Noun<br>i. Construct the emission probability matrix.<br>ii. Construct the transmission probability matrix.<br>iii. Calculate the probability of sequence of events: The/Det cat/Noun eats/Verb mice/Noun.<br>Note: Include start and end characters for all the sentences. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged sequence</th></tr></thead><tbody><tr><td>1</td><td>cat/Noun chase/Verb mice/Noun</td></tr><tr><td>2</td><td>the/Det dog/Noun runs/Verb</td></tr><tr><td>3</td><td>a/Det cat/Noun eats/Verb cheese/Noun</td></tr></tbody></table></div><p>Test words: the cat eats mice. Given tag sequence: Det → Noun → Verb → Noun. Include Start and End for all sentences. Lowercase the corpus so sentence-initial Cat and cat are one word.</p><h3>To find</h3><p>Emission probabilities, transition probabilities and the joint probability of the specified tag-and-word sequence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a732ea965eb9fa65.svg\" alt=\"P(w\\mid t)=\\frac{C(t,w)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>An emission probability asks: among tokens carrying this tag t, what fraction are the word w?</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/791852c27a57a918.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i,t_j)}{\\sum_k C(t_i,t_k)}\" style=\"width:24.245ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A transition probability asks: among transitions leaving tag tᵢ, what fraction go to tⱼ? Include End in the outgoing counts. The paper says “transmission”; the standard HMM term is transition.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c8c4a0c66e131a8f.svg\" alt=\"P(\\mathbf w,\\mathbf t)=P(t_1\\mid\\mathrm{Start})\\prod_{i=1}^{n}P(w_i\\mid t_i)\\prod_{i=2}^{n}P(t_i\\mid t_{i-1})P(\\mathrm{End}\\mid t_n)\" style=\"width:60.981ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Count tokens for each tag</h3><p>Det has 2 tokens; Noun has 5 tokens; Verb has 3 tokens. The repeated noun cat occurs twice with Noun; every other displayed noun occurs once. The three verb types each occur once.</p><h3>Step 2. Build the emission matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag / word</th><th>a</th><th>cat</th><th>chase</th><th>cheese</th><th>dog</th><th>eats</th><th>mice</th><th>runs</th><th>the</th></tr></thead><tbody><tr><td>Det</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1/2</td></tr><tr><td>Noun</td><td>0</td><td>2/5</td><td>0</td><td>1/5</td><td>1/5</td><td>0</td><td>1/5</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>1/3</td><td>0</td></tr></tbody></table></div><p>Each row sums to one. A zero means no occurrence under that tag in this unsmoothed training corpus; no add-one smoothing was requested.</p><h3>Step 3. Write the three tag chains</h3><p>Start → Noun → Verb → Noun → End<br>Start → Det → Noun → Verb → End<br>Start → Det → Noun → Verb → Noun → End</p><h3>Step 4. Count outgoing transitions</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>To Det</th><th>To Noun</th><th>To Verb</th><th>To End</th><th>Outgoing total</th></tr></thead><tbody><tr><td>Start</td><td>2</td><td>1</td><td>0</td><td>0</td><td>3</td></tr><tr><td>Det</td><td>0</td><td>2</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3</td><td>2</td><td>5</td></tr><tr><td>Verb</td><td>0</td><td>2</td><td>0</td><td>1</td><td>3</td></tr></tbody></table></div><h3>Step 5. Divide each row by its outgoing total</h3><div class=\"table-wrap\"><table><thead><tr><th>From / To</th><th>Det</th><th>Noun</th><th>Verb</th><th>End</th></tr></thead><tbody><tr><td>Start</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3/5</td><td>2/5</td></tr><tr><td>Verb</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td></tr></tbody></table></div><p>End is terminal, so it has no estimated outgoing row. The four nonterminal rows each sum to one.</p><h3>Step 6. Choose the factors for the given sequence</h3><div class=\"table-wrap\"><table><thead><tr><th>Event in order</th><th>Probability</th></tr></thead><tbody><tr><td>Start → Det</td><td>2/3</td></tr><tr><td>Det emits the</td><td>1/2</td></tr><tr><td>Det → Noun</td><td>1</td></tr><tr><td>Noun emits cat</td><td>2/5</td></tr><tr><td>Noun → Verb</td><td>3/5</td></tr><tr><td>Verb emits eats</td><td>1/3</td></tr><tr><td>Verb → Noun</td><td>2/3</td></tr><tr><td>Noun emits mice</td><td>1/5</td></tr><tr><td>Noun → End</td><td>2/5</td></tr></tbody></table></div><h3>Step 7. Multiply, including the end transition</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7b611360d98ac780.svg\" alt=\"P=\\frac23\\times\\frac12\\times1\\times\\frac25\\times\\frac35\\times\\frac13\\times\\frac23\\times\\frac15\\times\\frac25\" style=\"width:44.987ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. Start → Det</td><td><span class=\"math-inline\"><img src=\"math/b32eeb64b6ce8d87.svg\" alt=\"1\\times\\frac{2}{3}=\\frac{2}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. Det emits the</td><td><span class=\"math-inline\"><img src=\"math/0e0cb943fc030998.svg\" alt=\"\\frac{2}{3}\\times\\frac{1}{2}=\\frac{1}{3}\" style=\"width:11.169ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. Det → Noun</td><td><span class=\"math-inline\"><img src=\"math/3b61cadbe8860930.svg\" alt=\"\\frac{1}{3}\\times1=\\frac{1}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. Noun emits cat</td><td><span class=\"math-inline\"><img src=\"math/8e3868104c41a9da.svg\" alt=\"\\frac{1}{3}\\times\\frac{2}{5}=\\frac{2}{15}\" style=\"width:11.969ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. Noun → Verb</td><td><span class=\"math-inline\"><img src=\"math/69517c6e474a3048.svg\" alt=\"\\frac{2}{15}\\times\\frac{3}{5}=\\frac{2}{25}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. Verb emits eats</td><td><span class=\"math-inline\"><img src=\"math/3bb8a5077b206779.svg\" alt=\"\\frac{2}{25}\\times\\frac{1}{3}=\\frac{2}{75}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>7. Verb → Noun</td><td><span class=\"math-inline\"><img src=\"math/1a1bff7a79a3effd.svg\" alt=\"\\frac{2}{75}\\times\\frac{2}{3}=\\frac{4}{225}\" style=\"width:13.569ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>8. Noun emits mice</td><td><span class=\"math-inline\"><img src=\"math/55f13fa2c61c6016.svg\" alt=\"\\frac{4}{225}\\times\\frac{1}{5}=\\frac{4}{1125}\" style=\"width:15.168ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>9. Noun → End</td><td><span class=\"math-inline\"><img src=\"math/391357e72bb5bd3d.svg\" alt=\"\\frac{4}{1125}\\times\\frac{2}{5}=\\frac{8}{5625}\" style=\"width:15.968ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/236caebf4a4b2830.svg\" alt=\"P=\\frac8{5625}\\approx0.0014222222\" style=\"width:26.326ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>Joint sequence probability = 8/5625 ≈ 0.0014222222.</strong> This is the probability of the specified words and tags together. It is not the probability of the word sequence summed over every possible tag path.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Tag se tag = transition; tag se word = emission. Dono alternate multiply, end ko mat bhoolo.</p><p><strong>Boundary reminder:</strong> The initial factor is P(Det | Start) = 2/3, based on three sentence starts, and the final factor is P(End | Noun) = 2/5. The overall fraction of Det tokens, 2/10, is not the start probability. Using it and omitting End, as in the handwritten key’s last line, computes a different quantity.</p>","m2":true,"units":"4","marks":10},{"id":"final-2025-q5b","title":"Q5B · Naïve Bayes word-sense classification","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the sentence: “The bat hit the ball hard on the cricket field.” Two possible senses of “bat”: Sense 1: Bat (Sports equipment – cricket/baseball); Sense 2: Bat (Nocturnal flying mammal).<br><div class=\"table-wrap\"><table><thead><tr><th>Sentence ID</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>ball, cricket, score, stadium</td><td>Sports</td></tr><tr><td>2</td><td>night, cave, wings, fly</td><td>Animal</td></tr><tr><td>3</td><td>player, run, match, bat</td><td>Sports</td></tr><tr><td>4</td><td>nocturnal, vampire, insect</td><td>Animal</td></tr><tr><td>5</td><td>team, field, bowl, bat</td><td>Sports</td></tr><tr><td>6</td><td>dark, flying, cave, night</td><td>Animal</td></tr></tbody></table></div>a) Using the Naïve Bayes algorithm, classify the sense of “bat” in the given sentence. Apply Laplace Smoothing wherever applicable.<br>b) Discuss the significance of Laplace Smoothing in Naïve Bayes Classification. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>There are three Sports examples and three Animal examples. Treat training context lists as bag-of-words token counts. Exclude the ambiguous target “bat” from the test context. Use the fixed training vocabulary; ignore out-of-vocabulary test words hit and hard. The usable test features are ball, cricket and field.</p><h3>To find</h3><p>The posterior-score comparison for Sports and Animal, and the role of smoothing.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab6d19b2902f96bb.svg\" alt=\"\\mathrm{score}(s)=P(s)\\prod_{w\\in\\mathrm{context}}P(w\\mid s)\" style=\"width:31.469ex;height:4.819ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/df7198279b2281ba.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}\" style=\"width:23.102ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>P(s) is the class prior, C(w,s) counts occurrences of context word w in class s, Nₛ is the total number of context tokens in that class and V is the shared vocabulary size. Conditional independence lets us multiply word probabilities. The common denominator P(context) is unnecessary when only comparing classes.</p><h3>Solution</h3><h3>Step 1. Calculate the priors</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/979bfbb6524dbd77.svg\" alt=\"P(S)=\\frac36=0.5,\\qquad P(A)=\\frac36=0.5\" style=\"width:37.71ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 2. Count class tokens and vocabulary</h3><p>Sports has 4 + 4 + 4 = 12 tokens. Animal has 4 + 3 + 4 = 11 tokens. The shared training vocabulary has 20 distinct words: ball, cricket, score, stadium, player, run, match, bat, team, field, bowl, night, cave, wings, fly, nocturnal, vampire, insect, dark, flying. “bat”, “night” and “cave” repeat but count only once each towards V.</p><h3>Step 3. Look up each usable context word</h3><div class=\"table-wrap\"><table><thead><tr><th>Feature</th><th>Sports count</th><th>Animal count</th><th>P(word | Sports)</th><th>P(word | Animal)</th></tr></thead><tbody><tr><td>ball</td><td>1</td><td>0</td><td>(1+1)/(12+20) = 2/32</td><td>(0+1)/(11+20) = 1/31</td></tr><tr><td>cricket</td><td>1</td><td>0</td><td>2/32</td><td>1/31</td></tr><tr><td>field</td><td>1</td><td>0</td><td>2/32</td><td>1/31</td></tr></tbody></table></div><h3>Step 4. Multiply the Sports score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a90c8cf82da50b4f.svg\" alt=\"\\mathrm{score}(S)=0.5\\times\\frac2{32}\\times\\frac2{32}\\times\\frac2{32}=0.0001220703125\" style=\"width:51.601ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Multiply the Animal score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/118f04dc70642898.svg\" alt=\"\\mathrm{score}(A)=0.5\\times\\frac1{31}\\times\\frac1{31}\\times\\frac1{31}\\approx0.00001678359236\" style=\"width:52.969ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Compare the scores</h3><p>0.0001220703125 is greater than 0.00001678359236. Therefore select Sports. Optional normalization gives P(Sports | retained features) ≈ 0.87913; normalization is not needed for the decision.</p><h3>Final answer</h3><p>The intended sense is <strong>bat as sports equipment</strong>. Ball, cricket and field favour that sense.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pehle class prior, phir har context-word likelihood multiply; bigger score wali sense choose karo.</p><h3>Why Laplace smoothing matters</h3><p>Without smoothing, all three test features have zero count in Animal. One zero factor makes the entire class score zero, even if other evidence could support that class. Add-one smoothing assigns nonzero probability to every word in the defined vocabulary and redistributes probability mass. It does not mean every unseen word outside the vocabulary can be inserted without changing the vocabulary model.</p><h3>If following the supplied paper key exactly</h3><p>The key also multiplies probabilities for hit and hard using the same denominators 32 and 31. That convention produces Sports = 1.19209290 × 10⁻⁷ and Animal ≈ 1.74647163 × 10⁻⁸, again selecting Sports. Its treatment of out-of-vocabulary words is not a normalized fixed-vocabulary model. State your feature convention clearly; the complete calculation above uses a consistent fixed training vocabulary.</p>","m2":true,"units":"5","marks":10}]},{"id":"reexam-2026","title":"Solved re-exam · February 2026","unit":"PYQ","scope":"M2-relevant questions from an actual TEE paper · original marks retained for longer practice","sections":[{"id":"reexam-2026-q1b","title":"Q1B · Content and function words","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Define function words and content words.<br>ii. Which category (function words and content words) belong to open class and closed class? Justify your answer.<br>iii. For the sentence “The small cat is sleeping under the tree”, identify the function words and content words. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Content words</strong> carry much of a sentence’s lexical meaning, usually including nouns, main verbs, adjectives and many adverbs. <strong>Function words</strong> primarily express grammatical relationships, including determiners, prepositions, conjunctions, pronouns and auxiliary verbs.</p><div class=\"table-wrap\"><table><thead><tr><th>Category</th><th>Typical class</th><th>Reason</th></tr></thead><tbody><tr><td>Content words</td><td>Open class</td><td>New nouns, verbs and adjectives enter the language readily, such as new technology names</td></tr><tr><td>Function words</td><td>Closed class</td><td>The grammatical inventory is relatively stable; new determiners or pronouns are much less frequently added</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Role in this sentence</th><th>Category</th></tr></thead><tbody><tr><td>The</td><td>Determiner</td><td>Function</td></tr><tr><td>small</td><td>Adjective</td><td>Content</td></tr><tr><td>cat</td><td>Noun</td><td>Content</td></tr><tr><td>is</td><td>Auxiliary supporting progressive tense</td><td>Function</td></tr><tr><td>sleeping</td><td>Main verb</td><td>Content</td></tr><tr><td>under</td><td>Preposition</td><td>Function</td></tr><tr><td>the</td><td>Determiner</td><td>Function</td></tr><tr><td>tree</td><td>Noun</td><td>Content</td></tr></tbody></table></div><p><strong>Final answer:</strong> content words = small, cat, sleeping, tree; function words = The, is, under, the. “is” is auxiliary here; a word’s role must be judged in context. “Closed” means relatively resistant to new members, not that change is logically impossible.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Content words scene batate hain; function words grammar ka connection banate hain.</p>","m2":true,"units":"4","marks":5},{"id":"reexam-2026-q2b","title":"Q2B · Laplace smoothing on a second corpus","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following training corpus:<br>1. cats chase mice in the garden<br>2. dogs bark loudly at night<br>3. birds sing in the morning<br>4. children play games in the park<br>Using a bigram language model with Laplace smoothing, evaluate the probability of the test sentence: “cats bark in the park.” Assume &lt;s&gt; and &lt;/s&gt; as start and end of the sentence. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><ul><li>cats chase mice in the garden</li><li>dogs bark loudly at night</li><li>birds sing in the morning</li><li>children play games in the park</li></ul><p>Test: cats bark in the park. Add one start token &lt;s&gt; and one end token &lt;/s&gt; to every training and test sentence.</p><h3>To find</h3><p>The Laplace-smoothed bigram probability of the complete test sentence, including its end token.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0167293b8abe1cce.svg\" alt=\"P_{+1}(w_i\\mid w_{i-1})=\\frac{C(w_{i-1},w_i)+1}{C(w_{i-1})+V}\" style=\"width:33.254ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(previous,current) counts that adjacent pair in the training corpus. C(previous) counts its occurrences as a history. V is the vocabulary size. Add-one smoothing is necessary because an unseen pair must not force the whole sentence probability to zero.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/09cc94e28baa5a90.svg\" alt=\"P(w_1,\\ldots,w_n,\\langle/s\\rangle\\mid\\langle s\\rangle)=\\prod_{i=1}^{n+1}P(w_i\\mid w_{i-1})\" style=\"width:42.048ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Fix the token and vocabulary convention</h3><p>Lowercase words and remove the final punctuation. The supplied course key counts both boundary tokens in V. Following that convention: at, bark, birds, cats, chase, children, dogs, games, garden, in, loudly, mice, morning, night, park, play, sing, the, &lt;s&gt;, &lt;/s&gt; gives <strong>V = 20</strong>. The start marker supplies history; it is not an extra probability factor before the first word.</p><h3>Step 2. List every required transition</h3><p>The complete test chain is &lt;s&gt; → cats → bark → in → the → park → &lt;/s&gt;.</p><h3>Step 3. Count first, then add one</h3><div class=\"table-wrap\"><table><thead><tr><th>Required bigram</th><th>History count</th><th>Pair count</th><th>Smoothed probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → cats</td><td>4</td><td>1</td><td>(1+1)/(4+20) = 1/12</td></tr><tr><td>cats → bark</td><td>1</td><td>0</td><td>(0+1)/(1+20) = 1/21</td></tr><tr><td>bark → in</td><td>1</td><td>0</td><td>(0+1)/(1+20) = 1/21</td></tr><tr><td>in → the</td><td>3</td><td>3</td><td>(3+1)/(3+20) = 4/23</td></tr><tr><td>the → park</td><td>3</td><td>1</td><td>(1+1)/(3+20) = 2/23</td></tr><tr><td>park → &lt;/s&gt;</td><td>1</td><td>1</td><td>(1+1)/(1+20) = 2/21</td></tr></tbody></table></div><p>Count only adjacent words, never words that merely appear in the same sentence. The unseen pairs have count zero, so their numerator becomes one.</p><h3>Step 4. Multiply all six probabilities</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/661dddaa8d668f4e.svg\" alt=\"P=\\frac{2}{24}\\times\\frac{1}{21}\\times\\frac{1}{21}\\times\\frac{4}{23}\\times\\frac{2}{23}\\times\\frac{2}{21}\" style=\"width:38.092ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. &lt;s&gt; → cats</td><td><span class=\"math-inline\"><img src=\"math/9cf9ede86d758f1a.svg\" alt=\"1\\times\\frac{1}{12}=\\frac{1}{12}\" style=\"width:12.105ex;height:2.737ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. cats → bark</td><td><span class=\"math-inline\"><img src=\"math/15653088bc649e84.svg\" alt=\"\\frac{1}{12}\\times\\frac{1}{21}=\\frac{1}{252}\" style=\"width:14.368ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. bark → in</td><td><span class=\"math-inline\"><img src=\"math/bc2636bde4d927d0.svg\" alt=\"\\frac{1}{252}\\times\\frac{1}{21}=\\frac{1}{5292}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. in → the</td><td><span class=\"math-inline\"><img src=\"math/5be8f2428aa87996.svg\" alt=\"\\frac{1}{5292}\\times\\frac{4}{23}=\\frac{1}{30429}\" style=\"width:17.568ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. the → park</td><td><span class=\"math-inline\"><img src=\"math/5c01b946da36062b.svg\" alt=\"\\frac{1}{30429}\\times\\frac{2}{23}=\\frac{2}{699867}\" style=\"width:19.168ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. park → &lt;/s&gt;</td><td><span class=\"math-inline\"><img src=\"math/aa10a9e9b5ec1f5a.svg\" alt=\"\\frac{2}{699867}\\times\\frac{2}{21}=\\frac{4}{14697207}\" style=\"width:21.568ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/84afc176da8ea9ec.svg\" alt=\"P=\\frac{4}{14697207}\\approx 2.72160554\\times10^{-7}\" style=\"width:35.849ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Interpret the result</h3><p>This is a joint sentence probability, so a small value is normal. Do not add transition probabilities; each word must occur in sequence, so the chain multiplies them.</p><h3>Final answer</h3><p><strong>P ≈ 2.72160554 × 10<sup>-7</sup></strong> with the stated course vocabulary convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pair count mein 1 jodo, previous-word count mein V; phir saare fractions multiply karo.</p><p><strong>Convention note:</strong> Some implementations exclude &lt;s&gt; from the predicted vocabulary. Their V is one smaller and their numerical probability differs. In an exam, state V explicitly and follow the convention specified in the question or class solution.</p>","m2":true,"units":"3","marks":10},{"id":"reexam-2026-q3a","title":"Q3A · Top-down parsing","html":"<div class=\"question\" style=\"font-weight:700\">Question. In the context of natural language processing, explain the concept of top-down and bottom-up parsing approaches. Apply top-down syntax parsing approach to the sentence “The tall boy saw a girl in the park.” and draw a parse tree using the CFG grammar rules:<br>S → NP VP; NP → Det Adj N | Det N; VP → V NP | VP PP; PP → P NP.<br>Lexicon: Det → {the | a}; Adj → {tall}; N → {boy | girl | park}; V → {saw}; P → {in}. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Top-down</th><th>Bottom-up</th></tr></thead><tbody><tr><td>Start</td><td>The start symbol S</td><td>The input words</td></tr><tr><td>Operation</td><td>Expand a nonterminal using grammar productions</td><td>Combine words and constituents using productions in reverse</td></tr><tr><td>Success</td><td>Leaves match the complete input</td><td>All input is reduced to S</td></tr><tr><td>Possible difficulty</td><td>Naive recursive descent can loop on left recursion or need backtracking</td><td>A naive shift-reduce parser may face shift/reduce conflicts</td></tr></tbody></table></div><h3>Given</h3><p>The sentence contains the tokens the / tall / boy / saw / a / girl / in / the / park. Lowercase the initial “The” to match the lexicon. The full stop is punctuation outside the listed grammar.</p><h3>To find</h3><p>A derivation beginning at S and a parse tree matching the whole sentence.</p><h3>Rule: which one and why</h3><p>A context-free production replaces one nonterminal with its right-hand sequence. A top-down derivation begins at S and expands the desired structure. The supplied grammar attaches the PP through VP → VP PP; it does not provide NP → NP PP.</p><h3>Step 1. Expand the sentence</h3><p>S ⇒ NP VP. Choose NP → Det Adj N for “the tall boy”.</p><h3>Step 2. Match the subject words</h3><p>Det ⇒ the, Adj ⇒ tall, N ⇒ boy. The remaining material must be generated by VP.</p><h3>Step 3. Allow a verb phrase followed by a PP</h3><p>Expand the outer VP using VP → VP PP. Then expand the inner VP using VP → V NP. This finite derivation selects the recursive rule once.</p><h3>Step 4. Match the verb and object</h3><p>V ⇒ saw. Choose NP → Det N, then Det ⇒ a and N ⇒ girl.</p><h3>Step 5. Expand the prepositional phrase</h3><p>PP ⇒ P NP. P ⇒ in. NP ⇒ Det N, with Det ⇒ the and N ⇒ park.</p><h3>Step 6. Check the complete leaf order</h3><p>The leaves read “the tall boy saw a girl in the park”, exactly the normalized input. The PP “in the park” attaches to the VP under this supplied grammar.</p><figure><svg viewBox=\"0 0 820 350\" role=\"img\" aria-label=\"Top-down parse tree showing the PP attached to VP\" style=\"width:100%;max-width:820px;background:#f4f8f7\"><line x1=\"370\" y1=\"38\" x2=\"150\" y2=\"60\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"370\" y1=\"38\" x2=\"560\" y2=\"60\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"55\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"135\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"215\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"560\" y1=\"88\" x2=\"420\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"560\" y1=\"88\" x2=\"650\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"420\" y1=\"143\" x2=\"350\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"420\" y1=\"143\" x2=\"470\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"650\" y1=\"143\" x2=\"575\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"650\" y1=\"143\" x2=\"705\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"470\" y1=\"198\" x2=\"440\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"470\" y1=\"198\" x2=\"500\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"705\" y1=\"198\" x2=\"660\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"705\" y1=\"198\" x2=\"750\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"55\" y1=\"143\" x2=\"55\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"135\" y1=\"143\" x2=\"135\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"215\" y1=\"143\" x2=\"215\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"350\" y1=\"198\" x2=\"350\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"440\" y1=\"248\" x2=\"440\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"500\" y1=\"248\" x2=\"500\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"575\" y1=\"198\" x2=\"575\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"660\" y1=\"248\" x2=\"660\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"750\" y1=\"248\" x2=\"750\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><text x=\"370\" y=\"30\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">S</text><text x=\"150\" y=\"80\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"560\" y=\"80\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"55\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"135\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Adj</text><text x=\"215\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"420\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"650\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">PP</text><text x=\"350\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">V</text><text x=\"470\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"575\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">P</text><text x=\"705\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"440\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"500\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"660\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"750\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"55\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">The</text><text x=\"135\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">tall</text><text x=\"215\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">boy</text><text x=\"350\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">saw</text><text x=\"440\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">a</text><text x=\"500\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">girl</text><text x=\"575\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">in</text><text x=\"660\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">the</text><text x=\"750\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">park</text></svg><figcaption>Top-down parse tree showing the PP attached to VP.</figcaption></figure><h3>Complete derivation</h3><p>S ⇒ NP VP ⇒ Det Adj N VP ⇒ the tall boy VP ⇒ the tall boy VP PP ⇒ the tall boy V NP PP ⇒ the tall boy saw Det N PP ⇒ the tall boy saw a girl P NP ⇒ the tall boy saw a girl in Det N ⇒ the tall boy saw a girl in the park.</p><p><strong>Implementation caution:</strong> VP → VP PP is left-recursive. A naive recursive-descent implementation may loop; it must transform or otherwise handle the grammar. A valid finite top-down derivation, as shown above, still exists.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Rule jo diya hai wahi use karo: yahan “in the park” VP ka part hai.</p>","m2":true,"units":"4","marks":10},{"id":"reexam-2026-q3b","title":"Q3B · Lesk word-sense disambiguation","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the sentence: “The bank can ensure your deposits are safe.” The word “bank” has the following two possible senses (WordNet-style glosses):<br>Bank₁: Sloping land especially beside a body of water.<br>Bank₂: A financial institution that accepts deposits and channels the money into lending activities.<br>i. Apply the LESK algorithm to determine the correct sense of the word “bank” in the given sentence. Show the steps clearly.<br>ii. Briefly discuss limitations of the LESK algorithm in handling ambiguous words in real-world contexts. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Context sentence and the two supplied dictionary glosses. Use a simplified Lesk method: lowercase, remove function words, exclude the target bank and compare distinct content-word overlap. Do not add synonyms that the question does not supply.</p><h3>To find</h3><p>Which candidate gloss has the greatest overlap with the local context.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6ad61c84bee7b920.svg\" alt=\"\\mathrm{score}(s)=|C\\cap G_s|,\\qquad \\hat s=\\arg\\max_s\\mathrm{score}(s)\" style=\"width:44.428ex;height:3.457ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C is the set of context content words. Gₛ is the content-word set of the gloss for sense s. The intersection contains words appearing in both; its size is the score. This is an overlap count, not a probability.</p><h3>Solution</h3><h3>Step 1. Prepare the context</h3><p>Remove The, can, your, are and the target bank. A reasonable content set is C = {ensure, deposits, safe}. If “can” is retained under another fixed stop-list it matches neither gloss and does not change the result.</p><h3>Step 2. Prepare Bank₁’s gloss</h3><p>G₁ = {sloping, land, especially, beside, body, water}. There is no shared word with {ensure, deposits, safe}.</p><h3>Step 3. Calculate Bank₁’s score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bdca68bf983394ca.svg\" alt=\"C\\cap G_1=\\varnothing,\\qquad \\mathrm{score}(1)=0\" style=\"width:29.266ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Prepare Bank₂’s gloss and count overlap</h3><p>G₂ = {financial, institution, accepts, deposits, channels, money, lending, activities}. The shared word is deposits.</p><h3>Step 5. Calculate Bank₂’s score and select</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0107901b24c804b2.svg\" alt=\"C\\cap G_2=\\{\\mathrm{deposits}\\},\\qquad \\mathrm{score}(2)=1\" style=\"width:37.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>1 > 0, so choose the financial-institution sense.</p><h3>Final answer</h3><p><strong>Bank₂: financial institution.</strong> The explicit overlap “deposits” supports this choice.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Lesk: context aur har meaning ki definition mein common words count karo; highest overlap choose karo.</p><h3>ii. Limitations</h3><ul><li>Short contexts or short glosses may produce no overlaps or ties.</li><li>Exact word matching misses related words and synonyms, such as deposit versus savings, unless an extension is defined.</li><li>Irrelevant frequent words can create misleading overlaps if preprocessing is poor.</li><li>Dictionary glosses may omit a domain-specific sense or fail to express the context’s wording.</li><li>Simplified Lesk uses limited local information and may miss discourse or real-world knowledge.</li></ul><p>Lemmatization, richer glosses and semantic similarity can improve variants, but the exact variant and tie-breaking rule should be stated.</p>","m2":true,"units":"5","marks":10},{"id":"reexam-2026-q4b","title":"Q4B · A second HMM sequence","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following POS tagged corpus. Apply Hidden Markov Model (HMM) approach to:<br>1. Dog/Noun eats/Verb bread/Noun<br>2. The/Det cat/Noun sleeps/Verb<br>3. A/Det dog/Noun eats/Verb fish/Noun<br>i. Construct the emission probability matrix.<br>ii. Construct the transmission probability matrix.<br>iii. Calculate the probability of the given sequence of events: The/Det dog/Noun eats/Verb bread/Noun.<br>Note: Include start and end characters for all the sentences. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>The repeated verb eats has a different emission count from the final paper; recalculate it rather than copying the previous numerical result.</p><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged sequence</th></tr></thead><tbody><tr><td>1</td><td>dog/Noun eats/Verb bread/Noun</td></tr><tr><td>2</td><td>the/Det cat/Noun sleeps/Verb</td></tr><tr><td>3</td><td>a/Det dog/Noun eats/Verb fish/Noun</td></tr></tbody></table></div><p>Lowercase the corpus. Test sequence: the/Det dog/Noun eats/Verb bread/Noun. Add Start and End markers.</p><h3>To find</h3><p>Emission and transition matrices, then the probability of the supplied tagged sequence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a732ea965eb9fa65.svg\" alt=\"P(w\\mid t)=\\frac{C(t,w)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8da165d58e49419c.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i,t_j)}{\\sum_kC(t_i,t_k)}\" style=\"width:24.245ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Emission divides the word’s tag-specific count by the total tokens with that tag. Transition divides the tag-pair count by all transitions leaving the previous tag, including End.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/054557fae74f519d.svg\" alt=\"P(\\mathbf w,\\mathbf t)=P(t_1\\mid\\mathrm{Start})\\prod_iP(w_i\\mid t_i)\\prod_{i=2}^{n}P(t_i\\mid t_{i-1})P(\\mathrm{End}\\mid t_n)\" style=\"width:60.981ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Count tag totals and word frequencies</h3><p>Det: the=1, a=1, total2. Noun: dog=2, bread=1, cat=1, fish=1, total5. Verb: eats=2, sleeps=1, total3.</p><h3>Step 2. Construct emission matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag / word</th><th>a</th><th>bread</th><th>cat</th><th>dog</th><th>eats</th><th>fish</th><th>sleeps</th><th>the</th></tr></thead><tbody><tr><td>Det</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1/2</td></tr><tr><td>Noun</td><td>0</td><td>1/5</td><td>1/5</td><td>2/5</td><td>0</td><td>1/5</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>0</td><td>0</td><td>0</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td><td>0</td></tr></tbody></table></div><h3>Step 3. Count transitions from the three chains</h3><p>Start → Noun → Verb → Noun → End<br>Start → Det → Noun → Verb → End<br>Start → Det → Noun → Verb → Noun → End</p><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Det count</th><th>Noun count</th><th>Verb count</th><th>End count</th><th>Total</th></tr></thead><tbody><tr><td>Start</td><td>2</td><td>1</td><td>0</td><td>0</td><td>3</td></tr><tr><td>Det</td><td>0</td><td>2</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3</td><td>2</td><td>5</td></tr><tr><td>Verb</td><td>0</td><td>2</td><td>0</td><td>1</td><td>3</td></tr></tbody></table></div><h3>Step 4. Divide outgoing counts</h3><div class=\"table-wrap\"><table><thead><tr><th>From / to</th><th>Det</th><th>Noun</th><th>Verb</th><th>End</th></tr></thead><tbody><tr><td>Start</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3/5</td><td>2/5</td></tr><tr><td>Verb</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td></tr></tbody></table></div><p>All nonterminal rows sum to one. No smoothing is requested.</p><h3>Step 5. Write every sequence factor</h3><div class=\"table-wrap\"><table><thead><tr><th>Event</th><th>Probability</th></tr></thead><tbody><tr><td>Start → Det</td><td>2/3</td></tr><tr><td>Det emits the</td><td>1/2</td></tr><tr><td>Det → Noun</td><td>1</td></tr><tr><td>Noun emits dog</td><td>2/5</td></tr><tr><td>Noun → Verb</td><td>3/5</td></tr><tr><td>Verb emits eats</td><td>2/3</td></tr><tr><td>Verb → Noun</td><td>2/3</td></tr><tr><td>Noun emits bread</td><td>1/5</td></tr><tr><td>Noun → End</td><td>2/5</td></tr></tbody></table></div><h3>Step 6. Multiply all factors</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2931148a79074475.svg\" alt=\"P=\\frac23\\times\\frac12\\times1\\times\\frac25\\times\\frac35\\times\\frac23\\times\\frac23\\times\\frac15\\times\\frac25\" style=\"width:44.987ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. Start → Det</td><td><span class=\"math-inline\"><img src=\"math/b32eeb64b6ce8d87.svg\" alt=\"1\\times\\frac{2}{3}=\\frac{2}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. Det emits the</td><td><span class=\"math-inline\"><img src=\"math/0e0cb943fc030998.svg\" alt=\"\\frac{2}{3}\\times\\frac{1}{2}=\\frac{1}{3}\" style=\"width:11.169ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. Det → Noun</td><td><span class=\"math-inline\"><img src=\"math/3b61cadbe8860930.svg\" alt=\"\\frac{1}{3}\\times1=\\frac{1}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. Noun emits dog</td><td><span class=\"math-inline\"><img src=\"math/8e3868104c41a9da.svg\" alt=\"\\frac{1}{3}\\times\\frac{2}{5}=\\frac{2}{15}\" style=\"width:11.969ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. Noun → Verb</td><td><span class=\"math-inline\"><img src=\"math/69517c6e474a3048.svg\" alt=\"\\frac{2}{15}\\times\\frac{3}{5}=\\frac{2}{25}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. Verb emits eats</td><td><span class=\"math-inline\"><img src=\"math/e9a1944302b07ad1.svg\" alt=\"\\frac{2}{25}\\times\\frac{2}{3}=\\frac{4}{75}\" style=\"width:12.769ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>7. Verb → Noun</td><td><span class=\"math-inline\"><img src=\"math/a35b29cd9dbe9b05.svg\" alt=\"\\frac{4}{75}\\times\\frac{2}{3}=\\frac{8}{225}\" style=\"width:13.569ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>8. Noun emits bread</td><td><span class=\"math-inline\"><img src=\"math/3a78d82833b21a72.svg\" alt=\"\\frac{8}{225}\\times\\frac{1}{5}=\\frac{8}{1125}\" style=\"width:15.168ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>9. Noun → End</td><td><span class=\"math-inline\"><img src=\"math/2baf230e35df5c28.svg\" alt=\"\\frac{8}{1125}\\times\\frac{2}{5}=\\frac{16}{5625}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d4673af7839c15e4.svg\" alt=\"P=\\frac{16}{5625}\\approx0.0028444444\" style=\"width:26.326ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>P = 16/5625 ≈ 0.0028444444</strong> for these words and specified tags jointly. The two occurrences of eats give P(eats | Verb) = 2/3.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same tag structure ho sakta hai, lekin word emission counts dobara count karna.</p><p><strong>Boundary reminder:</strong> Include P(Det | Start) = 2/3 and P(End | Noun) = 2/5. The handwritten key’s final line instead inserts the overall Det fraction 2/10 and omits End; the complete boundary-aware probability requested here is 0.0028444444.</p>","m2":true,"units":"4","marks":10}]}],"mocks":[{"id":"mock-a","title":"M2 Mock A · core calculations","unit":"Practice","sections":[{"id":"instructions","title":"Paper instructions","html":"<p><strong>Practice paper · 10 marks · 60 minutes.</strong> Q1 and Q2 are compulsory (2 marks each). Attempt any two of Q3, Q4 and Q5 (3 marks each). All five solutions are included below their questions. These are newly authored practice questions, not predictions of the actual paper.</p><p>Use about 8 minutes each for Q1–Q2, 16 minutes each for the two chosen 3-mark questions, and the remaining 12 minutes to read, choose and check. Write the formula and substitutions even if a final calculation gets stuck.</p>"},{"id":"q1","title":"Q1 (2 marks)","html":"<section class=\"example\"><h3>Q1</h3><p class=\"question\">For “we study language models”, list the unigrams, bigrams and trigrams. Do not add boundary markers. <span class=\"marks\">(2 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Four tokens in the stated order.</p><strong>To find</strong><p>All contiguous n-grams for n=1,2,3.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/167913d5b2acc327.svg\" alt=\"\\#\\text{ n-grams}=T-n+1\" style=\"width:23.017ex;height:2.036ex\" loading=\"lazy\" decoding=\"async\"></div><p>T is the number of tokens. Slide a window of n consecutive tokens, one position at a time.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Unigrams, window size 1</h4><p>(we), (study), (language), (models); count=4.</p></div><div class=\"step\"><h4>Step 2. Bigrams, window size 2</h4><p>(we study), (study language), (language models); count=4−2+1=3.</p></div><div class=\"step\"><h4>Step 3. Trigrams, window size 3</h4><p>(we study language), (study language models); count=4−3+1=2.</p></div><div class=\"answer\">4 unigrams, 3 bigrams and 2 trigrams, listed above.</div></section>"},{"id":"q2","title":"Q2 (2 marks)","html":"<section class=\"example\"><h3>Q2</h3><p class=\"question\">A corpus has C(read)=10, C(read books)=6 and C(read papers)=4. Find both bigram conditional probabilities. <span class=\"marks\">(2 marks)</span></p><div class=\"given\"><strong>Given</strong><p>read has 10 continuation opportunities; 6 are books and 4 are papers.</p><strong>To find</strong><p>P(books | read) and P(papers | read).</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/1ce8860e624e2650.svg\" alt=\"P(w\\mid h)=\\frac{C(hw)}{C(h)}\" style=\"width:18.684ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>h is the preceding word. Divide each pair count by the count of its shared history.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Probability of books</h4><div class=\"math-display\"><img src=\"math/4f1e78e98a40bd62.svg\" alt=\"P(\\text{books}\\mid\\text{read})=\\frac6{10}=0.6\" style=\"width:27.416ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Probability of papers</h4><div class=\"math-display\"><img src=\"math/79d625a295e85470.svg\" alt=\"P(\\text{papers}\\mid\\text{read})=\\frac4{10}=0.4\" style=\"width:28.239ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Check the complete row</h4><div class=\"math-display\"><img src=\"math/ea2d73cc17f05950.svg\" alt=\"0.6+0.4=1\" style=\"width:12.697ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">P(books | read)=0.6 and P(papers | read)=0.4.</div></section>"},{"id":"q3","title":"Q3 (3 marks)","html":"<section class=\"example\"><h3>Q3</h3><p class=\"question\">Training corpus: “I like tea” and “I like coffee”. Lowercase all words and add &lt;s&gt; and &lt;/s&gt; to each sentence. Using add-one bigram smoothing and a vocabulary containing both boundary symbols, find P(“i like tea”). <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Padded corpus: &lt;s&gt; i like tea &lt;/s&gt;; &lt;s&gt; i like coffee &lt;/s&gt;. V={&lt;s&gt;, i, like, tea, coffee, &lt;/s&gt;}, |V|=6.</p><strong>To find</strong><p>Product of the four smoothed transition probabilities, including the end transition.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/749bec61cf2a8b8e.svg\" alt=\"P_{+1}(w\\mid h)=\\frac{C(hw)+1}{C(h)+|V|}\" style=\"width:24.813ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Every possible vocabulary continuation gets one pseudocount. Both boundaries are counted in V because the question explicitly requires the course convention.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Count histories and pairs</h4><table><thead><tr><th>Transition</th><th>Pair count</th><th>History count</th></tr></thead><tbody><tr><td>&lt;s&gt; → i</td><td>2</td><td>2</td></tr><tr><td>i → like</td><td>2</td><td>2</td></tr><tr><td>like → tea</td><td>1</td><td>2</td></tr><tr><td>tea → &lt;/s&gt;</td><td>1</td><td>1</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Compute first probability</h4><div class=\"math-display\"><img src=\"math/d9fa36d9af3de632.svg\" alt=\"P(i\\mid\\langle s\\rangle)=\\frac{2+1}{2+6}=\\frac38\" style=\"width:23.131ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute middle probabilities</h4><div class=\"math-display\"><img src=\"math/f7bf3c73f1ebb6dc.svg\" alt=\"P(\\text{like}\\mid i)=\\frac38\" style=\"width:14.726ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/96b2bf69d275056e.svg\" alt=\"P(\\text{tea}\\mid\\text{like})=\\frac{1+1}{2+6}=\\frac14\" style=\"width:26.003ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Compute end probability</h4><div class=\"math-display\"><img src=\"math/e8b1fabbba875fd8.svg\" alt=\"P(\\langle/ s\\rangle\\mid\\text{tea})=\\frac{1+1}{1+6}=\\frac27\" style=\"width:26.498ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Multiply</h4><div class=\"math-display\"><img src=\"math/395a3f897d526ccd.svg\" alt=\"P=\\frac38\\times\\frac38\\times\\frac14\\times\\frac27=\\frac9{896}\\approx0.010044643\" style=\"width:43.885ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Sentence probability = 9/896 ≈ 0.010044643.</div></section>"},{"id":"q4","title":"Q4 (3 marks)","html":"<section class=\"example\"><h3>Q4</h3><p class=\"question\">An HMM has P(N|start)=0.6, P(V|N)=0.5, P(end|V)=0.4, P(dogs|N)=0.5 and P(run|V)=0.8. Find the joint probability of words “dogs run” with tag path N,V, including the end transition. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>The five required transition/emission factors are supplied.</p><strong>To find</strong><p>P(dogs run, N V, end).</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/d74602d45a8f6006.svg\" alt=\"P(w,t)=P(t_1\\mid start)P(w_1\\mid t_1)P(t_2\\mid t_1)P(w_2\\mid t_2)P(end\\mid t_2)\" style=\"width:61.186ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Transitions move between tags. Emissions generate words from tags. Include both types of factor.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Place the factors along the path</h4><div class=\"flow\"><div class=\"node\">start → N: 0.6</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">emit dogs: 0.5</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">N → V: 0.5</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">emit run: 0.8</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">V → end: 0.4</div></div></div><div class=\"step\"><h4>Step 2. First word contribution</h4><div class=\"math-display\"><img src=\"math/93f751cb6f79ddc6.svg\" alt=\"0.6\\times0.5=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Enter V and emit run</h4><div class=\"math-display\"><img src=\"math/96f131bd67f1d124.svg\" alt=\"0.3\\times0.5=0.15\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0a217c93f9b6444f.svg\" alt=\"0.15\\times0.8=0.12\" style=\"width:16.719ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. End the sentence</h4><div class=\"math-display\"><img src=\"math/52a11bdd907960f4.svg\" alt=\"0.12\\times0.4=0.048\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Joint path-and-word probability = 0.048. This is not a normalised posterior over tag paths.</div></section>"},{"id":"q5","title":"Q5 (3 marks)","html":"<section class=\"example\"><h3>Q5</h3><p class=\"question\">For a two-sense Naive Bayes WSD model, P(F)=P(R)=0.5. After smoothing, P(loan|F)=0.4, P(money|F)=0.3, P(loan|R)=0.1 and P(money|R)=0.1. Classify “bank” using context {loan, money} and obtain the winning sense’s posterior. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>F=financial sense; R=river sense. Two exhaustive senses; conditional independence of the context words is assumed.</p><strong>To find</strong><p>Two scores, selected sense and normalised posterior.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/69a207d02fe88fc1.svg\" alt=\"s(c)=P(c)P(\\text{loan}\\mid c)P(\\text{money}\\mid c)\" style=\"width:34.529ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ff803a2123f521d.svg\" alt=\"P(c\\mid x)=\\frac{s(c)}{s(F)+s(R)}\" style=\"width:23.451ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply the prior by the two likelihoods, then normalise because a posterior is requested.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Financial score</h4><div class=\"math-display\"><img src=\"math/f3df697a20d8a380.svg\" alt=\"s(F)=0.5\\times0.4\\times0.3=0.06\" style=\"width:28.778ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. River score</h4><div class=\"math-display\"><img src=\"math/3b8218c2f9695700.svg\" alt=\"s(R)=0.5\\times0.1\\times0.1=0.005\" style=\"width:29.932ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Total evidence score</h4><div class=\"math-display\"><img src=\"math/1f46aceeecb6ce54.svg\" alt=\"0.06+0.005=0.065\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Normalise winner</h4><div class=\"math-display\"><img src=\"math/74cbf2f696cd1b4b.svg\" alt=\"P(F\\mid x)=\\frac{0.06}{0.065}=\\frac{12}{13}\\approx0.923077\" style=\"width:35.34ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Financial sense; posterior ≈0.923077.</div></section>"}],"scope":"M2 · confirmed 2 + 2 + any two of 3 + 3 + 3 · worked practice"},{"id":"mock-b","title":"M2 Mock B · unseen pairs & decoding","unit":"Practice","sections":[{"id":"instructions","title":"Paper instructions","html":"<p><strong>Practice paper · 10 marks · 60 minutes.</strong> Q1 and Q2 are compulsory (2 marks each). Attempt any two of Q3, Q4 and Q5 (3 marks each). All five solutions are included below their questions. These are newly authored practice questions, not predictions of the actual paper.</p><p>Use about 8 minutes each for Q1–Q2, 16 minutes each for the two chosen 3-mark questions, and the remaining 12 minutes to read, choose and check. Write the formula and substitutions even if a final calculation gets stuck.</p>"},{"id":"q1","title":"Q1 (2 marks)","html":"<section class=\"example\"><h3>Q1</h3><p class=\"question\">A language model gives a test sequence probability of 0.0016 across four predicted tokens. Calculate perplexity. <span class=\"marks\">(2 marks)</span></p><div class=\"given\"><strong>Given</strong><p>P=0.0016; N=4.</p><strong>To find</strong><p>PP.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/8263823864a08bf0.svg\" alt=\"PP=P^{-1/N}=\\left(\\frac1P\\right)^{1/N}\" style=\"width:24.943ex;height:6.01ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use the number of predicted events, not an unrelated training token count.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Reciprocal</h4><div class=\"math-display\"><img src=\"math/92106edf250f4af4.svg\" alt=\"\\frac1{0.0016}=625\" style=\"width:13.691ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Fourth root</h4><div class=\"math-display\"><img src=\"math/d84b412c777e5d8e.svg\" alt=\"PP=625^{1/4}=5\" style=\"width:16.545ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Perplexity=5.</div></section>"},{"id":"q2","title":"Q2 (2 marks)","html":"<section class=\"example\"><h3>Q2</h3><p class=\"question\">A first-order Markov model starts in state A with probability 0.7. P(B|A)=0.4 and P(A|B)=0.3. Compute the path probability A→B→A, with no end-state factor. <span class=\"marks\">(2 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Start A=0.7; A→B=0.4; B→A=0.3.</p><strong>To find</strong><p>Probability of this state path.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/5f8aae6191f91906.svg\" alt=\"P(A,B,A)=P(A)P(B\\mid A)P(A\\mid B)\" style=\"width:36.274ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>First-order dependence uses only the previous state for each transition.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. First transition contribution</h4><div class=\"math-display\"><img src=\"math/aaf2c572f2d6daa0.svg\" alt=\"0.7\\times0.4=0.28\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Second transition contribution</h4><div class=\"math-display\"><img src=\"math/fea2bef4fcebf46d.svg\" alt=\"0.28\\times0.3=0.084\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Path probability=0.084.</div></section>"},{"id":"q3","title":"Q3 (3 marks)","html":"<section class=\"example\"><h3>Q3</h3><p class=\"question\">For a fixed vocabulary of five possible continuations, C(very)=7 and C(very bright)=0. Calculate the unsmoothed and Laplace-smoothed probabilities of bright after very. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>History count=7; pair count=0; |V|=5.</p><strong>To find</strong><p>MLE and add-one probabilities.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/b6cda4dbf7b89bd7.svg\" alt=\"P_{MLE}(w\\mid h)=\\frac{C(hw)}{C(h)}\" style=\"width:22.618ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/749bec61cf2a8b8e.svg\" alt=\"P_{+1}(w\\mid h)=\\frac{C(hw)+1}{C(h)+|V|}\" style=\"width:24.813ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>MLE uses only observations. Laplace reserves probability for all known vocabulary outcomes, including unseen pairs.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Unsmoothed estimate</h4><div class=\"math-display\"><img src=\"math/af58dca7b04e5ea2.svg\" alt=\"P_{MLE}(\\text{bright}\\mid\\text{very})=\\frac07=0\" style=\"width:28.895ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Add one to the pair count</h4><div class=\"math-display\"><img src=\"math/dd66590db88ae5fa.svg\" alt=\"0+1=1\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Add vocabulary size to the history count</h4><div class=\"math-display\"><img src=\"math/519c72927bad6998.svg\" alt=\"7+5=12\" style=\"width:10.308ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Divide</h4><div class=\"math-display\"><img src=\"math/3b6878cf6c2ef959.svg\" alt=\"P_{+1}(\\text{bright}\\mid\\text{very})=\\frac1{12}\\approx0.083333\" style=\"width:35.494ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">MLE=0; Laplace=1/12≈0.083333. The zero count means unseen in this corpus, not impossible language.</div></section>"},{"id":"q4","title":"Q4 (3 marks)","html":"<section class=\"example\"><h3>Q4</h3><p class=\"question\">A two-state HMM has initial probabilities P(N)=0.6, P(V)=0.4. Transition rows (N→N,N→V)=(0.3,0.7) and (V→N,V→V)=(0.8,0.2). Emissions are P(fish|N)=0.5, P(fish|V)=0.4, P(swim|N)=0.1 and P(swim|V)=0.6. Find the best tag path for “fish swim”, without end transitions. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Two states N,V; all start, transition and relevant emission probabilities are supplied.</p><strong>To find</strong><p>Largest joint score and its tag sequence.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/9376db481e8e0e16.svg\" alt=\"\\delta_1(t)=P(t)P(w_1\\mid t)\" style=\"width:20.632ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/19da4a0018c4e11f.svg\" alt=\"\\delta_2(t)=P(w_2\\mid t)\\max_s[\\delta_1(s)P(t\\mid s)]\" style=\"width:34.238ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p>Viterbi keeps the best path ending at each tag and stores its predecessor. Enumerating four paths gives the same result for this tiny example.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise fish</h4><div class=\"math-display\"><img src=\"math/52ba9de4a33ff58d.svg\" alt=\"\\delta_1(N)=0.6\\times0.5=0.3\" style=\"width:23.236ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/3422eafaea5af482.svg\" alt=\"\\delta_1(V)=0.4\\times0.4=0.16\" style=\"width:24.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Score both paths ending in N</h4><div class=\"math-display\"><img src=\"math/31db017cf8adde14.svg\" alt=\"NN:0.3\\times0.3\\times0.1=0.009\" style=\"width:28.281ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/35f92b0ccc050c81.svg\" alt=\"VN:0.16\\times0.8\\times0.1=0.0128\" style=\"width:30.274ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div><p>Keep VN at N; predecessor V.</p></div><div class=\"step\"><h4>Step 3. Score both paths ending in V</h4><div class=\"math-display\"><img src=\"math/be98de9bc4ba04ab.svg\" alt=\"NV:0.3\\times0.7\\times0.6=0.126\" style=\"width:28.011ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4898969d0dee0618.svg\" alt=\"VV:0.16\\times0.2\\times0.6=0.0192\" style=\"width:30.005ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div><p>Keep NV at V; predecessor N.</p></div><div class=\"step\"><h4>Step 4. Choose and backtrack</h4><p>0.126 > 0.0128. End at V and follow its stored predecessor N.</p></div><div class=\"answer\">Best sequence: N,V, with joint score 0.126.</div></section>"},{"id":"q5","title":"Q5 (3 marks)","html":"<section class=\"example\"><h3>Q5</h3><p class=\"question\">Apply simplified Lesk to “bank” with preprocessed context {river, water, flooded}. Gloss R is {sloping, land, river, water}; gloss F is {financial, institution, money, loan}. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Two already preprocessed gloss sets and one context set.</p><strong>To find</strong><p>Overlap scores and selected sense.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/4b90e7419dc87033.svg\" alt=\"\\text{score}(s)=|\\text{context}\\cap\\text{gloss}(s)|\" style=\"width:29.378ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Simplified Lesk chooses the sense whose gloss shares the largest number of context words, using the specified set-overlap convention.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Intersect the river gloss</h4><p>{river, water, flooded} ∩ {sloping, land, river, water} = {river, water}.</p></div><div class=\"step\"><h4>Step 2. Count the river overlap</h4><div class=\"math-display\"><img src=\"math/dd672eb60c452a19.svg\" alt=\"score(R)=2\" style=\"width:12.838ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Intersect and count the financial gloss</h4><p>No shared words; intersection is empty, so score(F)=0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>2 > 0, hence select the river-bank sense.</p></div><div class=\"answer\">River-bank sense, with overlap 2 versus 0.</div></section>"}],"scope":"M2 · confirmed 2 + 2 + any two of 3 + 3 + 3 · worked practice"},{"id":"mock-c","title":"M2 Mock C · mixed numerical practice","unit":"Practice","sections":[{"id":"instructions","title":"Paper instructions","html":"<p><strong>Practice paper · 10 marks · 60 minutes.</strong> Q1 and Q2 are compulsory (2 marks each). Attempt any two of Q3, Q4 and Q5 (3 marks each). All five solutions are included below their questions. These are newly authored practice questions, not predictions of the actual paper.</p><p>Use about 8 minutes each for Q1–Q2, 16 minutes each for the two chosen 3-mark questions, and the remaining 12 minutes to read, choose and check. Write the formula and substitutions even if a final calculation gets stuck.</p>"},{"id":"q1","title":"Q1 (2 marks)","html":"<section class=\"example\"><h3>Q1</h3><p class=\"question\">A corpus contains five occurrences tagged Noun. Three of them are “cat”. It contains four Verb tokens, one of which is “cat”. Calculate P(cat|Noun) and P(cat|Verb). <span class=\"marks\">(2 marks)</span></p><div class=\"given\"><strong>Given</strong><p>C(N)=5; C(cat,N)=3; C(V)=4; C(cat,V)=1.</p><strong>To find</strong><p>The two emission probabilities.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/a89d9641a3681129.svg\" alt=\"P(w\\mid t)=\\frac{C(w,t)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>An emission conditions on the tag, so the denominator counts tokens of that tag.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Noun emission</h4><div class=\"math-display\"><img src=\"math/2c58a6fe2e2bd177.svg\" alt=\"P(\\text{cat}\\mid N)=\\frac35=0.6\" style=\"width:21.422ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Verb emission</h4><div class=\"math-display\"><img src=\"math/7ce20bd4ba2c5e3d.svg\" alt=\"P(\\text{cat}\\mid V)=\\frac14=0.25\" style=\"width:22.284ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">P(cat|N)=0.6 and P(cat|V)=0.25.</div></section>"},{"id":"q2","title":"Q2 (2 marks)","html":"<section class=\"example\"><h3>Q2</h3><p class=\"question\">Each of five words may receive any of three POS tags. How many possible tag sequences exist before applying constraints? <span class=\"marks\">(2 marks)</span></p><div class=\"given\"><strong>Given</strong><p>T=5 token positions; K=3 choices at each position.</p><strong>To find</strong><p>Total tag sequences.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/ed1eadf4591c422c.svg\" alt=\"K^T\" style=\"width:3.443ex;height:2.017ex\" loading=\"lazy\" decoding=\"async\"></div><p>Choose one tag independently for each position when counting candidates; multiply the number of options five times.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Expand the power</h4><div class=\"math-display\"><img src=\"math/064d395af2cadd10.svg\" alt=\"3^5=3\\times3\\times3\\times3\\times3\" style=\"width:21.855ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Multiply</h4><div class=\"math-display\"><img src=\"math/6a2ca9dea8abf7e6.svg\" alt=\"3\\times3=9,\\quad9\\times3=27\" style=\"width:22.753ex;height:1.968ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4502edf461289ab6.svg\" alt=\"27\\times3=81,\\quad81\\times3=243\" style=\"width:27.278ex;height:1.971ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">243 tag sequences.</div></section>"},{"id":"q3","title":"Q3 (3 marks)","html":"<section class=\"example\"><h3>Q3</h3><p class=\"question\">For trigram prediction, C(i like)=5, C(i like tea)=3 and C(i like coffee)=2. Find the MLE probability of each continuation. Then find add-one P(tea|i like) using a continuation vocabulary of size 4. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Two-word history i like occurs 5 times; continuations tea=3, coffee=2; |V|=4.</p><strong>To find</strong><p>Two MLE values and the smoothed tea probability.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/0ca97d5e894e09b1.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=\\frac{C(w_{i-2},w_{i-1},w_i)}{C(w_{i-2},w_{i-1})}\" style=\"width:38.191ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/749bec61cf2a8b8e.svg\" alt=\"P_{+1}(w\\mid h)=\\frac{C(hw)+1}{C(h)+|V|}\" style=\"width:24.813ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>A trigram conditions on two preceding words. The same add-one count rule applies to that longer history.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Tea MLE</h4><div class=\"math-display\"><img src=\"math/b943d3d9935a9541.svg\" alt=\"P(\\text{tea}\\mid i,\\text{like})=\\frac35=0.6\" style=\"width:24.657ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Coffee MLE</h4><div class=\"math-display\"><img src=\"math/c5f56302282fa692.svg\" alt=\"P(\\text{coffee}\\mid i,\\text{like})=\\frac25=0.4\" style=\"width:27.17ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Smooth tea</h4><div class=\"math-display\"><img src=\"math/36b3ccec8e82a718.svg\" alt=\"P_{+1}(\\text{tea}\\mid i,\\text{like})=\\frac{3+1}{5+4}=\\frac49\\approx0.444444\" style=\"width:41.339ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">MLE tea=0.6; coffee=0.4; smoothed tea=4/9≈0.444444.</div></section>"},{"id":"q4","title":"Q4 (3 marks)","html":"<section class=\"example\"><h3>Q4</h3><p class=\"question\">Training sentences with tags are: “the/D cat/N sleeps/V” and “a/D dog/N runs/V”. Estimate start/end-inclusive transition probabilities and the joint probability of “the cat sleeps” with path D,N,V. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>Two paths start→D→N→V→end. Four distinct words the,a,cat,dog and two verbs sleeps,runs. Use unsmoothed estimates and lowercase tokens.</p><strong>To find</strong><p>Transitions, required emissions and full path score.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/91497b7e4448d55d.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i\\to t_j)}{\\sum_k C(t_i\\to t_k)}\" style=\"width:26.759ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a89d9641a3681129.svg\" alt=\"P(w\\mid t)=\\frac{C(w,t)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Transition denominators count outgoing transitions from the previous state. Emission denominators count all tokens tagged with the emitting state.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Count transitions</h4><p>start→D, D→N, N→V and V→end each occur twice. Each state has just one observed next state.</p></div><div class=\"step\"><h4>Step 2. Divide to get probabilities</h4><div class=\"math-display\"><img src=\"math/a7ee998df3e74fd3.svg\" alt=\"P(D\\mid start)=P(N\\mid D)=P(V\\mid N)=P(end\\mid V)=\\frac22=1\" style=\"width:59.468ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Estimate emissions</h4><div class=\"math-display\"><img src=\"math/afa17db444c44e08.svg\" alt=\"P(\\text{the}\\mid D)=\\frac12\" style=\"width:15.505ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/00ba54f74d066f93.svg\" alt=\"P(\\text{cat}\\mid N)=\\frac12\" style=\"width:15.514ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/976665ab2b58cdd4.svg\" alt=\"P(\\text{sleeps}\\mid V)=\\frac12\" style=\"width:17.907ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Multiply in word order</h4><div class=\"math-display\"><img src=\"math/b84bd52617fb1279.svg\" alt=\"P=1\\times\\frac12\\times1\\times\\frac12\\times1\\times\\frac12\\times1=\\frac18=0.125\" style=\"width:45.53ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Joint probability=0.125. Each of the four observed transition probabilities is 1.</div></section>"},{"id":"q5","title":"Q5 (3 marks)","html":"<section class=\"example\"><h3>Q5</h3><p class=\"question\">In a WSD training set, financial bank and river bank each have two labelled contexts. Token totals are N(F)=6 and N(R)=6. Vocabulary size is 8. Counts are C(loan,F)=2, C(loan,R)=0, C(water,F)=0, C(water,R)=3. Use add-one Naive Bayes to classify context {loan,water}. <span class=\"marks\">(3 marks)</span></p><div class=\"given\"><strong>Given</strong><p>P(F)=P(R)=2/4=0.5; |V|=8; both class token totals=6.</p><strong>To find</strong><p>Smoothed scores and winning sense.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/684c27f96a1d3e08.svg\" alt=\"s(c)=P(c)\\prod_wP(w\\mid c)\" style=\"width:22.847ex;height:4.769ex\" loading=\"lazy\" decoding=\"async\"></div><p>Class priors use labelled-context counts; word likelihood denominators use class token totals. Do not exchange those two totals.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Find the denominator</h4><div class=\"math-display\"><img src=\"math/f1b9154da4378a4a.svg\" alt=\"6+8=14\" style=\"width:10.308ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Financial likelihoods</h4><div class=\"math-display\"><img src=\"math/eb9dda37004ceb2f.svg\" alt=\"P(loan\\mid F)=\\frac3{14},\\quad P(water\\mid F)=\\frac1{14}\" style=\"width:39.932ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. River likelihoods</h4><div class=\"math-display\"><img src=\"math/23fae5f134fd8df2.svg\" alt=\"P(loan\\mid R)=\\frac1{14},\\quad P(water\\mid R)=\\frac4{14}\" style=\"width:39.977ex;height:4.613ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Compute financial score</h4><div class=\"math-display\"><img src=\"math/6564e561ec421080.svg\" alt=\"s(F)=\\frac12\\times\\frac3{14}\\times\\frac1{14}=\\frac3{392}\\approx0.007653061\" style=\"width:44.071ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Compute river score</h4><div class=\"math-display\"><img src=\"math/db5c659ae2e27a2e.svg\" alt=\"s(R)=\\frac12\\times\\frac1{14}\\times\\frac4{14}=\\frac4{392}\\approx0.010204082\" style=\"width:44.094ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Choose</h4><p>4/392 > 3/392; the water evidence outweighs the loan evidence under these counts.</p></div><div class=\"answer\">River sense wins. If normalised, P(R|context)=4/7≈0.571429.</div></section>"}],"scope":"M2 · confirmed 2 + 2 + any two of 3 + 3 + 3 · worked practice"}],"revision":[{"id":"m2-revision","title":"M2 · last-day revision","unit":0,"sections":[{"id":"order","title":"Last-day reading order","html":"<p>Start with the families most likely to require arithmetic: <strong>smoothed bigrams, HMM probabilities and Naive Bayes WSD</strong>. Then revise perplexity, n-gram counts and Lesk. Parsing, POS approaches, WordNet and lexical relations remain in the confirmed portion; do not remove them merely because the expected paper is mostly numerical.</p><table><thead><tr><th>Time block</th><th>Read and work</th><th>What your written solution should contain</th></tr></thead><tbody><tr><td>First 60–90 min</td><td>N-grams, MLE and Laplace examples</td><td>Padded corpus → vocabulary → count table → each fraction → full product.</td></tr><tr><td>Next 60–90 min</td><td>HMM transition/emission and path examples</td><td>Tag totals → transition counts → matrices → alternating transition/emission factors.</td></tr><tr><td>Next 60–90 min</td><td>WSD and Lesk examples</td><td>Class priors → vocabulary → class totals → smoothed word likelihoods → score comparison.</td></tr><tr><td>Next 45–60 min</td><td>Perplexity, POS, parsing, WordNet, NER</td><td>Definitions, one meaningful example, a tree or table where needed.</td></tr><tr><td>Final 60 min</td><td>One M2 mock under exam time</td><td>Both 2-mark questions and any two 3-mark questions; compare every step with the answers.</td></tr></tbody></table><h3>The writing format to repeat</h3><div class=\"flow\"><div class=\"node\">Given</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">To find</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Formula + meaning</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Numbered calculations</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Answer</div></div><p>If the question supplies the corpus, draw the count table before using the calculator. A long product should be built from fractions that you have already justified. Keep fractions or stored calculator values until the end.</p>"},{"id":"method","title":"Recognise the question and start correctly","html":"<table><thead><tr><th>Question clue</th><th>Use this method</th><th>First thing to write</th></tr></thead><tbody><tr><td>“next word”, “sentence probability”</td><td>N-gram model</td><td>List the needed word transitions.</td></tr><tr><td>“unseen pair”, “Laplace”</td><td>Add-one smoothing</td><td>State V and count each history.</td></tr><tr><td>“perplexity”</td><td>Reciprocal Nth root</td><td>State P(test sequence) and N.</td></tr><tr><td>“transition/emission matrix”</td><td>HMM count estimation</td><td>Separate tag-to-tag counts from tag-to-word counts.</td></tr><tr><td>“given tag sequence”</td><td>HMM joint path</td><td>Initial × emission × transition × emission …</td></tr><tr><td>“best tag sequence”</td><td>Viterbi or enumerate tiny paths</td><td>Initialise one score per tag; retain predecessor maxima.</td></tr><tr><td>“gloss overlap”</td><td>Simplified Lesk</td><td>Preprocess context and glosses consistently.</td></tr><tr><td>“classify word sense with counts”</td><td>Naive Bayes WSD</td><td>Priors from examples, likelihoods from tokens.</td></tr><tr><td>“parse tree”</td><td>Given CFG + chosen parser</td><td>Show grammar expansions or stack reductions.</td></tr></tbody></table><h3>Errors that change the answer</h3><p>1. Dividing a conditional count by the whole corpus instead of its history count. 2. Adding 1 to the numerator without adding |V| to the denominator. 3. Forgetting the end transition. 4. Counting repeated words as new vocabulary types. 5. Using P(tag|word) in place of P(word|tag). 6. Calling an unnormalised score a posterior. 7. Silently mixing case, lemmatisation or boundary conventions.</p><h3>Short theory answer format</h3><p>For 2 marks: give the exact definition and one specific example or distinction. For 3 marks: add the mechanism or two ordered steps; include a small diagram/table where it carries information. The actual allocation is examiner-dependent, so these are writing guides, not an official marking scheme.</p>"}],"scope":"M2 · quick revision after completing the lessons"}],"about":[{"id":"scope","title":"Portion, paper pattern & sources","unit":0,"sections":[{"id":"sources","title":"What this NLP guide covers","html":"<p><strong>M2 portion confirmed by you:</strong> Unit 3 from PDF slide 62 to 160; Unit 4 complete (128 slides); Unit 5 slides 1–57. Slide 62 of Unit 3 starts N-grams. Slide 57 of Unit 5 completes the Naive Bayes WSD example. Vector-space models start on slide 58 and belong to TEE here.</p><p><strong>M2 pattern confirmed by you:</strong> both 2-mark questions compulsory; any two of the three 3-mark questions. Total attempted 10. Course policy gives one hour. Three newly authored, fully solved M2 practice papers use that pattern.</p><p><strong>TEE:</strong> all seven units of the official AY 2026–27 syllabus. The new ZIP supplies faculty slide packs for Units 1–5 plus a regular-expressions handout. Units 6–7 are syllabus-based explanations supplemented with the standard references below; their faculty slide packs were not supplied. The official syllabus includes GloVe and spelling correction, and both are retained even though the policy’s lecture table abbreviates them.</p><p><strong>Previous papers found:</strong> final exam dated 2 December 2025 and re-exam dated 9 February 2026, with answer keys, inside Semester V.zip. Programme copies were deduplicated. Every supplied question subpart is mapped to the current syllabus; no question was excluded as out of syllabus. Only wholly M2-eligible subparts appear in the M2 paper tab; mixed questions remain in the complete TEE papers.</p><p>The current syllabus lists course code 702AI0C037. The supplied policy and old papers use 702AI0C009; the policy also retains an older programme/semester header. Topic coverage follows the current official syllabus and your exact M2 cutoff, rather than treating the old header as a different course.</p><h3>Conventions that must stay visible</h3><p>Course bigram answer keys count both start and end symbols in vocabulary size. Worked PYQs state and follow that convention; other exercises state their own vocabulary explicitly. A start symbol is conditioning context, so alternative textbook conventions may exclude it from prediction vocabulary and produce a different smoothed number. HMM path scores and Naive Bayes class scores are labelled as unnormalised when applicable. Any normalisation, case-folding or lemmatisation assumption is stated before counting.</p><h3>Reading references</h3><ul class=\"source-list\"><li>Your uploaded course policy, official Semester V syllabus, five NLP slide packs and regular-expressions handout.</li><li>Your uploaded final and re-exam questions and answer keys (AY 2025–26).</li><li><a href=\"https://web.stanford.edu/~jurafsky/slp3/\" target=\"_blank\" rel=\"noopener\">Jurafsky & Martin · Speech and Language Processing</a> — terminology and standard methods.</li><li><a href=\"https://www.nltk.org/book/\" target=\"_blank\" rel=\"noopener\">NLTK Book</a> — corpus, tagging, parsing and information-extraction concepts.</li><li><a href=\"https://aclanthology.org/J01-4003.pdf\" target=\"_blank\" rel=\"noopener\">Tetreault · A Corpus-Based Evaluation of Centering and Pronoun Resolution</a> — precise Hobbs traversal.</li></ul><p>Examples are teaching problems unless explicitly identified by their paper and question number. Practice-paper marks indicate intended answer length, not an official forecast. Reading alone cannot guarantee a score; writing the solutions independently is what makes the procedures usable under exam time.</p><h3>TEE depth review · 10 October 2026</h3><p>The core TEE route retains the faculty topics CYK/CKY, grammar conversion, interpolation and Stupid Backoff. Add-k and HMM forward/posterior calculations are available separately under Optional extensions; they are not part of the core reading or formula sequence. The two TEE timed-practice entries reproduce the supplied actual papers and are not additional unseen mock papers.</p><p>Method references: <a href=\"https://web.stanford.edu/~jurafsky/slp3/A.pdf\" target=\"_blank\" rel=\"noopener\">Jurafsky and Martin: Hidden Markov Models</a>; <a href=\"https://web.stanford.edu/~jurafsky/slp3/E.pdf\" target=\"_blank\" rel=\"noopener\">Jurafsky and Martin: Constituency Parsing</a>. New numerical inputs and worked traces are teaching examples.</p>"},{"id":"videos","title":"Video companions in your NotebookLM","html":"<p>Your M2 notebook contains the exact three slide ranges and checked numerical teaching examples. The requested video topics are N-grams and Laplace smoothing, HMM/Viterbi, and Naive Bayes WSD. Use the written solutions here for the complete calculations.</p><p><a href=\"https://notebook.google.com/notebook/a270ef1e-c285-4d31-9db1-302090c5f8b1\" target=\"_blank\" rel=\"noopener\">Open your NLP M2 notebook →</a></p><p>The notebook is in your signed-in Google account. Video generation and availability are shown in its Studio panel. Generated narration is a supplementary explanation; the numerical results in this guide have been independently checked.</p>"}],"scope":"NLP · M2 and TEE · edition 3 October 2026"}]},"tee":{"read":[{"id":"foundations","title":"Start here · language & probability","unit":0,"sections":[{"id":"language","title":"What NLP is doing","html":"<p><strong>Natural Language Processing (NLP)</strong> is the study of computational methods for analysing, interpreting and producing human language. An NLP system receives text or speech and produces an output such as a tag, a meaning, a translation or a probability.</p><p>A central question in NLP is: <strong>how do counts from a training corpus become probabilities, and how do those probabilities help choose a sentence, a tag or a word sense?</strong> You will learn the vocabulary first, then do the arithmetic with complete working.</p><div class=\"flow\"><div class=\"node\">Training text<small>examples already observed</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Counts<small>how often things occur</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Probabilities<small>counts divided by totals</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Decision<small>compare possible answers</small></div></div><table><thead><tr><th>Term</th><th>Meaning</th><th>Concrete example</th></tr></thead><tbody><tr><td>Corpus</td><td>A collection of language data. The plural is corpora.</td><td>Three sentences saved together form a tiny corpus.</td></tr><tr><td>Document</td><td>One text item within a collection.</td><td>One review or one article.</td></tr><tr><td>Token</td><td>One occurrence produced by tokenization.</td><td>“cats like cats” has 3 word tokens.</td></tr><tr><td>Type</td><td>A distinct token value.</td><td>The same text has 2 types: cats and like.</td></tr><tr><td>Vocabulary</td><td>The set of token types recognised by the model.</td><td>V = {cats, like}; vocabulary size is 2.</td></tr><tr><td>Training</td><td>Estimating rules or numbers using examples.</td><td>Count how often like follows cats.</td></tr><tr><td>Test</td><td>Applying the learned model to a new example.</td><td>Calculate a probability for a sentence not used to build the counts.</td></tr></tbody></table><h3>Three levels you will repeatedly see</h3><table><thead><tr><th>Level</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>Word sequence</td><td>Which word is likely next?</td><td>After “drink”, is “water” likely?</td></tr><tr><td>Syntax</td><td>What role or structure does the word have?</td><td>“book” is a noun in “a book” and a verb in “book tickets”.</td></tr><tr><td>Semantics</td><td>Which meaning is intended?</td><td>“bank” near “deposit” means a financial institution.</td></tr></tbody></table><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka order = language model; word ka role = POS; word ka matlab = sense.</p><h3>Your TEE route</h3><p>Read these foundations, then continue through Units 1–7 in order. TEE includes preprocessing and vectors, corpora and regular expressions, language models, syntax, semantics, discourse and applications. The dedicated formula lessons and eight recovered previous papers follow the same methods. Original ambiguities are explained beside the affected answers.</p><p>Latest TEE pattern:100 marks in three hours; Q1 compulsory plus any four of Q2–Q7. Each full question carries20 marks. Historical December2023 ends at Q6; its choices are labelled separately. The M2 tab remains restricted to your confirmed midterm portion.</p><p><a href=\"#tee/about/pyq-analysis/all-papers\">Open the complete paper-by-paper map, original marks and full answers →</a></p><h3>Prepare the question forms seen in the latest papers first</h3><p>The 2 December 2025 final and 9 February 2026 re-exam both combine theory with applied work. Use their complete questions in <a href=\"#tee/papers\">Solved papers</a>; the two Timed papers are those actual papers, not new predictions.</p><ul><li><strong>Repeated calculations:</strong> add-one bigram sentence probability (Q2b in both); HMM emission/transition tables and the joint probability of a specified path (Q4b in both); co-occurrence vectors, cosine and a plot (final Q3b / re-exam Q5b).</li><li><strong>Other observed forms:</strong> TF–IDF matrix (final Q5a); BoW and pairwise cosines (re-exam Q4a); Naive Bayes WSD (final Q5b); Lesk with supplied glosses (re-exam Q3b).</li><li><strong>Theory and diagrams remain essential:</strong> definitions, comparisons, preprocessing, corpus uses, CFG trees, Hobbs traversal, embeddings and application workflows. An explanation question is not automatically a demand for a long calculation.</li></ul><p>Other faculty topics remain in the full syllabus route, but their authored exercises do not establish past-paper marks or frequency. <a href=\"#tee/about/optional-extensions\">Optional extensions</a> can wait until the actual paper methods are secure.</p>"},{"id":"notation","title":"Tokens, counts and symbols","html":"<p>A formula is a short way of stating a calculation. First name the quantities; only then insert the numbers. In this guide, C means a count and P means a probability.</p><table><thead><tr><th>Notation</th><th>Read it as</th><th>What to do</th></tr></thead><tbody><tr><td><span class=\"math-inline\"><img src=\"math/53df638c65412b2e.svg\" alt=\"C(\\text{cat})=3\" style=\"width:10.644ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Count of cat is three</td><td>Count every occurrence, including repeats.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/f74362866e81db35.svg\" alt=\"P(\\text{cat})\" style=\"width:6.475ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Probability of cat</td><td>A number from 0 to 1.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/c19161969f7b5db0.svg\" alt=\"P(\\text{cat}\\mid\\text{the})\" style=\"width:11.504ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Probability of cat given the</td><td>Restrict attention to occasions where the history is “the”.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/e1e73674daae58eb.svg\" alt=\"\\sum_i x_i\" style=\"width:5.54ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Sum of the x values</td><td>Add the terms: x₁ + x₂ + …</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/9213d2b315baaeb2.svg\" alt=\"\\prod_i x_i\" style=\"width:5.286ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Product of the x values</td><td>Multiply the terms: x₁ × x₂ × …</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/d6495ab774b17309.svg\" alt=\"\\arg\\max_c s(c)\" style=\"width:12.795ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>The choice c with the largest score</td><td>Return a label, not the numeric score.</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/b75d6d79f6931032.svg\" alt=\"\\max_c s(c)\" style=\"width:9.269ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Largest score</td><td>Return a number.</td></tr></tbody></table><section class=\"example\"><h3>Example 1 · tokens and types</h3><p class=\"question\">For the corpus “we study nlp” and “we like nlp”, find the token count, vocabulary and count of “we”.</p><div class=\"given\"><strong>Given</strong><p>Two lowercase sentences. Ignore punctuation; do not add boundary markers.</p><strong>To find</strong><p>Token count N, vocabulary V, vocabulary size |V| and C(we).</p></div><h3>Formula and why it applies</h3><p>A token is an occurrence; a type is a distinct word. Add sentence lengths to count tokens; remove duplicates only when finding the vocabulary.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. List every occurrence</h4><p>we, study, nlp, we, like, nlp.</p></div><div class=\"step\"><h4>Step 2. Count tokens</h4><div class=\"math-display\"><img src=\"math/ece835ece0dea071.svg\" alt=\"N=3+3=6\" style=\"width:14.203ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Keep one copy of each type</h4><p>V = {we, study, nlp, like}; |V| = 4.</p></div><div class=\"step\"><h4>Step 4. Count the requested word</h4><p>“we” appears once in each sentence, hence C(we) = 2.</p></div><div class=\"answer\">N = 6; |V| = 4; C(we) = 2.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Token mein repeat gin; type mein duplicate hata.</p></section><section class=\"example\"><h3>Example 2 · sum and product</h3><p class=\"question\">Given probabilities 0.5, 0.2 and 0.1, compute their sum and their product.</p><div class=\"given\"><strong>Given</strong><p>Three numbers: 0.5, 0.2, 0.1.</p><strong>To find</strong><p>Sum and product; recognise that these are different operations.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/63e5285ab6522f55.svg\" alt=\"\\sum_{i=1}^{3}p_i=p_1+p_2+p_3\" style=\"width:20.447ex;height:6.711ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/62eff7a248154cbf.svg\" alt=\"\\prod_{i=1}^{3}p_i=p_1p_2p_3\" style=\"width:14.54ex;height:6.711ex\" loading=\"lazy\" decoding=\"async\"></div><p>Add for a sum. Multiply for a product. A sentence-chain calculation normally uses the product of its conditional probabilities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Add the first two numbers</h4><div class=\"math-display\"><img src=\"math/7759ec5773e64d72.svg\" alt=\"0.5+0.2=0.7\" style=\"width:14.457ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Complete the sum</h4><div class=\"math-display\"><img src=\"math/5f21379b0e25bf90.svg\" alt=\"0.7+0.1=0.8\" style=\"width:14.457ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Multiply the first two numbers</h4><div class=\"math-display\"><img src=\"math/3666eec3c2831548.svg\" alt=\"0.5\\times0.2=0.1\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Complete the product</h4><div class=\"math-display\"><img src=\"math/3b2af630e6ad1d43.svg\" alt=\"0.1\\times0.1=0.01\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Sum = 0.8; product = 0.01.</div></section>"},{"id":"probability","title":"Probability, without skipped steps","html":"<p><strong>Empirical probability</strong> estimates how likely an event is from its observed frequency. Divide the number of relevant observations by the total number of observations in the selected group. For a conditional probability, the denominator is the count of the condition, not the size of the entire corpus.</p><div class=\"math-display\"><img src=\"math/cde1f475268fa5b4.svg\" alt=\"P(A)=\\frac{C(A)}{N}\" style=\"width:14.345ex;height:4.855ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/650cfba7e65676b7.svg\" alt=\"P(B\\mid A)=\\frac{C(A,B)}{C(A)}\" style=\"width:20.671ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Here A is the conditioning event, B is the event being predicted, C(A,B) counts observations containing both in the required relationship, and N is the total number of observations. “Given A” tells you which denominator to use.</p><div class=\"flow\"><div class=\"node\">Select the condition<small>“given A”</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Count matching outcomes<small>C(A,B)</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Divide by condition count<small>C(A)</small></div></div><section class=\"example\"><h3>Example 1 · word probability</h3><p class=\"question\">A corpus contains 20 tokens; “rain” occurs 5 times. Find the unigram probability of “rain”.</p><div class=\"given\"><strong>Given</strong><p>N = 20 and C(rain) = 5.</p><strong>To find</strong><p>P(rain).</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/2711f5706c9dc86b.svg\" alt=\"P(w)=\\frac{C(w)}{N}\" style=\"width:14.191ex;height:4.855ex\" loading=\"lazy\" decoding=\"async\"></div><p>Unigram probability ignores neighbouring words. Every token in the corpus is one observation.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Insert the count and total</h4><div class=\"math-display\"><img src=\"math/24d2e511eeadd9c0.svg\" alt=\"P(\\text{rain})=\\frac{5}{20}\" style=\"width:13.639ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Divide</h4><div class=\"math-display\"><img src=\"math/07337f908c856c5a.svg\" alt=\"\\frac{5}{20}=0.25\" style=\"width:10.298ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">P(rain) = 0.25, or 25%.</div></section><section class=\"example\"><h3>Example 2 · conditional probability</h3><p class=\"question\">In a corpus, “drink” is followed by another word 8 times. It is followed by “water” 6 times. Find P(water | drink).</p><div class=\"given\"><strong>Given</strong><p>C(drink as a history) = 8; C(drink, water) = 6.</p><strong>To find</strong><p>Probability that the next word is water, given drink.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/b16537e98cb2aea8.svg\" alt=\"P(\\text{water}\\mid\\text{drink})=\\frac{C(\\text{drink water})}{C(\\text{drink})}\" style=\"width:34.928ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>The condition is drink, so use the 8 drink-histories as the denominator.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the favourable continuations</h4><p>Six of the eight continuations are water.</p></div><div class=\"step\"><h4>Step 2. Divide</h4><div class=\"math-display\"><img src=\"math/c4bcc480ea0098b5.svg\" alt=\"P(\\text{water}\\mid\\text{drink})=\\frac68=0.75\" style=\"width:28.291ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">P(water | drink) = 0.75.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Bar ke right mein jo hai, denominator uska count.</p></section><section class=\"example\"><h3>Example 3 · multiply a sequence</h3><p class=\"question\">A model gives P(a | start) = 0.4, P(cat | a) = 0.5 and P(end | cat) = 0.2. Find the probability of the complete sentence “a cat”.</p><div class=\"given\"><strong>Given</strong><p>Start → a = 0.4; a → cat = 0.5; cat → end = 0.2.</p><strong>To find</strong><p>Probability of the three-transition path.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/20d792a0426e11b9.svg\" alt=\"P(\\text{a cat, end})=P(\\text{a}\\mid\\text{start})P(\\text{cat}\\mid\\text{a})P(\\text{end}\\mid\\text{cat})\" style=\"width:48.424ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Every transition must happen in sequence, so multiply the model’s conditional probabilities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Write the three factors in order</h4><div class=\"math-display\"><img src=\"math/aacb5800d20f6f86.svg\" alt=\"P=0.4\\times0.5\\times0.2\" style=\"width:18.922ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Multiply the first pair</h4><div class=\"math-display\"><img src=\"math/4528e6e7a97bb8e8.svg\" alt=\"0.4\\times0.5=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Multiply by the last factor</h4><div class=\"math-display\"><img src=\"math/45c99ba534e1771d.svg\" alt=\"0.2\\times0.2=0.04\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Complete-sentence probability = 0.04.</div></section><section class=\"example\"><h3>Example 4 · compare labels</h3><p class=\"question\">Two tag candidates have scores noun = 0.036 and verb = 0.048. Which tag does argmax return? If these are the only candidates, find the normalised noun probability.</p><div class=\"given\"><strong>Given</strong><p>s(noun) = 0.036 and s(verb) = 0.048.</p><strong>To find</strong><p>Winning label and normalised noun probability.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/d264cbc0f9fb7e13.svg\" alt=\"\\hat c=\\arg\\max_c s(c)\" style=\"width:15.912ex;height:3.459ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0cbb12db950a8417.svg\" alt=\"P(c)=\\frac{s(c)}{\\sum_j s(j)}\" style=\"width:15.818ex;height:5.881ex\" loading=\"lazy\" decoding=\"async\"></div><p>A score need not sum to 1. Dividing each score by the sum gives a distribution over the candidates.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compare scores</h4><p>0.048 > 0.036, so verb wins.</p></div><div class=\"step\"><h4>Step 2. Find their total</h4><div class=\"math-display\"><img src=\"math/884e5c8a756ca87a.svg\" alt=\"0.036+0.048=0.084\" style=\"width:21.244ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Divide the noun score by the total</h4><div class=\"math-display\"><img src=\"math/58bb63e903487b21.svg\" alt=\"P(\\text{noun})=\\frac{0.036}{0.084}=\\frac37\\approx0.428571\" style=\"width:34.239ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">argmax returns “verb”. The normalised noun probability is approximately 0.428571.</div></section>"},{"id":"bayes","title":"Bayes’ rule: prior, evidence and answer","html":"<p><strong>Bayes’ rule</strong> reverses a conditional probability. A word-sense classifier asks “which sense is most likely given these context words?” Training data more easily supplies “how likely are these words when this sense is used?” Bayes connects the two.</p><div class=\"math-display\"><img src=\"math/9afdb53fbf7886dd.svg\" alt=\"P(c\\mid x)=\\frac{P(x\\mid c)P(c)}{P(x)}\" style=\"width:23.689ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>c</td><td>A candidate class, tag or word sense.</td></tr><tr><td>x</td><td>The observed evidence, such as a context word.</td></tr><tr><td>P(c)</td><td>Prior: how common the class is before seeing the evidence.</td></tr><tr><td>P(x | c)</td><td>Likelihood: how compatible the evidence is with that class.</td></tr><tr><td>P(c | x)</td><td>Posterior: probability of the class after observing the evidence.</td></tr><tr><td>P(x)</td><td>Evidence normaliser, shared by all classes for the same observation.</td></tr></tbody></table><p>For ranking classes, calculate <strong>prior × likelihood</strong>. The common denominator does not affect which class is largest. For an actual posterior probability, divide by the sum of all class scores.</p><section class=\"example\"><h3>A complete Bayes calculation</h3><p class=\"question\">A word has two senses: financial bank and river bank. Priors are 0.6 and 0.4. The probability of observing “loan” is 0.5 under the financial sense and 0.1 under the river sense. Find the most likely sense and its posterior.</p><div class=\"given\"><strong>Given</strong><p>P(F) = 0.6; P(R) = 0.4; P(loan | F) = 0.5; P(loan | R) = 0.1. These two senses are exhaustive.</p><strong>To find</strong><p>Scores and P(F | loan).</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/c8e3aa7e814574bf.svg\" alt=\"s(c)=P(c)P(\\text{loan}\\mid c)\" style=\"width:21.731ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/1414aff0cfb8fbd2.svg\" alt=\"P(F\\mid\\text{loan})=\\frac{s(F)}{s(F)+s(R)}\" style=\"width:27.022ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply prior and likelihood to reverse the conditioning. Then normalise because a posterior was requested.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Score the financial sense</h4><div class=\"math-display\"><img src=\"math/72319d32a8913027.svg\" alt=\"s(F)=0.6\\times0.5=0.30\" style=\"width:23.121ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Score the river sense</h4><div class=\"math-display\"><img src=\"math/adf5b8b758b9a296.svg\" alt=\"s(R)=0.4\\times0.1=0.04\" style=\"width:23.144ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Add the scores</h4><div class=\"math-display\"><img src=\"math/d526374c15c8e154.svg\" alt=\"P(\\text{loan})=0.30+0.04=0.34\" style=\"width:28.476ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Normalise the financial score</h4><div class=\"math-display\"><img src=\"math/99c028fbba7fd3e1.svg\" alt=\"P(F\\mid\\text{loan})=\\frac{0.30}{0.34}=\\frac{15}{17}\\approx0.882353\" style=\"width:37.064ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Financial bank wins; its posterior probability is about 0.882353.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Pehle se kitna common × evidence kitna suit karta = score.</p></section>"},{"id":"calculator","title":"Small probabilities, logs and calculator use","html":"<p>Repeated multiplication of probabilities produces small numbers. A calculator may show 0.0000125 as <strong>1.25 × 10⁻⁵</strong>; they are the same value. A logarithm turns a product into a sum. Log probabilities are often negative because probabilities between 0 and 1 have negative logs.</p><div class=\"math-display\"><img src=\"math/aa22afa6e5e6a3ea.svg\" alt=\"\\log(ab)=\\log a+\\log b\" style=\"width:21.306ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/7a41936887c316a1.svg\" alt=\"\\log_b x=y\\quad\\Longleftrightarrow\\quad b^y=x\" style=\"width:25.801ex;height:2.205ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use the log base specified in the question. Natural log is ln (base e); ordinary calculator log is usually base 10. Perplexity is simplest to evaluate using the direct power formula. Do not mix bases in the same calculation.</p><section class=\"example\"><h3>Calculator example · roots in perplexity</h3><p class=\"question\">A model assigns probability 1/16 to a test sequence with 4 predicted tokens. Calculate perplexity.</p><div class=\"given\"><strong>Given</strong><p>P = 1/16; N = 4 predicted tokens.</p><strong>To find</strong><p>Perplexity PP.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/8263823864a08bf0.svg\" alt=\"PP=P^{-1/N}=\\left(\\frac1P\\right)^{1/N}\" style=\"width:24.943ex;height:6.01ex\" loading=\"lazy\" decoding=\"async\"></div><p>Perplexity takes the reciprocal probability and then its Nth root. N must match the number of predicted events in the product.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Take the reciprocal</h4><div class=\"math-display\"><img src=\"math/58b85b07a845828b.svg\" alt=\"\\frac{1}{1/16}=16\" style=\"width:10.8ex;height:5.208ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Take the fourth root</h4><div class=\"math-display\"><img src=\"math/fcf353f0637dd633.svg\" alt=\"PP=16^{1/4}=2\" style=\"width:15.414ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Interpret</h4><p>A perplexity of 2 means an effective average uncertainty comparable to two equally likely alternatives. It is not 2% error.</p></div><div class=\"answer\">PP = 2.</div></section><h3>Calculator entry order</h3><p>Enter the full product with parentheses. For the Nth root enter <strong>(1 ÷ P)^(1 ÷ N)</strong>. Keep at least 6 significant digits while working; round the final answer. If your calculator offers Ans, reuse the stored value instead of typing a heavily rounded result.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Probability ke factors multiply; log mein add; perplexity mein ulta karke root.</p>"}],"scope":"Shared language and probability foundations · TEE"},{"id":"u1-introduction","title":"NLP foundations: language, tasks and the processing pipeline","unit":1,"mode":"tee","scope":"TEE · Unit 1 full","sections":[{"id":"u1-nlp","title":"What natural language processing actually does","html":"<p><strong>Natural language processing (NLP) is the field concerned with computational methods for analysing, interpreting and generating human language.</strong> Natural languages such as English, Hindi and Marathi evolved through human use; their meanings are not specified by the rigid rules of a programming language.</p><p>An NLP system may receive text, speech converted to text, or another linguistic representation. Its output depends on the task: a category, a tag for every word, a translated sentence, a ranked document list or a generated answer. It does not always “understand” in the human sense; its performance must be evaluated for the specific task.</p><table><thead><tr><th>Task</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>Sentiment analysis</td><td>“The service was excellent.”</td><td>Positive sentiment</td></tr><tr><td>Text classification</td><td>An email</td><td>Spam / not spam</td></tr><tr><td>POS tagging</td><td>“Birds fly.”</td><td>Birds/NOUN fly/VERB</td></tr><tr><td>Named entity recognition</td><td>“Asha joined Google in Mumbai.”</td><td>Asha: person; Google: organisation; Mumbai: location</td></tr><tr><td>Machine translation</td><td>A Hindi sentence</td><td>A corresponding English sentence</td></tr><tr><td>Information retrieval</td><td>A search query</td><td>Ranked relevant documents</td></tr><tr><td>Question answering</td><td>Question plus knowledge/context</td><td>An answer</td></tr><tr><td>Summarization</td><td>A long article</td><td>A shorter text preserving key information</td></tr></tbody></table><h3>How NLP relates to AI, ML and DL</h3><p><strong>AI</strong> is the broader study of systems performing tasks associated with intelligent behaviour. <strong>Machine learning</strong> learns patterns from data. <strong>Deep learning</strong> uses multiple trainable neural layers. NLP is an application/research field that can use hand-written rules, statistical ML or deep learning. Therefore, not every NLP system is a neural network.</p><p>Linguistics supplies knowledge about language structure. Statistics supplies uncertainty models. Computer science supplies algorithms, storage and efficient implementation. A practical NLP system combines these ideas.</p><p class=\"cue\">NLP = human language ko computational task mein badlo: label, meaning, search ya generated sentence.</p>"},{"id":"u1-language","title":"Building blocks and levels of linguistic analysis","html":"<p><strong>A phoneme</strong> is a sound unit that can distinguish meanings in a language, such as the /p/ and /b/ contrast in “pat” and “bat”. A phoneme is a sound, not necessarily one alphabet letter. <strong>A morpheme</strong> is the smallest meaning-bearing grammatical unit: cats = cat + plural -s; unhappy = un- + happy.</p><p><strong>A lexeme</strong> is an abstract vocabulary item grouping its inflected forms: write, writes, wrote and writing belong to WRITE. A <strong>phrase</strong> is a group of words functioning together; a <strong>clause</strong> normally contains a predicate and its associated participants; a <strong>sentence</strong> expresses a complete grammatical unit.</p><table><thead><tr><th>Level</th><th>What it analyses</th><th>Concrete example</th></tr></thead><tbody><tr><td>Phonetics / phonology</td><td>Physical sounds / sound patterns in a language</td><td>Distinguish bat from pat</td></tr><tr><td>Morphology / lexical analysis</td><td>Word structure and lexical items</td><td>un + help + ful → unhelpful</td></tr><tr><td>Syntax</td><td>Grammatical arrangement and relationships</td><td>The dog chased the cat: subject, verb, object</td></tr><tr><td>Semantics</td><td>Meaning of words and composed expressions</td><td>The dog is the chaser; the cat is chased</td></tr><tr><td>Discourse</td><td>Connections across sentences</td><td>“Riya arrived. She smiled.” → She refers to Riya</td></tr><tr><td>Pragmatics</td><td>Intended meaning in the situation</td><td>“It is cold here” may request closing the window</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">word forms</div><span aria-hidden=\"true\">→</span><div class=\"node\">grammatical structure</div><span aria-hidden=\"true\">→</span><div class=\"node\">sentence meaning</div><span aria-hidden=\"true\">→</span><div class=\"node\">cross-sentence context</div><span aria-hidden=\"true\">→</span><div class=\"node\">speaker intention</div></div><h3>Three worked interpretations</h3><p><strong>“The cats are sleeping.”</strong> Morphology identifies cat + s as plural. Syntax connects “cats” to “are sleeping”. Semantics represents animals engaged in sleeping.</p><p><strong>“Aman bought a laptop. It was expensive.”</strong> Sentence-level syntax alone does not identify “it”. Discourse connects “it” to the laptop across the sentence boundary.</p><p><strong>“Wonderful, another power cut!”</strong> The word wonderful is positive literally, but situational context can indicate sarcasm and frustration. This is a pragmatic interpretation.</p><p>The analysis levels are conceptual descriptions. Modern systems may learn several jointly rather than executing a compulsory separate module for every level.</p><p class=\"cue\">Morphology = word ke andar; syntax = sentence ka structure; semantics = meaning; discourse = sentences ka link; pragmatics = intention.</p>"},{"id":"u1-approaches","title":"Rule-based, statistical and deep-learning approaches","html":"<p><strong>A rule-based system</strong> applies explicit patterns, dictionaries or linguistic rules written by people. Example: mark an email as a candidate company message when its sender matches a known domain. Rules are transparent but can be brittle under paraphrasing.</p><p><strong>A statistical/ML system</strong> estimates useful patterns from examples. A supervised classifier learns from texts with known labels. Unsupervised learning finds structure without those labels, such as clusters of news articles. <strong>A deep-learning system</strong> learns layered representations and can model context using neural architectures.</p><table><thead><tr><th>Criterion</th><th>Rule based</th><th>Statistical ML</th><th>Deep learning</th></tr></thead><tbody><tr><td>Main knowledge source</td><td>Expert-written rules</td><td>Features and training examples</td><td>Data and learned representations</td></tr><tr><td>Example</td><td>Regex + sentiment lexicon</td><td>TF–IDF + Naive Bayes/SVM</td><td>Transformer text classifier</td></tr><tr><td>Typical benefit</td><td>Interpretable, little training data</td><td>Effective with suitable features</td><td>Learns complex context</td></tr><tr><td>Typical limitation</td><td>Rule maintenance; exceptions</td><td>Feature dependence; data mismatch</td><td>Compute/data needs; harder interpretation</td></tr></tbody></table><h3>Understanding the learning terms</h3><p>A <strong>training example</strong> is one input instance. A <strong>label</strong> is its desired output. A <strong>feature</strong> is an input property used by the model. <strong>Training</strong> estimates parameters; <strong>inference</strong> applies fixed learned parameters to new input. Separate training, validation and test sets prevent evaluation from merely measuring memorization of examples already seen.</p><p><strong>Supervised example:</strong> review → positive/negative, using labelled reviews. <strong>Unsupervised example:</strong> cluster documents by word usage without topic labels. <strong>Reinforcement learning:</strong> choose actions using feedback or reward over interactions; it is not the same as training an ordinary classifier from labelled text.</p><p class=\"cue\">Rules: hum likhte hain. ML: examples se pattern. DL: representation bhi layers se seekhta hai.</p>"},{"id":"u1-nlu-nlg","title":"NLU versus NLG, explained through one assistant","html":"<p><strong>Natural language understanding (NLU)</strong> maps language into an interpretation useful for a task: intents, entities, semantic relations or another meaning representation. <strong>Natural language generation (NLG)</strong> produces human-language output from data, a representation or another source.</p><div class=\"flow\"><div class=\"node\">“Book a ticket to Pune tomorrow.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">NLU: intent=book; destination=Pune; date=tomorrow</div><span aria-hidden=\"true\">→</span><div class=\"node\">Application: search available journeys</div><span aria-hidden=\"true\">→</span><div class=\"node\">NLG: “Here are the available journeys to Pune.”</div></div><table><thead><tr><th>Feature</th><th>NLU</th><th>NLG</th></tr></thead><tbody><tr><td>Direction</td><td>Language → interpretation</td><td>Data/representation → language</td></tr><tr><td>Main concern</td><td>Meaning, intent, ambiguity</td><td>Content choice, organization, fluent wording</td></tr><tr><td>Example</td><td>Find destination in a request</td><td>Write the booking confirmation</td></tr><tr><td>Common failure</td><td>Wrong destination or sense</td><td>Unclear, unsupported or ungrammatical output</td></tr></tbody></table><h3>NLG stages in a classical pipeline</h3><ol><li><strong>Content determination:</strong> choose facts to communicate.</li><li><strong>Data interpretation:</strong> identify relationships or trends.</li><li><strong>Document planning:</strong> organize facts in a useful order.</li><li><strong>Sentence aggregation:</strong> combine related facts without repetition.</li><li><strong>Lexical and grammatical realization:</strong> choose words and construct grammatical sentences.</li><li><strong>Presentation:</strong> format the generated message for its audience.</li></ol><p>For a weather report, facts {city=Pune, temperature=28°C, rain=yes} can become “Pune will have rain with a temperature of 28°C.” NLU would instead extract facts or intent from an incoming language message.</p><p class=\"cue\">NLU = language se meaning andar. NLG = data se language bahar.</p>"},{"id":"u1-pipeline","title":"Generic NLP pipeline, evaluation and deployment","html":"<p><strong>An NLP pipeline is an organized sequence of operations that transforms raw language into a task output and checks whether that output is useful.</strong> Not every task needs every cleaning operation.</p><div class=\"flow\"><div class=\"node\">Data acquisition</div><span aria-hidden=\"true\">→</span><div class=\"node\">Preprocessing</div><span aria-hidden=\"true\">→</span><div class=\"node\">Feature representation</div><span aria-hidden=\"true\">→</span><div class=\"node\">Model</div><span aria-hidden=\"true\">→</span><div class=\"node\">Evaluation</div><span aria-hidden=\"true\">→</span><div class=\"node\">Deployment and monitoring</div></div><ol><li><strong>Data acquisition:</strong> collect relevant text and, when needed, labels.</li><li><strong>Cleaning and preprocessing:</strong> handle markup, tokenize, normalize and decide which information to retain.</li><li><strong>Feature engineering:</strong> represent text numerically using BoW, TF–IDF or embeddings.</li><li><strong>Modelling:</strong> apply rules or train a statistical/neural model.</li><li><strong>Evaluation:</strong> test on held-out data using task-appropriate measures.</li><li><strong>Deployment:</strong> make the system available, log suitable feedback and monitor errors or data changes.</li></ol><h3>Concrete spam-filter example</h3><p>Collect labelled emails → separate train/test data → tokenize text while preserving meaningful terms → fit vocabulary and IDF on training data → train classifier → evaluate spam detection on the held-out set → deploy an email service filter → monitor legitimate emails wrongly blocked.</p><p><strong>Intrinsic evaluation</strong> measures model/task quality, such as precision, recall or tagging accuracy. <strong>Extrinsic evaluation</strong> measures effect in the wider application, such as whether users find answers faster. A higher internal metric does not automatically guarantee a better user outcome.</p><p><strong>Data leakage:</strong> learning vocabulary statistics, labels or preprocessing decisions from the test set can make reported performance too optimistic. Fit learned transformations on training data, then apply them to validation/test data.</p><p class=\"cue\">Collect → clean → numbers → model → test → use. Test data ko training ki information mat banao.</p>"},{"id":"u1-challenges","title":"Ambiguity and other challenges with precise examples","html":"<p><strong>Ambiguity</strong> means an expression supports more than one interpretation. Good exam answers name the ambiguity and explain both readings.</p><table><thead><tr><th>Challenge</th><th>Example</th><th>Why a system can fail</th></tr></thead><tbody><tr><td>Lexical/sense ambiguity</td><td>bank: finance or river edge</td><td>One written word has several senses</td></tr><tr><td>Syntactic ambiguity</td><td>I saw the man with a telescope.</td><td>The telescope may modify saw or the man</td></tr><tr><td>Reference ambiguity</td><td>Riya told Neha that she won.</td><td>She may refer to either person without more context</td></tr><tr><td>Sarcasm</td><td>Great, another delay.</td><td>Literal positive word conveys frustration</td></tr><tr><td>Negation</td><td>The film was not good.</td><td>Dropping not reverses meaning</td></tr><tr><td>Domain shift</td><td>“Positive” in a medical report</td><td>Meaning/use differs by domain</td></tr><tr><td>Code mixing</td><td>Kal meeting reschedule karna.</td><td>Several languages and spelling conventions</td></tr><tr><td>Noisy text</td><td>tmrw, repeated letters, typos</td><td>Vocabulary/token boundaries become uncertain</td></tr><tr><td>Low-resource setting</td><td>Few labelled examples in a language</td><td>Models lack representative training evidence</td></tr><tr><td>Bias and privacy</td><td>Skewed data or personal details</td><td>Errors and harms can persist in deployed systems</td></tr></tbody></table><p><strong>Homophones</strong> sound alike but may differ in spelling (pair/pear). <strong>Homographs</strong> share spelling but can differ in meaning or pronunciation (lead the team / lead metal). These are different dimensions from syntactic ambiguity.</p><p>Long-distance dependencies, cultural knowledge, idioms, morphology and multilingual writing systems also complicate processing. For “kick the bucket”, literal word-by-word interpretation can miss the idiomatic meaning. For “The book that the students recommended is useful”, the verb is agrees with book across an intervening phrase.</p><p class=\"cue\">Exam mein challenge ka naam + ek sentence + dono meanings/actual failure likho.</p>"}]},{"id":"u2-preprocess","title":"Text preprocessing, normalization and lexical diversity","unit":2,"mode":"tee","scope":"TEE · Unit 2 PDF pages 1–50","sections":[{"id":"u2-tokenize","title":"Tokenization: sentence, word, character and subword","html":"<p><strong>Tokenization divides text into units called tokens for further processing.</strong> A token may be a word, punctuation mark, character or subword, depending on the tokenizer. <strong>Sentence segmentation</strong> identifies sentence boundaries. Tokenization is not necessarily just splitting on spaces.</p><table><thead><tr><th>Method</th><th>Example</th><th>Trade-off</th></tr></thead><tbody><tr><td>Word</td><td>“cats sleep” → [cats,sleep]</td><td>Easy to interpret; unfamiliar words can be unseen tokens</td></tr><tr><td>Character</td><td>cat → [c,a,t]</td><td>Handles spelling units; creates longer sequences</td></tr><tr><td>Subword</td><td>unhappiness → pieces such as [un,happi,ness] in an illustrative vocabulary</td><td>Balances vocabulary size and rare-word representation</td></tr><tr><td>Sentence</td><td>“Birds fly. Fish swim.” → two sentences</td><td>Abbreviations and punctuation complicate boundaries</td></tr></tbody></table><p>Actual subword splits depend on the learned vocabulary; the example is illustrative, not a universal tokenizer output. Word segmentation is especially important where spaces do not reliably separate words or in compound-rich languages.</p><div class=\"example\"><p><strong>Question. Tokenize “Dr. Rao can't come today.” into words and punctuation under this rule: preserve Dr. and can't as whole tokens, and split only the final full stop.</strong></p><div class=\"given\"><h4>Given</h4><p>The tokenization rule is explicitly supplied.</p><h4>To find</h4><p>The resulting token sequence.</p></div><h4>Formula and why it applies</h4><p>Apply the stated boundary rule; do not assume every period or apostrophe is a split point.</p><div class=\"step\"><h4>Step 1. Handle abbreviation</h4><p>Dr. remains one token.</p></div><div class=\"step\"><h4>Step 2. Handle contraction</h4><p>can't remains one token.</p></div><div class=\"step\"><h4>Step 3. Write sequence</h4><p>[Dr., Rao, can't, come, today, .]</p></div><p class=\"answer\"><strong>Answer.</strong> 6 tokens under the specified rule. Another tokenizer may legitimately produce a different sequence.</p></div><h3>Three difficult cases</h3><p><strong>New York</strong> may be two tokens but one named entity. <strong>3.14</strong> should not normally end a sentence at the decimal point. <strong>don't</strong> may remain whole or split into do + n't, depending on the tokenizer. Always state the convention when calculating counts.</p><p class=\"cue\">Token = chosen unit. Space split ko universal rule mat samajh.</p>"},{"id":"u2-normalization","title":"Cleaning, case folding, punctuation and stopwords","html":"<p><strong>Normalization reduces superficial variation so comparable forms can be processed consistently.</strong> Common operations include lowercasing, Unicode normalization, appropriate spelling correction, contraction handling, and optional stemming or lemmatization.</p><p><strong>Stopwords</strong> are frequent words selected for removal for a particular task, such as the or a. Removing them may reduce feature size, but removing not, no or nor can destroy sentiment meaning. Punctuation can convey sentence boundaries, emotion or mathematical structure. Lowercasing can erase differences such as US versus us.</p><div class=\"example\"><p><strong>Question. Preprocess “The CATS are not sleeping!!!” by lowercasing, removing punctuation, removing only stopwords {the,are}, and lemmatizing plural cats→cat and sleeping→sleep.</strong></p><div class=\"given\"><h4>Given</h4><p>Operations and stopword set are fixed. Do not remove not.</p><h4>To find</h4><p>The final token list.</p></div><h4>Formula and why it applies</h4><p>Apply the requested operations in order, keeping a visible intermediate result after each transformation.</p><div class=\"step\"><h4>Step 1. Lowercase</h4><p>the cats are not sleeping!!!</p></div><div class=\"step\"><h4>Step 2. Tokenize and remove punctuation</h4><p>[the,cats,are,not,sleeping]</p></div><div class=\"step\"><h4>Step 3. Remove specified stopwords</h4><p>Remove the and are → [cats,not,sleeping].</p></div><div class=\"step\"><h4>Step 4. Lemmatize</h4><p>cats→cat; sleeping→sleep → [cat,not,sleep].</p></div><p class=\"answer\"><strong>Answer.</strong> [cat,not,sleep]. The negative meaning is retained.</p></div><h3>Task decides preprocessing</h3><p>For a simple keyword-retrieval model, removing selected function words can help. For machine translation, question answering, grammar analysis or transformer input, aggressive removal may discard necessary syntax or violate the model's expected input format. Emoji can carry sentiment; convert or retain them when relevant instead of always deleting them.</p><p class=\"cue\">Clean karna = useful signal bachake noise hatao. Har word/punctuation delete karna cleaning nahi.</p>"},{"id":"u2-stem-lemma","title":"Stemming versus lemmatization","html":"<p><strong>Stemming</strong> applies string-based rules, often stripping suffixes, to reduce related forms to a stem. The result need not be a valid dictionary word. <strong>Lemmatization</strong> uses vocabulary and morphological analysis, often with POS information, to return a dictionary lemma.</p><table><thead><tr><th>Criterion</th><th>Stemming</th><th>Lemmatization</th></tr></thead><tbody><tr><td>Basis</td><td>Surface form/suffix rules</td><td>Lexicon and morphological/POS analysis</td></tr><tr><td>Output</td><td>May be nonword, e.g. studi</td><td>Dictionary form, e.g. study</td></tr><tr><td>Context/POS</td><td>Usually little or none</td><td>Often important</td></tr><tr><td>Irregular forms</td><td>May miss went→go</td><td>Can map went→go with verb analysis</td></tr><tr><td>Cost</td><td>Generally simpler</td><td>Usually more linguistic processing</td></tr></tbody></table><p>Porter applies a sequence of suffix-removal rules subject to conditions; Snowball provides related language-specific stemming algorithms; Lancaster is often more aggressive; regex stemming uses explicit patterns; Lovins is another established stemming approach. Exact output depends on the algorithm and implementation.</p><h3>Three worked reductions</h3><ol><li><strong>studies, studying:</strong> an English stemmer may yield studi/study depending on the rule sequence; verb lemmatization aims at study. State the exact algorithm if exact outputs are asked.</li><li><strong>better:</strong> adjective-aware lemmatization can map it to good; naïve suffix removal cannot infer that irregular relation.</li><li><strong>saw:</strong> as a past-tense verb it can become see; as a cutting-tool noun it remains saw. POS and context matter.</li></ol><p><strong>Over-stemming</strong> merges forms that should remain distinct; <strong>under-stemming</strong> fails to merge related forms. Normalization can increase recall in search while losing useful distinctions, so it is a task-dependent choice.</p><p class=\"cue\">Stem = rules se cut; lemma = dictionary form, meaning/POS ka dhyan.</p>"},{"id":"u2-ttr","title":"Type–token ratio: three fully worked sums","html":"<p><strong>A token is one occurrence; a type is a distinct token form under the chosen normalization.</strong> In “cat cat dog”, there are three tokens and two types. Type–token ratio (TTR) measures observed lexical diversity.</p><div class=\"math-display\"><img src=\"math/83c58242dcad1838.svg\" alt=\"\\operatorname{TTR}=\\frac{\\text{number of distinct types}}{\\text{number of tokens}}.\" style=\"width:33.302ex;height:4.701ex\" loading=\"lazy\" decoding=\"async\"></div><p>A larger TTR means more distinct words relative to text length in that sample. It is strongly affected by text length and preprocessing, so comparisons should use comparable samples.</p><div class=\"example\"><p><strong>Question. Find TTR for “the cat saw the cat” after lowercasing and ignoring punctuation. Keep all words.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens [the,cat,saw,the,cat].</p><h4>To find</h4><p>Type count, token count and TTR.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/b4293b5e8a5a504c.svg\" alt=\"TTR=V/N\" style=\"width:12.8ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, where <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> counts unique forms and <span class=\"math-inline\"><img src=\"math/284cee6629b09719.svg\" alt=\"N\" style=\"width:2.009ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> counts all occurrences.</p><div class=\"step\"><h4>Step 1. Count tokens</h4><p>There are 5 positions → N=5.</p></div><div class=\"step\"><h4>Step 2. List types</h4><p>{the,cat,saw} → V=3.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p><span class=\"math-inline\"><img src=\"math/cbe1c80ba427d405.svg\" alt=\"TTR=3/5=0.6\" style=\"width:17.222ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> TTR=0.6, or 60%.</p></div><div class=\"example\"><p><strong>Question. Find TTR for “Run run RUN” before and after lowercasing.</strong></p><div class=\"given\"><h4>Given</h4><p>Before lowercasing, case distinguishes forms. There are 3 occurrences in either case.</p><h4>To find</h4><p>Two TTR values.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/b4293b5e8a5a504c.svg\" alt=\"TTR=V/N\" style=\"width:12.8ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Recount types after normalization.</p><div class=\"step\"><h4>Step 1. Before case folding</h4><p>{Run,run,RUN} has 3 types; N=3.</p></div><div class=\"step\"><h4>Step 2. First ratio</h4><p><span class=\"math-inline\"><img src=\"math/96b707212e8196a2.svg\" alt=\"3/3=1\" style=\"width:7.542ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. After case folding</h4><p>Tokens [run,run,run]; types {run} → V=1.</p></div><div class=\"step\"><h4>Step 4. Second ratio</h4><p><span class=\"math-inline\"><img src=\"math/e3565e86f7464cf8.svg\" alt=\"1/3\\approx0.333333\" style=\"width:14.958ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Before=1; after≈0.333333.</p></div><div class=\"example\"><p><strong>Question. A text has 80 tokens and 20 types. Another has 50 tokens and 25 types. Find and compare their TTRs.</strong></p><div class=\"given\"><h4>Given</h4><p>Text A: N=80,V=20. Text B: N=50,V=25.</p><h4>To find</h4><p>Both ratios.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/b4293b5e8a5a504c.svg\" alt=\"TTR=V/N\" style=\"width:12.8ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Text A</h4><p><span class=\"math-inline\"><img src=\"math/74c949323dee3d6f.svg\" alt=\"20/80=0.25\" style=\"width:12.696ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Text B</h4><p><span class=\"math-inline\"><img src=\"math/65bda32fec36f0b1.svg\" alt=\"25/50=0.5\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Interpret</h4><p>B has a larger observed type proportion, but unequal text lengths prevent treating this alone as an unbiased measure of richer language.</p></div><p class=\"answer\"><strong>Answer.</strong> A=0.25, B=0.5.</p></div><p class=\"cue\">Tokens = sab occurrences; types = unique names; TTR = unique ÷ total.</p>"}]},{"id":"u2-representation","title":"Text to numbers: label encoding, one-hot, BoW and TF–IDF","unit":2,"mode":"tee","scope":"TEE · Unit 2 PDF pages 51–92","sections":[{"id":"u2-vocab","title":"Vocabulary and vectors—what each coordinate means","html":"<p><strong>A vocabulary</strong> is the ordered collection of distinct terms allowed by a representation. Its order defines what every coordinate means. A <strong>vector</strong> is simply an ordered number-list. A <strong>document–term matrix</strong> puts one document in each row and one vocabulary term in each column.</p><p>With vocabulary [cat,dog,fish], the count vector [2,0,1] means cat appears twice, dog zero times and fish once. With [dog,cat,fish], the same text becomes [0,2,1]. A vector without its vocabulary order is incomplete.</p><table><thead><tr><th>Document</th><th>cat</th><th>dog</th><th>fish</th></tr></thead><tbody><tr><td>cat cat fish</td><td>2</td><td>0</td><td>1</td></tr><tr><td>dog fish</td><td>0</td><td>1</td><td>1</td></tr></tbody></table><p><strong>Nominal categories</strong> have no inherent order, such as cities. <strong>Ordinal categories</strong> do have an order, such as low &lt; medium &lt; high. Assigning arbitrary word IDs does not create meaningful numerical distances between words.</p><p class=\"cue\">Vector ka har box ek fixed word ka hai. Pehle column order fix, phir numbers.</p>"},{"id":"u2-label-onehot","title":"Label and one-hot encoding: three complete examples","html":"<p><strong>Label encoding</strong> assigns each category or word a unique integer ID. <strong>One-hot encoding</strong> assigns a length-<span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> vector with one 1 at the word's vocabulary position and zeros elsewhere.</p><div class=\"math-display\"><img src=\"math/47e78a40b0a5b0bd.svg\" alt=\"\\operatorname{onehot}(w)_j=\\begin{cases}1,&amp;j=\\operatorname{index}(w)\\\\0,&amp;\\text{otherwise.}\\end{cases}\" style=\"width:32.3ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div><p>The index is an ID, not a meaning score. One-hot represents one token/category; a multiword document generally needs multiple token vectors or an aggregation scheme.</p><div class=\"example\"><p><strong>Question. Encode “dog cat dog” using vocabulary [cat,dog,fish], IDs starting at 0. Give label IDs and a one-hot vector for every token.</strong></p><div class=\"given\"><h4>Given</h4><p>cat→0, dog→1, fish→2. Vector columns have the same order.</p><h4>To find</h4><p>The ID sequence and three one-hot rows.</p></div><h4>Formula and why it applies</h4><p>Replace each word by its ID for labels; set its vocabulary position to 1 for one-hot.</p><div class=\"step\"><h4>Step 1. Label IDs</h4><p>dog→1, cat→0, dog→1 → [1,0,1].</p></div><div class=\"step\"><h4>Step 2. First dog</h4><p>[0,1,0].</p></div><div class=\"step\"><h4>Step 3. Cat</h4><p>[1,0,0].</p></div><div class=\"step\"><h4>Step 4. Second dog</h4><p>[0,1,0]. Repeated tokens keep the same representation.</p></div><p class=\"answer\"><strong>Answer.</strong> IDs [1,0,1]; one-hot rows [0,1,0], [1,0,0], [0,1,0].</p></div><div class=\"example\"><p><strong>Question. Encode the city sequence Mumbai, Delhi, Mumbai, Pune using vocabulary [Delhi,Mumbai,Pune] and label IDs starting at 1.</strong></p><div class=\"given\"><h4>Given</h4><p>Delhi→1, Mumbai→2, Pune→3.</p><h4>To find</h4><p>IDs and one-hot rows.</p></div><h4>Formula and why it applies</h4><p>One-hot uses three coordinates regardless of whether label IDs begin at 0 or 1.</p><div class=\"step\"><h4>Step 1. IDs</h4><p>[2,1,2,3].</p></div><div class=\"step\"><h4>Step 2. Mumbai rows</h4><p>Each Mumbai → [0,1,0].</p></div><div class=\"step\"><h4>Step 3. Delhi and Pune</h4><p>Delhi→[1,0,0]; Pune→[0,0,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Rows [0,1,0], [1,0,0], [0,1,0], [0,0,1].</p></div><div class=\"example\"><p><strong>Question. One-hot encode categories [red,green,blue] for a linear regression with an intercept. Then give dummy coding after dropping blue.</strong></p><div class=\"given\"><h4>Given</h4><p>Full column order [red,green,blue]. Blue is the baseline.</p><h4>To find</h4><p>Full and reduced codes.</p></div><h4>Formula and why it applies</h4><p>Full one-hot rows sum to 1. With an intercept this creates a linear dependency; dropping one category column gives k−1 independent dummy indicators.</p><div class=\"step\"><h4>Step 1. Full encoding</h4><table><thead><tr><th>Category</th><th>red</th><th>green</th><th>blue</th></tr></thead><tbody><tr><td>red</td><td>1</td><td>0</td><td>0</td></tr><tr><td>green</td><td>0</td><td>1</td><td>0</td></tr><tr><td>blue</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Drop blue column</h4><table><thead><tr><th>Category</th><th>red</th><th>green</th></tr></thead><tbody><tr><td>red</td><td>1</td><td>0</td></tr><tr><td>green</td><td>0</td><td>1</td></tr><tr><td>blue</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 3. Interpret zero row</h4><p>[0,0] now identifies the baseline blue, not missing data.</p></div><p class=\"answer\"><strong>Answer.</strong> Full width 3; reduced dummy width 2. Dropping a column is model-dependent, not a requirement for every neural embedding input.</p></div><p><strong>Limitations:</strong> one-hot is large and sparse and does not express semantic similarity. Unseen words need a defined unknown-token or vocabulary-update policy. Label IDs are compact but should not be treated as an ordered scalar feature for nominal words.</p><p class=\"cue\">Label = ID number. One-hot = us ID ke box mein 1, baaki 0.</p>"},{"id":"u2-bow","title":"Bag of words and bag of n-grams","html":"<p><strong>Bag of words (BoW) represents a document by the counts of vocabulary terms, discarding their positions.</strong> A binary BoW variant stores only presence/absence; a count BoW stores frequencies. State which is used.</p><div class=\"math-display\"><img src=\"math/b587e59a2f7e4537.svg\" alt=\"x_{d,j}=C(v_j,d).\" style=\"width:14.67ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/8bfe4f4285f4b225.svg\" alt=\"x_{d,j}\" style=\"width:3.418ex;height:1.666ex\" loading=\"lazy\" decoding=\"async\"></span> is document <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>'s coordinate for vocabulary term <span class=\"math-inline\"><img src=\"math/f032d29fd7d0f0b5.svg\" alt=\"v_j\" style=\"width:1.944ex;height:1.668ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/4c241e4d8abb2427.svg\" alt=\"C(v_j,d)\" style=\"width:7.606ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span> is its occurrence count.</p><p>A <strong>bag of n-grams</strong> uses short contiguous token sequences as features. Bigrams can distinguish “not good” from “good”, but increasing n enlarges the vocabulary and creates more rare features.</p><div class=\"example\"><p><strong>Question. Build count and binary BoW for D1=“cat cat dog” and D2=“dog fish”. Use vocabulary [cat,dog,fish] and no stopword removal.</strong></p><div class=\"given\"><h4>Given</h4><p>Two tokenized documents, fixed vocabulary order.</p><h4>To find</h4><p>Count vectors and binary vectors.</p></div><h4>Formula and why it applies</h4><p>Count BoW uses <span class=\"math-inline\"><img src=\"math/4c241e4d8abb2427.svg\" alt=\"C(v_j,d)\" style=\"width:7.606ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>. Binary BoW is 1 when that count is positive and 0 otherwise.</p><div class=\"step\"><h4>Step 1. D1 counts</h4><p>cat=2, dog=1, fish=0 → [2,1,0].</p></div><div class=\"step\"><h4>Step 2. D2 counts</h4><p>cat=0, dog=1, fish=1 → [0,1,1].</p></div><div class=\"step\"><h4>Step 3. Convert to presence</h4><p>D1 [1,1,0]; D2 [0,1,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Count rows [2,1,0], [0,1,1]; binary rows [1,1,0], [0,1,1].</p></div><div class=\"example\"><p><strong>Question. After lowercasing and removing {is,a,means}, obtain BoW vectors for D1=“Continuous learning is learning lifetime”, D2=“Continuous learning means lifetime learning”, D3=“Learning is a good practice”. Use [continuous,good,learning,lifetime,practice].</strong></p><div class=\"given\"><h4>Given</h4><p>Three documents and exact stopword set from the supplied slides.</p><h4>To find</h4><p>The document–term count matrix.</p></div><h4>Formula and why it applies</h4><p>Remove only the listed stopwords, then count every remaining token in the fixed column order.</p><div class=\"step\"><h4>Step 1. Clean D1</h4><p>[continuous,learning,learning,lifetime] → [1,0,2,1,0].</p></div><div class=\"step\"><h4>Step 2. Clean D2</h4><p>[continuous,learning,lifetime,learning] → [1,0,2,1,0].</p></div><div class=\"step\"><h4>Step 3. Clean D3</h4><p>[learning,good,practice] → [0,1,1,0,1].</p></div><div class=\"step\"><h4>Step 4. Compare D1 and D2</h4><p>They have identical BoW vectors despite different original wording/order.</p></div><p class=\"answer\"><strong>Answer.</strong> Rows [1,0,2,1,0], [1,0,2,1,0], [0,1,1,0,1].</p></div><div class=\"example\"><p><strong>Question. Build a bag of bigrams for “not good but not bad” with vocabulary [not good,good but,but not,not bad]. Do not add sentence boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Five tokens; use adjacent pairs, stride 1.</p><h4>To find</h4><p>The bigram count vector.</p></div><h4>Formula and why it applies</h4><p>A sequence of <span class=\"math-inline\"><img src=\"math/c16b65225745dbd1.svg\" alt=\"L\" style=\"width:1.541ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> tokens has <span class=\"math-inline\"><img src=\"math/8c8ba2cc6117f74c.svg\" alt=\"L-1\" style=\"width:5.438ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> adjacent bigrams when no boundaries are added.</p><div class=\"step\"><h4>Step 1. Enumerate pairs</h4><p>(not,good), (good,but), (but,not), (not,bad).</p></div><div class=\"step\"><h4>Step 2. Count each vocabulary bigram</h4><p>Each appears once.</p></div><div class=\"step\"><h4>Step 3. Write vector</h4><p>[1,1,1,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Four bigram features, each with count 1.</p></div><p class=\"cue\">BoW: order bhool, word-count rakh. Bag of bigrams: neighbouring word-pair count.</p>"},{"id":"u2-tfidf","title":"TF–IDF from the exact slide convention","html":"<p><strong>TF–IDF weights a term highly when it is frequent in a particular document but uncommon across the corpus.</strong> The supplied Unit 2 slides use normalized term frequency and base-10 inverse document frequency:</p><div class=\"math-display\"><img src=\"math/deca468dd207619e.svg\" alt=\"\\operatorname{TF}(t,d)=\\frac{C(t,d)}{N_d}\" style=\"width:18.362ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/dd1eb7f26551c5f0.svg\" alt=\"\\operatorname{IDF}(t)=\\log_{10}\\frac{D}{\\operatorname{df}(t)}\" style=\"width:20.345ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c3205280fe205579.svg\" alt=\"\\operatorname{TFIDF}(t,d)=\\operatorname{TF}(t,d)\\operatorname{IDF}(t).\" style=\"width:30.386ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/716cbce384bea429.svg\" alt=\"N_d\" style=\"width:2.836ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the document's token count after the specified preprocessing; <span class=\"math-inline\"><img src=\"math/62ef1c41dad1fbc8.svg\" alt=\"D\" style=\"width:1.873ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is number of documents; <span class=\"math-inline\"><img src=\"math/92f4a76a32f5c806.svg\" alt=\"\\operatorname{df}(t)\" style=\"width:4.676ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of documents containing the term at least once. A word repeated ten times in one document contributes one to document frequency.</p><p><strong>Why the log?</strong> It compresses the ratio's scale. If a term occurs in all documents, <span class=\"math-inline\"><img src=\"math/2d65862ad68e4d56.svg\" alt=\"D/df=1\" style=\"width:9.574ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, so IDF=0 under this unsmoothed convention. Other libraries use smoothed IDF, different TF or normalization. Use the question's formula; do not silently substitute a library default.</p><div class=\"example\"><p><strong>Question. A corpus contains 10 documents. The word model appears in 2 documents and occurs 3 times in a 12-token document. Compute TF, IDF and TF–IDF using the slide convention.</strong></p><div class=\"given\"><h4>Given</h4><p>D=10, df(model)=2, C(model,d)=3, Nd=12; log base 10.</p><h4>To find</h4><p>The TF–IDF weight.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>, then multiply.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/51ccdc5dee01783f.svg\" alt=\"3/12=0.25\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Document ratio</h4><p><span class=\"math-inline\"><img src=\"math/e03ff475f4b9e538.svg\" alt=\"10/2=5\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. IDF</h4><p><span class=\"math-inline\"><img src=\"math/35a02628576f1000.svg\" alt=\"\\log_{10}5\\approx0.698970\" style=\"width:17.752ex;height:2.151ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Weight</h4><p><span class=\"math-inline\"><img src=\"math/f8ed981eba287429.svg\" alt=\"0.25\\times0.698970\\approx0.174743\" style=\"width:26.9ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> TF=0.25, IDF≈0.698970, TF–IDF≈0.174743.</p></div><div class=\"example\"><p><strong>Question. A term occurs 4 times in a 20-token document and is present in all 8 corpus documents. Calculate its TF–IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>C=4, Nd=20, D=8, df=8.</p><h4>To find</h4><p>Its weight under unsmoothed base-10 IDF.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/b0de7a9a9a0c728c.svg\" alt=\"4/20=0.2\" style=\"width:10.433ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. IDF</h4><p><span class=\"math-inline\"><img src=\"math/9a61d3220cb1a861.svg\" alt=\"\\log_{10}(8/8)=\\log_{10}1=0\" style=\"width:23.186ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/97ff1a04375e7994.svg\" alt=\"0.2\\times0=0\" style=\"width:10.937ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Weight 0: this term does not distinguish documents under this convention.</p></div><div class=\"example\"><p><strong>Question. Find TF–IDF vectors for D1=“cat cat dog”, D2=“dog fish”, D3=“cat fish fish”, using [cat,dog,fish], normalized TF and log10 IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>No further preprocessing. Each term occurs in exactly two of the three documents.</p><h4>To find</h4><p>All three vectors.</p></div><h4>Formula and why it applies</h4><p>First count df by documents, then compute each document's TF, then multiply by its term's IDF.</p><div class=\"step\"><h4>Step 1. Common IDF</h4><p><span class=\"math-inline\"><img src=\"math/a912b37fed2477fc.svg\" alt=\"D=3\" style=\"width:6.022ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/8279f303c7e95ae1.svg\" alt=\"df(cat)=df(dog)=df(fish)=2\" style=\"width:33.461ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Each IDF <span class=\"math-inline\"><img src=\"math/fdd435a4274ddcc4.svg\" alt=\"=\\log_{10}(3/2)\\approx0.176091\" style=\"width:23.786ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. D1 term frequencies</h4><p>Length 3 → <span class=\"math-inline\"><img src=\"math/33108c032f375ccc.svg\" alt=\"[2/3,1/3,0]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. D1 weights</h4><p><span class=\"math-inline\"><img src=\"math/a969ee9cc56b474e.svg\" alt=\"[(2/3)0.176091,(1/3)0.176091,0]\\approx[0.117394,0.058697,0]\" style=\"width:56.317ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. D2 weights</h4><p>Length 2; TF <span class=\"math-inline\"><img src=\"math/3a45dfb5933f8388.svg\" alt=\"[0,1/2,1/2]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/42c4ea9d39b355c1.svg\" alt=\"\\approx[0,0.088046,0.088046]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. D3 weights</h4><p>Length 3; TF <span class=\"math-inline\"><img src=\"math/b75534a4556b2589.svg\" alt=\"[1/3,0,2/3]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/f530e35b75352a92.svg\" alt=\"\\approx[0.058697,0,0.117394]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> D1≈[0.117394,0.058697,0]; D2≈[0,0.088046,0.088046]; D3≈[0.058697,0,0.117394].</p></div><p class=\"cue\">TF: iss document mein kitna. IDF: poore corpus mein kitna rare. Dono multiply.</p>"},{"id":"u2-slide-combined","title":"Combined slide numerical: TF–IDF followed by cosine","html":"<div class=\"example\"><p><strong>Question. For D1=“Continuous learning is learning lifetime”, D2=“Continuous learning means lifetime learning”, D3=“Learning is a good practice”, find the TF–IDF cosine similarity of D1 and D2. Lowercase and remove {is,a,means}. Use normalized TF and log10 IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>Vocabulary [continuous,good,learning,lifetime,practice]. D1 and D2 each have 4 retained tokens; D3 has 3.</p><h4>To find</h4><p>TF–IDF vectors and cosine(D1,D2).</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. First build the vectors; cosine cannot be applied directly to words.</p><div class=\"step\"><h4>Step 1. Count documents containing each term</h4><table><thead><tr><th>Term</th><th>df</th><th>IDF</th></tr></thead><tbody><tr><td>continuous</td><td>2</td><td>log10(3/2)≈0.176091</td></tr><tr><td>good</td><td>1</td><td>log10(3)≈0.477121</td></tr><tr><td>learning</td><td>3</td><td>log10(1)=0</td></tr><tr><td>lifetime</td><td>2</td><td>≈0.176091</td></tr><tr><td>practice</td><td>1</td><td>≈0.477121</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Term frequencies</h4><p>D1=D2=[1/4,0,2/4,1/4,0]. D3=[0,1/3,1/3,0,1/3].</p></div><div class=\"step\"><h4>Step 3. Multiply TF by IDF</h4><p>Let <span class=\"math-inline\"><img src=\"math/36558fafa06680e2.svg\" alt=\"a=\\tfrac14\\log_{10}(3/2)\\approx0.0440228\" style=\"width:28.538ex;height:2.737ex\" loading=\"lazy\" decoding=\"async\"></span>. Then D1=D2=[a,0,0,a,0]. D3≈[0,0.159040,0,0,0.159040].</p></div><div class=\"step\"><h4>Step 4. Dot product</h4><p><span class=\"math-inline\"><img src=\"math/8684c855bb57efcc.svg\" alt=\"x\\cdot y=a^2+0+0+a^2+0=2a^2\" style=\"width:32.213ex;height:2.351ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Vector lengths</h4><p><span class=\"math-inline\"><img src=\"math/bfb4b0e406e7642a.svg\" alt=\"\\|x\\|=\\|y\\|=\\sqrt{2a^2}\" style=\"width:18.207ex;height:2.834ex\" loading=\"lazy\" decoding=\"async\"></span>. Their product is <span class=\"math-inline\"><img src=\"math/eca0d1bd6ebd3288.svg\" alt=\"2a^2\" style=\"width:3.316ex;height:1.909ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 6. Divide</h4><p><span class=\"math-inline\"><img src=\"math/fea488d21ebb7221.svg\" alt=\"\\cos(x,y)=2a^2/(2a^2)=1\" style=\"width:24.884ex;height:2.452ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Cosine(D1,D2)=1. Their BoW Euclidean distance is also 0 because their counts are identical.</p></div><p>The learning coordinate becomes zero because learning occurs in every document. D1–D3 cosine is 0 under this exact TF–IDF convention: their only originally shared word was learning, whose IDF is zero. This is a consequence of the model, not proof that the sentences have unrelated meanings.</p><p class=\"cue\">Combined sum: pehle cleaned words → counts → TF-IDF → similarity. Beech ka stage skip mat kar.</p>"}]},{"id":"u2-similarity","title":"Similarity and distance: every numerical step","unit":2,"mode":"tee","scope":"Unit 2 · PDF pages 93–103","sections":[{"id":"u2-cosine","title":"Cosine: products, lengths and division","html":"<p><strong>Cosine similarity compares the direction of two nonzero vectors.</strong> Multiply matching coordinates and add to obtain the dot product. To obtain each vector's norm, square its coordinates, add them and take a square root.</p><div class=\"math-display\"><img src=\"math/c7fc299613856e1a.svg\" alt=\"\\cos(x,y)=\\frac{\\sum_i x_i y_i}{\\sqrt{\\sum_i x_i^2}\\sqrt{\\sum_i y_i^2}}.\" style=\"width:28.843ex;height:7.518ex\" loading=\"lazy\" decoding=\"async\"></div><p>The vectors must use the same coordinate/vocabulary order. For nonnegative BoW or TF–IDF vectors, the result lies from 0 to 1; for general real-valued vectors, it can range from −1 to 1. A zero vector makes this formula undefined.</p><div class=\"example\"><p><strong>Question. Find cosine similarity for x=[1,1] and y=[1,0].</strong></p><div class=\"given\"><h4>Given</h4><p>Nonzero vectors, matching coordinate order.</p><h4>To find</h4><p>Find cosine similarity for x=[1,1] and y=[1,0].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because direction similarity is required.</p><div class=\"step\"><h4>Step 1. Multiply matching coordinates</h4><p>1 × 1 = 1; 1 × 0 = 0.</p></div><div class=\"step\"><h4>Step 2. Add products</h4><p>1 + 0 = 1.</p></div><div class=\"step\"><h4>Step 3. Length of x</h4><p><span class=\"math-inline\"><img src=\"math/546bd34545f00851.svg\" alt=\"\\sqrt{(1)^2+(1)^2}=\\sqrt{2}.\" style=\"width:19.539ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 4. Length of y</h4><p><span class=\"math-inline\"><img src=\"math/300c6695721d0668.svg\" alt=\"\\sqrt{(1)^2+(0)^2}=\\sqrt{1}.\" style=\"width:19.539ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/70b251889baa0790.svg\" alt=\"\\frac{1}{\\sqrt{2}\\sqrt{1}}\\approx 0.707107.\" style=\"width:17.518ex;height:3.291ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Cosine≈0.707107.</p></div><div class=\"example\"><p><strong>Question. Find cosine similarity for x=[1,2] and y=[2,4].</strong></p><div class=\"given\"><h4>Given</h4><p>Nonzero vectors, matching coordinate order.</p><h4>To find</h4><p>Find cosine similarity for x=[1,2] and y=[2,4].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because direction similarity is required.</p><div class=\"step\"><h4>Step 1. Multiply matching coordinates</h4><p>1 × 2 = 2; 2 × 4 = 8.</p></div><div class=\"step\"><h4>Step 2. Add products</h4><p>2 + 8 = 10.</p></div><div class=\"step\"><h4>Step 3. Length of x</h4><p><span class=\"math-inline\"><img src=\"math/bd2d42d1e7a24550.svg\" alt=\"\\sqrt{(1)^2+(2)^2}=\\sqrt{5}.\" style=\"width:19.539ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 4. Length of y</h4><p><span class=\"math-inline\"><img src=\"math/e6c0085ce3b598a8.svg\" alt=\"\\sqrt{(2)^2+(4)^2}=\\sqrt{20}.\" style=\"width:20.67ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/ce85a11409a92a5a.svg\" alt=\"\\frac{10}{\\sqrt{5}\\sqrt{20}}\\approx 1.000000.\" style=\"width:18.318ex;height:3.291ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Cosine≈1.000000.</p></div><div class=\"example\"><p><strong>Question. Find cosine similarity for x=[1,2,0] and y=[0,1,2].</strong></p><div class=\"given\"><h4>Given</h4><p>Nonzero vectors, matching coordinate order.</p><h4>To find</h4><p>Find cosine similarity for x=[1,2,0] and y=[0,1,2].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because direction similarity is required.</p><div class=\"step\"><h4>Step 1. Multiply matching coordinates</h4><p>1 × 0 = 0; 2 × 1 = 2; 0 × 2 = 0.</p></div><div class=\"step\"><h4>Step 2. Add products</h4><p>0 + 2 + 0 = 2.</p></div><div class=\"step\"><h4>Step 3. Length of x</h4><p><span class=\"math-inline\"><img src=\"math/8232d196e4629829.svg\" alt=\"\\sqrt{(1)^2+(2)^2+(0)^2}=\\sqrt{5}.\" style=\"width:26.183ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 4. Length of y</h4><p><span class=\"math-inline\"><img src=\"math/7c552c58c81e3b57.svg\" alt=\"\\sqrt{(0)^2+(1)^2+(2)^2}=\\sqrt{5}.\" style=\"width:26.183ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/659dfd20c2e54394.svg\" alt=\"\\frac{2}{\\sqrt{5}\\sqrt{5}}\\approx 0.400000.\" style=\"width:17.518ex;height:3.291ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Cosine≈0.400000.</p></div><p>Proportional vectors [1,2] and [2,4] have cosine 1 but nonzero Euclidean distance. Direction similarity does not require identical magnitudes.</p><p class=\"cue\">Cosine: matching products add upar; dono lengths multiply neeche.</p>"},{"id":"u2-jaccard","title":"Jaccard: intersection, union and distance","html":"<p><strong>Jaccard similarity is the fraction of shared distinct elements among all distinct elements in either set.</strong></p><div class=\"math-display\"><img src=\"math/59eaa3e10117805d.svg\" alt=\"J(A,B)=\\frac{|A\\cap B|}{|A\\cup B|}.\" style=\"width:19.44ex;height:5.471ex\" loading=\"lazy\" decoding=\"async\"></div><p>Intersection means common elements; union means all distinct elements. Repetitions do not count again. Jaccard distance is <span class=\"math-inline\"><img src=\"math/6a1612157fb25e7c.svg\" alt=\"1-J\" style=\"width:5.329ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, not the same quantity as similarity. Two empty sets require a declared convention because the fraction becomes 0/0.</p><div class=\"example\"><p><strong>Question. Find Jaccard similarity and distance for A={cat, dog} and B={dog, fish}.</strong></p><div class=\"given\"><h4>Given</h4><p>Sets contain unique elements.</p><h4>To find</h4><p>Find Jaccard similarity and distance for A={cat, dog} and B={dog, fish}.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/ffa98f175c301d1c.svg\" alt=\"J=|A\\cap B|/|A\\cup B|\" style=\"width:19.953ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/14ba87d96baf7247.svg\" alt=\"d=1-J\" style=\"width:9.523ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Find intersection</h4><p>{dog}; count 1.</p></div><div class=\"step\"><h4>Step 2. Find union</h4><p>{cat, dog, fish}; count 3.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p>J=1/3≈0.333333.</p></div><div class=\"step\"><h4>Step 4. Subtract from one</h4><p>Distance=1−0.333333≈0.666667.</p></div><p class=\"answer\"><strong>Answer.</strong> Similarity≈0.333333; distance≈0.666667.</p></div><div class=\"example\"><p><strong>Question. Find Jaccard similarity and distance for A={red, blue} and B={red, blue}.</strong></p><div class=\"given\"><h4>Given</h4><p>Sets contain unique elements.</p><h4>To find</h4><p>Find Jaccard similarity and distance for A={red, blue} and B={red, blue}.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/ffa98f175c301d1c.svg\" alt=\"J=|A\\cap B|/|A\\cup B|\" style=\"width:19.953ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/14ba87d96baf7247.svg\" alt=\"d=1-J\" style=\"width:9.523ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Find intersection</h4><p>{red, blue}; count 2.</p></div><div class=\"step\"><h4>Step 2. Find union</h4><p>{red, blue}; count 2.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p>J=2/2≈1.000000.</p></div><div class=\"step\"><h4>Step 4. Subtract from one</h4><p>Distance=1−1.000000≈0.000000.</p></div><p class=\"answer\"><strong>Answer.</strong> Similarity≈1.000000; distance≈0.000000.</p></div><div class=\"example\"><p><strong>Question. Find Jaccard similarity and distance for A={apple} and B={orange, pear}.</strong></p><div class=\"given\"><h4>Given</h4><p>Sets contain unique elements.</p><h4>To find</h4><p>Find Jaccard similarity and distance for A={apple} and B={orange, pear}.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/ffa98f175c301d1c.svg\" alt=\"J=|A\\cap B|/|A\\cup B|\" style=\"width:19.953ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/14ba87d96baf7247.svg\" alt=\"d=1-J\" style=\"width:9.523ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Find intersection</h4><p>{}; count 0.</p></div><div class=\"step\"><h4>Step 2. Find union</h4><p>{apple, orange, pear}; count 3.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p>J=0/3≈0.000000.</p></div><div class=\"step\"><h4>Step 4. Subtract from one</h4><p>Distance=1−0.000000≈1.000000.</p></div><p class=\"answer\"><strong>Answer.</strong> Similarity≈0.000000; distance≈1.000000.</p></div><p class=\"cue\">Jaccard = common unique ÷ total unique. Distance = 1 minus similarity.</p>"},{"id":"u2-distances","title":"Manhattan, Euclidean and Minkowski: three complete comparisons","html":"<p><strong>Distance measures separation; smaller means closer.</strong> Absolute values prevent positive and negative differences from cancelling.</p><div class=\"math-display\"><img src=\"math/fe89867dfd286879.svg\" alt=\"d_1=\\sum_i|x_i-y_i|\\quad\\text{Manhattan}\" style=\"width:29.996ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/64b5f21c9b008394.svg\" alt=\"d_2=\\sqrt{\\sum_i(x_i-y_i)^2}\\quad\\text{Euclidean}\" style=\"width:32.127ex;height:5.566ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/24cfaa0ff892eddd.svg\" alt=\"d_p=\\left(\\sum_i|x_i-y_i|^p\\right)^{1/p},\\quad p\\ge1\\quad\\text{Minkowski}.\" style=\"width:45.986ex;height:7.367ex\" loading=\"lazy\" decoding=\"async\"></div><p>Manhattan is p=1; Euclidean is p=2. For p=3, cube absolute differences, add, then take a cube root.</p><div class=\"example\"><p><strong>Question. Find Manhattan, Euclidean and Minkowski p=3 distances for x=[1,2], y=[4,6].</strong></p><div class=\"given\"><h4>Given</h4><p>Vectors share coordinate order; negative inputs are allowed.</p><h4>To find</h4><p>Find Manhattan, Euclidean and Minkowski p=3 distances for x=[1,2], y=[4,6].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/52b6164a35837b22.svg\" alt=\"d_1=\\sum|\\Delta_i|\" style=\"width:11.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/182b357a15210739.svg\" alt=\"d_2=\\sqrt{\\sum|\\Delta_i|^2}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/f6e68c062a394495.svg\" alt=\"d_3=\\sqrt[3]{\\sum|\\Delta_i|^3}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Absolute differences</h4><p>|1 − (4)| = 3; |2 − (6)| = 4.</p></div><div class=\"step\"><h4>Step 2. Manhattan</h4><p>3 + 4 = 7.</p></div><div class=\"step\"><h4>Step 3. Square and add</h4><p>3²=9; 4²=16. Sum=25.</p></div><div class=\"step\"><h4>Step 4. Euclidean root</h4><p><span class=\"math-inline\"><img src=\"math/4150d3f3df4a566b.svg\" alt=\"\\sqrt{25}\\approx 5.000000.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Cube and add</h4><p>3³=27; 4³=64. Sum=91.</p></div><div class=\"step\"><h4>Step 6. Minkowski root</h4><p><span class=\"math-inline\"><img src=\"math/3a576bee1de26274.svg\" alt=\"\\sqrt[3]{91}\\approx 4.497941.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Manhattan=7; Euclidean≈5.000000; p=3≈4.497941.</p></div><div class=\"example\"><p><strong>Question. Find Manhattan, Euclidean and Minkowski p=3 distances for x=[0,1,2], y=[2,1,0].</strong></p><div class=\"given\"><h4>Given</h4><p>Vectors share coordinate order; negative inputs are allowed.</p><h4>To find</h4><p>Find Manhattan, Euclidean and Minkowski p=3 distances for x=[0,1,2], y=[2,1,0].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/52b6164a35837b22.svg\" alt=\"d_1=\\sum|\\Delta_i|\" style=\"width:11.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/182b357a15210739.svg\" alt=\"d_2=\\sqrt{\\sum|\\Delta_i|^2}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/f6e68c062a394495.svg\" alt=\"d_3=\\sqrt[3]{\\sum|\\Delta_i|^3}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Absolute differences</h4><p>|0 − (2)| = 2; |1 − (1)| = 0; |2 − (0)| = 2.</p></div><div class=\"step\"><h4>Step 2. Manhattan</h4><p>2 + 0 + 2 = 4.</p></div><div class=\"step\"><h4>Step 3. Square and add</h4><p>2²=4; 0²=0; 2²=4. Sum=8.</p></div><div class=\"step\"><h4>Step 4. Euclidean root</h4><p><span class=\"math-inline\"><img src=\"math/37625b38e47e1914.svg\" alt=\"\\sqrt{8}\\approx 2.828427.\" style=\"width:15.255ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Cube and add</h4><p>2³=8; 0³=0; 2³=8. Sum=16.</p></div><div class=\"step\"><h4>Step 6. Minkowski root</h4><p><span class=\"math-inline\"><img src=\"math/498a102c3a9a2537.svg\" alt=\"\\sqrt[3]{16}\\approx 2.519842.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Manhattan=4; Euclidean≈2.828427; p=3≈2.519842.</p></div><div class=\"example\"><p><strong>Question. Find Manhattan, Euclidean and Minkowski p=3 distances for x=[-1,3], y=[2,-1].</strong></p><div class=\"given\"><h4>Given</h4><p>Vectors share coordinate order; negative inputs are allowed.</p><h4>To find</h4><p>Find Manhattan, Euclidean and Minkowski p=3 distances for x=[-1,3], y=[2,-1].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/52b6164a35837b22.svg\" alt=\"d_1=\\sum|\\Delta_i|\" style=\"width:11.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/182b357a15210739.svg\" alt=\"d_2=\\sqrt{\\sum|\\Delta_i|^2}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/f6e68c062a394495.svg\" alt=\"d_3=\\sqrt[3]{\\sum|\\Delta_i|^3}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Absolute differences</h4><p>|-1 − (2)| = 3; |3 − (-1)| = 4.</p></div><div class=\"step\"><h4>Step 2. Manhattan</h4><p>3 + 4 = 7.</p></div><div class=\"step\"><h4>Step 3. Square and add</h4><p>3²=9; 4²=16. Sum=25.</p></div><div class=\"step\"><h4>Step 4. Euclidean root</h4><p><span class=\"math-inline\"><img src=\"math/4150d3f3df4a566b.svg\" alt=\"\\sqrt{25}\\approx 5.000000.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Cube and add</h4><p>3³=27; 4³=64. Sum=91.</p></div><div class=\"step\"><h4>Step 6. Minkowski root</h4><p><span class=\"math-inline\"><img src=\"math/3a576bee1de26274.svg\" alt=\"\\sqrt[3]{91}\\approx 4.497941.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Manhattan=7; Euclidean≈5.000000; p=3≈4.497941.</p></div><p class=\"cue\">Manhattan: absolute-add. Euclidean: square-add-root. Minkowski: p-power-add-p-root.</p>"},{"id":"u2-choice","title":"Choose the representation before the metric","html":"<table><thead><tr><th>Question</th><th>Measure</th><th>Closer means</th></tr></thead><tbody><tr><td>Compare vector direction</td><td>Cosine similarity</td><td>Higher</td></tr><tr><td>Compare term sets</td><td>Jaccard similarity</td><td>Higher</td></tr><tr><td>Straight-line separation</td><td>Euclidean distance</td><td>Lower</td></tr><tr><td>Sum coordinate changes</td><td>Manhattan distance</td><td>Lower</td></tr><tr><td>General p specified</td><td>Minkowski distance</td><td>Lower</td></tr></tbody></table><p>BoW and TF–IDF may give different similarities. First show preprocessing, vocabulary and vectors; then use the metric. Arbitrary label IDs do not define meaningful word distances. Never compare vectors using different term orders. Keep intermediate precision until the final result.</p><p class=\"cue\">Representation + metric dono question ke hisaab se. Formula pe seedha jump nahi.</p>"}]},{"id":"u3-corpora","title":"Corpora, lexical resources and data acquisition","unit":3,"mode":"tee","scope":"Unit 3 · PDF pages 1–61; pronouncing dictionary from current syllabus","sections":[{"id":"u3-corpus","title":"Corpus structure and annotations","html":"<p><strong>A corpus is a collection of language data assembled for study or computational use.</strong> Its plural is corpora. A corpus can contain books, news, reviews or conversations. It need not be labelled. <strong>Annotation</strong> adds linguistic information such as POS tags, entities, parse structures or sense labels.</p><table><thead><tr><th>Structure</th><th>Meaning</th><th>Use</th></tr></thead><tbody><tr><td>Plain</td><td>Collection without category labels</td><td>Word counts, language modelling</td></tr><tr><td>Categorized</td><td>Documents grouped by genre/topic</td><td>Classification</td></tr><tr><td>Overlapping categories</td><td>One document has several categories</td><td>Multi-topic news</td></tr><tr><td>Temporal</td><td>Documents indexed by time</td><td>Language change</td></tr><tr><td>Annotated</td><td>Linguistic labels attached</td><td>Tagging, parsing, WSD</td></tr><tr><td>Parallel</td><td>Aligned texts in different languages</td><td>Translation</td></tr></tbody></table><p>A <strong>tagset</strong> is the allowed label inventory. A <strong>treebank</strong> is a corpus annotated with syntax trees. <strong>Metadata</strong> records source, date, genre, language, annotation method and limitations. A common benchmark supports comparison under shared data and evaluation conditions.</p><p><strong>Raw example:</strong> “Riya works in Pune.” <strong>POS annotation:</strong> Riya/PROPN works/VERB in/ADP Pune/PROPN. <strong>NER annotation:</strong> Riya/PERSON, Pune/LOCATION. Each annotation answers a different task.</p><p>A good corpus is relevant to its domain, sufficiently representative, consistently annotated and appropriately split. More data alone do not repair duplicated examples, incorrect labels or a mismatch between training and real use.</p><p class=\"cue\">Corpus=text collection. Annotation=text ke saath labels. Metadata=collection ki information.</p>"},{"id":"u3-types","title":"Gutenberg, web/chat, Brown, Reuters and Inaugural","html":"<table><thead><tr><th>Resource</th><th>Contents</th><th>Typical use</th></tr></thead><tbody><tr><td>Gutenberg selection</td><td>Literary/book texts</td><td>Long-form language and vocabulary</td></tr><tr><td>Web text</td><td>Informal domain-specific text</td><td>Study usage beyond edited books</td></tr><tr><td>Chat corpus</td><td>Conversational posts</td><td>Dialogue, informal forms</td></tr><tr><td>Brown</td><td>English texts across genres</td><td>Genre comparison</td></tr><tr><td>Reuters</td><td>News with topic labels</td><td>Text classification; overlapping topics</td></tr><tr><td>Inaugural</td><td>Speeches indexed by time</td><td>Vocabulary change across years</td></tr><tr><td>Wordlist</td><td>Words/names/stopwords</td><td>Lexical filtering</td></tr><tr><td>Pronouncing dictionary</td><td>Words and phonetic forms</td><td>Speech, stress, rhyme</td></tr></tbody></table><p><strong>Gutenberg versus web/chat:</strong> book language does not represent every spelling or conversational pattern in messages. <strong>Brown versus Reuters:</strong> Brown emphasizes genres; Reuters news can have overlapping topic labels. <strong>Inaugural addresses:</strong> dates provide a time dimension.</p><p>Corpus sizes depend on version, subset and tokenization. Explain their purpose and structure rather than assuming a historical count is a permanent property.</p><p class=\"cue\">Gutenberg=books; web/chat=informal; Brown=genres; Reuters=news topics; Inaugural=time.</p>"},{"id":"u3-access","title":"Raw text, tokens and sentences are different views","html":"<p>Corpus readers expose several views. <strong>raw</strong> returns a character string, <strong>words</strong> returns token occurrences, and <strong>sents</strong> returns a list of sentences where each sentence contains tokens.</p><table><thead><tr><th>Conceptual method</th><th>Returned view</th><th>Its length counts</th></tr></thead><tbody><tr><td>fileids()</td><td>Document IDs</td><td>Files</td></tr><tr><td>raw(fileid)</td><td>Character string</td><td>Characters</td></tr><tr><td>words(fileid)</td><td>Token list</td><td>Token occurrences</td></tr><tr><td>sents(fileid)</td><td>Sentence lists</td><td>Sentences</td></tr><tr><td>categories()</td><td>Genre/topic labels</td><td>Categories</td></tr><tr><td>tagged_words(fileid)</td><td>Word–tag pairs</td><td>Annotated tokens</td></tr></tbody></table><div class=\"example\"><p><strong>Question. For sentence lists [the,cat,sleeps,.] and [the,dog,runs,.], count all tokens, sentences and lowercase alphabetic word types.</strong></p><div class=\"given\"><h4>Given</h4><p>Punctuation is included in token count but excluded from word types.</p><h4>To find</h4><p>For sentence lists [the,cat,sleeps,.] and [the,dog,runs,.], count all tokens, sentences and lowercase alphabetic word types.</p></div><h4>Formula and why it applies</h4><p>Count every token occurrence, then distinct alphabetic forms. Different counting rules give different totals.</p><div class=\"step\"><h4>Step 1. Token count</h4><p>4+4=8.</p></div><div class=\"step\"><h4>Step 2. Sentence count</h4><p>Two outer lists → 2.</p></div><div class=\"step\"><h4>Step 3. Types</h4><p>{the,cat,sleeps,dog,runs} → 5.</p></div><p class=\"answer\"><strong>Answer.</strong> 8 tokens, 2 sentences, 5 word types.</p></div><p>For “Cats run. Dogs sleep.”, a reader may return six tokens including two periods, but only four alphabetic word tokens. State the convention before calculating TTR or probabilities.</p><p class=\"cue\">raw=characters, words=tokens, sents=sentences. Teen alag counts.</p>"},{"id":"u3-resources","title":"Wordlists, pronunciation and semantic resources","html":"<p><strong>A wordlist</strong> stores lexical entries without necessarily giving usage context. A stopword list gives task-specific filtering terms. Names lists can support lexical analysis but cannot reliably infer a real person's identity or gender.</p><p><strong>A pronouncing dictionary</strong> maps a written word to one or more phonetic symbol sequences. CMU-style dictionaries use ARPAbet; vowel stress suffixes distinguish unstressed, primary-stressed and secondary-stressed vowels. A spelling can have more than one pronunciation, as “read” does.</p><table><thead><tr><th>Question</th><th>Resource</th><th>Reason</th></tr></thead><tbody><tr><td>Which words rhyme with night?</td><td>Pronouncing dictionary</td><td>Compare sounds, not just spelling</td></tr><tr><td>Which terms should be filtered?</td><td>Specified stopword list</td><td>Apply task's filtering convention</td></tr><tr><td>What broader concept includes car?</td><td>WordNet</td><td>Follow hypernym relation</td></tr><tr><td>How frequently does car occur?</td><td>Text corpus</td><td>Count actual usage occurrences</td></tr></tbody></table><p><strong>WordNet</strong> groups word senses in synsets, supplies glosses and connects meanings by semantic relations. Its full treatment is in Unit 5. A corpus supplies usage evidence; a lexical resource supplies organized knowledge. A system can combine both.</p><p class=\"cue\">Sound→pronouncing dictionary. Meaning→WordNet. Occurrence→corpus.</p>"},{"id":"u3-acquisition","title":"Acquiring data and preserving labels during augmentation","html":"<p><strong>Data acquisition</strong> obtains language examples relevant to the task from existing data, public resources or appropriate new collection. Product instrumentation can gather useful feedback. Supervised learning additionally needs an annotation process when labels are absent.</p><p><strong>Data augmentation</strong> creates training variants intended to preserve the correct label. It is not simply changing words arbitrarily.</p><table><thead><tr><th>Method</th><th>Procedure</th><th>Caution</th></tr></thead><tbody><tr><td>Synonym replacement</td><td>Use suitable synonyms for selected words</td><td>Choose the right sense</td></tr><tr><td>Back translation</td><td>Translate to another language and back</td><td>May change meanings/entities</td></tr><tr><td>TF–IDF-informed replacement</td><td>Protect informative words while varying others</td><td>Do not remove label-bearing clues</td></tr><tr><td>Bigram flipping</td><td>Swap adjacent words</td><td>Can break grammar or meaning</td></tr><tr><td>Entity replacement</td><td>Replace by same-type entity</td><td>Must preserve the task label</td></tr><tr><td>Noise injection</td><td>Simulate typos/keyboard errors</td><td>Match expected noise</td></tr><tr><td>Active learning</td><td>Select informative cases for human labels</td><td>This acquires labels; it is not synthetic text</td></tr></tbody></table><h3>Three label decisions</h3><p>“The film is good”→“The film is excellent” may preserve a positive sentiment label. “The film is not good”→“The film is good” reverses the label and is not valid label-preserving augmentation. “Flights to Pune”→“Flights to Mumbai” may preserve a travel-topic label but changes the destination label.</p><p>Split train/test data before creating related augmented variants. Otherwise near-duplicates can leak between sets and produce misleading evaluation. Keep a representative evaluation set of genuine examples.</p><p class=\"cue\">Sentence badal sakta hai; required correct label nahi. Label badla toh augmentation invalid.</p>"},{"id":"u3-links","title":"How corpus evidence powers later units","html":"<p>Word-sequence counts support n-gram language models and smoothing. POS-annotated sentences support supervised taggers. Sense-labelled contexts support Naive Bayes WSD. Word-context counts support distributional semantics and GloVe. Parallel aligned sentences support translation.</p><p>For a question asking the importance of corpora, give three points: empirical language evidence, examples for training/evaluation, and reproducible comparison. For an annotated-corpus question, define the added labels and give a concrete example. For resource comparisons, distinguish running text, lexical lists, pronunciation entries and semantic relations.</p><p class=\"cue\">Same text se task ke hisaab se counts, tags, senses ya context patterns nikaalte hain.</p>"}]},{"id":"u3-regex","title":"Regular expressions: read, build and test text patterns","unit":3,"mode":"tee","scope":"TEE · current Unit 3 syllabus and supplied Regular Expressions handout; outside confirmed M2 page cutoff","sections":[{"id":"regex-language","title":"Characters, classes, anchors and repetition","html":"<p><strong>A regular expression (regex) is a pattern language for specifying classes of text strings.</strong> A regex engine tests or finds strings matching a pattern. It can extract numbers, locate words, clean text and implement rule-based NLP features. A match is a string satisfying the pattern; it is not an interpretation of the string's meaning.</p><p>Start with a literal: <code>cat</code> matches those three consecutive letters. Without boundary constraints it also matches the cat part inside “catalog” or “wildcat”. Add restrictions only when the question asks for them.</p><table><thead><tr><th>Pattern</th><th>Meaning</th><th>Example</th></tr></thead><tbody><tr><td><code>[aeiou]</code></td><td>Exactly one listed lowercase vowel</td><td>a, e; not b</td></tr><tr><td><code>[A-Z]</code></td><td>One uppercase ASCII letter</td><td>A through Z</td></tr><tr><td><code>[^0-9]</code></td><td>One character not in the digit range</td><td>a or a space; not 5</td></tr><tr><td><code>\\d</code></td><td>One digit under the regex engine's character rules</td><td>Use [0-9] if only ASCII digits are intended</td></tr><tr><td><code>\\w</code></td><td>Word character, usually letters/digits/underscore</td><td>Unicode details depend on engine</td></tr><tr><td><code>\\s</code></td><td>Whitespace character</td><td>Space, tab, newline</td></tr><tr><td><code>\\D, \\W, \\S</code></td><td>Complement classes</td><td>Non-digit, non-word, non-whitespace</td></tr><tr><td><code>.</code></td><td>One arbitrary character except newline by default</td><td>DOTALL flag can include newlines</td></tr><tr><td><code>\\.</code></td><td>Literal full stop</td><td>Escaping removes the wildcard meaning</td></tr><tr><td><code>^</code></td><td>Start of string/line depending on mode</td><td>^The</td></tr><tr><td><code>$</code></td><td>End anchor under the engine's rules</td><td>Spain$</td></tr><tr><td><code>\\b</code></td><td>Boundary between word and non-word positions</td><td>Whole-word matching</td></tr><tr><td><code>*</code></td><td>Zero or more repetitions of previous item</td><td>ab* matches a, ab, abb</td></tr><tr><td><code>+</code></td><td>One or more</td><td>ab+ requires at least one b</td></tr><tr><td><code>?</code></td><td>Zero or one</td><td>colou?r allows color and colour</td></tr><tr><td><code>{m}, {m,n}, {m,}</code></td><td>Exact, bounded or minimum repetitions</td><td>[0-9]{3}</td></tr><tr><td><code>(...)</code></td><td>Group a sequence</td><td>(ab)+ repeats the pair</td></tr><tr><td><code>|</code></td><td>Choose an alternative</td><td>cat|dog</td></tr></tbody></table><p><strong>Critical distinction:</strong> a character class chooses one character, whereas alternatives can choose whole strings. <code>[cat]</code> matches one c, a or t; <code>(cat|dog)</code> matches either complete word.</p><p>A quantifier acts on the immediately preceding atom/group. <code>abc*</code> means ab followed by any number of c; <code>(abc)*</code> repeats the entire abc group.</p><p class=\"cue\">Regex left-to-right padho: kaunsa character, kitni baar, aur start/end/word boundary kya hai?</p>"},{"id":"regex-functions","title":"Search, match, fullmatch, findall, substitution and flags","html":"<table><thead><tr><th>Python operation</th><th>What it does</th><th>Typical use</th></tr></thead><tbody><tr><td>re.search(pattern,text)</td><td>Finds the first match anywhere</td><td>Locate a clue inside a sentence</td></tr><tr><td>re.match(pattern,text)</td><td>Tests only from the start</td><td>Check a prefix</td></tr><tr><td>re.fullmatch(pattern,text)</td><td>Requires the complete string to match</td><td>Validate an exact format</td></tr><tr><td>re.findall(pattern,text)</td><td>Returns non-overlapping matches</td><td>Extract all numbers</td></tr><tr><td>re.finditer(pattern,text)</td><td>Returns match objects with spans</td><td>Locate match positions</td></tr><tr><td>re.sub(pattern,replacement,text)</td><td>Replaces matches</td><td>Normalize repeated whitespace</td></tr><tr><td>re.split(pattern,text)</td><td>Splits at matches</td><td>Custom token boundaries</td></tr></tbody></table><p>Python raw strings such as <code>r\"\\bcat\\b\"</code> keep the backslashes for the regex engine. In an ordinary Python string, <code>\\b</code> is a backspace escape, so using a raw string prevents a common mistake. Capturing groups can change what <code>findall</code> returns; use a noncapturing group <code>(?:...)</code> when grouping is needed but capturing is not.</p><h3>Flags and engine differences</h3><p><strong>IGNORECASE / i</strong> ignores case. <strong>MULTILINE / m</strong> lets ^ and $ refer to line boundaries. <strong>DOTALL / s</strong> lets dot match newline. JavaScript's <strong>g</strong> flag requests repeated/global matching; Python has no separate global flag for <code>findall</code>, which already finds successive non-overlapping matches. Do not mix JavaScript slash delimiters with Python's string syntax.</p><h3>Greedy versus lazy quantifiers</h3><p>A greedy quantifier tries to consume as much as possible while permitting the whole match; a lazy quantifier tries as little as possible. On <code>&lt;b&gt;one&lt;/b&gt;&lt;b&gt;two&lt;/b&gt;</code>, <code>&lt;.*&gt;</code> can match the entire string from the first &lt; to last &gt;. The lazy <code>&lt;.*?&gt;</code> returns shorter tag-shaped matches during repeated matching. Regex is useful for restricted patterns; robust arbitrary HTML processing should use an HTML parser.</p><p class=\"cue\">search=kahin bhi; match=start se; fullmatch=poora text; findall=sab matches. Greedy zyada, lazy kam.</p>"},{"id":"regex-worked","title":"Six full regex questions and solutions","html":"<div class=\"example\"><p><strong>Question. From “cat catalog wildcat Cat”, extract only the lowercase whole word cat using Python regex.</strong></p><div class=\"given\"><h4>Given</h4><p>Case-sensitive matching; whole words only.</p><h4>To find</h4><p>A pattern and its matches.</p></div><h4>Rule and why it applies</h4><p>Use <code>\\b</code> boundaries around the literal word. This prevents substring matches inside longer word tokens.</p><div class=\"step\"><h4>Step 1. Write the literal</h4><p><code>cat</code> alone would also match catalog and wildcat.</p></div><div class=\"step\"><h4>Step 2. Add both word boundaries</h4><p><code>r\"\\bcat\\b\"</code>.</p></div><div class=\"step\"><h4>Step 3. Check candidates</h4><p>cat matches. catalog fails at the ending boundary. wildcat fails at the starting boundary. Cat fails because matching is case sensitive.</p></div><div class=\"step\"><h4>Step 4. Extract</h4><p><code>re.findall(r\"\\bcat\\b\", text)</code> returns <code>[\"cat\"]</code>.</p></div><p class=\"answer\"><strong>Answer.</strong> Pattern <code>\\bcat\\b</code>; one match: cat. With IGNORECASE, Cat would also match.</p></div><div class=\"example\"><p><strong>Question. Write a regex that validates exactly ten ASCII digits, then test 9876543210, 98765 and A9876543210.</strong></p><div class=\"given\"><h4>Given</h4><p>No country-prefix restriction; digits only; entire input must match.</p><h4>To find</h4><p>A validation pattern and each result.</p></div><h4>Rule and why it applies</h4><p><code>[0-9]</code> permits one ASCII digit; <code>{10}</code> repeats it exactly ten times; fullmatch prevents extra characters.</p><div class=\"step\"><h4>Step 1. Choose the character class</h4><p><code>[0-9]</code>.</p></div><div class=\"step\"><h4>Step 2. Specify exact length</h4><p><code>[0-9]{10}</code>.</p></div><div class=\"step\"><h4>Step 3. Require the whole input</h4><p><code>re.fullmatch(r\"[0-9]{10}\", text)</code>. In a simple single-line exam pattern, <code>^[0-9]{10}$</code> expresses the intended format.</p></div><div class=\"step\"><h4>Step 4. Test all examples</h4><p>9876543210: 10 digits → valid. 98765: only 5 → invalid. A9876543210: contains an extra letter → invalid.</p></div><p class=\"answer\"><strong>Answer.</strong> Use fullmatch with <code>[0-9]{10}</code>. Only 9876543210 passes. This checks format, not whether a phone number exists.</p></div><div class=\"example\"><p><strong>Question. Extract date-shaped strings in DD/MM/YYYY format from “On 05/10/2026 and 7/10/2026 we met.” Require two digits for day and month and four for year.</strong></p><div class=\"given\"><h4>Given</h4><p>Format recognition only; no calendar-validity test.</p><h4>To find</h4><p>Pattern and extracted strings.</p></div><h4>Rule and why it applies</h4><p>Use fixed repetition counts separated by literal slashes, and boundaries around the full pattern.</p><div class=\"step\"><h4>Step 1. Day part</h4><p><code>[0-9]{2}</code>.</p></div><div class=\"step\"><h4>Step 2. Month and year</h4><p><code>[0-9]{2}/[0-9]{2}/[0-9]{4}</code>.</p></div><div class=\"step\"><h4>Step 3. Add boundaries</h4><p><code>r\"\\b[0-9]{2}/[0-9]{2}/[0-9]{4}\\b\"</code>.</p></div><div class=\"step\"><h4>Step 4. Evaluate the two candidates</h4><p>05/10/2026 has 2/2/4 digits and matches. 7/10/2026 has a one-digit day and fails.</p></div><p class=\"answer\"><strong>Answer.</strong> Only 05/10/2026 is extracted. A date such as 99/99/2026 has the right shape but needs a calendar parser to reject it semantically.</p></div><div class=\"example\"><p><strong>Question. Use a regex to check a simple email shape: one or more username characters from letters, digits, dot, underscore, percent, plus or hyphen; @; a domain of letters, digits, dots or hyphens; a literal dot; a letter-only suffix of length at least two.</strong></p><div class=\"given\"><h4>Given</h4><p>This is the simplified handout format, not full standards-compliant validation.</p><h4>To find</h4><p>The pattern and an explanation of every part.</p></div><h4>Rule and why it applies</h4><p>Build the requested components and use fullmatch so no extra prefix or suffix is accepted.</p><div class=\"step\"><h4>Step 1. Username</h4><p><code>[A-Za-z0-9._%+-]+</code>: one or more allowed username characters. The hyphen is last, so it is literal.</p></div><div class=\"step\"><h4>Step 2. Separator and domain</h4><p><code>@[A-Za-z0-9.-]+</code>: literal @ followed by domain characters.</p></div><div class=\"step\"><h4>Step 3. Suffix</h4><p><code>\\.[A-Za-z]{2,}</code>: escaped dot, then at least two letters.</p></div><div class=\"step\"><h4>Step 4. Combine and test</h4><p><code>re.fullmatch(r\"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\", text)</code>. <code>riya+nlp@example.com</code> matches; <code>riya.example.com</code> lacks @ and fails.</p></div><p class=\"answer\"><strong>Answer.</strong> The combined pattern meets the stated classroom shape. It neither proves address existence nor enforces every real email/domain constraint.</p></div><div class=\"example\"><p><strong>Question. For text “The rain in Spain”, write patterns that test starts with The, ends with Spain, and satisfies both.</strong></p><div class=\"given\"><h4>Given</h4><p>Single-line, case-sensitive text.</p><h4>To find</h4><p>Three patterns and outcomes.</p></div><h4>Rule and why it applies</h4><p>Use ^ for beginning, $ for ending, and .* for the intervening sequence in this simple one-line task.</p><div class=\"step\"><h4>Step 1. Starts with</h4><p><code>^The</code> succeeds.</p></div><div class=\"step\"><h4>Step 2. Ends with</h4><p><code>Spain$</code> succeeds.</p></div><div class=\"step\"><h4>Step 3. Both</h4><p><code>^The.*Spain$</code> succeeds because the text begins with The and ends with Spain.</p></div><div class=\"step\"><h4>Step 4. Why dot-star?</h4><p><code>.</code> consumes one intervening character; <code>*</code> allows zero or more, including spaces here.</p></div><p class=\"answer\"><strong>Answer.</strong> All three checks succeed. Without anchors a substring match alone would not enforce the required position.</p></div><div class=\"example\"><p><strong>Question. Construct a case-sensitive pattern for full filenames ending in .jpg or .png and test photo.jpg, chart.png and photo.jpg.exe.</strong></p><div class=\"given\"><h4>Given</h4><p>Filename must have at least one character before the dot. Treat the filename as a single line.</p><h4>To find</h4><p>Pattern and three results.</p></div><h4>Rule and why it applies</h4><p>Use a noncapturing alternative for the two complete suffixes and fullmatch to disallow trailing text.</p><div class=\"step\"><h4>Step 1. Filename stem</h4><p><code>.+</code> requires one or more characters.</p></div><div class=\"step\"><h4>Step 2. Literal dot</h4><p><code>\\.</code>.</p></div><div class=\"step\"><h4>Step 3. Choose suffix</h4><p><code>(?:jpg|png)</code> chooses jpg or png.</p></div><div class=\"step\"><h4>Step 4. Full match and test</h4><p><code>re.fullmatch(r\".+\\.(?:jpg|png)\", filename)</code>. photo.jpg passes; chart.png passes; photo.jpg.exe fails.</p></div><p class=\"answer\"><strong>Answer.</strong> Full pattern <code>.+\\.(?:jpg|png)</code>; use IGNORECASE only if uppercase extensions should also be accepted.</p></div><p class=\"cue\">Pattern likhke ek valid, ek short/wrong, ek extra-character case zaroor mentally run karo.</p>"},{"id":"regex-reference","title":"Pattern reference for the handout's remaining tasks","html":"<table><thead><tr><th>Task</th><th>Pattern / operation</th><th>Read it correctly</th></tr></thead><tbody><tr><td>Extract hashtags</td><td><code>#[A-Za-z0-9_]+</code></td><td># followed by one or more permitted tag characters</td></tr><tr><td>Extract integer sequences</td><td><code>[0-9]+</code></td><td>Does not include decimal dots or signs</td></tr><tr><td>Extract words ending ing</td><td><code>\\b[A-Za-z]*ing\\b</code></td><td>Zero or more prefix letters, then ing</td></tr><tr><td>Currency amounts, simple integers</td><td><code>[$₹][0-9]+</code></td><td>One currency symbol followed by digits; decimals need extension</td></tr><tr><td>Words containing exact uppercase AI</td><td><code>\\b[A-Za-z]*AI[A-Za-z]*\\b</code></td><td>Case-sensitive; letters before/after may be absent</td></tr><tr><td>Capital-initial alphabetic words</td><td><code>\\b[A-Z][A-Za-z]*\\b</code></td><td>One capital then zero or more letters</td></tr><tr><td>Extract mentions</td><td><code>@[A-Za-z0-9_]+</code></td><td>Simple username rule, not any platform's complete policy</td></tr><tr><td>Exactly five-letter words</td><td><code>\\b[A-Za-z]{5}\\b</code></td><td>Word boundaries plus exact length</td></tr><tr><td>Starts N and ends P</td><td><code>\\bN[A-Za-z]*P\\b</code></td><td>NP itself is allowed; require + to demand middle letters</td></tr><tr><td>Alphabetic words only</td><td><code>\\b[A-Za-z]+\\b</code></td><td>ASCII letter-only token matches</td></tr><tr><td>Basic http/https URL extraction</td><td><code>https?://[^\\s&lt;&gt;]+</code></td><td>Matches a URL-shaped span; trailing punctuation may need removal</td></tr><tr><td>Collapse whitespace</td><td><code>re.sub(r\"\\s+\", \" \", text)</code></td><td>Replace each whitespace run with one space</td></tr></tbody></table><h3>IPv4 addresses: shape versus numeric validity</h3><p><code>(?:[0-9]{1,3}\\.){3}[0-9]{1,3}</code> recognizes four dotted digit groups, but permits 999.999.999.999. For numeric octets 0–255 without leading zeros, define one octet as <code>(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])</code>, join four with escaped dots, and require fullmatch. An IP-address parser is clearer for production validation.</p><p><strong>Limits:</strong> regex recognizes surface patterns; it cannot infer the intended sense of bank, establish a person's identity from capitalization, or decide arbitrary grammatical meaning. A date/email/URL-shaped match is not automatically a valid or real-world existing item.</p><p class=\"cue\">Regex shape verify karta hai; real meaning/existence ke liye extra logic lagta hai.</p>"}]},{"id":"m2-language-models","title":"N-grams and language models","unit":3,"scope":"Unit 3, pages 62–108; essential probability revision","sections":[{"id":"words-counts-probability","title":"Words, counts and probabilities: the notation you need","html":"<p><strong>A token</strong> is one occurrence of a word. A <strong>type</strong> is one distinct word. A <strong>corpus</strong> is a collection of texts used for analysis or training. In “cats chase cats”, there are three word tokens but only two word types: cats and chase. A language model learns regularities from such a corpus to assign probabilities to word sequences. It does not simply count whether a sentence is grammatically correct.</p><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Read it as</th><th>Concrete meaning</th></tr></thead><tbody><tr><td>C(cat)</td><td>count of cat</td><td>Number of times cat occurs.</td></tr><tr><td>C(the, cat)</td><td>count of the followed by cat</td><td>Count adjacent ordered pairs; cat the is different.</td></tr><tr><td>P(cat)</td><td>probability of cat</td><td>A number from 0 to 1.</td></tr><tr><td>P(cat | the)</td><td>probability of cat given the</td><td>Among contexts ending in the, how often cat follows.</td></tr><tr><td>V</td><td>vocabulary size</td><td>Number of distinct outcomes the model may predict.</td></tr><tr><td>N</td><td>number of tokens or predictions</td><td>Its exact meaning must be stated for the calculation.</td></tr></tbody></table></div><p>The vertical bar <strong>| means “given”</strong>. The condition is on its right. In P(cat | the), the model has already seen “the” and is predicting “cat”. This direction matters: P(cat | the) and P(the | cat) usually have different denominators.</p><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains 20 word tokens. The word cat occurs 5 times. Find the maximum-likelihood unigram probability of cat.</strong></p><div class=\"given\"><h4>Given</h4><p>Total tokens N = 20; count C(cat) = 5.</p><h4>To find</h4><p>P(cat).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2711f5706c9dc86b.svg\" alt=\"P(w)=\\frac{C(w)}{N}\" style=\"width:14.191ex;height:4.855ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Relative frequency estimates the probability of drawing this word from the corpus. The denominator includes every token, not just distinct words.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Select the matching count</h5><p>The required outcome is cat, which occurs 5 times.</p></div><div class=\"step\"><h5>Step 2. Divide by the total number of trials</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4e5251cd8736de84.svg\" alt=\"P(\\text{cat})=\\frac{5}{20}=0.25\" style=\"width:19.79ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Interpret the result</h5><p>Under this unigram model, cat receives probability 0.25, or 25%.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(cat) = 0.25.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Jo chahiye uska count upar; total possible trials neeche.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. The word the has 10 outgoing occurrences in a corpus. It is followed by cat on 4 occasions and dog on 6. Find P(cat | the) and P(dog | the).</strong></p><div class=\"given\"><h4>Given</h4><p>C(the, cat) = 4; C(the, dog) = 6; C(the) = 10 outgoing contexts.</p><h4>To find</h4><p>Both next-word probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1f5e1649537aa36.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{C(h)}\" style=\"width:19.69ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The condition h = the restricts attention to its 10 continuations. We do not divide by the total corpus size.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Use the cat continuation</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3bf149513726477a.svg\" alt=\"P(\\text{cat}\\mid\\text{the})=\\frac{4}{10}=0.4\" style=\"width:23.687ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the dog continuation</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75de664b10c4bbcd.svg\" alt=\"P(\\text{dog}\\mid\\text{the})=\\frac{6}{10}=0.6\" style=\"width:24.192ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Check the complete row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b7387cc7f2626c50.svg\" alt=\"0.4+0.6=1\" style=\"width:12.697ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(cat | the) = 0.4 and P(dog | the) = 0.6.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Given waala word denominator choose karata hai.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. A collection has 8 sentences; 6 start with I and 2 start with we. Estimate each starting-word probability.</strong></p><div class=\"given\"><h4>Given</h4><p>Each sentence receives a start marker &lt;s&gt;. C(&lt;s&gt;) = 8; C(&lt;s&gt;, I) = 6; C(&lt;s&gt;, we) = 2.</p><h4>To find</h4><p>P(I | &lt;s&gt;) and P(we | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d997b6731cad785.svg\" alt=\"P(w_1\\mid\\langle s\\rangle)=\\frac{C(\\langle s\\rangle,w_1)}{C(\\langle s\\rangle)}\" style=\"width:24.701ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The start marker supplies the context for the first word; one start context is available per sentence.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate the first option</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f61ebf6be6e02d19.svg\" alt=\"P(I\\mid\\langle s\\rangle)=6/8=0.75\" style=\"width:22.757ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the second option</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e61e15f5786a3aaa.svg\" alt=\"P(we\\mid\\langle s\\rangle)=2/8=0.25\" style=\"width:24.291ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The estimated probabilities are 0.75 and 0.25.</div></section>"},{"id":"n-grams-construction","title":"Unigrams, bigrams and trigrams: construct them correctly","html":"<p><strong>Definition.</strong> An n-gram is a contiguous sequence of n items. For word n-grams, the items are consecutive word tokens. A unigram contains one word; a bigram contains two; a trigram contains three. Character n-grams use characters instead, so always identify the unit being counted.</p><div class=\"flow\"><div class=\"node\">Tokens: we | study | natural | language</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Move a window one token at a time</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Bigrams: we study / study natural / natural language</div></div><p>For m tokens without padding, the number of n-gram <em>positions</em> is max(0, m−n+1). Repeated positions may contain the same n-gram type. A bag-of-n-grams representation counts each n-gram type and loses the overall sentence order beyond the local order inside each n-gram.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9097807b6ad98d38.svg\" alt=\"\\text{Number of unpadded n-gram positions}=\\max(0,m-n+1)\" style=\"width:58.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. List all word unigrams, bigrams and trigrams for “the prime minister of our country”. Do not add boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Six tokens: the, prime, minister, of, our, country. n = 1, 2 and 3.</p><h4>To find</h4><p>All three lists and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad44404e3f41cdd.svg\" alt=\"\\#\\text{positions}=m-n+1\" style=\"width:23.607ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each window must contain consecutive words and move one position. No wraparound or invented final word is allowed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take one word at a time</h5><p>Unigrams: (the), (prime), (minister), (of), (our), (country). Count = 6−1+1 = 6.</p></div><div class=\"step\"><h5>Step 2. Take two consecutive words</h5><p>Bigrams: (the, prime), (prime, minister), (minister, of), (of, our), (our, country). Count = 6−2+1 = 5.</p></div><div class=\"step\"><h5>Step 3. Take three consecutive words</h5><p>Trigrams: (the, prime, minister), (prime, minister, of), (minister, of, our), (of, our, country). Count = 6−3+1 = 4.</p></div><div class=\"answer\"><strong>Final answer.</strong> 6 unigrams, 5 bigrams and 4 trigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct bigrams for “I like tea” using one start and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original tokens: I, like, tea. Add &lt;s&gt; and &lt;/s&gt; once each.</p><h4>To find</h4><p>The boundary-aware bigram sequence.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1b167f71a6a973b4.svg\" alt=\"\\#\\text{bigrams}=(m+2)-1=m+1\" style=\"width:33.155ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The start context predicts the first word, and the last word predicts that the sentence ends.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write the padded sequence</h5><p>&lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Move a two-token window</h5><p>(&lt;s&gt;, I), (I, like), (like, tea), (tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count the windows</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c37463b701447787.svg\" alt=\"3+1=4\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> There are four boundary-aware bigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct trigrams for “I like tea” using two start markers and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original sentence has three words. For a trigram model each predicted token needs two prior context tokens.</p><h4>To find</h4><p>All trigram prediction events.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/12c99aed7b535ad6.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:17.519ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Two start markers provide a complete context even for the first word.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Pad with two starts</h5><p>&lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Slide a three-token window</h5><p>(&lt;s&gt;, &lt;s&gt;, I), (&lt;s&gt;, I, like), (I, like, tea), (like, tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count predicted events</h5><p>The model predicts I, like, tea and the end marker: four predictions.</p></div><div class=\"answer\"><strong>Final answer.</strong> Four trigrams. Start markers are context; they are not ordinary predicted words.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Give the bag-of-bigrams counts for “a b a b” without padding.</strong></p><div class=\"given\"><h4>Given</h4><p>Four tokens in their given order.</p><h4>To find</h4><p>Bigram positions, distinct bigram types and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8326144ada817e2c.svg\" alt=\"\\#\\text{positions}=4-2+1=3\" style=\"width:26.674ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A bag stores frequencies; repeated bigrams must not be discarded.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Enumerate all positions</h5><p>(a,b), (b,a), (a,b).</p></div><div class=\"step\"><h5>Step 2. Group identical pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Bigram type</th><th>Count</th></tr></thead><tbody><tr><td>a b</td><td>2</td></tr><tr><td>b a</td><td>1</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> Three bigram positions but two distinct bigram types.</div><p class=\"cue\"><strong>Yaad rakho:</strong> n-gram mein n words; context mein n−1 words.</p></section>"},{"id":"collocations-and-lm","title":"Collocations and the purpose of a language model","html":"<p><strong>A collocation</strong> is a conventional word combination whose words occur together more strongly than ordinary chance or independent frequencies would suggest. Examples include “strong tea”, “heavy rain” and “red wine”. A bigram is merely two consecutive items; it need not be a collocation. “of the” can be frequent because both words are frequent, while a collocation expresses a particularly strong association.</p><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>What it represents</th><th>Example</th></tr></thead><tbody><tr><td>Bigram</td><td>Any adjacent two-token sequence</td><td>the book</td></tr><tr><td>Collocation</td><td>A characteristic strongly associated expression</td><td>heavy rain</td></tr><tr><td>Language model</td><td>A distribution used to score or predict sequences</td><td>P(rain | heavy)</td></tr></tbody></table></div><p><strong>Definition.</strong> A statistical language model assigns a probability to a sequence of words, or equivalently predicts the next word from preceding context. It is useful for autocomplete, speech recognition, machine translation, spelling correction, assistive communication and ranking candidate text. High probability reflects patterns learned from its training distribution; it is not a guarantee of truth or grammatical correctness.</p><div class=\"flow\"><div class=\"node\">Previous words: please turn your homework</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Candidate: in / over / elephant</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Language model gives each candidate a probability</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Application selects or ranks candidates</div></div><p><strong>Noisy-channel connection.</strong> Suppose x is the observed noisy text or speech and y is a candidate intended message. The noisy-channel approach chooses the y that maximizes P(x | y)P(y). The channel model P(x | y) asks how y could produce x; the language model P(y) asks whether y is a plausible message. P(x) is the same for all candidate y and therefore can be omitted when ranking.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d214e55148d91eec.svg\" alt=\"\\hat y=\\arg\\max_y P(y\\mid x)=\\arg\\max_y P(x\\mid y)P(y)\" style=\"width:43.434ex;height:3.769ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A spelling-correction system considers “flowers” and “flours”. For the observed input, the channel likelihoods are 0.2 and 0.4, and the respective language-model probabilities in context are 0.08 and 0.01. Which candidate does the noisy-channel rule choose?</strong></p><div class=\"given\"><h4>Given</h4><p>Candidate flowers: P(x|flowers)=0.2, P(flowers)=0.08. Candidate flours: P(x|flours)=0.4, P(flours)=0.01.</p><h4>To find</h4><p>The larger unnormalized candidate score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ad804659d9b93edc.svg\" alt=\"\\operatorname{score}(y)=P(x\\mid y)P(y)\" style=\"width:23.12ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both the error mechanism and the language context matter. The same denominator would normalize both candidates.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score flowers</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8f15b3cdfefd2ca8.svg\" alt=\"0.2\\times0.08=0.016\" style=\"width:17.851ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Score flours</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0c266d4a40683c9b.svg\" alt=\"0.4\\times0.01=0.004\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c236ae69fa45b6c2.svg\" alt=\"0.016&gt;0.004\" style=\"width:13.325ex;height:1.622ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Choose flowers. The scores are not yet posterior probabilities.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Har word-pair bigram hai; har frequent pair meaningful collocation nahi.</p>"},{"id":"chain-rule-markov","title":"Probability chain rule and the Markov assumption","html":"<p><strong>The probability chain rule</strong> decomposes the probability of a complete sequence into successive conditional probabilities. It is different from the derivative chain rule used in deep learning. Here we multiply probabilities, not derivatives.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5c8b1d21b7b346a9.svg\" alt=\"P(w_1,w_2,w_3)=P(w_1)P(w_2\\mid w_1)P(w_3\\mid w_1,w_2)\" style=\"width:47.112ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read left to right: probability of the first word; then probability of the second after the first; then probability of the third after both previous words. For a longer sentence, continue the same pattern. The product symbol ∏ simply means “multiply all of these terms”.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/430725f0e531e2f7.svg\" alt=\"P(w_1,\\ldots,w_m)=\\prod_{i=1}^{m}P(w_i\\mid w_1,\\ldots,w_{i-1})\" style=\"width:40.363ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><p><strong>The Markov assumption</strong> approximates long history by a limited recent context. A unigram model ignores preceding words. A bigram model keeps the previous word. A trigram model keeps the previous two words. This reduces the number of counts needed, but loses longer-range dependencies.</p><div class=\"table-wrap\"><table><thead><tr><th>Model</th><th>Prediction rule</th><th>For the next word country after the prime minister of our</th></tr></thead><tbody><tr><td>Unigram</td><td>P(wᵢ)</td><td>P(country)</td></tr><tr><td>Bigram</td><td>P(wᵢ | wᵢ₋₁)</td><td>P(country | our)</td></tr><tr><td>Trigram</td><td>P(wᵢ | wᵢ₋₂,wᵢ₋₁)</td><td>P(country | of, our)</td></tr><tr><td>Full chain rule</td><td>P(wᵢ | all previous words)</td><td>P(country | the, prime, minister, of, our)</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. For the three-word sentence “I like tea”, P(I)=0.2, P(like|I)=0.5 and P(tea|I,like)=0.4. Find its probability using the full chain rule.</strong></p><div class=\"given\"><h4>Given</h4><p>Three conditional factors are given, including the full two-word history for tea. No end probability is requested.</p><h4>To find</h4><p>P(I, like, tea).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/51a05236a3c51a81.svg\" alt=\"P(I,like,tea)=P(I)P(like\\mid I)P(tea\\mid I,like)\" style=\"width:45.404ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The chain rule supplies one factor per word in the specified sequence.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the three supplied factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6ed38d660fa17e1d.svg\" alt=\"P=0.2\\times0.5\\times0.4\" style=\"width:18.922ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply the first two</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5574a2d8fcf3abb3.svg\" alt=\"0.2\\times0.5=0.1\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Multiply by the third</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d17f98269b12c97d.svg\" alt=\"0.1\\times0.4=0.04\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The sentence probability is 0.04.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A bigram model gives P(I|&lt;s&gt;)=0.5, P(like|I)=0.6, P(tea|like)=0.25 and P(&lt;/s&gt;|tea)=0.8. Find the full sentence probability.</strong></p><div class=\"given\"><h4>Given</h4><p>All four conditional probabilities, including the end event, are supplied.</p><h4>To find</h4><p>P(I like tea &lt;/s&gt; | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7363c7dc5cab171f.svg\" alt=\"P=P(I\\mid\\langle s\\rangle)P(like\\mid I)P(tea\\mid like)P(\\langle/s\\rangle\\mid tea)\" style=\"width:48.662ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Under the bigram assumption, every factor uses one preceding token.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the factors in sentence order</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e3c41e56b889ac9f.svg\" alt=\"P=0.5\\times0.6\\times0.25\\times0.8\" style=\"width:25.71ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Start and second word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/389d6af9cfa7b052.svg\" alt=\"0.5\\times0.6=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Third word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bdfb9291e6974dcf.svg\" alt=\"0.3\\times0.25=0.075\" style=\"width:17.851ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/98c43f5a93d1dcf9.svg\" alt=\"0.075\\times0.8=0.06\" style=\"width:17.851ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The complete sentence probability is 0.06.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Sequence probability = saare required transitions ka product.</p></section><p><strong>Typical 2-mark answer.</strong> An n-gram language model predicts a word from its previous n−1 words using a Markov approximation. For example, a bigram model uses P(wᵢ | wᵢ₋₁). It estimates these probabilities from corpus counts and multiplies the appropriate factors to score a sentence.</p>"}]},{"id":"m2-count-to-probability","title":"From a corpus to sentence probabilities","unit":3,"scope":"Unit 3, pages 97–120 and appendix","sections":[{"id":"unigram-estimation","title":"Unigram estimation and complete worked examples","html":"<p><strong>Maximum likelihood estimation (MLE)</strong> chooses probabilities equal to observed relative frequencies. In a unigram model, every word is predicted independently of its surrounding words. If a word occurs c times in N training tokens, its estimate is c/N. To score m specified words, multiply their m unigram probabilities.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/151df11dd9b4e4ca.svg\" alt=\"P_{\\mathrm{MLE}}(w)=\\frac{C(w)}{N}\\qquad P(w_1,\\ldots,w_m)\\approx\\prod_{i=1}^{m}P(w_i)\" style=\"width:48.638ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Choose a tokenization convention before counting. Lowercasing, punctuation handling and boundary markers can change the vocabulary and counts. Never count words with one convention and form the denominator with another. A unigram model gives the same product to rearrangements of the same word multiset; that is one of its limitations.</p><section class=\"example\"><p class=\"question\"><strong>Question. Train an unpadded, case-insensitive unigram model on “I like tea” and “I like coffee”. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Training sentences: I like tea; I like coffee. Use lowercase words; exclude punctuation and sentence boundaries.</p><h4>To find</h4><p>The vocabulary, word probabilities and test-sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92c670591895f879.svg\" alt=\"P(w)=C(w)/N,\\qquad P(I\\ like\\ tea)=P(I)P(like)P(tea)\" style=\"width:55.644ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The unigram approximation ignores order and uses total token count for every denominator.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count every training token</h5><p>Each sentence contains three words, so N = 3+3 = 6.</p></div><div class=\"step\"><h5>Step 2. Count types and frequencies</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th><th>MLE probability</th></tr></thead><tbody><tr><td>i</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>like</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>tea</td><td>1</td><td>1/6</td></tr><tr><td>coffee</td><td>1</td><td>1/6</td></tr></tbody></table></div><p>Vocabulary size V = 4.</p></div><div class=\"step\"><h5>Step 3. Write one factor per test word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8823227ec8a6a1a.svg\" alt=\"P=\\frac{2}{6}\\times\\frac{2}{6}\\times\\frac{1}{6}\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply the fractions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3a5496aef6f0526.svg\" alt=\"P=\\frac{4}{216}=\\frac{1}{54}\\approx0.018519\" style=\"width:26.945ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The unigram sentence probability is approximately 0.018519.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains counts a: 4, b: 3 and c: 1. Find the unigram probability of “a b a”.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=4, C(b)=3, C(c)=1. No boundary markers.</p><h4>To find</h4><p>P(a b a).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/97d27988b1cff86a.svg\" alt=\"P(a\\,b\\,a)=P(a)P(b)P(a)\" style=\"width:24.338ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A repeated test word contributes a probability factor at every occurrence; do not include it just once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/489d9ca17e456579.svg\" alt=\"N=4+3+1=8\" style=\"width:18.1ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the required probabilities</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c986ed6d03f3c421.svg\" alt=\"P(a)=4/8=1/2,\\qquad P(b)=3/8\" style=\"width:33.849ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Use both occurrences of a</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a46bf6ca459b44e0.svg\" alt=\"P=\\frac12\\times\\frac38\\times\\frac12\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Simplify</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c91fa325852e9b20.svg\" alt=\"P=\\frac3{32}=0.09375\" style=\"width:18.407ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(a b a) = 0.09375.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Repeated word ka probability bhi repeat multiply hoga.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. An unsmoothed unigram model is trained on “red blue red”. Find the probability of “red green”.</strong></p><div class=\"given\"><h4>Given</h4><p>N=3. Counts: red=2, blue=1, green=0. The test contains red and green.</p><h4>To find</h4><p>The unsmoothed test probability and the reason for its value.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ad862e46bb0787a.svg\" alt=\"P(red\\ green)=P(red)P(green)\" style=\"width:31.594ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>MLE assigns zero to an unseen outcome. Smoothing is needed if an unseen in-vocabulary item must receive probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Estimate red</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4e4dbe2f8003f7d7.svg\" alt=\"P(red)=2/3\" style=\"width:13.121ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the unseen word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5ae67848fc965273.svg\" alt=\"P(green)=0/3=0\" style=\"width:19.584ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c86e2ed24bee6fb.svg\" alt=\"(2/3)\\times0=0\" style=\"width:13.199ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed probability = 0. This reflects missing training evidence, not proof that the phrase is impossible.</div></section>"},{"id":"bigram-count-table","title":"Bigram counts: build the table before multiplying","html":"<p>A <strong>bigram probability table</strong> uses the previous word as its row and the next word as its column. Divide each cell count by its row's total outgoing count. With one end marker on every sentence, each ordinary training word has a continuation, so its outgoing count equals its token frequency. Do not create a bigram that crosses from one sentence into the next.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/16ee67bf50a203c3.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{\\sum_{v\\in V}C(h,v)}=\\frac{C(h,w)}{C(h)}\" style=\"width:36.615ex;height:5.619ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"flow\"><div class=\"node\">Add boundaries to each sentence separately</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">List adjacent pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Count repeated pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Divide each row by its total</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Follow the test sentence through the table</div></div><section class=\"example\"><p class=\"question\"><strong>Question. Train a bigram model on “I like tea”, “I like coffee” and “you like tea”. Use one start and one end marker. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: &lt;s&gt; I like tea &lt;/s&gt;; &lt;s&gt; I like coffee &lt;/s&gt;; &lt;s&gt; you like tea &lt;/s&gt;. Preserve these tokens.</p><h4>To find</h4><p>All nonzero bigram estimates and the test probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every sentence starts and ends independently. Four probability factors are required for the three test words plus end.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. List the training pairs</h5><p>Sentence 1: (&lt;s&gt;,I), (I,like), (like,tea), (tea,&lt;/s&gt;).<br>Sentence 2: (&lt;s&gt;,I), (I,like), (like,coffee), (coffee,&lt;/s&gt;).<br>Sentence 3: (&lt;s&gt;,you), (you,like), (like,tea), (tea,&lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 2. Create the nonzero count table</h5><div class=\"table-wrap\"><table><thead><tr><th>History → next</th><th>Pair count</th><th>History count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → I</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>&lt;s&gt; → you</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>I → like</td><td>2</td><td>2</td><td>1</td></tr><tr><td>you → like</td><td>1</td><td>1</td><td>1</td></tr><tr><td>like → tea</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>like → coffee</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>tea → &lt;/s&gt;</td><td>2</td><td>2</td><td>1</td></tr><tr><td>coffee → &lt;/s&gt;</td><td>1</td><td>1</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the test path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7363c7dc5cab171f.svg\" alt=\"P=P(I\\mid\\langle s\\rangle)P(like\\mid I)P(tea\\mid like)P(\\langle/s\\rangle\\mid tea)\" style=\"width:48.662ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Substitute each matching row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2c319bafd1386357.svg\" alt=\"P=\\frac23\\times1\\times\\frac23\\times1\" style=\"width:19.529ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d5107e2738f0177f.svg\" alt=\"P=\\frac49\\approx0.444444\" style=\"width:18.407ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(I like tea) = 4/9 ≈ 0.444444.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using the same three-sentence corpus given here—“I like tea”, “I like coffee”, “you like tea”—find the bigram probabilities of “you like coffee” and “tea like I”. Include boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus with one start/end marker per sentence. Counts: start→you=1/3; you→like=1; like→coffee=1/3; coffee→end=1. No training sentence starts with tea.</p><h4>To find</h4><p>The two test probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92e554afbd43b835.svg\" alt=\"P(\\text{sentence})=\\prod P(\\text{next token}\\mid\\text{previous token})\" style=\"width:48.054ex;height:3.167ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A model can assign a nonzero probability to a sentence it never saw if all of its local bigrams were seen.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score you like coffee</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bccffa0a6f23966a.svg\" alt=\"P=\\frac13\\times1\\times\\frac13\\times1=\\frac19\\approx0.111111\" style=\"width:36.238ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Inspect tea like I</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c17c8267050aec19.svg\" alt=\"P(tea\\mid\\langle s\\rangle)=0/3=0\" style=\"width:21.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply the zero factor</h5><p>The full product is zero, regardless of the remaining factors.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(you like coffee) = 1/9; P(tea like I) = 0. A new sentence is not necessarily a zero-probability sentence.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Obtain the unsmoothed bigram probability of “students are from Vellore” from this corpus: “I am from Vellore”; “I am a teacher”; “students are good and are from various cities”; “students from Vellore do engineering”. Use sentence boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Four training sentences, each padded with one &lt;s&gt; and &lt;/s&gt;. Test sequence: &lt;s&gt; students are from Vellore &lt;/s&gt;.</p><h4>To find</h4><p>The five required conditional probabilities and their product.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Count all occurrences in the entire corpus. In particular, are occurs twice inside the third sentence, and Vellore is followed by end once and do once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the histories</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Occurrences with continuation</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>4</td></tr><tr><td>students</td><td>2</td></tr><tr><td>are</td><td>2</td></tr><tr><td>from</td><td>3</td></tr><tr><td>Vellore</td><td>2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count the required pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Required pair</th><th>Count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; students</td><td>2</td><td>2/4</td></tr><tr><td>students are</td><td>1</td><td>1/2</td></tr><tr><td>are from</td><td>1</td><td>1/2</td></tr><tr><td>from Vellore</td><td>2</td><td>2/3</td></tr><tr><td>Vellore &lt;/s&gt;</td><td>1</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the complete product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6420e3d4b5982a43.svg\" alt=\"P=\\frac24\\times\\frac12\\times\\frac12\\times\\frac23\\times\\frac12\" style=\"width:26.413ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply progressively</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6c021a4ae77c326e.svg\" alt=\"\\frac24\\times\\frac12=\\frac14,\\quad \\frac14\\times\\frac12=\\frac18\" style=\"width:27.594ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e9b12d6d627642db.svg\" alt=\"\\frac18\\times\\frac23=\\frac1{12},\\quad \\frac1{12}\\times\\frac12=\\frac1{24}\" style=\"width:30.988ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 1/24 ≈ 0.0416667.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Same sentence mein word do baar aaye toh count bhi do.</p></section>"},{"id":"trigram-estimation","title":"Trigram estimates: two-word history, not two denominators","html":"<p>A trigram model predicts the next word from the two preceding words. The numerator is the count of a triple. The denominator is the count of its two-word history with an available next token. Do not multiply two independent bigram probabilities and call that a trigram probability.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ca97d5e894e09b1.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=\\frac{C(w_{i-2},w_{i-1},w_i)}{C(w_{i-2},w_{i-1})}\" style=\"width:38.191ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains 12 occurrences of “prime minister”. Eight are followed by “of”, three by “said”, and one by “visited”. Estimate the three trigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>History h = (prime, minister). Count of this history = 12. Triple counts for of, said, visited are 8, 3, 1.</p><h4>To find</h4><p>The conditional distribution of the next word.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8ba899fcd0d6112.svg\" alt=\"P(w\\mid prime,minister)=C(prime,minister,w)/12\" style=\"width:51.168ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All three candidates share one two-word history, so they share denominator 12.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate of</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69d53078e2ba6e25.svg\" alt=\"P(of\\mid prime,minister)=8/12=2/3\" style=\"width:37.483ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate said</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a742b6dcdf3bfef5.svg\" alt=\"P(said\\mid prime,minister)=3/12=1/4\" style=\"width:39.356ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate visited</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/170c0f0886c42082.svg\" alt=\"P(visited\\mid prime,minister)=1/12\" style=\"width:35.497ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Confirm normalization</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8a19e47f93490280.svg\" alt=\"8/12+3/12+1/12=12/12=1\" style=\"width:31.928ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The probabilities are 2/3, 1/4 and 1/12.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Train a trigram model on “I like tea”, “I like coffee” and “you like tea”. Use two start markers and one end marker. Score “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences. Padded first sentence is &lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;; pad the other two in the same way.</p><h4>To find</h4><p>Four trigram prediction probabilities and the sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0b4f2f8e9cf3fc17.svg\" alt=\"P=\\prod_i P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:25.504ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each prediction uses a two-token context; the two start markers supply the first history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the first-word event</h5><p>The history (&lt;s&gt;,&lt;s&gt;) occurs three times, and two are followed by I.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/88a613de059c9165.svg\" alt=\"P(I\\mid\\langle s\\rangle,\\langle s\\rangle)=2/3\" style=\"width:19.545ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Count the second-word event</h5><p>(&lt;s&gt;,I) occurs twice; both are followed by like.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99919b0a3770ff5c.svg\" alt=\"P(like\\mid\\langle s\\rangle,I)=2/2=1\" style=\"width:24.56ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count the third-word event</h5><p>(I,like) occurs twice; one is followed by tea.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/22c4756e3a5a9146.svg\" alt=\"P(tea\\mid I,like)=1/2\" style=\"width:20.658ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Count the end event</h5><p>(like,tea) occurs twice; both are followed by end.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/221a8d0201199a49.svg\" alt=\"P(\\langle/s\\rangle\\mid like,tea)=2/2=1\" style=\"width:27.618ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply all four</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15f0c8914a694355.svg\" alt=\"P=\\frac23\\times1\\times\\frac12\\times1=\\frac13\" style=\"width:24.673ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Trigram P(I like tea) = 1/3. It differs from the bigram estimate because the context and denominator changed.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A trigram model supplies P(we|&lt;s&gt;,&lt;s&gt;)=0.4, P(study|&lt;s&gt;,we)=0.5, P(NLP|we,study)=0.8 and P(&lt;/s&gt;|study,NLP)=0.25. Score “we study NLP”.</strong></p><div class=\"given\"><h4>Given</h4><p>Four trigram conditional factors. The end marker is included.</p><h4>To find</h4><p>The complete sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f7ce4e6b173900c6.svg\" alt=\"P=P(we\\mid s,s)P(study\\mid s,we)P(NLP\\mid we,study)P(end\\mid study,NLP)\" style=\"width:71.784ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use each supplied two-word history exactly; do not swap its word order.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the values</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7e1f0a0c2ffc974b.svg\" alt=\"P=0.4\\times0.5\\times0.8\\times0.25\" style=\"width:25.71ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply the first pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4528e6e7a97bb8e8.svg\" alt=\"0.4\\times0.5=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Include NLP</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd4748e690ad03d9.svg\" alt=\"0.2\\times0.8=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Include the end</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5bbc9c588899b389.svg\" alt=\"0.16\\times0.25=0.04\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 0.04.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Trigram: teen-word count upar, pehle do-word count neeche.</p></section><p><strong>Why larger n is not automatically better.</strong> More context can capture local order more precisely, but each longer history occurs less often. Parameter count, storage and sparsity grow. A model trained on Shakespeare may assign poor probabilities to financial news because training and test distributions differ. Keep a held-out test set; do not evaluate only on memorized training sentences.</p>"},{"id":"class-count-table-questions","title":"Class-style count-table questions and partial-table traps","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Train a bigram model on “I am Sam”, “Sam I am”, and “I do not like green eggs and ham”. Include sentence boundaries. Find P(I|&lt;s&gt;), P(Sam|&lt;s&gt;), P(am|I), P(do|I), P(Sam|am) and P(&lt;/s&gt;|Sam).</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences; one &lt;s&gt; and &lt;/s&gt; per sentence; preserve capital I and Sam.</p><h4>To find</h4><p>Six bigram estimates.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Count all matching histories, including repeated words in different sentence positions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the histories</h5><p>START occurs 3 times; I occurs 3 times; am occurs 2 times; Sam occurs 2 times.</p></div><div class=\"step\"><h5>Step 2. Count the requested pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Pair count</th><th>History count</th></tr></thead><tbody><tr><td>START I</td><td>2</td><td>3</td></tr><tr><td>START Sam</td><td>1</td><td>3</td></tr><tr><td>I am</td><td>2</td><td>3</td></tr><tr><td>I do</td><td>1</td><td>3</td></tr><tr><td>am Sam</td><td>1</td><td>2</td></tr><tr><td>Sam END</td><td>1</td><td>2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Divide pair by history</h5><div class=\"table-wrap\"><table><thead><tr><th>Requested probability</th><th>Result</th></tr></thead><tbody><tr><td>P(I|START)</td><td>2/3</td></tr><tr><td>P(Sam|START)</td><td>1/3</td></tr><tr><td>P(am|I)</td><td>2/3</td></tr><tr><td>P(do|I)</td><td>1/3</td></tr><tr><td>P(Sam|am)</td><td>1/2</td></tr><tr><td>P(END|Sam)</td><td>1/2</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> The six estimates are 2/3,1/3,2/3,1/3,1/2,1/2 in the requested order.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A bigram table gives P(i|&lt;s&gt;)=0.25, P(want|i)=0.33, P(english|want)=0.0011, P(food|english)=0.5 and P(&lt;/s&gt;|food)=0.68. Score “i want english food” using these supplied rounded values.</strong></p><div class=\"given\"><h4>Given</h4><p>All five transition probabilities are explicitly given. Include the end marker.</p><h4>To find</h4><p>The sentence probability from the supplied table.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c573bb6be6835221.svg\" alt=\"P=P(i\\mid START)P(want\\mid i)P(english\\mid want)P(food\\mid english)P(END\\mid food)\" style=\"width:80.505ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A table-based question uses the provided values; slight differences can arise if exact corpus fractions are used instead.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. First two events</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/536a06c85da5d9e1.svg\" alt=\"0.25(0.33)=0.0825\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add english</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cc8c5266050b1825.svg\" alt=\"0.0825(0.0011)=0.00009075\" style=\"width:28.157ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add food</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/55d45996875f92e6.svg\" alt=\"0.00009075(0.5)=0.000045375\" style=\"width:30.42ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69c2e9e932b1b959.svg\" alt=\"0.000045375(0.68)=0.000030855\" style=\"width:32.682ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P≈0.000030855 using the supplied rounded probabilities.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A corpus has vocabulary size 1446, C(i)=2533 and C(i,want)=827. Compute the unsmoothed and add-one-smoothed P(want|i). The displayed bigram table contains only eight vocabulary columns.</strong></p><div class=\"given\"><h4>Given</h4><p>Full history count C(i)=2533; pair count 827; complete vocabulary size V=1446. The displayed table is only a subset.</p><h4>To find</h4><p>Both conditional probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ccfa3c73248a102f.svg\" alt=\"P(want\\mid i)=827/2533,\\qquad P_L(want\\mid i)=\\frac{827+1}{2533+1446}\" style=\"width:56.69ex;height:4.796ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use the supplied full history total. Summing only the eight displayed columns would wrongly ignore all other possible continuations.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate the unsmoothed ratio</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a38462b5efb9f1e3.svg\" alt=\"P=827/2533\\approx0.326490\" style=\"width:25.331ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add one to the pair count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/02a3d76972ac332b.svg\" alt=\"827+1=828\" style=\"width:13.701ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add V to the history count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/56cd165dd5075aa7.svg\" alt=\"2533+1446=3979\" style=\"width:19.357ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ca005fa10935e238.svg\" alt=\"P_L=828/3979\\approx0.208092\" style=\"width:26.361ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed≈0.326490; smoothed≈0.208092.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Partial table ka visible row-sum, full history total nahi hota.</p></section>"}]},{"id":"m2-evaluation-smoothing","title":"Perplexity, log probabilities and smoothing","unit":3,"scope":"Unit 3, pages 121–156","sections":[{"id":"evaluation-perplexity","title":"Perplexity: meaning, formula and four complete examples","html":"<p><strong>Intrinsic evaluation</strong> evaluates a model directly on a held-out test corpus, for example using perplexity. <strong>Extrinsic evaluation</strong> places it inside a downstream application, such as a speech recognizer or translation system, and measures the application's performance. Extrinsic testing is closer to actual use but often slower and more expensive. A lower perplexity is not a guarantee of improvement on every downstream task.</p><p><strong>Perplexity</strong> is the inverse probability of a test sequence, normalized by the number of prediction events. Intuitively, it is the model's effective average number of equally plausible choices. A model that always gives the correct next word probability 1/4 has perplexity 4. Lower is better when the models are tested on the same data, vocabulary, tokenization and boundary convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dab12face5c56858.svg\" alt=\"\\operatorname{PP}(W)=P(W)^{-1/N}=\\sqrt[N]{\\frac1{P(W)}}\" style=\"width:32.663ex;height:6.923ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>W</td><td>The complete test sequence.</td></tr><tr><td>P(W)</td><td>Product of the probabilities assigned to the actual next tokens.</td></tr><tr><td>N</td><td>Number of scored prediction events under the stated convention.</td></tr><tr><td>Exponent −1/N</td><td>Take the reciprocal, then the Nth root.</td></tr></tbody></table></div><p>For calculator entry, use parentheses: P raised to (−1 ÷ N), or (1 ÷ P) raised to (1 ÷ N). Retain several digits in intermediate products. The ordinary start marker is usually given context, not a predicted event; the end marker counts if its probability is included.</p><section class=\"example\"><p class=\"question\"><strong>Question. A model assigns probability 0.0625 to a test sequence containing four scored tokens. Compute its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>P(W)=0.0625=1/16; N=4.</p><h4>To find</h4><p>PP(W).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7873b84adddec337.svg\" alt=\"\\operatorname{PP}(W)=\\left(\\frac1{P(W)}\\right)^{1/N}\" style=\"width:23.594ex;height:6.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The root removes the effect of sequence length; the reciprocal makes lower surprise correspond to lower perplexity.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/31c8e928444ef07c.svg\" alt=\"1/P(W)=1/0.0625=16\" style=\"width:24.937ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the fourth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/560b6664723185b3.svg\" alt=\"\\operatorname{PP}=16^{1/4}\" style=\"width:10.948ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c15dbdf7cfc85ea8.svg\" alt=\"2^4=16\\quad\\Rightarrow\\quad\\operatorname{PP}=2\" style=\"width:22.672ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 2.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Two language models score the same three-token test sequence. Model A gives next-token probabilities 0.5, 0.5, 0.5. Model B gives 0.5, 0.25, 0.25. Compute their perplexities and select the better intrinsic result.</strong></p><div class=\"given\"><h4>Given</h4><p>Same sequence and N=3 for both models. A factors: 0.5,0.5,0.5. B factors: 0.5,0.25,0.25.</p><h4>To find</h4><p>Both sequence probabilities and perplexities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3f347a2e35262f3f.svg\" alt=\"P(W)=\\prod_i p_i,\\qquad\\operatorname{PP}=P(W)^{-1/3}\" style=\"width:35.285ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A fair comparison uses identical test tokens and scoring conventions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate A's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/072e354cb1ef7f5e.svg\" alt=\"P_A=0.5\\times0.5\\times0.5=0.125=1/8\" style=\"width:34.645ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate A's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/eaa36684164a8ec6.svg\" alt=\"\\operatorname{PP}_A=8^{1/3}=2\" style=\"width:15.353ex;height:2.48ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate B's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e4c44123baab46cd.svg\" alt=\"P_B=0.5\\times0.25\\times0.25=0.03125=1/32\" style=\"width:40.315ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate B's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7cad7e80704e87a9.svg\" alt=\"\\operatorname{PP}_B=32^{1/3}\\approx3.174802\" style=\"width:23.915ex;height:2.474ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Compare</h5><p>2 is lower than 3.174802; A places more probability on the observed sequence.</p></div><div class=\"answer\"><strong>Final answer.</strong> Model A is better by perplexity on this test: 2 versus about 3.174802.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The bigram training corpus is “This is a dog”, “This is a cat”, “I love my cat”, “This is my name”. Score “This is my cat”, including an end marker, and compute perplexity using five predicted events.</strong></p><div class=\"given\"><h4>Given</h4><p>Each training sentence has one start and end marker. Test predictions: This, is, my, cat, &lt;/s&gt;. Thus N=5.</p><h4>To find</h4><p>Bigram sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cdcbde9621e0e24d.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h),\\qquad\\operatorname{PP}=P(W)^{-1/5}\" style=\"width:45.9ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start is given context. Four words plus the end marker produce five probability factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the required transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Transition</th><th>Pair count / history count</th></tr></thead><tbody><tr><td>&lt;s&gt;→This</td><td>3/4</td></tr><tr><td>This→is</td><td>3/3</td></tr><tr><td>is→my</td><td>1/3</td></tr><tr><td>my→cat</td><td>1/2</td></tr><tr><td>cat→&lt;/s&gt;</td><td>2/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Form the product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9c8a03a484dfb763.svg\" alt=\"P=\\frac34\\times1\\times\\frac13\\times\\frac12\\times1=\\frac18\" style=\"width:29.565ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/063b3931740c7830.svg\" alt=\"1/P=8\" style=\"width:8.11ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c0fbb6bb85c1b79f.svg\" alt=\"\\operatorname{PP}=8^{1/5}\\approx1.515717\" style=\"width:21.382ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(W)=1/8 and perplexity≈1.515717 using five predicted events.</div></section><p><strong>If the question explicitly states N = 6:</strong> use that supplied convention and report PP = 8<sup>1/6</sup> ≈ 1.414214. The class slide counts both boundary markers in N. Write the chosen N beside the formula; do not silently switch between 5 and 6. Also, This occurs three times and is follows it three times, so P(is|This)=3/3, not 3/4.</p><section class=\"example\"><p class=\"question\"><strong>Question. A uniform model assigns probability 1/10 to each actual next word in a five-token test. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Five scored tokens, each with assigned probability 0.1. N=5.</p><h4>To find</h4><p>The sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/245311d6fb2b9841.svg\" alt=\"P(W)=(1/10)^5,\\qquad \\operatorname{PP}=P(W)^{-1/5}\" style=\"width:37.412ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Uniform equal probabilities make the effective number of choices especially clear.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Multiply the five factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dbea309801bb43da.svg\" alt=\"P(W)=0.1^5=0.00001=10^{-5}\" style=\"width:30.672ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Invert</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a7f36a9eff1f3a2c.svg\" alt=\"1/P(W)=10^5\" style=\"width:14.36ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a14770a9a80e5984.svg\" alt=\"\\operatorname{PP}=(10^5)^{1/5}=10\" style=\"width:18.976ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 10.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Probability high → surprise low → perplexity low.</p></section>"},{"id":"log-probabilities","title":"Log probabilities: replace long products with sums","html":"<p>Probabilities are at most 1, so multiplying many of them produces very small numbers. Computers can round extremely small positive products to zero: <strong>numerical underflow</strong>. Log probabilities convert multiplication into addition and are more stable for long sequences. Natural logs use base e; log₂ uses base 2. Choose one base consistently.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cbf31ffd35c5c322.svg\" alt=\"\\ln P(W)=\\sum_{i=1}^{N}\\ln p_i\" style=\"width:18.897ex;height:6.74ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab927afa9cd05bef.svg\" alt=\"P(W)=e^{\\ln P(W)},\\qquad \\operatorname{PP}(W)=\\exp\\left(-\\frac1N\\sum_i\\ln p_i\\right)\" style=\"width:51.919ex;height:6.785ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The log of a probability below 1 is negative. A value closer to zero means a larger probability: ln(0.5) ≈ −0.693 is larger than ln(0.1) ≈ −2.303. A zero probability has log −∞; taking logs does not solve the unseen-event problem. Smoothing handles that separate problem.</p><section class=\"example\"><p class=\"question\"><strong>Question. The next-word probabilities are 0.5, 0.25 and 0.5. Calculate the natural log probability, ordinary probability and perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>p₁=0.5; p₂=0.25; p₃=0.5; N=3.</p><h4>To find</h4><p>ln P(W), P(W), and PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9bced9ebe87e44c7.svg\" alt=\"\\ln P=\\sum_i\\ln p_i,\\quad P=e^{\\ln P},\\quad\\operatorname{PP}=e^{-\\ln P/N}\" style=\"width:43.938ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Logarithms preserve products as sums and the exponent converts the result back.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute individual logs</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8fc9ba50109d8156.svg\" alt=\"\\ln0.5\\approx-0.693147,\\quad\\ln0.25\\approx-1.386294\" style=\"width:41.36ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add all three terms</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fcdc8edcec916f1f.svg\" alt=\"\\ln P=-0.693147-1.386294-0.693147\\approx-2.772589\" style=\"width:53.239ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Recover the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b886c03a804cf5a4.svg\" alt=\"P=e^{-2.772589}\\approx0.0625\" style=\"width:22.549ex;height:2.201ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find average negative log probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4d6cc3cf68cb5127.svg\" alt=\"-\\ln P/3\\approx2.772589/3=0.924196\" style=\"width:33.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Exponentiate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d34de424885d00e.svg\" alt=\"\\operatorname{PP}=e^{0.924196}\\approx2.519842\" style=\"width:24.949ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> ln P≈−2.772589, P=0.0625, PP≈2.519842.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A model has a total natural log probability −12 over six scored tokens. Calculate its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>ln P(W)=−12; N=6.</p><h4>To find</h4><p>PP without forming the tiny ordinary probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f166d1cce0943ce3.svg\" alt=\"\\operatorname{PP}=\\exp(-\\ln P(W)/N)\" style=\"width:24.688ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The logarithmic formula directly uses the supplied log score.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Negate the log score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/90abe91c0eba5423.svg\" alt=\"-\\ln P=12\" style=\"width:11.38ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Divide by token count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9d8a38c0a5d6d98a.svg\" alt=\"12/6=2\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply exponential</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d421123292e12a1.svg\" alt=\"\\operatorname{PP}=e^2\\approx7.389056\" style=\"width:19.705ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity≈7.389056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A language model's average negative log₂ probability is 3 bits per token. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Cross-entropy H=3 bits/token. Log base is 2.</p><h4>To find</h4><p>PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50941856f700d45e.svg\" alt=\"\\operatorname{PP}=2^H\" style=\"width:8.838ex;height:2.213ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The inverse operation of log₂ is raising 2 to that power; use e only for natural logs.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the log base</h5><p>Bits mean base 2.</p></div><div class=\"step\"><h5>Step 2. Raise the base to H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ffdeccced5f3a45.svg\" alt=\"\\operatorname{PP}=2^3=8\" style=\"width:12.366ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 8.</div><p class=\"cue\"><strong>Yaad rakho:</strong> ln use kiya toh e se wapas; log₂ use kiya toh 2 se wapas.</p></section>"},{"id":"laplace-basics","title":"Laplace smoothing: why both numerator and denominator change","html":"<p><strong>Smoothing</strong> reallocates some probability mass to events that received zero or unreliable estimates from finite training data. <strong>Laplace, or add-one, smoothing</strong> adds one pseudo-count to every possible next outcome. If there are V possible outcomes, the total added count is V, so adding 1 only to the numerator would produce probabilities that do not sum to 1.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0d44559007b7dea6.svg\" alt=\"P_{\\mathrm{Laplace}}(w)=\\frac{C(w)+1}{N+V}\" style=\"width:23.384ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e38a73cc66cdd3f1.svg\" alt=\"P_{\\mathrm{Laplace}}(w\\mid h)=\\frac{C(h,w)+1}{C(h)+V}\" style=\"width:28.882ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For unigram smoothing, N is the total training token count. For bigram smoothing, C(h) is the count of the particular history. In both cases V is the number of outcomes being predicted, not the number of training sentences and not the number of distinct bigrams. When end is a possible prediction, include it in V; the start marker is usually context only.</p><div class=\"flow\"><div class=\"node\">Observed counts: 3, 1, 0</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Add one to every outcome: 4, 2, 1</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New total: 7</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Smoothed probabilities: 4/7, 2/7, 1/7</div></div><section class=\"example\"><p class=\"question\"><strong>Question. A fixed unigram vocabulary is {a,b,c}. The training counts are 3,1,0. Compute unsmoothed and Laplace-smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=3, C(b)=1, C(c)=0; N=4; V=3.</p><h4>To find</h4><p>The complete distributions.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/80d7161647b260e8.svg\" alt=\"P(w)=C(w)/N,\\qquad P_L(w)=(C(w)+1)/(N+V)\" style=\"width:51.157ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The zero-count c is still in the fixed vocabulary, so it must receive one pseudo-count and contribute to V.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute unsmoothed values</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Unsmoothed</th></tr></thead><tbody><tr><td>a</td><td>3/4 = 0.75</td></tr><tr><td>b</td><td>1/4 = 0.25</td></tr><tr><td>c</td><td>0/4 = 0</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Calculate the new denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1918c0a9ceaec186.svg\" alt=\"N+V=4+3=7\" style=\"width:18.708ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add one to each numerator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/345a4b4f00828435.svg\" alt=\"C(a)+1=4,\\quad C(b)+1=2,\\quad C(c)+1=1\" style=\"width:44.259ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Divide</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Smoothed</th></tr></thead><tbody><tr><td>a</td><td>4/7 ≈ 0.571429</td></tr><tr><td>b</td><td>2/7 ≈ 0.285714</td></tr><tr><td>c</td><td>1/7 ≈ 0.142857</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Confirm the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/172a91eacd7bcf59.svg\" alt=\"4/7+2/7+1/7=1\" style=\"width:19.861ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Smoothed probabilities: a=4/7, b=2/7, c=1/7. Common a loses mass; unseen c gains mass.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. After history I, a corpus records like three times, study once and sleep zero times. The allowed next vocabulary is {like,study,sleep}. Compute all Laplace-smoothed bigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(I,like)=3; C(I,study)=1; C(I,sleep)=0. History count C(I)=4. V=3.</p><h4>To find</h4><p>P_L(like|I), P_L(study|I), P_L(sleep|I).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a1c0980897f9361.svg\" alt=\"P_L(w\\mid I)=\\frac{C(I,w)+1}{C(I)+V}\" style=\"width:24.291ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>This is smoothing within the I row; use its total 4, not the global corpus token count.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the common denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d3c1688373da86b2.svg\" alt=\"C(I)+V=4+3=7\" style=\"width:21.319ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate like</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/848e1d743f230579.svg\" alt=\"P_L(like\\mid I)=(3+1)/7=4/7\" style=\"width:29.682ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate study</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ed5edd3a14936914.svg\" alt=\"P_L(study\\mid I)=(1+1)/7=2/7\" style=\"width:31.452ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate sleep</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e0b14bd8e108207.svg\" alt=\"P_L(sleep\\mid I)=(0+1)/7=1/7\" style=\"width:30.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The row is (4/7, 2/7, 1/7). An unseen bigram is no longer forced to zero.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A fixed vocabulary has five possible next tokens. A history h is unseen in training. What is its add-one probability for each next token?</strong></p><div class=\"given\"><h4>Given</h4><p>C(h)=0; C(h,w)=0 for each outcome; V=5.</p><h4>To find</h4><p>P_L(w|h) for each token.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e1f42d7a9537f57.svg\" alt=\"P_L(w\\mid h)=\\frac{0+1}{0+V}\" style=\"width:18.948ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All outcomes receive equal pseudo-counts because the training data gives no preference for this history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Add the pseudo-count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dd66590db88ae5fa.svg\" alt=\"0+1=1\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Form the denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/190ddc58c7516f91.svg\" alt=\"0+5=5\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Divide and sum</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/39038359834be22e.svg\" alt=\"P_L(w\\mid h)=1/5=0.2,\\qquad5(0.2)=1\" style=\"width:37.08ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Every outcome gets 0.2 under this fixed-vocabulary model.</div></section><p><strong>Vocabulary warning.</strong> Add-one does not automatically define probabilities for every word in the world. Unknown words require a declared vocabulary/UNK convention. If a question supplies V, use that stated V rather than inventing additional tokens.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Add-one: upar +1, neeche +V; bigram mein neeche history ka count.</p>"},{"id":"smoothed-sentence","title":"A complete unseen-bigram question from corpus to final answer","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Consider the corpus “I love to code in Python. I love to learn new things. I code every day.” Obtain the bigram probabilities needed for “I love Python”. Explain the zero-probability issue, then use Laplace smoothing to score it. Treat each sentence separately, preserve case, remove punctuation, and include an end token among predicted outcomes.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences padded with one start/end marker. Distinct words: I, love, to, code, in, Python, learn, new, things, every, day. With &lt;/s&gt;, V=12. Start is context only.</p><h4>To find</h4><p>Unsmoothed and smoothed P(I love Python &lt;/s&gt; | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a627bcb8a0b3808.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{C(h)},\\qquad P_L(w\\mid h)=\\frac{C(h,w)+1}{C(h)+12}\" style=\"width:49.838ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The test contains an unseen transition love→Python. Smoothing assigns probability to that transition and renormalizes every required history row.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the contexts</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>3</td></tr><tr><td>I</td><td>3</td></tr><tr><td>love</td><td>2</td></tr><tr><td>Python</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count each required pair</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt; I</td><td>3</td></tr><tr><td>I love</td><td>2</td></tr><tr><td>love Python</td><td>0</td></tr><tr><td>Python &lt;/s&gt;</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Compute the unsmoothed product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/420a50ccd335ade1.svg\" alt=\"P=\\frac33\\times\\frac23\\times\\frac02\\times\\frac11=0\" style=\"width:25.668ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both words love and Python were seen, but their adjacent pair was not. This is an unseen bigram, not an unknown-word case.</p></div><div class=\"step\"><h5>Step 4. Smooth the first event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f16fc85077f5670b.svg\" alt=\"P_L(I\\mid\\langle s\\rangle)=\\frac{3+1}{3+12}=\\frac4{15}\" style=\"width:26.784ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Smooth the second event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a94897ddface7219.svg\" alt=\"P_L(love\\mid I)=\\frac{2+1}{3+12}=\\frac3{15}\" style=\"width:27.886ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Smooth the unseen event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f023b28c09df9a1a.svg\" alt=\"P_L(Python\\mid love)=\\frac{0+1}{2+12}=\\frac1{14}\" style=\"width:34.128ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 7. Smooth the end event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cfdc24dda127984e.svg\" alt=\"P_L(\\langle/s\\rangle\\mid Python)=\\frac{1+1}{1+12}=\\frac2{13}\" style=\"width:34.158ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 8. Multiply the smoothed factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8b4c9f0eec18e2b4.svg\" alt=\"P_L=\\frac4{15}\\times\\frac3{15}\\times\\frac1{14}\\times\\frac2{13}\" style=\"width:27.076ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be31ee9de701fcab.svg\" alt=\"P_L=\\frac{24}{40950}=\\frac4{6825}\\approx0.000586081\" style=\"width:35.894ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed P=0. With the stated V=12 and boundaries, Laplace-smoothed P≈0.000586081.</div></section><p>If an exam states a different convention—for example excluding boundary tokens from the entire calculation—recompute both V and the set of probability factors consistently. Do not combine a boundary-aware numerator with a boundary-free denominator.</p>"},{"id":"adjusted-count-discount","title":"Adjusted counts and relative discounting","html":"<p>The slides also express smoothing through an <strong>adjusted count</strong> c*. Instead of writing the smoothed probability with denominator N+V, they rescale its numerator so the denominator can remain N. Algebraically these are equivalent:</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/70d92382a6cc1e9c.svg\" alt=\"c^*=(c+1)\\frac{N}{N+V},\\qquad P_L(w)=\\frac{c^*}{N}\" style=\"width:36.794ex;height:4.832ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6597274c03aa7f00.svg\" alt=\"d=\\frac{c^*}{c}\\quad(c&gt;0)\" style=\"width:16.307ex;height:4.672ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The relative discount d compares adjusted and original counts. It is undefined when c=0 because division by zero is undefined. Add-one smoothing moves the distribution toward uniformity: frequent events are reduced, but some rare seen events may increase. It is not correct to claim that every nonzero count must decrease under Laplace smoothing.</p><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, a word has original count c=10. Find its adjusted count, smoothed probability and relative discount.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=10.</p><h4>To find</h4><p>c*, P_L and d.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/63cfdcd2de177903.svg\" alt=\"c^*=(c+1)N/(N+V),\\quad P_L=c^*/N,\\quad d=c^*/c\" style=\"width:48.699ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>These expressions rewrite add-one smoothing without changing its probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the new total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/749a0f4867a4b3db.svg\" alt=\"N+V=20+5=25\" style=\"width:20.971ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Find the adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/866c6ee174b3d21b.svg\" alt=\"c^*=(10+1)\\frac{20}{25}=11(0.8)=8.8\" style=\"width:32.002ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Find the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5fb26f5353edaa9.svg\" alt=\"P_L=8.8/20=0.44\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find the relative discount</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be28007774d8c2d5.svg\" alt=\"d=8.8/10=0.88\" style=\"width:17.518ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=8.8, P_L=0.44, d=0.88. The original probability 0.5 is reduced.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Under N=20, V=5, a rare word occurs once. Compute its adjusted count and compare the original and smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=1.</p><h4>To find</h4><p>c*, original P and smoothed P_L.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/509478366d59c2ce.svg\" alt=\"c^*=(c+1)N/(N+V)\" style=\"width:23.036ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same smoothing rule may increase a rare event's probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Original probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3fc24a506f12b888.svg\" alt=\"P=1/20=0.05\" style=\"width:16.281ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/13803fe6f5045ef1.svg\" alt=\"c^*=(1+1)(20/25)=1.6\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0fd3e6bc0e9d2f40.svg\" alt=\"P_L=1.6/20=0.08\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=1.6 and P_L=0.08, which exceeds the original 0.05.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, an in-vocabulary word has count zero. Find its adjusted count and smoothed probability. Can a relative discount be calculated?</strong></p><div class=\"given\"><h4>Given</h4><p>c=0; N=20; V=5.</p><h4>To find</h4><p>c*, P_L and whether d exists.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dc6d3ca40a034b28.svg\" alt=\"c^*=(c+1)N/(N+V),\\qquad P_L=c^*/N\" style=\"width:39.422ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The pseudo-count creates positive mass for the unseen vocabulary item.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e073545bb6c88eb4.svg\" alt=\"c^*=(0+1)(20/25)=0.8\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5e8f939253d4321b.svg\" alt=\"P_L=0.8/20=0.04\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Relative discount</h5><p>d would be 0.8/0. That is undefined, so do not report a finite discount.</p></div><div class=\"answer\"><strong>Final answer.</strong> c*=0.8 and P_L=0.04; relative discount is undefined for c=0.</div></section>"},{"id":"class-perplexity-characters","title":"Character-model perplexity: keep exact probabilities","html":"<section class=\"example\"><p class=\"question\"><strong>Question. A unigram character model gives P(A)=0.25, P(B)=0.50, P(C)=0.25. Find the perplexity of AAA and ABC. Then find both perplexities when the three characters are equally likely.</strong></p><div class=\"given\"><h4>Given</h4><p>Each test string contains 3 scored characters, so N=3. Initial distribution 0.25,0.50,0.25; comparison distribution 1/3,1/3,1/3.</p><h4>To find</h4><p>Both sequence probabilities and perplexities under each distribution.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e9f6c28675d3dd90.svg\" alt=\"P(c_1c_2c_3)=P(c_1)P(c_2)P(c_3),\\qquad PP=P(W)^{-1/3}\" style=\"width:50.267ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Characters, not words, are the model's prediction units in this question. Use exact 1/3 for uniform probabilities, rather than rounded 0.33.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score AAA</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/227b8a572c539a9c.svg\" alt=\"P(AAA)=0.25^3=\\frac1{64}=0.015625\" style=\"width:34.417ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Find AAA perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ced7ad162e418ee6.svg\" alt=\"PP(AAA)=64^{1/3}=4\" style=\"width:22.264ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Score ABC</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9b87b238251977b6.svg\" alt=\"P(ABC)=0.25(0.5)(0.25)=\\frac1{32}=0.03125\" style=\"width:42.775ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find ABC perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f1633e91cb3db49f.svg\" alt=\"PP(ABC)=32^{1/3}\\approx3.174802\" style=\"width:29.723ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Change to an exactly uniform model</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6366e364bc9f8ccd.svg\" alt=\"P(AAA)=P(ABC)=(1/3)^3=1/27\" style=\"width:36.86ex;height:2.564ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Find both uniform-model perplexities</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c2e12c89ac512fd3.svg\" alt=\"PP=27^{1/3}=3\" style=\"width:15.414ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Original model: AAA→4, ABC→3.174802. Uniform model: both→3. These values follow the stated formulas without intermediate rounding.</div></section>"}]},{"id":"u3-smoothing-extensions","title":"Faculty topics: interpolation and Stupid Backoff","unit":3,"mode":"tee","order":100,"scope":"Unit 3 PDF p147 names these methods. Neither supplied TEE paper asks their numerical calculation; the worked values below are authored examples.","sections":[{"id":"interpolation","title":"N-gram interpolation: weighted evidence from several histories","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 3 PDF p147 names these methods. Neither supplied TEE paper asks their numerical calculation; the worked values below are authored examples.</p><p><strong>Interpolation combines several context lengths for every prediction.</strong> A trigram estimate is specific but may have little evidence. Bigram and unigram estimates use less context and can support unseen longer sequences. A weighted mixture combines their information.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/402b0524fed55b5a.svg\" alt=\"P_{\\mathrm{mix}}(w\\mid u,v)=\\lambda_3P(w\\mid u,v)+\\lambda_2P(w\\mid v)+\\lambda_1P(w)\" style=\"width:51.898ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/934ad91d11cebd33.svg\" alt=\"\\lambda_1,\\lambda_2,\\lambda_3\\ge0,\\qquad\\lambda_1+\\lambda_2+\\lambda_3=1.\" style=\"width:35.84ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each component must be a normalized distribution over the same vocabulary. Then summing the mixture over all possible words gives λ₁+λ₂+λ₃=1. A zero higher-order count can be rescued by positive lower-order evidence. Unlike simple backoff, interpolation can combine all levels even when the trigram was seen.</p><section class=\"example\"><p class=\"question\"><strong>Question. For predicting tea after I like, suppose trigram, bigram and unigram probabilities are 0, 0.2 and 0.1. Use weights λ₃=0.5, λ₂=0.3 and λ₁=0.2 to calculate the interpolated probability. Repeat for coffee with probabilities 0.4, 0.1 and 0.05. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>The three distributions use one vocabulary. Nonnegative weights sum to 1. These are supplied probabilities; no count estimation is needed.</p><h4>To find</h4><p>Pmix(tea | I,like) and Pmix(coffee | I,like).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fbe778721993c743.svg\" alt=\"P_{mix}=\\lambda_3P_3+\\lambda_2P_2+\\lambda_1P_1\" style=\"width:27.301ex;height:1.945ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>We add weighted alternatives from models, rather than multiply sequential word events.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Check the weights</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3e929c377d815fdc.svg\" alt=\"0.5+0.3+0.2=1.\" style=\"width:18.983ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the three tea contributions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/226058093bf8c6aa.svg\" alt=\"0.5(0)=0,\\qquad0.3(0.2)=0.06,\\qquad0.2(0.1)=0.02.\" style=\"width:50.787ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add the tea contributions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b1c5370fd614e492.svg\" alt=\"P_{mix}(tea)=0+0.06+0.02=0.08.\" style=\"width:34.734ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate the coffee contributions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4318d6a3e52440bd.svg\" alt=\"0.5(0.4)=0.20,\\qquad0.3(0.1)=0.03,\\qquad0.2(0.05)=0.01.\" style=\"width:56.57ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Add and compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/538b559c97ffd180.svg\" alt=\"P_{mix}(coffee)=0.20+0.03+0.01=0.24.\" style=\"width:41.231ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Coffee gets three times tea’s probability in this model. Other vocabulary outcomes carry the remaining mass; these two displayed entries are not the whole distribution.</p></div><div class=\"answer\"><strong>Final answer.</strong> Tea=0.08 and coffee=0.24. A zero trigram probability does not force a zero mixture.</div></section><p><strong>Yaad rakho:</strong> Interpolation = sab context-lengths ka weighted mix. Word-sequence product aur model-mixture sum alag operations hain.</p>"},{"id":"stupid-backoff","title":"Backoff and the important score-versus-probability distinction","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 3 PDF p147 names these methods. Neither supplied TEE paper asks their numerical calculation; the worked values below are authored examples.</p><p><strong>Backoff uses a shorter history when the longer-history estimate lacks evidence.</strong> A properly normalized backoff model discounts some seen-event probability and allocates the remaining mass across unseen continuations using lower-order probabilities and normalization factors.</p><p><strong>Stupid Backoff</strong> is a specifically named efficient scoring method in the slides’ list. It uses an observed n-gram relative frequency when available; otherwise it multiplies the shorter-history score by a fixed penalty, commonly 0.4. Its output is generally an <strong>unnormalized score</strong>, not a conditional probability distribution. Do not insert raw Stupid Backoff scores into standard probability-based perplexity and call the result a normalized-model perplexity.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/55b65d9f12d95541.svg\" alt=\"S(w\\mid h)=\\begin{cases}C(h,w)/C(h),&amp;C(h,w)&gt;0\\\\ \\alpha S(w\\mid h&#39;),&amp;C(h,w)=0.\\end{cases}\" style=\"width:41.143ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Here h′ drops the oldest history word; α is the backoff penalty. At the unigram base, use C(w)/N. The letter α here is a penalty, not the forward-HMM variable introduced later.</p><section class=\"example\"><p class=\"question\"><strong>Question. A bigram scorer has complete vocabulary {a,b}. After h, C(h,a)=2 and C(h,b)=0. The unigram probabilities are P(a)=P(b)=0.5. Apply Stupid Backoff with penalty 0.4 and show whether the scores form a normalized row. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>C(h)=2. The a bigram is observed; the b bigram is unseen. Unigram probabilities are supplied.</p><h4>To find</h4><p>S(a|h), S(b|h), their sum, and whether they are probabilities.</p></div><h4>Formula and why it applies</h4><p>Use relative frequency for an observed pair and α times the unigram base for an unseen pair. The method does not discount a’s observed score in this example.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score the observed pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/84f0ae8328abe0b8.svg\" alt=\"S(a\\mid h)=2/2=1.\" style=\"width:18.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Back off for the unseen pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0aa2b77f15f8a15c.svg\" alt=\"S(b\\mid h)=0.4(0.5)=0.2.\" style=\"width:24.477ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add the complete row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6d9f4f0a09441a66.svg\" alt=\"1+0.2=1.2\\ne1.\" style=\"width:17.474ex;height:2.106ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Interpret the failure of normalization</h5><p>The scores can rank a above b, but the raw row cannot be called a probability distribution. Merely labelling the method “smoothing” does not change this.</p></div><div class=\"answer\"><strong>Final answer.</strong> Scores are 1 and 0.2; their sum is 1.2. They are useful ranking scores under this rule, not normalized probabilities.</div></section><div class=\"table-wrap\"><table><thead><tr><th>Method</th><th>Operation</th><th>Normalization</th></tr></thead><tbody><tr><td>Add-one/add-k</td><td>Adjust all allowed outcome counts and the total</td><td>Normalized with a fixed vocabulary</td></tr><tr><td>Interpolation</td><td>Mix normalized distributions using nonnegative weights summing to 1</td><td>Normalized</td></tr><tr><td>Normalized backoff</td><td>Discount seen events and distribute remaining mass over unseen events</td><td>Normalized when its factors are correctly computed</td></tr><tr><td>Stupid Backoff</td><td>Keep seen relative frequencies; penalize shorter-history scores for unseen n-grams</td><td>Generally not normalized</td></tr></tbody></table></div><p>Scope: Unit 3 slide 147 lists Stupid Backoff and n-gram interpolation; the class calculations emphasize Laplace. These short worked extensions explain the listed methods without claiming extra official exam weight.</p>"}]},{"id":"m2-pos-tagging","title":"POS tagging and its learning approaches","unit":4,"scope":"Unit 4, pages 3–46","sections":[{"id":"word-classes-pos","title":"Parts of speech and contextual ambiguity","html":"<p><strong>Part-of-speech (POS) tagging</strong> assigns a grammatical category to every word token in context, such as noun, verb, adjective or determiner. It is a sequence-labeling task: the input is a sequence of words, and the output is a tag for each word. A tag describes the word's role in this sentence, not its meaning in every possible sentence.</p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Role</th><th>Example in context</th></tr></thead><tbody><tr><td>NN / NNS</td><td>Singular / plural common noun</td><td>a book / two books</td></tr><tr><td>NNP</td><td>Proper noun</td><td>Mary, Mumbai</td></tr><tr><td>VB / VBD / VBZ</td><td>Base / past / third-person singular verb</td><td>read / read / reads</td></tr><tr><td>JJ</td><td>Adjective</td><td>the red book</td></tr><tr><td>RB</td><td>Adverb</td><td>runs quickly</td></tr><tr><td>DT</td><td>Determiner</td><td>the, a, this</td></tr><tr><td>IN</td><td>Preposition or subordinating conjunction</td><td>on the table</td></tr><tr><td>PRP</td><td>Personal pronoun</td><td>she, they</td></tr><tr><td>MD</td><td>Modal auxiliary</td><td>can, will, should</td></tr></tbody></table></div><p><strong>Open classes</strong> readily accept new content words: nouns, verbs, adjectives and adverbs. Examples include chatbot and livestream. <strong>Closed classes</strong> contain comparatively stable grammatical/function words: determiners, pronouns, prepositions and conjunctions. These are tendencies, not a claim that language never changes.</p><div class=\"flow\"><div class=\"node\">Input: Book that flight</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context: an imperative request</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Output: Book/VB that/DT flight/NN</div></div><p>Compare “hand me that <strong>book</strong>”: book is a noun here. Similarly, “I <strong>can</strong> swim” has can/MD, while “the <strong>can</strong> is empty” has can/NN. The spelling stays the same; neighboring words and sentence structure change the correct tag. This is <strong>POS ambiguity</strong>.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged interpretation</th><th>Reason</th></tr></thead><tbody><tr><td>They watch birds.</td><td>They/PRP watch/VBP birds/NNS</td><td>watch is the action.</td></tr><tr><td>The watch stopped.</td><td>The/DT watch/NN stopped/VBD</td><td>watch is the object that stopped.</td></tr><tr><td>She has a light bag.</td><td>She/PRP has/VBZ a/DT light/JJ bag/NN</td><td>light describes bag.</td></tr><tr><td>Light the lamp.</td><td>Light/VB the/DT lamp/NN</td><td>Light is an imperative verb.</td></tr></tbody></table></div><p>POS tags support parsing, named entity recognition, question answering, sentiment analysis and word-sense disambiguation. They do not by themselves identify every entity or fully resolve meaning.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka naam same ho sakta hai; sentence mein uska kaam tag decide karta hai.</p>"},{"id":"tagger-methods","title":"Lexical, rule-based, stochastic, Brill and neural taggers","html":"<p><strong>A lexical baseline</strong> gives each known word its most frequent training tag. It is simple and often useful, but ignores context. A <strong>rule-based tagger</strong> uses a lexicon of possible tags plus manually designed contextual or morphological rules to resolve ambiguity. For example, after a determiner, a noun reading of “can” may be preferred in “the can”.</p><p>Rules are usually heuristics with exceptions. “A red car” shows that the word immediately after an article is not always a noun. The suffix -ed does not make “red” a past-tense verb. A robust rule system uses multiple linguistic constraints instead of treating such shortcuts as universal laws.</p><div class=\"table-wrap\"><table><thead><tr><th>Method</th><th>How it chooses tags</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>Most frequent / lexical</td><td>Most common training tag for the word</td><td>Simple baseline</td><td>Misses contextual changes and unknown words</td></tr><tr><td>Rule-based</td><td>Lexicon plus handwritten rules</td><td>Readable, controllable linguistic decisions</td><td>Expert effort; rules may conflict or need updates</td></tr><tr><td>Stochastic</td><td>Scores tag sequences using estimated probabilities</td><td>Uses corpus evidence and context</td><td>Sparse/unseen events; depends on training domain</td></tr><tr><td>Transformation-based / Brill</td><td>Start with baseline, then apply learned correction rules</td><td>Readable learned corrections</td><td>Needs tagged training data and suitable rule templates</td></tr><tr><td>Neural</td><td>Learns contextual representations and sequence predictions</td><td>Can exploit richer context</td><td>Needs training resources and data; less directly interpretable</td></tr></tbody></table></div><p><strong>Transformation-based error-driven learning (Brill tagging)</strong> combines a simple starting assignment with learned correction rules. First tag the training corpus with a baseline. Compare against the gold tags. Generate candidate correction rules from templates, such as “change MD to NN after DT”. Apply the rule that fixes the most errors net of newly introduced errors; repeat until further improvement is too small. At test time apply the learned ordered rule list.</p><div class=\"flow\"><div class=\"node\">Baseline: The/DT can/MD was/VBD crushed/VBN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context rule: change can from MD to NN after DT</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Result: The/DT can/NN was/VBD crushed/VBN</div></div><p><strong>Rule-based versus Brill:</strong> a purely rule-based system depends on linguists specifying its rules; a Brill tagger learns which transformations improve a labeled corpus. A <strong>stochastic tagger</strong> such as an HMM finds a high-probability tag sequence using transition and emission probabilities. CRFs and neural sequence taggers are other learning approaches; they do not have to make the same HMM independence assumptions.</p><p><strong>Exam-ready answer.</strong> POS tagging assigns a grammatical tag to each word in context. A rule-based tagger uses lexicons and linguistic rules, whereas a stochastic tagger chooses tags through probabilities estimated from a corpus. For example, can is MD in “I can swim” but NN in “the can”; context resolves the ambiguity.</p>"},{"id":"generative-discriminative","title":"Generative versus discriminative models and Bayes' rule","html":"<p>Let x be the observed words and y be the desired tag sequence. A <strong>generative model</strong> describes their joint distribution P(x,y), often as P(y)P(x|y). A <strong>discriminative model</strong> learns P(y|x) directly or learns a decision boundary that separates possible labels. Both kinds can be trained with labeled data; “generative” does not mean “always unsupervised”.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/279bb8404538a591.svg\" alt=\"P(y\\mid x)=\\frac{P(x\\mid y)P(y)}{P(x)}\" style=\"width:24.076ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Quantity</th><th>Meaning</th><th>POS interpretation</th></tr></thead><tbody><tr><td>P(y)</td><td>Prior</td><td>How plausible is this tag or tag sequence before seeing the words?</td></tr><tr><td>P(x|y)</td><td>Likelihood</td><td>How plausible are these words under that tag sequence?</td></tr><tr><td>P(x)</td><td>Evidence</td><td>Total probability of the observed words across possible labels.</td></tr><tr><td>P(y|x)</td><td>Posterior</td><td>Probability of the tags after seeing the words.</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Generative</th><th>Discriminative</th></tr></thead><tbody><tr><td>Models</td><td>Joint P(x,y), or prior × likelihood</td><td>Conditional P(y|x) or decision boundary</td></tr><tr><td>Classification examples</td><td>Naive Bayes</td><td>Logistic regression, SVM</td></tr><tr><td>Sequence-labeling examples</td><td>HMM</td><td>Linear-chain CRF</td></tr><tr><td>Intuition</td><td>Model how a label could generate the observation</td><td>Model which label fits the observation</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. A token has two possible tags, noun N and verb V. P(N)=0.6, P(V)=0.4, P(book|N)=0.2 and P(book|V)=0.5. Calculate P(N|book) and P(V|book).</strong></p><div class=\"given\"><h4>Given</h4><p>Two tags are exhaustive. Priors: 0.6,0.4. Word likelihoods: 0.2,0.5.</p><h4>To find</h4><p>Normalized posterior probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1b37c73f9aa13957.svg\" alt=\"P(t\\mid w)=\\frac{P(w\\mid t)P(t)}{\\sum_{u}P(w\\mid u)P(u)}\" style=\"width:28.676ex;height:5.573ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Bayes' rule combines prior and likelihood. Normalization is needed to convert scores into posterior probabilities.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate the noun score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bef5ede62cecaa67.svg\" alt=\"0.2\\times0.6=0.12\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the verb score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7510fe35c0e59838.svg\" alt=\"0.5\\times0.4=0.20\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Find the evidence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f24842cc6cea4777.svg\" alt=\"P(book)=0.12+0.20=0.32\" style=\"width:28.671ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Normalize the noun score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/886a6346c0609831.svg\" alt=\"P(N\\mid book)=0.12/0.32=0.375\" style=\"width:32.063ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Normalize the verb score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a4c885afdd1366d5.svg\" alt=\"P(V\\mid book)=0.20/0.32=0.625\" style=\"width:31.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Verb is more probable in this simplified model: 0.625 versus 0.375.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Two candidate tags have prior-likelihood products 0.06 and 0.14. Find their normalized probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Unnormalized scores s₁=0.06 and s₂=0.14; these are the only candidates.</p><h4>To find</h4><p>The two posterior probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3f5210a24ca75d45.svg\" alt=\"P_i=s_i/(s_1+s_2)\" style=\"width:16.765ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A common denominator converts the candidate scores to a distribution summing to one.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Add scores</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/67c63d0fb7e2a504.svg\" alt=\"0.06+0.14=0.20\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Normalize first</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8d4386c048d353e.svg\" alt=\"0.06/0.20=0.3\" style=\"width:15.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Normalize second</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/593a5443e39d17c3.svg\" alt=\"0.14/0.20=0.7\" style=\"width:15.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Posterior probabilities are 0.3 and 0.7.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Generative: tag se word ka model. Discriminative: word se tag ka decision.</p>"}]},{"id":"m2-hmm","title":"Markov chains and Hidden Markov Models","unit":4,"scope":"Unit 4, pages 47–73","sections":[{"id":"markov-chain","title":"Markov chains: read a transition table and multiply a path","html":"<p><strong>A Markov chain</strong> is a probabilistic model of a sequence of states. Under the first-order Markov assumption, the next state's probability depends on the current state rather than the complete previous history. The <strong>initial probability</strong> tells us how likely each first state is. A <strong>transition probability</strong> tells us how likely a move from one state to another is.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c9611ed107ec9047.svg\" alt=\"P(s_t\\mid s_1,\\ldots,s_{t-1})=P(s_t\\mid s_{t-1})\" style=\"width:32.192ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e50f813caaa8d825.svg\" alt=\"P(s_1,\\ldots,s_T)=P(s_1)\\prod_{t=2}^{T}P(s_t\\mid s_{t-1})\" style=\"width:36.137ex;height:6.73ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For T states in a path, use one initial factor and T−1 transition factors. A row-oriented transition matrix must have each complete row sum to 1. Always read the row/column labels; some exam diagrams use a transposed arrangement.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><section class=\"example\"><p class=\"question\"><strong>Question. For the Rain/Dry Markov chain with initial P(Rain)=0.4 and P(Dry)=0.6, and transitions Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8, find the probability of Dry, Dry, Rain, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Dry,Dry,Rain,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d6fc24a22e2f64d.svg\" alt=\"P(D,D,R,R)=P(D)P(D\\mid D)P(R\\mid D)P(R\\mid R)\" style=\"width:48.815ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each step conditions on the immediately preceding state. The sequence contains four states, so it needs one initial plus three transition factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start in Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cf847b7db44f5fad.svg\" alt=\"P(D)=0.6\" style=\"width:11.241ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move Dry to Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5e47f480eb58213.svg\" alt=\"0.6\\times0.8=0.48\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move Dry to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0e4bbd812b1ba4d.svg\" alt=\"0.48\\times0.2=0.096\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Rain to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/da540845c4cc326e.svg\" alt=\"0.096\\times0.3=0.0288\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.0288.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For initial probabilities Rain=0.4, Dry=0.6 and transition rows Rain=(0.3,0.7), Dry=(0.2,0.8) in column order Rain,Dry, find the probability of Rain, Dry, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Rain,Dry,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c4b2bba9bbf4c148.svg\" alt=\"P(R,D,R)=P(R)P(D\\mid R)P(R\\mid D)\" style=\"width:36.844ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Do not replace Dry→Rain with Rain→Dry: the two directional probabilities differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/634e8d0183974542.svg\" alt=\"P(R)=0.4\" style=\"width:11.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ff067547e9b897f.svg\" alt=\"P(D\\mid R)=0.7,\\quad0.4(0.7)=0.28\" style=\"width:32.695ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Second transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ca3a09e7de1ba004.svg\" alt=\"P(R\\mid D)=0.2,\\quad0.28(0.2)=0.056\" style=\"width:34.958ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same fully specified chain—initial Rain=0.4, Dry=0.6; Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8—find P(Dry,Dry). Also find the conditional probability of next Dry given current Dry.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>The two-state joint probability and the one-step conditional probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83080c3651cd8fc6.svg\" alt=\"P(D,D)=P(D)P(D\\mid D)\" style=\"width:25.653ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The joint path includes an uncertain initial state. The conditional transition assumes the current state is already Dry.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Read the conditional transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1cf8b238b738730b.svg\" alt=\"P(D\\mid D)=0.8\" style=\"width:15ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Include the initial state for the joint path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/21b9a2b02a067056.svg\" alt=\"P(D,D)=0.6\\times0.8=0.48\" style=\"width:26.817ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(Dry,Dry)=0.48; P(next Dry|current Dry)=0.8. These answer different questions.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Path: pehle start probability, phir har arrow ki probability.</p></section>"},{"id":"hmm-components","title":"Hidden states, observations, transitions and emissions","html":"<p><strong>A Hidden Markov Model (HMM)</strong> is a probabilistic sequence model in which the underlying state sequence is unobserved, while each state emits an observed item. For POS tagging, words are observed and their grammatical tags are hidden. The task is to infer a suitable tag sequence from the words.</p><div class=\"flow\"><div class=\"node\">Hidden: Noun</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Hidden: Verb</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Hidden: Noun</div></div><div class=\"flow\"><div class=\"node\">Observed: birds</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Observed: eat</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Observed: seeds</div></div><p>Horizontal state-to-state links are <strong>transitions</strong>. The relation from each hidden state to its observed word is an <strong>emission</strong>. A transition P(V|N) asks how often a verb tag follows a noun tag. An emission P(eat|V) asks how often the observed word eat appears among verb-tagged tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Component</th><th>Notation</th><th>Meaning</th></tr></thead><tbody><tr><td>State set</td><td>S={N,V,…}</td><td>Possible hidden tags.</td></tr><tr><td>Observation vocabulary</td><td>O={birds,eat,seeds,…}</td><td>Visible word tokens.</td></tr><tr><td>Initial distribution</td><td>πⱼ=P(t₁=j)</td><td>Probability of starting in tag j.</td></tr><tr><td>Transition matrix</td><td>aᵢⱼ=P(tₖ=j|tₖ₋₁=i)</td><td>Probability of next tag j after i.</td></tr><tr><td>Emission matrix</td><td>bⱼ(w)=P(w|tag j)</td><td>Probability that state j emits word w.</td></tr></tbody></table></div><p>Two basic assumptions are used: the current hidden state depends only on the previous hidden state, and the current observation depends only on the current hidden state. A standard first-order HMM therefore does not explicitly condition an emitted word on the whole sentence.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8849ce22bc4d03e.svg\" alt=\"P(t_{1:T},w_{1:T})=\\pi_{t_1}b_{t_1}(w_1)\\prod_{k=2}^{T}a_{t_{k-1},t_k}b_{t_k}(w_k)\" style=\"width:40.971ex;height:6.775ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read the formula as <strong>start × first emission × transition × emission × transition × emission…</strong>. There are T emission factors and T−1 transitions, plus one initial factor. If the question supplies an explicit end-state probability, multiply that too. Do not invent an end factor when the model has none.</p><p><strong>Three different questions.</strong> (1) Scoring a specified tag path uses the joint product above. (2) Finding the probability of the observed words sums scores over all possible tag paths. (3) Finding the best tag path maximizes the path score, typically using Viterbi. A joint path score is not a normalized posterior P(tags|words).</p><p class=\"cue\"><strong>Yaad rakho:</strong> Transition = tag se agla tag. Emission = tag se visible word.</p>"},{"id":"transition-emission-estimation","title":"Estimate transition and emission probabilities from tagged data","html":"<div class=\"equation\"><div class=\"math-display\"><img src=\"math/2145c612575540f3.svg\" alt=\"P(t&#39;\\mid t)=\\frac{C(t,t&#39;)}{C(t)\\text{ with a following tag/end event}}\" style=\"width:46.275ex;height:5.495ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a89d9641a3681129.svg\" alt=\"P(w\\mid t)=\\frac{C(w,t)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>In a transition denominator, count the previous tag's outgoing events. In an emission denominator, count all tokens bearing that tag. With explicit end transitions the totals align conveniently. Keep the two numerator types separate: tag→tag counts are not word→tag counts.</p><section class=\"example\"><p class=\"question\"><strong>Question. A tagged corpus contains 116454 determiner tags DT, each counted with an outgoing event. DT is followed by NN 56509 times. Estimate P(NN|DT).</strong></p><div class=\"given\"><h4>Given</h4><p>C(DT)=116454; C(DT,NN)=56509.</p><h4>To find</h4><p>The DT→NN transition probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5163e6a68004bc8.svg\" alt=\"P(NN\\mid DT)=C(DT,NN)/C(DT)\" style=\"width:35.893ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The denominator is the number of previous DT contexts because DT is the condition.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the transition count</h5><p>DT followed by NN occurs 56509 times.</p></div><div class=\"step\"><h5>Step 2. Identify the conditional total</h5><p>There are 116454 DT contexts.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/47e9bc9d8bc16788.svg\" alt=\"P(NN\\mid DT)=\\frac{56509}{116454}\\approx0.485247\" style=\"width:35.194ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(NN|DT)≈0.485247.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The tag VBZ occurs 21627 times, and 10073 of those tokens are the word “is”. Estimate P(is|VBZ).</strong></p><div class=\"given\"><h4>Given</h4><p>C(VBZ)=21627; C(is,VBZ)=10073.</p><h4>To find</h4><p>The emission probability of is from VBZ.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ec13ac6a8a9bdae.svg\" alt=\"P(is\\mid VBZ)=C(is,VBZ)/C(VBZ)\" style=\"width:36.42ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The condition is the tag VBZ; we ask which word it emits.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Choose the word-tag count</h5><p>The required word is is with tag VBZ: count 10073.</p></div><div class=\"step\"><h5>Step 2. Choose the tag total</h5><p>All VBZ-tagged word tokens: count 21627.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/481557575db95324.svg\" alt=\"P(is\\mid VBZ)=\\frac{10073}{21627}\\approx0.465760\" style=\"width:33.513ex;height:4.661ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(is|VBZ)≈0.465760. This is different from P(VBZ|is).</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use the tagged sentences “dogs/N chase/V cats/N” and “cats/N sleep/V”. Estimate the initial tag probabilities, all nonzero transitions including END, and emissions.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: START dogs/N chase/V cats/N END; START cats/N sleep/V END.</p><h4>To find</h4><p>Initial distribution, transition rows and emission rows.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/46d6d50083ab5629.svg\" alt=\"\\pi_t=C(START,t)/2,\\quad a_{tu}=C(t,u)/C(t),\\quad b_t(w)=C(w,t)/C(t)\" style=\"width:65.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The corpus explicitly tells us the tags, so we can count training frequencies directly.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count tag tokens</h5><p>N occurs 3 times: dogs, cats, cats. V occurs 2 times: chase, sleep.</p></div><div class=\"step\"><h5>Step 2. Count sentence starts</h5><p>Both sentences start with N.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a5ae0d0edad4515.svg\" alt=\"\\pi_N=2/2=1,\\quad \\pi_V=0/2=0\" style=\"width:29.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>N→V</td><td>2</td></tr><tr><td>N→END</td><td>1</td></tr><tr><td>V→N</td><td>1</td></tr><tr><td>V→END</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 4. Normalize transition rows</h5><div class=\"table-wrap\"><table><thead><tr><th>Current</th><th>To N</th><th>To V</th><th>To END</th></tr></thead><tbody><tr><td>N</td><td>0</td><td>2/3</td><td>1/3</td></tr><tr><td>V</td><td>1/2</td><td>0</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Count and normalize emissions</h5><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>dogs</th><th>cats</th><th>chase</th><th>sleep</th></tr></thead><tbody><tr><td>N</td><td>1/3</td><td>2/3</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/2</td><td>1/2</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> π=(1,0); transitions and emissions are given in the completed tables. Each complete probability row sums to 1.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Tag→tag table aur tag→word table ko mix mat karna.</p>"},{"id":"hot-cold-paths","title":"HMM path probabilities: three complete numerical examples","html":"<p>The following model uses hidden weather states Hot (H) and Cold (C). Observations are numbers 1, 2 and 3. These numbers are observation labels, not quantities to multiply directly. Their emission probabilities come from the table.</p><div class=\"table-wrap\"><table><thead><tr><th>Initial state</th><th>Probability</th></tr></thead><tbody><tr><td>H</td><td>0.8</td></tr><tr><td>C</td><td>0.2</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>From → to</th><th>H</th><th>C</th></tr></thead><tbody><tr><td>H</td><td>0.7</td><td>0.3</td></tr><tr><td>C</td><td>0.4</td><td>0.6</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Emission state</th><th>Observation 1</th><th>Observation 2</th><th>Observation 3</th></tr></thead><tbody><tr><td>H</td><td>0.2</td><td>0.4</td><td>0.4</td></tr><tr><td>C</td><td>0.5</td><td>0.4</td><td>0.1</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for observations (1,2,3) are H:(0.2,0.4,0.4) and C:(0.5,0.4,0.1). Find the joint probability of hidden path H,C,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path H→C→H. Observations 1→3→1. Model probabilities are specified in the question. There is no END factor.</p><h4>To find</h4><p>P(H,C,H; 1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d9c99617b5e16c0.svg\" alt=\"P=\\pi_H b_H(1)a_{HC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.863ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>There are three hidden states and observations: three emissions, two transitions, and one initial probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Hot and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/78369e147be76567.svg\" alt=\"0.8\\times0.2=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Transition Hot to Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/24d6c09c3069c91f.svg\" alt=\"0.16\\times0.3=0.048\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Cold emits 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/59bb445235ff63a6.svg\" alt=\"0.048\\times0.1=0.0048\" style=\"width:20.113ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Transition Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1146803e8605f2e.svg\" alt=\"0.0048\\times0.4=0.00192\" style=\"width:22.376ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Hot emits the last 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e3b740dc0fd787f.svg\" alt=\"0.00192\\times0.2=0.000384\" style=\"width:24.638ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.000384 = 3.84×10⁻⁴.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels (1,2,3), find the joint probability of path H,H,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>State path H→H→H, observations 1→3→1; no END factor.</p><h4>To find</h4><p>P(H,H,H;1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83f5cb754dc77195.svg\" alt=\"P=\\pi_H b_H(1)a_{HH}b_H(3)a_{HH}b_H(1)\" style=\"width:32.477ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The state remains Hot; each transition still contributes its probability 0.7.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial state and first emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/806228a802bab106.svg\" alt=\"0.8(0.2)=0.16\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f1106c30e00cc2ce.svg\" alt=\"0.16(0.7)=0.112\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/359ae9ea2534c8f2.svg\" alt=\"0.112(0.4)=0.0448\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Second self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d2be9254f3d2eee1.svg\" alt=\"0.0448(0.7)=0.03136\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit final observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/af971b25ad6922c0.svg\" alt=\"0.03136(0.2)=0.006272\" style=\"width:23.632ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.006272. A self-transition is not automatically probability 1.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6) in next-state order H,C; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3, find the score of path C,C,H with observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path C→C→H. Observation sequence 1→3→1. No end-state factor.</p><h4>To find</h4><p>The joint path-and-observation probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c39dbc8fa9b14a01.svg\" alt=\"P=\\pi_C b_C(1)a_{CC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.248ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The initial state is Cold, so use π(C), not π(H). Each emission is selected from the state at the same position.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Cold and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ea1ebd665b713576.svg\" alt=\"0.2(0.5)=0.1\" style=\"width:13.451ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Stay Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3af50c5661f75952.svg\" alt=\"0.1(0.6)=0.06\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit 3 from Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2039ca068efac123.svg\" alt=\"0.06(0.1)=0.006\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99539fe7f4612c73.svg\" alt=\"0.006(0.4)=0.0024\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit 1 from Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/315780f838015183.svg\" alt=\"0.0024(0.2)=0.00048\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.00048.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har column par: state ka emission. Columns ke beech: transition.</p></section>"},{"id":"tagging-corpus-case","title":"POS HMM worked corpus: Mary, Jane, can, will and spot","html":"<p>The class example contains words that can be either names or ordinary verbs/modal auxiliaries. The term is <strong>modal</strong> (M), not “model”. To avoid guessing tags from spelling, the training corpus below supplies them explicitly and lowercases words for the emission vocabulary.</p><div class=\"table-wrap\"><table><thead><tr><th>Training sentence</th><th>Gold tags</th></tr></thead><tbody><tr><td>mary jane can see will</td><td>N N M V N</td></tr><tr><td>spot will see mary</td><td>N M V N</td></tr><tr><td>will jane spot mary</td><td>M N V N</td></tr><tr><td>mary will pat spot</td><td>N M V N</td></tr></tbody></table></div><p>There are 9 noun tokens, 4 modal tokens and 4 verb tokens. Each sentence includes a start and end transition. For nouns, the next event can be another noun, modal, verb or END.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>N</th><th>M</th><th>V</th><th>END</th></tr></thead><tbody><tr><td>START</td><td>3/4</td><td>1/4</td><td>0</td><td>0</td></tr><tr><td>N</td><td>1/9</td><td>3/9</td><td>1/9</td><td>4/9</td></tr><tr><td>M</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td></tr><tr><td>V</td><td>4/4</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Tag → word</th><th>mary</th><th>jane</th><th>can</th><th>see</th><th>will</th><th>spot</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>4/9</td><td>2/9</td><td>0</td><td>0</td><td>1/9</td><td>2/9</td><td>0</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>0</td><td>2/4</td><td>0</td><td>1/4</td><td>1/4</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Using the fully tagged four-sentence corpus above, calculate the joint score of “will jane spot mary” assigned tags M,N,V,N, including END.</strong></p><div class=\"given\"><h4>Given</h4><p>Required factors from the tables: START→M=1/4; emit will|M=3/4; M→N=1/4; jane|N=2/9; N→V=1/9; spot|V=1/4; V→N=1; mary|N=4/9; N→END=4/9.</p><h4>To find</h4><p>The specified tag-path score, including words and sentence end.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/23c70e8086b83a3b.svg\" alt=\"P=\\pi_M b_M(will)a_{MN}b_N(jane)a_{NV}b_V(spot)a_{VN}b_N(mary)a_{N,END}\" style=\"width:62.792ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both transitions and emissions are needed. A tag transition alone cannot tell us whether a particular word is plausible.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start and emit will</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a7d30f8cd240d72.svg\" alt=\"\\frac14\\times\\frac34=\\frac3{16}\" style=\"width:13.294ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move to N and emit jane</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/934eaa8bf4f9d42a.svg\" alt=\"\\frac3{16}\\times\\frac14\\times\\frac29=\\frac1{96}\" style=\"width:19.318ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move to V and emit spot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/40b213c06ef8b7d2.svg\" alt=\"\\frac1{96}\\times\\frac19\\times\\frac14=\\frac1{3456}\" style=\"width:21.58ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move to N and emit mary</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a0e9571f3b95594c.svg\" alt=\"\\frac1{3456}\\times1\\times\\frac49=\\frac1{7776}\" style=\"width:22.847ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/171a6c8b22e17d35.svg\" alt=\"\\frac1{7776}\\times\\frac49=\\frac1{17496}\\approx0.0000571559\" style=\"width:36.171ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The joint score is 1/17496 ≈ 0.0000571559.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same tagged corpus and tables, explain the unsmoothed score of “will can spot mary” assigned tags M,V,N,N.</strong></p><div class=\"given\"><h4>Given</h4><p>The proposed second word is can with hidden tag V. In the training corpus, can occurs only with M, so b_V(can)=0.</p><h4>To find</h4><p>Whether the complete path score is zero and what this means.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0957b6ab0a1aa0cc.svg\" alt=\"P(\\text{path,words})=(\\text{other required factors})\\times b_V(can)\" style=\"width:50.674ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A product containing one zero factor is zero even if every other factor is positive.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the critical emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fdca0f8e7f8d838a.svg\" alt=\"b_V(can)=C(can,V)/C(V)=0/4=0\" style=\"width:37.369ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the full-product consequence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e316f36777dd5.svg\" alt=\"P(\\text{path,words})=0\" style=\"width:18.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Interpret correctly</h5><p>This unsmoothed corpus model has no evidence for can as a verb. It does not prove that a verb usage of can is impossible in English.</p></div><div class=\"answer\"><strong>Final answer.</strong> The unsmoothed path score is zero.</div></section>"}]},{"id":"m2-hmm-decoding","title":"Choosing the most likely tag sequence","unit":4,"scope":"Unit 4 page 73: Viterbi motivation, explained with small worked extensions","sections":[{"id":"sequence-count","title":"Why exhaustive search grows exponentially","html":"<p>If each of T observed words can receive any of N tags, there are N choices at each position. Thus the total number of complete tag sequences is N multiplied by itself T times. This counts possible assignments before grammar rules or zero probabilities eliminate any.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/014ed66c3c0df2b1.svg\" alt=\"\\text{Number of tag sequences}=N^T\" style=\"width:30.626ex;height:2.484ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A four-word sentence is tagged using three possible POS tags per word. How many complete tag sequences are possible?</strong></p><div class=\"given\"><h4>Given</h4><p>N=3 possible tags per position; T=4 word positions.</p><h4>To find</h4><p>The number of tag sequences.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every independent position contributes a factor of three choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write one factor per position</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d7b06b7e39ae0a5.svg\" alt=\"M=3\\times3\\times3\\times3\" style=\"width:18.217ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6570633fef12ecb5.svg\" alt=\"3\\times3=9,\\quad9\\times3=27,\\quad27\\times3=81\" style=\"width:37.46ex;height:1.968ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 81 possible tag sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A five-word sentence has two candidate tags per word. Count its tag sequences.</strong></p><div class=\"given\"><h4>Given</h4><p>N=2; T=5.</p><h4>To find</h4><p>M.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The length is the exponent, not a multiplier.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Substitute</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e0b25a2374d09c2d.svg\" alt=\"M=2^5\" style=\"width:7.514ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/85ec03497588b6d5.svg\" alt=\"2\\times2\\times2\\times2\\times2=32\" style=\"width:21.998ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 32 possible sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using 45 possible tags, compare the number of tag sequences for sentences of length 2 and 3.</strong></p><div class=\"given\"><h4>Given</h4><p>N=45. First T=2, then T=3.</p><h4>To find</h4><p>Both counts and the growth factor.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0806abcd5d0a43e.svg\" alt=\"M_2=45^2,\\quad M_3=45^3\" style=\"width:22.167ex;height:2.439ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Adding one position multiplies the possibilities by the number of tag choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Two words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/672617aa8909800b.svg\" alt=\"45^2=2025\" style=\"width:10.792ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Three words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/96a0c5c55e4f8048.svg\" alt=\"45^3=2025\\times45=91125\" style=\"width:24.493ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3daee8fcfcc1adea.svg\" alt=\"91125/2025=45\" style=\"width:16.592ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 2 words: 2025 paths. 3 words: 91125 paths. One additional word multiplies the count by 45.</div></section><p>The slides introduce Viterbi to avoid enumerating every path. It reuses the best prefix score for each ending state. For a dense first-order HMM, it needs O(TN²) recurrence work instead of enumerating N<sup>T</sup> complete paths.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Choices per word ki power = sentence length.</p>"},{"id":"viterbi-explained","title":"Viterbi decoding: compare incoming paths, keep the best, trace back","html":"<p><strong>The Viterbi algorithm</strong> finds the most likely hidden-state sequence for a fixed observation sequence. At each position, it keeps the best path ending in each state. This is safe because, under the HMM assumptions, future extensions depend on that ending state, not the discarded details of the prefix.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3fa79f3d8232431.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1)\" style=\"width:15.501ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50951d9d0cf5dcf6.svg\" alt=\"\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:27.716ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3935aac800940d84.svg\" alt=\"\\psi_t(j)=\\arg\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:25.893ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning in ordinary words</th></tr></thead><tbody><tr><td>δₜ(j)</td><td>Score of the best prefix that ends in state j at position t.</td></tr><tr><td>ψₜ(j)</td><td>Previous state that supplied that best prefix; keep it as a backpointer.</td></tr><tr><td>max</td><td>Choose the larger candidate score; do not add.</td></tr><tr><td>argmax</td><td>Remember which previous state won, rather than only its value.</td></tr></tbody></table></div><div class=\"flow\"><div class=\"node\">Initialize: start × first emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">For each next state: compare incoming scores</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Multiply winner by this state's emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Keep score + winning predecessor</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose best final state and trace arrows backward</div></div><p>Do not choose the best state independently at each word. The best last state can come from a different best predecessor than a local guess. Backpointers recover one consistent complete path. If scores tie, either tied path is optimal under the model; state the tie.</p><section class=\"example\"><p class=\"question\"><strong>Question. Use an HMM with π(H)=0.8, π(C)=0.2, transitions H:(0.7,0.3), C:(0.4,0.6) in H,C order, and emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3. Find the most likely hidden path for observations 1,3,1 using Viterbi.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>The best hidden-state sequence and its joint score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/712c98f9c4966f84.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1),\\quad\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:46.485ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Viterbi keeps two best prefix scores per column, one ending H and one ending C.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize at observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/44fc29f14406bbca.svg\" alt=\"\\delta_1(H)=0.8(0.2)=0.16\" style=\"width:23.361ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1500f80244db39b.svg\" alt=\"\\delta_1(C)=0.2(0.5)=0.10\" style=\"width:23.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. At observation 3, calculate the H cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/61623e2cd024bab3.svg\" alt=\"H\\to H:\\ 0.16(0.7)=0.112\" style=\"width:26.834ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/256055f1b5c81a60.svg\" alt=\"C\\to H:\\ 0.10(0.4)=0.040\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ee04f7fda3bf226b.svg\" alt=\"\\delta_2(H)=\\max(0.112,0.040)(0.4)=0.0448\" style=\"width:40.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this H cell: H.</p></div><div class=\"step\"><h5>Step 3. At observation 3, calculate the C cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e9c32ed85546537.svg\" alt=\"H\\to C:\\ 0.16(0.3)=0.048\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c0863275b12a91e.svg\" alt=\"C\\to C:\\ 0.10(0.6)=0.060\" style=\"width:26.255ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a8ea78adb0cc4576.svg\" alt=\"\\delta_2(C)=\\max(0.048,0.060)(0.1)=0.006\" style=\"width:38.596ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this C cell: C.</p></div><div class=\"step\"><h5>Step 4. At final observation 1, calculate H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e2373be2aa769a8.svg\" alt=\"H\\to H:\\ 0.0448(0.7)=0.03136\" style=\"width:31.359ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/286832c2c26620dd.svg\" alt=\"C\\to H:\\ 0.006(0.4)=0.0024\" style=\"width:28.807ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/48b05bab6b13e38a.svg\" alt=\"\\delta_3(H)=0.03136(0.2)=0.006272\" style=\"width:32.411ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 5. At final observation 1, calculate C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5f431d2a23d6fe1.svg\" alt=\"H\\to C:\\ 0.0448(0.3)=0.01344\" style=\"width:31.069ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b69919a26d75a560.svg\" alt=\"C\\to C:\\ 0.006(0.6)=0.0036\" style=\"width:28.517ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/709ea0da7f36d663.svg\" alt=\"\\delta_3(C)=0.01344(0.5)=0.00672\" style=\"width:30.99ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 6. Select the final state</h5><p>0.00672 > 0.006272, so the best final state is C.</p></div><div class=\"step\"><h5>Step 7. Trace back</h5><p>Final C came from H at position2. That H came from H at position1. Reading forward gives H,H,C.</p></div><div class=\"step\"><h5>Step 8. Verify the recovered complete path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5aa4b0fd88f37247.svg\" alt=\"0.8(0.2)(0.7)(0.4)(0.3)(0.5)=0.00672\" style=\"width:36.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H→C with joint score 0.00672.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best two-state hidden path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/801327bb8fdbd394.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(3),\\quad\\delta_2(j)=b_j(1)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same recurrence applies even though the observation order changed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2e38d10b83c569f4.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.1)=0.02\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1716d45167a355a0.svg\" alt=\"\\max(0.32(0.7),0.02(0.4))(0.2)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4db3393304c21c23.svg\" alt=\"=\\max(0.224,0.008)(0.2)=0.0448\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 3. Calculate the final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bd4ebf48e761f108.svg\" alt=\"\\max(0.32(0.3),0.02(0.6))(0.5)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15d2f168f4fe9604.svg\" alt=\"=\\max(0.096,0.012)(0.5)=0.048\" style=\"width:32.495ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>Final C wins with 0.048 and came from H. The path is H,C.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→C, score 0.048.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 2,2.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a478f4924f42dec2.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(2),\\quad\\delta_2(j)=b_j(2)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both states emit2 with probability 0.4, but their initial and transition probabilities still differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/56ea5abfdb65b387.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.4)=0.08\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75472da37ba442a1.svg\" alt=\"\\max(0.32(0.7),0.08(0.4))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f9a0610a246e0ed0.svg\" alt=\"=\\max(0.224,0.032)(0.4)=0.0896\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 3. Final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/87b9dd83765528d1.svg\" alt=\"\\max(0.32(0.3),0.08(0.6))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/088fd26aaafea320.svg\" alt=\"=\\max(0.096,0.048)(0.4)=0.0384\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>The final H score 0.0896 is larger. Its predecessor is H.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H with score 0.0896.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har destination ke liye incoming paths compare; winner ka arrow yaad.</p></section>"},{"id":"joint-vs-posterior","title":"A path score is not the probability of the observed sentence","html":"<section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3. For observations 1,3, calculate the probability of the observations by summing all four two-state paths.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>P(observations 1,3), not just the best-path score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e591ebf359dce.svg\" alt=\"P(o_1,o_2)=\\sum_{s_1,s_2}\\pi_{s_1}b_{s_1}(o_1)a_{s_1s_2}b_{s_2}(o_2)\" style=\"width:35.484ex;height:5.061ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The hidden path is unspecified, so its mutually exclusive alternatives must be summed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score H,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c316d3e7d10ea4e8.svg\" alt=\"0.8(0.2)(0.7)(0.4)=0.0448\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Score H,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/076745077c7c6109.svg\" alt=\"0.8(0.2)(0.3)(0.1)=0.0048\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Score C,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2dbad158b7e2df38.svg\" alt=\"0.2(0.5)(0.4)(0.4)=0.016\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Score C,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/595d09221813b65c.svg\" alt=\"0.2(0.5)(0.6)(0.1)=0.006\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Add all paths</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2b05babdadbfdf90.svg\" alt=\"P(1,3)=0.0448+0.0048+0.016+0.006=0.0716\" style=\"width:50.222ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Observation probability =0.0716. The best single-path score 0.0448 is a different quantity.</div></section><p>If asked for the posterior of path H,H given observations 1,3, normalize: 0.0448/0.0716 ≈0.625698. Viterbi chooses the best path using joint scores because the observation denominator is common to every candidate. It does not compute that denominator by taking a maximum.</p>"}]},{"id":"m2-chunks-grammar","title":"Chunking, chinking and context-free grammar","unit":4,"scope":"Unit 4, pages 14–19, 74–97","sections":[{"id":"chunking-chinking","title":"Chunking groups words; chinking removes words from a candidate chunk","html":"<p><strong>Chunking</strong>, also called shallow parsing, groups adjacent tagged words into meaningful non-overlapping units, commonly noun phrases. It usually identifies local phrase boundaries without producing the complete hierarchical structure of a sentence. <strong>Chinking</strong> removes specified tokens from an existing candidate chunk, splitting or trimming it.</p><div class=\"flow\"><div class=\"node\">The/DT small/JJ cat/NN sat/VBD on/IN the/DT mat/NN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [The small cat]</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Outside: sat on</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [the mat]</div></div><p>A POS tagger labels individual words. A chunker groups words into phrases. A full parser shows how phrases relate recursively to form the entire sentence. These are related tasks with different outputs.</p><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>POS tagging</td><td>The small cat</td><td>The/DT small/JJ cat/NN</td></tr><tr><td>NP chunking</td><td>Tagged tokens</td><td>[NP The small cat]</td></tr><tr><td>Chinking</td><td>A broad candidate chunk</td><td>Remove verbs/prepositions, keep noun-phrase segments</td></tr><tr><td>Full parsing</td><td>Sentence + grammar</td><td>A nested tree with sentence, noun phrase and verb phrase nodes</td></tr></tbody></table></div><p><strong>Rule-based chunking</strong> uses tag patterns. Statistical or learned chunkers infer boundaries from labeled examples. A useful NP rule is an optional determiner, followed by zero or more adjectives, followed by a noun. In NLTK-style notation: <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;}</code>. Here ? means zero or one occurrence; * means zero or more; + means one or more when used. The braces mean “form a chunk around the matched sequence”.</p><section class=\"example\"><p class=\"question\"><strong>Question. Apply the NP rule optional DT, zero or more JJ, then one NN to “The/DT quick/JJ brown/JJ fox/NN jumps/VBZ over/IN the/DT lazy/JJ dog/NN”.</strong></p><div class=\"given\"><h4>Given</h4><p>Tagged input is supplied. Rule: DT? JJ* NN.</p><h4>To find</h4><p>All noun-phrase chunks.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The rule groups a noun with its preceding determiner and adjectives; a verb or preposition does not match this NP pattern.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start at The</h5><p>The matches optional DT; quick and brown both match JJ*; fox matches NN.</p></div><div class=\"step\"><h5>Step 2. Form the first NP</h5><p><strong>[NP The quick brown fox]</strong></p></div><div class=\"step\"><h5>Step 3. Skip nonmatching tokens</h5><p>jumps/VBZ and over/IN do not satisfy the NP pattern.</p></div><div class=\"step\"><h5>Step 4. Match the second NP</h5><p>the is DT, lazy is JJ, dog is NN: <strong>[NP the lazy dog]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> [NP The quick brown fox] jumps over [NP the lazy dog].</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using NP → DT? JJ* NN, identify the chunks in “bright/JJ stars/NN shine/VBP and/CC a/DT moon/NN glows/VBZ”. Use the supplied tags exactly.</strong></p><div class=\"given\"><h4>Given</h4><p>Input tags label stars as NN for this exercise. Rule requires optional DT, zero or more JJ, then NN.</p><h4>To find</h4><p>The matched NP spans.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The optional determiner may be absent and the adjective repetition may be empty.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Match bright stars</h5><p>No determiner is present, which DT? permits. bright matches JJ; stars matches NN.</p></div><div class=\"step\"><h5>Step 2. Inspect shine and and</h5><p>VBP and CC fall outside the NP rule.</p></div><div class=\"step\"><h5>Step 3. Match a moon</h5><p>a matches DT; no adjective is present; moon matches NN.</p></div><div class=\"answer\"><strong>Final answer.</strong> Chunks are [NP bright stars] and [NP a moon]. With ordinary Penn tagging, stars is usually NNS; broaden the noun pattern to include NNS when that tag is used.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Begin with one candidate chunk containing “The/DT cat/NN sat/VBD on/IN the/DT mat/NN”. Chink out verbs and prepositions. Show the remaining chunks.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial candidate: [The cat sat on the mat]. Remove tags VBD and IN.</p><h4>To find</h4><p>The chunk segments after exclusion.</p></div><h4>Formula and why it applies</h4><p>Chinking removes matched tokens from the existing chunk.</p><p>Removing the middle verb/preposition region divides the original candidate into two remaining contiguous spans.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the tokens to remove</h5><p>sat is VBD and on is IN.</p></div><div class=\"step\"><h5>Step 2. Remove those tokens from chunk membership</h5><p>The remaining token groups are “The cat” and “the mat”. sat and on still exist in the sentence; they are simply outside these chunks.</p></div><div class=\"step\"><h5>Step 3. Write the final chunked sentence</h5><p><strong>[The cat]</strong> sat on <strong>[the mat]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> Two chunks remain: The cat; the mat.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Chunking = andar group karo; chinking = unwanted tokens ko group se bahar karo.</p></section>"},{"id":"cfg-foundation","title":"CFG: terminals, nonterminals, production rules and parse trees","html":"<p><strong>A context-free grammar (CFG)</strong> specifies a language using production rules whose left side is a single nonterminal. Formally, G=(N,Σ,R,S): N is the set of nonterminals, Σ the terminal vocabulary, R the production rules, and S the start symbol. A rule can expand its nonterminal regardless of the neighboring symbols; that is the meaning of “context-free”.</p><div class=\"table-wrap\"><table><thead><tr><th>Concept</th><th>Plain explanation</th><th>Example</th></tr></thead><tbody><tr><td>Terminal</td><td>A word at a leaf; it is not expanded further</td><td>the, girl, read</td></tr><tr><td>Nonterminal</td><td>A grammatical category that can be expanded</td><td>S, NP, VP, Det, N, V</td></tr><tr><td>Production</td><td>A permitted replacement</td><td>S → NP VP</td></tr><tr><td>Start symbol</td><td>Category for a complete sentence</td><td>S</td></tr><tr><td>Lexicon</td><td>Word-to-category rules</td><td>N → girl | paper</td></tr><tr><td>Derivation</td><td>Sequence of rule applications</td><td>S ⇒ NP VP ⇒ Det N VP ⇒ …</td></tr><tr><td>Parse tree</td><td>Hierarchical picture of those expansions</td><td>Root S, internal phrases, word leaves</td></tr></tbody></table></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/08274dbc564789d5.svg\" alt=\"S\\to NP\\ VP,\\quad NP\\to Det\\ N,\\quad VP\\to V\\ NP\" style=\"width:45.747ex;height:2.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read S→NP VP as “a sentence can contain a noun phrase followed by a verb phrase”. It does not mean subtraction or multiplication. A vertical bar in a grammar rule means alternatives: Det→the | a allows either the or a. This is different from the probability bar meaning “given”.</p><div class=\"flow\"><div class=\"node\">S: the whole sentence</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: the girl  +  VP: read the paper</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP→Det N; VP→V NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Leaves in order: the / girl / read / the / paper</div></div><p><strong>A constituent</strong> is a group of words that acts as a grammatical unit, such as “the girl”. <strong>Syntactic parsing</strong> assigns a grammatical structure to an input sentence using a grammar. It can support grammar checking, information extraction, translation and later semantic analysis. Failure under one restricted grammar means that grammar could not derive the sentence; it does not necessarily prove the sentence is invalid English.</p><p><strong>A treebank</strong> is a corpus annotated with parse trees. It supplies training/evaluation structures for parsers and lets linguists study recurring syntactic patterns. A tagged corpus gives word tags; a treebank additionally records relationships among phrases.</p><div class=\"table-wrap\"><table><thead><tr><th>Representation</th><th>Example information retained</th></tr></thead><tbody><tr><td>Bag of words</td><td>Words occur, but word order/grammar is lost</td></tr><tr><td>POS tags</td><td>Each word's local grammatical category</td></tr><tr><td>Chunks</td><td>Short phrase boundaries</td></tr><tr><td>Parse tree</td><td>Nested constituent structure of the whole sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Grammar rule ek expansion instruction hai: S ko NP aur VP mein kholo.</p>"},{"id":"structural-ambiguity","title":"Ambiguity and grammar coverage","html":"<p><strong>Structural ambiguity</strong> occurs when a sentence has more than one valid parse tree. In “I saw the man with a telescope”, the prepositional phrase “with a telescope” can attach to saw (the instrument I used) or to the man (the man possessing the telescope). The words and their order stay the same, but the grouping changes.</p><div class=\"table-wrap\"><table><thead><tr><th>Reading</th><th>Attachment</th><th>Meaning</th></tr></thead><tbody><tr><td>I [saw the man] [with a telescope]</td><td>PP modifies VP</td><td>I used a telescope to see the man.</td></tr><tr><td>I saw [the man with a telescope]</td><td>PP modifies NP</td><td>The man had a telescope.</td></tr></tbody></table></div><p>A parser may need context, probabilities or semantic constraints to choose between trees. A plain CFG describes permitted structures but does not itself assign a probability to each tree. Do not invent rule probabilities for an ordinary CFG question.</p><p>Lexical ambiguity also matters: book can be a noun or verb. In “Book the flight”, the imperative analysis begins S→VP, followed by VP→V NP. A parser that initially chooses book as a noun may reach a dead end and must try another permitted analysis.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Same words, alag grouping → alag meaning.</p>"}]},{"id":"m2-parsing","title":"Top-down and bottom-up parsing: complete traces","unit":4,"scope":"Unit 4, pages 98–116","sections":[{"id":"top-down-theory","title":"Recursive-descent top-down parsing","html":"<p><strong>Top-down parsing</strong> starts at the grammar's start symbol S and expands nonterminals until the leaves match the input words in order. <strong>Recursive descent</strong> commonly implements each nonterminal as a procedure that tries its productions. It builds from the root toward the leaves.</p><div class=\"flow\"><div class=\"node\">Start with S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose an allowed S production</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Expand its next nonterminal</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match the resulting terminal to the input</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Continue, or backtrack if the choice fails</div></div><p><strong>Algorithm.</strong> Start with S as the current goal. Choose a production for the leftmost unexpanded nonterminal. Replace that nonterminal by the production's right side. If a terminal appears, compare it with the next input token. If it matches, consume the token; if it does not, reject that branch and try another production. Accept only when the complete input is consumed and all grammar goals are satisfied.</p><p>A <strong>leftmost derivation</strong> always expands the leftmost remaining nonterminal first. Top-down parsing can make guesses that the actual words cannot support, so it may need backtracking. A naive recursive-descent parser can loop on left-recursive rules such as NP→NP PP unless the grammar or algorithm is changed. Predictive LL(1) parsing chooses productions using one lookahead token when the grammar permits; not every English CFG is LL(1).</p><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>Begins with</th><th>Direction</th><th>Common difficulty</th></tr></thead><tbody><tr><td>Top-down</td><td>Start symbol S</td><td>Root to word leaves</td><td>Predictions that do not match input; left recursion</td></tr><tr><td>Bottom-up</td><td>Actual input tokens</td><td>Leaves to root S</td><td>Reductions that cannot contribute to a complete sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Top-down: sentence ka structure pehle, words tak neeche aao.</p>"},{"id":"top-down-examples","title":"Three full top-down derivations with parse trees","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Using S→NP VP, NP→Det N, VP→V NP, Det→the, N→girl|paper and V→read, give a leftmost top-down derivation and parse tree for “the girl read the paper”.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Rule type</th><th>Rules</th></tr></thead><tbody><tr><td>Structure</td><td>S → NP VP; NP → Det N; VP → V NP</td></tr><tr><td>Lexicon</td><td>Det → the; N → girl | paper; V → read</td></tr></tbody></table></div><h4>To find</h4><p>A successful derivation and tree whose leaves equal the input.</p></div><h4>Formula and why it applies</h4><p>At every stage expand the leftmost nonterminal using a supplied production.</p><p>A top-down derivation begins at S; the input determines which terminal alternatives can succeed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Begin at the sentence symbol</h5><p>S</p></div><div class=\"step\"><h5>Step 2. Expand the sentence</h5><p>S ⇒ NP VP</p></div><div class=\"step\"><h5>Step 3. Expand its first noun phrase</h5><p>⇒ Det N VP</p></div><div class=\"step\"><h5>Step 4. Match the first determiner</h5><p>⇒ the N VP</p></div><div class=\"step\"><h5>Step 5. Match the subject noun</h5><p>⇒ the girl VP</p></div><div class=\"step\"><h5>Step 6. Expand the verb phrase</h5><p>⇒ the girl V NP</p></div><div class=\"step\"><h5>Step 7. Match the verb</h5><p>⇒ the girl read NP</p></div><div class=\"step\"><h5>Step 8. Expand the object noun phrase</h5><p>⇒ the girl read Det N</p></div><div class=\"step\"><h5>Step 9. Match its determiner</h5><p>⇒ the girl read the N</p></div><div class=\"step\"><h5>Step 10. Match the last noun</h5><p>⇒ the girl read the paper</p></div><div class=\"step\"><h5>Step 11. Draw the tree</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Parse tree: the girl read the paper\" viewBox=\"0 0 560 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Parse tree: the girl read the paper</title><line x1=\"238.75\" y1=\"40\" x2=\"115\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"170\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"238.75\" y1=\"40\" x2=\"362.5\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"362.5\" y1=\"104\" x2=\"280\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"362.5\" y1=\"104\" x2=\"445\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"445\" y1=\"168\" x2=\"390\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"232\" x2=\"390\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"445\" y1=\"168\" x2=\"500\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"500\" y1=\"232\" x2=\"500\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"238.75\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"115\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">the</text><text x=\"170\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">girl</text><text x=\"362.5\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"280\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">read</text><text x=\"445\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"390\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"390\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">the</text><text x=\"500\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"500\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">paper</text></svg></div><figcaption>Parse tree: the girl read the paper</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> The grammar derives the complete sentence. The subject NP is “the girl”; the object NP is “the paper”.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use S→NP VP, NP→Det N|N, VP→V NP, Det→A, N→restaurant|Dosas and V→serves to parse “A restaurant serves Dosas” by a leftmost top-down derivation.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Rule type</th><th>Rules</th></tr></thead><tbody><tr><td>Structure</td><td>S → NP VP; NP → Det N | N; VP → V NP</td></tr><tr><td>Lexicon</td><td>Det → A; N → restaurant | Dosas; V → serves</td></tr></tbody></table></div><h4>To find</h4><p>A derivation and parse tree.</p></div><h4>Formula and why it applies</h4><p>Expand the leftmost nonterminal; choose NP→Det N for the subject and NP→N for the object.</p><p>The object has no determiner, so forcing NP→Det N there would fail.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start and expand S</h5><p>S ⇒ NP VP</p></div><div class=\"step\"><h5>Step 2. Choose the subject NP</h5><p>⇒ Det N VP</p></div><div class=\"step\"><h5>Step 3. Match A</h5><p>⇒ A N VP</p></div><div class=\"step\"><h5>Step 4. Match restaurant</h5><p>⇒ A restaurant VP</p></div><div class=\"step\"><h5>Step 5. Expand the VP</h5><p>⇒ A restaurant V NP</p></div><div class=\"step\"><h5>Step 6. Match serves</h5><p>⇒ A restaurant serves NP</p></div><div class=\"step\"><h5>Step 7. Choose the object NP rule</h5><p>⇒ A restaurant serves N</p></div><div class=\"step\"><h5>Step 8. Match Dosas</h5><p>⇒ A restaurant serves Dosas</p></div><div class=\"step\"><h5>Step 9. Draw the successful tree</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Parse tree: A restaurant serves Dosas\" viewBox=\"0 0 450 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Parse tree: A restaurant serves Dosas</title><line x1=\"225\" y1=\"40\" x2=\"115\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"115\" y1=\"104\" x2=\"170\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"225\" y1=\"40\" x2=\"335\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"335\" y1=\"104\" x2=\"280\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"335\" y1=\"104\" x2=\"390\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"168\" x2=\"390\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"232\" x2=\"390\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"225\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"115\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">A</text><text x=\"170\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">restaurant</text><text x=\"335\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"280\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">serves</text><text x=\"390\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"390\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"390\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">Dosas</text></svg></div><figcaption>Parse tree: A restaurant serves Dosas</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> The parse succeeds with subject NP→Det N and object NP→N.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using S→NP VP|VP, NP→Det N, VP→V NP, Det→that, N→book|flight and V→book, derive the imperative “book that flight” and explain the role of book.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Rule type</th><th>Rules</th></tr></thead><tbody><tr><td>Structure</td><td>S → NP VP | VP; NP → Det N; VP → V NP</td></tr><tr><td>Lexicon</td><td>Det → that; N → book | flight; V → book</td></tr></tbody></table></div><h4>To find</h4><p>The successful derivation, tree and POS of book.</p></div><h4>Formula and why it applies</h4><p>Choose a production for S that can derive the actual input; an imperative may consist of VP.</p><p>The grammar allows book as both noun and verb, but this imperative needs the verb reading.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Choose the imperative sentence rule</h5><p>S ⇒ VP</p></div><div class=\"step\"><h5>Step 2. Expand the verb phrase</h5><p>⇒ V NP</p></div><div class=\"step\"><h5>Step 3. Choose the verb book</h5><p>⇒ book NP</p></div><div class=\"step\"><h5>Step 4. Expand the object</h5><p>⇒ book Det N</p></div><div class=\"step\"><h5>Step 5. Match that</h5><p>⇒ book that N</p></div><div class=\"step\"><h5>Step 6. Match flight</h5><p>⇒ book that flight</p></div><div class=\"step\"><h5>Step 7. Draw the tree</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Imperative parse: book that flight\" viewBox=\"0 0 360 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Imperative parse: book that flight</title><line x1=\"142.5\" y1=\"40\" x2=\"142.5\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"142.5\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"142.5\" y1=\"104\" x2=\"225\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"225\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"232\" x2=\"170\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"225\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"232\" x2=\"280\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"142.5\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"142.5\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">book</text><text x=\"225\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"170\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">that</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"280\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">flight</text></svg></div><figcaption>Imperative parse: book that flight</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> book is V; that flight is NP; S→VP derives the imperative.</div></section>"},{"id":"shift-reduce-theory","title":"Shift-reduce bottom-up parsing: stack, input and actions","html":"<p><strong>Bottom-up parsing</strong> starts from the input tokens and combines them into larger constituents until the start symbol is reached. A <strong>shift-reduce parser</strong> maintains a stack of recognized material and a list of remaining input tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Action</th><th>Exact operation</th><th>Example</th></tr></thead><tbody><tr><td>Shift</td><td>Move the next input token onto the stack</td><td>Stack: the; remaining input: dog runs</td></tr><tr><td>Reduce</td><td>Replace a suffix of the stack matching a rule's RHS with its LHS</td><td>Det N becomes NP using NP→Det N</td></tr><tr><td>Accept</td><td>Stack is S and input is exhausted</td><td>Stack: S; input: empty</td></tr><tr><td>Fail/backtrack</td><td>Chosen reductions cannot complete a parse</td><td>A noun reading of book blocks an imperative parse</td></tr></tbody></table></div><p>Reduction uses a production in reverse: the grammar NP→Det N expands an NP top-down, but reduces Det N into NP bottom-up. The stack's <strong>rightmost item is its top</strong> in the traces below. Each row shows the state <strong>after</strong> the listed action, avoiding an off-by-one mismatch between actions and stack contents.</p><p>A lexical reduction such as N→dog still counts as a reduction. Do not skip the sequence from word to category to phrase when the question asks for a complete trace. Backtracking means returning to an earlier choice and trying another applicable rule, not changing the original input.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Shift = input se stack. Reduce = chhote pieces se bada grammatical unit.</p>"},{"id":"shift-reduce-examples","title":"Three full shift-reduce traces","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Show a complete shift-reduce parse of “the big dog sees the cat” using S→NP VP, NP→Det N|Det Adj N, VP→V NP, Det→the, Adj→big, N→dog|cat and V→sees.</strong></p><div class=\"given\"><h4>Given</h4><p>Grammar is as specified. Stack starts empty; input is the big dog sees the cat. Top of stack is on the right.</p><h4>To find</h4><p>The stack, remaining input and action at every step.</p></div><h4>Formula and why it applies</h4><p>Shift tokens; reduce matched right-hand sides to their left-hand nonterminals.</p><p>The first noun phrase includes an adjective and must use NP→Det Adj N.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Trace each action</h5><div class=\"table-wrap\"><table><thead><tr><th>Step / action</th><th>Stack after action</th><th>Remaining input</th></tr></thead><tbody><tr><td>0. Start</td><td>∅</td><td>the big dog sees the cat</td></tr><tr><td>1. Shift the</td><td>the</td><td>big dog sees the cat</td></tr><tr><td>2. Reduce Det→the</td><td>Det</td><td>big dog sees the cat</td></tr><tr><td>3. Shift big</td><td>Det big</td><td>dog sees the cat</td></tr><tr><td>4. Reduce Adj→big</td><td>Det Adj</td><td>dog sees the cat</td></tr><tr><td>5. Shift dog</td><td>Det Adj dog</td><td>sees the cat</td></tr><tr><td>6. Reduce N→dog</td><td>Det Adj N</td><td>sees the cat</td></tr><tr><td>7. Reduce NP→Det Adj N</td><td>NP</td><td>sees the cat</td></tr><tr><td>8. Shift sees</td><td>NP sees</td><td>the cat</td></tr><tr><td>9. Reduce V→sees</td><td>NP V</td><td>the cat</td></tr><tr><td>10. Shift the</td><td>NP V the</td><td>cat</td></tr><tr><td>11. Reduce Det→the</td><td>NP V Det</td><td>cat</td></tr><tr><td>12. Shift cat</td><td>NP V Det cat</td><td>∅</td></tr><tr><td>13. Reduce N→cat</td><td>NP V Det N</td><td>∅</td></tr><tr><td>14. Reduce NP→Det N</td><td>NP V NP</td><td>∅</td></tr><tr><td>15. Reduce VP→V NP</td><td>NP VP</td><td>∅</td></tr><tr><td>16. Reduce S→NP VP</td><td>S</td><td>∅</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Check acceptance</h5><p>Input is empty and stack is exactly S; therefore accept.</p></div><div class=\"step\"><h5>Step 3. Draw the resulting structure</h5><figure class=\"diagram\"><div class=\"table-wrap\"><svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" aria-label=\"Parse tree: the big dog sees the cat\" viewBox=\"0 0 670 321\" style=\"width:100%;min-width:500px;max-width:820px\"><title>Parse tree: the big dog sees the cat</title><line x1=\"321.25\" y1=\"40\" x2=\"170\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"104\" x2=\"60\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"60\" y1=\"168\" x2=\"60\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"104\" x2=\"170\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"168\" x2=\"170\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"170\" y1=\"104\" x2=\"280\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"280\" y1=\"168\" x2=\"280\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"321.25\" y1=\"40\" x2=\"472.5\" y2=\"75\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"472.5\" y1=\"104\" x2=\"390\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"390\" y1=\"168\" x2=\"390\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"472.5\" y1=\"104\" x2=\"555\" y2=\"139\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"555\" y1=\"168\" x2=\"500\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"500\" y1=\"232\" x2=\"500\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"555\" y1=\"168\" x2=\"610\" y2=\"203\" stroke=\"#70988b\" stroke-width=\"2\"/><line x1=\"610\" y1=\"232\" x2=\"610\" y2=\"267\" stroke=\"#70988b\" stroke-width=\"2\"/><text x=\"321.25\" y=\"28\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">S</text><text x=\"170\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"60\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"60\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">the</text><text x=\"170\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Adj</text><text x=\"170\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">big</text><text x=\"280\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"280\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">dog</text><text x=\"472.5\" y=\"92\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">VP</text><text x=\"390\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">V</text><text x=\"390\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">sees</text><text x=\"555\" y=\"156\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">NP</text><text x=\"500\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">Det</text><text x=\"500\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">the</text><text x=\"610\" y=\"220\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"600\">N</text><text x=\"610\" y=\"284\" text-anchor=\"middle\" fill=\"#173d35\" font-size=\"17\" font-family=\"Arial, sans-serif\" font-weight=\"400\">cat</text></svg></div><figcaption>Parse tree: the big dog sees the cat</figcaption></figure></div><div class=\"answer\"><strong>Final answer.</strong> Accepted. The parser builds both noun phrases, then VP, then S.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use S→NP VP, NP→Det N, VP→V NP, Det→the|this, N→man|book and V→read to give a shift-reduce trace for “the man read this book”.</strong></p><div class=\"given\"><h4>Given</h4><p>The input has five tokens. Stack is empty initially. The lexical verb read is supplied by V→read.</p><h4>To find</h4><p>A complete bottom-up trace.</p></div><h4>Formula and why it applies</h4><p>Reduce only when the top stack sequence matches a supplied production's right side.</p><p>Both noun phrases follow Det N, and the verb phrase follows V NP.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Trace all operations</h5><div class=\"table-wrap\"><table><thead><tr><th>Step / action</th><th>Stack after action</th><th>Remaining input</th></tr></thead><tbody><tr><td>0. Start</td><td>∅</td><td>the man read this book</td></tr><tr><td>1. Shift the</td><td>the</td><td>man read this book</td></tr><tr><td>2. Reduce Det→the</td><td>Det</td><td>man read this book</td></tr><tr><td>3. Shift man</td><td>Det man</td><td>read this book</td></tr><tr><td>4. Reduce N→man</td><td>Det N</td><td>read this book</td></tr><tr><td>5. Reduce NP→Det N</td><td>NP</td><td>read this book</td></tr><tr><td>6. Shift read</td><td>NP read</td><td>this book</td></tr><tr><td>7. Reduce V→read</td><td>NP V</td><td>this book</td></tr><tr><td>8. Shift this</td><td>NP V this</td><td>book</td></tr><tr><td>9. Reduce Det→this</td><td>NP V Det</td><td>book</td></tr><tr><td>10. Shift book</td><td>NP V Det book</td><td>∅</td></tr><tr><td>11. Reduce N→book</td><td>NP V Det N</td><td>∅</td></tr><tr><td>12. Reduce NP→Det N</td><td>NP V NP</td><td>∅</td></tr><tr><td>13. Reduce VP→V NP</td><td>NP VP</td><td>∅</td></tr><tr><td>14. Reduce S→NP VP</td><td>S</td><td>∅</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Verify the final state</h5><p>The complete sentence has reduced to S with no input left.</p></div><div class=\"answer\"><strong>Final answer.</strong> Accepted. Subject: the man. Predicate: read this book. Object: this book.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Parse “book the flight” bottom-up using S→NP VP|VP, NP→Det N, VP→V NP, Det→the, N→book|flight, V→book. Explain why choosing the noun reading first can fail and show the successful alternative.</strong></p><div class=\"given\"><h4>Given</h4><p>book has two lexical categories N and V. The input is an imperative. Stack starts empty.</p><h4>To find</h4><p>The failed choice and a complete successful trace with backtracking.</p></div><h4>Formula and why it applies</h4><p>Try lexical reductions allowed by the grammar; on a dead end, return to the ambiguous choice and try another.</p><p>Grammar ambiguity requires a search choice. The noun reading cannot supply the required imperative verb.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Show the noun-first dead end</h5><p>Shift book and reduce it to N. Continue shifting/reducing the flight to Det N. Reducing Det N→NP leaves stack N NP and empty input. No supplied rule reduces N NP into S, so this branch fails.</p></div><div class=\"step\"><h5>Step 2. Return to the lexical choice</h5><p>Restore the state just after shifting book, then choose V→book instead of N→book.</p></div><div class=\"step\"><h5>Step 3. Trace the successful branch</h5><div class=\"table-wrap\"><table><thead><tr><th>Step / action</th><th>Stack after action</th><th>Remaining input</th></tr></thead><tbody><tr><td>0. Restored after shifting book</td><td>book</td><td>the flight</td></tr><tr><td>1. Reduce V→book</td><td>V</td><td>the flight</td></tr><tr><td>2. Shift the</td><td>V the</td><td>flight</td></tr><tr><td>3. Reduce Det→the</td><td>V Det</td><td>flight</td></tr><tr><td>4. Shift flight</td><td>V Det flight</td><td>∅</td></tr><tr><td>5. Reduce N→flight</td><td>V Det N</td><td>∅</td></tr><tr><td>6. Reduce NP→Det N</td><td>V NP</td><td>∅</td></tr><tr><td>7. Reduce VP→V NP</td><td>VP</td><td>∅</td></tr><tr><td>8. Reduce S→VP</td><td>S</td><td>∅</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 4. Accept the alternative</h5><p>The verb reading produces S and consumes all tokens.</p></div><div class=\"answer\"><strong>Final answer.</strong> The noun-first branch fails; backtracking to book/V yields the successful imperative parse.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Wrong branch fail hua toh sentence wrong nahi; next legal rule try karo.</p></section>"}]},{"id":"m2-ner","title":"Named Entity Recognition","unit":4,"scope":"Unit 4, pages 117–128","sections":[{"id":"ner-definition","title":"Entity spans, categories and context","html":"<p><strong>Named Entity Recognition (NER)</strong> identifies text spans referring to entities and assigns their types, such as PERSON, ORGANIZATION and LOCATION. Many practical schemas also include DATE, TIME, MONEY or domain-specific types. The exact allowed labels depend on the application's annotation scheme.</p><p>NER has two parts: <strong>boundary detection</strong> finds where the entity starts and ends; <strong>classification</strong> assigns the appropriate type. A multiword name should normally be one entity span: “New York” is a location span, not two unrelated location decisions.</p><div class=\"flow\"><div class=\"node\">Text: Mary joined Google in New York on Monday.</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Mary → PERSON</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Google → ORGANIZATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New York → LOCATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Monday → DATE</div></div><p>Not every noun is a named entity. In “a developer works at Google”, developer is an ordinary job description while Google is a named organization. A specialized HR system may define a JOB_TITLE category, but it must state that schema explicitly. NER identifies mentions; entity linking is the separate task of connecting a mention to a unique database identity.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>POS</td><td>What grammatical role does this token have?</td><td>Google/NNP</td></tr><tr><td>Chunking</td><td>Which adjacent words form a phrase?</td><td>[NP a skilled developer]</td></tr><tr><td>NER</td><td>Which span names an entity, and of what type?</td><td>[Google] ORGANIZATION</td></tr><tr><td>Entity linking</td><td>Which real entity does this mention denote?</td><td>Connect Paris to the intended city or person record</td></tr></tbody></table></div><p><strong>Applications.</strong> NER structures search results and documents, extracts organizations/people from news, routes support tickets by product or organization, supports recommendation, and extracts specialized entities from healthcare or legal text. Context is essential: “Apple released a laptop” names an organization, while “she ate an apple” describes fruit.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER mein do kaam: naam kahan se kahan tak, aur kis category ka.</p>"},{"id":"ner-approaches","title":"Dictionary, rules, machine learning and deep learning","html":"<div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>How it works</th><th>Example</th><th>Main limitation</th></tr></thead><tbody><tr><td>Dictionary / gazetteer</td><td>Match text against lists of known names</td><td>A city list includes Mumbai and Pune</td><td>New names, spelling variants and ambiguous names are missed</td></tr><tr><td>Rule-based</td><td>Use word shapes, regular expressions and context</td><td>A title such as Dr. followed by a name-like span suggests PERSON</td><td>Manual maintenance; exceptions and domain/language dependence</td></tr><tr><td>Machine learning</td><td>Learn a labeling rule from annotated examples using features</td><td>Capitalization, suffixes, POS and surrounding words help a classifier/CRF</td><td>Requires labeled data and useful features</td></tr><tr><td>Deep learning</td><td>Learn contextual word/character representations and predict labels</td><td>A contextual sequence encoder labels multiword entity spans</td><td>Training/domain dependence and resource demands</td></tr></tbody></table></div><p>A <strong>pattern-based rule</strong> examines the form of text, such as an email pattern or a date format. A <strong>context-based rule</strong> examines neighboring words: “Dr.” can support a following PERSON span, while “headquartered in” can support a following LOCATION span. Capitalization alone is insufficient because sentence-initial common nouns are also capitalized.</p><p>A dictionary may find “May” as a person's name, but “in May” may refer to a month. A learned model uses surrounding evidence to disambiguate. Hybrid systems can combine dictionaries, rules and learned models; these categories are practical tools rather than mutually exclusive restrictions.</p><p><strong>Preprocessing for NER.</strong> Tokenize while preserving token offsets and useful capitalization. Blindly removing capital letters or stopwords before recognition can damage names such as “Bank of India”. NER output should preserve the original span so the reader can locate it in the input.</p><p><strong>Exam-ready 3-mark answer.</strong> NER locates named-entity spans and classifies them into categories such as person, organization and location. A dictionary-based approach matches known name lists; a rule-based approach uses patterns or context; machine-learning and deep-learning approaches learn entity decisions from labeled data and representations. For example, in “Mary works at Google in Mumbai”, Mary is PERSON, Google is ORGANIZATION and Mumbai is LOCATION.</p>"},{"id":"ner-worked-examples","title":"Three complete entity-recognition examples","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Identify PERSON, ORGANIZATION and LOCATION entities in “Asha Rao joined Infosys in Bengaluru.”</strong></p><div class=\"given\"><h4>Given</h4><p>Sentence: Asha Rao joined Infosys in Bengaluru. Allowed entity types: PERSON, ORGANIZATION, LOCATION.</p><h4>To find</h4><p>Complete entity spans and labels.</p></div><h4>Formula and why it applies</h4><p>Find the span first, then assign its type from context.</p><p>A multiword personal name is a single entity; the verb and preposition remain outside entities.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the person span</h5><p>Asha Rao names the person who joined, so take both words together.</p></div><div class=\"step\"><h5>Step 2. Identify the organization</h5><p>Infosys is the organization joined.</p></div><div class=\"step\"><h5>Step 3. Identify the location</h5><p>Bengaluru names the city.</p></div><div class=\"step\"><h5>Step 4. Write the output</h5><div class=\"table-wrap\"><table><thead><tr><th>Span</th><th>Label</th></tr></thead><tbody><tr><td>Asha Rao</td><td>PERSON</td></tr><tr><td>Infosys</td><td>ORGANIZATION</td></tr><tr><td>Bengaluru</td><td>LOCATION</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> [Asha Rao]PERSON joined [Infosys]ORGANIZATION in [Bengaluru]LOCATION.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using PERSON, ORGANIZATION, LOCATION and DATE, identify entities in “Dr. Meera Shah visited New Delhi on 5 October 2026.” Treat professional titles as outside the PERSON span for this exercise.</strong></p><div class=\"given\"><h4>Given</h4><p>Allowed types and title-boundary convention are specified. Tokens include a multiword name, city and date.</p><h4>To find</h4><p>Entity boundaries and types.</p></div><h4>Formula and why it applies</h4><p>Boundary rules come from the annotation schema; use the stated title convention.</p><p>Dr. supplies context for a person but is excluded from that span here.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the person</h5><p>Meera Shah is the PERSON span; Dr. is outside by instruction.</p></div><div class=\"step\"><h5>Step 2. Locate the location</h5><p>New Delhi is one LOCATION span.</p></div><div class=\"step\"><h5>Step 3. Locate the date</h5><p>5 October 2026 is one DATE span.</p></div><div class=\"step\"><h5>Step 4. Check organization mentions</h5><p>No organization is named in this sentence.</p></div><div class=\"answer\"><strong>Final answer.</strong> Meera Shah→PERSON; New Delhi→LOCATION; 5 October 2026→DATE.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Explain the entity label of Apple in “Apple opened an office in Mumbai” and apple in “Ravi ate an apple”. Use PERSON, ORGANIZATION and LOCATION only.</strong></p><div class=\"given\"><h4>Given</h4><p>Two contexts contain the same surface word apart from capitalization. The schema contains no FOOD category.</p><h4>To find</h4><p>Contextual labels and the ordinary noun case.</p></div><h4>Formula and why it applies</h4><p>NER labels a mention in context, not every occurrence of a dictionary string identically.</p><p>A company can open an office; the object eaten in the second sentence is a fruit.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Analyze the first sentence</h5><p>Apple refers to the company, so label it ORGANIZATION. Mumbai is LOCATION.</p></div><div class=\"step\"><h5>Step 2. Analyze the second sentence</h5><p>Ravi is PERSON. apple is an ordinary fruit noun and receives no entity label under this schema.</p></div><div class=\"step\"><h5>Step 3. State the dictionary limitation</h5><p>Blindly labeling every apple as an organization would produce a false positive.</p></div><div class=\"answer\"><strong>Final answer.</strong> First: Apple→ORGANIZATION, Mumbai→LOCATION. Second: Ravi→PERSON; apple is outside the entity types.</div></section>"}]},{"id":"u4-forward-cky","title":"Faculty topic: CNF and CYK / CKY parsing","unit":4,"mode":"tee","order":100,"scope":"Unit 4 PDF p105 names CYK. The supplied papers ask top-down / bottom-up CFG trees, not CKY charts. These traces explain the taught topic.","sections":[{"id":"cnf","title":"Prepare a grammar for CYK / CKY","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 4 PDF p105 names CYK. The supplied papers ask top-down / bottom-up CFG trees, not CKY charts. These traces explain the taught topic.</p><p><strong>CYK and CKY are two names for the same dynamic-programming parsing family.</strong> A chart stores which grammatical categories can generate each contiguous span of the sentence. Small spans are solved first and reused to build larger spans. Basic CKY uses a context-free grammar in Chomsky normal form (CNF): a production has either two nonterminals on its right, A→B C, or one terminal, A→word. Empty-string handling is a separate special case; the examples here have no empty production.</p><div class=\"table-wrap\"><table><thead><tr><th>Rule</th><th>Basic CKY status</th><th>Reason</th></tr></thead><tbody><tr><td>S → NP VP</td><td>Allowed</td><td>Two nonterminals</td></tr><tr><td>N → cat</td><td>Allowed</td><td>One terminal</td></tr><tr><td>NP → Det Adj N</td><td>Convert first</td><td>Three nonterminals</td></tr><tr><td>NP → N</td><td>Eliminate or handle unary closure</td><td>One nonterminal, not a lexical terminal</td></tr><tr><td>VP → eats NP</td><td>Convert first</td><td>Mixed terminal and nonterminal</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Convert NP→Det Adj N, NP→N, N→cat and VP→eats NP into basic CNF-compatible productions. Preserve their possible word yields. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>The symbols NP,Det,Adj,N,VP are nonterminals; cat and eats are terminals. Other needed lexical rules remain as supplied.</p><h4>To find</h4><p>Equivalent binary or terminal productions for these cases.</p></div><h4>Formula and why it applies</h4><p>Introduce helper categories for a long right-hand side or a terminal mixed with nonterminals. Eliminate a unary nonterminal rule by inheriting the reachable non-unit productions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Binarize the three-part NP</h5><p>Introduce X: NP→Det X and X→Adj N. X is a helper, not a word; the terminal order remains Det, Adj, N.</p></div><div class=\"step\"><h5>Step 2. Remove the unit production</h5><p>NP→N and N→cat allow NP to derive cat. Add NP→cat, retain N→cat where needed, and remove NP→N. With more rules reachable through unit chains, inherit every corresponding non-unit rule, not only the first one.</p></div><div class=\"step\"><h5>Step 3. Replace the mixed terminal</h5><p>Introduce Vlex→eats and replace VP→eats NP by VP→Vlex NP.</p></div><div class=\"step\"><h5>Step 4. Read the converted forms</h5><p>NP→Det X | cat; X→Adj N; N→cat; VP→Vlex NP; Vlex→eats. All displayed productions are binary nonterminal or single-terminal rules.</p></div><div class=\"answer\"><strong>Final answer.</strong> The converted rules preserve the original word sequences while satisfying the displayed basic CKY forms. Helper nodes change tree shape; they can be removed when presenting the original grammar’s tree.</div></section><p>General CNF conversion may also require eliminating nullable productions and useless symbols while preserving the intended language. Do not claim that simply splitting long rules handles every arbitrary CFG. An Earley parser instead supports general CFG rules using prediction, scanning and completion; it combines top-down expectations with bottom-up evidence. LR and operator-precedence parsers are other methods named in the faculty list, with grammar restrictions of their own.</p>"},{"id":"cky","title":"CYK / CKY: complete charts, backpointers and ambiguity","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 4 PDF p105 names CYK. The supplied papers ask top-down / bottom-up CFG trees, not CKY charts. These traces explain the taught topic.</p><p>Number the words 1 to n. Let <strong>T[i,j]</strong> contain all categories that derive the span from word i through word j, inclusive. Start with one-word cells from lexical rules. For every longer span try <strong>every split k</strong> between i and j: if B belongs to T[i,k], C belongs to T[k+1,j], and A→B C is a rule, put A in T[i,j]. Store the rule and split as backpointers when a tree is required.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/de5d4255c3f9d98c.svg\" alt=\"A\\in T[i,j]\\quad\\text{if}\\quad A\\to BC,\\ B\\in T[i,k],\\ C\\in T[k+1,j],\\ i\\le k&lt;j.\" style=\"width:63.45ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Accept precisely when S is in T[1,n]. Empty cells are meaningful: no category in this grammar derives that span. Basic recognition takes O(n³|G|) time using the straightforward rule-loop analysis and O(n²|N|) category storage; packed backpointers can preserve alternative parses without listing all trees immediately.</p><section class=\"example\"><p class=\"question\"><strong>Question. Use CKY to parse “the cat eats a fish” with S→NP VP, NP→Det N, VP→V NP; Det→the|a; N→cat|fish; V→eats. Show the complete span chart and reconstruct a tree. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Words 1=the, 2=cat, 3=eats, 4=a, 5=fish. The grammar is already in the basic CNF form. ∅ denotes an empty cell.</p><h4>To find</h4><p>All chart cells, acceptance, and a parse tree.</p></div><h4>Formula and why it applies</h4><p>Fill lexical cells, then spans of length 2,3,4,5. For each span try all split points and combine only categories permitted by a binary grammar rule.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Fill the five one-word cells</h5><p>T[1,1]={Det}; T[2,2]={N}; T[3,3]={V}; T[4,4]={Det}; T[5,5]={N}.</p></div><div class=\"step\"><h5>Step 2. Fill length-two spans</h5><p>T[1,2]={NP} because Det+N matches NP→Det N. T[2,3]=∅ (N V has no rule). T[3,4]=∅ (V Det has no rule). T[4,5]={NP} using Det+N.</p></div><div class=\"step\"><h5>Step 3. Fill length-three spans</h5><p>T[1,3]=∅: neither Det+(N eats) nor NP+V matches a rule. T[2,4]=∅. For T[3,5], split after word 3: V from [3,3] plus NP from [4,5] gives VP. Thus T[3,5]={VP}; the other split has an empty left child.</p></div><div class=\"step\"><h5>Step 4. Fill length-four spans</h5><p>T[1,4]=∅ because every split has an empty child or an unmatched category pair. T[2,5]=∅: the only wholly nonempty possibility is N+VP, and no rule produces a parent from that pair.</p></div><div class=\"step\"><h5>Step 5. Fill the complete span</h5><p>For T[1,5], k=1 has an empty right cell; k=2 gives NP from [1,2] and VP from [3,5], hence S. k=3 and k=4 have empty left cells. Therefore T[1,5]={S}.</p></div><div class=\"step\"><h5>Step 6. Copy the completed upper-triangular chart</h5><div class=\"table-wrap\"><table><thead><tr><th>Start i / end j</th><th>1: the</th><th>2: cat</th><th>3: eats</th><th>4: a</th><th>5: fish</th></tr></thead><tbody><tr><td>1</td><td>Det</td><td>NP</td><td>∅</td><td>∅</td><td>S</td></tr><tr><td>2</td><td>—</td><td>N</td><td>∅</td><td>∅</td><td>∅</td></tr><tr><td>3</td><td>—</td><td>—</td><td>V</td><td>∅</td><td>VP</td></tr><tr><td>4</td><td>—</td><td>—</td><td>—</td><td>Det</td><td>NP</td></tr><tr><td>5</td><td>—</td><td>—</td><td>—</td><td>—</td><td>N</td></tr></tbody></table></div><p>A dash is outside the chart (i>j); ∅ is an evaluated but empty valid span. Read the chart by increasing span length, not left-to-right across a row.</p></div><div class=\"step\"><h5>Step 7. Follow the stored backpointers</h5><p>S[1,5]→NP[1,2] VP[3,5]; NP[1,2]→Det[1,1] N[2,2]; VP[3,5]→V[3,3] NP[4,5]; NP[4,5]→Det[4,4] N[5,5].</p><pre>S\n├── NP\n│   ├── Det: the\n│   └── N: cat\n└── VP\n    ├── V: eats\n    └── NP\n        ├── Det: a\n        └── N: fish</pre></div><div class=\"answer\"><strong>Final answer.</strong> Accepted because S∈T[1,5]. The reconstructed tree’s leaves are exactly the five input words in order.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A grammar has S→A A, A→A A and A→a. Use CKY for “a a a” and explain how two parse trees are preserved. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Three identical terminal tokens. S is the start symbol. No unit or empty rules are present.</p><h4>To find</h4><p>Chart categories and both successful split choices for the root.</p></div><h4>Formula and why it applies</h4><p>A chart cell is a set of possible categories. For each category keep all successful backpointers when the task requires every parse.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize the diagonal</h5><p>Each of T[1,1], T[2,2], T[3,3] is {A}, from A→a.</p></div><div class=\"step\"><h5>Step 2. Fill two-word spans</h5><p>T[1,2] and T[2,3] each contain {A,S}: A+A can use A→A A or S→A A.</p></div><div class=\"step\"><h5>Step 3. Try both root splits</h5><p>k=1: A[1,1] + A[2,3] permits S. k=2: A[1,2] + A[3,3] also permits S. The complete cell is {A,S}, but S has two distinct backpointer alternatives.</p></div><div class=\"step\"><h5>Step 4. Draw both bracketed trees</h5><p>[S [A a] [A [A a] [A a]]] and [S [A [A a] [A a]] [A a]]. Both yield a a a; the constituent grouping differs.</p></div><div class=\"answer\"><strong>Final answer.</strong> Accepted, with two S-rooted parses. A category appearing once in a set does not mean there is only one derivation.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. With S→NP VP, NP→Det N, VP→V NP; Det→the|a; N→cat|fish; V→eats, test “the eats cat” using CKY. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Tokens are the/eats/cat, with no punctuation. Use exactly the supplied grammar.</p><h4>To find</h4><p>Whether the grammar accepts the whole input.</p></div><h4>Formula and why it applies</h4><p>A parse exists only if the complete chart cell contains the start symbol.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize the diagonal</h5><p>T[1,1]={Det}; T[2,2]={V}; T[3,3]={N}.</p></div><div class=\"step\"><h5>Step 2. Try length-two combinations</h5><p>Det+V matches no binary rule; V+N also matches no rule (VP requires V+NP). Both two-word cells are empty.</p></div><div class=\"step\"><h5>Step 3. Try the two full-span splits</h5><p>Each split has an empty child, so T[1,3]=∅ and S is absent.</p></div><div class=\"answer\"><strong>Final answer.</strong> Rejected by this grammar. Do not invent NP→N to force acceptance. Grammar rejection and a universal judgment about every possible English grammar are different claims.</div></section><p><strong>Yaad rakho:</strong> Diagonal par words ke tags; phir chhote spans jodo. Har split dekho. Full sentence cell mein S aaya toh parse possible.</p>"}]},{"id":"u5-meaning","title":"Word meaning, lexical relations and WordNet","unit":5,"mode":"both","scope":"Unit 5 · PDF pages 1–22","sections":[{"id":"u5-words","title":"Lexeme, lemma, sense and context","html":"<p><strong>Semantics is the study of meaning in language.</strong> Lexical semantics studies meanings of words and relationships between their meanings. Sentence semantics studies how word meanings and sentence structure combine.</p><p>A <strong>word form</strong> is what appears in the sentence. A <strong>lexeme</strong> is the underlying vocabulary item whose grammatical forms belong together. A <strong>lemma</strong> is the dictionary form used to name it. A <strong>sense</strong> is one particular meaning.</p><table><thead><tr><th>Term</th><th>Example</th><th>What to understand</th></tr></thead><tbody><tr><td>Word forms</td><td>run, runs, ran, running</td><td>Different grammatical forms</td></tr><tr><td>Lexeme</td><td>RUN</td><td>The shared underlying vocabulary item</td></tr><tr><td>Lemma</td><td>run</td><td>Dictionary heading</td></tr><tr><td>Sense</td><td>run a race / run a business</td><td>Different meanings need context</td></tr><tr><td>Lexicon</td><td>A language's vocabulary resource</td><td>Stores lexical items and information about them</td></tr></tbody></table><p>The four forms <em>run, ran, runs, running</em> belong to the same lexeme. They are not four unrelated lexemes. “I deposited cash in the bank” and “We sat by the bank of the river” contain the same written form but different senses.</p><div class=\"flow\"><div class=\"node\">word: bank</div><span aria-hidden=\"true\">→</span><div class=\"node\">context: cash, deposit</div><span aria-hidden=\"true\">→</span><div class=\"node\">sense: financial institution</div></div><p><strong>Syntax</strong> asks how words are arranged. <strong>Semantics</strong> asks what the expression means. <strong>Pragmatics</strong> uses situation and speaker intention: “Can you open the window?” is grammatically a question about ability but is normally a request.</p><p class=\"cue\">Form = jo likha; lemma = dictionary naam; sense = iss sentence mein matlab.</p>"},{"id":"u5-relations","title":"Every lexical relation with examples","html":"<p><strong>A lexical relation connects words or senses by a meaning relationship.</strong> State the relation and its direction before giving the example.</p><table><thead><tr><th>Relation</th><th>Exam definition</th><th>Examples and direction</th></tr></thead><tbody><tr><td>Homonymy</td><td>The same form has unrelated meanings.</td><td>bank: financial institution / river edge; bat: animal / sports implement</td></tr><tr><td>Polysemy</td><td>One lexical item has multiple related senses.</td><td>head: body part / head of a department; paper: material / article</td></tr><tr><td>Synonymy</td><td>Different words have identical or closely similar meanings in a specified sense.</td><td>sofa / couch; automobile / car</td></tr><tr><td>Antonymy</td><td>Words have opposite meanings.</td><td>hot / cold; alive / dead; buy / sell</td></tr><tr><td>Hyponymy</td><td>A more specific concept is a type of a more general one.</td><td>rose is a flower; car is a vehicle</td></tr><tr><td>Hypernymy</td><td>A broader concept includes a more specific one.</td><td>flower is a hypernym of rose</td></tr><tr><td>Meronymy</td><td>A concept is a part of another concept.</td><td>wheel is part of car; finger is part of hand</td></tr><tr><td>Holonymy</td><td>A concept is the whole containing a part.</td><td>car is a holonym of wheel</td></tr></tbody></table><h3>How to distinguish the commonly confused pairs</h3><p>For homonymy versus polysemy, ask whether the senses share an identifiable meaning. A river bank and a financial bank are unrelated. A financial bank and a blood bank share a repository/storage idea, illustrating polysemy in the supplied notes.</p><p>For hyponymy versus meronymy, use the sentence test: <strong>“X is a kind of Y”</strong> indicates hyponymy; <strong>“X is part of Y”</strong> indicates meronymy. A wheel is not a type of car.</p><table><thead><tr><th>Expression</th><th>Correct relation</th><th>Reason</th></tr></thead><tbody><tr><td>sparrow → bird</td><td>Hyponymy</td><td>A sparrow is a kind of bird</td></tr><tr><td>bird → sparrow</td><td>Hypernymy</td><td>Bird is the broader category</td></tr><tr><td>keyboard → computer</td><td>Meronymy</td><td>Keyboard is a component</td></tr><tr><td>computer → keyboard</td><td>Holonymy</td><td>Computer is the containing whole</td></tr><tr><td>mouth of a person / mouth of a river</td><td>Polysemy</td><td>Both senses share the idea of an opening; the river use is a related extension</td></tr></tbody></table><p>Synonyms are not always interchangeable in every context or register. “Big mistake” and “large mistake” can sound different even though big and large overlap in meaning. Antonyms can be gradable (hot/cold), complementary (alive/dead) or relational converses (buy/sell).</p><p class=\"cue\">HYPO = specific type; HYPER = bigger category. MERO = part; HOLO = whole.</p>"},{"id":"u5-wordnet","title":"WordNet: synsets, glosses and hierarchy","html":"<p><strong>WordNet is a lexical database that groups word senses into synonym sets called synsets and links them through semantic and lexical relations.</strong> It is a network of meanings, not merely a list of similar spellings.</p><p>A synset represents one concept. Its <strong>lemmas</strong> are the words that can express that concept. A <strong>gloss</strong> is a short definition, often accompanied by an example. An ambiguous word can occur in several synsets.</p><div class=\"flow\"><div class=\"node\">vehicle (general)</div><span aria-hidden=\"true\">→</span><div class=\"node\">car / automobile (same concept)</div><span aria-hidden=\"true\">→</span><div class=\"node\">sports car (specific)</div></div><p>This is a simplified teaching hierarchy, not a claim about every intermediate WordNet node. Going upward reaches hypernyms; going downward reaches hyponyms. Multiple parents can exist, so the structure need not be a single simple tree.</p><table><thead><tr><th>Operation</th><th>Meaning</th><th>Illustration</th></tr></thead><tbody><tr><td>Get senses of a word</td><td>Find candidate synsets</td><td>bank → financial sense, river-edge sense, …</td></tr><tr><td>Get lemmas</td><td>Find synonyms within one synset</td><td>car, automobile, motorcar</td></tr><tr><td>Get definition/examples</td><td>Read the gloss and uses</td><td>Choose the intended concept</td></tr><tr><td>Get hypernyms</td><td>Move to broader categories</td><td>car → vehicle</td></tr><tr><td>Get hyponyms</td><td>Move to narrower categories</td><td>vehicle → particular vehicle categories</td></tr><tr><td>Get meronyms/holonyms</td><td>Find part/whole links</td><td>car ↔ wheel</td></tr></tbody></table><h3>WordNet versus a thesaurus</h3><p>A thesaurus mainly groups related expressions for vocabulary lookup. WordNet explicitly distinguishes senses and labels relations such as hypernymy, hyponymy and meronymy. This supports WSD, query expansion, lexical similarity and semantic search.</p><h3>Three uses explained</h3><ol><li><strong>Search expansion:</strong> a query for “automobile” can retrieve relevant documents using “car”. Expansion should use the right sense.</li><li><strong>WSD:</strong> definitions of the senses of “bank” provide words that can be compared with the sentence context.</li><li><strong>Similarity:</strong> concepts near one another in an “is-a” hierarchy tend to be semantically related. Path-based measures depend on which senses were selected.</li></ol><p class=\"cue\">WordNet mein spelling ka group nahi—meaning ka synset, aur meanings ke beech labelled links.</p>"}]},{"id":"u5-wsd","title":"Word sense disambiguation: Lesk, Walker and graph methods","unit":5,"mode":"both","scope":"Unit 5 · PDF pages 23–48","sections":[{"id":"u5-wsd-basics","title":"What WSD solves and how approaches differ","html":"<p><strong>Word sense disambiguation (WSD) is the task of selecting the intended sense of an ambiguous word in its context from a set of possible senses.</strong> The output is a sense label, not a different replacement word.</p><div class=\"flow\"><div class=\"node\">Input: “He grilled the bass.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">Candidate senses: fish / low sound</div><span aria-hidden=\"true\">→</span><div class=\"node\">Context: grilled</div><span aria-hidden=\"true\">→</span><div class=\"node\">Output: fish sense</div></div><p>The <strong>target word</strong> is the ambiguous word. The <strong>context</strong> is the surrounding evidence. The <strong>sense inventory</strong> lists candidate meanings, often using WordNet. A <strong>feature</strong> is a usable clue: nearby word, position, part-of-speech tag or a phrase.</p><table><thead><tr><th>Approach</th><th>What it needs</th><th>How it decides</th><th>Limitation</th></tr></thead><tbody><tr><td>Knowledge based</td><td>Dictionary, thesaurus or semantic graph</td><td>Definition overlap, category evidence or graph scores</td><td>Short definitions and missing knowledge</td></tr><tr><td>Supervised</td><td>Examples already labelled with senses</td><td>Learns context → sense mapping</td><td>Labelling cost, limited rare-sense examples</td></tr><tr><td>Semi-supervised</td><td>Small labelled set plus unlabelled data</td><td>Bootstraps from reliable seed examples</td><td>Early errors can spread</td></tr><tr><td>Unsupervised sense induction</td><td>Unlabelled contextual occurrences</td><td>Clusters similar contexts</td><td>Clusters are not automatically named dictionary senses</td></tr><tr><td>Neural/contextual</td><td>Learned word/context representations</td><td>Predicts or compares a context representation</td><td>Needs suitable data/model and evaluation</td></tr></tbody></table><p><strong>Bag-of-words features</strong> record nearby words while ignoring exact positions. <strong>Collocational features</strong> preserve a positional phrase such as “river bank”, “bank account”, “chocolate bar” or “bar exam”.</p><h3>Why WSD matters</h3><p>Machine translation needs the correct target-language meaning; information retrieval should distinguish river-bank travel from banking services; text-to-speech may need different pronunciations for “bass”; information extraction should avoid connecting entities through the wrong relation.</p><p class=\"cue\">WSD: same spelling ke options mein context dekh ke sahi meaning select.</p>"},{"id":"u5-lesk","title":"Lesk algorithm, from words to overlap scores","html":"<p><strong>Lesk is a knowledge-based WSD method that chooses senses whose dictionary descriptions have the greatest overlap with contextual evidence.</strong> Original Lesk compares definitions of neighbouring words' senses. A common simplified version compares each target-sense gloss directly with the sentence context. State which version you use.</p><h3>Simplified Lesk procedure</h3><ol><li>Remove the target word from the context; tokenize and normalize the remaining content words.</li><li>Obtain the gloss for each candidate sense and apply the same normalization.</li><li>Count shared words between the context and each gloss.</li><li>Select the sense with maximum overlap. If scores tie, report the tie or use a specified tie-break rule.</li></ol><div class=\"math-display\"><img src=\"math/691fb54513999f0d.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|,\\qquad s^*=\\arg\\max_s\\operatorname{score}(s)\" style=\"width:45.416ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b5a9729b8c25c0f7.svg\" alt=\"C\" style=\"width:1.719ex;height:1.645ex\" loading=\"lazy\" decoding=\"async\"></span> is the set of context words, <span class=\"math-inline\"><img src=\"math/a5684e27b28daffa.svg\" alt=\"G_s\" style=\"width:2.716ex;height:1.95ex\" loading=\"lazy\" decoding=\"async\"></span> the set of words in sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>'s gloss, <span class=\"math-inline\"><img src=\"math/c7de95563fc530c3.svg\" alt=\"\\cap\" style=\"width:1.509ex;height:1.403ex\" loading=\"lazy\" decoding=\"async\"></span> means common elements, <span class=\"math-inline\"><img src=\"math/468f3b6d2f1b95a0.svg\" alt=\"|\\cdot|\" style=\"width:2.892ex;height:2.26ex\" loading=\"lazy\" decoding=\"async\"></span> means count, and <span class=\"math-inline\"><img src=\"math/dfccac0c4f581832.svg\" alt=\"\\arg\\max\" style=\"width:7.737ex;height:1.491ex\" loading=\"lazy\" decoding=\"async\"></span> means “the sense giving the largest score”. This version counts unique matching words once.</p><div class=\"example\"><p><strong>Question. Use simplified Lesk to disambiguate “bank” in “The river water rose near the bank.” Use C = {river, water, rose, near}; financial gloss = {institution, money, deposit}; river gloss = {land, river, water, edge}.</strong></p><div class=\"given\"><h4>Given</h4><p>The normalized context and two gloss sets are given. Count exact shared words.</p><h4>To find</h4><p>The score of each sense and the selected meaning.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because the task specifies context–gloss overlap.</p><div class=\"step\"><h4>Step 1. Compare the financial sense</h4><p>No word occurs in both {river, water, rose, near} and {institution, money, deposit}. Overlap = {}.</p></div><div class=\"step\"><h4>Step 2. Count the financial score</h4><p><span class=\"math-inline\"><img src=\"math/bdc75dbcd361db69.svg\" alt=\"\\operatorname{score}(F)=0\" style=\"width:12.522ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare the river sense</h4><p>Shared words are {river, water}. “Rose” and “near” are not in the gloss.</p></div><div class=\"step\"><h4>Step 4. Count and select</h4><p><span class=\"math-inline\"><img src=\"math/384740febd8dd4b0.svg\" alt=\"\\operatorname{score}(R)=2\" style=\"width:12.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Since <span class=\"math-inline\"><img src=\"math/6e25b81ec200909a.svg\" alt=\"2&gt;0\" style=\"width:5.28ex;height:1.597ex\" loading=\"lazy\" decoding=\"async\"></span>, choose the river-edge sense.</p></div><p class=\"answer\"><strong>Answer.</strong> Bank means land beside a river.</p></div><div class=\"example\"><p><strong>Question. Use simplified Lesk for “The dog barked loudly.” Treat barked as bark. Context C = {dog, loudly}; sound gloss = {sharp, cry, dog}; tree gloss = {outer, covering, tree}; ship gloss = {sailing, ship}.</strong></p><div class=\"given\"><h4>Given</h4><p>Three glosses and normalized context {dog, loudly}.</p><h4>To find</h4><p>Select the sense of bark.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Lemmatization lets barked match the target lemma bark; it does not create additional overlap words.</p><div class=\"step\"><h4>Step 1. Sound sense</h4><p>Intersection = {dog}; score = 1.</p></div><div class=\"step\"><h4>Step 2. Tree sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 3. Ship sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>The sound sense has the unique maximum: 1 &gt; 0.</p></div><p class=\"answer\"><strong>Answer.</strong> Bark is the dog's cry.</p></div><div class=\"example\"><p><strong>Question. Apply definition–definition Lesk to “pine cone”. Pine senses: P1 = {evergreen, tree, needle, leaf}; P2 = {waste, sorrow, illness}. Cone senses: C1 = {solid, shape, circular}; C2 = {fruit, evergreen, tree}.</strong></p><div class=\"given\"><h4>Given</h4><p>Two candidate senses for each word. Tokens are already normalized; tree and trees would be reduced to the same form if necessary.</p><h4>To find</h4><p>The most compatible pair of senses.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/bb2259d0f8a3b048.svg\" alt=\"|G_{P_i}\\cap G_{C_j}|\" style=\"width:10.997ex;height:2.506ex\" loading=\"lazy\" decoding=\"async\"></span> for every pair because this is original-style gloss–gloss comparison.</p><div class=\"step\"><h4>Step 1. P1 with C1</h4><p>No shared word → 0.</p></div><div class=\"step\"><h4>Step 2. P1 with C2</h4><p>Shared {evergreen, tree} → 2.</p></div><div class=\"step\"><h4>Step 3. P2 with each cone sense</h4><p>P2–C1 has no overlap → 0; P2–C2 has no overlap → 0.</p></div><div class=\"step\"><h4>Step 4. Choose the best pair</h4><p>The four scores are 0, 2, 0, 0. Maximum 2 belongs to P1–C2.</p></div><p class=\"answer\"><strong>Answer.</strong> Pine is the evergreen tree; cone is its fruit-like reproductive structure.</p></div><p><strong>Limitations:</strong> exact overlap misses synonyms, short glosses may produce zeros, and different preprocessing choices change the score. Extended Lesk may include related synset definitions or longer phrase overlaps; do not silently substitute it for a simple question.</p><p class=\"cue\">Lesk: context aur dictionary mein common words gino; sabse bada overlap jeeta.</p>"},{"id":"u5-walker","title":"Thesaurus / Walker approach, with three complete examples","html":"<p><strong>The Walker approach uses thesaurus categories as semantic evidence.</strong> Associate each candidate sense with a category. Count or weight context words that support that category. Choose the largest total.</p><div class=\"math-display\"><img src=\"math/9d7b8384c080650b.svg\" alt=\"\\operatorname{score}(s)=\\sum_{w\\in C} I(w,\\operatorname{category}(s))\" style=\"width:31.274ex;height:4.963ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b186266d0d476166.svg\" alt=\"I=1\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> if the supplied category mapping says the context word supports the sense, otherwise <span class=\"math-inline\"><img src=\"math/5fd951e2f99cd39c.svg\" alt=\"I=0\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>. The summation symbol means add all those contributions. Weighted questions may replace 1 with a supplied weight. Category membership must be supplied or justified; it is not guessed from word frequency.</p><div class=\"example\"><p><strong>Question. Disambiguate bank using Walker scoring. Context words are money, interest, annum, fetch. The finance category supports money, interest and annum; the location category supports none of these words.</strong></p><div class=\"given\"><h4>Given</h4><p>Two categories: Finance and Location. Each supported word contributes 1.</p><h4>To find</h4><p>The two totals and selected bank sense.</p></div><h4>Formula and why it applies</h4><p>Sum the category indicators for each sense.</p><div class=\"step\"><h4>Step 1. Make a contribution table</h4><table><thead><tr><th>Word</th><th>Finance</th><th>Location</th></tr></thead><tbody><tr><td>money</td><td>1</td><td>0</td></tr><tr><td>interest</td><td>1</td><td>0</td></tr><tr><td>annum</td><td>1</td><td>0</td></tr><tr><td>fetch</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Add Finance</h4><p><span class=\"math-inline\"><img src=\"math/6a517f05661478a7.svg\" alt=\"1+1+1+0=3\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Location</h4><p><span class=\"math-inline\"><img src=\"math/79d13a087a88c477.svg\" alt=\"0+0+0+0=0\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Select</h4><p>3 &gt; 0, so select the financial institution.</p></div><p class=\"answer\"><strong>Answer.</strong> Finance, with score 3 versus 0.</p></div><div class=\"example\"><p><strong>Question. Use Walker scoring for “The fisherman caught bass beside the lake.” Context {fisherman,caught,lake}. The Fish category contains all three clues; the Music category contains none.</strong></p><div class=\"given\"><h4>Given</h4><p>Fish and Music senses, binary category membership given.</p><h4>To find</h4><p>The correct bass sense.</p></div><h4>Formula and why it applies</h4><p>Score = sum of context-category matches.</p><div class=\"step\"><h4>Step 1. Record Fish matches</h4><p>fisherman → 1; caught → 1; lake → 1.</p></div><div class=\"step\"><h4>Step 2. Add Fish score</h4><p><span class=\"math-inline\"><img src=\"math/7e22dbf6b1c68d2b.svg\" alt=\"1+1+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Music score</h4><p><span class=\"math-inline\"><img src=\"math/f4ccd7a1f1f516c9.svg\" alt=\"0+0+0=0\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Choose</h4><p>Fish has the larger score.</p></div><p class=\"answer\"><strong>Answer.</strong> Bass refers to a fish.</p></div><div class=\"example\"><p><strong>Question. Score “The player used a bat in the match.” Context {player,match}. Sport supports both words with weights 2 and 1; Animal supports neither. Use the supplied weighted Walker scheme.</strong></p><div class=\"given\"><h4>Given</h4><p>Sport weights {player:2, match:1}; Animal weights {player:0, match:0}.</p><h4>To find</h4><p>Weighted sense scores.</p></div><h4>Formula and why it applies</h4><p>Use the sum of supplied weights, not an unweighted count, because the question explicitly gives weights.</p><div class=\"step\"><h4>Step 1. Sport contribution of player</h4><p>Add 2.</p></div><div class=\"step\"><h4>Step 2. Sport contribution of match</h4><p>Add 1. Sport total = 2 + 1 = 3.</p></div><div class=\"step\"><h4>Step 3. Animal total</h4><p>0 + 0 = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>3 &gt; 0 selects the sporting implement.</p></div><p class=\"answer\"><strong>Answer.</strong> Bat is the sports implement.</p></div><p class=\"cue\">Walker: dictionary ke exact words nahi, context kis topic/category ko support karta hai woh count.</p>"},{"id":"u5-graph","title":"Random-walk WSD and supervised alternatives","html":"<p><strong>Graph-based WSD represents candidate senses as vertices and semantic relationships as weighted edges.</strong> A random walk repeatedly transfers score along these edges. Senses supported by other strongly connected context senses tend to obtain higher ranks.</p><ol><li>Create a vertex for every candidate sense of every relevant word.</li><li>Connect semantically related senses; similarity or gloss overlap can set edge weights.</li><li>Normalize outgoing edge weights into transition probabilities.</li><li>Run a graph-ranking method such as PageRank.</li><li>For each target word, choose its highest-ranked candidate sense.</li></ol><div class=\"flow\"><div class=\"node\">church context</div><span aria-hidden=\"true\">→</span><div class=\"node\">bell: instrument sense ↔ ring: sound sense</div><span aria-hidden=\"true\">→</span><div class=\"node\">mutually supported senses receive rank</div></div><p>One common rank update is</p><div class=\"math-display\"><img src=\"math/58c328eed762e371.svg\" alt=\"r_{t+1}(j)=\\frac{1-d}{N}+d\\sum_i r_t(i)P(i\\rightarrow j).\" style=\"width:37.218ex;height:5.797ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/d0ac5d68953e63fb.svg\" alt=\"r_t(i)\" style=\"width:4.326ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is current score of vertex <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/2e580e2c56ce5fb8.svg\" alt=\"P(i\\to j)\" style=\"width:8.691ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is its outgoing probability to <span class=\"math-inline\"><img src=\"math/7a5268d94266eaaf.svg\" alt=\"j\" style=\"width:0.932ex;height:1.957ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/284cee6629b09719.svg\" alt=\"N\" style=\"width:2.009ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of vertices, and <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span> is the probability of following a graph edge. The remaining probability <span class=\"math-inline\"><img src=\"math/03ba8413969b1f03.svg\" alt=\"1-d\" style=\"width:5.073ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span> gives a uniform restart here. A personalized variant uses a nonuniform restart. The course requires the graph method concept; numerical details depend on supplied ranking rules.</p><div class=\"example\"><p><strong>Question. A two-vertex toy sense graph has transition matrix rows A:[0.2,0.8], B:[0.4,0.6]. Starting scores are A=0.5, B=0.5. Find one random-walk update with no restart.</strong></p><div class=\"given\"><h4>Given</h4><p>Rows denote source vertices, columns destination vertices. d = 1.</p><h4>To find</h4><p>New scores at A and B.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/1f9486c13badc4b9.svg\" alt=\"r_{t+1}(j)=\\sum_i r_t(i)P(i\\to j)\" style=\"width:26.063ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>: incoming contributions are added.</p><div class=\"step\"><h4>Step 1. Contribution to A from A</h4><p><span class=\"math-inline\"><img src=\"math/f5b0bcf0ed9035b5.svg\" alt=\"0.5\\times0.2=0.1\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Contribution to A from B</h4><p><span class=\"math-inline\"><img src=\"math/0a2405c4d5291b52.svg\" alt=\"0.5\\times0.4=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>, hence <span class=\"math-inline\"><img src=\"math/b3f4e8d5ae51ab54.svg\" alt=\"r_1(A)=0.1+0.2=0.3\" style=\"width:22.939ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Contribution to B from A and B</h4><p><span class=\"math-inline\"><img src=\"math/ce0a35fc09c4be55.svg\" alt=\"0.5\\times0.8=0.4\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ec4de7a9661ab386.svg\" alt=\"0.5\\times0.6=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Add B and verify total</h4><p><span class=\"math-inline\"><img src=\"math/4a0be788a6cd2a62.svg\" alt=\"r_1(B)=0.4+0.3=0.7\" style=\"width:22.96ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/76cecf94aaf6078d.svg\" alt=\"0.3+0.7=1\" style=\"width:12.697ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> A=0.3, B=0.7 after one update. This is one iteration, not a converged PageRank result.</p></div><h3>Other approaches explained without assuming ML knowledge</h3><p><strong>A supervised classifier</strong> learns from examples such as “cash … bank” labelled FINANCE and “river … bank” labelled RIVER. A decision list applies ranked context rules; a decision tree branches on clues; an SVM separates feature representations; a neural model learns contextual patterns. Naive Bayes, developed next, multiplies class-specific context probabilities.</p><p><strong>Semi-supervised bootstrapping</strong> begins with a few labelled examples or high-confidence rules, labels suitable unlabelled cases, and retrains. <strong>Unsupervised clustering</strong> groups usages by context similarity without gold sense labels; an additional mapping is needed to name the discovered groups.</p><p class=\"cue\">Graph WSD: meanings ko jodo; jo meaning context ke strong meanings se supported hai uska rank badhega.</p>"}]},{"id":"u5-naive-bayes","title":"Naive Bayes WSD: probabilities to a complete numerical","unit":5,"mode":"both","scope":"Unit 5 · PDF pages 49–57","sections":[{"id":"u5-bayes-meaning","title":"Prior, likelihood and posterior—before the formula","html":"<p><strong>A probability is a number from 0 to 1 measuring how likely an event is under a stated model.</strong> A class probability of <span class=\"math-inline\"><img src=\"math/ebc0c6fa20ed6a98.svg\" alt=\"3/6=0.5\" style=\"width:9.302ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> means 3 of 6 training examples belong to that class.</p><p><strong>Conditional probability</strong> means probability inside a restricted group. <span class=\"math-inline\"><img src=\"math/3e3b57b2d1341cd6.svg\" alt=\"P(\\text{loan}\\mid F)\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> reads “probability of the word loan given the finance sense”. The vertical bar means “given”; it is not division.</p><table><thead><tr><th>Symbol</th><th>Name</th><th>Plain meaning</th></tr></thead><tbody><tr><td><span class=\"math-inline\"><img src=\"math/b22ff6e7eb0a8abb.svg\" alt=\"P(F)\" style=\"width:5.154ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Prior</td><td>How common finance is before reading the new context</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/5d8f091329836633.svg\" alt=\"P(C\\mid F)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Likelihood</td><td>How compatible the observed context is with finance</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/6d368ab85d9177c5.svg\" alt=\"P(F\\mid C)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Posterior</td><td>How likely finance is after seeing the context</td></tr><tr><td><span class=\"math-inline\"><img src=\"math/57aab4348bb4d572.svg\" alt=\"P(C)\" style=\"width:5.179ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span></td><td>Evidence</td><td>Total probability of this context under all senses</td></tr></tbody></table><div class=\"math-display\"><img src=\"math/d2028c752e4c5347.svg\" alt=\"P(F\\mid C)=\\frac{P(C\\mid F)P(F)}{P(C)}.\" style=\"width:27.314ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Bayes' theorem reverses a conditional direction using the prior. Do not swap <span class=\"math-inline\"><img src=\"math/6d368ab85d9177c5.svg\" alt=\"P(F\\mid C)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> and <span class=\"math-inline\"><img src=\"math/5d8f091329836633.svg\" alt=\"P(C\\mid F)\" style=\"width:8.759ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>: one asks about the sense, the other about the evidence.</p><p>The <strong>naive conditional independence assumption</strong> says that, once the sense is fixed, the context-word features can be multiplied as if they were independent. It is an approximation: natural-language words are not actually independent in general.</p><div class=\"flow\"><div class=\"node\">Training examples → count classes</div><span aria-hidden=\"true\">→</span><div class=\"node\">Prior per sense</div><span aria-hidden=\"true\">→</span><div class=\"node\">Count words within each sense</div><span aria-hidden=\"true\">→</span><div class=\"node\">Likelihood of query clues</div><span aria-hidden=\"true\">→</span><div class=\"node\">Multiply → compare → normalize if asked</div></div><p class=\"cue\">Prior = pehle kitna common; likelihood = clue kitna fit; posterior = clue dekhne ke baad meaning ki chance.</p>"},{"id":"u5-bayes-steps","title":"Multinomial Naive Bayes: the exact solving method","html":"<p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><h3>Always keep these counts separate</h3><p>Class priors use <strong>number of examples</strong>. Word likelihoods in this multinomial model use <strong>number of word occurrences</strong>. The vocabulary counts <strong>unique words across all classes</strong>.</p><ol><li>List the class examples and calculate priors.</li><li>Write one shared vocabulary and count its size.</li><li>Count total word occurrences in each class.</li><li>Count each query word in each class.</li><li>Apply the given smoothing rule.</li><li>Multiply each prior by all its query likelihoods.</li><li>Compare scores; divide each score by their sum only if a normalized posterior is requested.</li></ol><div class=\"math-display\"><img src=\"math/0fd59effd2bb7926.svg\" alt=\"P(s\\mid C)=\\frac{\\operatorname{score}(s)}{\\sum_{s&#39;}\\operatorname{score}(s&#39;)}.\" style=\"width:25.283ex;height:5.571ex\" loading=\"lazy\" decoding=\"async\"></div><p><strong>Why smoothing is needed:</strong> an unseen clue gives <span class=\"math-inline\"><img src=\"math/5d29fa66aa3ef2ee.svg\" alt=\"0/N_s=0\" style=\"width:9.166ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; one zero makes the whole product zero. Add-one smoothing redistributes probability across every vocabulary word and prevents these zero factors. Use it only when requested, taught for the task, or state the assumption.</p><p><strong>Different model warning:</strong> a Bernoulli Naive Bayes question counts presence/absence per document and may include absence factors. Do not use its denominator in a multinomial word-count question.</p><p class=\"cue\">Pehle sentences se prior; phir words se likelihood; dono counts mix mat kar.</p>"},{"id":"u5-bayes-mam","title":"Mam's bank numerical—every count and every multiplication","html":"<div class=\"example\"><p><strong>Question. Classify the sense of “bank” using the training table below. The sentence is: “As the stream flowed gently past the shore, we set up camp by the bank of the river, discussing the possibility of borrowing a loan to buy a boat for future trips.” Use only the highlighted feature words stream, shore and loan, and add-one multinomial smoothing.</strong></p><div class=\"given\"><h4>Given</h4><table><thead><tr><th>Training row</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>money, deposit, loan</td><td>Finance</td></tr><tr><td>2</td><td>river, water, shore</td><td>Riverbank</td></tr><tr><td>3</td><td>account, savings, investment</td><td>Finance</td></tr><tr><td>4</td><td>boat, river, stream</td><td>Riverbank</td></tr><tr><td>5</td><td>branch, deposit, check</td><td>Finance</td></tr><tr><td>6</td><td>fishing, shore, river</td><td>Riverbank</td></tr></tbody></table><p>Query feature set: {stream, shore, loan}. Other sentence words are not included as features in this supplied example.</p><h4>To find</h4><p>The most probable bank sense and normalized posteriors.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Calculate priors</h4><p>Finance appears in 3 of the 6 rows; Riverbank appears in 3 of 6.</p><div class=\"math-display\"><img src=\"math/2f05aa3a89468f5e.svg\" alt=\"P(F)=\\frac36=\\frac12,\\qquad P(R)=\\frac36=\\frac12.\" style=\"width:37.065ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Construct the vocabulary</h4><p>{money, deposit, loan, river, water, shore, account, savings, investment, boat, stream, fishing, branch, check}. Thus V=14. Repeated deposit or river is counted once in vocabulary.</p></div><div class=\"step\"><h4>Step 3. Count word occurrences per class</h4><p>There are 3 finance rows × 3 words = 9 word occurrences. There are 3 river rows × 3 words = 9. Thus <span class=\"math-inline\"><img src=\"math/2fe9227521f0d9d8.svg\" alt=\"N_F=N_R=9\" style=\"width:13.587ex;height:1.918ex\" loading=\"lazy\" decoding=\"async\"></span>, and each smoothed denominator is <span class=\"math-inline\"><img src=\"math/989b4387cd367e7a.svg\" alt=\"9+14=23\" style=\"width:11.439ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Count the three query words</h4><table><thead><tr><th>Word</th><th>Finance count</th><th>Riverbank count</th></tr></thead><tbody><tr><td>stream</td><td>0</td><td>1</td></tr><tr><td>shore</td><td>0</td><td>2</td></tr><tr><td>loan</td><td>1</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 5. Calculate finance likelihoods</h4><div class=\"math-display\"><img src=\"math/dece6048e91d14ee.svg\" alt=\"P(\\text{stream}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:29.034ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/48b17e3adf6f62bb.svg\" alt=\"P(\\text{shore}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:27.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/622a2e615b1ad17f.svg\" alt=\"P(\\text{loan}\\mid F)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:26.505ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Multiply the finance score</h4><div class=\"math-display\"><img src=\"math/ca9dd31ae9d5dc12.svg\" alt=\"\\operatorname{score}(F)=\\frac12\\times\\frac1{23}\\times\\frac1{23}\\times\\frac2{23}=\\frac1{23^3}=\\frac1{12167}\\approx0.00008219.\" style=\"width:62.975ex;height:4.949ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 7. Calculate river likelihoods</h4><div class=\"math-display\"><img src=\"math/0612a35cf28c3394.svg\" alt=\"P(\\text{stream}\\mid R)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:29.057ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c71632f8b691648b.svg\" alt=\"P(\\text{shore}\\mid R)=\\frac{2+1}{23}=\\frac3{23}\" style=\"width:27.55ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/bff44b72ce8cc8e7.svg\" alt=\"P(\\text{loan}\\mid R)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:26.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 8. Multiply the river score</h4><div class=\"math-display\"><img src=\"math/665624fd363dd007.svg\" alt=\"\\operatorname{score}(R)=\\frac12\\times\\frac2{23}\\times\\frac3{23}\\times\\frac1{23}=\\frac3{12167}\\approx0.00024657.\" style=\"width:55.735ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 9. Compare scores</h4><p>3/12167 is larger than 1/12167. Riverbank wins even though “loan” is financial evidence: the combined clues matter.</p></div><div class=\"step\"><h4>Step 10. Normalize if a posterior is requested</h4><div class=\"math-display\"><img src=\"math/4b082736e405b96c.svg\" alt=\"P(F\\mid C)=\\frac{1/12167}{4/12167}=\\frac14=0.25\" style=\"width:32.874ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/371000172a7d5f5f.svg\" alt=\"P(R\\mid C)=\\frac{3/12167}{4/12167}=\\frac34=0.75.\" style=\"width:33.525ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Bank is the riverbank sense. Scores are 1/12167 and 3/12167; normalized model posteriors are 0.25 and 0.75.</p></div><p><strong>Without smoothing:</strong> stream and shore are absent in Finance; loan is absent in Riverbank. Both unsmoothed scores become zero, so there is no valid winning class from those products. Also, unnormalized scores should not be labelled as final posterior probabilities.</p><p class=\"cue\">Zero word? Add-one: count+1 upar, total words+vocabulary neeche. Last mein score bada wala sense.</p>"},{"id":"u5-bayes-practice","title":"More WSD numericals: given likelihoods, unequal priors and repeated clues","html":"<div class=\"example\"><p><strong>Question. For bass, let P(Fish)=0.6 and P(Music)=0.4. Given Fish likelihoods P(caught|Fish)=0.5, P(lake|Fish)=0.4 and Music likelihoods P(caught|Music)=0.05, P(lake|Music)=0.1, classify context {caught,lake} and normalize.</strong></p><div class=\"given\"><h4>Given</h4><p>Priors and likelihoods are provided directly; no smoothing or training-count estimation is requested.</p><h4>To find</h4><p>The winning sense and its posterior.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/8414ab183de734ec.svg\" alt=\"\\operatorname{score}(s)=P(s)P(\\text{caught}\\mid s)P(\\text{lake}\\mid s)\" style=\"width:38.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, because the two features are treated as conditionally independent.</p><div class=\"step\"><h4>Step 1. Fish multiplication</h4><p><span class=\"math-inline\"><img src=\"math/115f9e8e47cda84d.svg\" alt=\"0.6\\times0.5=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/99bd356c706eee9f.svg\" alt=\"0.3\\times0.4=0.12\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Music multiplication</h4><p><span class=\"math-inline\"><img src=\"math/b1d1c4fd715bfbf9.svg\" alt=\"0.4\\times0.05=0.02\" style=\"width:16.719ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/6ea85a9a0fdfcde1.svg\" alt=\"0.02\\times0.1=0.002\" style=\"width:17.851ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Total evidence</h4><p><span class=\"math-inline\"><img src=\"math/908f94107aa11373.svg\" alt=\"0.12+0.002=0.122\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><div class=\"math-display\"><img src=\"math/957c68e55d605895.svg\" alt=\"P(Fish\\mid C)=0.12/0.122\\approx0.983607\" style=\"width:36.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/d8a1b99447a84030.svg\" alt=\"P(Music\\mid C)=0.002/0.122\\approx0.016393.\" style=\"width:40.207ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Fish, with model posterior approximately 0.983607.</p></div><div class=\"example\"><p><strong>Question. Disambiguate bank from the repeated context tokens {loan, loan, river}. Priors are Finance=2/3 and River=1/3. Vocabulary V=4. Finance has N=8 total tokens, loan count 3 and river count 0; River has N=4, loan count 0 and river count 2. Apply add-one smoothing.</strong></p><div class=\"given\"><h4>Given</h4><p>Multinomial counts are supplied. The two appearances of loan must both contribute.</p><h4>To find</h4><p>Scores and normalized Finance posterior.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Finance denominator</h4><p><span class=\"math-inline\"><img src=\"math/4dcd6d36e73676fe.svg\" alt=\"8+4=12\" style=\"width:10.308ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/c83ba89d49bb7c55.svg\" alt=\"P(loan\\mid F)=(3+1)/12=1/3\" style=\"width:30.975ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ed4e2c4c1b9881ea.svg\" alt=\"P(river\\mid F)=(0+1)/12=1/12\" style=\"width:32.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. River denominator</h4><p><span class=\"math-inline\"><img src=\"math/34a0153bb137796a.svg\" alt=\"4+4=8\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/739f9e9752ebca3d.svg\" alt=\"P(loan\\mid R)=(0+1)/8=1/8\" style=\"width:29.867ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/cb1959ca98dd60bb.svg\" alt=\"P(river\\mid R)=(2+1)/8=3/8\" style=\"width:30.514ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Finance product</h4><div class=\"math-display\"><img src=\"math/94333571a54ef7df.svg\" alt=\"\\operatorname{score}(F)=\\frac23\\times\\frac13\\times\\frac13\\times\\frac1{12}=\\frac1{162}\\approx0.00617284.\" style=\"width:51.188ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. River product</h4><div class=\"math-display\"><img src=\"math/ffa63ee974248624.svg\" alt=\"\\operatorname{score}(R)=\\frac13\\times\\frac18\\times\\frac18\\times\\frac38=\\frac1{512}\\approx0.001953125.\" style=\"width:51.21ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Compare and normalize</h4><div class=\"math-display\"><img src=\"math/6e05aa52a40b6b55.svg\" alt=\"P(F\\mid C)=\\frac{1/162}{1/162+1/512}=\\frac{512}{674}=\\frac{256}{337}\\approx0.759644.\" style=\"width:53.856ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Finance wins. Repeated loan contributes a squared likelihood; do not reduce the query to a unique-word set.</p></div><h3>Answer-writing order in an exam</h3><p>Write the class priors, vocabulary size, class token totals, a likelihood table, both score products and the final class. Keep fractions until the comparison where possible. If the question only asks classification, normalization is optional; if it asks posterior probabilities, normalization is required.</p><p class=\"cue\">Repeated word aaye toh factor bhi repeat. Sirf word-set bana diya toh multinomial answer badal jayega.</p>"}]},{"id":"u5-vectors","title":"Vector semantics and word embeddings","unit":5,"mode":"tee","scope":"TEE · Unit 5 PDF pages 58–118","sections":[{"id":"u5-distribution","title":"Distributional hypothesis and a co-occurrence matrix","html":"<p><strong>The distributional hypothesis states that words occurring in similar contexts tend to have similar meanings or semantic behaviour.</strong> “Cat” and “dog” often occur near pet, feed and animal. Their context patterns can therefore be represented and compared numerically.</p><p>A <strong>vector</strong> is an ordered list of numbers. Each position must have a fixed meaning. For context order [pet, food, road], cat=[4,3,0] means four co-occurrences with pet, three with food, none with road. A <strong>matrix</strong> stacks vectors as rows in a table.</p><p>A <strong>word–context co-occurrence matrix</strong> records how often a target word occurs with each context word under a specified context definition. A window may be a sentence, document, or a fixed number of neighbouring tokens. State its width, direction and whether targets count themselves.</p><div class=\"flow\"><div class=\"node\">Choose target words</div><span aria-hidden=\"true\">→</span><div class=\"node\">Choose context/window</div><span aria-hidden=\"true\">→</span><div class=\"node\">Count co-occurrences</div><span aria-hidden=\"true\">→</span><div class=\"node\">Store each row as a vector</div><span aria-hidden=\"true\">→</span><div class=\"node\">Compare vectors</div></div><div class=\"example\"><p><strong>Question. Build the symmetric co-occurrence matrix for “cats eat fish” using a window of one token on either side, no self-counts and vocabulary [cats,eat,fish].</strong></p><div class=\"given\"><h4>Given</h4><p>One sentence, one occurrence of each token. Left and right adjacent tokens are contexts.</p><h4>To find</h4><p>A 3×3 target-by-context count matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/e26c85d7637ed303.svg\" alt=\"X_{ij}\" style=\"width:3.272ex;height:2.211ex\" loading=\"lazy\" decoding=\"async\"></span> counts the number of times context word <span class=\"math-inline\"><img src=\"math/7a5268d94266eaaf.svg\" alt=\"j\" style=\"width:0.932ex;height:1.957ex\" loading=\"lazy\" decoding=\"async\"></span> occurs within the chosen window of target <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Target cats</h4><p>Only eat is adjacent. Row cats = [0,1,0].</p></div><div class=\"step\"><h4>Step 2. Target eat</h4><p>cats is left and fish is right. Row eat = [1,0,1].</p></div><div class=\"step\"><h4>Step 3. Target fish</h4><p>Only eat is adjacent. Row fish = [0,1,0].</p></div><div class=\"step\"><h4>Step 4. Assemble the matrix</h4><table><thead><tr><th>Target / context</th><th>cats</th><th>eat</th><th>fish</th></tr></thead><tbody><tr><td>cats</td><td>0</td><td>1</td><td>0</td></tr><tr><td>eat</td><td>1</td><td>0</td><td>1</td></tr><tr><td>fish</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> Rows are [0,1,0], [1,0,1], [0,1,0]. The symmetry follows from the symmetric window.</p></div><div class=\"example\"><p><strong>Question. Build a target–context matrix for sentences “cats eat fish” and “dogs eat fish”. Target words are cats and dogs; context columns [eat,fish]; use the entire sentence excluding the target.</strong></p><div class=\"given\"><h4>Given</h4><p>Each sentence contains one target. Count context token occurrences.</p><h4>To find</h4><p>Two context vectors.</p></div><h4>Formula and why it applies</h4><p>Count each context word in every sentence containing the target.</p><div class=\"step\"><h4>Step 1. Count cats contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 2. Count dogs contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 3. Compare</h4><p>Both targets have identical observed context patterns in this very small corpus.</p></div><p class=\"answer\"><strong>Answer.</strong> cats=[1,1], dogs=[1,1]. This corpus supplies no context evidence to distinguish them.</p></div><div class=\"example\"><p><strong>Question. For “a b a”, use a right-only window of one token. Build the matrix with rows/columns [a,b].</strong></p><div class=\"given\"><h4>Given</h4><p>Count directed target→next-word events, not both directions.</p><h4>To find</h4><p>The co-occurrence matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/584bbdf22ac0ea3c.svg\" alt=\"X_{ij}=C(\\text{target }i\\text{ immediately followed by }j)\" style=\"width:42.914ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. First target a</h4><p>Next token is b → add 1 to X(a,b).</p></div><div class=\"step\"><h4>Step 2. Target b</h4><p>Next token is a → add 1 to X(b,a).</p></div><div class=\"step\"><h4>Step 3. Final a</h4><p>No following token → no addition.</p></div><div class=\"step\"><h4>Step 4. Write matrix</h4><table><thead><tr><th>Target / next</th><th>a</th><th>b</th></tr></thead><tbody><tr><td>a</td><td>0</td><td>1</td></tr><tr><td>b</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> a=[0,1], b=[1,0]. A different context window would produce a different matrix.</p></div><p class=\"cue\">Word ka meaning: uske aas-paas kaunse words kitni baar aaye, uski number-list.</p>"},{"id":"u5-representation","title":"Sparse, dense, distributional and distributed","html":"<p><strong>A sparse representation</strong> has many zero entries and often one coordinate per vocabulary item. BoW and TF–IDF are common sparse document representations. <strong>A dense embedding</strong> has comparatively few learned real-valued coordinates; one word's properties are spread across many coordinates.</p><table><thead><tr><th>Representation</th><th>What coordinates mean</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>One-hot</td><td>One identity position per vocabulary word</td><td>Unambiguous ID</td><td>Different words are orthogonal; no learned similarity</td></tr><tr><td>Count-based context vector</td><td>Context-word co-occurrence counts</td><td>Transparent corpus evidence</td><td>Large, sparse; frequent words may dominate</td></tr><tr><td>TF–IDF document vector</td><td>Weighted vocabulary terms</td><td>Useful retrieval weighting</td><td>Word order and contextual meaning are limited</td></tr><tr><td>Dense word embedding</td><td>Learned latent features</td><td>Compact semantic/syntactic relationships</td><td>Coordinates are not generally human-labelled features</td></tr></tbody></table><p><strong>Distributional</strong> describes learning from patterns of linguistic context. <strong>Distributed</strong> describes representing an item across multiple coordinates rather than a single active identity bit. These are related but different ideas. A one-hot ID alone does not learn distributional similarity.</p><h3>Model design choices</h3><p>Choose contexts (document, sentence, fixed window), weighting (raw counts, normalization, TF–IDF-like weighting or association scores), dimensionality reduction or learned embeddings, and a similarity measure. Cosine compares direction and is less affected by length than a raw dot product; Euclidean distance also reflects magnitude.</p><p class=\"cue\">Sparse = bahut zero. Dense = chhoti learned number-list. Similar context se useful similarity seekhte hain.</p>"},{"id":"u5-word2vec","title":"Word2Vec: CBOW and skip-gram from training pairs","html":"<p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>"},{"id":"u5-sentence","title":"Word analogies and sentence embeddings","html":"<p><strong>A sentence embedding</strong> represents an entire sentence by one fixed-length vector. A basic method averages word embeddings. More advanced encoders learn a sentence representation from context and task objectives.</p><div class=\"math-display\"><img src=\"math/9bd733523385a6f0.svg\" alt=\"v_{\\text{sentence}}=\\frac1n\\sum_{i=1}^{n}v_{w_i}.\" style=\"width:20.132ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div><p>This means add corresponding coordinates and divide each coordinate by the number of words. Averaging ignores order: “dog bites man” and “man bites dog” have the same average if their words are identical.</p><div class=\"example\"><p><strong>Question. Average the word vectors [1,0], [0,2] and [2,1] to represent a three-word sentence.</strong></p><div class=\"given\"><h4>Given</h4><p>Three two-dimensional vectors with equal weights.</p><h4>To find</h4><p>The two-dimensional sentence vector.</p></div><h4>Formula and why it applies</h4><p>Use coordinate-wise mean <span class=\"math-inline\"><img src=\"math/59b4e5d5faf31ee8.svg\" alt=\"v=(v_1+v_2+v_3)/3\" style=\"width:19.923ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. First coordinate</h4><p><span class=\"math-inline\"><img src=\"math/9e9f60c0d5d4390a.svg\" alt=\"1+0+2=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/96b707212e8196a2.svg\" alt=\"3/3=1\" style=\"width:7.542ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Second coordinate</h4><p><span class=\"math-inline\"><img src=\"math/8658ccf788305270.svg\" alt=\"0+2+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/96b707212e8196a2.svg\" alt=\"3/3=1\" style=\"width:7.542ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Sentence vector = [1,1].</p></div><div class=\"example\"><p><strong>Question. Toy word vectors are king=[3,2], man=[1,0], woman=[1,1]. Find king−man+woman and compare to queen=[3,3].</strong></p><div class=\"given\"><h4>Given</h4><p>All vectors use the same two-coordinate space.</p><h4>To find</h4><p>The analogy vector and its distance from queen.</p></div><h4>Formula and why it applies</h4><p>Vector arithmetic is coordinate by coordinate. Euclidean distance is the square root of the sum of squared coordinate differences.</p><div class=\"step\"><h4>Step 1. Subtract man</h4><p><span class=\"math-inline\"><img src=\"math/b6233b70d329ba84.svg\" alt=\"[3-1,2-0]=[2,2]\" style=\"width:19.864ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Add woman</h4><p><span class=\"math-inline\"><img src=\"math/ad3021d33d70757e.svg\" alt=\"[2+1,2+1]=[3,3]\" style=\"width:19.864ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare with queen</h4><p><span class=\"math-inline\"><img src=\"math/3428ab21f04811a8.svg\" alt=\"\\sqrt{(3-3)^2+(3-3)^2}=0\" style=\"width:24.774ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> The toy analogy exactly equals queen. Real learned embeddings only approximate some analogies.</p></div><p><strong>Contextual encoders</strong> can assign “bank” different representations in different sentences. BERT and RoBERTa produce contextual token representations; obtaining strong sentence similarity vectors requires an appropriate pooling/training method, not simply assuming every raw token vector is a sentence embedding. Universal Sentence Encoder is designed to encode sentence-level meaning. Skip-thought predicts surrounding sentences; InferSent learns from natural-language-inference supervision.</p><p class=\"cue\">Sentence average: har column add karo, words ki count se divide. Word order ka loss yaad rakh.</p>"}]},{"id":"u5-glove","title":"GloVe: global co-occurrence and weighted error","unit":5,"mode":"tee","scope":"TEE · Unit 5 PDF pages 119–130","sections":[{"id":"u5-glove-theory","title":"Why GloVe uses global statistics","html":"<p><strong>GloVe (Global Vectors) learns word embeddings by fitting weighted relationships in a global word–context co-occurrence matrix.</strong> Word2Vec uses local prediction examples; GloVe uses aggregate counts directly in its objective.</p><div class=\"math-display\"><img src=\"math/678c585ed4cafa14.svg\" alt=\"X_i=\\sum_k X_{ik},\\qquad P_{ik}=\\frac{X_{ik}}{X_i}.\" style=\"width:29.365ex;height:5.825ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6053336a6b0040cd.svg\" alt=\"X_{ik}\" style=\"width:3.447ex;height:1.902ex\" loading=\"lazy\" decoding=\"async\"></span> is how often context word <span class=\"math-inline\"><img src=\"math/1dc6f9b1a0213681.svg\" alt=\"k\" style=\"width:1.179ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> appears around target <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/e51016ac22dc64d1.svg\" alt=\"X_i\" style=\"width:2.613ex;height:1.902ex\" loading=\"lazy\" decoding=\"async\"></span> is the total of row <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/737c2c9c574f2ad5.svg\" alt=\"P_{ik}\" style=\"width:3.026ex;height:1.902ex\" loading=\"lazy\" decoding=\"async\"></span> is the resulting context probability.</p><p>The ratio <span class=\"math-inline\"><img src=\"math/330098eff375745b.svg\" alt=\"P(k\\mid i)/P(k\\mid j)\" style=\"width:15.892ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> helps identify how a probe context differs between two words. For targets ice and steam, a probe such as solid should favour ice; gas should favour steam; a probe shared similarly by both gives a ratio near one. These are data tendencies, not universal numerical identities.</p><div class=\"example\"><p><strong>Question. For context solid, ice has count 12 out of row total 20; steam has count 2 out of row total 40. Compute P(solid|ice), P(solid|steam) and their ratio.</strong></p><div class=\"given\"><h4>Given</h4><p>X(ice,solid)=12, X(ice)=20; X(steam,solid)=2, X(steam)=40.</p><h4>To find</h4><p>Two conditional probabilities and the ice/steam ratio.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/1b6f3de99376d438.svg\" alt=\"P(k\\mid i)=X_{ik}/X_i\" style=\"width:17.512ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, and <span class=\"math-inline\"><img src=\"math/f8639f057ec07b30.svg\" alt=\"R=P(k\\mid ice)/P(k\\mid steam)\" style=\"width:27.843ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Ice probability</h4><p><span class=\"math-inline\"><img src=\"math/b553cd0f20af7e2a.svg\" alt=\"12/20=0.6\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Steam probability</h4><p><span class=\"math-inline\"><img src=\"math/a23f9c2192e787e1.svg\" alt=\"2/40=0.05\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Ratio</h4><p><span class=\"math-inline\"><img src=\"math/4a1735e84fe18a45.svg\" alt=\"0.6/0.05=12\" style=\"width:13.325ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> The probe solid is 12 times as probable in ice's context under these counts.</p></div><div class=\"example\"><p><strong>Question. For probe water, ice and steam both have row total 50. Counts are 10 and 10. Calculate the ratio.</strong></p><div class=\"given\"><h4>Given</h4><p>Both probabilities use a denominator of 50.</p><h4>To find</h4><p>The probability ratio.</p></div><h4>Formula and why it applies</h4><p>Use row-normalized counts before taking the ratio.</p><div class=\"step\"><h4>Step 1. Ice probability</h4><p><span class=\"math-inline\"><img src=\"math/2d17e669222fac35.svg\" alt=\"10/50=0.2\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Steam probability</h4><p><span class=\"math-inline\"><img src=\"math/2d17e669222fac35.svg\" alt=\"10/50=0.2\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p><span class=\"math-inline\"><img src=\"math/468ec9ecee826ded.svg\" alt=\"0.2/0.2=1\" style=\"width:11.062ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Ratio 1: this probe does not distinguish the targets in this toy data.</p></div><div class=\"example\"><p><strong>Question. For probe gas, counts are 1/100 around ice and 20/100 around steam. Compute the ice-to-steam ratio.</strong></p><div class=\"given\"><h4>Given</h4><p>Conditional counts have the same row denominator.</p><h4>To find</h4><p>The ratio and interpretation.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/efe28e7e3bde3014.svg\" alt=\"R=P(gas\\mid ice)/P(gas\\mid steam)\" style=\"width:32.16ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Ice probability</h4><p><span class=\"math-inline\"><img src=\"math/fa188fed61277d35.svg\" alt=\"1/100=0.01\" style=\"width:12.696ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Steam probability</h4><p><span class=\"math-inline\"><img src=\"math/4373563868df4a11.svg\" alt=\"20/100=0.2\" style=\"width:12.696ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Ratio</h4><p><span class=\"math-inline\"><img src=\"math/4ed5ae8db66197fd.svg\" alt=\"0.01/0.2=0.05\" style=\"width:15.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Ratio 0.05, so gas is much more strongly associated with steam.</p></div><p class=\"cue\">Ratio >1: pehla word favoured. <1: doosra. ≈1: probe dono mein similar.</p>"},{"id":"u5-glove-loss","title":"The GloVe objective and numerical interpretation","html":"<div class=\"math-display\"><img src=\"math/2e4b741639de8430.svg\" alt=\"J=\\sum_{i,j:X_{ij}&gt;0}f(X_{ij})\\left(w_i^T\\widetilde w_j+b_i+\\widetilde b_j-\\ln X_{ij}\\right)^2.\" style=\"width:44.641ex;height:6.234ex\" loading=\"lazy\" decoding=\"async\"></div><p><strong>What each piece means:</strong> <span class=\"math-inline\"><img src=\"math/1990ec0f29e8d861.svg\" alt=\"w_i\" style=\"width:2.36ex;height:1.359ex\" loading=\"lazy\" decoding=\"async\"></span> is a target vector; <span class=\"math-inline\"><img src=\"math/57e45239d1931442.svg\" alt=\"\\widetilde w_j\" style=\"width:2.467ex;height:2.415ex\" loading=\"lazy\" decoding=\"async\"></span> is a separate context vector; the dot product estimates their compatibility; biases adjust word-level baselines. The desired score is the natural log of the observed count. Squaring penalizes both positive and negative errors. Weighting prevents unreliable rare pairs or extremely frequent pairs from dominating inappropriately.</p><div class=\"math-display\"><img src=\"math/9889df20ad438723.svg\" alt=\"f(x)=\\begin{cases}(x/x_{\\max})^\\alpha,&amp;0&lt;x&lt;x_{\\max}\\\\1,&amp;x\\ge x_{\\max}.\\end{cases}\" style=\"width:34.679ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div><p>The original commonly used settings are <span class=\"math-inline\"><img src=\"math/d2d81040be91ac39.svg\" alt=\"x_{\\max}=100\" style=\"width:10.87ex;height:1.864ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/57c3b9fea49de9d2.svg\" alt=\"\\alpha=0.75\" style=\"width:8.488ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></span>. They are hyperparameters, not learned word embeddings. Zero-count pairs do not require evaluating <span class=\"math-inline\"><img src=\"math/a4450c8290ea350d.svg\" alt=\"\\ln 0\" style=\"width:3.395ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span> in the displayed nonzero-count objective.</p><div class=\"example\"><p><strong>Question. For one nonzero GloVe pair, X=4, weighting f(X)=0.5, target vector [1,2], context vector [0.5,0], and both biases 0. Find its contribution to J.</strong></p><div class=\"given\"><h4>Given</h4><p>Use natural logarithm. Only one pair is being evaluated.</p><h4>To find</h4><p>Weighted squared residual.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/0b9576850c99f85a.svg\" alt=\"J_{ij}=f(X)(w^T\\widetilde w+b+\\widetilde b-\\ln X)^2\" style=\"width:32.335ex;height:2.933ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Dot product</h4><p><span class=\"math-inline\"><img src=\"math/b3e5abe1a60dc7f4.svg\" alt=\"1(0.5)+2(0)=0.5\" style=\"width:18.48ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Log-count target</h4><p><span class=\"math-inline\"><img src=\"math/88f99752ef835c83.svg\" alt=\"\\ln4\\approx1.386294\" style=\"width:14.96ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Residual</h4><p><span class=\"math-inline\"><img src=\"math/51c0d80ff79ed2cd.svg\" alt=\"0.5+0+0-1.386294=-0.886294\" style=\"width:35.323ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Square and weight</h4><p><span class=\"math-inline\"><img src=\"math/faebe1abd20fb32f.svg\" alt=\"(-0.886294)^2\\approx0.785518\" style=\"width:24.62ex;height:2.452ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiply by 0.5 → approximately 0.392759.</p></div><p class=\"answer\"><strong>Answer.</strong> The pair contributes approximately 0.392759 to the objective.</p></div><div class=\"example\"><p><strong>Question. A GloVe pair has X=e², weight 1, dot product 1.5 and biases 0.2 and 0.3. Calculate its objective contribution.</strong></p><div class=\"given\"><h4>Given</h4><p>Natural logarithm, so ln(e²)=2.</p><h4>To find</h4><p>The squared weighted error.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/b1d9328b46f12df0.svg\" alt=\"J_{ij}=f(X)(\\text{dot}+b+\\widetilde b-\\ln X)^2\" style=\"width:31.051ex;height:2.933ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Predicted score</h4><p><span class=\"math-inline\"><img src=\"math/e84d0514f15f7e73.svg\" alt=\"1.5+0.2+0.3=2\" style=\"width:18.354ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Target score</h4><p><span class=\"math-inline\"><img src=\"math/5c3429ffd674bcbd.svg\" alt=\"\\ln(e^2)=2\" style=\"width:9.837ex;height:2.452ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Residual and square</h4><p><span class=\"math-inline\"><img src=\"math/5e9eb71fd28f428c.svg\" alt=\"2-2=0\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ab6810c2ebb5c0c0.svg\" alt=\"1\\times0^2=0\" style=\"width:10.164ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Contribution 0: this pair is fitted exactly.</p></div><div class=\"example\"><p><strong>Question. Use xmax=100 and α=0.75. A GloVe pair has X=16 and residual 2. Find its weighting and loss contribution.</strong></p><div class=\"given\"><h4>Given</h4><p>16 is below xmax, so use the power branch.</p><h4>To find</h4><p>f(16) and weighted squared residual.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/2307be092fac7a7f.svg\" alt=\"f(16)=(16/100)^{0.75}\" style=\"width:19.864ex;height:2.468ex\" loading=\"lazy\" decoding=\"async\"></span>, and <span class=\"math-inline\"><img src=\"math/aa2cbf1be1ca48e7.svg\" alt=\"J_{ij}=f(16)\\times2^2\" style=\"width:15.823ex;height:2.552ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Ratio</h4><p><span class=\"math-inline\"><img src=\"math/1b290111c4a2b057.svg\" alt=\"16/100=0.16\" style=\"width:13.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Power</h4><p><span class=\"math-inline\"><img src=\"math/4ec2c364222018a7.svg\" alt=\"0.16^{0.75}=0.16^{3/4}\\approx0.252982\" style=\"width:28.247ex;height:2.275ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Square residual</h4><p><span class=\"math-inline\"><img src=\"math/7839fb9a78007523.svg\" alt=\"2^2=4\" style=\"width:6.267ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/5f73059a0e8e07a5.svg\" alt=\"0.252982\\times4\\approx1.011929\" style=\"width:24.009ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> f≈0.252982 and contribution≈1.011929.</p></div><h3>Six steps to explain the algorithm</h3><ol><li>Collect a corpus and choose a context window.</li><li>Build the global co-occurrence matrix.</li><li>Study row-normalized context probabilities and their ratios.</li><li>Define the weighted log-count fitting objective.</li><li>Optimize word/context vectors and biases.</li><li>Use the learned embeddings for similarity, analogy or downstream tasks.</li></ol><p class=\"cue\">GloVe: global counts → log target → dot product prediction → weighted squared error kam karo.</p>"}]},{"id":"u6","title":"Unit 6 · reference & discourse","unit":6,"sections":[{"id":"reference","title":"Reference, pragmatics and discourse","html":"<p><strong>Pragmatic analysis</strong> interprets an utterance using its situation and the speaker’s intended meaning. <strong>Discourse analysis</strong> studies how utterances connect across a text or conversation. Syntax and literal word meanings alone cannot settle every interpretation.</p><table><thead><tr><th>Text</th><th>Literal content</th><th>Contextual interpretation</th></tr></thead><tbody><tr><td>“Can you close the window?”</td><td>A question about ability.</td><td>Usually a polite request.</td></tr><tr><td>“Meera bought a laptop. It was expensive.”</td><td>Two sentences.</td><td>“It” connects the second sentence to the laptop.</td></tr><tr><td>“Meet me here tomorrow.”</td><td>An instruction.</td><td>Me, here and tomorrow depend on speaker, place and date.</td></tr></tbody></table><h3>Reference, mention and antecedent</h3><p>A <strong>referring expression</strong> points to an entity; a <strong>mention</strong> is its occurrence in the text. Its <strong>referent</strong> is the entity being discussed. An <strong>antecedent</strong> is a preceding expression used to interpret a later referring expression. Reference resolution identifies the intended referent. Coreference resolution groups mentions that refer to the same entity.</p><div class=\"flow\"><div class=\"node\">“Meera”<small>name mention</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Person entity<small>same referent</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">“she” / “the engineer”<small>other mentions</small></div></div><table><thead><tr><th>Concept</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Anaphora</td><td>Reference back to something introduced earlier.</td><td>“Riya arrived. She sat down.” She → Riya.</td></tr><tr><td>Cataphora</td><td>Reference forward to a later expression.</td><td>“Before she spoke, Riya checked the microphone.” she → Riya.</td></tr><tr><td>Exophora</td><td>Reference to the situation outside the text.</td><td>“Put it there”, said while pointing.</td></tr><tr><td>Coreference</td><td>Two or more mentions refer to the same entity.</td><td>“Dr Rao”, “the lecturer”, “she”.</td></tr><tr><td>Pronoun resolution</td><td>Find the referent of a pronoun.</td><td>Resolve “it” in “The laptop stopped because it overheated.”</td></tr></tbody></table><p>Coreference is broader than pronoun resolution: repeated names and descriptions also form a chain. Anaphora describes direction/dependence; coreference describes identity. In “I bought a car. The engine is noisy”, engine is related to the car but is not the same entity.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Reference = kiski baat? Coreference = alag mentions, same entity. Pronoun resolution = he/she/it kis se linked?</p><h3>Cohesion, coherence and discourse markers</h3>\n<p><strong>Cohesion</strong> is the explicit linguistic linking of a text through reference, repeated or related words, conjunctions and other devices. In “Rita bought a book. She read it”, she and it connect the second sentence to Rita and the book.</p>\n<p><strong>Coherence</strong> is the conceptual unity that makes a discourse meaningful. “The road flooded, so the match was cancelled” presents a plausible cause and consequence. A reader relates the propositions using context and knowledge.</p>\n<p><strong>Discourse markers</strong> signal relationships or organize speech: however signals contrast; therefore signals a result; first and next signal sequence; for example introduces an illustration.</p>\n<p>These concepts differ: “I like apples. Therefore the moon is square” has a linking word but no sensible inference. A connector alone does not guarantee coherence.</p>\n<p><strong>Yaad rakho:</strong> Cohesion = words se link; coherence = meaning se link; marker = relation ka signal.</p>"},{"id":"resolution","title":"Pronoun resolution: methods and examples","html":"<h3>A practical resolution procedure</h3><p>First detect the pronoun and candidate noun phrases. Eliminate candidates inconsistent with person, number, grammatical binding or relevant semantic constraints. Rank the surviving candidates using syntactic prominence, recency and discourse context. Preserve ambiguity if the available evidence does not decide.</p><table><thead><tr><th>Approach</th><th>How it works</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>Rule based / syntactic</td><td>Use parse trees, agreement and explicit search order; Hobbs is a classic example.</td><td>Can explain each decision without labelled training data.</td><td>Parsing errors and world knowledge gaps cause errors.</td></tr><tr><td>Salience based</td><td>Score candidates using recency, subjecthood and other discourse features; select the strongest compatible candidate.</td><td>Captures the tendency to refer again to prominent entities.</td><td>Feature weights and competing candidates can mislead.</td></tr><tr><td>Supervised statistical</td><td>Learn candidate/pronoun compatibility from labelled examples.</td><td>Combines many features from data.</td><td>Needs representative annotated examples.</td></tr><tr><td>Neural / contextual</td><td>Encode the surrounding text and score mention pairs or antecedents.</td><td>Can learn contextual patterns and long-range dependencies.</td><td>Needs data/compute and can still make confident mistakes.</td></tr></tbody></table><section class=\"example\"><h3>Worked analysis 1 · number and semantics</h3><p class=\"question\">Resolve “they” in: “Riya put the books on the shelf because they were heavy.”</p><div class=\"given\"><strong>Given</strong><p>Candidates: Riya (singular person), books (plural objects), shelf (singular object); pronoun they is plural here.</p><strong>To find</strong><p>The antecedent and a justified resolution procedure.</p></div><h3>Formula and why it applies</h3><p>Use number agreement first, then semantic compatibility. There is no multiplication formula in this linguistic task.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. List candidates</h4><p>Riya, the books, the shelf.</p></div><div class=\"step\"><h4>Step 2. Apply number agreement</h4><p>Riya and shelf are singular. Books is plural, matching they.</p></div><div class=\"step\"><h4>Step 3. Check meaning</h4><p>Books can be heavy; the causal explanation fits carrying/placing books.</p></div><div class=\"answer\">“They” refers to “the books”.</div></section><section class=\"example\"><h3>Worked analysis 2 · a complete coreference chain</h3><p class=\"question\">Identify the coreference chain in: “Dr Sen entered. The surgeon greeted Ravi. She opened her notebook.”</p><div class=\"given\"><strong>Given</strong><p>Mentions: Dr Sen, the surgeon, Ravi, she, her, her notebook. Assume the surgeon is Dr Sen and she/her refers to that surgeon.</p><strong>To find</strong><p>The person chain, and a mention that must not be placed in it.</p></div><h3>Formula and why it applies</h3><p>Group expressions by identity of referent; a possessive expression and the owned object are different entities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Link the name and description</h4><p>Dr Sen and the surgeon denote the same person under the given context.</p></div><div class=\"step\"><h4>Step 2. Link the pronouns</h4><p>She and her refer to the surgeon.</p></div><div class=\"step\"><h4>Step 3. Keep the notebook separate</h4><p>“Her notebook” is an object owned by the person; it is not the person herself.</p></div><div class=\"answer\">Person chain: {Dr Sen, the surgeon, She, her}. “Her notebook” is a separate object mention.</div></section><section class=\"example\"><h3>Worked analysis 3 · honest ambiguity</h3><p class=\"question\">Discuss the pronoun in: “Asha called Nisha after she finished work.”</p><div class=\"given\"><strong>Given</strong><p>Both named candidates are singular; the sentence gives no further context.</p><strong>To find</strong><p>Whether one referent is logically guaranteed.</p></div><h3>Formula and why it applies</h3><p>Agreement filters incompatible candidates but cannot always select between equally compatible candidates.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Check agreement</h4><p>Both Asha and Nisha are compatible with she.</p></div><div class=\"step\"><h4>Step 2. Check the event</h4><p>Either person could have finished work.</p></div><div class=\"step\"><h4>Step 3. State the limitation</h4><p>A heuristic may prefer a candidate, but grammar and this sentence alone do not prove the intended referent.</p></div><div class=\"answer\">Ambiguous without further context. State any heuristic and parse assumption before giving its preferred candidate.</div></section>"},{"id":"hobbs","title":"Hobbs’ algorithm, step by step","html":"<p><strong>Hobbs’ algorithm is a syntax-based procedure that searches constituent parse trees in a fixed order for a compatible noun-phrase antecedent of a pronoun.</strong> The tree determines which candidates are proposed first. Agreement and other relevant constraints determine whether a proposed candidate can be accepted.</p><p>It is not simply the rule “choose the closest noun”. A nearby noun may have the wrong number, may be syntactically ineligible, or may be visited after a structurally more prominent noun. The algorithm produces a preference under the supplied parse; ambiguous language can still require context.</p><h3>The tree vocabulary you need</h3><table><thead><tr><th>Term</th><th>Meaning</th><th>Example</th></tr></thead><tbody><tr><td>NP</td><td>Noun phrase: a phrase referring to an entity</td><td>the student; Anita; they</td></tr><tr><td>S</td><td>A sentence/clause node</td><td>the node containing a subject and predicate</td></tr><tr><td>VP</td><td>Verb phrase</td><td>told Ravi that she should revise</td></tr><tr><td>X</td><td>The NP or S node currently being searched</td><td>An algorithm label, not a word</td></tr><tr><td>Path p</td><td>The branch travelled upward from the pronoun/previous X</td><td>Used to distinguish left and right subtrees</td></tr><tr><td>N-bar (N′)</td><td>The noun-centred part of an NP in a grammar using that label</td><td>The nominal-child test depends on the given tree</td></tr><tr><td>Breadth-first</td><td>Visit shallower nodes before deeper ones</td><td>Level 1 before level 2</td></tr><tr><td>Left-to-right</td><td>Visit equally deep nodes in their written/tree order</td><td>Earlier left branch before right branch</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">Locate pronoun NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Climb to NP/S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Propose candidates in tree order</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Check compatibility</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Accept or continue searching</div></div><h3>The complete search procedure</h3><div class=\"step\"><h4>Step 1. Start at the pronoun</h4><p>Locate the NP immediately dominating the pronoun. “Dominating” means containing it as a descendant in the tree.</p></div><div class=\"step\"><h4>Step 2. Climb to the first NP or S</h4><p>Move upward to the first NP or S above that starting NP. Call this node X. Keep the upward path p.</p></div><div class=\"step\"><h4>Step 3. Search the left branches initially</h4><p>Below X, traverse branches to the left of p breadth-first and left-to-right. At this initial search, propose an NP only if another NP or S lies between that candidate and X. Test proposed candidates for the required agreement and constraints.</p></div><div class=\"step\"><h4>Step 4. If X is the highest sentence node, inspect earlier sentences</h4><p>Search previous sentence trees from most recent to oldest. Within each, use breadth-first, left-to-right order to propose NPs. Accept the first eligible compatible candidate, or report that no candidate was found in the available context.</p></div><div class=\"step\"><h4>Step 5. Otherwise climb again</h4><p>Move from X to the next NP or S above it. Record this new X and the path followed during the climb.</p></div><div class=\"step\"><h4>Step 6. Apply the higher-NP test</h4><p>If the new X is an NP, propose X when the path did not pass through its nominal N-bar child. Use the given parse labels; do not invent an N-bar branch missing from the question's structure.</p></div><div class=\"step\"><h4>Step 7. Search its left branches</h4><p>Traverse branches below the new X to the left of the path, breadth-first and left-to-right, proposing NPs. The special intervening-NP/S restriction belongs to the initial search in Step 3.</p></div><div class=\"step\"><h4>Step 8. If X is S, search the permitted right branches</h4><p>Search branches to the right of the path breadth-first and left-to-right. Do not descend below an encountered NP or S. Propose eligible NP candidates there.</p></div><div class=\"step\"><h4>Step 9. Repeat or stop</h4><p>Return to the highest-S check and continue the climb/search procedure until a compatible candidate is accepted or the available trees are exhausted. Record the candidate order rather than only writing an unexplained name.</p></div><h3>Why the first left search has an extra condition</h3><p>In a simple clause such as “John saw him”, the subject NP John is directly under the clause S. There is no extra NP or S between John and that S. The initial-search restriction therefore prevents casually selecting John as the ordinary local antecedent of him. Compare the reflexive “John saw himself”, which is a different grammatical case; do not treat every pronoun type as interchangeable.</p><section class=\"example\"><h3>Worked tree 1 · move to the previous sentence</h3><p class=\"question\"><strong>Question. Apply Hobbs’ search to “The student arrived. She smiled.” Assume the student is compatible with she.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree: [S [NP The student] [VP arrived]]. Current tree: [S [NP She] [VP smiled]].</p><h4>To find</h4><p>The selected antecedent and the search path.</p></div><h4>Method and why it applies</h4><p>Use the supplied constituent trees. The current sentence has no earlier candidate, so the highest-S rule activates previous-sentence search.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw both sentence structures</h4><pre aria-label=\"Two constituent trees\">Previous sentence             Current sentence\nS                             S\n├── NP: The student            ├── NP: She ← start\n└── VP: arrived                └── VP: smiled</pre></div><div class=\"step\"><h4>Step 2. Locate and climb</h4><p>Start at NP She. Its first higher NP/S is the current S. Set X to that S.</p></div><div class=\"step\"><h4>Step 3. Search left of the path</h4><p>She is the leftmost subject. No NP lies to its left in the current sentence.</p></div><div class=\"step\"><h4>Step 4. Use the highest-S rule</h4><p>This X is the highest S. Inspect the immediately preceding sentence tree.</p></div><div class=\"step\"><h4>Step 5. Propose its first NP</h4><p>Breadth-first, left-to-right finds NP The student.</p></div><div class=\"step\"><h4>Step 6. Check compatibility and accept</h4><p>The question stipulates that the student agrees with she. Accept this candidate.</p></div><div class=\"answer\"><strong>Answer.</strong> She refers to the student under the supplied assumptions.</div></section><section class=\"example\"><h3>Worked tree 2 · reject an incompatible subject</h3><p class=\"question\"><strong>Question. Resolve they in “Riya spoke to the students. They laughed.” Use a previous-sentence search and interpret they as plural.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree has subject NP Riya, then VP spoke [PP to [NP the students]]. Current subject is NP They.</p><h4>To find</h4><p>The candidate order and accepted antecedent.</p></div><h4>Method and why it applies</h4><p>Breadth-first search favours a shallow subject, but agreement must still be applied; a first candidate is not automatically a valid answer.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw the useful part of the previous tree</h4><pre aria-label=\"Riya and the students constituent tree\">S\n├── NP: Riya                 ← candidate 1\n└── VP\n    ├── V: spoke\n    └── PP\n        ├── P: to\n        └── NP: the students ← candidate 2</pre></div><div class=\"step\"><h4>Step 2. Search the current sentence</h4><p>From NP They climb to its S; there is no earlier NP in “They laughed”. This is the highest S, so move to the previous tree.</p></div><div class=\"step\"><h4>Step 3. Visit Riya first</h4><p>Riya is the shallower leftmost NP. Under the stated plural interpretation, this singular candidate fails number agreement.</p></div><div class=\"step\"><h4>Step 4. Visit the students</h4><p>Continue breadth-first. The next relevant NP is the students.</p></div><div class=\"step\"><h4>Step 5. Apply number agreement</h4><p>Students is plural and is an eligible candidate. It matches plural they.</p></div><div class=\"step\"><h4>Step 6. State the resolution</h4><p>Accept the students. The method did not simply accept the first noun it saw.</p></div><div class=\"answer\"><strong>Answer.</strong> They → the students. Candidate order: Riya rejected; the students accepted.</div></section><section class=\"example\"><h3>Worked tree 3 · climb out of an embedded clause</h3><p class=\"question\"><strong>Question. Resolve she in “Anita told Ravi that she should revise.” Assume Anita is compatible with she and Ravi is not. Use the displayed parse.</strong></p><div class=\"given\"><h4>Given</h4><p>The pronoun is the subject of an embedded S inside the main VP.</p><h4>To find</h4><p>The preferred antecedent found by the climb and left-branch search.</p></div><h4>Method and why it applies</h4><p>The embedded clause has no left candidate. Climbing to the main S exposes its subject Anita as the first suitable higher-level candidate.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Show the clause structure</h4><pre aria-label=\"Embedded clause pronoun tree\">S (main)\n├── NP: Anita                  ← accepted candidate\n└── VP\n    ├── V: told\n    ├── NP: Ravi\n    └── SBAR: that\n        └── S (embedded)       ← first X\n            ├── NP: she        ← start\n            └── VP: should revise</pre></div><div class=\"step\"><h4>Step 2. Start inside the embedded clause</h4><p>From NP she climb to the embedded S. There is no candidate to the left of she within this embedded S.</p></div><div class=\"step\"><h4>Step 3. Climb to the next NP/S</h4><p>The embedded S is not the highest S. Move upward through SBAR and VP to the main S. These intermediate nodes are not NP/S search nodes.</p></div><div class=\"step\"><h4>Step 4. Search left of the upward path</h4><p>At the main S, the subject NP Anita is a shallow left candidate. The object Ravi is deeper within the VP. Breadth-first order proposes Anita first.</p></div><div class=\"step\"><h4>Step 5. Check the stated compatibility</h4><p>Anita is compatible with she by the question's assumption. Accept it; no need to choose a later incompatible candidate.</p></div><div class=\"step\"><h4>Step 6. Give the result and its limit</h4><p>This is the algorithm's result under the displayed parse and agreement assumptions. It does not prove the intention of every speaker using an otherwise ambiguous sentence.</p></div><div class=\"answer\"><strong>Answer.</strong> She → Anita under the stated tree and compatibility information.</div></section><h3>Advantages, limitations and a complete exam answer</h3><table><thead><tr><th>Advantages</th><th>Limitations</th></tr></thead><tbody><tr><td>Explicit candidate order makes the decision traceable.</td><td>Wrong parse structure can produce the wrong search order.</td></tr><tr><td>Requires no labelled coreference-training corpus for its basic rules.</td><td>World knowledge and discourse intention may override syntactic preference.</td></tr><tr><td>Uses structure rather than only surface distance.</td><td>Some ambiguous, long-distance or unusual constructions need additional treatment.</td></tr></tbody></table><p>For a longer answer, write the definition, inputs, tree notation, ordered algorithm, one labelled tree with a candidate table, final antecedent, and limitations. In a worked question show separately: candidate → why proposed → agreement result → accept/reject. Do not equate the selected candidate with a logically guaranteed interpretation when the sentence is ambiguous.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Tree order candidate deta hai; agreement usko allow/reject karta hai. Nearest noun automatically answer nahi.</p>"}],"scope":"TEE only · Unit 6 · syllabus-based supplement; faculty slide pack not supplied"},{"id":"u7","title":"Unit 7 · applications","unit":7,"sections":[{"id":"classification","title":"Text classification and its full pipeline","html":"<p><strong>Text classification</strong> assigns a document to one or more predefined categories. Spam detection usually uses two classes; news classification may use several topics. In single-label multiclass classification, choose one of several categories. In multilabel classification, several labels may apply to the same document.</p><div class=\"flow\"><div class=\"node\">Define labels</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Prepare labelled examples</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Train representation + model</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evaluate on unseen text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Predict new labels</div></div><h3>An exam-ready pipeline</h3><table><thead><tr><th>Stage</th><th>What you do</th><th>Why it matters</th></tr></thead><tbody><tr><td>Task definition</td><td>Decide what counts as spam or which news topics exist.</td><td>Unclear labels create inconsistent training data.</td></tr><tr><td>Data collection and annotation</td><td>Collect representative examples and assign correct labels.</td><td>The model learns from these examples.</td></tr><tr><td>Split data</td><td>Separate training, validation and test data.</td><td>Test examples must not influence training choices.</td></tr><tr><td>Preprocess</td><td>Tokenize and normalise where suitable; retain meaningful negation.</td><td>Reduce irrelevant variation without deleting signal.</td></tr><tr><td>Represent</td><td>Use BoW, TF-IDF or learned embeddings.</td><td>Models need numerical features.</td></tr><tr><td>Train</td><td>Fit Naive Bayes, logistic regression or another appropriate model.</td><td>Learn how features predict categories.</td></tr><tr><td>Evaluate</td><td>Measure relevant precision, recall and F1 on held-out examples.</td><td>Accuracy alone may hide poor minority-class performance.</td></tr><tr><td>Deploy and monitor</td><td>Apply the same preprocessing and monitor changing language.</td><td>Incoming data can differ from old examples.</td></tr></tbody></table><p>Naive Bayes is especially useful for hand calculations. With a bag-of-words representation, its class score is the prior multiplied by the conditional probability of each token; repeated tokens repeat the factor. The “naive” assumption is conditional independence of features given the class, not that words are independent in real language.</p><div class=\"math-display\"><img src=\"math/6dd9b21835eaff13.svg\" alt=\"s(c)=P(c)\\prod_{w\\in V}P(w\\mid c)^{C(w,d)}\" style=\"width:28.469ex;height:4.928ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>C(w,d) counts word w in document d. C(w,c) counts it in training documents belonging to class c. N<sub>c</sub> is the total token count for class c. Add-one smoothing adds one to every vocabulary count and therefore adds |V| to the denominator. This is the same arithmetic taught for WSD, with document classes instead of senses.</p><section class=\"example\"><h3>Worked classification · two-token message</h3><p class=\"question\">A spam classifier has vocabulary {win, prize, meeting}. Priors are P(spam)=P(ham)=0.5. Spam token counts are [3,2,0]; ham counts are [0,0,5]. With add-one smoothing, classify “win prize”.</p><div class=\"given\"><strong>Given</strong><p>|V|=3; N(spam)=5; N(ham)=5; message has win once and prize once.</p><strong>To find</strong><p>Class scores and predicted label.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/81645a009f312045.svg\" alt=\"s(c)=P(c)P(\\text{win}\\mid c)P(\\text{prize}\\mid c)\" style=\"width:32.21ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>The model is multinomial Naive Bayes; multiply the two token likelihoods and the class prior.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compute the smoothed denominators</h4><div class=\"math-display\"><img src=\"math/7e931d91ea22e68e.svg\" alt=\"5+3=8\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Compute spam likelihoods</h4><div class=\"math-display\"><img src=\"math/724a47033195de19.svg\" alt=\"P(\\text{win}\\mid S)=\\frac{3+1}{8}=\\frac12\" style=\"width:24.509ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fc2cdb5225a070b5.svg\" alt=\"P(\\text{prize}\\mid S)=\\frac{2+1}{8}=\\frac38\" style=\"width:25.772ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute ham likelihoods</h4><div class=\"math-display\"><img src=\"math/4134fa5958e2a1ed.svg\" alt=\"P(\\text{win}\\mid H)=P(\\text{prize}\\mid H)=\\frac{0+1}{8}=\\frac18\" style=\"width:40.213ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Multiply the spam score</h4><div class=\"math-display\"><img src=\"math/79f02eee2a0a5ddb.svg\" alt=\"s(S)=\\frac12\\times\\frac12\\times\\frac38=\\frac{3}{32}=0.09375\" style=\"width:35.918ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Multiply the ham score</h4><div class=\"math-display\"><img src=\"math/05ad87647bbe0b7d.svg\" alt=\"s(H)=\\frac12\\times\\frac18\\times\\frac18=\\frac{1}{128}=0.0078125\" style=\"width:39.861ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Compare</h4><p>0.09375 > 0.0078125. These are unnormalised scores; the label is chosen by the larger score.</p></div><div class=\"answer\">Predicted label: spam.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Class prior × har word ki class-likelihood; sabse bada score wins.</p></section>"},{"id":"sentiment","title":"Sentiment analysis: meaning, methods, example","html":"<p><strong>Sentiment analysis</strong> identifies expressed opinion or attitude, often as positive, negative or neutral. Document-level analysis labels a complete text; sentence-level analysis labels a sentence; aspect-level analysis attaches sentiment to a specific feature or entity.</p><table><thead><tr><th>Review</th><th>Useful interpretation</th></tr></thead><tbody><tr><td>“The display is excellent, but the battery is poor.”</td><td>Display: positive; battery: negative. One overall label loses this distinction.</td></tr><tr><td>“The service is not good.”</td><td>Negative: negation changes good. Removing not can reverse the intended meaning.</td></tr><tr><td>“Great, another two-hour delay.”</td><td>Likely sarcasm: literal positive word alone is insufficient.</td></tr></tbody></table><h3>Approaches</h3><p><strong>Lexicon based:</strong> look up sentiment scores, combine them, and apply stated handling for negation/intensifiers. It is interpretable but fragile with context and sarcasm. <strong>Supervised:</strong> learn a mapping from labelled text features to sentiment labels. <strong>Neural/contextual:</strong> learn or use contextual representations to capture word interactions, then fine-tune a sentiment classifier. None guarantees correct interpretation of every review.</p><section class=\"example\"><h3>A specified lexicon calculation</h3><p class=\"question\">Use good = +2, excellent = +3 and slow = −2. A “not” immediately before a sentiment word reverses its score. Score “The support was not good but the delivery was excellent and slow.”</p><div class=\"given\"><strong>Given</strong><p>Three sentiment words; not modifies good only; sum word scores under the stated rule.</p><strong>To find</strong><p>Total sentiment score and label, taking positive totals as positive.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/f9356cb0249ff14a.svg\" alt=\"S=\\sum_i s_i\" style=\"width:9.921ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Apply the given negation rule before summing. This is a simplified specified model, not a universal linguistic rule.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify sentiment words</h4><p>good, excellent and slow.</p></div><div class=\"step\"><h4>Step 2. Apply negation</h4><div class=\"math-display\"><img src=\"math/b751e154a1c1b2a0.svg\" alt=\"s(\\text{not good})=-2\" style=\"width:17.216ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Add the contributions</h4><div class=\"math-display\"><img src=\"math/76ffe09c2be2d0ce.svg\" alt=\"S=-2+3-2=-1\" style=\"width:21.07ex;height:1.781ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Map score to label</h4><p>The sum is negative.</p></div><div class=\"answer\">Total score = −1; negative under this rule.</div></section>"},{"id":"evaluation","title":"Precision, recall, F1 and accuracy","html":"<p>Evaluation compares predicted results with known answers. A <strong>true positive</strong> is a correctly predicted positive; a <strong>false positive</strong> is a negative item predicted positive; a <strong>false negative</strong> is a missed positive; a <strong>true negative</strong> is a correctly rejected negative.</p><div class=\"math-display\"><img src=\"math/d9fa10a04601a634.svg\" alt=\"\\text{Precision}=\\frac{TP}{TP+FP}\" style=\"width:22.439ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/65330df51cf428ee.svg\" alt=\"\\text{Recall}=\\frac{TP}{TP+FN}\" style=\"width:19.837ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fa461c3c89d25a66.svg\" alt=\"F_1=\\frac{2PR}{P+R}=\\frac{2TP}{2TP+FP+FN}\" style=\"width:33.701ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c35bcbb3c320de01.svg\" alt=\"\\text{Accuracy}=\\frac{TP+TN}{TP+TN+FP+FN}\" style=\"width:35.482ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Precision asks how many predicted positives were correct. Recall asks how many actual positives were found. F1 balances them by a harmonic mean. If a denominator is zero, state the convention rather than dividing by zero.</p><section class=\"example\"><h3>Example 1 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=6, FP=2, FN=4, TN=8. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=6; FP=2; FN=4; TN=8.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/16635e3dc332a6fb.svg\" alt=\"P=\\frac{6}{6+2}=0.750000\" style=\"width:22.304ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/a1b816258848d9dc.svg\" alt=\"R=\\frac{6}{6+4}=0.600000\" style=\"width:22.323ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/2de5ef4a0ac69e0e.svg\" alt=\"F_1=\\frac{12}{12+2+4}=0.666667\" style=\"width:28.076ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/8934313942e2b516.svg\" alt=\"A=\\frac{6+8}{6+2+4+8}=0.700000\" style=\"width:30.096ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 0.7500; recall 0.6000; F1 0.6667; accuracy 0.7000.</div></section><section class=\"example\"><h3>Example 2 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=9, FP=3, FN=1, TN=7. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=9; FP=3; FN=1; TN=7.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/97b392f1812900f2.svg\" alt=\"P=\\frac{9}{9+3}=0.750000\" style=\"width:22.304ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/eec2430e01f99107.svg\" alt=\"R=\\frac{9}{9+1}=0.900000\" style=\"width:22.323ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/b58f8dd0b3cf6f35.svg\" alt=\"F_1=\\frac{18}{18+3+1}=0.818182\" style=\"width:28.076ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/df21b30335e9b090.svg\" alt=\"A=\\frac{9+7}{9+3+1+7}=0.800000\" style=\"width:30.096ex;height:4.796ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 0.7500; recall 0.9000; F1 0.8182; accuracy 0.8000.</div></section><section class=\"example\"><h3>Example 3 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=4, FP=0, FN=4, TN=12. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=4; FP=0; FN=4; TN=12.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/f133094efa30d271.svg\" alt=\"P=\\frac{4}{4+0}=1.000000\" style=\"width:22.304ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/656d499e455af020.svg\" alt=\"R=\\frac{4}{4+4}=0.500000\" style=\"width:22.323ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/a2397b5600ed6ed2.svg\" alt=\"F_1=\\frac{8}{8+0+4}=0.666667\" style=\"width:26.945ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/1cc17a482eb72469.svg\" alt=\"A=\\frac{4+12}{4+0+4+12}=0.800000\" style=\"width:31.227ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 1.0000; recall 0.5000; F1 0.6667; accuracy 0.8000.</div></section>"},{"id":"spelling","title":"Spelling correction and edit distance","html":"<p><strong>Spelling correction</strong> proposes the intended word or sentence when the observed text contains an error. A non-word error produces an invalid vocabulary item (“recieve”); a real-word error produces an existing word in the wrong context (“I will meat you”). Dictionary lookup can detect many non-words but cannot reliably detect real-word errors.</p><div class=\"flow\"><div class=\"node\">Detect suspicious text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Generate candidates</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Score edit + context fit</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose correction</div></div><h3>Minimum edit distance</h3><p>Levenshtein distance is the minimum total cost of insertions, deletions and substitutions needed to transform one string into another. In the examples below, each edit costs 1; matching characters cost 0. Transposition is not a single Levenshtein operation. State different costs explicitly if the question gives them.</p><div class=\"math-display\"><img src=\"math/ef2777a0390860c8.svg\" alt=\"D(i,j)=\\min\\begin{cases}D(i-1,j)+1\\\\D(i,j-1)+1\\\\D(i-1,j-1)+[a_i\\ne b_j]\\end{cases}\" style=\"width:40.47ex;height:7.792ex\" loading=\"lazy\" decoding=\"async\"></div><p>Rows represent prefixes of the source; columns represent prefixes of the target. D(i,j) is the best cost for transforming the first i source characters to the first j target characters. Initialise D(i,0)=i and D(0,j)=j. The three choices are deletion, insertion and diagonal match/substitution.</p><section class=\"example\"><h3>Example 1 · cat → cut</h3><p class=\"question\">Calculate the unit-cost Levenshtein distance from “cat” to “cut”. Show the dynamic-programming table.</p><div class=\"given\"><strong>Given</strong><p>Source=cat; target=cut; insertion=deletion=substitution=1; match=0.</p><strong>To find</strong><p>Minimum edit cost.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/dbb6791fed13f314.svg\" alt=\"D(i,j)=\\min(D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+c)\" style=\"width:63.097ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>c = 0 for matching characters, 1 otherwise. Compare all three possible ways to reach each cell.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise empty prefixes</h4><p>First row counts insertions; first column counts deletions.</p></div><div class=\"step\"><h4>Step 2. Fill row 1: source character “c”</h4><div class=\"math-display\"><img src=\"math/715c07a4ab771469.svg\" alt=\"D(1,1)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0ab677a634f01ae0.svg\" alt=\"D(1,2)=\\min(2+1,\\ 0+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a0d37091a67b769a.svg\" alt=\"D(1,3)=\\min(3+1,\\ 1+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Fill row 2: source character “a”</h4><div class=\"math-display\"><img src=\"math/132b0bf994fa1fe9.svg\" alt=\"D(2,1)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/26524a35ae995b95.svg\" alt=\"D(2,2)=\\min(1+1,\\ 1+1,\\ 0+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/ef96295cbb47c0f8.svg\" alt=\"D(2,3)=\\min(2+1,\\ 1+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Fill row 3: source character “t”</h4><div class=\"math-display\"><img src=\"math/d443351dab39e649.svg\" alt=\"D(3,1)=\\min(1+1,\\ 3+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0d6484992af2f005.svg\" alt=\"D(3,2)=\\min(1+1,\\ 2+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/725867dfbce579ce.svg\" alt=\"D(3,3)=\\min(2+1,\\ 2+1,\\ 1+0)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Read the completed matrix</h4><table><thead><tr><th>Source / target</th><th>∅</th><th>c</th><th>u</th><th>t</th></tr></thead><tbody><tr><td>∅</td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td>c</td><td>1</td><td>0</td><td>1</td><td>2</td></tr><tr><td>a</td><td>2</td><td>1</td><td>1</td><td>2</td></tr><tr><td>t</td><td>3</td><td>2</td><td>2</td><td>1</td></tr></tbody></table></div><div class=\"answer\">Minimum edit distance = 1.</div></section><section class=\"example\"><h3>Example 2 · at → cat</h3><p class=\"question\">Calculate the unit-cost Levenshtein distance from “at” to “cat”. Show the dynamic-programming table.</p><div class=\"given\"><strong>Given</strong><p>Source=at; target=cat; insertion=deletion=substitution=1; match=0.</p><strong>To find</strong><p>Minimum edit cost.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/dbb6791fed13f314.svg\" alt=\"D(i,j)=\\min(D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+c)\" style=\"width:63.097ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>c = 0 for matching characters, 1 otherwise. Compare all three possible ways to reach each cell.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise empty prefixes</h4><p>First row counts insertions; first column counts deletions.</p></div><div class=\"step\"><h4>Step 2. Fill row 1: source character “a”</h4><div class=\"math-display\"><img src=\"math/e16686e02e9f18c0.svg\" alt=\"D(1,1)=\\min(1+1,\\ 1+1,\\ 0+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a6adb2bfe71ef208.svg\" alt=\"D(1,2)=\\min(2+1,\\ 1+1,\\ 1+0)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a0d37091a67b769a.svg\" alt=\"D(1,3)=\\min(3+1,\\ 1+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Fill row 2: source character “t”</h4><div class=\"math-display\"><img src=\"math/a3ee153834d01ea4.svg\" alt=\"D(2,1)=\\min(1+1,\\ 2+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/7cf9b393d47f5d6d.svg\" alt=\"D(2,2)=\\min(1+1,\\ 2+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/ccb8721250bf5a16.svg\" alt=\"D(2,3)=\\min(2+1,\\ 2+1,\\ 1+0)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Read the completed matrix</h4><table><thead><tr><th>Source / target</th><th>∅</th><th>c</th><th>a</th><th>t</th></tr></thead><tbody><tr><td>∅</td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td>a</td><td>1</td><td>1</td><td>1</td><td>2</td></tr><tr><td>t</td><td>2</td><td>2</td><td>2</td><td>1</td></tr></tbody></table></div><div class=\"answer\">Minimum edit distance = 1.</div></section><section class=\"example\"><h3>Example 3 · cats → cat</h3><p class=\"question\">Calculate the unit-cost Levenshtein distance from “cats” to “cat”. Show the dynamic-programming table.</p><div class=\"given\"><strong>Given</strong><p>Source=cats; target=cat; insertion=deletion=substitution=1; match=0.</p><strong>To find</strong><p>Minimum edit cost.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/dbb6791fed13f314.svg\" alt=\"D(i,j)=\\min(D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+c)\" style=\"width:63.097ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>c = 0 for matching characters, 1 otherwise. Compare all three possible ways to reach each cell.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise empty prefixes</h4><p>First row counts insertions; first column counts deletions.</p></div><div class=\"step\"><h4>Step 2. Fill row 1: source character “c”</h4><div class=\"math-display\"><img src=\"math/715c07a4ab771469.svg\" alt=\"D(1,1)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0ab677a634f01ae0.svg\" alt=\"D(1,2)=\\min(2+1,\\ 0+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a0d37091a67b769a.svg\" alt=\"D(1,3)=\\min(3+1,\\ 1+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Fill row 2: source character “a”</h4><div class=\"math-display\"><img src=\"math/132b0bf994fa1fe9.svg\" alt=\"D(2,1)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/7acd2ee646c6109c.svg\" alt=\"D(2,2)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/e9bf43ed11bd7fac.svg\" alt=\"D(2,3)=\\min(2+1,\\ 0+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Fill row 3: source character “t”</h4><div class=\"math-display\"><img src=\"math/d443351dab39e649.svg\" alt=\"D(3,1)=\\min(1+1,\\ 3+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/b374d7c3144e3404.svg\" alt=\"D(3,2)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/24fd76b9544c3db3.svg\" alt=\"D(3,3)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Fill row 4: source character “s”</h4><div class=\"math-display\"><img src=\"math/0dd1d63ad4a25f3e.svg\" alt=\"D(4,1)=\\min(2+1,\\ 4+1,\\ 3+1)=3\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/cff6b6d394377532.svg\" alt=\"D(4,2)=\\min(1+1,\\ 3+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/f23dc80f45d4021b.svg\" alt=\"D(4,3)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Read the completed matrix</h4><table><thead><tr><th>Source / target</th><th>∅</th><th>c</th><th>a</th><th>t</th></tr></thead><tbody><tr><td>∅</td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td>c</td><td>1</td><td>0</td><td>1</td><td>2</td></tr><tr><td>a</td><td>2</td><td>1</td><td>0</td><td>1</td></tr><tr><td>t</td><td>3</td><td>2</td><td>1</td><td>0</td></tr><tr><td>s</td><td>4</td><td>3</td><td>2</td><td>1</td></tr></tbody></table></div><div class=\"answer\">Minimum edit distance = 1.</div></section><h3>Noisy-channel correction</h3><div class=\"math-display\"><img src=\"math/3ede23f6f61aee5c.svg\" alt=\"\\hat w=\\arg\\max_w P(x\\mid w)P(w)\" style=\"width:26.089ex;height:3.461ex\" loading=\"lazy\" decoding=\"async\"></div><p>x is the observed misspelling and w a candidate intended word. P(x | w) is the error-model likelihood; P(w) is the language-model prior. In context, replace the isolated-word prior with an appropriate contextual probability. A frequent word with a plausible typo may beat a rarer candidate, but context can reverse the ranking.</p><section class=\"example\"><h3>Candidate ranking</h3><p class=\"question\">For observed “teh”, candidate “the” has prior 0.05 and error likelihood 0.02. Candidate “ten” has prior 0.01 and likelihood 0.01. Select the intended word.</p><div class=\"given\"><strong>Given</strong><p>Two candidates and their prior/error-model likelihoods are supplied.</p><strong>To find</strong><p>Largest noisy-channel score.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/c03956cd222f4789.svg\" alt=\"s(w)=P(x\\mid w)P(w)\" style=\"width:20.797ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply likelihood by prior; the same evidence normaliser is irrelevant to ranking.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Score the</h4><div class=\"math-display\"><img src=\"math/0057723bfc328243.svg\" alt=\"s(\\text{the})=0.02\\times0.05=0.001\" style=\"width:27.963ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Score ten</h4><div class=\"math-display\"><img src=\"math/ef19fb34efc392f6.svg\" alt=\"s(\\text{ten})=0.01\\times0.01=0.0001\" style=\"width:29.094ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compare</h4><p>0.001 is ten times 0.0001.</p></div><div class=\"answer\">Choose “the”.</div></section>"},{"id":"translation","title":"Machine translation","html":"<p><strong>Machine translation (MT) automatically converts a source-language text into a target-language text while aiming to preserve its meaning and produce natural, grammatical output.</strong> The source is the language received; the target is the language generated. Translating words independently is insufficient because languages differ in order, agreement, idioms and word senses.</p><h3>What a translation must preserve</h3><table><thead><tr><th>Requirement</th><th>What to check</th><th>Example</th></tr></thead><tbody><tr><td>Participants</td><td>Who performed the action and who received it</td><td>Asha helped Riya must not become Riya helped Asha</td></tr><tr><td>Event and polarity</td><td>What happened, and whether it did not happen</td><td>Do not remove not</td></tr><tr><td>Time/aspect</td><td>When and how the event unfolds</td><td>is working differs from worked</td></tr><tr><td>Entities and quantities</td><td>Names, dates and numbers</td><td>₹500 must not become ₹5,000</td></tr><tr><td>Intended sense</td><td>Meaning selected by context</td><td>Financial bank versus riverbank</td></tr><tr><td>Target grammar</td><td>Natural order and agreement</td><td>Hindi object-before-verb often becomes English verb-before-object</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">Source text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Tokenize and analyse</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Resolve structure + sense</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose target words/structure</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Generate target sentence</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Check adequacy and fluency</div></div><h3>The three major approaches</h3><table><thead><tr><th>Approach</th><th>Procedure</th><th>Advantages</th><th>Limitations</th></tr></thead><tbody><tr><td>Rule-based MT</td><td>Analyse source words/grammar → transfer structure or meaning → generate target language using dictionaries and rules.</td><td>Explicit rules and terminology can be inspected.</td><td>Rule writing is expensive; exceptions and language pairs require maintenance.</td></tr><tr><td>Statistical MT</td><td>Learn translation correspondences from parallel text; combine translation adequacy with a target-language model; search candidate translations.</td><td>Learns from examples and can use phrase correspondences.</td><td>Sparse data, word-order differences and rare phrases cause errors.</td></tr><tr><td>Neural MT</td><td>Encode source context; a decoder generates target tokens conditioned on that context, often using attention.</td><td>Learns contextual representations and long-range interactions.</td><td>Needs suitable data/compute; can omit, distort or generate unsupported content.</td></tr></tbody></table><p><strong>Parallel corpus:</strong> aligned source and target examples expressing corresponding content. A monolingual corpus contains text in only one language. Parallel alignment does not mean every source word maps to exactly one target word: translation may insert, omit or reorder function words to preserve meaning.</p><p>In a simple noisy-channel view of statistical MT, let f be the observed source sentence and e a candidate target sentence. The decoder compares translation compatibility and target-language fluency:</p><div class=\"math-display\"><img src=\"math/ab454138c207cedf.svg\" alt=\"\\hat e=\\arg\\max_e P(f\\mid e)P(e).\" style=\"width:24.972ex;height:3.459ex\" loading=\"lazy\" decoding=\"async\"></div><p>P(f|e) is the translation-model likelihood; P(e) is the target-language-model prior. The common P(f) denominator is omitted for ranking. A modern MT system may use a different objective; this formula explains the stated statistical model rather than every translation system.</p><section class=\"example\"><h3>Worked application 1 · translation requires reordering</h3><p class=\"question\"><strong>Question. Translate the simple Hindi sentence “मैं पानी पीता हूँ” into natural English and explain the processing stages.</strong></p><div class=\"given\"><h4>Given</h4><p>Intended subject is I; object is water; predicate expresses drinking in a habitual/simple-present reading.</p><h4>To find</h4><p>A natural translation with preserved roles and the stage-by-stage explanation.</p></div><h4>Method and why it applies</h4><p>Identify roles before generating the target order. Use natural English subject–verb–object order for this sentence rather than copying the Hindi order.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the source components</h4><table><thead><tr><th>Source component</th><th>Function</th><th>Meaning</th></tr></thead><tbody><tr><td>मैं</td><td>Subject</td><td>I</td></tr><tr><td>पानी</td><td>Object</td><td>water</td></tr><tr><td>पीता हूँ</td><td>Predicate</td><td>drink, habitual/simple-present reading</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Build the meaning relation</h4><p>The speaker performs the action drink; water is what is drunk. The subject and object must stay attached to these roles.</p></div><div class=\"step\"><h4>Step 3. Choose target lexical forms</h4><p>मैं → I; पानी → water; the predicate is naturally realized as drink with subject I in this reading.</p></div><div class=\"step\"><h4>Step 4. Arrange target syntax</h4><p>English order here is subject I + verb drink + object water.</p></div><div class=\"step\"><h4>Step 5. Check adequacy</h4><p>The participant, action and object are retained. No new object, negation or time expression has been invented.</p></div><div class=\"step\"><h4>Step 6. Check fluency</h4><p>“I drink water” is natural English. A literal “I water drink” retains words but fails the required target order.</p></div><div class=\"answer\"><strong>Answer.</strong> A suitable translation is “I drink water.” The processing preserves meaning while changing structure.</div></section><section class=\"example\"><h3>Worked application 2 · one word, two meanings</h3><p class=\"question\"><strong>Question. Explain how an MT system should distinguish bank in “She deposited money in the bank” and “They sat on the bank of the river” before translation.</strong></p><div class=\"given\"><h4>Given</h4><p>Two English source sentences contain the same written word bank.</p><h4>To find</h4><p>The intended sense in each and suitable Hindi phrase-level renderings.</p></div><h4>Method and why it applies</h4><p>Apply word-sense disambiguation using nearby context before choosing the target term. Identical spelling does not force identical translation.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Collect the first sentence's clues</h4><p>Deposited and money strongly support the financial-institution sense.</p></div><div class=\"step\"><h4>Step 2. Select its target expression</h4><p>Use बैंक for the financial institution; retain the money-deposit event in the complete translated sentence.</p></div><div class=\"step\"><h4>Step 3. Collect the second sentence's clues</h4><p>River, sat and the location phrase support land beside a river.</p></div><div class=\"step\"><h4>Step 4. Select its target expression</h4><p>Use नदी का किनारा / नदी के किनारे as appropriate to the target sentence. A financial-bank translation would be wrong here.</p></div><div class=\"step\"><h4>Step 5. Generate grammatical context</h4><p>A suitable rendering of the second sentence is “वे नदी के किनारे बैठे।” Grammar adjusts the phrase to its role; do not paste an isolated dictionary form without inflection.</p></div><div class=\"step\"><h4>Step 6. State why a dictionary alone fails</h4><p>A bilingual entry offers candidate words. Context and syntax select and inflect the candidate expressing the intended sense.</p></div><div class=\"answer\"><strong>Answer.</strong> Financial bank → बैंक; riverbank → नदी का किनारा, with grammatical realization such as नदी के किनारे in the sentence.</div></section><section class=\"example\"><h3>Worked numerical 3 · compare two statistical translations</h3><p class=\"question\"><strong>Question. A statistical MT system compares candidate A with P(f|A)=0.12 and P(A)=0.03, and candidate B with P(f|B)=0.08 and P(B)=0.06. Select the candidate under the noisy-channel product model.</strong></p><div class=\"given\"><h4>Given</h4><p>Two candidate translations; likelihoods and target-language priors are provided. Ignore all other candidates for this ranking exercise.</p><h4>To find</h4><p>Each score and the selected translation.</p></div><h4>Method and why it applies</h4><p>Multiply translation likelihood by target-language prior because this specified model values both compatibility and fluency. These products are comparison scores, not normalized posterior probabilities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Write the scoring rule</h4><div class=\"math-display\"><img src=\"math/cff4fc3f67bedf64.svg\" alt=\"s(e)=P(f\\mid e)P(e).\" style=\"width:19.679ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Compute candidate A</h4><div class=\"math-display\"><img src=\"math/e1fe9eb8c63ff3f5.svg\" alt=\"s(A)=0.12\\times0.03=0.0036.\" style=\"width:28.277ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute candidate B</h4><div class=\"math-display\"><img src=\"math/723c1308f4a70743.svg\" alt=\"s(B)=0.08\\times0.06=0.0048.\" style=\"width:28.298ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Compare the products</h4><p>0.0048 > 0.0036. B wins even though A had a larger translation likelihood; B's target-language prior compensates.</p></div><div class=\"step\"><h4>Step 5. Interpret the result</h4><p>The model prefers B under the supplied numbers. The score alone does not establish that B is semantically correct; a poor model can rank a bad translation highly.</p></div><div class=\"answer\"><strong>Answer.</strong> Select B, with score 0.0048 versus A's 0.0036.</div></section><h3>Evaluation and common failure cases</h3><p><strong>Adequacy</strong> asks whether the original information and intended meaning were preserved. <strong>Fluency</strong> asks whether the target text is natural and grammatical. A fluent sentence can still mistranslate a negation or number, so assess both. Automatic reference-overlap metrics provide a useful signal, but several valid translations can use different words.</p><table><thead><tr><th>Failure</th><th>Why it occurs</th><th>What the system needs</th></tr></thead><tbody><tr><td>Word-for-word order</td><td>Source and target syntax differ</td><td>Structural modelling/reordering</td></tr><tr><td>Wrong bank/bat sense</td><td>Multiple senses share a written form</td><td>Context-sensitive lexical choice</td></tr><tr><td>Idiomatic phrase translated literally</td><td>Meaning is not the sum of isolated words</td><td>Phrase/context knowledge</td></tr><tr><td>Rare name or specialist term corrupted</td><td>Weak vocabulary/domain coverage</td><td>Appropriate data and terminology handling</td></tr><tr><td>Missing negation or number</td><td>Omission or generation error</td><td>Content-preservation checks</td></tr><tr><td>Low-resource language pair</td><td>Few representative parallel examples</td><td>Suitable data collection/adaptation</td></tr></tbody></table><p>For a 10-mark design explanation, connect the definition, pipeline, three approaches, worked source-to-target example, data requirements, evaluation and limitations. Merely listing “rule based, statistical, neural” does not explain how a translation is produced.</p><p class=\"cue\"><strong>Yaad rakho:</strong> MT: pehle kaun-kya-kisko samjho; phir target language ke words aur order mein wahi meaning banao.</p>"},{"id":"qa","title":"Question answering","html":"<p><strong>Question answering (QA) returns an answer to a natural-language question using available evidence or knowledge.</strong> Information retrieval usually returns ranked documents; QA must identify the requested information and deliver the answer. A relevant document is useful evidence but is not automatically the answer.</p><h3>Question types and answer types</h3><table><thead><tr><th>Question</th><th>Expected answer type</th><th>Required operation</th></tr></thead><tbody><tr><td>Who founded the company?</td><td>Person or organisation</td><td>Find the founder relation</td></tr><tr><td>When did the museum open?</td><td>Date/time</td><td>Locate the opening date</td></tr><tr><td>Where is the campus?</td><td>Location</td><td>Locate the campus-location relation</td></tr><tr><td>How many books were issued?</td><td>Quantity</td><td>Read or compute the stated count</td></tr><tr><td>Why was the train cancelled?</td><td>Reason/explanation</td><td>Find the causal evidence</td></tr><tr><td>Is the office open on Sunday?</td><td>Yes/no with evidence</td><td>Check the relevant schedule statement</td></tr></tbody></table><p><strong>Closed-domain QA</strong> operates within a restricted area such as a university handbook. <strong>Open-domain QA</strong> addresses a wider range of subjects and usually needs broad retrieval. <strong>Extractive QA</strong> selects a span from a passage. <strong>Generative QA</strong> constructs answer text; it still must preserve the evidence and avoid unsupported details.</p><div class=\"flow\"><div class=\"node\">Question analysis</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evidence retrieval</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Passage/record understanding</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Answer selection or composition</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Support check</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Present answer</div></div><h3>Explain each module</h3><table><thead><tr><th>Module</th><th>What happens</th><th>Why it matters</th></tr></thead><tbody><tr><td>Question analysis</td><td>Identify topic, intent, constraints and answer type.</td><td>When asks for a time, not a place.</td></tr><tr><td>Retrieval</td><td>Find a relevant passage or structured fact.</td><td>Reduces the search space.</td></tr><tr><td>Evidence understanding</td><td>Parse relations, resolve references and ambiguous words.</td><td>The correct date must belong to the correct event.</td></tr><tr><td>Answer formation</td><td>Extract a span or compose a short supported response.</td><td>Turns a document into an actual answer.</td></tr><tr><td>Verification</td><td>Check whether every claimed detail follows from evidence.</td><td>Prevents filling gaps by guessing.</td></tr><tr><td>Presentation</td><td>Return a concise answer with suitable context.</td><td>Avoids dumping unrelated text.</td></tr></tbody></table><section class=\"example\"><h3>Worked application 1 · extract the correct fact</h3><p class=\"question\"><strong>Question. Given “The City Museum opened in 1998 in Pune. It was renovated in 2016”, answer “When did the museum open?” Show the QA stages.</strong></p><div class=\"given\"><h4>Given</h4><p>A two-sentence passage. Dates 1998 and 2016 refer to different events.</p><h4>To find</h4><p>The opening date, not the renovation date.</p></div><h4>Method and why it applies</h4><p>Use extractive QA: identify the requested event and expected date type, then choose the span linked to that event.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Analyse the question</h4><p>When requires a date/time answer. The event is opening; the entity is the City Museum.</p></div><div class=\"step\"><h4>Step 2. Retrieve the relevant sentence</h4><p>The first sentence mentions the museum and its opening. The second sentence discusses renovation.</p></div><div class=\"step\"><h4>Step 3. Identify event–date relations</h4><table><thead><tr><th>Event</th><th>Date</th></tr></thead><tbody><tr><td>opened</td><td>1998</td></tr><tr><td>renovated</td><td>2016</td></tr></tbody></table></div><div class=\"step\"><h4>Step 4. Select the answer span</h4><p>1998 is attached to opened, so select the four-character year span 1998.</p></div><div class=\"step\"><h4>Step 5. Reject the distractor</h4><p>2016 is also a date, but it answers a different question: when was the museum renovated?</p></div><div class=\"step\"><h4>Step 6. Present the answer</h4><p>“The museum opened in 1998.”</p></div><div class=\"answer\"><strong>Answer.</strong> 1998. Matching only the answer type date would be insufficient without matching the event.</div></section><section class=\"example\"><h3>Worked application 2 · resolve a pronoun before answering</h3><p class=\"question\"><strong>Question. Given “Mira joined Orion Labs in 2022. She became its research lead in 2024”, answer “Who became Orion Labs' research lead, and when?”</strong></p><div class=\"given\"><h4>Given</h4><p>The passage contains the name Mira, pronoun She, organisation Orion Labs and possessive its. Assume the normal reading that She refers to Mira and its to Orion Labs.</p><h4>To find</h4><p>The person and the date of becoming research lead.</p></div><h4>Method and why it applies</h4><p>Combine reference resolution with relation extraction. The question asks for two fields, both tied to the promotion/role event.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify requested fields</h4><p>Who → person; when → date. The relation is became research lead of Orion Labs.</p></div><div class=\"step\"><h4>Step 2. Resolve mentions</h4><table><thead><tr><th>Mention</th><th>Referent</th></tr></thead><tbody><tr><td>She</td><td>Mira</td></tr><tr><td>its</td><td>Orion Labs</td></tr></tbody></table></div><div class=\"step\"><h4>Step 3. Read the target event</h4><p>After resolution, the second sentence states that Mira became Orion Labs' research lead in 2024.</p></div><div class=\"step\"><h4>Step 4. Distinguish the dates</h4><p>2022 belongs to joining the organisation. 2024 belongs to becoming research lead.</p></div><div class=\"step\"><h4>Step 5. Compose a supported answer</h4><p>“Mira became Orion Labs' research lead in 2024.”</p></div><div class=\"step\"><h4>Step 6. Verify completeness</h4><p>The answer supplies both requested fields and does not add an unsupported department, qualification or reason.</p></div><div class=\"answer\"><strong>Answer.</strong> Mira, in 2024. Reference resolution connects the second sentence to the named person and organisation.</div></section><section class=\"example\"><h3>Worked application 3 · detect insufficient evidence</h3><p class=\"question\"><strong>Question. A handbook excerpt states “The library opens at 8 a.m. on weekdays.” A user asks “At what time does it close on Sunday?” Explain the correct QA response.</strong></p><div class=\"given\"><h4>Given</h4><p>Only the opening time for weekdays is supplied. No closing time or Sunday schedule is present.</p><h4>To find</h4><p>Whether an answer is supported and how to handle the missing information.</p></div><h4>Method and why it applies</h4><p>Compare every question constraint against the evidence. Topic overlap with library is not sufficient: time type and day must also match.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Extract the question constraints</h4><table><thead><tr><th>Constraint</th><th>Requested</th></tr></thead><tbody><tr><td>Entity</td><td>Library</td></tr><tr><td>Event</td><td>Closing</td></tr><tr><td>Day</td><td>Sunday</td></tr><tr><td>Answer type</td><td>Time</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Extract the supplied fact</h4><p>Entity=library; event=opening; day=weekdays; time=8 a.m.</p></div><div class=\"step\"><h4>Step 3. Identify mismatches</h4><p>Opening is not closing. Weekdays do not supply a Sunday schedule.</p></div><div class=\"step\"><h4>Step 4. Avoid the unsupported substitution</h4><p>Do not answer 8 a.m. just because it is the only time in the passage.</p></div><div class=\"step\"><h4>Step 5. Return an evidence-limited response</h4><p>“The excerpt does not state the library's Sunday closing time.” A system with further retrieval can search a relevant schedule.</p></div><div class=\"step\"><h4>Step 6. State the benefit</h4><p>The system avoids converting a relevant-looking number into an incorrect answer.</p></div><div class=\"answer\"><strong>Answer.</strong> No Sunday closing time is supported by the excerpt. Report insufficient evidence or retrieve the missing schedule.</div></section><h3>Advantages, limits and evaluation</h3><table><thead><tr><th>Design choice</th><th>Benefit</th><th>Limitation</th></tr></thead><tbody><tr><td>Extractive answer</td><td>The returned wording comes directly from evidence.</td><td>The answer may require combining sentences or may not be present as one span.</td></tr><tr><td>Generative answer</td><td>Can combine supported facts into a readable response.</td><td>Can introduce unsupported information unless carefully checked.</td></tr><tr><td>Closed-domain collection</td><td>Controlled terminology and relevant resources.</td><td>Cannot answer facts outside its knowledge source.</td></tr><tr><td>Broad retrieval</td><td>Wider question coverage.</td><td>Irrelevant, outdated or conflicting sources can be retrieved.</td></tr></tbody></table><p>Evaluate <strong>exact match</strong> when a canonical answer string is expected, <strong>token overlap/F1</strong> when wording may vary, and <strong>factual correctness and completeness</strong> when answers are composed. An answer can be grammatically fluent but wrong. Questions with no answer in the evidence should be included in evaluation so the system's restraint is also tested.</p><p>For a longer exam answer, define QA, distinguish it from retrieval, explain answer types and system variants, draw the pipeline, work through a passage including distractors, and discuss ambiguity, missing evidence and evaluation. A list of chatbot names is not a QA design.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Question ka entity + event + constraint match karo. Passage mein koi bhi number mil gaya matlab answer nahi.</p>"},{"id":"extraction","title":"Information extraction","html":"<p><strong>Information extraction (IE) converts unstructured language into structured information such as named entities, relations and events.</strong> A structured output has explicit fields or records that can be stored, searched or analysed. IE is broader than NER: finding two names does not yet determine how those entities are related.</p><h3>The three levels of extracted information</h3><table><thead><tr><th>Level</th><th>What it identifies</th><th>Example</th></tr></thead><tbody><tr><td>Entity extraction / NER</td><td>A span and its entity type</td><td>Asha → person; Orbit Labs → organisation</td></tr><tr><td>Relation extraction</td><td>A labelled connection between entities</td><td>works-for(Asha, Orbit Labs)</td></tr><tr><td>Event extraction</td><td>An occurrence with roles and attributes</td><td>Joining: employee=Asha, employer=Orbit Labs, date=2025</td></tr></tbody></table><p>An <strong>entity</strong> is a participant such as a person or organisation. A <strong>relation</strong> links participants. An <strong>event</strong> describes something that happened, may happen or did not happen. An <strong>event role</strong> names a participant's function: buyer, seller, employee, employer, location or time. These labels must follow the chosen extraction schema.</p><div class=\"flow\"><div class=\"node\">Raw text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Sentence/token processing</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Entity spans + types</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Reference resolution</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Relations and event roles</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Normalize and store records</div></div><h3>An extraction pipeline explained</h3><table><thead><tr><th>Step</th><th>Operation</th><th>Reason</th></tr></thead><tbody><tr><td>Specify schema</td><td>Choose fields and allowed relations/events.</td><td>A system needs to know what records it is building.</td></tr><tr><td>Preprocess</td><td>Segment sentences and tokenize without losing useful structure.</td><td>Locate expressions and boundaries.</td></tr><tr><td>Recognise entities</td><td>Find spans and assign types.</td><td>Names can contain several words.</td></tr><tr><td>Resolve references</td><td>Link pronouns/descriptions to the right entities.</td><td>Two mentions may denote one participant.</td></tr><tr><td>Extract links/events</td><td>Use patterns, syntax or learned models.</td><td>Co-occurrence alone does not identify a relationship.</td></tr><tr><td>Handle qualifiers</td><td>Preserve negation, time and uncertainty.</td><td>Not hired differs from hired.</td></tr><tr><td>Normalize</td><td>Standardize dates, names or quantities where justified.</td><td>Equivalent forms should be comparable.</td></tr><tr><td>Store/evaluate</td><td>Save records and compare them with annotated answers.</td><td>Wrong links matter even if entity names are correct.</td></tr></tbody></table><section class=\"example\"><h3>Worked application 1 · turn a sentence into a record</h3><p class=\"question\"><strong>Question. Extract entities and a joining event from “Asha joined Orbit Labs in Mumbai on 3 May 2025.” Use fields person, organisation, location, event and date.</strong></p><div class=\"given\"><h4>Given</h4><p>One affirmative sentence; Orbit Labs is an organisation and Mumbai is a location.</p><h4>To find</h4><p>Entity spans/types and one structured joining record.</p></div><h4>Method and why it applies</h4><p>Find the complete entity spans, then assign their roles using the verb joined and its grammatical context.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Mark entity spans</h4><table><thead><tr><th>Span</th><th>Type</th></tr></thead><tbody><tr><td>Asha</td><td>Person</td></tr><tr><td>Orbit Labs</td><td>Organisation</td></tr><tr><td>Mumbai</td><td>Location</td></tr><tr><td>3 May 2025</td><td>Date</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Identify the event trigger</h4><p>Joined signals a joining event. The subject Asha is the joining person; Orbit Labs is the joined organisation.</p></div><div class=\"step\"><h4>Step 3. Attach contextual fields</h4><p>In Mumbai supplies a location associated with the stated joining event. On 3 May 2025 supplies its date. Do not infer the company's permanent headquarters from this sentence alone.</p></div><div class=\"step\"><h4>Step 4. Normalize the date</h4><p>The unambiguous date can be stored as 2025-05-03 while preserving its original text.</p></div><div class=\"step\"><h4>Step 5. Build the record</h4><table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td>event</td><td>joining</td></tr><tr><td>person</td><td>Asha</td></tr><tr><td>organisation</td><td>Orbit Labs</td></tr><tr><td>location</td><td>Mumbai</td></tr><tr><td>date</td><td>2025-05-03</td></tr></tbody></table></div><div class=\"step\"><h4>Step 6. State the information limit</h4><p>The sentence supports a joining event on that date. By itself it does not prove that Asha still works there indefinitely.</p></div><div class=\"answer\"><strong>Answer.</strong> A joining record for Asha and Orbit Labs at the stated location/date, with complete entity spans preserved.</div></section><section class=\"example\"><h3>Worked application 2 · direction of a relation matters</h3><p class=\"question\"><strong>Question. From “Nova acquired Luma for ₹50 crore in 2025”, extract an acquisition event with buyer, acquired organisation, amount and year.</strong></p><div class=\"given\"><h4>Given</h4><p>Nova and Luma are organisation names. The active verb is acquired; no seller is named.</p><h4>To find</h4><p>A correctly directed acquisition record.</p></div><h4>Method and why it applies</h4><p>Use grammatical roles to identify buyer and acquired organisation. Merely returning the unordered pair {Nova,Luma} loses the event direction.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Recognise participant entities</h4><p>Nova is the subject organisation; Luma is the object organisation.</p></div><div class=\"step\"><h4>Step 2. Locate the trigger</h4><p>Acquired identifies an acquisition event.</p></div><div class=\"step\"><h4>Step 3. Assign roles</h4><table><thead><tr><th>Role</th><th>Entity</th></tr></thead><tbody><tr><td>Buyer/acquirer</td><td>Nova</td></tr><tr><td>Acquired organisation</td><td>Luma</td></tr></tbody></table></div><div class=\"step\"><h4>Step 4. Extract amount and time</h4><p>Amount text=₹50 crore; year=2025. Currency and magnitude belong together; do not drop crore or replace it by lakh.</p></div><div class=\"step\"><h4>Step 5. Create the record</h4><table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td>event</td><td>acquisition</td></tr><tr><td>buyer</td><td>Nova</td></tr><tr><td>acquired_organisation</td><td>Luma</td></tr><tr><td>amount</td><td>INR 50 crore</td></tr><tr><td>year</td><td>2025</td></tr><tr><td>seller</td><td>Not stated</td></tr></tbody></table></div><div class=\"step\"><h4>Step 6. Reject an unsupported inference</h4><p>The sentence does not name the former owner/seller. Luma is the acquired organisation, not automatically the seller.</p></div><div class=\"answer\"><strong>Answer.</strong> Acquisition(buyer=Nova, acquired organisation=Luma, amount=INR 50 crore, year=2025). Seller remains unspecified.</div></section><section class=\"example\"><h3>Worked application 3 · reference, negation and time</h3><p class=\"question\"><strong>Question. Extract employment-related events from “Ravi joined Vega in 2021. He left the company in 2024. He did not join Orion.” Keep event type, person, organisation, date and polarity.</strong></p><div class=\"given\"><h4>Given</h4><p>He refers to Ravi; the company refers to Vega. The last sentence explicitly negates joining Orion.</p><h4>To find</h4><p>A structured event list without claiming an unsupported current employer.</p></div><h4>Method and why it applies</h4><p>Resolve references, identify each event separately and preserve whether it is affirmed or negated.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Resolve the repeated mentions</h4><table><thead><tr><th>Mention</th><th>Referent</th></tr></thead><tbody><tr><td>He in sentence 2</td><td>Ravi</td></tr><tr><td>the company</td><td>Vega</td></tr><tr><td>He in sentence 3</td><td>Ravi</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Extract the first event</h4><p>Joining; person=Ravi; organisation=Vega; date=2021; polarity=affirmed.</p></div><div class=\"step\"><h4>Step 3. Extract the second event</h4><p>Leaving; person=Ravi; organisation=Vega; date=2024; polarity=affirmed.</p></div><div class=\"step\"><h4>Step 4. Extract the third statement</h4><p>Joining; person=Ravi; organisation=Orion; date=not stated; polarity=negated. This must not create an affirmative employment relation with Orion.</p></div><div class=\"step\"><h4>Step 5. Write the event table</h4><table><thead><tr><th>Event</th><th>Person</th><th>Organisation</th><th>Date</th><th>Polarity</th></tr></thead><tbody><tr><td>joining</td><td>Ravi</td><td>Vega</td><td>2021</td><td>Affirmed</td></tr><tr><td>leaving</td><td>Ravi</td><td>Vega</td><td>2024</td><td>Affirmed</td></tr><tr><td>joining</td><td>Ravi</td><td>Orion</td><td>Not stated</td><td>Negated</td></tr></tbody></table></div><div class=\"step\"><h4>Step 6. Interpret current status cautiously</h4><p>The text says that Ravi left Vega and did not join Orion. It supplies no other current employer. Do not fill that field by guessing.</p></div><div class=\"answer\"><strong>Answer.</strong> Three qualified event statements, including a negated Orion joining. No current employer can be established from this text.</div></section><h3>Approaches and their trade-offs</h3><table><thead><tr><th>Approach</th><th>Mechanism</th><th>Advantage</th><th>Limitation</th></tr></thead><tbody><tr><td>Dictionary/rule based</td><td>Match known names, trigger words and patterns such as person joined organisation.</td><td>Transparent and useful in a narrow domain.</td><td>New names, paraphrases and complex syntax can escape patterns.</td></tr><tr><td>Supervised statistical</td><td>Learn entity/relation/event labels from annotated examples and features.</td><td>Combines several cues consistently.</td><td>Requires representative labels and careful feature design.</td></tr><tr><td>Neural/contextual</td><td>Use contextual representations to classify spans and links or generate a structured record.</td><td>Can capture paraphrases and broader context.</td><td>May still invent or misassign fields; schema and factual checks remain necessary.</td></tr></tbody></table><p>Applications include extracting company events from news, conditions/treatments from clinical text, skills from resumes and attributes from product descriptions. Extraction quality is measured against annotated records: an entity match can require the correct span and type; a relation match additionally requires the correct participants and direction. Precision measures how many extracted records are correct; recall measures how many gold records were found.</p><p>For a 10-mark answer, begin with the definition and structured output, distinguish NER/relation/event extraction, draw and explain the pipeline, work through a record with roles and qualifiers, compare approaches, then state evaluation and limitations. “Extract keywords” alone is too narrow: keywords do not necessarily represent a factual relation.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER naam pakadta hai; relation kaun-kisse jodta hai; event kya hua batata hai. Negation aur date mat girao.</p>"},{"id":"retrieval","title":"Information retrieval","html":"<p><strong>Information retrieval (IR)</strong> locates and ranks items relevant to an information need, usually expressed as a query. The collection may contain documents, product descriptions or scientific papers. Retrieval estimates relevance; it does not itself establish that every retrieved claim is true.</p><div class=\"flow\"><div class=\"node\">Documents → cleaning</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Build index</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Query → same representation</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match & rank</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Return relevant results</div></div><h3>The inverted index</h3><p>An inverted index maps a term to the documents containing it, often with positions or counts. For D1 “cats drink milk” and D2 “dogs drink water”, the posting list for drink is {D1,D2}, while milk maps only to D1. This avoids rescanning every document for every query.</p><table><thead><tr><th>Term</th><th>Posting list</th></tr></thead><tbody><tr><td>cats</td><td>D1</td></tr><tr><td>drink</td><td>D1, D2</td></tr><tr><td>milk</td><td>D1</td></tr><tr><td>dogs</td><td>D2</td></tr><tr><td>water</td><td>D2</td></tr></tbody></table><h3>Matching and ranking</h3><p>Boolean retrieval combines term membership using AND, OR and NOT. Vector-space retrieval represents documents and queries as weighted vectors, for example with TF-IDF, and compares them with cosine similarity. Learned retrieval can use dense embeddings for meaning-based matching. The representation used at query time must be compatible with the document index.</p><h3>Search engines and recommendation</h3><p>A search engine receives an explicit query and ranks matching indexed pages. A recommender may derive an implicit query from a user’s liked items or profile and retrieve similar candidates. Both require candidate retrieval and ranking, but the source of the information need differs.</p><h3>Evaluate the results</h3><p>For retrieval, TP is the number of retrieved relevant documents, FP retrieved irrelevant documents, and FN relevant documents not retrieved. Precision and recall use the same formulas as classification. Ranking measures also consider the positions of relevant items; a relevant result at rank 1 is more useful than one far below.</p><section class=\"example\"><h3>Retrieval evaluation</h3><p class=\"question\">A search system retrieves 8 documents; 6 are relevant. There are 10 relevant documents in the collection. Find precision, recall and F1.</p><div class=\"given\"><strong>Given</strong><p>Retrieved=8; relevant retrieved=6; all relevant=10.</p><strong>To find</strong><p>P, R and F1.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/58a11f3930a42815.svg\" alt=\"P=\\frac{\\text{relevant retrieved}}{\\text{retrieved}},\\quad R=\\frac{\\text{relevant retrieved}}{\\text{all relevant}}\" style=\"width:49.316ex;height:4.676ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4743421649dff6a6.svg\" alt=\"F_1=\\frac{2PR}{P+R}\" style=\"width:12.637ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>The denominator is 8 for precision and 10 for recall because they ask different questions.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the confusion counts</h4><p>TP=6; FP=8−6=2; FN=10−6=4.</p></div><div class=\"step\"><h4>Step 2. Precision</h4><div class=\"math-display\"><img src=\"math/6a30a7f6694209de.svg\" alt=\"P=\\frac68=0.75\" style=\"width:13.883ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Recall</h4><div class=\"math-display\"><img src=\"math/402ac41b5040dfdd.svg\" alt=\"R=\\frac6{10}=0.6\" style=\"width:13.901ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. F1</h4><div class=\"math-display\"><img src=\"math/aedd722bd9955777.svg\" alt=\"F_1=\\frac{2(0.75)(0.6)}{0.75+0.6}=\\frac{0.9}{1.35}=\\frac23\\approx0.666667\" style=\"width:42.764ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision=0.75, recall=0.60, F1≈0.666667.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Precision: jo laaye, unmein kitne sahi? Recall: jo sahi the, unmein kitne laaye?</p>"}],"scope":"TEE only · Unit 7 · current syllabus, including spelling correction; faculty slide pack not supplied"}],"formulas":[{"id":"formula-index","title":"Core formulas","unit":0,"sections":[{"id":"all","title":"Core formula sheet","html":"<p>Read each formula with its meaning. The remaining lessons in this tab contain the complete worked examples for these methods. Use the same vocabulary, boundary, case and token-count conventions throughout one solution.</p><h3>N-gram count</h3><div class=\"math-display\"><img src=\"math/c6f5691757b3dce9.svg\" alt=\"\\max(T-n+1,0)\" style=\"width:17.721ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Unpadded sequence of T tokens. Count only valid contiguous windows.</p><h3>Unigram MLE</h3><div class=\"math-display\"><img src=\"math/6ce6bece84751874.svg\" alt=\"P(w)=C(w)/N\" style=\"width:16.336ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>N is the training-token total under the stated boundary convention.</p><h3>Bigram MLE</h3><div class=\"math-display\"><img src=\"math/7a356598298a4b8a.svg\" alt=\"P(w_i\\mid w_{i-1})=C(w_{i-1},w_i)/C(w_{i-1})\" style=\"width:35.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Denominator = history count.</p><h3>Trigram MLE</h3><div class=\"math-display\"><img src=\"math/d95e106d3b255b6a.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=C(w_{i-2},w_{i-1},w_i)/C(w_{i-2},w_{i-1})\" style=\"width:51.621ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Denominator = two-word history count.</p><h3>Add-one / Laplace</h3><div class=\"math-display\"><img src=\"math/f6db957bd553fd41.svg\" alt=\"P(w\\mid h)=\\frac{C(hw)+1}{C(h)+|V|}\" style=\"width:22.827ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><p>Add one to every possible vocabulary continuation.</p><h3>Sentence probability</h3><div class=\"math-display\"><img src=\"math/1bb8f8f2c685b8c8.svg\" alt=\"P(W)\\approx\\prod_iP(w_i\\mid w_{i-1})\" style=\"width:24.225ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply in order; include an end factor if specified.</p><h3>Perplexity</h3><div class=\"math-display\"><img src=\"math/be3b71a436d652a8.svg\" alt=\"PP=P(W)^{-1/N}\" style=\"width:16.698ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div><p>N is the number of predicted tokens/events used by the question.</p><h3>Emission</h3><div class=\"math-display\"><img src=\"math/597b97fa150cfb9b.svg\" alt=\"P(w\\mid t)=C(w,t)/C(t)\" style=\"width:23.149ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Word given tag; count tokens with that tag.</p><h3>Transition</h3><div class=\"math-display\"><img src=\"math/a89cf52a2261bb02.svg\" alt=\"P(t_j\\mid t_i)=C(t_i\\to t_j)/\\sum_k C(t_i\\to t_k)\" style=\"width:37.347ex;height:4.899ex\" loading=\"lazy\" decoding=\"async\"></div><p>Next tag given previous tag; count outgoing transitions.</p><h3>HMM joint path</h3><div class=\"math-display\"><img src=\"math/aed9bbaaf2578ce2.svg\" alt=\"P(W,T)=\\pi_{t_1}b_{t_1}(w_1)\\prod_{i=2}^{n}a_{t_{i-1},t_i}b_{t_i}(w_i)\" style=\"width:36.502ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply initial, emission and transition factors; add end probability if used.</p><h3>Tag sequences</h3><div class=\"math-display\"><img src=\"math/ed1eadf4591c422c.svg\" alt=\"K^T\" style=\"width:3.443ex;height:2.017ex\" loading=\"lazy\" decoding=\"async\"></div><p>K tags, T word positions; count before constraints.</p><h3>Viterbi</h3><div class=\"math-display\"><img src=\"math/bb085669dbdb35d4.svg\" alt=\"\\delta_i(t)=b_t(w_i)\\max_s[\\delta_{i-1}(s)a_{s,t}]\" style=\"width:28.807ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p>Choose the largest predecessor score; store a backpointer.</p><h3>Lesk</h3><div class=\"math-display\"><img src=\"math/28ab6543e5b805ca.svg\" alt=\"score(s)=|context\\cap gloss(s)|\" style=\"width:30.034ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use the specified normalisation and overlap convention.</p><h3>Naive Bayes class prior</h3><div class=\"math-display\"><img src=\"math/b91d8ff6433f1da4.svg\" alt=\"P(c)=D_c/D\" style=\"width:13.214ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>D counts labelled examples; this is not the word-token total.</p><h3>Smoothed NB likelihood</h3><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>N_c counts training tokens in class c.</p><h3>NB decision</h3><div class=\"math-display\"><img src=\"math/d28d2ec54104fe0c.svg\" alt=\"\\hat c=\\arg\\max_c P(c)\\prod_iP(w_i\\mid c)\" style=\"width:28.879ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Select label with largest score; normalise only for posterior values.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Condition jis par hai, denominator usi ka; sequence mein multiply; options mein maximum.</p>"}],"scope":"M2 · formulas with meaning · full examples follow"},{"id":"f-counts","title":"N-grams & probability","unit":0,"sections":[{"id":"n-grams-construction","title":"Unigrams, bigrams and trigrams: construct them correctly","html":"<p><strong>Definition.</strong> An n-gram is a contiguous sequence of n items. For word n-grams, the items are consecutive word tokens. A unigram contains one word; a bigram contains two; a trigram contains three. Character n-grams use characters instead, so always identify the unit being counted.</p><div class=\"flow\"><div class=\"node\">Tokens: we | study | natural | language</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Move a window one token at a time</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Bigrams: we study / study natural / natural language</div></div><p>For m tokens without padding, the number of n-gram <em>positions</em> is max(0, m−n+1). Repeated positions may contain the same n-gram type. A bag-of-n-grams representation counts each n-gram type and loses the overall sentence order beyond the local order inside each n-gram.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9097807b6ad98d38.svg\" alt=\"\\text{Number of unpadded n-gram positions}=\\max(0,m-n+1)\" style=\"width:58.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. List all word unigrams, bigrams and trigrams for “the prime minister of our country”. Do not add boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Six tokens: the, prime, minister, of, our, country. n = 1, 2 and 3.</p><h4>To find</h4><p>All three lists and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad44404e3f41cdd.svg\" alt=\"\\#\\text{positions}=m-n+1\" style=\"width:23.607ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each window must contain consecutive words and move one position. No wraparound or invented final word is allowed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take one word at a time</h5><p>Unigrams: (the), (prime), (minister), (of), (our), (country). Count = 6−1+1 = 6.</p></div><div class=\"step\"><h5>Step 2. Take two consecutive words</h5><p>Bigrams: (the, prime), (prime, minister), (minister, of), (of, our), (our, country). Count = 6−2+1 = 5.</p></div><div class=\"step\"><h5>Step 3. Take three consecutive words</h5><p>Trigrams: (the, prime, minister), (prime, minister, of), (minister, of, our), (of, our, country). Count = 6−3+1 = 4.</p></div><div class=\"answer\"><strong>Final answer.</strong> 6 unigrams, 5 bigrams and 4 trigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct bigrams for “I like tea” using one start and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original tokens: I, like, tea. Add &lt;s&gt; and &lt;/s&gt; once each.</p><h4>To find</h4><p>The boundary-aware bigram sequence.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1b167f71a6a973b4.svg\" alt=\"\\#\\text{bigrams}=(m+2)-1=m+1\" style=\"width:33.155ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The start context predicts the first word, and the last word predicts that the sentence ends.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write the padded sequence</h5><p>&lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Move a two-token window</h5><p>(&lt;s&gt;, I), (I, like), (like, tea), (tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count the windows</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c37463b701447787.svg\" alt=\"3+1=4\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> There are four boundary-aware bigrams.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Construct trigrams for “I like tea” using two start markers and one end marker.</strong></p><div class=\"given\"><h4>Given</h4><p>Original sentence has three words. For a trigram model each predicted token needs two prior context tokens.</p><h4>To find</h4><p>All trigram prediction events.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/12c99aed7b535ad6.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:17.519ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Two start markers provide a complete context even for the first word.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Pad with two starts</h5><p>&lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;</p></div><div class=\"step\"><h5>Step 2. Slide a three-token window</h5><p>(&lt;s&gt;, &lt;s&gt;, I), (&lt;s&gt;, I, like), (I, like, tea), (like, tea, &lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 3. Count predicted events</h5><p>The model predicts I, like, tea and the end marker: four predictions.</p></div><div class=\"answer\"><strong>Final answer.</strong> Four trigrams. Start markers are context; they are not ordinary predicted words.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Give the bag-of-bigrams counts for “a b a b” without padding.</strong></p><div class=\"given\"><h4>Given</h4><p>Four tokens in their given order.</p><h4>To find</h4><p>Bigram positions, distinct bigram types and their counts.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8326144ada817e2c.svg\" alt=\"\\#\\text{positions}=4-2+1=3\" style=\"width:26.674ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A bag stores frequencies; repeated bigrams must not be discarded.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Enumerate all positions</h5><p>(a,b), (b,a), (a,b).</p></div><div class=\"step\"><h5>Step 2. Group identical pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Bigram type</th><th>Count</th></tr></thead><tbody><tr><td>a b</td><td>2</td></tr><tr><td>b a</td><td>1</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> Three bigram positions but two distinct bigram types.</div><p class=\"cue\"><strong>Yaad rakho:</strong> n-gram mein n words; context mein n−1 words.</p></section>"},{"id":"unigram-estimation","title":"Unigram estimation and complete worked examples","html":"<p><strong>Maximum likelihood estimation (MLE)</strong> chooses probabilities equal to observed relative frequencies. In a unigram model, every word is predicted independently of its surrounding words. If a word occurs c times in N training tokens, its estimate is c/N. To score m specified words, multiply their m unigram probabilities.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/151df11dd9b4e4ca.svg\" alt=\"P_{\\mathrm{MLE}}(w)=\\frac{C(w)}{N}\\qquad P(w_1,\\ldots,w_m)\\approx\\prod_{i=1}^{m}P(w_i)\" style=\"width:48.638ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Choose a tokenization convention before counting. Lowercasing, punctuation handling and boundary markers can change the vocabulary and counts. Never count words with one convention and form the denominator with another. A unigram model gives the same product to rearrangements of the same word multiset; that is one of its limitations.</p><section class=\"example\"><p class=\"question\"><strong>Question. Train an unpadded, case-insensitive unigram model on “I like tea” and “I like coffee”. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Training sentences: I like tea; I like coffee. Use lowercase words; exclude punctuation and sentence boundaries.</p><h4>To find</h4><p>The vocabulary, word probabilities and test-sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92c670591895f879.svg\" alt=\"P(w)=C(w)/N,\\qquad P(I\\ like\\ tea)=P(I)P(like)P(tea)\" style=\"width:55.644ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The unigram approximation ignores order and uses total token count for every denominator.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count every training token</h5><p>Each sentence contains three words, so N = 3+3 = 6.</p></div><div class=\"step\"><h5>Step 2. Count types and frequencies</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th><th>MLE probability</th></tr></thead><tbody><tr><td>i</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>like</td><td>2</td><td>2/6 = 1/3</td></tr><tr><td>tea</td><td>1</td><td>1/6</td></tr><tr><td>coffee</td><td>1</td><td>1/6</td></tr></tbody></table></div><p>Vocabulary size V = 4.</p></div><div class=\"step\"><h5>Step 3. Write one factor per test word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8823227ec8a6a1a.svg\" alt=\"P=\\frac{2}{6}\\times\\frac{2}{6}\\times\\frac{1}{6}\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply the fractions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3a5496aef6f0526.svg\" alt=\"P=\\frac{4}{216}=\\frac{1}{54}\\approx0.018519\" style=\"width:26.945ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The unigram sentence probability is approximately 0.018519.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains counts a: 4, b: 3 and c: 1. Find the unigram probability of “a b a”.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=4, C(b)=3, C(c)=1. No boundary markers.</p><h4>To find</h4><p>P(a b a).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/97d27988b1cff86a.svg\" alt=\"P(a\\,b\\,a)=P(a)P(b)P(a)\" style=\"width:24.338ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A repeated test word contributes a probability factor at every occurrence; do not include it just once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/489d9ca17e456579.svg\" alt=\"N=4+3+1=8\" style=\"width:18.1ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the required probabilities</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c986ed6d03f3c421.svg\" alt=\"P(a)=4/8=1/2,\\qquad P(b)=3/8\" style=\"width:33.849ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Use both occurrences of a</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a46bf6ca459b44e0.svg\" alt=\"P=\\frac12\\times\\frac38\\times\\frac12\" style=\"width:16.628ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Simplify</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c91fa325852e9b20.svg\" alt=\"P=\\frac3{32}=0.09375\" style=\"width:18.407ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(a b a) = 0.09375.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Repeated word ka probability bhi repeat multiply hoga.</p></section><section class=\"example\"><p class=\"question\"><strong>Question. An unsmoothed unigram model is trained on “red blue red”. Find the probability of “red green”.</strong></p><div class=\"given\"><h4>Given</h4><p>N=3. Counts: red=2, blue=1, green=0. The test contains red and green.</p><h4>To find</h4><p>The unsmoothed test probability and the reason for its value.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ad862e46bb0787a.svg\" alt=\"P(red\\ green)=P(red)P(green)\" style=\"width:31.594ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>MLE assigns zero to an unseen outcome. Smoothing is needed if an unseen in-vocabulary item must receive probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Estimate red</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4e4dbe2f8003f7d7.svg\" alt=\"P(red)=2/3\" style=\"width:13.121ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Estimate the unseen word</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5ae67848fc965273.svg\" alt=\"P(green)=0/3=0\" style=\"width:19.584ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c86e2ed24bee6fb.svg\" alt=\"(2/3)\\times0=0\" style=\"width:13.199ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed probability = 0. This reflects missing training evidence, not proof that the phrase is impossible.</div></section>"},{"id":"bigram-count-table","title":"Bigram counts: build the table before multiplying","html":"<p>A <strong>bigram probability table</strong> uses the previous word as its row and the next word as its column. Divide each cell count by its row's total outgoing count. With one end marker on every sentence, each ordinary training word has a continuation, so its outgoing count equals its token frequency. Do not create a bigram that crosses from one sentence into the next.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/16ee67bf50a203c3.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{\\sum_{v\\in V}C(h,v)}=\\frac{C(h,w)}{C(h)}\" style=\"width:36.615ex;height:5.619ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"flow\"><div class=\"node\">Add boundaries to each sentence separately</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">List adjacent pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Count repeated pairs</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Divide each row by its total</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Follow the test sentence through the table</div></div><section class=\"example\"><p class=\"question\"><strong>Question. Train a bigram model on “I like tea”, “I like coffee” and “you like tea”. Use one start and one end marker. Find the probability of “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: &lt;s&gt; I like tea &lt;/s&gt;; &lt;s&gt; I like coffee &lt;/s&gt;; &lt;s&gt; you like tea &lt;/s&gt;. Preserve these tokens.</p><h4>To find</h4><p>All nonzero bigram estimates and the test probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every sentence starts and ends independently. Four probability factors are required for the three test words plus end.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. List the training pairs</h5><p>Sentence 1: (&lt;s&gt;,I), (I,like), (like,tea), (tea,&lt;/s&gt;).<br>Sentence 2: (&lt;s&gt;,I), (I,like), (like,coffee), (coffee,&lt;/s&gt;).<br>Sentence 3: (&lt;s&gt;,you), (you,like), (like,tea), (tea,&lt;/s&gt;).</p></div><div class=\"step\"><h5>Step 2. Create the nonzero count table</h5><div class=\"table-wrap\"><table><thead><tr><th>History → next</th><th>Pair count</th><th>History count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → I</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>&lt;s&gt; → you</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>I → like</td><td>2</td><td>2</td><td>1</td></tr><tr><td>you → like</td><td>1</td><td>1</td><td>1</td></tr><tr><td>like → tea</td><td>2</td><td>3</td><td>2/3</td></tr><tr><td>like → coffee</td><td>1</td><td>3</td><td>1/3</td></tr><tr><td>tea → &lt;/s&gt;</td><td>2</td><td>2</td><td>1</td></tr><tr><td>coffee → &lt;/s&gt;</td><td>1</td><td>1</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the test path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7363c7dc5cab171f.svg\" alt=\"P=P(I\\mid\\langle s\\rangle)P(like\\mid I)P(tea\\mid like)P(\\langle/s\\rangle\\mid tea)\" style=\"width:48.662ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Substitute each matching row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2c319bafd1386357.svg\" alt=\"P=\\frac23\\times1\\times\\frac23\\times1\" style=\"width:19.529ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d5107e2738f0177f.svg\" alt=\"P=\\frac49\\approx0.444444\" style=\"width:18.407ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(I like tea) = 4/9 ≈ 0.444444.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using the same three-sentence corpus given here—“I like tea”, “I like coffee”, “you like tea”—find the bigram probabilities of “you like coffee” and “tea like I”. Include boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus with one start/end marker per sentence. Counts: start→you=1/3; you→like=1; like→coffee=1/3; coffee→end=1. No training sentence starts with tea.</p><h4>To find</h4><p>The two test probabilities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/92e554afbd43b835.svg\" alt=\"P(\\text{sentence})=\\prod P(\\text{next token}\\mid\\text{previous token})\" style=\"width:48.054ex;height:3.167ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A model can assign a nonzero probability to a sentence it never saw if all of its local bigrams were seen.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score you like coffee</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bccffa0a6f23966a.svg\" alt=\"P=\\frac13\\times1\\times\\frac13\\times1=\\frac19\\approx0.111111\" style=\"width:36.238ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Inspect tea like I</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c17c8267050aec19.svg\" alt=\"P(tea\\mid\\langle s\\rangle)=0/3=0\" style=\"width:21.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply the zero factor</h5><p>The full product is zero, regardless of the remaining factors.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(you like coffee) = 1/9; P(tea like I) = 0. A new sentence is not necessarily a zero-probability sentence.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Obtain the unsmoothed bigram probability of “students are from Vellore” from this corpus: “I am from Vellore”; “I am a teacher”; “students are good and are from various cities”; “students from Vellore do engineering”. Use sentence boundaries.</strong></p><div class=\"given\"><h4>Given</h4><p>Four training sentences, each padded with one &lt;s&gt; and &lt;/s&gt;. Test sequence: &lt;s&gt; students are from Vellore &lt;/s&gt;.</p><h4>To find</h4><p>The five required conditional probabilities and their product.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8150207b365ec07a.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h)\" style=\"width:24.608ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Count all occurrences in the entire corpus. In particular, are occurs twice inside the third sentence, and Vellore is followed by end once and do once.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the histories</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Occurrences with continuation</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>4</td></tr><tr><td>students</td><td>2</td></tr><tr><td>are</td><td>2</td></tr><tr><td>from</td><td>3</td></tr><tr><td>Vellore</td><td>2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count the required pairs</h5><div class=\"table-wrap\"><table><thead><tr><th>Required pair</th><th>Count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;s&gt; students</td><td>2</td><td>2/4</td></tr><tr><td>students are</td><td>1</td><td>1/2</td></tr><tr><td>are from</td><td>1</td><td>1/2</td></tr><tr><td>from Vellore</td><td>2</td><td>2/3</td></tr><tr><td>Vellore &lt;/s&gt;</td><td>1</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Write the complete product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6420e3d4b5982a43.svg\" alt=\"P=\\frac24\\times\\frac12\\times\\frac12\\times\\frac23\\times\\frac12\" style=\"width:26.413ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Multiply progressively</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6c021a4ae77c326e.svg\" alt=\"\\frac24\\times\\frac12=\\frac14,\\quad \\frac14\\times\\frac12=\\frac18\" style=\"width:27.594ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e9b12d6d627642db.svg\" alt=\"\\frac18\\times\\frac23=\\frac1{12},\\quad \\frac1{12}\\times\\frac12=\\frac1{24}\" style=\"width:30.988ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 1/24 ≈ 0.0416667.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Same sentence mein word do baar aaye toh count bhi do.</p></section>"},{"id":"trigram-estimation","title":"Trigram estimates: two-word history, not two denominators","html":"<p>A trigram model predicts the next word from the two preceding words. The numerator is the count of a triple. The denominator is the count of its two-word history with an available next token. Do not multiply two independent bigram probabilities and call that a trigram probability.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ca97d5e894e09b1.svg\" alt=\"P(w_i\\mid w_{i-2},w_{i-1})=\\frac{C(w_{i-2},w_{i-1},w_i)}{C(w_{i-2},w_{i-1})}\" style=\"width:38.191ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A corpus contains 12 occurrences of “prime minister”. Eight are followed by “of”, three by “said”, and one by “visited”. Estimate the three trigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>History h = (prime, minister). Count of this history = 12. Triple counts for of, said, visited are 8, 3, 1.</p><h4>To find</h4><p>The conditional distribution of the next word.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8ba899fcd0d6112.svg\" alt=\"P(w\\mid prime,minister)=C(prime,minister,w)/12\" style=\"width:51.168ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All three candidates share one two-word history, so they share denominator 12.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate of</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69d53078e2ba6e25.svg\" alt=\"P(of\\mid prime,minister)=8/12=2/3\" style=\"width:37.483ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate said</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a742b6dcdf3bfef5.svg\" alt=\"P(said\\mid prime,minister)=3/12=1/4\" style=\"width:39.356ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate visited</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/170c0f0886c42082.svg\" alt=\"P(visited\\mid prime,minister)=1/12\" style=\"width:35.497ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Confirm normalization</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8a19e47f93490280.svg\" alt=\"8/12+3/12+1/12=12/12=1\" style=\"width:31.928ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The probabilities are 2/3, 1/4 and 1/12.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Train a trigram model on “I like tea”, “I like coffee” and “you like tea”. Use two start markers and one end marker. Score “I like tea”.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences. Padded first sentence is &lt;s&gt; &lt;s&gt; I like tea &lt;/s&gt;; pad the other two in the same way.</p><h4>To find</h4><p>Four trigram prediction probabilities and the sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0b4f2f8e9cf3fc17.svg\" alt=\"P=\\prod_i P(w_i\\mid w_{i-2},w_{i-1})\" style=\"width:25.504ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each prediction uses a two-token context; the two start markers supply the first history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the first-word event</h5><p>The history (&lt;s&gt;,&lt;s&gt;) occurs three times, and two are followed by I.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/88a613de059c9165.svg\" alt=\"P(I\\mid\\langle s\\rangle,\\langle s\\rangle)=2/3\" style=\"width:19.545ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Count the second-word event</h5><p>(&lt;s&gt;,I) occurs twice; both are followed by like.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99919b0a3770ff5c.svg\" alt=\"P(like\\mid\\langle s\\rangle,I)=2/2=1\" style=\"width:24.56ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count the third-word event</h5><p>(I,like) occurs twice; one is followed by tea.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/22c4756e3a5a9146.svg\" alt=\"P(tea\\mid I,like)=1/2\" style=\"width:20.658ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Count the end event</h5><p>(like,tea) occurs twice; both are followed by end.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/221a8d0201199a49.svg\" alt=\"P(\\langle/s\\rangle\\mid like,tea)=2/2=1\" style=\"width:27.618ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Multiply all four</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15f0c8914a694355.svg\" alt=\"P=\\frac23\\times1\\times\\frac12\\times1=\\frac13\" style=\"width:24.673ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Trigram P(I like tea) = 1/3. It differs from the bigram estimate because the context and denominator changed.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A trigram model supplies P(we|&lt;s&gt;,&lt;s&gt;)=0.4, P(study|&lt;s&gt;,we)=0.5, P(NLP|we,study)=0.8 and P(&lt;/s&gt;|study,NLP)=0.25. Score “we study NLP”.</strong></p><div class=\"given\"><h4>Given</h4><p>Four trigram conditional factors. The end marker is included.</p><h4>To find</h4><p>The complete sentence probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f7ce4e6b173900c6.svg\" alt=\"P=P(we\\mid s,s)P(study\\mid s,we)P(NLP\\mid we,study)P(end\\mid study,NLP)\" style=\"width:71.784ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use each supplied two-word history exactly; do not swap its word order.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Insert the values</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7e1f0a0c2ffc974b.svg\" alt=\"P=0.4\\times0.5\\times0.8\\times0.25\" style=\"width:25.71ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply the first pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4528e6e7a97bb8e8.svg\" alt=\"0.4\\times0.5=0.2\" style=\"width:14.457ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Include NLP</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd4748e690ad03d9.svg\" alt=\"0.2\\times0.8=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Include the end</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5bbc9c588899b389.svg\" alt=\"0.16\\times0.25=0.04\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P = 0.04.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Trigram: teen-word count upar, pehle do-word count neeche.</p></section><p><strong>Why larger n is not automatically better.</strong> More context can capture local order more precisely, but each longer history occurs less often. Parameter count, storage and sparsity grow. A model trained on Shakespeare may assign poor probabilities to financial news because training and test distributions differ. Keep a held-out test set; do not evaluate only on memorized training sentences.</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-smoothing","title":"Smoothing & perplexity","unit":0,"sections":[{"id":"laplace-basics","title":"Laplace smoothing: why both numerator and denominator change","html":"<p><strong>Smoothing</strong> reallocates some probability mass to events that received zero or unreliable estimates from finite training data. <strong>Laplace, or add-one, smoothing</strong> adds one pseudo-count to every possible next outcome. If there are V possible outcomes, the total added count is V, so adding 1 only to the numerator would produce probabilities that do not sum to 1.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0d44559007b7dea6.svg\" alt=\"P_{\\mathrm{Laplace}}(w)=\\frac{C(w)+1}{N+V}\" style=\"width:23.384ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e38a73cc66cdd3f1.svg\" alt=\"P_{\\mathrm{Laplace}}(w\\mid h)=\\frac{C(h,w)+1}{C(h)+V}\" style=\"width:28.882ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For unigram smoothing, N is the total training token count. For bigram smoothing, C(h) is the count of the particular history. In both cases V is the number of outcomes being predicted, not the number of training sentences and not the number of distinct bigrams. When end is a possible prediction, include it in V; the start marker is usually context only.</p><div class=\"flow\"><div class=\"node\">Observed counts: 3, 1, 0</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Add one to every outcome: 4, 2, 1</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New total: 7</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Smoothed probabilities: 4/7, 2/7, 1/7</div></div><section class=\"example\"><p class=\"question\"><strong>Question. A fixed unigram vocabulary is {a,b,c}. The training counts are 3,1,0. Compute unsmoothed and Laplace-smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(a)=3, C(b)=1, C(c)=0; N=4; V=3.</p><h4>To find</h4><p>The complete distributions.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/80d7161647b260e8.svg\" alt=\"P(w)=C(w)/N,\\qquad P_L(w)=(C(w)+1)/(N+V)\" style=\"width:51.157ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The zero-count c is still in the fixed vocabulary, so it must receive one pseudo-count and contribute to V.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute unsmoothed values</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Unsmoothed</th></tr></thead><tbody><tr><td>a</td><td>3/4 = 0.75</td></tr><tr><td>b</td><td>1/4 = 0.25</td></tr><tr><td>c</td><td>0/4 = 0</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Calculate the new denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1918c0a9ceaec186.svg\" alt=\"N+V=4+3=7\" style=\"width:18.708ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add one to each numerator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/345a4b4f00828435.svg\" alt=\"C(a)+1=4,\\quad C(b)+1=2,\\quad C(c)+1=1\" style=\"width:44.259ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Divide</h5><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Smoothed</th></tr></thead><tbody><tr><td>a</td><td>4/7 ≈ 0.571429</td></tr><tr><td>b</td><td>2/7 ≈ 0.285714</td></tr><tr><td>c</td><td>1/7 ≈ 0.142857</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Confirm the total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/172a91eacd7bcf59.svg\" alt=\"4/7+2/7+1/7=1\" style=\"width:19.861ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Smoothed probabilities: a=4/7, b=2/7, c=1/7. Common a loses mass; unseen c gains mass.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. After history I, a corpus records like three times, study once and sleep zero times. The allowed next vocabulary is {like,study,sleep}. Compute all Laplace-smoothed bigram probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>C(I,like)=3; C(I,study)=1; C(I,sleep)=0. History count C(I)=4. V=3.</p><h4>To find</h4><p>P_L(like|I), P_L(study|I), P_L(sleep|I).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a1c0980897f9361.svg\" alt=\"P_L(w\\mid I)=\\frac{C(I,w)+1}{C(I)+V}\" style=\"width:24.291ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>This is smoothing within the I row; use its total 4, not the global corpus token count.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the common denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d3c1688373da86b2.svg\" alt=\"C(I)+V=4+3=7\" style=\"width:21.319ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate like</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/848e1d743f230579.svg\" alt=\"P_L(like\\mid I)=(3+1)/7=4/7\" style=\"width:29.682ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate study</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ed5edd3a14936914.svg\" alt=\"P_L(study\\mid I)=(1+1)/7=2/7\" style=\"width:31.452ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate sleep</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e0b14bd8e108207.svg\" alt=\"P_L(sleep\\mid I)=(0+1)/7=1/7\" style=\"width:30.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The row is (4/7, 2/7, 1/7). An unseen bigram is no longer forced to zero.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A fixed vocabulary has five possible next tokens. A history h is unseen in training. What is its add-one probability for each next token?</strong></p><div class=\"given\"><h4>Given</h4><p>C(h)=0; C(h,w)=0 for each outcome; V=5.</p><h4>To find</h4><p>P_L(w|h) for each token.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1e1f42d7a9537f57.svg\" alt=\"P_L(w\\mid h)=\\frac{0+1}{0+V}\" style=\"width:18.948ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All outcomes receive equal pseudo-counts because the training data gives no preference for this history.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Add the pseudo-count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dd66590db88ae5fa.svg\" alt=\"0+1=1\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Form the denominator</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/190ddc58c7516f91.svg\" alt=\"0+5=5\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Divide and sum</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/39038359834be22e.svg\" alt=\"P_L(w\\mid h)=1/5=0.2,\\qquad5(0.2)=1\" style=\"width:37.08ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Every outcome gets 0.2 under this fixed-vocabulary model.</div></section><p><strong>Vocabulary warning.</strong> Add-one does not automatically define probabilities for every word in the world. Unknown words require a declared vocabulary/UNK convention. If a question supplies V, use that stated V rather than inventing additional tokens.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Add-one: upar +1, neeche +V; bigram mein neeche history ka count.</p>"},{"id":"smoothed-sentence","title":"A complete unseen-bigram question from corpus to final answer","html":"<section class=\"example\"><p class=\"question\"><strong>Question. Consider the corpus “I love to code in Python. I love to learn new things. I code every day.” Obtain the bigram probabilities needed for “I love Python”. Explain the zero-probability issue, then use Laplace smoothing to score it. Treat each sentence separately, preserve case, remove punctuation, and include an end token among predicted outcomes.</strong></p><div class=\"given\"><h4>Given</h4><p>Three sentences padded with one start/end marker. Distinct words: I, love, to, code, in, Python, learn, new, things, every, day. With &lt;/s&gt;, V=12. Start is context only.</p><h4>To find</h4><p>Unsmoothed and smoothed P(I love Python &lt;/s&gt; | &lt;s&gt;).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a627bcb8a0b3808.svg\" alt=\"P(w\\mid h)=\\frac{C(h,w)}{C(h)},\\qquad P_L(w\\mid h)=\\frac{C(h,w)+1}{C(h)+12}\" style=\"width:49.838ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The test contains an unseen transition love→Python. Smoothing assigns probability to that transition and renormalizes every required history row.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the contexts</h5><div class=\"table-wrap\"><table><thead><tr><th>History</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt;</td><td>3</td></tr><tr><td>I</td><td>3</td></tr><tr><td>love</td><td>2</td></tr><tr><td>Python</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Count each required pair</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt; I</td><td>3</td></tr><tr><td>I love</td><td>2</td></tr><tr><td>love Python</td><td>0</td></tr><tr><td>Python &lt;/s&gt;</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 3. Compute the unsmoothed product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/420a50ccd335ade1.svg\" alt=\"P=\\frac33\\times\\frac23\\times\\frac02\\times\\frac11=0\" style=\"width:25.668ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both words love and Python were seen, but their adjacent pair was not. This is an unseen bigram, not an unknown-word case.</p></div><div class=\"step\"><h5>Step 4. Smooth the first event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f16fc85077f5670b.svg\" alt=\"P_L(I\\mid\\langle s\\rangle)=\\frac{3+1}{3+12}=\\frac4{15}\" style=\"width:26.784ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Smooth the second event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a94897ddface7219.svg\" alt=\"P_L(love\\mid I)=\\frac{2+1}{3+12}=\\frac3{15}\" style=\"width:27.886ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Smooth the unseen event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f023b28c09df9a1a.svg\" alt=\"P_L(Python\\mid love)=\\frac{0+1}{2+12}=\\frac1{14}\" style=\"width:34.128ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 7. Smooth the end event</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cfdc24dda127984e.svg\" alt=\"P_L(\\langle/s\\rangle\\mid Python)=\\frac{1+1}{1+12}=\\frac2{13}\" style=\"width:34.158ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 8. Multiply the smoothed factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8b4c9f0eec18e2b4.svg\" alt=\"P_L=\\frac4{15}\\times\\frac3{15}\\times\\frac1{14}\\times\\frac2{13}\" style=\"width:27.076ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be31ee9de701fcab.svg\" alt=\"P_L=\\frac{24}{40950}=\\frac4{6825}\\approx0.000586081\" style=\"width:35.894ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Unsmoothed P=0. With the stated V=12 and boundaries, Laplace-smoothed P≈0.000586081.</div></section><p>If an exam states a different convention—for example excluding boundary tokens from the entire calculation—recompute both V and the set of probability factors consistently. Do not combine a boundary-aware numerator with a boundary-free denominator.</p>"},{"id":"adjusted-count-discount","title":"Adjusted counts and relative discounting","html":"<p>The slides also express smoothing through an <strong>adjusted count</strong> c*. Instead of writing the smoothed probability with denominator N+V, they rescale its numerator so the denominator can remain N. Algebraically these are equivalent:</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/70d92382a6cc1e9c.svg\" alt=\"c^*=(c+1)\\frac{N}{N+V},\\qquad P_L(w)=\\frac{c^*}{N}\" style=\"width:36.794ex;height:4.832ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6597274c03aa7f00.svg\" alt=\"d=\\frac{c^*}{c}\\quad(c&gt;0)\" style=\"width:16.307ex;height:4.672ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The relative discount d compares adjusted and original counts. It is undefined when c=0 because division by zero is undefined. Add-one smoothing moves the distribution toward uniformity: frequent events are reduced, but some rare seen events may increase. It is not correct to claim that every nonzero count must decrease under Laplace smoothing.</p><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, a word has original count c=10. Find its adjusted count, smoothed probability and relative discount.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=10.</p><h4>To find</h4><p>c*, P_L and d.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/63cfdcd2de177903.svg\" alt=\"c^*=(c+1)N/(N+V),\\quad P_L=c^*/N,\\quad d=c^*/c\" style=\"width:48.699ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>These expressions rewrite add-one smoothing without changing its probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the new total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/749a0f4867a4b3db.svg\" alt=\"N+V=20+5=25\" style=\"width:20.971ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Find the adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/866c6ee174b3d21b.svg\" alt=\"c^*=(10+1)\\frac{20}{25}=11(0.8)=8.8\" style=\"width:32.002ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Find the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5fb26f5353edaa9.svg\" alt=\"P_L=8.8/20=0.44\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find the relative discount</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/be28007774d8c2d5.svg\" alt=\"d=8.8/10=0.88\" style=\"width:17.518ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=8.8, P_L=0.44, d=0.88. The original probability 0.5 is reduced.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Under N=20, V=5, a rare word occurs once. Compute its adjusted count and compare the original and smoothed probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>N=20; V=5; c=1.</p><h4>To find</h4><p>c*, original P and smoothed P_L.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/509478366d59c2ce.svg\" alt=\"c^*=(c+1)N/(N+V)\" style=\"width:23.036ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same smoothing rule may increase a rare event's probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Original probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3fc24a506f12b888.svg\" alt=\"P=1/20=0.05\" style=\"width:16.281ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/13803fe6f5045ef1.svg\" alt=\"c^*=(1+1)(20/25)=1.6\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0fd3e6bc0e9d2f40.svg\" alt=\"P_L=1.6/20=0.08\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> c*=1.6 and P_L=0.08, which exceeds the original 0.05.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For N=20 and V=5, an in-vocabulary word has count zero. Find its adjusted count and smoothed probability. Can a relative discount be calculated?</strong></p><div class=\"given\"><h4>Given</h4><p>c=0; N=20; V=5.</p><h4>To find</h4><p>c*, P_L and whether d exists.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dc6d3ca40a034b28.svg\" alt=\"c^*=(c+1)N/(N+V),\\qquad P_L=c^*/N\" style=\"width:39.422ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The pseudo-count creates positive mass for the unseen vocabulary item.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Adjusted count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e073545bb6c88eb4.svg\" alt=\"c^*=(0+1)(20/25)=0.8\" style=\"width:25.098ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Smoothed probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5e8f939253d4321b.svg\" alt=\"P_L=0.8/20=0.04\" style=\"width:19.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Relative discount</h5><p>d would be 0.8/0. That is undefined, so do not report a finite discount.</p></div><div class=\"answer\"><strong>Final answer.</strong> c*=0.8 and P_L=0.04; relative discount is undefined for c=0.</div></section>"},{"id":"evaluation-perplexity","title":"Perplexity: meaning, formula and four complete examples","html":"<p><strong>Intrinsic evaluation</strong> evaluates a model directly on a held-out test corpus, for example using perplexity. <strong>Extrinsic evaluation</strong> places it inside a downstream application, such as a speech recognizer or translation system, and measures the application's performance. Extrinsic testing is closer to actual use but often slower and more expensive. A lower perplexity is not a guarantee of improvement on every downstream task.</p><p><strong>Perplexity</strong> is the inverse probability of a test sequence, normalized by the number of prediction events. Intuitively, it is the model's effective average number of equally plausible choices. A model that always gives the correct next word probability 1/4 has perplexity 4. Lower is better when the models are tested on the same data, vocabulary, tokenization and boundary convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dab12face5c56858.svg\" alt=\"\\operatorname{PP}(W)=P(W)^{-1/N}=\\sqrt[N]{\\frac1{P(W)}}\" style=\"width:32.663ex;height:6.923ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>W</td><td>The complete test sequence.</td></tr><tr><td>P(W)</td><td>Product of the probabilities assigned to the actual next tokens.</td></tr><tr><td>N</td><td>Number of scored prediction events under the stated convention.</td></tr><tr><td>Exponent −1/N</td><td>Take the reciprocal, then the Nth root.</td></tr></tbody></table></div><p>For calculator entry, use parentheses: P raised to (−1 ÷ N), or (1 ÷ P) raised to (1 ÷ N). Retain several digits in intermediate products. The ordinary start marker is usually given context, not a predicted event; the end marker counts if its probability is included.</p><section class=\"example\"><p class=\"question\"><strong>Question. A model assigns probability 0.0625 to a test sequence containing four scored tokens. Compute its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>P(W)=0.0625=1/16; N=4.</p><h4>To find</h4><p>PP(W).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7873b84adddec337.svg\" alt=\"\\operatorname{PP}(W)=\\left(\\frac1{P(W)}\\right)^{1/N}\" style=\"width:23.594ex;height:6.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The root removes the effect of sequence length; the reciprocal makes lower surprise correspond to lower perplexity.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/31c8e928444ef07c.svg\" alt=\"1/P(W)=1/0.0625=16\" style=\"width:24.937ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the fourth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/560b6664723185b3.svg\" alt=\"\\operatorname{PP}=16^{1/4}\" style=\"width:10.948ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c15dbdf7cfc85ea8.svg\" alt=\"2^4=16\\quad\\Rightarrow\\quad\\operatorname{PP}=2\" style=\"width:22.672ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 2.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Two language models score the same three-token test sequence. Model A gives next-token probabilities 0.5, 0.5, 0.5. Model B gives 0.5, 0.25, 0.25. Compute their perplexities and select the better intrinsic result.</strong></p><div class=\"given\"><h4>Given</h4><p>Same sequence and N=3 for both models. A factors: 0.5,0.5,0.5. B factors: 0.5,0.25,0.25.</p><h4>To find</h4><p>Both sequence probabilities and perplexities.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3f347a2e35262f3f.svg\" alt=\"P(W)=\\prod_i p_i,\\qquad\\operatorname{PP}=P(W)^{-1/3}\" style=\"width:35.285ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A fair comparison uses identical test tokens and scoring conventions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Calculate A's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/072e354cb1ef7f5e.svg\" alt=\"P_A=0.5\\times0.5\\times0.5=0.125=1/8\" style=\"width:34.645ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate A's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/eaa36684164a8ec6.svg\" alt=\"\\operatorname{PP}_A=8^{1/3}=2\" style=\"width:15.353ex;height:2.48ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate B's probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e4c44123baab46cd.svg\" alt=\"P_B=0.5\\times0.25\\times0.25=0.03125=1/32\" style=\"width:40.315ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate B's perplexity</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7cad7e80704e87a9.svg\" alt=\"\\operatorname{PP}_B=32^{1/3}\\approx3.174802\" style=\"width:23.915ex;height:2.474ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Compare</h5><p>2 is lower than 3.174802; A places more probability on the observed sequence.</p></div><div class=\"answer\"><strong>Final answer.</strong> Model A is better by perplexity on this test: 2 versus about 3.174802.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The bigram training corpus is “This is a dog”, “This is a cat”, “I love my cat”, “This is my name”. Score “This is my cat”, including an end marker, and compute perplexity using five predicted events.</strong></p><div class=\"given\"><h4>Given</h4><p>Each training sentence has one start and end marker. Test predictions: This, is, my, cat, &lt;/s&gt;. Thus N=5.</p><h4>To find</h4><p>Bigram sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cdcbde9621e0e24d.svg\" alt=\"P(w\\mid h)=C(h,w)/C(h),\\qquad\\operatorname{PP}=P(W)^{-1/5}\" style=\"width:45.9ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start is given context. Four words plus the end marker produce five probability factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count the required transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Transition</th><th>Pair count / history count</th></tr></thead><tbody><tr><td>&lt;s&gt;→This</td><td>3/4</td></tr><tr><td>This→is</td><td>3/3</td></tr><tr><td>is→my</td><td>1/3</td></tr><tr><td>my→cat</td><td>1/2</td></tr><tr><td>cat→&lt;/s&gt;</td><td>2/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 2. Form the product</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9c8a03a484dfb763.svg\" alt=\"P=\\frac34\\times1\\times\\frac13\\times\\frac12\\times1=\\frac18\" style=\"width:29.565ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the reciprocal</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/063b3931740c7830.svg\" alt=\"1/P=8\" style=\"width:8.11ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c0fbb6bb85c1b79f.svg\" alt=\"\\operatorname{PP}=8^{1/5}\\approx1.515717\" style=\"width:21.382ex;height:2.32ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(W)=1/8 and perplexity≈1.515717 using five predicted events.</div></section><p><strong>If the question explicitly states N = 6:</strong> use that supplied convention and report PP = 8<sup>1/6</sup> ≈ 1.414214. The class slide counts both boundary markers in N. Write the chosen N beside the formula; do not silently switch between 5 and 6. Also, This occurs three times and is follows it three times, so P(is|This)=3/3, not 3/4.</p><section class=\"example\"><p class=\"question\"><strong>Question. A uniform model assigns probability 1/10 to each actual next word in a five-token test. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Five scored tokens, each with assigned probability 0.1. N=5.</p><h4>To find</h4><p>The sentence probability and perplexity.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/245311d6fb2b9841.svg\" alt=\"P(W)=(1/10)^5,\\qquad \\operatorname{PP}=P(W)^{-1/5}\" style=\"width:37.412ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Uniform equal probabilities make the effective number of choices especially clear.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Multiply the five factors</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/dbea309801bb43da.svg\" alt=\"P(W)=0.1^5=0.00001=10^{-5}\" style=\"width:30.672ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Invert</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a7f36a9eff1f3a2c.svg\" alt=\"1/P(W)=10^5\" style=\"width:14.36ex;height:2.565ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Take the fifth root</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a14770a9a80e5984.svg\" alt=\"\\operatorname{PP}=(10^5)^{1/5}=10\" style=\"width:18.976ex;height:2.7ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 10.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Probability high → surprise low → perplexity low.</p></section>"},{"id":"log-probabilities","title":"Log probabilities: replace long products with sums","html":"<p>Probabilities are at most 1, so multiplying many of them produces very small numbers. Computers can round extremely small positive products to zero: <strong>numerical underflow</strong>. Log probabilities convert multiplication into addition and are more stable for long sequences. Natural logs use base e; log₂ uses base 2. Choose one base consistently.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cbf31ffd35c5c322.svg\" alt=\"\\ln P(W)=\\sum_{i=1}^{N}\\ln p_i\" style=\"width:18.897ex;height:6.74ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab927afa9cd05bef.svg\" alt=\"P(W)=e^{\\ln P(W)},\\qquad \\operatorname{PP}(W)=\\exp\\left(-\\frac1N\\sum_i\\ln p_i\\right)\" style=\"width:51.919ex;height:6.785ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The log of a probability below 1 is negative. A value closer to zero means a larger probability: ln(0.5) ≈ −0.693 is larger than ln(0.1) ≈ −2.303. A zero probability has log −∞; taking logs does not solve the unseen-event problem. Smoothing handles that separate problem.</p><section class=\"example\"><p class=\"question\"><strong>Question. The next-word probabilities are 0.5, 0.25 and 0.5. Calculate the natural log probability, ordinary probability and perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>p₁=0.5; p₂=0.25; p₃=0.5; N=3.</p><h4>To find</h4><p>ln P(W), P(W), and PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9bced9ebe87e44c7.svg\" alt=\"\\ln P=\\sum_i\\ln p_i,\\quad P=e^{\\ln P},\\quad\\operatorname{PP}=e^{-\\ln P/N}\" style=\"width:43.938ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Logarithms preserve products as sums and the exponent converts the result back.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Compute individual logs</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8fc9ba50109d8156.svg\" alt=\"\\ln0.5\\approx-0.693147,\\quad\\ln0.25\\approx-1.386294\" style=\"width:41.36ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Add all three terms</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fcdc8edcec916f1f.svg\" alt=\"\\ln P=-0.693147-1.386294-0.693147\\approx-2.772589\" style=\"width:53.239ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Recover the probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b886c03a804cf5a4.svg\" alt=\"P=e^{-2.772589}\\approx0.0625\" style=\"width:22.549ex;height:2.201ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Find average negative log probability</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4d6cc3cf68cb5127.svg\" alt=\"-\\ln P/3\\approx2.772589/3=0.924196\" style=\"width:33.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Exponentiate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d34de424885d00e.svg\" alt=\"\\operatorname{PP}=e^{0.924196}\\approx2.519842\" style=\"width:24.949ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> ln P≈−2.772589, P=0.0625, PP≈2.519842.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A model has a total natural log probability −12 over six scored tokens. Calculate its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>ln P(W)=−12; N=6.</p><h4>To find</h4><p>PP without forming the tiny ordinary probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f166d1cce0943ce3.svg\" alt=\"\\operatorname{PP}=\\exp(-\\ln P(W)/N)\" style=\"width:24.688ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The logarithmic formula directly uses the supplied log score.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Negate the log score</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/90abe91c0eba5423.svg\" alt=\"-\\ln P=12\" style=\"width:11.38ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Divide by token count</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9d8a38c0a5d6d98a.svg\" alt=\"12/6=2\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Apply exponential</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d421123292e12a1.svg\" alt=\"\\operatorname{PP}=e^2\\approx7.389056\" style=\"width:19.705ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity≈7.389056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A language model's average negative log₂ probability is 3 bits per token. Find its perplexity.</strong></p><div class=\"given\"><h4>Given</h4><p>Cross-entropy H=3 bits/token. Log base is 2.</p><h4>To find</h4><p>PP.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50941856f700d45e.svg\" alt=\"\\operatorname{PP}=2^H\" style=\"width:8.838ex;height:2.213ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The inverse operation of log₂ is raising 2 to that power; use e only for natural logs.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the log base</h5><p>Bits mean base 2.</p></div><div class=\"step\"><h5>Step 2. Raise the base to H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ffdeccced5f3a45.svg\" alt=\"\\operatorname{PP}=2^3=8\" style=\"width:12.366ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Perplexity = 8.</div><p class=\"cue\"><strong>Yaad rakho:</strong> ln use kiya toh e se wapas; log₂ use kiya toh 2 se wapas.</p></section>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-hmm","title":"HMM & decoding","unit":0,"sections":[{"id":"markov-chain","title":"Markov chains: read a transition table and multiply a path","html":"<p><strong>A Markov chain</strong> is a probabilistic model of a sequence of states. Under the first-order Markov assumption, the next state's probability depends on the current state rather than the complete previous history. The <strong>initial probability</strong> tells us how likely each first state is. A <strong>transition probability</strong> tells us how likely a move from one state to another is.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c9611ed107ec9047.svg\" alt=\"P(s_t\\mid s_1,\\ldots,s_{t-1})=P(s_t\\mid s_{t-1})\" style=\"width:32.192ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e50f813caaa8d825.svg\" alt=\"P(s_1,\\ldots,s_T)=P(s_1)\\prod_{t=2}^{T}P(s_t\\mid s_{t-1})\" style=\"width:36.137ex;height:6.73ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For T states in a path, use one initial factor and T−1 transition factors. A row-oriented transition matrix must have each complete row sum to 1. Always read the row/column labels; some exam diagrams use a transposed arrangement.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><section class=\"example\"><p class=\"question\"><strong>Question. For the Rain/Dry Markov chain with initial P(Rain)=0.4 and P(Dry)=0.6, and transitions Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8, find the probability of Dry, Dry, Rain, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Dry,Dry,Rain,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d6fc24a22e2f64d.svg\" alt=\"P(D,D,R,R)=P(D)P(D\\mid D)P(R\\mid D)P(R\\mid R)\" style=\"width:48.815ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each step conditions on the immediately preceding state. The sequence contains four states, so it needs one initial plus three transition factors.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start in Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/cf847b7db44f5fad.svg\" alt=\"P(D)=0.6\" style=\"width:11.241ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move Dry to Dry</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5e47f480eb58213.svg\" alt=\"0.6\\times0.8=0.48\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move Dry to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0e4bbd812b1ba4d.svg\" alt=\"0.48\\times0.2=0.096\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Rain to Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/da540845c4cc326e.svg\" alt=\"0.096\\times0.3=0.0288\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.0288.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For initial probabilities Rain=0.4, Dry=0.6 and transition rows Rain=(0.3,0.7), Dry=(0.2,0.8) in column order Rain,Dry, find the probability of Rain, Dry, Rain.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>P(Rain,Dry,Rain).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c4b2bba9bbf4c148.svg\" alt=\"P(R,D,R)=P(R)P(D\\mid R)P(R\\mid D)\" style=\"width:36.844ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Do not replace Dry→Rain with Rain→Dry: the two directional probabilities differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial Rain</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/634e8d0183974542.svg\" alt=\"P(R)=0.4\" style=\"width:11.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2ff067547e9b897f.svg\" alt=\"P(D\\mid R)=0.7,\\quad0.4(0.7)=0.28\" style=\"width:32.695ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Second transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ca3a09e7de1ba004.svg\" alt=\"P(R\\mid D)=0.2,\\quad0.28(0.2)=0.056\" style=\"width:34.958ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Path probability = 0.056.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same fully specified chain—initial Rain=0.4, Dry=0.6; Rain→Rain=0.3, Rain→Dry=0.7, Dry→Rain=0.2, Dry→Dry=0.8—find P(Dry,Dry). Also find the conditional probability of next Dry given current Dry.</strong></p><div class=\"given\"><h4>Given</h4><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>Rain</th><th>Dry</th></tr></thead><tbody><tr><td>Rain</td><td>0.3</td><td>0.7</td></tr><tr><td>Dry</td><td>0.2</td><td>0.8</td></tr></tbody></table></div><p>Initial probabilities: P(Rain)=0.4, P(Dry)=0.6. Rows describe the current state; columns describe the next state.</p><h4>To find</h4><p>The two-state joint probability and the one-step conditional probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83080c3651cd8fc6.svg\" alt=\"P(D,D)=P(D)P(D\\mid D)\" style=\"width:25.653ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The joint path includes an uncertain initial state. The conditional transition assumes the current state is already Dry.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Read the conditional transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1cf8b238b738730b.svg\" alt=\"P(D\\mid D)=0.8\" style=\"width:15ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Include the initial state for the joint path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/21b9a2b02a067056.svg\" alt=\"P(D,D)=0.6\\times0.8=0.48\" style=\"width:26.817ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(Dry,Dry)=0.48; P(next Dry|current Dry)=0.8. These answer different questions.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Path: pehle start probability, phir har arrow ki probability.</p></section>"},{"id":"transition-emission-estimation","title":"Estimate transition and emission probabilities from tagged data","html":"<div class=\"equation\"><div class=\"math-display\"><img src=\"math/2145c612575540f3.svg\" alt=\"P(t&#39;\\mid t)=\\frac{C(t,t&#39;)}{C(t)\\text{ with a following tag/end event}}\" style=\"width:46.275ex;height:5.495ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a89d9641a3681129.svg\" alt=\"P(w\\mid t)=\\frac{C(w,t)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>In a transition denominator, count the previous tag's outgoing events. In an emission denominator, count all tokens bearing that tag. With explicit end transitions the totals align conveniently. Keep the two numerator types separate: tag→tag counts are not word→tag counts.</p><section class=\"example\"><p class=\"question\"><strong>Question. A tagged corpus contains 116454 determiner tags DT, each counted with an outgoing event. DT is followed by NN 56509 times. Estimate P(NN|DT).</strong></p><div class=\"given\"><h4>Given</h4><p>C(DT)=116454; C(DT,NN)=56509.</p><h4>To find</h4><p>The DT→NN transition probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f5163e6a68004bc8.svg\" alt=\"P(NN\\mid DT)=C(DT,NN)/C(DT)\" style=\"width:35.893ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The denominator is the number of previous DT contexts because DT is the condition.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Identify the transition count</h5><p>DT followed by NN occurs 56509 times.</p></div><div class=\"step\"><h5>Step 2. Identify the conditional total</h5><p>There are 116454 DT contexts.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/47e9bc9d8bc16788.svg\" alt=\"P(NN\\mid DT)=\\frac{56509}{116454}\\approx0.485247\" style=\"width:35.194ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(NN|DT)≈0.485247.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. The tag VBZ occurs 21627 times, and 10073 of those tokens are the word “is”. Estimate P(is|VBZ).</strong></p><div class=\"given\"><h4>Given</h4><p>C(VBZ)=21627; C(is,VBZ)=10073.</p><h4>To find</h4><p>The emission probability of is from VBZ.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ec13ac6a8a9bdae.svg\" alt=\"P(is\\mid VBZ)=C(is,VBZ)/C(VBZ)\" style=\"width:36.42ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The condition is the tag VBZ; we ask which word it emits.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Choose the word-tag count</h5><p>The required word is is with tag VBZ: count 10073.</p></div><div class=\"step\"><h5>Step 2. Choose the tag total</h5><p>All VBZ-tagged word tokens: count 21627.</p></div><div class=\"step\"><h5>Step 3. Divide</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/481557575db95324.svg\" alt=\"P(is\\mid VBZ)=\\frac{10073}{21627}\\approx0.465760\" style=\"width:33.513ex;height:4.661ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> P(is|VBZ)≈0.465760. This is different from P(VBZ|is).</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Use the tagged sentences “dogs/N chase/V cats/N” and “cats/N sleep/V”. Estimate the initial tag probabilities, all nonzero transitions including END, and emissions.</strong></p><div class=\"given\"><h4>Given</h4><p>Corpus: START dogs/N chase/V cats/N END; START cats/N sleep/V END.</p><h4>To find</h4><p>Initial distribution, transition rows and emission rows.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/46d6d50083ab5629.svg\" alt=\"\\pi_t=C(START,t)/2,\\quad a_{tu}=C(t,u)/C(t),\\quad b_t(w)=C(w,t)/C(t)\" style=\"width:65.634ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The corpus explicitly tells us the tags, so we can count training frequencies directly.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Count tag tokens</h5><p>N occurs 3 times: dogs, cats, cats. V occurs 2 times: chase, sleep.</p></div><div class=\"step\"><h5>Step 2. Count sentence starts</h5><p>Both sentences start with N.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a5ae0d0edad4515.svg\" alt=\"\\pi_N=2/2=1,\\quad \\pi_V=0/2=0\" style=\"width:29.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Count transitions</h5><div class=\"table-wrap\"><table><thead><tr><th>Pair</th><th>Count</th></tr></thead><tbody><tr><td>N→V</td><td>2</td></tr><tr><td>N→END</td><td>1</td></tr><tr><td>V→N</td><td>1</td></tr><tr><td>V→END</td><td>1</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 4. Normalize transition rows</h5><div class=\"table-wrap\"><table><thead><tr><th>Current</th><th>To N</th><th>To V</th><th>To END</th></tr></thead><tbody><tr><td>N</td><td>0</td><td>2/3</td><td>1/3</td></tr><tr><td>V</td><td>1/2</td><td>0</td><td>1/2</td></tr></tbody></table></div></div><div class=\"step\"><h5>Step 5. Count and normalize emissions</h5><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>dogs</th><th>cats</th><th>chase</th><th>sleep</th></tr></thead><tbody><tr><td>N</td><td>1/3</td><td>2/3</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/2</td><td>1/2</td></tr></tbody></table></div></div><div class=\"answer\"><strong>Final answer.</strong> π=(1,0); transitions and emissions are given in the completed tables. Each complete probability row sums to 1.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Tag→tag table aur tag→word table ko mix mat karna.</p>"},{"id":"hot-cold-paths","title":"HMM path probabilities: three complete numerical examples","html":"<p>The following model uses hidden weather states Hot (H) and Cold (C). Observations are numbers 1, 2 and 3. These numbers are observation labels, not quantities to multiply directly. Their emission probabilities come from the table.</p><div class=\"table-wrap\"><table><thead><tr><th>Initial state</th><th>Probability</th></tr></thead><tbody><tr><td>H</td><td>0.8</td></tr><tr><td>C</td><td>0.2</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>From → to</th><th>H</th><th>C</th></tr></thead><tbody><tr><td>H</td><td>0.7</td><td>0.3</td></tr><tr><td>C</td><td>0.4</td><td>0.6</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Emission state</th><th>Observation 1</th><th>Observation 2</th><th>Observation 3</th></tr></thead><tbody><tr><td>H</td><td>0.2</td><td>0.4</td><td>0.4</td></tr><tr><td>C</td><td>0.5</td><td>0.4</td><td>0.1</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for observations (1,2,3) are H:(0.2,0.4,0.4) and C:(0.5,0.4,0.1). Find the joint probability of hidden path H,C,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path H→C→H. Observations 1→3→1. Model probabilities are specified in the question. There is no END factor.</p><h4>To find</h4><p>P(H,C,H; 1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7d9c99617b5e16c0.svg\" alt=\"P=\\pi_H b_H(1)a_{HC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.863ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>There are three hidden states and observations: three emissions, two transitions, and one initial probability.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Hot and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/78369e147be76567.svg\" alt=\"0.8\\times0.2=0.16\" style=\"width:15.588ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Transition Hot to Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/24d6c09c3069c91f.svg\" alt=\"0.16\\times0.3=0.048\" style=\"width:17.851ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Cold emits 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/59bb445235ff63a6.svg\" alt=\"0.048\\times0.1=0.0048\" style=\"width:20.113ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Transition Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1146803e8605f2e.svg\" alt=\"0.0048\\times0.4=0.00192\" style=\"width:22.376ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Hot emits the last 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e3b740dc0fd787f.svg\" alt=\"0.00192\\times0.2=0.000384\" style=\"width:24.638ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.000384 = 3.84×10⁻⁴.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels (1,2,3), find the joint probability of path H,H,H and observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>State path H→H→H, observations 1→3→1; no END factor.</p><h4>To find</h4><p>P(H,H,H;1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/83f5cb754dc77195.svg\" alt=\"P=\\pi_H b_H(1)a_{HH}b_H(3)a_{HH}b_H(1)\" style=\"width:32.477ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The state remains Hot; each transition still contributes its probability 0.7.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initial state and first emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/806228a802bab106.svg\" alt=\"0.8(0.2)=0.16\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. First self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f1106c30e00cc2ce.svg\" alt=\"0.16(0.7)=0.112\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/359ae9ea2534c8f2.svg\" alt=\"0.112(0.4)=0.0448\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Second self-transition</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d2be9254f3d2eee1.svg\" alt=\"0.0448(0.7)=0.03136\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit final observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/af971b25ad6922c0.svg\" alt=\"0.03136(0.2)=0.006272\" style=\"width:23.632ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.006272. A self-transition is not automatically probability 1.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6) in next-state order H,C; emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3, find the score of path C,C,H with observations 1,3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Hidden path C→C→H. Observation sequence 1→3→1. No end-state factor.</p><h4>To find</h4><p>The joint path-and-observation probability.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c39dbc8fa9b14a01.svg\" alt=\"P=\\pi_C b_C(1)a_{CC}b_C(3)a_{CH}b_H(1)\" style=\"width:31.248ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The initial state is Cold, so use π(C), not π(H). Each emission is selected from the state at the same position.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start Cold and emit 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ea1ebd665b713576.svg\" alt=\"0.2(0.5)=0.1\" style=\"width:13.451ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Stay Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3af50c5661f75952.svg\" alt=\"0.1(0.6)=0.06\" style=\"width:14.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Emit 3 from Cold</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2039ca068efac123.svg\" alt=\"0.06(0.1)=0.006\" style=\"width:16.845ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move Cold to Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/99539fe7f4612c73.svg\" alt=\"0.006(0.4)=0.0024\" style=\"width:19.108ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Emit 1 from Hot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/315780f838015183.svg\" alt=\"0.0024(0.2)=0.00048\" style=\"width:21.37ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Joint probability = 0.00048.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har column par: state ka emission. Columns ke beech: transition.</p></section>"},{"id":"tagging-corpus-case","title":"POS HMM worked corpus: Mary, Jane, can, will and spot","html":"<p>The class example contains words that can be either names or ordinary verbs/modal auxiliaries. The term is <strong>modal</strong> (M), not “model”. To avoid guessing tags from spelling, the training corpus below supplies them explicitly and lowercases words for the emission vocabulary.</p><div class=\"table-wrap\"><table><thead><tr><th>Training sentence</th><th>Gold tags</th></tr></thead><tbody><tr><td>mary jane can see will</td><td>N N M V N</td></tr><tr><td>spot will see mary</td><td>N M V N</td></tr><tr><td>will jane spot mary</td><td>M N V N</td></tr><tr><td>mary will pat spot</td><td>N M V N</td></tr></tbody></table></div><p>There are 9 noun tokens, 4 modal tokens and 4 verb tokens. Each sentence includes a start and end transition. For nouns, the next event can be another noun, modal, verb or END.</p><div class=\"table-wrap\"><table><thead><tr><th>Current → next</th><th>N</th><th>M</th><th>V</th><th>END</th></tr></thead><tbody><tr><td>START</td><td>3/4</td><td>1/4</td><td>0</td><td>0</td></tr><tr><td>N</td><td>1/9</td><td>3/9</td><td>1/9</td><td>4/9</td></tr><tr><td>M</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td></tr><tr><td>V</td><td>4/4</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Tag → word</th><th>mary</th><th>jane</th><th>can</th><th>see</th><th>will</th><th>spot</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>4/9</td><td>2/9</td><td>0</td><td>0</td><td>1/9</td><td>2/9</td><td>0</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>3/4</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>0</td><td>2/4</td><td>0</td><td>1/4</td><td>1/4</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Using the fully tagged four-sentence corpus above, calculate the joint score of “will jane spot mary” assigned tags M,N,V,N, including END.</strong></p><div class=\"given\"><h4>Given</h4><p>Required factors from the tables: START→M=1/4; emit will|M=3/4; M→N=1/4; jane|N=2/9; N→V=1/9; spot|V=1/4; V→N=1; mary|N=4/9; N→END=4/9.</p><h4>To find</h4><p>The specified tag-path score, including words and sentence end.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/23c70e8086b83a3b.svg\" alt=\"P=\\pi_M b_M(will)a_{MN}b_N(jane)a_{NV}b_V(spot)a_{VN}b_N(mary)a_{N,END}\" style=\"width:62.792ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both transitions and emissions are needed. A tag transition alone cannot tell us whether a particular word is plausible.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start and emit will</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7a7d30f8cd240d72.svg\" alt=\"\\frac14\\times\\frac34=\\frac3{16}\" style=\"width:13.294ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Move to N and emit jane</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/934eaa8bf4f9d42a.svg\" alt=\"\\frac3{16}\\times\\frac14\\times\\frac29=\\frac1{96}\" style=\"width:19.318ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Move to V and emit spot</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/40b213c06ef8b7d2.svg\" alt=\"\\frac1{96}\\times\\frac19\\times\\frac14=\\frac1{3456}\" style=\"width:21.58ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Move to N and emit mary</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a0e9571f3b95594c.svg\" alt=\"\\frac1{3456}\\times1\\times\\frac49=\\frac1{7776}\" style=\"width:22.847ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. End the sentence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/171a6c8b22e17d35.svg\" alt=\"\\frac1{7776}\\times\\frac49=\\frac1{17496}\\approx0.0000571559\" style=\"width:36.171ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The joint score is 1/17496 ≈ 0.0000571559.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For the same tagged corpus and tables, explain the unsmoothed score of “will can spot mary” assigned tags M,V,N,N.</strong></p><div class=\"given\"><h4>Given</h4><p>The proposed second word is can with hidden tag V. In the training corpus, can occurs only with M, so b_V(can)=0.</p><h4>To find</h4><p>Whether the complete path score is zero and what this means.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0957b6ab0a1aa0cc.svg\" alt=\"P(\\text{path,words})=(\\text{other required factors})\\times b_V(can)\" style=\"width:50.674ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A product containing one zero factor is zero even if every other factor is positive.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Find the critical emission</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fdca0f8e7f8d838a.svg\" alt=\"b_V(can)=C(can,V)/C(V)=0/4=0\" style=\"width:37.369ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Use the full-product consequence</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e316f36777dd5.svg\" alt=\"P(\\text{path,words})=0\" style=\"width:18.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Interpret correctly</h5><p>This unsmoothed corpus model has no evidence for can as a verb. It does not prove that a verb usage of can is impossible in English.</p></div><div class=\"answer\"><strong>Final answer.</strong> The unsmoothed path score is zero.</div></section>"},{"id":"sequence-count","title":"Why exhaustive search grows exponentially","html":"<p>If each of T observed words can receive any of N tags, there are N choices at each position. Thus the total number of complete tag sequences is N multiplied by itself T times. This counts possible assignments before grammar rules or zero probabilities eliminate any.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/014ed66c3c0df2b1.svg\" alt=\"\\text{Number of tag sequences}=N^T\" style=\"width:30.626ex;height:2.484ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A four-word sentence is tagged using three possible POS tags per word. How many complete tag sequences are possible?</strong></p><div class=\"given\"><h4>Given</h4><p>N=3 possible tags per position; T=4 word positions.</p><h4>To find</h4><p>The number of tag sequences.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every independent position contributes a factor of three choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write one factor per position</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d7b06b7e39ae0a5.svg\" alt=\"M=3\\times3\\times3\\times3\" style=\"width:18.217ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6570633fef12ecb5.svg\" alt=\"3\\times3=9,\\quad9\\times3=27,\\quad27\\times3=81\" style=\"width:37.46ex;height:1.968ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 81 possible tag sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A five-word sentence has two candidate tags per word. Count its tag sequences.</strong></p><div class=\"given\"><h4>Given</h4><p>N=2; T=5.</p><h4>To find</h4><p>M.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The length is the exponent, not a multiplier.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Substitute</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e0b25a2374d09c2d.svg\" alt=\"M=2^5\" style=\"width:7.514ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/85ec03497588b6d5.svg\" alt=\"2\\times2\\times2\\times2\\times2=32\" style=\"width:21.998ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 32 possible sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using 45 possible tags, compare the number of tag sequences for sentences of length 2 and 3.</strong></p><div class=\"given\"><h4>Given</h4><p>N=45. First T=2, then T=3.</p><h4>To find</h4><p>Both counts and the growth factor.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0806abcd5d0a43e.svg\" alt=\"M_2=45^2,\\quad M_3=45^3\" style=\"width:22.167ex;height:2.439ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Adding one position multiplies the possibilities by the number of tag choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Two words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/672617aa8909800b.svg\" alt=\"45^2=2025\" style=\"width:10.792ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Three words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/96a0c5c55e4f8048.svg\" alt=\"45^3=2025\\times45=91125\" style=\"width:24.493ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3daee8fcfcc1adea.svg\" alt=\"91125/2025=45\" style=\"width:16.592ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 2 words: 2025 paths. 3 words: 91125 paths. One additional word multiplies the count by 45.</div></section><p>The slides introduce Viterbi to avoid enumerating every path. It reuses the best prefix score for each ending state. For a dense first-order HMM, it needs O(TN²) recurrence work instead of enumerating N<sup>T</sup> complete paths.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Choices per word ki power = sentence length.</p>"},{"id":"viterbi-explained","title":"Viterbi decoding: compare incoming paths, keep the best, trace back","html":"<p><strong>The Viterbi algorithm</strong> finds the most likely hidden-state sequence for a fixed observation sequence. At each position, it keeps the best path ending in each state. This is safe because, under the HMM assumptions, future extensions depend on that ending state, not the discarded details of the prefix.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b3fa79f3d8232431.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1)\" style=\"width:15.501ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/50951d9d0cf5dcf6.svg\" alt=\"\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:27.716ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3935aac800940d84.svg\" alt=\"\\psi_t(j)=\\arg\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:25.893ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"table-wrap\"><table><thead><tr><th>Symbol</th><th>Meaning in ordinary words</th></tr></thead><tbody><tr><td>δₜ(j)</td><td>Score of the best prefix that ends in state j at position t.</td></tr><tr><td>ψₜ(j)</td><td>Previous state that supplied that best prefix; keep it as a backpointer.</td></tr><tr><td>max</td><td>Choose the larger candidate score; do not add.</td></tr><tr><td>argmax</td><td>Remember which previous state won, rather than only its value.</td></tr></tbody></table></div><div class=\"flow\"><div class=\"node\">Initialize: start × first emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">For each next state: compare incoming scores</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Multiply winner by this state's emission</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Keep score + winning predecessor</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose best final state and trace arrows backward</div></div><p>Do not choose the best state independently at each word. The best last state can come from a different best predecessor than a local guess. Backpointers recover one consistent complete path. If scores tie, either tied path is optimal under the model; state the tie.</p><section class=\"example\"><p class=\"question\"><strong>Question. Use an HMM with π(H)=0.8, π(C)=0.2, transitions H:(0.7,0.3), C:(0.4,0.6) in H,C order, and emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for observations 1,2,3. Find the most likely hidden path for observations 1,3,1 using Viterbi.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>The best hidden-state sequence and its joint score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/712c98f9c4966f84.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(o_1),\\quad\\delta_t(j)=b_j(o_t)\\max_i[\\delta_{t-1}(i)a_{ij}]\" style=\"width:46.485ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Viterbi keeps two best prefix scores per column, one ending H and one ending C.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize at observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/44fc29f14406bbca.svg\" alt=\"\\delta_1(H)=0.8(0.2)=0.16\" style=\"width:23.361ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1500f80244db39b.svg\" alt=\"\\delta_1(C)=0.2(0.5)=0.10\" style=\"width:23.072ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. At observation 3, calculate the H cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/61623e2cd024bab3.svg\" alt=\"H\\to H:\\ 0.16(0.7)=0.112\" style=\"width:26.834ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/256055f1b5c81a60.svg\" alt=\"C\\to H:\\ 0.10(0.4)=0.040\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ee04f7fda3bf226b.svg\" alt=\"\\delta_2(H)=\\max(0.112,0.040)(0.4)=0.0448\" style=\"width:40.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this H cell: H.</p></div><div class=\"step\"><h5>Step 3. At observation 3, calculate the C cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e9c32ed85546537.svg\" alt=\"H\\to C:\\ 0.16(0.3)=0.048\" style=\"width:26.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4c0863275b12a91e.svg\" alt=\"C\\to C:\\ 0.10(0.6)=0.060\" style=\"width:26.255ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a8ea78adb0cc4576.svg\" alt=\"\\delta_2(C)=\\max(0.048,0.060)(0.1)=0.006\" style=\"width:38.596ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer for this C cell: C.</p></div><div class=\"step\"><h5>Step 4. At final observation 1, calculate H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6e2373be2aa769a8.svg\" alt=\"H\\to H:\\ 0.0448(0.7)=0.03136\" style=\"width:31.359ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/286832c2c26620dd.svg\" alt=\"C\\to H:\\ 0.006(0.4)=0.0024\" style=\"width:28.807ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/48b05bab6b13e38a.svg\" alt=\"\\delta_3(H)=0.03136(0.2)=0.006272\" style=\"width:32.411ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 5. At final observation 1, calculate C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a5f431d2a23d6fe1.svg\" alt=\"H\\to C:\\ 0.0448(0.3)=0.01344\" style=\"width:31.069ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b69919a26d75a560.svg\" alt=\"C\\to C:\\ 0.006(0.6)=0.0036\" style=\"width:28.517ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/709ea0da7f36d663.svg\" alt=\"\\delta_3(C)=0.01344(0.5)=0.00672\" style=\"width:30.99ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Backpointer: H.</p></div><div class=\"step\"><h5>Step 6. Select the final state</h5><p>0.00672 > 0.006272, so the best final state is C.</p></div><div class=\"step\"><h5>Step 7. Trace back</h5><p>Final C came from H at position2. That H came from H at position1. Reading forward gives H,H,C.</p></div><div class=\"step\"><h5>Step 8. Verify the recovered complete path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5aa4b0fd88f37247.svg\" alt=\"0.8(0.2)(0.7)(0.4)(0.3)(0.5)=0.00672\" style=\"width:36.583ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H→C with joint score 0.00672.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 3,1.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best two-state hidden path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/801327bb8fdbd394.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(3),\\quad\\delta_2(j)=b_j(1)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The same recurrence applies even though the observation order changed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2e38d10b83c569f4.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.1)=0.02\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1716d45167a355a0.svg\" alt=\"\\max(0.32(0.7),0.02(0.4))(0.2)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4db3393304c21c23.svg\" alt=\"=\\max(0.224,0.008)(0.2)=0.0448\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 3. Calculate the final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bd4ebf48e761f108.svg\" alt=\"\\max(0.32(0.3),0.02(0.6))(0.5)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15d2f168f4fe9604.svg\" alt=\"=\\max(0.096,0.012)(0.5)=0.048\" style=\"width:32.495ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Winning predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>Final C wins with 0.048 and came from H. The path is H,C.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→C, score 0.048.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. For π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3, decode observations 2,2.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>Best path and score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a478f4924f42dec2.svg\" alt=\"\\delta_1(j)=\\pi_jb_j(2),\\quad\\delta_2(j)=b_j(2)\\max_i[\\delta_1(i)a_{ij}]\" style=\"width:43.2ex;height:3.401ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Both states emit2 with probability 0.4, but their initial and transition probabilities still differ.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/56ea5abfdb65b387.svg\" alt=\"\\delta_1(H)=0.8(0.4)=0.32,\\quad\\delta_1(C)=0.2(0.4)=0.08\" style=\"width:49.701ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Final H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75472da37ba442a1.svg\" alt=\"\\max(0.32(0.7),0.08(0.4))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f9a0610a246e0ed0.svg\" alt=\"=\\max(0.224,0.032)(0.4)=0.0896\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 3. Final C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/87b9dd83765528d1.svg\" alt=\"\\max(0.32(0.3),0.08(0.6))(0.4)\" style=\"width:28.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/088fd26aaafea320.svg\" alt=\"=\\max(0.096,0.048)(0.4)=0.0384\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Predecessor H.</p></div><div class=\"step\"><h5>Step 4. Select and trace</h5><p>The final H score 0.0896 is larger. Its predecessor is H.</p></div><div class=\"answer\"><strong>Final answer.</strong> Best path H→H with score 0.0896.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Har destination ke liye incoming paths compare; winner ka arrow yaad.</p></section>"},{"id":"joint-vs-posterior","title":"A path score is not the probability of the observed sentence","html":"<section class=\"example\"><p class=\"question\"><strong>Question. An HMM has π(H)=0.8, π(C)=0.2; transitions H:(0.7,0.3), C:(0.4,0.6); emissions H:(0.2,0.4,0.4), C:(0.5,0.4,0.1) for labels1,2,3. For observations 1,3, calculate the probability of the observations by summing all four two-state paths.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial probabilities: π(H)=0.8, π(C)=0.2. Transition matrix: H→H=0.7, H→C=0.3, C→H=0.4, C→C=0.6. Emissions for labels (1,2,3): H=(0.2,0.4,0.4), C=(0.5,0.4,0.1). There is no END-state factor.</p><h4>To find</h4><p>P(observations 1,3), not just the best-path score.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e24e591ebf359dce.svg\" alt=\"P(o_1,o_2)=\\sum_{s_1,s_2}\\pi_{s_1}b_{s_1}(o_1)a_{s_1s_2}b_{s_2}(o_2)\" style=\"width:35.484ex;height:5.061ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The hidden path is unspecified, so its mutually exclusive alternatives must be summed.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score H,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c316d3e7d10ea4e8.svg\" alt=\"0.8(0.2)(0.7)(0.4)=0.0448\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Score H,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/076745077c7c6109.svg\" alt=\"0.8(0.2)(0.3)(0.1)=0.0048\" style=\"width:26.148ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Score C,H</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2dbad158b7e2df38.svg\" alt=\"0.2(0.5)(0.4)(0.4)=0.016\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Score C,C</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/595d09221813b65c.svg\" alt=\"0.2(0.5)(0.6)(0.1)=0.006\" style=\"width:25.017ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Add all paths</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2b05babdadbfdf90.svg\" alt=\"P(1,3)=0.0448+0.0048+0.016+0.006=0.0716\" style=\"width:50.222ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Observation probability =0.0716. The best single-path score 0.0448 is a different quantity.</div></section><p>If asked for the posterior of path H,H given observations 1,3, normalize: 0.0448/0.0716 ≈0.625698. Viterbi chooses the best path using joint scores because the observation denominator is common to every candidate. It does not compute that denominator by taking a maximum.</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-wsd","title":"WSD: Lesk & Naive Bayes","unit":0,"sections":[{"id":"u5-lesk","title":"Lesk algorithm, from words to overlap scores","html":"<p><strong>Lesk is a knowledge-based WSD method that chooses senses whose dictionary descriptions have the greatest overlap with contextual evidence.</strong> Original Lesk compares definitions of neighbouring words' senses. A common simplified version compares each target-sense gloss directly with the sentence context. State which version you use.</p><h3>Simplified Lesk procedure</h3><ol><li>Remove the target word from the context; tokenize and normalize the remaining content words.</li><li>Obtain the gloss for each candidate sense and apply the same normalization.</li><li>Count shared words between the context and each gloss.</li><li>Select the sense with maximum overlap. If scores tie, report the tie or use a specified tie-break rule.</li></ol><div class=\"math-display\"><img src=\"math/691fb54513999f0d.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|,\\qquad s^*=\\arg\\max_s\\operatorname{score}(s)\" style=\"width:45.416ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b5a9729b8c25c0f7.svg\" alt=\"C\" style=\"width:1.719ex;height:1.645ex\" loading=\"lazy\" decoding=\"async\"></span> is the set of context words, <span class=\"math-inline\"><img src=\"math/a5684e27b28daffa.svg\" alt=\"G_s\" style=\"width:2.716ex;height:1.95ex\" loading=\"lazy\" decoding=\"async\"></span> the set of words in sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>'s gloss, <span class=\"math-inline\"><img src=\"math/c7de95563fc530c3.svg\" alt=\"\\cap\" style=\"width:1.509ex;height:1.403ex\" loading=\"lazy\" decoding=\"async\"></span> means common elements, <span class=\"math-inline\"><img src=\"math/468f3b6d2f1b95a0.svg\" alt=\"|\\cdot|\" style=\"width:2.892ex;height:2.26ex\" loading=\"lazy\" decoding=\"async\"></span> means count, and <span class=\"math-inline\"><img src=\"math/dfccac0c4f581832.svg\" alt=\"\\arg\\max\" style=\"width:7.737ex;height:1.491ex\" loading=\"lazy\" decoding=\"async\"></span> means “the sense giving the largest score”. This version counts unique matching words once.</p><div class=\"example\"><p><strong>Question. Use simplified Lesk to disambiguate “bank” in “The river water rose near the bank.” Use C = {river, water, rose, near}; financial gloss = {institution, money, deposit}; river gloss = {land, river, water, edge}.</strong></p><div class=\"given\"><h4>Given</h4><p>The normalized context and two gloss sets are given. Count exact shared words.</p><h4>To find</h4><p>The score of each sense and the selected meaning.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because the task specifies context–gloss overlap.</p><div class=\"step\"><h4>Step 1. Compare the financial sense</h4><p>No word occurs in both {river, water, rose, near} and {institution, money, deposit}. Overlap = {}.</p></div><div class=\"step\"><h4>Step 2. Count the financial score</h4><p><span class=\"math-inline\"><img src=\"math/bdc75dbcd361db69.svg\" alt=\"\\operatorname{score}(F)=0\" style=\"width:12.522ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare the river sense</h4><p>Shared words are {river, water}. “Rose” and “near” are not in the gloss.</p></div><div class=\"step\"><h4>Step 4. Count and select</h4><p><span class=\"math-inline\"><img src=\"math/384740febd8dd4b0.svg\" alt=\"\\operatorname{score}(R)=2\" style=\"width:12.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Since <span class=\"math-inline\"><img src=\"math/6e25b81ec200909a.svg\" alt=\"2&gt;0\" style=\"width:5.28ex;height:1.597ex\" loading=\"lazy\" decoding=\"async\"></span>, choose the river-edge sense.</p></div><p class=\"answer\"><strong>Answer.</strong> Bank means land beside a river.</p></div><div class=\"example\"><p><strong>Question. Use simplified Lesk for “The dog barked loudly.” Treat barked as bark. Context C = {dog, loudly}; sound gloss = {sharp, cry, dog}; tree gloss = {outer, covering, tree}; ship gloss = {sailing, ship}.</strong></p><div class=\"given\"><h4>Given</h4><p>Three glosses and normalized context {dog, loudly}.</p><h4>To find</h4><p>Select the sense of bark.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Lemmatization lets barked match the target lemma bark; it does not create additional overlap words.</p><div class=\"step\"><h4>Step 1. Sound sense</h4><p>Intersection = {dog}; score = 1.</p></div><div class=\"step\"><h4>Step 2. Tree sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 3. Ship sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>The sound sense has the unique maximum: 1 &gt; 0.</p></div><p class=\"answer\"><strong>Answer.</strong> Bark is the dog's cry.</p></div><div class=\"example\"><p><strong>Question. Apply definition–definition Lesk to “pine cone”. Pine senses: P1 = {evergreen, tree, needle, leaf}; P2 = {waste, sorrow, illness}. Cone senses: C1 = {solid, shape, circular}; C2 = {fruit, evergreen, tree}.</strong></p><div class=\"given\"><h4>Given</h4><p>Two candidate senses for each word. Tokens are already normalized; tree and trees would be reduced to the same form if necessary.</p><h4>To find</h4><p>The most compatible pair of senses.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/bb2259d0f8a3b048.svg\" alt=\"|G_{P_i}\\cap G_{C_j}|\" style=\"width:10.997ex;height:2.506ex\" loading=\"lazy\" decoding=\"async\"></span> for every pair because this is original-style gloss–gloss comparison.</p><div class=\"step\"><h4>Step 1. P1 with C1</h4><p>No shared word → 0.</p></div><div class=\"step\"><h4>Step 2. P1 with C2</h4><p>Shared {evergreen, tree} → 2.</p></div><div class=\"step\"><h4>Step 3. P2 with each cone sense</h4><p>P2–C1 has no overlap → 0; P2–C2 has no overlap → 0.</p></div><div class=\"step\"><h4>Step 4. Choose the best pair</h4><p>The four scores are 0, 2, 0, 0. Maximum 2 belongs to P1–C2.</p></div><p class=\"answer\"><strong>Answer.</strong> Pine is the evergreen tree; cone is its fruit-like reproductive structure.</p></div><p><strong>Limitations:</strong> exact overlap misses synonyms, short glosses may produce zeros, and different preprocessing choices change the score. Extended Lesk may include related synset definitions or longer phrase overlaps; do not silently substitute it for a simple question.</p><p class=\"cue\">Lesk: context aur dictionary mein common words gino; sabse bada overlap jeeta.</p>"},{"id":"u5-walker","title":"Thesaurus / Walker approach, with three complete examples","html":"<p><strong>The Walker approach uses thesaurus categories as semantic evidence.</strong> Associate each candidate sense with a category. Count or weight context words that support that category. Choose the largest total.</p><div class=\"math-display\"><img src=\"math/9d7b8384c080650b.svg\" alt=\"\\operatorname{score}(s)=\\sum_{w\\in C} I(w,\\operatorname{category}(s))\" style=\"width:31.274ex;height:4.963ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b186266d0d476166.svg\" alt=\"I=1\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> if the supplied category mapping says the context word supports the sense, otherwise <span class=\"math-inline\"><img src=\"math/5fd951e2f99cd39c.svg\" alt=\"I=0\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>. The summation symbol means add all those contributions. Weighted questions may replace 1 with a supplied weight. Category membership must be supplied or justified; it is not guessed from word frequency.</p><div class=\"example\"><p><strong>Question. Disambiguate bank using Walker scoring. Context words are money, interest, annum, fetch. The finance category supports money, interest and annum; the location category supports none of these words.</strong></p><div class=\"given\"><h4>Given</h4><p>Two categories: Finance and Location. Each supported word contributes 1.</p><h4>To find</h4><p>The two totals and selected bank sense.</p></div><h4>Formula and why it applies</h4><p>Sum the category indicators for each sense.</p><div class=\"step\"><h4>Step 1. Make a contribution table</h4><table><thead><tr><th>Word</th><th>Finance</th><th>Location</th></tr></thead><tbody><tr><td>money</td><td>1</td><td>0</td></tr><tr><td>interest</td><td>1</td><td>0</td></tr><tr><td>annum</td><td>1</td><td>0</td></tr><tr><td>fetch</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Add Finance</h4><p><span class=\"math-inline\"><img src=\"math/6a517f05661478a7.svg\" alt=\"1+1+1+0=3\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Location</h4><p><span class=\"math-inline\"><img src=\"math/79d13a087a88c477.svg\" alt=\"0+0+0+0=0\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Select</h4><p>3 &gt; 0, so select the financial institution.</p></div><p class=\"answer\"><strong>Answer.</strong> Finance, with score 3 versus 0.</p></div><div class=\"example\"><p><strong>Question. Use Walker scoring for “The fisherman caught bass beside the lake.” Context {fisherman,caught,lake}. The Fish category contains all three clues; the Music category contains none.</strong></p><div class=\"given\"><h4>Given</h4><p>Fish and Music senses, binary category membership given.</p><h4>To find</h4><p>The correct bass sense.</p></div><h4>Formula and why it applies</h4><p>Score = sum of context-category matches.</p><div class=\"step\"><h4>Step 1. Record Fish matches</h4><p>fisherman → 1; caught → 1; lake → 1.</p></div><div class=\"step\"><h4>Step 2. Add Fish score</h4><p><span class=\"math-inline\"><img src=\"math/7e22dbf6b1c68d2b.svg\" alt=\"1+1+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Music score</h4><p><span class=\"math-inline\"><img src=\"math/f4ccd7a1f1f516c9.svg\" alt=\"0+0+0=0\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Choose</h4><p>Fish has the larger score.</p></div><p class=\"answer\"><strong>Answer.</strong> Bass refers to a fish.</p></div><div class=\"example\"><p><strong>Question. Score “The player used a bat in the match.” Context {player,match}. Sport supports both words with weights 2 and 1; Animal supports neither. Use the supplied weighted Walker scheme.</strong></p><div class=\"given\"><h4>Given</h4><p>Sport weights {player:2, match:1}; Animal weights {player:0, match:0}.</p><h4>To find</h4><p>Weighted sense scores.</p></div><h4>Formula and why it applies</h4><p>Use the sum of supplied weights, not an unweighted count, because the question explicitly gives weights.</p><div class=\"step\"><h4>Step 1. Sport contribution of player</h4><p>Add 2.</p></div><div class=\"step\"><h4>Step 2. Sport contribution of match</h4><p>Add 1. Sport total = 2 + 1 = 3.</p></div><div class=\"step\"><h4>Step 3. Animal total</h4><p>0 + 0 = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>3 &gt; 0 selects the sporting implement.</p></div><p class=\"answer\"><strong>Answer.</strong> Bat is the sports implement.</p></div><p class=\"cue\">Walker: dictionary ke exact words nahi, context kis topic/category ko support karta hai woh count.</p>"},{"id":"u5-bayes-steps","title":"Multinomial Naive Bayes: the exact solving method","html":"<p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><h3>Always keep these counts separate</h3><p>Class priors use <strong>number of examples</strong>. Word likelihoods in this multinomial model use <strong>number of word occurrences</strong>. The vocabulary counts <strong>unique words across all classes</strong>.</p><ol><li>List the class examples and calculate priors.</li><li>Write one shared vocabulary and count its size.</li><li>Count total word occurrences in each class.</li><li>Count each query word in each class.</li><li>Apply the given smoothing rule.</li><li>Multiply each prior by all its query likelihoods.</li><li>Compare scores; divide each score by their sum only if a normalized posterior is requested.</li></ol><div class=\"math-display\"><img src=\"math/0fd59effd2bb7926.svg\" alt=\"P(s\\mid C)=\\frac{\\operatorname{score}(s)}{\\sum_{s&#39;}\\operatorname{score}(s&#39;)}.\" style=\"width:25.283ex;height:5.571ex\" loading=\"lazy\" decoding=\"async\"></div><p><strong>Why smoothing is needed:</strong> an unseen clue gives <span class=\"math-inline\"><img src=\"math/5d29fa66aa3ef2ee.svg\" alt=\"0/N_s=0\" style=\"width:9.166ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; one zero makes the whole product zero. Add-one smoothing redistributes probability across every vocabulary word and prevents these zero factors. Use it only when requested, taught for the task, or state the assumption.</p><p><strong>Different model warning:</strong> a Bernoulli Naive Bayes question counts presence/absence per document and may include absence factors. Do not use its denominator in a multinomial word-count question.</p><p class=\"cue\">Pehle sentences se prior; phir words se likelihood; dono counts mix mat kar.</p>"},{"id":"u5-bayes-mam","title":"Mam's bank numerical—every count and every multiplication","html":"<div class=\"example\"><p><strong>Question. Classify the sense of “bank” using the training table below. The sentence is: “As the stream flowed gently past the shore, we set up camp by the bank of the river, discussing the possibility of borrowing a loan to buy a boat for future trips.” Use only the highlighted feature words stream, shore and loan, and add-one multinomial smoothing.</strong></p><div class=\"given\"><h4>Given</h4><table><thead><tr><th>Training row</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>money, deposit, loan</td><td>Finance</td></tr><tr><td>2</td><td>river, water, shore</td><td>Riverbank</td></tr><tr><td>3</td><td>account, savings, investment</td><td>Finance</td></tr><tr><td>4</td><td>boat, river, stream</td><td>Riverbank</td></tr><tr><td>5</td><td>branch, deposit, check</td><td>Finance</td></tr><tr><td>6</td><td>fishing, shore, river</td><td>Riverbank</td></tr></tbody></table><p>Query feature set: {stream, shore, loan}. Other sentence words are not included as features in this supplied example.</p><h4>To find</h4><p>The most probable bank sense and normalized posteriors.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Calculate priors</h4><p>Finance appears in 3 of the 6 rows; Riverbank appears in 3 of 6.</p><div class=\"math-display\"><img src=\"math/2f05aa3a89468f5e.svg\" alt=\"P(F)=\\frac36=\\frac12,\\qquad P(R)=\\frac36=\\frac12.\" style=\"width:37.065ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Construct the vocabulary</h4><p>{money, deposit, loan, river, water, shore, account, savings, investment, boat, stream, fishing, branch, check}. Thus V=14. Repeated deposit or river is counted once in vocabulary.</p></div><div class=\"step\"><h4>Step 3. Count word occurrences per class</h4><p>There are 3 finance rows × 3 words = 9 word occurrences. There are 3 river rows × 3 words = 9. Thus <span class=\"math-inline\"><img src=\"math/2fe9227521f0d9d8.svg\" alt=\"N_F=N_R=9\" style=\"width:13.587ex;height:1.918ex\" loading=\"lazy\" decoding=\"async\"></span>, and each smoothed denominator is <span class=\"math-inline\"><img src=\"math/989b4387cd367e7a.svg\" alt=\"9+14=23\" style=\"width:11.439ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Count the three query words</h4><table><thead><tr><th>Word</th><th>Finance count</th><th>Riverbank count</th></tr></thead><tbody><tr><td>stream</td><td>0</td><td>1</td></tr><tr><td>shore</td><td>0</td><td>2</td></tr><tr><td>loan</td><td>1</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 5. Calculate finance likelihoods</h4><div class=\"math-display\"><img src=\"math/dece6048e91d14ee.svg\" alt=\"P(\\text{stream}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:29.034ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/48b17e3adf6f62bb.svg\" alt=\"P(\\text{shore}\\mid F)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:27.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/622a2e615b1ad17f.svg\" alt=\"P(\\text{loan}\\mid F)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:26.505ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Multiply the finance score</h4><div class=\"math-display\"><img src=\"math/ca9dd31ae9d5dc12.svg\" alt=\"\\operatorname{score}(F)=\\frac12\\times\\frac1{23}\\times\\frac1{23}\\times\\frac2{23}=\\frac1{23^3}=\\frac1{12167}\\approx0.00008219.\" style=\"width:62.975ex;height:4.949ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 7. Calculate river likelihoods</h4><div class=\"math-display\"><img src=\"math/0612a35cf28c3394.svg\" alt=\"P(\\text{stream}\\mid R)=\\frac{1+1}{23}=\\frac2{23}\" style=\"width:29.057ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c71632f8b691648b.svg\" alt=\"P(\\text{shore}\\mid R)=\\frac{2+1}{23}=\\frac3{23}\" style=\"width:27.55ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/bff44b72ce8cc8e7.svg\" alt=\"P(\\text{loan}\\mid R)=\\frac{0+1}{23}=\\frac1{23}\" style=\"width:26.527ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 8. Multiply the river score</h4><div class=\"math-display\"><img src=\"math/665624fd363dd007.svg\" alt=\"\\operatorname{score}(R)=\\frac12\\times\\frac2{23}\\times\\frac3{23}\\times\\frac1{23}=\\frac3{12167}\\approx0.00024657.\" style=\"width:55.735ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 9. Compare scores</h4><p>3/12167 is larger than 1/12167. Riverbank wins even though “loan” is financial evidence: the combined clues matter.</p></div><div class=\"step\"><h4>Step 10. Normalize if a posterior is requested</h4><div class=\"math-display\"><img src=\"math/4b082736e405b96c.svg\" alt=\"P(F\\mid C)=\\frac{1/12167}{4/12167}=\\frac14=0.25\" style=\"width:32.874ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/371000172a7d5f5f.svg\" alt=\"P(R\\mid C)=\\frac{3/12167}{4/12167}=\\frac34=0.75.\" style=\"width:33.525ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Bank is the riverbank sense. Scores are 1/12167 and 3/12167; normalized model posteriors are 0.25 and 0.75.</p></div><p><strong>Without smoothing:</strong> stream and shore are absent in Finance; loan is absent in Riverbank. Both unsmoothed scores become zero, so there is no valid winning class from those products. Also, unnormalized scores should not be labelled as final posterior probabilities.</p><p class=\"cue\">Zero word? Add-one: count+1 upar, total words+vocabulary neeche. Last mein score bada wala sense.</p>"},{"id":"u5-bayes-practice","title":"More WSD numericals: given likelihoods, unequal priors and repeated clues","html":"<div class=\"example\"><p><strong>Question. For bass, let P(Fish)=0.6 and P(Music)=0.4. Given Fish likelihoods P(caught|Fish)=0.5, P(lake|Fish)=0.4 and Music likelihoods P(caught|Music)=0.05, P(lake|Music)=0.1, classify context {caught,lake} and normalize.</strong></p><div class=\"given\"><h4>Given</h4><p>Priors and likelihoods are provided directly; no smoothing or training-count estimation is requested.</p><h4>To find</h4><p>The winning sense and its posterior.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/8414ab183de734ec.svg\" alt=\"\\operatorname{score}(s)=P(s)P(\\text{caught}\\mid s)P(\\text{lake}\\mid s)\" style=\"width:38.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, because the two features are treated as conditionally independent.</p><div class=\"step\"><h4>Step 1. Fish multiplication</h4><p><span class=\"math-inline\"><img src=\"math/115f9e8e47cda84d.svg\" alt=\"0.6\\times0.5=0.3\" style=\"width:14.457ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/99bd356c706eee9f.svg\" alt=\"0.3\\times0.4=0.12\" style=\"width:15.588ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Music multiplication</h4><p><span class=\"math-inline\"><img src=\"math/b1d1c4fd715bfbf9.svg\" alt=\"0.4\\times0.05=0.02\" style=\"width:16.719ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/6ea85a9a0fdfcde1.svg\" alt=\"0.02\\times0.1=0.002\" style=\"width:17.851ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Total evidence</h4><p><span class=\"math-inline\"><img src=\"math/908f94107aa11373.svg\" alt=\"0.12+0.002=0.122\" style=\"width:20.113ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><div class=\"math-display\"><img src=\"math/957c68e55d605895.svg\" alt=\"P(Fish\\mid C)=0.12/0.122\\approx0.983607\" style=\"width:36.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/d8a1b99447a84030.svg\" alt=\"P(Music\\mid C)=0.002/0.122\\approx0.016393.\" style=\"width:40.207ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Fish, with model posterior approximately 0.983607.</p></div><div class=\"example\"><p><strong>Question. Disambiguate bank from the repeated context tokens {loan, loan, river}. Priors are Finance=2/3 and River=1/3. Vocabulary V=4. Finance has N=8 total tokens, loan count 3 and river count 0; River has N=4, loan count 0 and river count 2. Apply add-one smoothing.</strong></p><div class=\"given\"><h4>Given</h4><p>Multinomial counts are supplied. The two appearances of loan must both contribute.</p><h4>To find</h4><p>Scores and normalized Finance posterior.</p></div><h4>Formula and why it applies</h4><p>Naive Bayes selects the sense with the largest prior × likelihood product. The context evidence denominator is identical across candidate senses, so it can be omitted for comparison.</p><div class=\"math-display\"><img src=\"math/1711a8d0c3782b27.svg\" alt=\"\\operatorname{score}(s)=P(s)\\prod_j P(w_j\\mid s).\" style=\"width:28.425ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div><p>For add-one multinomial smoothing:</p><div class=\"math-display\"><img src=\"math/8423df4009ba426a.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}.\" style=\"width:23.731ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/365a4595c962f2f2.svg\" alt=\"C(w,s)\" style=\"width:7.167ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> counts occurrences of word <span class=\"math-inline\"><img src=\"math/5388050eb01d765c.svg\" alt=\"w\" style=\"width:1.62ex;height:1.027ex\" loading=\"lazy\" decoding=\"async\"></span> in training contexts of sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/1d9c73ba4ad13811.svg\" alt=\"N_s\" style=\"width:2.755ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the total number of word occurrences in those contexts; <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> is the shared vocabulary size. It is not the number of training sentences. Repeated query words contribute repeated factors.</p><div class=\"step\"><h4>Step 1. Finance denominator</h4><p><span class=\"math-inline\"><img src=\"math/4dcd6d36e73676fe.svg\" alt=\"8+4=12\" style=\"width:10.308ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/c83ba89d49bb7c55.svg\" alt=\"P(loan\\mid F)=(3+1)/12=1/3\" style=\"width:30.975ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ed4e2c4c1b9881ea.svg\" alt=\"P(river\\mid F)=(0+1)/12=1/12\" style=\"width:32.754ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. River denominator</h4><p><span class=\"math-inline\"><img src=\"math/34a0153bb137796a.svg\" alt=\"4+4=8\" style=\"width:9.176ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/739f9e9752ebca3d.svg\" alt=\"P(loan\\mid R)=(0+1)/8=1/8\" style=\"width:29.867ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/cb1959ca98dd60bb.svg\" alt=\"P(river\\mid R)=(2+1)/8=3/8\" style=\"width:30.514ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Finance product</h4><div class=\"math-display\"><img src=\"math/94333571a54ef7df.svg\" alt=\"\\operatorname{score}(F)=\\frac23\\times\\frac13\\times\\frac13\\times\\frac1{12}=\\frac1{162}\\approx0.00617284.\" style=\"width:51.188ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. River product</h4><div class=\"math-display\"><img src=\"math/ffa63ee974248624.svg\" alt=\"\\operatorname{score}(R)=\\frac13\\times\\frac18\\times\\frac18\\times\\frac38=\\frac1{512}\\approx0.001953125.\" style=\"width:51.21ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Compare and normalize</h4><div class=\"math-display\"><img src=\"math/6e05aa52a40b6b55.svg\" alt=\"P(F\\mid C)=\\frac{1/162}{1/162+1/512}=\\frac{512}{674}=\\frac{256}{337}\\approx0.759644.\" style=\"width:53.856ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p class=\"answer\"><strong>Answer.</strong> Finance wins. Repeated loan contributes a squared likelihood; do not reduce the query to a unique-word set.</p></div><h3>Answer-writing order in an exam</h3><p>Write the class priors, vocabulary size, class token totals, a likelihood table, both score products and the final class. Keep fractions until the comparison where possible. If the question only asks classification, normalization is optional; if it asks posterior probabilities, normalization is required.</p><p class=\"cue\">Repeated word aaye toh factor bhi repeat. Sirf word-set bana diya toh multinomial answer badal jayega.</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-vectors","title":"Representation & similarity","unit":0,"sections":[{"id":"u2-label-onehot","title":"Label and one-hot encoding: three complete examples","html":"<p><strong>Label encoding</strong> assigns each category or word a unique integer ID. <strong>One-hot encoding</strong> assigns a length-<span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> vector with one 1 at the word's vocabulary position and zeros elsewhere.</p><div class=\"math-display\"><img src=\"math/47e78a40b0a5b0bd.svg\" alt=\"\\operatorname{onehot}(w)_j=\\begin{cases}1,&amp;j=\\operatorname{index}(w)\\\\0,&amp;\\text{otherwise.}\\end{cases}\" style=\"width:32.3ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div><p>The index is an ID, not a meaning score. One-hot represents one token/category; a multiword document generally needs multiple token vectors or an aggregation scheme.</p><div class=\"example\"><p><strong>Question. Encode “dog cat dog” using vocabulary [cat,dog,fish], IDs starting at 0. Give label IDs and a one-hot vector for every token.</strong></p><div class=\"given\"><h4>Given</h4><p>cat→0, dog→1, fish→2. Vector columns have the same order.</p><h4>To find</h4><p>The ID sequence and three one-hot rows.</p></div><h4>Formula and why it applies</h4><p>Replace each word by its ID for labels; set its vocabulary position to 1 for one-hot.</p><div class=\"step\"><h4>Step 1. Label IDs</h4><p>dog→1, cat→0, dog→1 → [1,0,1].</p></div><div class=\"step\"><h4>Step 2. First dog</h4><p>[0,1,0].</p></div><div class=\"step\"><h4>Step 3. Cat</h4><p>[1,0,0].</p></div><div class=\"step\"><h4>Step 4. Second dog</h4><p>[0,1,0]. Repeated tokens keep the same representation.</p></div><p class=\"answer\"><strong>Answer.</strong> IDs [1,0,1]; one-hot rows [0,1,0], [1,0,0], [0,1,0].</p></div><div class=\"example\"><p><strong>Question. Encode the city sequence Mumbai, Delhi, Mumbai, Pune using vocabulary [Delhi,Mumbai,Pune] and label IDs starting at 1.</strong></p><div class=\"given\"><h4>Given</h4><p>Delhi→1, Mumbai→2, Pune→3.</p><h4>To find</h4><p>IDs and one-hot rows.</p></div><h4>Formula and why it applies</h4><p>One-hot uses three coordinates regardless of whether label IDs begin at 0 or 1.</p><div class=\"step\"><h4>Step 1. IDs</h4><p>[2,1,2,3].</p></div><div class=\"step\"><h4>Step 2. Mumbai rows</h4><p>Each Mumbai → [0,1,0].</p></div><div class=\"step\"><h4>Step 3. Delhi and Pune</h4><p>Delhi→[1,0,0]; Pune→[0,0,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Rows [0,1,0], [1,0,0], [0,1,0], [0,0,1].</p></div><div class=\"example\"><p><strong>Question. One-hot encode categories [red,green,blue] for a linear regression with an intercept. Then give dummy coding after dropping blue.</strong></p><div class=\"given\"><h4>Given</h4><p>Full column order [red,green,blue]. Blue is the baseline.</p><h4>To find</h4><p>Full and reduced codes.</p></div><h4>Formula and why it applies</h4><p>Full one-hot rows sum to 1. With an intercept this creates a linear dependency; dropping one category column gives k−1 independent dummy indicators.</p><div class=\"step\"><h4>Step 1. Full encoding</h4><table><thead><tr><th>Category</th><th>red</th><th>green</th><th>blue</th></tr></thead><tbody><tr><td>red</td><td>1</td><td>0</td><td>0</td></tr><tr><td>green</td><td>0</td><td>1</td><td>0</td></tr><tr><td>blue</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Drop blue column</h4><table><thead><tr><th>Category</th><th>red</th><th>green</th></tr></thead><tbody><tr><td>red</td><td>1</td><td>0</td></tr><tr><td>green</td><td>0</td><td>1</td></tr><tr><td>blue</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 3. Interpret zero row</h4><p>[0,0] now identifies the baseline blue, not missing data.</p></div><p class=\"answer\"><strong>Answer.</strong> Full width 3; reduced dummy width 2. Dropping a column is model-dependent, not a requirement for every neural embedding input.</p></div><p><strong>Limitations:</strong> one-hot is large and sparse and does not express semantic similarity. Unseen words need a defined unknown-token or vocabulary-update policy. Label IDs are compact but should not be treated as an ordered scalar feature for nominal words.</p><p class=\"cue\">Label = ID number. One-hot = us ID ke box mein 1, baaki 0.</p>"},{"id":"u2-bow","title":"Bag of words and bag of n-grams","html":"<p><strong>Bag of words (BoW) represents a document by the counts of vocabulary terms, discarding their positions.</strong> A binary BoW variant stores only presence/absence; a count BoW stores frequencies. State which is used.</p><div class=\"math-display\"><img src=\"math/b587e59a2f7e4537.svg\" alt=\"x_{d,j}=C(v_j,d).\" style=\"width:14.67ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/8bfe4f4285f4b225.svg\" alt=\"x_{d,j}\" style=\"width:3.418ex;height:1.666ex\" loading=\"lazy\" decoding=\"async\"></span> is document <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>'s coordinate for vocabulary term <span class=\"math-inline\"><img src=\"math/f032d29fd7d0f0b5.svg\" alt=\"v_j\" style=\"width:1.944ex;height:1.668ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/4c241e4d8abb2427.svg\" alt=\"C(v_j,d)\" style=\"width:7.606ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span> is its occurrence count.</p><p>A <strong>bag of n-grams</strong> uses short contiguous token sequences as features. Bigrams can distinguish “not good” from “good”, but increasing n enlarges the vocabulary and creates more rare features.</p><div class=\"example\"><p><strong>Question. Build count and binary BoW for D1=“cat cat dog” and D2=“dog fish”. Use vocabulary [cat,dog,fish] and no stopword removal.</strong></p><div class=\"given\"><h4>Given</h4><p>Two tokenized documents, fixed vocabulary order.</p><h4>To find</h4><p>Count vectors and binary vectors.</p></div><h4>Formula and why it applies</h4><p>Count BoW uses <span class=\"math-inline\"><img src=\"math/4c241e4d8abb2427.svg\" alt=\"C(v_j,d)\" style=\"width:7.606ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>. Binary BoW is 1 when that count is positive and 0 otherwise.</p><div class=\"step\"><h4>Step 1. D1 counts</h4><p>cat=2, dog=1, fish=0 → [2,1,0].</p></div><div class=\"step\"><h4>Step 2. D2 counts</h4><p>cat=0, dog=1, fish=1 → [0,1,1].</p></div><div class=\"step\"><h4>Step 3. Convert to presence</h4><p>D1 [1,1,0]; D2 [0,1,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Count rows [2,1,0], [0,1,1]; binary rows [1,1,0], [0,1,1].</p></div><div class=\"example\"><p><strong>Question. After lowercasing and removing {is,a,means}, obtain BoW vectors for D1=“Continuous learning is learning lifetime”, D2=“Continuous learning means lifetime learning”, D3=“Learning is a good practice”. Use [continuous,good,learning,lifetime,practice].</strong></p><div class=\"given\"><h4>Given</h4><p>Three documents and exact stopword set from the supplied slides.</p><h4>To find</h4><p>The document–term count matrix.</p></div><h4>Formula and why it applies</h4><p>Remove only the listed stopwords, then count every remaining token in the fixed column order.</p><div class=\"step\"><h4>Step 1. Clean D1</h4><p>[continuous,learning,learning,lifetime] → [1,0,2,1,0].</p></div><div class=\"step\"><h4>Step 2. Clean D2</h4><p>[continuous,learning,lifetime,learning] → [1,0,2,1,0].</p></div><div class=\"step\"><h4>Step 3. Clean D3</h4><p>[learning,good,practice] → [0,1,1,0,1].</p></div><div class=\"step\"><h4>Step 4. Compare D1 and D2</h4><p>They have identical BoW vectors despite different original wording/order.</p></div><p class=\"answer\"><strong>Answer.</strong> Rows [1,0,2,1,0], [1,0,2,1,0], [0,1,1,0,1].</p></div><div class=\"example\"><p><strong>Question. Build a bag of bigrams for “not good but not bad” with vocabulary [not good,good but,but not,not bad]. Do not add sentence boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Five tokens; use adjacent pairs, stride 1.</p><h4>To find</h4><p>The bigram count vector.</p></div><h4>Formula and why it applies</h4><p>A sequence of <span class=\"math-inline\"><img src=\"math/c16b65225745dbd1.svg\" alt=\"L\" style=\"width:1.541ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> tokens has <span class=\"math-inline\"><img src=\"math/8c8ba2cc6117f74c.svg\" alt=\"L-1\" style=\"width:5.438ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> adjacent bigrams when no boundaries are added.</p><div class=\"step\"><h4>Step 1. Enumerate pairs</h4><p>(not,good), (good,but), (but,not), (not,bad).</p></div><div class=\"step\"><h4>Step 2. Count each vocabulary bigram</h4><p>Each appears once.</p></div><div class=\"step\"><h4>Step 3. Write vector</h4><p>[1,1,1,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Four bigram features, each with count 1.</p></div><p class=\"cue\">BoW: order bhool, word-count rakh. Bag of bigrams: neighbouring word-pair count.</p>"},{"id":"u2-tfidf","title":"TF–IDF from the exact slide convention","html":"<p><strong>TF–IDF weights a term highly when it is frequent in a particular document but uncommon across the corpus.</strong> The supplied Unit 2 slides use normalized term frequency and base-10 inverse document frequency:</p><div class=\"math-display\"><img src=\"math/deca468dd207619e.svg\" alt=\"\\operatorname{TF}(t,d)=\\frac{C(t,d)}{N_d}\" style=\"width:18.362ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/dd1eb7f26551c5f0.svg\" alt=\"\\operatorname{IDF}(t)=\\log_{10}\\frac{D}{\\operatorname{df}(t)}\" style=\"width:20.345ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c3205280fe205579.svg\" alt=\"\\operatorname{TFIDF}(t,d)=\\operatorname{TF}(t,d)\\operatorname{IDF}(t).\" style=\"width:30.386ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/716cbce384bea429.svg\" alt=\"N_d\" style=\"width:2.836ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the document's token count after the specified preprocessing; <span class=\"math-inline\"><img src=\"math/62ef1c41dad1fbc8.svg\" alt=\"D\" style=\"width:1.873ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is number of documents; <span class=\"math-inline\"><img src=\"math/92f4a76a32f5c806.svg\" alt=\"\\operatorname{df}(t)\" style=\"width:4.676ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of documents containing the term at least once. A word repeated ten times in one document contributes one to document frequency.</p><p><strong>Why the log?</strong> It compresses the ratio's scale. If a term occurs in all documents, <span class=\"math-inline\"><img src=\"math/2d65862ad68e4d56.svg\" alt=\"D/df=1\" style=\"width:9.574ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, so IDF=0 under this unsmoothed convention. Other libraries use smoothed IDF, different TF or normalization. Use the question's formula; do not silently substitute a library default.</p><div class=\"example\"><p><strong>Question. A corpus contains 10 documents. The word model appears in 2 documents and occurs 3 times in a 12-token document. Compute TF, IDF and TF–IDF using the slide convention.</strong></p><div class=\"given\"><h4>Given</h4><p>D=10, df(model)=2, C(model,d)=3, Nd=12; log base 10.</p><h4>To find</h4><p>The TF–IDF weight.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>, then multiply.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/51ccdc5dee01783f.svg\" alt=\"3/12=0.25\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Document ratio</h4><p><span class=\"math-inline\"><img src=\"math/e03ff475f4b9e538.svg\" alt=\"10/2=5\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. IDF</h4><p><span class=\"math-inline\"><img src=\"math/35a02628576f1000.svg\" alt=\"\\log_{10}5\\approx0.698970\" style=\"width:17.752ex;height:2.151ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Weight</h4><p><span class=\"math-inline\"><img src=\"math/f8ed981eba287429.svg\" alt=\"0.25\\times0.698970\\approx0.174743\" style=\"width:26.9ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> TF=0.25, IDF≈0.698970, TF–IDF≈0.174743.</p></div><div class=\"example\"><p><strong>Question. A term occurs 4 times in a 20-token document and is present in all 8 corpus documents. Calculate its TF–IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>C=4, Nd=20, D=8, df=8.</p><h4>To find</h4><p>Its weight under unsmoothed base-10 IDF.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/b0de7a9a9a0c728c.svg\" alt=\"4/20=0.2\" style=\"width:10.433ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. IDF</h4><p><span class=\"math-inline\"><img src=\"math/9a61d3220cb1a861.svg\" alt=\"\\log_{10}(8/8)=\\log_{10}1=0\" style=\"width:23.186ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/97ff1a04375e7994.svg\" alt=\"0.2\\times0=0\" style=\"width:10.937ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Weight 0: this term does not distinguish documents under this convention.</p></div><div class=\"example\"><p><strong>Question. Find TF–IDF vectors for D1=“cat cat dog”, D2=“dog fish”, D3=“cat fish fish”, using [cat,dog,fish], normalized TF and log10 IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>No further preprocessing. Each term occurs in exactly two of the three documents.</p><h4>To find</h4><p>All three vectors.</p></div><h4>Formula and why it applies</h4><p>First count df by documents, then compute each document's TF, then multiply by its term's IDF.</p><div class=\"step\"><h4>Step 1. Common IDF</h4><p><span class=\"math-inline\"><img src=\"math/a912b37fed2477fc.svg\" alt=\"D=3\" style=\"width:6.022ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/8279f303c7e95ae1.svg\" alt=\"df(cat)=df(dog)=df(fish)=2\" style=\"width:33.461ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Each IDF <span class=\"math-inline\"><img src=\"math/fdd435a4274ddcc4.svg\" alt=\"=\\log_{10}(3/2)\\approx0.176091\" style=\"width:23.786ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. D1 term frequencies</h4><p>Length 3 → <span class=\"math-inline\"><img src=\"math/33108c032f375ccc.svg\" alt=\"[2/3,1/3,0]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. D1 weights</h4><p><span class=\"math-inline\"><img src=\"math/a969ee9cc56b474e.svg\" alt=\"[(2/3)0.176091,(1/3)0.176091,0]\\approx[0.117394,0.058697,0]\" style=\"width:56.317ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. D2 weights</h4><p>Length 2; TF <span class=\"math-inline\"><img src=\"math/3a45dfb5933f8388.svg\" alt=\"[0,1/2,1/2]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/42c4ea9d39b355c1.svg\" alt=\"\\approx[0,0.088046,0.088046]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. D3 weights</h4><p>Length 3; TF <span class=\"math-inline\"><img src=\"math/b75534a4556b2589.svg\" alt=\"[1/3,0,2/3]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/f530e35b75352a92.svg\" alt=\"\\approx[0.058697,0,0.117394]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> D1≈[0.117394,0.058697,0]; D2≈[0,0.088046,0.088046]; D3≈[0.058697,0,0.117394].</p></div><p class=\"cue\">TF: iss document mein kitna. IDF: poore corpus mein kitna rare. Dono multiply.</p>"},{"id":"u2-cosine","title":"Cosine: products, lengths and division","html":"<p><strong>Cosine similarity compares the direction of two nonzero vectors.</strong> Multiply matching coordinates and add to obtain the dot product. To obtain each vector's norm, square its coordinates, add them and take a square root.</p><div class=\"math-display\"><img src=\"math/c7fc299613856e1a.svg\" alt=\"\\cos(x,y)=\\frac{\\sum_i x_i y_i}{\\sqrt{\\sum_i x_i^2}\\sqrt{\\sum_i y_i^2}}.\" style=\"width:28.843ex;height:7.518ex\" loading=\"lazy\" decoding=\"async\"></div><p>The vectors must use the same coordinate/vocabulary order. For nonnegative BoW or TF–IDF vectors, the result lies from 0 to 1; for general real-valued vectors, it can range from −1 to 1. A zero vector makes this formula undefined.</p><div class=\"example\"><p><strong>Question. Find cosine similarity for x=[1,1] and y=[1,0].</strong></p><div class=\"given\"><h4>Given</h4><p>Nonzero vectors, matching coordinate order.</p><h4>To find</h4><p>Find cosine similarity for x=[1,1] and y=[1,0].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because direction similarity is required.</p><div class=\"step\"><h4>Step 1. Multiply matching coordinates</h4><p>1 × 1 = 1; 1 × 0 = 0.</p></div><div class=\"step\"><h4>Step 2. Add products</h4><p>1 + 0 = 1.</p></div><div class=\"step\"><h4>Step 3. Length of x</h4><p><span class=\"math-inline\"><img src=\"math/546bd34545f00851.svg\" alt=\"\\sqrt{(1)^2+(1)^2}=\\sqrt{2}.\" style=\"width:19.539ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 4. Length of y</h4><p><span class=\"math-inline\"><img src=\"math/300c6695721d0668.svg\" alt=\"\\sqrt{(1)^2+(0)^2}=\\sqrt{1}.\" style=\"width:19.539ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/70b251889baa0790.svg\" alt=\"\\frac{1}{\\sqrt{2}\\sqrt{1}}\\approx 0.707107.\" style=\"width:17.518ex;height:3.291ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Cosine≈0.707107.</p></div><div class=\"example\"><p><strong>Question. Find cosine similarity for x=[1,2] and y=[2,4].</strong></p><div class=\"given\"><h4>Given</h4><p>Nonzero vectors, matching coordinate order.</p><h4>To find</h4><p>Find cosine similarity for x=[1,2] and y=[2,4].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because direction similarity is required.</p><div class=\"step\"><h4>Step 1. Multiply matching coordinates</h4><p>1 × 2 = 2; 2 × 4 = 8.</p></div><div class=\"step\"><h4>Step 2. Add products</h4><p>2 + 8 = 10.</p></div><div class=\"step\"><h4>Step 3. Length of x</h4><p><span class=\"math-inline\"><img src=\"math/bd2d42d1e7a24550.svg\" alt=\"\\sqrt{(1)^2+(2)^2}=\\sqrt{5}.\" style=\"width:19.539ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 4. Length of y</h4><p><span class=\"math-inline\"><img src=\"math/e6c0085ce3b598a8.svg\" alt=\"\\sqrt{(2)^2+(4)^2}=\\sqrt{20}.\" style=\"width:20.67ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/ce85a11409a92a5a.svg\" alt=\"\\frac{10}{\\sqrt{5}\\sqrt{20}}\\approx 1.000000.\" style=\"width:18.318ex;height:3.291ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Cosine≈1.000000.</p></div><div class=\"example\"><p><strong>Question. Find cosine similarity for x=[1,2,0] and y=[0,1,2].</strong></p><div class=\"given\"><h4>Given</h4><p>Nonzero vectors, matching coordinate order.</p><h4>To find</h4><p>Find cosine similarity for x=[1,2,0] and y=[0,1,2].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/f5ba4ff6b359de70.svg\" alt=\"\\cos(x,y)=(x\\cdot y)/(\\|x\\|\\|y\\|)\" style=\"width:26.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because direction similarity is required.</p><div class=\"step\"><h4>Step 1. Multiply matching coordinates</h4><p>1 × 0 = 0; 2 × 1 = 2; 0 × 2 = 0.</p></div><div class=\"step\"><h4>Step 2. Add products</h4><p>0 + 2 + 0 = 2.</p></div><div class=\"step\"><h4>Step 3. Length of x</h4><p><span class=\"math-inline\"><img src=\"math/8232d196e4629829.svg\" alt=\"\\sqrt{(1)^2+(2)^2+(0)^2}=\\sqrt{5}.\" style=\"width:26.183ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 4. Length of y</h4><p><span class=\"math-inline\"><img src=\"math/7c552c58c81e3b57.svg\" alt=\"\\sqrt{(0)^2+(1)^2+(2)^2}=\\sqrt{5}.\" style=\"width:26.183ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/659dfd20c2e54394.svg\" alt=\"\\frac{2}{\\sqrt{5}\\sqrt{5}}\\approx 0.400000.\" style=\"width:17.518ex;height:3.291ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Cosine≈0.400000.</p></div><p>Proportional vectors [1,2] and [2,4] have cosine 1 but nonzero Euclidean distance. Direction similarity does not require identical magnitudes.</p><p class=\"cue\">Cosine: matching products add upar; dono lengths multiply neeche.</p>"},{"id":"u2-jaccard","title":"Jaccard: intersection, union and distance","html":"<p><strong>Jaccard similarity is the fraction of shared distinct elements among all distinct elements in either set.</strong></p><div class=\"math-display\"><img src=\"math/59eaa3e10117805d.svg\" alt=\"J(A,B)=\\frac{|A\\cap B|}{|A\\cup B|}.\" style=\"width:19.44ex;height:5.471ex\" loading=\"lazy\" decoding=\"async\"></div><p>Intersection means common elements; union means all distinct elements. Repetitions do not count again. Jaccard distance is <span class=\"math-inline\"><img src=\"math/6a1612157fb25e7c.svg\" alt=\"1-J\" style=\"width:5.329ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, not the same quantity as similarity. Two empty sets require a declared convention because the fraction becomes 0/0.</p><div class=\"example\"><p><strong>Question. Find Jaccard similarity and distance for A={cat, dog} and B={dog, fish}.</strong></p><div class=\"given\"><h4>Given</h4><p>Sets contain unique elements.</p><h4>To find</h4><p>Find Jaccard similarity and distance for A={cat, dog} and B={dog, fish}.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/ffa98f175c301d1c.svg\" alt=\"J=|A\\cap B|/|A\\cup B|\" style=\"width:19.953ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/14ba87d96baf7247.svg\" alt=\"d=1-J\" style=\"width:9.523ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Find intersection</h4><p>{dog}; count 1.</p></div><div class=\"step\"><h4>Step 2. Find union</h4><p>{cat, dog, fish}; count 3.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p>J=1/3≈0.333333.</p></div><div class=\"step\"><h4>Step 4. Subtract from one</h4><p>Distance=1−0.333333≈0.666667.</p></div><p class=\"answer\"><strong>Answer.</strong> Similarity≈0.333333; distance≈0.666667.</p></div><div class=\"example\"><p><strong>Question. Find Jaccard similarity and distance for A={red, blue} and B={red, blue}.</strong></p><div class=\"given\"><h4>Given</h4><p>Sets contain unique elements.</p><h4>To find</h4><p>Find Jaccard similarity and distance for A={red, blue} and B={red, blue}.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/ffa98f175c301d1c.svg\" alt=\"J=|A\\cap B|/|A\\cup B|\" style=\"width:19.953ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/14ba87d96baf7247.svg\" alt=\"d=1-J\" style=\"width:9.523ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Find intersection</h4><p>{red, blue}; count 2.</p></div><div class=\"step\"><h4>Step 2. Find union</h4><p>{red, blue}; count 2.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p>J=2/2≈1.000000.</p></div><div class=\"step\"><h4>Step 4. Subtract from one</h4><p>Distance=1−1.000000≈0.000000.</p></div><p class=\"answer\"><strong>Answer.</strong> Similarity≈1.000000; distance≈0.000000.</p></div><div class=\"example\"><p><strong>Question. Find Jaccard similarity and distance for A={apple} and B={orange, pear}.</strong></p><div class=\"given\"><h4>Given</h4><p>Sets contain unique elements.</p><h4>To find</h4><p>Find Jaccard similarity and distance for A={apple} and B={orange, pear}.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/ffa98f175c301d1c.svg\" alt=\"J=|A\\cap B|/|A\\cup B|\" style=\"width:19.953ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/14ba87d96baf7247.svg\" alt=\"d=1-J\" style=\"width:9.523ex;height:1.756ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Find intersection</h4><p>{}; count 0.</p></div><div class=\"step\"><h4>Step 2. Find union</h4><p>{apple, orange, pear}; count 3.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p>J=0/3≈0.000000.</p></div><div class=\"step\"><h4>Step 4. Subtract from one</h4><p>Distance=1−0.000000≈1.000000.</p></div><p class=\"answer\"><strong>Answer.</strong> Similarity≈0.000000; distance≈1.000000.</p></div><p class=\"cue\">Jaccard = common unique ÷ total unique. Distance = 1 minus similarity.</p>"},{"id":"u2-distances","title":"Manhattan, Euclidean and Minkowski: three complete comparisons","html":"<p><strong>Distance measures separation; smaller means closer.</strong> Absolute values prevent positive and negative differences from cancelling.</p><div class=\"math-display\"><img src=\"math/fe89867dfd286879.svg\" alt=\"d_1=\\sum_i|x_i-y_i|\\quad\\text{Manhattan}\" style=\"width:29.996ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/64b5f21c9b008394.svg\" alt=\"d_2=\\sqrt{\\sum_i(x_i-y_i)^2}\\quad\\text{Euclidean}\" style=\"width:32.127ex;height:5.566ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/24cfaa0ff892eddd.svg\" alt=\"d_p=\\left(\\sum_i|x_i-y_i|^p\\right)^{1/p},\\quad p\\ge1\\quad\\text{Minkowski}.\" style=\"width:45.986ex;height:7.367ex\" loading=\"lazy\" decoding=\"async\"></div><p>Manhattan is p=1; Euclidean is p=2. For p=3, cube absolute differences, add, then take a cube root.</p><div class=\"example\"><p><strong>Question. Find Manhattan, Euclidean and Minkowski p=3 distances for x=[1,2], y=[4,6].</strong></p><div class=\"given\"><h4>Given</h4><p>Vectors share coordinate order; negative inputs are allowed.</p><h4>To find</h4><p>Find Manhattan, Euclidean and Minkowski p=3 distances for x=[1,2], y=[4,6].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/52b6164a35837b22.svg\" alt=\"d_1=\\sum|\\Delta_i|\" style=\"width:11.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/182b357a15210739.svg\" alt=\"d_2=\\sqrt{\\sum|\\Delta_i|^2}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/f6e68c062a394495.svg\" alt=\"d_3=\\sqrt[3]{\\sum|\\Delta_i|^3}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Absolute differences</h4><p>|1 − (4)| = 3; |2 − (6)| = 4.</p></div><div class=\"step\"><h4>Step 2. Manhattan</h4><p>3 + 4 = 7.</p></div><div class=\"step\"><h4>Step 3. Square and add</h4><p>3²=9; 4²=16. Sum=25.</p></div><div class=\"step\"><h4>Step 4. Euclidean root</h4><p><span class=\"math-inline\"><img src=\"math/4150d3f3df4a566b.svg\" alt=\"\\sqrt{25}\\approx 5.000000.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Cube and add</h4><p>3³=27; 4³=64. Sum=91.</p></div><div class=\"step\"><h4>Step 6. Minkowski root</h4><p><span class=\"math-inline\"><img src=\"math/3a576bee1de26274.svg\" alt=\"\\sqrt[3]{91}\\approx 4.497941.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Manhattan=7; Euclidean≈5.000000; p=3≈4.497941.</p></div><div class=\"example\"><p><strong>Question. Find Manhattan, Euclidean and Minkowski p=3 distances for x=[0,1,2], y=[2,1,0].</strong></p><div class=\"given\"><h4>Given</h4><p>Vectors share coordinate order; negative inputs are allowed.</p><h4>To find</h4><p>Find Manhattan, Euclidean and Minkowski p=3 distances for x=[0,1,2], y=[2,1,0].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/52b6164a35837b22.svg\" alt=\"d_1=\\sum|\\Delta_i|\" style=\"width:11.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/182b357a15210739.svg\" alt=\"d_2=\\sqrt{\\sum|\\Delta_i|^2}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/f6e68c062a394495.svg\" alt=\"d_3=\\sqrt[3]{\\sum|\\Delta_i|^3}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Absolute differences</h4><p>|0 − (2)| = 2; |1 − (1)| = 0; |2 − (0)| = 2.</p></div><div class=\"step\"><h4>Step 2. Manhattan</h4><p>2 + 0 + 2 = 4.</p></div><div class=\"step\"><h4>Step 3. Square and add</h4><p>2²=4; 0²=0; 2²=4. Sum=8.</p></div><div class=\"step\"><h4>Step 4. Euclidean root</h4><p><span class=\"math-inline\"><img src=\"math/37625b38e47e1914.svg\" alt=\"\\sqrt{8}\\approx 2.828427.\" style=\"width:15.255ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Cube and add</h4><p>2³=8; 0³=0; 2³=8. Sum=16.</p></div><div class=\"step\"><h4>Step 6. Minkowski root</h4><p><span class=\"math-inline\"><img src=\"math/498a102c3a9a2537.svg\" alt=\"\\sqrt[3]{16}\\approx 2.519842.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Manhattan=4; Euclidean≈2.828427; p=3≈2.519842.</p></div><div class=\"example\"><p><strong>Question. Find Manhattan, Euclidean and Minkowski p=3 distances for x=[-1,3], y=[2,-1].</strong></p><div class=\"given\"><h4>Given</h4><p>Vectors share coordinate order; negative inputs are allowed.</p><h4>To find</h4><p>Find Manhattan, Euclidean and Minkowski p=3 distances for x=[-1,3], y=[2,-1].</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/52b6164a35837b22.svg\" alt=\"d_1=\\sum|\\Delta_i|\" style=\"width:11.83ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/182b357a15210739.svg\" alt=\"d_2=\\sqrt{\\sum|\\Delta_i|^2}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/f6e68c062a394495.svg\" alt=\"d_3=\\sqrt[3]{\\sum|\\Delta_i|^3}\" style=\"width:15.125ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Absolute differences</h4><p>|-1 − (2)| = 3; |3 − (-1)| = 4.</p></div><div class=\"step\"><h4>Step 2. Manhattan</h4><p>3 + 4 = 7.</p></div><div class=\"step\"><h4>Step 3. Square and add</h4><p>3²=9; 4²=16. Sum=25.</p></div><div class=\"step\"><h4>Step 4. Euclidean root</h4><p><span class=\"math-inline\"><img src=\"math/4150d3f3df4a566b.svg\" alt=\"\\sqrt{25}\\approx 5.000000.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><div class=\"step\"><h4>Step 5. Cube and add</h4><p>3³=27; 4³=64. Sum=91.</p></div><div class=\"step\"><h4>Step 6. Minkowski root</h4><p><span class=\"math-inline\"><img src=\"math/3a576bee1de26274.svg\" alt=\"\\sqrt[3]{91}\\approx 4.497941.\" style=\"width:16.386ex;height:2.398ex\" loading=\"lazy\" decoding=\"async\"></span></p></div><p class=\"answer\"><strong>Answer.</strong> Manhattan=7; Euclidean≈5.000000; p=3≈4.497941.</p></div><p class=\"cue\">Manhattan: absolute-add. Euclidean: square-add-root. Minkowski: p-power-add-p-root.</p>"},{"id":"u5-distribution","title":"Distributional hypothesis and a co-occurrence matrix","html":"<p><strong>The distributional hypothesis states that words occurring in similar contexts tend to have similar meanings or semantic behaviour.</strong> “Cat” and “dog” often occur near pet, feed and animal. Their context patterns can therefore be represented and compared numerically.</p><p>A <strong>vector</strong> is an ordered list of numbers. Each position must have a fixed meaning. For context order [pet, food, road], cat=[4,3,0] means four co-occurrences with pet, three with food, none with road. A <strong>matrix</strong> stacks vectors as rows in a table.</p><p>A <strong>word–context co-occurrence matrix</strong> records how often a target word occurs with each context word under a specified context definition. A window may be a sentence, document, or a fixed number of neighbouring tokens. State its width, direction and whether targets count themselves.</p><div class=\"flow\"><div class=\"node\">Choose target words</div><span aria-hidden=\"true\">→</span><div class=\"node\">Choose context/window</div><span aria-hidden=\"true\">→</span><div class=\"node\">Count co-occurrences</div><span aria-hidden=\"true\">→</span><div class=\"node\">Store each row as a vector</div><span aria-hidden=\"true\">→</span><div class=\"node\">Compare vectors</div></div><div class=\"example\"><p><strong>Question. Build the symmetric co-occurrence matrix for “cats eat fish” using a window of one token on either side, no self-counts and vocabulary [cats,eat,fish].</strong></p><div class=\"given\"><h4>Given</h4><p>One sentence, one occurrence of each token. Left and right adjacent tokens are contexts.</p><h4>To find</h4><p>A 3×3 target-by-context count matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/e26c85d7637ed303.svg\" alt=\"X_{ij}\" style=\"width:3.272ex;height:2.211ex\" loading=\"lazy\" decoding=\"async\"></span> counts the number of times context word <span class=\"math-inline\"><img src=\"math/7a5268d94266eaaf.svg\" alt=\"j\" style=\"width:0.932ex;height:1.957ex\" loading=\"lazy\" decoding=\"async\"></span> occurs within the chosen window of target <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Target cats</h4><p>Only eat is adjacent. Row cats = [0,1,0].</p></div><div class=\"step\"><h4>Step 2. Target eat</h4><p>cats is left and fish is right. Row eat = [1,0,1].</p></div><div class=\"step\"><h4>Step 3. Target fish</h4><p>Only eat is adjacent. Row fish = [0,1,0].</p></div><div class=\"step\"><h4>Step 4. Assemble the matrix</h4><table><thead><tr><th>Target / context</th><th>cats</th><th>eat</th><th>fish</th></tr></thead><tbody><tr><td>cats</td><td>0</td><td>1</td><td>0</td></tr><tr><td>eat</td><td>1</td><td>0</td><td>1</td></tr><tr><td>fish</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> Rows are [0,1,0], [1,0,1], [0,1,0]. The symmetry follows from the symmetric window.</p></div><div class=\"example\"><p><strong>Question. Build a target–context matrix for sentences “cats eat fish” and “dogs eat fish”. Target words are cats and dogs; context columns [eat,fish]; use the entire sentence excluding the target.</strong></p><div class=\"given\"><h4>Given</h4><p>Each sentence contains one target. Count context token occurrences.</p><h4>To find</h4><p>Two context vectors.</p></div><h4>Formula and why it applies</h4><p>Count each context word in every sentence containing the target.</p><div class=\"step\"><h4>Step 1. Count cats contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 2. Count dogs contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 3. Compare</h4><p>Both targets have identical observed context patterns in this very small corpus.</p></div><p class=\"answer\"><strong>Answer.</strong> cats=[1,1], dogs=[1,1]. This corpus supplies no context evidence to distinguish them.</p></div><div class=\"example\"><p><strong>Question. For “a b a”, use a right-only window of one token. Build the matrix with rows/columns [a,b].</strong></p><div class=\"given\"><h4>Given</h4><p>Count directed target→next-word events, not both directions.</p><h4>To find</h4><p>The co-occurrence matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/584bbdf22ac0ea3c.svg\" alt=\"X_{ij}=C(\\text{target }i\\text{ immediately followed by }j)\" style=\"width:42.914ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. First target a</h4><p>Next token is b → add 1 to X(a,b).</p></div><div class=\"step\"><h4>Step 2. Target b</h4><p>Next token is a → add 1 to X(b,a).</p></div><div class=\"step\"><h4>Step 3. Final a</h4><p>No following token → no addition.</p></div><div class=\"step\"><h4>Step 4. Write matrix</h4><table><thead><tr><th>Target / next</th><th>a</th><th>b</th></tr></thead><tbody><tr><td>a</td><td>0</td><td>1</td></tr><tr><td>b</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> a=[0,1], b=[1,0]. A different context window would produce a different matrix.</p></div><p class=\"cue\">Word ka meaning: uske aas-paas kaunse words kitni baar aaye, uski number-list.</p>"},{"id":"u5-word2vec","title":"Word2Vec: CBOW and skip-gram from training pairs","html":"<p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>"},{"id":"u5-sentence","title":"Word analogies and sentence embeddings","html":"<p><strong>A sentence embedding</strong> represents an entire sentence by one fixed-length vector. A basic method averages word embeddings. More advanced encoders learn a sentence representation from context and task objectives.</p><div class=\"math-display\"><img src=\"math/9bd733523385a6f0.svg\" alt=\"v_{\\text{sentence}}=\\frac1n\\sum_{i=1}^{n}v_{w_i}.\" style=\"width:20.132ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div><p>This means add corresponding coordinates and divide each coordinate by the number of words. Averaging ignores order: “dog bites man” and “man bites dog” have the same average if their words are identical.</p><div class=\"example\"><p><strong>Question. Average the word vectors [1,0], [0,2] and [2,1] to represent a three-word sentence.</strong></p><div class=\"given\"><h4>Given</h4><p>Three two-dimensional vectors with equal weights.</p><h4>To find</h4><p>The two-dimensional sentence vector.</p></div><h4>Formula and why it applies</h4><p>Use coordinate-wise mean <span class=\"math-inline\"><img src=\"math/59b4e5d5faf31ee8.svg\" alt=\"v=(v_1+v_2+v_3)/3\" style=\"width:19.923ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. First coordinate</h4><p><span class=\"math-inline\"><img src=\"math/9e9f60c0d5d4390a.svg\" alt=\"1+0+2=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/96b707212e8196a2.svg\" alt=\"3/3=1\" style=\"width:7.542ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Second coordinate</h4><p><span class=\"math-inline\"><img src=\"math/8658ccf788305270.svg\" alt=\"0+2+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/96b707212e8196a2.svg\" alt=\"3/3=1\" style=\"width:7.542ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Sentence vector = [1,1].</p></div><div class=\"example\"><p><strong>Question. Toy word vectors are king=[3,2], man=[1,0], woman=[1,1]. Find king−man+woman and compare to queen=[3,3].</strong></p><div class=\"given\"><h4>Given</h4><p>All vectors use the same two-coordinate space.</p><h4>To find</h4><p>The analogy vector and its distance from queen.</p></div><h4>Formula and why it applies</h4><p>Vector arithmetic is coordinate by coordinate. Euclidean distance is the square root of the sum of squared coordinate differences.</p><div class=\"step\"><h4>Step 1. Subtract man</h4><p><span class=\"math-inline\"><img src=\"math/b6233b70d329ba84.svg\" alt=\"[3-1,2-0]=[2,2]\" style=\"width:19.864ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Add woman</h4><p><span class=\"math-inline\"><img src=\"math/ad3021d33d70757e.svg\" alt=\"[2+1,2+1]=[3,3]\" style=\"width:19.864ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare with queen</h4><p><span class=\"math-inline\"><img src=\"math/3428ab21f04811a8.svg\" alt=\"\\sqrt{(3-3)^2+(3-3)^2}=0\" style=\"width:24.774ex;height:2.851ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> The toy analogy exactly equals queen. Real learned embeddings only approximate some analogies.</p></div><p><strong>Contextual encoders</strong> can assign “bank” different representations in different sentences. BERT and RoBERTa produce contextual token representations; obtaining strong sentence similarity vectors requires an appropriate pooling/training method, not simply assuming every raw token vector is a sentence embedding. Universal Sentence Encoder is designed to encode sentence-level meaning. Skip-thought predicts surrounding sentences; InferSent learns from natural-language-inference supervision.</p><p class=\"cue\">Sentence average: har column add karo, words ki count se divide. Word order ka loss yaad rakh.</p>"},{"id":"u5-glove-loss","title":"The GloVe objective and numerical interpretation","html":"<div class=\"math-display\"><img src=\"math/2e4b741639de8430.svg\" alt=\"J=\\sum_{i,j:X_{ij}&gt;0}f(X_{ij})\\left(w_i^T\\widetilde w_j+b_i+\\widetilde b_j-\\ln X_{ij}\\right)^2.\" style=\"width:44.641ex;height:6.234ex\" loading=\"lazy\" decoding=\"async\"></div><p><strong>What each piece means:</strong> <span class=\"math-inline\"><img src=\"math/1990ec0f29e8d861.svg\" alt=\"w_i\" style=\"width:2.36ex;height:1.359ex\" loading=\"lazy\" decoding=\"async\"></span> is a target vector; <span class=\"math-inline\"><img src=\"math/57e45239d1931442.svg\" alt=\"\\widetilde w_j\" style=\"width:2.467ex;height:2.415ex\" loading=\"lazy\" decoding=\"async\"></span> is a separate context vector; the dot product estimates their compatibility; biases adjust word-level baselines. The desired score is the natural log of the observed count. Squaring penalizes both positive and negative errors. Weighting prevents unreliable rare pairs or extremely frequent pairs from dominating inappropriately.</p><div class=\"math-display\"><img src=\"math/9889df20ad438723.svg\" alt=\"f(x)=\\begin{cases}(x/x_{\\max})^\\alpha,&amp;0&lt;x&lt;x_{\\max}\\\\1,&amp;x\\ge x_{\\max}.\\end{cases}\" style=\"width:34.679ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div><p>The original commonly used settings are <span class=\"math-inline\"><img src=\"math/d2d81040be91ac39.svg\" alt=\"x_{\\max}=100\" style=\"width:10.87ex;height:1.864ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/57c3b9fea49de9d2.svg\" alt=\"\\alpha=0.75\" style=\"width:8.488ex;height:1.715ex\" loading=\"lazy\" decoding=\"async\"></span>. They are hyperparameters, not learned word embeddings. Zero-count pairs do not require evaluating <span class=\"math-inline\"><img src=\"math/a4450c8290ea350d.svg\" alt=\"\\ln 0\" style=\"width:3.395ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span> in the displayed nonzero-count objective.</p><div class=\"example\"><p><strong>Question. For one nonzero GloVe pair, X=4, weighting f(X)=0.5, target vector [1,2], context vector [0.5,0], and both biases 0. Find its contribution to J.</strong></p><div class=\"given\"><h4>Given</h4><p>Use natural logarithm. Only one pair is being evaluated.</p><h4>To find</h4><p>Weighted squared residual.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/0b9576850c99f85a.svg\" alt=\"J_{ij}=f(X)(w^T\\widetilde w+b+\\widetilde b-\\ln X)^2\" style=\"width:32.335ex;height:2.933ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Dot product</h4><p><span class=\"math-inline\"><img src=\"math/b3e5abe1a60dc7f4.svg\" alt=\"1(0.5)+2(0)=0.5\" style=\"width:18.48ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Log-count target</h4><p><span class=\"math-inline\"><img src=\"math/88f99752ef835c83.svg\" alt=\"\\ln4\\approx1.386294\" style=\"width:14.96ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Residual</h4><p><span class=\"math-inline\"><img src=\"math/51c0d80ff79ed2cd.svg\" alt=\"0.5+0+0-1.386294=-0.886294\" style=\"width:35.323ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Square and weight</h4><p><span class=\"math-inline\"><img src=\"math/faebe1abd20fb32f.svg\" alt=\"(-0.886294)^2\\approx0.785518\" style=\"width:24.62ex;height:2.452ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiply by 0.5 → approximately 0.392759.</p></div><p class=\"answer\"><strong>Answer.</strong> The pair contributes approximately 0.392759 to the objective.</p></div><div class=\"example\"><p><strong>Question. A GloVe pair has X=e², weight 1, dot product 1.5 and biases 0.2 and 0.3. Calculate its objective contribution.</strong></p><div class=\"given\"><h4>Given</h4><p>Natural logarithm, so ln(e²)=2.</p><h4>To find</h4><p>The squared weighted error.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/b1d9328b46f12df0.svg\" alt=\"J_{ij}=f(X)(\\text{dot}+b+\\widetilde b-\\ln X)^2\" style=\"width:31.051ex;height:2.933ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Predicted score</h4><p><span class=\"math-inline\"><img src=\"math/e84d0514f15f7e73.svg\" alt=\"1.5+0.2+0.3=2\" style=\"width:18.354ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Target score</h4><p><span class=\"math-inline\"><img src=\"math/5c3429ffd674bcbd.svg\" alt=\"\\ln(e^2)=2\" style=\"width:9.837ex;height:2.452ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Residual and square</h4><p><span class=\"math-inline\"><img src=\"math/5e9eb71fd28f428c.svg\" alt=\"2-2=0\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/ab6810c2ebb5c0c0.svg\" alt=\"1\\times0^2=0\" style=\"width:10.164ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Contribution 0: this pair is fitted exactly.</p></div><div class=\"example\"><p><strong>Question. Use xmax=100 and α=0.75. A GloVe pair has X=16 and residual 2. Find its weighting and loss contribution.</strong></p><div class=\"given\"><h4>Given</h4><p>16 is below xmax, so use the power branch.</p><h4>To find</h4><p>f(16) and weighted squared residual.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/2307be092fac7a7f.svg\" alt=\"f(16)=(16/100)^{0.75}\" style=\"width:19.864ex;height:2.468ex\" loading=\"lazy\" decoding=\"async\"></span>, and <span class=\"math-inline\"><img src=\"math/aa2cbf1be1ca48e7.svg\" alt=\"J_{ij}=f(16)\\times2^2\" style=\"width:15.823ex;height:2.552ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Ratio</h4><p><span class=\"math-inline\"><img src=\"math/1b290111c4a2b057.svg\" alt=\"16/100=0.16\" style=\"width:13.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Power</h4><p><span class=\"math-inline\"><img src=\"math/4ec2c364222018a7.svg\" alt=\"0.16^{0.75}=0.16^{3/4}\\approx0.252982\" style=\"width:28.247ex;height:2.275ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Square residual</h4><p><span class=\"math-inline\"><img src=\"math/7839fb9a78007523.svg\" alt=\"2^2=4\" style=\"width:6.267ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/5f73059a0e8e07a5.svg\" alt=\"0.252982\\times4\\approx1.011929\" style=\"width:24.009ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> f≈0.252982 and contribution≈1.011929.</p></div><h3>Six steps to explain the algorithm</h3><ol><li>Collect a corpus and choose a context window.</li><li>Build the global co-occurrence matrix.</li><li>Study row-normalized context probabilities and their ratios.</li><li>Define the weighted log-count fitting objective.</li><li>Optimize word/context vectors and biases.</li><li>Use the learned embeddings for similarity, analogy or downstream tasks.</li></ol><p class=\"cue\">GloVe: global counts → log target → dot product prediction → weighted squared error kam karo.</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-applications","title":"Application calculations","unit":0,"sections":[{"id":"classification","title":"Text classification and its full pipeline","html":"<p><strong>Text classification</strong> assigns a document to one or more predefined categories. Spam detection usually uses two classes; news classification may use several topics. In single-label multiclass classification, choose one of several categories. In multilabel classification, several labels may apply to the same document.</p><div class=\"flow\"><div class=\"node\">Define labels</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Prepare labelled examples</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Train representation + model</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evaluate on unseen text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Predict new labels</div></div><h3>An exam-ready pipeline</h3><table><thead><tr><th>Stage</th><th>What you do</th><th>Why it matters</th></tr></thead><tbody><tr><td>Task definition</td><td>Decide what counts as spam or which news topics exist.</td><td>Unclear labels create inconsistent training data.</td></tr><tr><td>Data collection and annotation</td><td>Collect representative examples and assign correct labels.</td><td>The model learns from these examples.</td></tr><tr><td>Split data</td><td>Separate training, validation and test data.</td><td>Test examples must not influence training choices.</td></tr><tr><td>Preprocess</td><td>Tokenize and normalise where suitable; retain meaningful negation.</td><td>Reduce irrelevant variation without deleting signal.</td></tr><tr><td>Represent</td><td>Use BoW, TF-IDF or learned embeddings.</td><td>Models need numerical features.</td></tr><tr><td>Train</td><td>Fit Naive Bayes, logistic regression or another appropriate model.</td><td>Learn how features predict categories.</td></tr><tr><td>Evaluate</td><td>Measure relevant precision, recall and F1 on held-out examples.</td><td>Accuracy alone may hide poor minority-class performance.</td></tr><tr><td>Deploy and monitor</td><td>Apply the same preprocessing and monitor changing language.</td><td>Incoming data can differ from old examples.</td></tr></tbody></table><p>Naive Bayes is especially useful for hand calculations. With a bag-of-words representation, its class score is the prior multiplied by the conditional probability of each token; repeated tokens repeat the factor. The “naive” assumption is conditional independence of features given the class, not that words are independent in real language.</p><div class=\"math-display\"><img src=\"math/6dd9b21835eaff13.svg\" alt=\"s(c)=P(c)\\prod_{w\\in V}P(w\\mid c)^{C(w,d)}\" style=\"width:28.469ex;height:4.928ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>C(w,d) counts word w in document d. C(w,c) counts it in training documents belonging to class c. N<sub>c</sub> is the total token count for class c. Add-one smoothing adds one to every vocabulary count and therefore adds |V| to the denominator. This is the same arithmetic taught for WSD, with document classes instead of senses.</p><section class=\"example\"><h3>Worked classification · two-token message</h3><p class=\"question\">A spam classifier has vocabulary {win, prize, meeting}. Priors are P(spam)=P(ham)=0.5. Spam token counts are [3,2,0]; ham counts are [0,0,5]. With add-one smoothing, classify “win prize”.</p><div class=\"given\"><strong>Given</strong><p>|V|=3; N(spam)=5; N(ham)=5; message has win once and prize once.</p><strong>To find</strong><p>Class scores and predicted label.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/81645a009f312045.svg\" alt=\"s(c)=P(c)P(\\text{win}\\mid c)P(\\text{prize}\\mid c)\" style=\"width:32.21ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>The model is multinomial Naive Bayes; multiply the two token likelihoods and the class prior.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compute the smoothed denominators</h4><div class=\"math-display\"><img src=\"math/7e931d91ea22e68e.svg\" alt=\"5+3=8\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Compute spam likelihoods</h4><div class=\"math-display\"><img src=\"math/724a47033195de19.svg\" alt=\"P(\\text{win}\\mid S)=\\frac{3+1}{8}=\\frac12\" style=\"width:24.509ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fc2cdb5225a070b5.svg\" alt=\"P(\\text{prize}\\mid S)=\\frac{2+1}{8}=\\frac38\" style=\"width:25.772ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute ham likelihoods</h4><div class=\"math-display\"><img src=\"math/4134fa5958e2a1ed.svg\" alt=\"P(\\text{win}\\mid H)=P(\\text{prize}\\mid H)=\\frac{0+1}{8}=\\frac18\" style=\"width:40.213ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Multiply the spam score</h4><div class=\"math-display\"><img src=\"math/79f02eee2a0a5ddb.svg\" alt=\"s(S)=\\frac12\\times\\frac12\\times\\frac38=\\frac{3}{32}=0.09375\" style=\"width:35.918ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Multiply the ham score</h4><div class=\"math-display\"><img src=\"math/05ad87647bbe0b7d.svg\" alt=\"s(H)=\\frac12\\times\\frac18\\times\\frac18=\\frac{1}{128}=0.0078125\" style=\"width:39.861ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Compare</h4><p>0.09375 > 0.0078125. These are unnormalised scores; the label is chosen by the larger score.</p></div><div class=\"answer\">Predicted label: spam.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Class prior × har word ki class-likelihood; sabse bada score wins.</p></section>"},{"id":"evaluation","title":"Precision, recall, F1 and accuracy","html":"<p>Evaluation compares predicted results with known answers. A <strong>true positive</strong> is a correctly predicted positive; a <strong>false positive</strong> is a negative item predicted positive; a <strong>false negative</strong> is a missed positive; a <strong>true negative</strong> is a correctly rejected negative.</p><div class=\"math-display\"><img src=\"math/d9fa10a04601a634.svg\" alt=\"\\text{Precision}=\\frac{TP}{TP+FP}\" style=\"width:22.439ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/65330df51cf428ee.svg\" alt=\"\\text{Recall}=\\frac{TP}{TP+FN}\" style=\"width:19.837ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fa461c3c89d25a66.svg\" alt=\"F_1=\\frac{2PR}{P+R}=\\frac{2TP}{2TP+FP+FN}\" style=\"width:33.701ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c35bcbb3c320de01.svg\" alt=\"\\text{Accuracy}=\\frac{TP+TN}{TP+TN+FP+FN}\" style=\"width:35.482ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Precision asks how many predicted positives were correct. Recall asks how many actual positives were found. F1 balances them by a harmonic mean. If a denominator is zero, state the convention rather than dividing by zero.</p><section class=\"example\"><h3>Example 1 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=6, FP=2, FN=4, TN=8. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=6; FP=2; FN=4; TN=8.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/16635e3dc332a6fb.svg\" alt=\"P=\\frac{6}{6+2}=0.750000\" style=\"width:22.304ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/a1b816258848d9dc.svg\" alt=\"R=\\frac{6}{6+4}=0.600000\" style=\"width:22.323ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/2de5ef4a0ac69e0e.svg\" alt=\"F_1=\\frac{12}{12+2+4}=0.666667\" style=\"width:28.076ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/8934313942e2b516.svg\" alt=\"A=\\frac{6+8}{6+2+4+8}=0.700000\" style=\"width:30.096ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 0.7500; recall 0.6000; F1 0.6667; accuracy 0.7000.</div></section><section class=\"example\"><h3>Example 2 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=9, FP=3, FN=1, TN=7. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=9; FP=3; FN=1; TN=7.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/97b392f1812900f2.svg\" alt=\"P=\\frac{9}{9+3}=0.750000\" style=\"width:22.304ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/eec2430e01f99107.svg\" alt=\"R=\\frac{9}{9+1}=0.900000\" style=\"width:22.323ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/b58f8dd0b3cf6f35.svg\" alt=\"F_1=\\frac{18}{18+3+1}=0.818182\" style=\"width:28.076ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/df21b30335e9b090.svg\" alt=\"A=\\frac{9+7}{9+3+1+7}=0.800000\" style=\"width:30.096ex;height:4.796ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 0.7500; recall 0.9000; F1 0.8182; accuracy 0.8000.</div></section><section class=\"example\"><h3>Example 3 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=4, FP=0, FN=4, TN=12. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=4; FP=0; FN=4; TN=12.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/f133094efa30d271.svg\" alt=\"P=\\frac{4}{4+0}=1.000000\" style=\"width:22.304ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/656d499e455af020.svg\" alt=\"R=\\frac{4}{4+4}=0.500000\" style=\"width:22.323ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/a2397b5600ed6ed2.svg\" alt=\"F_1=\\frac{8}{8+0+4}=0.666667\" style=\"width:26.945ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/1cc17a482eb72469.svg\" alt=\"A=\\frac{4+12}{4+0+4+12}=0.800000\" style=\"width:31.227ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 1.0000; recall 0.5000; F1 0.6667; accuracy 0.8000.</div></section>"},{"id":"spelling","title":"Spelling correction and edit distance","html":"<p><strong>Spelling correction</strong> proposes the intended word or sentence when the observed text contains an error. A non-word error produces an invalid vocabulary item (“recieve”); a real-word error produces an existing word in the wrong context (“I will meat you”). Dictionary lookup can detect many non-words but cannot reliably detect real-word errors.</p><div class=\"flow\"><div class=\"node\">Detect suspicious text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Generate candidates</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Score edit + context fit</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose correction</div></div><h3>Minimum edit distance</h3><p>Levenshtein distance is the minimum total cost of insertions, deletions and substitutions needed to transform one string into another. In the examples below, each edit costs 1; matching characters cost 0. Transposition is not a single Levenshtein operation. State different costs explicitly if the question gives them.</p><div class=\"math-display\"><img src=\"math/ef2777a0390860c8.svg\" alt=\"D(i,j)=\\min\\begin{cases}D(i-1,j)+1\\\\D(i,j-1)+1\\\\D(i-1,j-1)+[a_i\\ne b_j]\\end{cases}\" style=\"width:40.47ex;height:7.792ex\" loading=\"lazy\" decoding=\"async\"></div><p>Rows represent prefixes of the source; columns represent prefixes of the target. D(i,j) is the best cost for transforming the first i source characters to the first j target characters. Initialise D(i,0)=i and D(0,j)=j. The three choices are deletion, insertion and diagonal match/substitution.</p><section class=\"example\"><h3>Example 1 · cat → cut</h3><p class=\"question\">Calculate the unit-cost Levenshtein distance from “cat” to “cut”. Show the dynamic-programming table.</p><div class=\"given\"><strong>Given</strong><p>Source=cat; target=cut; insertion=deletion=substitution=1; match=0.</p><strong>To find</strong><p>Minimum edit cost.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/dbb6791fed13f314.svg\" alt=\"D(i,j)=\\min(D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+c)\" style=\"width:63.097ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>c = 0 for matching characters, 1 otherwise. Compare all three possible ways to reach each cell.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise empty prefixes</h4><p>First row counts insertions; first column counts deletions.</p></div><div class=\"step\"><h4>Step 2. Fill row 1: source character “c”</h4><div class=\"math-display\"><img src=\"math/715c07a4ab771469.svg\" alt=\"D(1,1)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0ab677a634f01ae0.svg\" alt=\"D(1,2)=\\min(2+1,\\ 0+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a0d37091a67b769a.svg\" alt=\"D(1,3)=\\min(3+1,\\ 1+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Fill row 2: source character “a”</h4><div class=\"math-display\"><img src=\"math/132b0bf994fa1fe9.svg\" alt=\"D(2,1)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/26524a35ae995b95.svg\" alt=\"D(2,2)=\\min(1+1,\\ 1+1,\\ 0+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/ef96295cbb47c0f8.svg\" alt=\"D(2,3)=\\min(2+1,\\ 1+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Fill row 3: source character “t”</h4><div class=\"math-display\"><img src=\"math/d443351dab39e649.svg\" alt=\"D(3,1)=\\min(1+1,\\ 3+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0d6484992af2f005.svg\" alt=\"D(3,2)=\\min(1+1,\\ 2+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/725867dfbce579ce.svg\" alt=\"D(3,3)=\\min(2+1,\\ 2+1,\\ 1+0)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Read the completed matrix</h4><table><thead><tr><th>Source / target</th><th>∅</th><th>c</th><th>u</th><th>t</th></tr></thead><tbody><tr><td>∅</td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td>c</td><td>1</td><td>0</td><td>1</td><td>2</td></tr><tr><td>a</td><td>2</td><td>1</td><td>1</td><td>2</td></tr><tr><td>t</td><td>3</td><td>2</td><td>2</td><td>1</td></tr></tbody></table></div><div class=\"answer\">Minimum edit distance = 1.</div></section><section class=\"example\"><h3>Example 2 · at → cat</h3><p class=\"question\">Calculate the unit-cost Levenshtein distance from “at” to “cat”. Show the dynamic-programming table.</p><div class=\"given\"><strong>Given</strong><p>Source=at; target=cat; insertion=deletion=substitution=1; match=0.</p><strong>To find</strong><p>Minimum edit cost.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/dbb6791fed13f314.svg\" alt=\"D(i,j)=\\min(D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+c)\" style=\"width:63.097ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>c = 0 for matching characters, 1 otherwise. Compare all three possible ways to reach each cell.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise empty prefixes</h4><p>First row counts insertions; first column counts deletions.</p></div><div class=\"step\"><h4>Step 2. Fill row 1: source character “a”</h4><div class=\"math-display\"><img src=\"math/e16686e02e9f18c0.svg\" alt=\"D(1,1)=\\min(1+1,\\ 1+1,\\ 0+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a6adb2bfe71ef208.svg\" alt=\"D(1,2)=\\min(2+1,\\ 1+1,\\ 1+0)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a0d37091a67b769a.svg\" alt=\"D(1,3)=\\min(3+1,\\ 1+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Fill row 2: source character “t”</h4><div class=\"math-display\"><img src=\"math/a3ee153834d01ea4.svg\" alt=\"D(2,1)=\\min(1+1,\\ 2+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/7cf9b393d47f5d6d.svg\" alt=\"D(2,2)=\\min(1+1,\\ 2+1,\\ 1+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/ccb8721250bf5a16.svg\" alt=\"D(2,3)=\\min(2+1,\\ 2+1,\\ 1+0)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Read the completed matrix</h4><table><thead><tr><th>Source / target</th><th>∅</th><th>c</th><th>a</th><th>t</th></tr></thead><tbody><tr><td>∅</td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td>a</td><td>1</td><td>1</td><td>1</td><td>2</td></tr><tr><td>t</td><td>2</td><td>2</td><td>2</td><td>1</td></tr></tbody></table></div><div class=\"answer\">Minimum edit distance = 1.</div></section><section class=\"example\"><h3>Example 3 · cats → cat</h3><p class=\"question\">Calculate the unit-cost Levenshtein distance from “cats” to “cat”. Show the dynamic-programming table.</p><div class=\"given\"><strong>Given</strong><p>Source=cats; target=cat; insertion=deletion=substitution=1; match=0.</p><strong>To find</strong><p>Minimum edit cost.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/dbb6791fed13f314.svg\" alt=\"D(i,j)=\\min(D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+c)\" style=\"width:63.097ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>c = 0 for matching characters, 1 otherwise. Compare all three possible ways to reach each cell.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Initialise empty prefixes</h4><p>First row counts insertions; first column counts deletions.</p></div><div class=\"step\"><h4>Step 2. Fill row 1: source character “c”</h4><div class=\"math-display\"><img src=\"math/715c07a4ab771469.svg\" alt=\"D(1,1)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/0ab677a634f01ae0.svg\" alt=\"D(1,2)=\\min(2+1,\\ 0+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/a0d37091a67b769a.svg\" alt=\"D(1,3)=\\min(3+1,\\ 1+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Fill row 2: source character “a”</h4><div class=\"math-display\"><img src=\"math/132b0bf994fa1fe9.svg\" alt=\"D(2,1)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/7acd2ee646c6109c.svg\" alt=\"D(2,2)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/e9bf43ed11bd7fac.svg\" alt=\"D(2,3)=\\min(2+1,\\ 0+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Fill row 3: source character “t”</h4><div class=\"math-display\"><img src=\"math/d443351dab39e649.svg\" alt=\"D(3,1)=\\min(1+1,\\ 3+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/b374d7c3144e3404.svg\" alt=\"D(3,2)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/24fd76b9544c3db3.svg\" alt=\"D(3,3)=\\min(1+1,\\ 1+1,\\ 0+0)=0\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Fill row 4: source character “s”</h4><div class=\"math-display\"><img src=\"math/0dd1d63ad4a25f3e.svg\" alt=\"D(4,1)=\\min(2+1,\\ 4+1,\\ 3+1)=3\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/cff6b6d394377532.svg\" alt=\"D(4,2)=\\min(1+1,\\ 3+1,\\ 2+1)=2\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/f23dc80f45d4021b.svg\" alt=\"D(4,3)=\\min(0+1,\\ 2+1,\\ 1+1)=1\" style=\"width:37.827ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Read the completed matrix</h4><table><thead><tr><th>Source / target</th><th>∅</th><th>c</th><th>a</th><th>t</th></tr></thead><tbody><tr><td>∅</td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td>c</td><td>1</td><td>0</td><td>1</td><td>2</td></tr><tr><td>a</td><td>2</td><td>1</td><td>0</td><td>1</td></tr><tr><td>t</td><td>3</td><td>2</td><td>1</td><td>0</td></tr><tr><td>s</td><td>4</td><td>3</td><td>2</td><td>1</td></tr></tbody></table></div><div class=\"answer\">Minimum edit distance = 1.</div></section><h3>Noisy-channel correction</h3><div class=\"math-display\"><img src=\"math/3ede23f6f61aee5c.svg\" alt=\"\\hat w=\\arg\\max_w P(x\\mid w)P(w)\" style=\"width:26.089ex;height:3.461ex\" loading=\"lazy\" decoding=\"async\"></div><p>x is the observed misspelling and w a candidate intended word. P(x | w) is the error-model likelihood; P(w) is the language-model prior. In context, replace the isolated-word prior with an appropriate contextual probability. A frequent word with a plausible typo may beat a rarer candidate, but context can reverse the ranking.</p><section class=\"example\"><h3>Candidate ranking</h3><p class=\"question\">For observed “teh”, candidate “the” has prior 0.05 and error likelihood 0.02. Candidate “ten” has prior 0.01 and likelihood 0.01. Select the intended word.</p><div class=\"given\"><strong>Given</strong><p>Two candidates and their prior/error-model likelihoods are supplied.</p><strong>To find</strong><p>Largest noisy-channel score.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/c03956cd222f4789.svg\" alt=\"s(w)=P(x\\mid w)P(w)\" style=\"width:20.797ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply likelihood by prior; the same evidence normaliser is irrelevant to ranking.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Score the</h4><div class=\"math-display\"><img src=\"math/0057723bfc328243.svg\" alt=\"s(\\text{the})=0.02\\times0.05=0.001\" style=\"width:27.963ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Score ten</h4><div class=\"math-display\"><img src=\"math/ef19fb34efc392f6.svg\" alt=\"s(\\text{ten})=0.01\\times0.01=0.0001\" style=\"width:29.094ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compare</h4><p>0.001 is ten times 0.0001.</p></div><div class=\"answer\">Choose “the”.</div></section>"},{"id":"retrieval","title":"Information retrieval","html":"<p><strong>Information retrieval (IR)</strong> locates and ranks items relevant to an information need, usually expressed as a query. The collection may contain documents, product descriptions or scientific papers. Retrieval estimates relevance; it does not itself establish that every retrieved claim is true.</p><div class=\"flow\"><div class=\"node\">Documents → cleaning</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Build index</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Query → same representation</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match & rank</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Return relevant results</div></div><h3>The inverted index</h3><p>An inverted index maps a term to the documents containing it, often with positions or counts. For D1 “cats drink milk” and D2 “dogs drink water”, the posting list for drink is {D1,D2}, while milk maps only to D1. This avoids rescanning every document for every query.</p><table><thead><tr><th>Term</th><th>Posting list</th></tr></thead><tbody><tr><td>cats</td><td>D1</td></tr><tr><td>drink</td><td>D1, D2</td></tr><tr><td>milk</td><td>D1</td></tr><tr><td>dogs</td><td>D2</td></tr><tr><td>water</td><td>D2</td></tr></tbody></table><h3>Matching and ranking</h3><p>Boolean retrieval combines term membership using AND, OR and NOT. Vector-space retrieval represents documents and queries as weighted vectors, for example with TF-IDF, and compares them with cosine similarity. Learned retrieval can use dense embeddings for meaning-based matching. The representation used at query time must be compatible with the document index.</p><h3>Search engines and recommendation</h3><p>A search engine receives an explicit query and ranks matching indexed pages. A recommender may derive an implicit query from a user’s liked items or profile and retrieve similar candidates. Both require candidate retrieval and ranking, but the source of the information need differs.</p><h3>Evaluate the results</h3><p>For retrieval, TP is the number of retrieved relevant documents, FP retrieved irrelevant documents, and FN relevant documents not retrieved. Precision and recall use the same formulas as classification. Ranking measures also consider the positions of relevant items; a relevant result at rank 1 is more useful than one far below.</p><section class=\"example\"><h3>Retrieval evaluation</h3><p class=\"question\">A search system retrieves 8 documents; 6 are relevant. There are 10 relevant documents in the collection. Find precision, recall and F1.</p><div class=\"given\"><strong>Given</strong><p>Retrieved=8; relevant retrieved=6; all relevant=10.</p><strong>To find</strong><p>P, R and F1.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/58a11f3930a42815.svg\" alt=\"P=\\frac{\\text{relevant retrieved}}{\\text{retrieved}},\\quad R=\\frac{\\text{relevant retrieved}}{\\text{all relevant}}\" style=\"width:49.316ex;height:4.676ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4743421649dff6a6.svg\" alt=\"F_1=\\frac{2PR}{P+R}\" style=\"width:12.637ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>The denominator is 8 for precision and 10 for recall because they ask different questions.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the confusion counts</h4><p>TP=6; FP=8−6=2; FN=10−6=4.</p></div><div class=\"step\"><h4>Step 2. Precision</h4><div class=\"math-display\"><img src=\"math/6a30a7f6694209de.svg\" alt=\"P=\\frac68=0.75\" style=\"width:13.883ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Recall</h4><div class=\"math-display\"><img src=\"math/402ac41b5040dfdd.svg\" alt=\"R=\\frac6{10}=0.6\" style=\"width:13.901ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. F1</h4><div class=\"math-display\"><img src=\"math/aedd722bd9955777.svg\" alt=\"F_1=\\frac{2(0.75)(0.6)}{0.75+0.6}=\\frac{0.9}{1.35}=\\frac23\\approx0.666667\" style=\"width:42.764ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision=0.75, recall=0.60, F1≈0.666667.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Precision: jo laaye, unmein kitne sahi? Recall: jo sahi the, unmein kitne laaye?</p>"}],"scope":"Formulas explained through full worked examples"},{"id":"f-deep-u3-smoothing-extensions","title":"Faculty topics: interpolation and Stupid Backoff","unit":3,"mode":"tee","order":100,"scope":"Unit 3 PDF p147 names these methods. Neither supplied TEE paper asks their numerical calculation; the worked values below are authored examples.","sections":[{"id":"interpolation","title":"N-gram interpolation: weighted evidence from several histories","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 3 PDF p147 names these methods. Neither supplied TEE paper asks their numerical calculation; the worked values below are authored examples.</p><p><strong>Interpolation combines several context lengths for every prediction.</strong> A trigram estimate is specific but may have little evidence. Bigram and unigram estimates use less context and can support unseen longer sequences. A weighted mixture combines their information.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/402b0524fed55b5a.svg\" alt=\"P_{\\mathrm{mix}}(w\\mid u,v)=\\lambda_3P(w\\mid u,v)+\\lambda_2P(w\\mid v)+\\lambda_1P(w)\" style=\"width:51.898ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/934ad91d11cebd33.svg\" alt=\"\\lambda_1,\\lambda_2,\\lambda_3\\ge0,\\qquad\\lambda_1+\\lambda_2+\\lambda_3=1.\" style=\"width:35.84ex;height:2.009ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Each component must be a normalized distribution over the same vocabulary. Then summing the mixture over all possible words gives λ₁+λ₂+λ₃=1. A zero higher-order count can be rescued by positive lower-order evidence. Unlike simple backoff, interpolation can combine all levels even when the trigram was seen.</p><section class=\"example\"><p class=\"question\"><strong>Question. For predicting tea after I like, suppose trigram, bigram and unigram probabilities are 0, 0.2 and 0.1. Use weights λ₃=0.5, λ₂=0.3 and λ₁=0.2 to calculate the interpolated probability. Repeat for coffee with probabilities 0.4, 0.1 and 0.05. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>The three distributions use one vocabulary. Nonnegative weights sum to 1. These are supplied probabilities; no count estimation is needed.</p><h4>To find</h4><p>Pmix(tea | I,like) and Pmix(coffee | I,like).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fbe778721993c743.svg\" alt=\"P_{mix}=\\lambda_3P_3+\\lambda_2P_2+\\lambda_1P_1\" style=\"width:27.301ex;height:1.945ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>We add weighted alternatives from models, rather than multiply sequential word events.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Check the weights</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3e929c377d815fdc.svg\" alt=\"0.5+0.3+0.2=1.\" style=\"width:18.983ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the three tea contributions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/226058093bf8c6aa.svg\" alt=\"0.5(0)=0,\\qquad0.3(0.2)=0.06,\\qquad0.2(0.1)=0.02.\" style=\"width:50.787ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add the tea contributions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b1c5370fd614e492.svg\" alt=\"P_{mix}(tea)=0+0.06+0.02=0.08.\" style=\"width:34.734ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate the coffee contributions</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4318d6a3e52440bd.svg\" alt=\"0.5(0.4)=0.20,\\qquad0.3(0.1)=0.03,\\qquad0.2(0.05)=0.01.\" style=\"width:56.57ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Add and compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/538b559c97ffd180.svg\" alt=\"P_{mix}(coffee)=0.20+0.03+0.01=0.24.\" style=\"width:41.231ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Coffee gets three times tea’s probability in this model. Other vocabulary outcomes carry the remaining mass; these two displayed entries are not the whole distribution.</p></div><div class=\"answer\"><strong>Final answer.</strong> Tea=0.08 and coffee=0.24. A zero trigram probability does not force a zero mixture.</div></section><p><strong>Yaad rakho:</strong> Interpolation = sab context-lengths ka weighted mix. Word-sequence product aur model-mixture sum alag operations hain.</p>"},{"id":"stupid-backoff","title":"Backoff and the important score-versus-probability distinction","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 3 PDF p147 names these methods. Neither supplied TEE paper asks their numerical calculation; the worked values below are authored examples.</p><p><strong>Backoff uses a shorter history when the longer-history estimate lacks evidence.</strong> A properly normalized backoff model discounts some seen-event probability and allocates the remaining mass across unseen continuations using lower-order probabilities and normalization factors.</p><p><strong>Stupid Backoff</strong> is a specifically named efficient scoring method in the slides’ list. It uses an observed n-gram relative frequency when available; otherwise it multiplies the shorter-history score by a fixed penalty, commonly 0.4. Its output is generally an <strong>unnormalized score</strong>, not a conditional probability distribution. Do not insert raw Stupid Backoff scores into standard probability-based perplexity and call the result a normalized-model perplexity.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/55b65d9f12d95541.svg\" alt=\"S(w\\mid h)=\\begin{cases}C(h,w)/C(h),&amp;C(h,w)&gt;0\\\\ \\alpha S(w\\mid h&#39;),&amp;C(h,w)=0.\\end{cases}\" style=\"width:41.143ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Here h′ drops the oldest history word; α is the backoff penalty. At the unigram base, use C(w)/N. The letter α here is a penalty, not the forward-HMM variable introduced later.</p><section class=\"example\"><p class=\"question\"><strong>Question. A bigram scorer has complete vocabulary {a,b}. After h, C(h,a)=2 and C(h,b)=0. The unigram probabilities are P(a)=P(b)=0.5. Apply Stupid Backoff with penalty 0.4 and show whether the scores form a normalized row. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>C(h)=2. The a bigram is observed; the b bigram is unseen. Unigram probabilities are supplied.</p><h4>To find</h4><p>S(a|h), S(b|h), their sum, and whether they are probabilities.</p></div><h4>Formula and why it applies</h4><p>Use relative frequency for an observed pair and α times the unigram base for an unseen pair. The method does not discount a’s observed score in this example.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Score the observed pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/84f0ae8328abe0b8.svg\" alt=\"S(a\\mid h)=2/2=1.\" style=\"width:18.793ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Back off for the unseen pair</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0aa2b77f15f8a15c.svg\" alt=\"S(b\\mid h)=0.4(0.5)=0.2.\" style=\"width:24.477ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Add the complete row</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6d9f4f0a09441a66.svg\" alt=\"1+0.2=1.2\\ne1.\" style=\"width:17.474ex;height:2.106ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Interpret the failure of normalization</h5><p>The scores can rank a above b, but the raw row cannot be called a probability distribution. Merely labelling the method “smoothing” does not change this.</p></div><div class=\"answer\"><strong>Final answer.</strong> Scores are 1 and 0.2; their sum is 1.2. They are useful ranking scores under this rule, not normalized probabilities.</div></section><div class=\"table-wrap\"><table><thead><tr><th>Method</th><th>Operation</th><th>Normalization</th></tr></thead><tbody><tr><td>Add-one/add-k</td><td>Adjust all allowed outcome counts and the total</td><td>Normalized with a fixed vocabulary</td></tr><tr><td>Interpolation</td><td>Mix normalized distributions using nonnegative weights summing to 1</td><td>Normalized</td></tr><tr><td>Normalized backoff</td><td>Discount seen events and distribute remaining mass over unseen events</td><td>Normalized when its factors are correctly computed</td></tr><tr><td>Stupid Backoff</td><td>Keep seen relative frequencies; penalize shorter-history scores for unseen n-grams</td><td>Generally not normalized</td></tr></tbody></table></div><p>Scope: Unit 3 slide 147 lists Stupid Backoff and n-gram interpolation; the class calculations emphasize Laplace. These short worked extensions explain the listed methods without claiming extra official exam weight.</p>"}]},{"id":"f-deep-u4-forward-cky","title":"Faculty topic: CNF and CYK / CKY parsing","unit":4,"mode":"tee","order":100,"scope":"Unit 4 PDF p105 names CYK. The supplied papers ask top-down / bottom-up CFG trees, not CKY charts. These traces explain the taught topic.","sections":[{"id":"cnf","title":"Prepare a grammar for CYK / CKY","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 4 PDF p105 names CYK. The supplied papers ask top-down / bottom-up CFG trees, not CKY charts. These traces explain the taught topic.</p><p><strong>CYK and CKY are two names for the same dynamic-programming parsing family.</strong> A chart stores which grammatical categories can generate each contiguous span of the sentence. Small spans are solved first and reused to build larger spans. Basic CKY uses a context-free grammar in Chomsky normal form (CNF): a production has either two nonterminals on its right, A→B C, or one terminal, A→word. Empty-string handling is a separate special case; the examples here have no empty production.</p><div class=\"table-wrap\"><table><thead><tr><th>Rule</th><th>Basic CKY status</th><th>Reason</th></tr></thead><tbody><tr><td>S → NP VP</td><td>Allowed</td><td>Two nonterminals</td></tr><tr><td>N → cat</td><td>Allowed</td><td>One terminal</td></tr><tr><td>NP → Det Adj N</td><td>Convert first</td><td>Three nonterminals</td></tr><tr><td>NP → N</td><td>Eliminate or handle unary closure</td><td>One nonterminal, not a lexical terminal</td></tr><tr><td>VP → eats NP</td><td>Convert first</td><td>Mixed terminal and nonterminal</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Convert NP→Det Adj N, NP→N, N→cat and VP→eats NP into basic CNF-compatible productions. Preserve their possible word yields. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>The symbols NP,Det,Adj,N,VP are nonterminals; cat and eats are terminals. Other needed lexical rules remain as supplied.</p><h4>To find</h4><p>Equivalent binary or terminal productions for these cases.</p></div><h4>Formula and why it applies</h4><p>Introduce helper categories for a long right-hand side or a terminal mixed with nonterminals. Eliminate a unary nonterminal rule by inheriting the reachable non-unit productions.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Binarize the three-part NP</h5><p>Introduce X: NP→Det X and X→Adj N. X is a helper, not a word; the terminal order remains Det, Adj, N.</p></div><div class=\"step\"><h5>Step 2. Remove the unit production</h5><p>NP→N and N→cat allow NP to derive cat. Add NP→cat, retain N→cat where needed, and remove NP→N. With more rules reachable through unit chains, inherit every corresponding non-unit rule, not only the first one.</p></div><div class=\"step\"><h5>Step 3. Replace the mixed terminal</h5><p>Introduce Vlex→eats and replace VP→eats NP by VP→Vlex NP.</p></div><div class=\"step\"><h5>Step 4. Read the converted forms</h5><p>NP→Det X | cat; X→Adj N; N→cat; VP→Vlex NP; Vlex→eats. All displayed productions are binary nonterminal or single-terminal rules.</p></div><div class=\"answer\"><strong>Final answer.</strong> The converted rules preserve the original word sequences while satisfying the displayed basic CKY forms. Helper nodes change tree shape; they can be removed when presenting the original grammar’s tree.</div></section><p>General CNF conversion may also require eliminating nullable productions and useless symbols while preserving the intended language. Do not claim that simply splitting long rules handles every arbitrary CFG. An Earley parser instead supports general CFG rules using prediction, scanning and completion; it combines top-down expectations with bottom-up evidence. LR and operator-precedence parsers are other methods named in the faculty list, with grammar restrictions of their own.</p>"},{"id":"cky","title":"CYK / CKY: complete charts, backpointers and ambiguity","html":"<p class=\"note\"><strong>Faculty topic; not an observed numerical PYQ.</strong> Unit 4 PDF p105 names CYK. The supplied papers ask top-down / bottom-up CFG trees, not CKY charts. These traces explain the taught topic.</p><p>Number the words 1 to n. Let <strong>T[i,j]</strong> contain all categories that derive the span from word i through word j, inclusive. Start with one-word cells from lexical rules. For every longer span try <strong>every split k</strong> between i and j: if B belongs to T[i,k], C belongs to T[k+1,j], and A→B C is a rule, put A in T[i,j]. Store the rule and split as backpointers when a tree is required.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/de5d4255c3f9d98c.svg\" alt=\"A\\in T[i,j]\\quad\\text{if}\\quad A\\to BC,\\ B\\in T[i,k],\\ C\\in T[k+1,j],\\ i\\le k&lt;j.\" style=\"width:63.45ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Accept precisely when S is in T[1,n]. Empty cells are meaningful: no category in this grammar derives that span. Basic recognition takes O(n³|G|) time using the straightforward rule-loop analysis and O(n²|N|) category storage; packed backpointers can preserve alternative parses without listing all trees immediately.</p><section class=\"example\"><p class=\"question\"><strong>Question. Use CKY to parse “the cat eats a fish” with S→NP VP, NP→Det N, VP→V NP; Det→the|a; N→cat|fish; V→eats. Show the complete span chart and reconstruct a tree. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Words 1=the, 2=cat, 3=eats, 4=a, 5=fish. The grammar is already in the basic CNF form. ∅ denotes an empty cell.</p><h4>To find</h4><p>All chart cells, acceptance, and a parse tree.</p></div><h4>Formula and why it applies</h4><p>Fill lexical cells, then spans of length 2,3,4,5. For each span try all split points and combine only categories permitted by a binary grammar rule.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Fill the five one-word cells</h5><p>T[1,1]={Det}; T[2,2]={N}; T[3,3]={V}; T[4,4]={Det}; T[5,5]={N}.</p></div><div class=\"step\"><h5>Step 2. Fill length-two spans</h5><p>T[1,2]={NP} because Det+N matches NP→Det N. T[2,3]=∅ (N V has no rule). T[3,4]=∅ (V Det has no rule). T[4,5]={NP} using Det+N.</p></div><div class=\"step\"><h5>Step 3. Fill length-three spans</h5><p>T[1,3]=∅: neither Det+(N eats) nor NP+V matches a rule. T[2,4]=∅. For T[3,5], split after word 3: V from [3,3] plus NP from [4,5] gives VP. Thus T[3,5]={VP}; the other split has an empty left child.</p></div><div class=\"step\"><h5>Step 4. Fill length-four spans</h5><p>T[1,4]=∅ because every split has an empty child or an unmatched category pair. T[2,5]=∅: the only wholly nonempty possibility is N+VP, and no rule produces a parent from that pair.</p></div><div class=\"step\"><h5>Step 5. Fill the complete span</h5><p>For T[1,5], k=1 has an empty right cell; k=2 gives NP from [1,2] and VP from [3,5], hence S. k=3 and k=4 have empty left cells. Therefore T[1,5]={S}.</p></div><div class=\"step\"><h5>Step 6. Copy the completed upper-triangular chart</h5><div class=\"table-wrap\"><table><thead><tr><th>Start i / end j</th><th>1: the</th><th>2: cat</th><th>3: eats</th><th>4: a</th><th>5: fish</th></tr></thead><tbody><tr><td>1</td><td>Det</td><td>NP</td><td>∅</td><td>∅</td><td>S</td></tr><tr><td>2</td><td>—</td><td>N</td><td>∅</td><td>∅</td><td>∅</td></tr><tr><td>3</td><td>—</td><td>—</td><td>V</td><td>∅</td><td>VP</td></tr><tr><td>4</td><td>—</td><td>—</td><td>—</td><td>Det</td><td>NP</td></tr><tr><td>5</td><td>—</td><td>—</td><td>—</td><td>—</td><td>N</td></tr></tbody></table></div><p>A dash is outside the chart (i>j); ∅ is an evaluated but empty valid span. Read the chart by increasing span length, not left-to-right across a row.</p></div><div class=\"step\"><h5>Step 7. Follow the stored backpointers</h5><p>S[1,5]→NP[1,2] VP[3,5]; NP[1,2]→Det[1,1] N[2,2]; VP[3,5]→V[3,3] NP[4,5]; NP[4,5]→Det[4,4] N[5,5].</p><pre>S\n├── NP\n│   ├── Det: the\n│   └── N: cat\n└── VP\n    ├── V: eats\n    └── NP\n        ├── Det: a\n        └── N: fish</pre></div><div class=\"answer\"><strong>Final answer.</strong> Accepted because S∈T[1,5]. The reconstructed tree’s leaves are exactly the five input words in order.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A grammar has S→A A, A→A A and A→a. Use CKY for “a a a” and explain how two parse trees are preserved. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Three identical terminal tokens. S is the start symbol. No unit or empty rules are present.</p><h4>To find</h4><p>Chart categories and both successful split choices for the root.</p></div><h4>Formula and why it applies</h4><p>A chart cell is a set of possible categories. For each category keep all successful backpointers when the task requires every parse.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize the diagonal</h5><p>Each of T[1,1], T[2,2], T[3,3] is {A}, from A→a.</p></div><div class=\"step\"><h5>Step 2. Fill two-word spans</h5><p>T[1,2] and T[2,3] each contain {A,S}: A+A can use A→A A or S→A A.</p></div><div class=\"step\"><h5>Step 3. Try both root splits</h5><p>k=1: A[1,1] + A[2,3] permits S. k=2: A[1,2] + A[3,3] also permits S. The complete cell is {A,S}, but S has two distinct backpointer alternatives.</p></div><div class=\"step\"><h5>Step 4. Draw both bracketed trees</h5><p>[S [A a] [A [A a] [A a]]] and [S [A [A a] [A a]] [A a]]. Both yield a a a; the constituent grouping differs.</p></div><div class=\"answer\"><strong>Final answer.</strong> Accepted, with two S-rooted parses. A category appearing once in a set does not mean there is only one derivation.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. With S→NP VP, NP→Det N, VP→V NP; Det→the|a; N→cat|fish; V→eats, test “the eats cat” using CKY. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Tokens are the/eats/cat, with no punctuation. Use exactly the supplied grammar.</p><h4>To find</h4><p>Whether the grammar accepts the whole input.</p></div><h4>Formula and why it applies</h4><p>A parse exists only if the complete chart cell contains the start symbol.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize the diagonal</h5><p>T[1,1]={Det}; T[2,2]={V}; T[3,3]={N}.</p></div><div class=\"step\"><h5>Step 2. Try length-two combinations</h5><p>Det+V matches no binary rule; V+N also matches no rule (VP requires V+NP). Both two-word cells are empty.</p></div><div class=\"step\"><h5>Step 3. Try the two full-span splits</h5><p>Each split has an empty child, so T[1,3]=∅ and S is absent.</p></div><div class=\"answer\"><strong>Final answer.</strong> Rejected by this grammar. Do not invent NP→N to force acceptance. Grammar rejection and a universal judgment about every possible English grammar are different claims.</div></section><p><strong>Yaad rakho:</strong> Diagonal par words ke tags; phir chhote spans jodo. Har split dekho. Full sentence cell mein S aaya toh parse possible.</p>"}]},{"id":"tee-formula-index","title":"TEE · additional formulas","unit":0,"sections":[{"id":"all-tee","title":"TEE formula sheet: vectors and applications","html":"<p>These formulas extend the M2 sheet to the complete TEE syllabus. Each coordinate, token-count convention and log base must be defined before calculation. Worked-example chapters follow this sheet.</p><h3>Type–token ratio</h3><div class=\"math-display\"><img src=\"math/d8b9766d1f538431.svg\" alt=\"TTR=\\frac{\\#\\text{types}}{\\#\\text{tokens}}\" style=\"width:17.16ex;height:5.09ex\" loading=\"lazy\" decoding=\"async\"></div><p>Distinct vocabulary types divided by all token occurrences. Often expressed as a percentage.</p><h3>Normalized term frequency</h3><div class=\"math-display\"><img src=\"math/326e2d23a0474bba.svg\" alt=\"TF(t,d)=\\frac{C(t,d)}{\\sum_w C(w,d)}\" style=\"width:23.441ex;height:5.573ex\" loading=\"lazy\" decoding=\"async\"></div><p>The slides use count of the term divided by the document token total after the specified preprocessing.</p><h3>Inverse document frequency</h3><div class=\"math-display\"><img src=\"math/d11da5cd42950e34.svg\" alt=\"IDF(t)=\\log_{10}\\frac{D}{df(t)}\" style=\"width:21.351ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div><p>D is the number of documents; df counts documents containing the term at least once. This is the course slide convention.</p><h3>TF–IDF</h3><div class=\"math-display\"><img src=\"math/ab5dadabf0c331ca.svg\" alt=\"TF\\!\\operatorname{-}\\!IDF(t,d)=TF(t,d)IDF(t)\" style=\"width:31.856ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply the local frequency weight by the global rarity weight.</p><h3>Dot product</h3><div class=\"math-display\"><img src=\"math/eb860722f2212f6a.svg\" alt=\"a\\cdot b=\\sum_i a_ib_i\" style=\"width:14.11ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Multiply corresponding coordinates, then add. Vectors need the same coordinate order.</p><h3>Vector length</h3><div class=\"math-display\"><img src=\"math/61ee9e4ad4caa506.svg\" alt=\"\\|a\\|_2=\\sqrt{\\sum_i a_i^2}\" style=\"width:15.6ex;height:5.566ex\" loading=\"lazy\" decoding=\"async\"></div><p>Square each coordinate, add, then take the square root.</p><h3>Cosine similarity</h3><div class=\"math-display\"><img src=\"math/79fe3d8fd2840024.svg\" alt=\"\\cos(a,b)=\\frac{\\sum_i a_ib_i}{\\sqrt{\\sum_i a_i^2}\\sqrt{\\sum_i b_i^2}}\" style=\"width:27.743ex;height:7.518ex\" loading=\"lazy\" decoding=\"async\"></div><p>Compare direction; undefined for a zero-length vector.</p><h3>Jaccard similarity</h3><div class=\"math-display\"><img src=\"math/0eeb7c5512da08e8.svg\" alt=\"J(A,B)=\\frac{|A\\cap B|}{|A\\cup B|}\" style=\"width:18.811ex;height:5.471ex\" loading=\"lazy\" decoding=\"async\"></div><p>Set membership, not repeated word counts. Jaccard distance = 1 − J.</p><h3>Manhattan distance</h3><div class=\"math-display\"><img src=\"math/105c539acb46c968.svg\" alt=\"d_1(a,b)=\\sum_i|a_i-b_i|\" style=\"width:21.429ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Add coordinate-wise absolute differences.</p><h3>Euclidean distance</h3><div class=\"math-display\"><img src=\"math/bffa849afa7462de.svg\" alt=\"d_2(a,b)=\\sqrt{\\sum_i(a_i-b_i)^2}\" style=\"width:24.85ex;height:5.566ex\" loading=\"lazy\" decoding=\"async\"></div><p>Square differences, add, square root.</p><h3>Minkowski distance</h3><div class=\"math-display\"><img src=\"math/80afdfa17b2f9274.svg\" alt=\"d_p(a,b)=\\left(\\sum_i|a_i-b_i|^p\\right)^{1/p}\" style=\"width:28.603ex;height:7.367ex\" loading=\"lazy\" decoding=\"async\"></div><p>p≥1; Manhattan p=1, Euclidean p=2.</p><h3>Mean sentence embedding</h3><div class=\"math-display\"><img src=\"math/739624bae7d9725e.svg\" alt=\"v_{sentence}=\\frac1n\\sum_{i=1}^n v_{w_i}\" style=\"width:19.807ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div><p>Add word vectors coordinate by coordinate; divide each coordinate by n. This baseline loses word order.</p><h3>GloVe objective</h3><div class=\"math-display\"><img src=\"math/2aeda5f45a0334aa.svg\" alt=\"J=\\sum_{i,j}f(X_{ij})(w_i^T\\widetilde w_j+b_i+\\widetilde b_j-\\log X_{ij})^2\" style=\"width:40.884ex;height:5.273ex\" loading=\"lazy\" decoding=\"async\"></div><p>X is a co-occurrence count. Compute the residual, square it and apply the weighting function. Use observed positive counts.</p><h3>Precision and recall</h3><div class=\"math-display\"><img src=\"math/f39c3956a7771d5d.svg\" alt=\"P=\\frac{TP}{TP+FP},\\qquad R=\\frac{TP}{TP+FN}\" style=\"width:36.185ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Precision checks predicted positives; recall checks actual positives.</p><h3>F1 score</h3><div class=\"math-display\"><img src=\"math/fa461c3c89d25a66.svg\" alt=\"F_1=\\frac{2PR}{P+R}=\\frac{2TP}{2TP+FP+FN}\" style=\"width:33.701ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Harmonic mean of precision and recall.</p><h3>Accuracy</h3><div class=\"math-display\"><img src=\"math/c65e0cb33ac1ccf1.svg\" alt=\"A=\\frac{TP+TN}{TP+TN+FP+FN}\" style=\"width:27.997ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>All correct predictions divided by all predictions.</p><h3>Noisy-channel correction</h3><div class=\"math-display\"><img src=\"math/3ede23f6f61aee5c.svg\" alt=\"\\hat w=\\arg\\max_w P(x\\mid w)P(w)\" style=\"width:26.089ex;height:3.461ex\" loading=\"lazy\" decoding=\"async\"></div><p>Rank intended word w using observed typo x; likelihood × prior.</p><h3>Unit-cost edit distance</h3><div class=\"math-display\"><img src=\"math/3eb73cb97ea627b1.svg\" alt=\"D(i,j)=\\min\\{D(i-1,j)+1,D(i,j-1)+1,D(i-1,j-1)+[a_i\\ne b_j]\\}\" style=\"width:70.648ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div><p>Initialise first row/column by insertion/deletion counts; fill all cells using min.</p>"}],"scope":"TEE · used together with the M2 formula sheet"}],"papers":[{"id":"final-2025","title":"Solved final paper · December 2025","unit":"PYQ","scope":"Actual final examination · 2 December 2025 · 100 marks · 3 hours","sections":[{"id":"final-2025-q1a","title":"Q1A · NLU and NLG","html":"<div class=\"question\" style=\"font-weight:700\">Question. Differentiate between Natural Language Understanding (NLU) and Natural Language Generation (NLG) in NLP with suitable examples. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Natural Language Understanding (NLU)</strong> interprets language to identify its meaning, intent and relevant information. <strong>Natural Language Generation (NLG)</strong> produces language that expresses information in a useful form.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>NLU</th><th>NLG</th></tr></thead><tbody><tr><td>Direction</td><td>Language → meaning or structured information</td><td>Meaning or structured information → language</td></tr><tr><td>Typical input</td><td>A user utterance, document or sentence</td><td>Facts, a database record, a prompt or a representation</td></tr><tr><td>Typical output</td><td>Intent, entities, sentiment or a semantic representation</td><td>A sentence, explanation, summary or dialogue response</td></tr><tr><td>Main difficulty</td><td>Resolving ambiguity and context</td><td>Choosing accurate content and producing coherent, fluent wording</td></tr></tbody></table></div><h3>Example: a weather assistant</h3><p>User: “Will it rain in Mumbai tomorrow?” NLU recognises a weather-query intent, the location Mumbai and the date tomorrow. After a weather service supplies the forecast, NLG produces “Rain is likely in Mumbai tomorrow; carry an umbrella.”</p><div class=\"flow\"><span class=\"flow-box\">User language</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">NLU: identify request</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Retrieve forecast</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">NLG: express answer</span></div><p>The two functions often work together in a chatbot. Understanding the request and wording the reply are separate tasks; fluent generation alone does not prove correct understanding.</p><p class=\"memory\"><strong>Yaad rakho:</strong> NLU mein meaning nikalo; NLG mein meaning ko sentence banao.</p>","m2":false,"units":"1","marks":5},{"id":"final-2025-q1b","title":"Q1B · Chunking and chinking","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain the concepts of chunking and chinking in Natural Language Processing (NLP). Discuss how Part-of-Speech (POS) tagging supports these processes, and illustrate your explanation with a suitable example. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Chunking</strong> groups adjacent tagged words into shallow phrases, such as noun phrases, without building a complete sentence parse. <strong>Chinking</strong> removes a specified sequence of tags or words from a chunk, splitting a larger candidate chunk when required.</p><h3>POS tags provide the pattern</h3><p>A POS tag describes a grammatical category: DT = determiner, JJ = adjective, NN = singular noun, VBD = past-tense verb and IN = preposition. A noun-phrase rule can be written as <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;+}</code>: an optional determiner, zero or more adjectives, followed by one or more nouns.</p><h3>Worked example</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>The</th><th>small</th><th>cat</th><th>sat</th><th>on</th><th>the</th><th>mat</th></tr></thead><tbody><tr><td>Tag</td><td>DT</td><td>JJ</td><td>NN</td><td>VBD</td><td>IN</td><td>DT</td><td>NN</td></tr></tbody></table></div><p>Applying the NP rule gives <strong>[The small cat] sat on [the mat]</strong>. The first chunk contains DT–JJ–NN; the second contains DT–NN. “sat on” is not included because it does not match the noun-phrase rule.</p><p>For chinking, begin with one broad chunk: <strong>[The small cat sat on the mat]</strong>. Remove the VBD and IN sequence “sat on”, for example with <code>}&lt;VBD|IN&gt;+{</code>. The result is <strong>[The small cat] sat on [the mat]</strong>.</p><p>POS tagging therefore supplies grammatical labels; chunking uses labels to select phrases, while chinking uses labels to exclude unwanted material. Incorrect tags can lead to incorrect chunks.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Chunking = phrase ko jodo; chinking = beech ka unwanted part nikalo.</p>","m2":true,"units":"4","marks":5},{"id":"final-2025-q1c","title":"Q1C · Hyponymy, hypernymy and WSD","html":"<div class=\"question\" style=\"font-weight:700\">Question. Define hyponymy and hypernymy with suitable linguistic examples. How can hypernymy be applied in Word Sense Disambiguation (WSD) to resolve the correct meaning of polysemous words? Provide an example? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Hyponymy</strong> is the “is-a-kind-of” relation from a specific concept to a broader concept. <strong>Hypernymy</strong> is the inverse relation from the broader concept to the specific one. “Rose” is a hyponym of “flower”; “flower” is a hypernym of “rose”.</p><div class=\"flow\"><span class=\"flow-box\">rose / tulip</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">flower</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">plant</span></div><p>The arrow points towards a broader category. Hyponymy is not a part–whole relation: a wheel is part of a car, but it is not a kind of car.</p><h3>Using the hierarchy for WSD</h3><p>WSD selects the intended sense of a word from its context. Obtain candidate senses from a lexical resource such as WordNet, inspect their hypernym chains, and favour the chain most compatible with nearby words.</p><ol><li>Sentence: “The mouse clicked the icon.”</li><li>Candidate 1: mouse → rodent → mammal → animal. Candidate 2: mouse → pointing device → computer peripheral.</li><li>The context words “clicked” and “icon” belong to the computer-use domain. They support the device hierarchy, rather than the animal hierarchy.</li><li>Select the computer-pointing-device sense. In “The mouse ate cheese,” the animal hierarchy is more compatible.</li></ol><p>Hypernym evidence supplies semantic generalisation; it is a useful signal rather than a guarantee, because short or unusual contexts may still be ambiguous.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Hyponym specific hai; hypernym uska bada category hai.</p>","m2":true,"units":"5","marks":5},{"id":"final-2025-q1d","title":"Q1D · Pragmatics and discourse","html":"<div class=\"question\" style=\"font-weight:700\">Question. Compare pragmatic and discourse analysis with the help of appropriate examples. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Pragmatic analysis</strong> interprets an utterance using the situation, speaker intention, shared knowledge and conversational expectations. <strong>Discourse analysis</strong> studies how multiple utterances form a connected text or conversation.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Pragmatic analysis</th><th>Discourse analysis</th></tr></thead><tbody><tr><td>Focus</td><td>Intended meaning in context</td><td>Relationships and coherence across utterances</td></tr><tr><td>Useful information</td><td>Speaker, listener, place, time and common knowledge</td><td>Previous sentences, entities, topics and rhetorical relations</td></tr><tr><td>Typical tasks</td><td>Interpret requests, implicatures and deixis</td><td>Resolve references and analyse cohesion, coherence and discourse structure</td></tr><tr><td>Example</td><td>“It is cold here” may be a request to close a window</td><td>“Riya bought a book. She read it.” links She to Riya and it to book</td></tr></tbody></table></div><p>In “Can you pass the salt?”, literal syntax asks about ability; pragmatic interpretation usually identifies a polite request. In “The road flooded. Therefore, the school closed,” discourse analysis identifies a cause–result link between the sentences.</p><p>The levels interact: resolving “she” across a conversation may require both earlier text and real-world context. They are complementary rather than mutually exclusive.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pragmatics: bolne ka intention. Discourse: sentences ka connection.</p>","m2":false,"units":"6","marks":5},{"id":"final-2025-q2a","title":"Q2A · Morpheme, lexeme and NER","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Differentiate between Morpheme and Lexeme with examples.<br>ii. Discuss the significance of NER in three different NLP applications. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Morpheme and lexeme</h3><p>A <strong>morpheme</strong> is the smallest linguistic unit that contributes meaning or grammatical function. A <strong>lexeme</strong> is an abstract vocabulary item representing a family of inflected word forms.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Morpheme</th><th>Lexeme</th></tr></thead><tbody><tr><td>Unit</td><td>A meaningful component of a word</td><td>An abstract dictionary vocabulary item</td></tr><tr><td>Examples</td><td>un-, happy, -ness; cat and plural -s</td><td>RUN covers run, runs, ran and running</td></tr><tr><td>Independence</td><td>Free morphemes can stand alone; bound morphemes cannot</td><td>A lexeme is realised through one or more word forms</td></tr><tr><td>NLP relevance</td><td>Morphological segmentation, stemming and analysis</td><td>Lemmatization and lexical meaning</td></tr></tbody></table></div><p>“Cats” contains two morphemes: cat + plural -s. “cat” and “cats” are forms of the lexeme CAT. “Unhappiness” can be segmented into un + happy + ness, although its spelling changes at the boundary. A morpheme and a syllable are different: syllables concern pronunciation, while morphemes concern meaning or grammar.</p><h3>ii. Named Entity Recognition in applications</h3><p><strong>NER</strong> locates spans that name entities and assigns types such as PERSON, ORGANIZATION, LOCATION, DATE or domain-specific categories.</p><div class=\"table-wrap\"><table><thead><tr><th>Application</th><th>Entities and example</th><th>Why NER matters</th></tr></thead><tbody><tr><td>News information extraction</td><td>“Asha joined Infosys in Pune.” → Asha/PERSON, Infosys/ORG, Pune/LOCATION</td><td>Creates searchable people–organisation–location records and supports later relation extraction</td></tr><tr><td>Healthcare document processing</td><td>Find disease, drug and dosage spans in a clinical note</td><td>Supports record indexing and medication extraction; specialist labels and validation are required</td></tr><tr><td>Customer support and commerce</td><td>Extract product names, dates and order identifiers from “My Pixel arrived damaged on Monday.”</td><td>Routes complaints, links the correct product and fills structured support fields</td></tr></tbody></table></div><p>NER answers “Which entity spans occur here, and what type are they?” It does not by itself establish every relation between those entities or resolve all names to unique real-world identities.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Morpheme = word ka meaningful piece; lexeme = word family. NER = naam dhoondho aur type do.</p>","m2":false,"units":"1,4","marks":10},{"id":"final-2025-q2b","title":"Q2B · Laplace-smoothed bigram probability","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following training corpus:<br>1. artists paint murals in city<br>2. musicians play songs in city<br>3. painters paint murals on walls<br>4. signs are near city<br>Using a bigram language model with Laplace smoothing, evaluate the probability of the test sentence: “artists paint murals near city”. Assume the &lt;s&gt; and &lt;/s&gt; for each sentence. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><ul><li>artists paint murals in city</li><li>musicians play songs in city</li><li>painters paint murals on walls</li><li>signs are near city</li></ul><p>Test: artists paint murals near city. Add one start token &lt;s&gt; and one end token &lt;/s&gt; to every training and test sentence.</p><h3>To find</h3><p>The Laplace-smoothed bigram probability of the complete test sentence, including its end token.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0167293b8abe1cce.svg\" alt=\"P_{+1}(w_i\\mid w_{i-1})=\\frac{C(w_{i-1},w_i)+1}{C(w_{i-1})+V}\" style=\"width:33.254ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(previous,current) counts that adjacent pair in the training corpus. C(previous) counts its occurrences as a history. V is the vocabulary size. Add-one smoothing is necessary because an unseen pair must not force the whole sentence probability to zero.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/09cc94e28baa5a90.svg\" alt=\"P(w_1,\\ldots,w_n,\\langle/s\\rangle\\mid\\langle s\\rangle)=\\prod_{i=1}^{n+1}P(w_i\\mid w_{i-1})\" style=\"width:42.048ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Fix the token and vocabulary convention</h3><p>Lowercase words and remove the final punctuation. The supplied course key counts both boundary tokens in V. Following that convention: are, artists, city, in, murals, musicians, near, on, paint, painters, play, signs, songs, walls, &lt;s&gt;, &lt;/s&gt; gives <strong>V = 16</strong>. The start marker supplies history; it is not an extra probability factor before the first word.</p><h3>Step 2. List every required transition</h3><p>The complete test chain is &lt;s&gt; → artists → paint → murals → near → city → &lt;/s&gt;.</p><h3>Step 3. Count first, then add one</h3><div class=\"table-wrap\"><table><thead><tr><th>Required bigram</th><th>History count</th><th>Pair count</th><th>Smoothed probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → artists</td><td>4</td><td>1</td><td>(1+1)/(4+16) = 1/10</td></tr><tr><td>artists → paint</td><td>1</td><td>1</td><td>(1+1)/(1+16) = 2/17</td></tr><tr><td>paint → murals</td><td>2</td><td>2</td><td>(2+1)/(2+16) = 1/6</td></tr><tr><td>murals → near</td><td>2</td><td>0</td><td>(0+1)/(2+16) = 1/18</td></tr><tr><td>near → city</td><td>1</td><td>1</td><td>(1+1)/(1+16) = 2/17</td></tr><tr><td>city → &lt;/s&gt;</td><td>3</td><td>3</td><td>(3+1)/(3+16) = 4/19</td></tr></tbody></table></div><p>Count only adjacent words, never words that merely appear in the same sentence. The unseen pairs have count zero, so their numerator becomes one.</p><h3>Step 4. Multiply all six probabilities</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/62ad7b9fcca8c7b7.svg\" alt=\"P=\\frac{2}{20}\\times\\frac{2}{17}\\times\\frac{3}{18}\\times\\frac{1}{18}\\times\\frac{2}{17}\\times\\frac{4}{19}\" style=\"width:38.092ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. &lt;s&gt; → artists</td><td><span class=\"math-inline\"><img src=\"math/8fc51cfa0d4d18ef.svg\" alt=\"1\\times\\frac{1}{10}=\\frac{1}{10}\" style=\"width:12.105ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. artists → paint</td><td><span class=\"math-inline\"><img src=\"math/11b6a388c4744fa9.svg\" alt=\"\\frac{1}{10}\\times\\frac{2}{17}=\\frac{1}{85}\" style=\"width:13.569ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. paint → murals</td><td><span class=\"math-inline\"><img src=\"math/3123e759352a19f6.svg\" alt=\"\\frac{1}{85}\\times\\frac{1}{6}=\\frac{1}{510}\" style=\"width:13.569ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. murals → near</td><td><span class=\"math-inline\"><img src=\"math/8396eb2fae42ff25.svg\" alt=\"\\frac{1}{510}\\times\\frac{1}{18}=\\frac{1}{9180}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. near → city</td><td><span class=\"math-inline\"><img src=\"math/6b756a42abed1715.svg\" alt=\"\\frac{1}{9180}\\times\\frac{2}{17}=\\frac{1}{78030}\" style=\"width:17.568ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. city → &lt;/s&gt;</td><td><span class=\"math-inline\"><img src=\"math/c4371974205f854f.svg\" alt=\"\\frac{1}{78030}\\times\\frac{4}{19}=\\frac{2}{741285}\" style=\"width:19.168ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8bf61abdfc6b7956.svg\" alt=\"P=\\frac{2}{741285}\\approx 2.69801763\\times10^{-6}\" style=\"width:33.587ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Interpret the result</h3><p>This is a joint sentence probability, so a small value is normal. Do not add transition probabilities; each word must occur in sequence, so the chain multiplies them.</p><h3>Final answer</h3><p><strong>P ≈ 2.69801763 × 10<sup>-6</sup></strong> with the stated course vocabulary convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pair count mein 1 jodo, previous-word count mein V; phir saare fractions multiply karo.</p><p><strong>Convention note:</strong> Some implementations exclude &lt;s&gt; from the predicted vocabulary. Their V is one smaller and their numerical probability differs. In an exam, state V explicitly and follow the convention specified in the question or class solution.</p>","m2":true,"units":"3","marks":10},{"id":"final-2025-q3a","title":"Q3A · Ambiguity and bottom-up parsing","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain the various types of ambiguities encountered in Natural Language Processing (NLP). Illustrate each type with suitable examples.<br>ii. Compare top-down and bottom-up parsing and apply bottom-up syntax parsing approach to the sentence “A cat chased the mouse” and draw a parse tree using the grammar rules:<br>S → NP VP; NP → Pronoun | Proper-Noun | Det Nominal; Nominal → Noun | Nominal Noun | Nominal PP; VP → Verb | Verb NP | VP PP; PP → Prep NP.<br>Lexicon: Det → {A, the}; Noun → {cat, mouse}; Verb → {chased}. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Types of ambiguity</h3><p>Ambiguity exists when the same language expression permits more than one interpretation. The correct interpretation usually requires grammatical, semantic or contextual evidence.</p><div class=\"table-wrap\"><table><thead><tr><th>Type</th><th>Meaning</th><th>Example and readings</th></tr></thead><tbody><tr><td>Lexical</td><td>One word has multiple meanings</td><td>“She visited the bank”: financial institution or riverbank</td></tr><tr><td>Syntactic</td><td>The sentence permits different structural attachments</td><td>“I saw the man with a telescope”: I used the telescope, or the man had it</td></tr><tr><td>Semantic / scope</td><td>A structured sentence permits different interpretations</td><td>“Every student read a book”: one shared book, or possibly a different book per student</td></tr><tr><td>Referential</td><td>A referring expression has more than one candidate referent</td><td>“Asha told Riya that she won”: she could refer to Asha or Riya</td></tr><tr><td>Pragmatic</td><td>Intention depends on the situation</td><td>“Can you open the door?” can ask about ability or request an action</td></tr></tbody></table></div><h3>ii. Parsing approaches</h3><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Top-down</th><th>Bottom-up</th></tr></thead><tbody><tr><td>Start</td><td>The start symbol S</td><td>The input words</td></tr><tr><td>Operation</td><td>Expand a nonterminal using grammar productions</td><td>Combine words and constituents using productions in reverse</td></tr><tr><td>Success</td><td>Leaves match the complete input</td><td>All input is reduced to S</td></tr><tr><td>Possible difficulty</td><td>Naive recursive descent can loop on left recursion or need backtracking</td><td>A naive shift-reduce parser may face shift/reduce conflicts</td></tr></tbody></table></div><h3>Given</h3><p>The five tokens are A / cat / chased / the / mouse. The supplied grammar permits determiner + nominal noun phrases and a verb + noun phrase verb phrase.</p><h3>To find</h3><p>A bottom-up sequence of reductions and a parse tree whose root is S and whose leaves preserve the input order.</p><h3>Rule: which one and why</h3><p>A production A → B C permits B C to be reduced to A. Bottom-up parsing begins with the words; lexical rules assign their categories, and phrase rules combine those categories.</p><h3>Step 1. Assign lexical categories</h3><p>A → Det; cat → Noun; chased → Verb; the → Det; mouse → Noun.</p><h3>Step 2. Build the first noun phrase</h3><p>cat is Noun. Reduce Noun to Nominal using Nominal → Noun. Then reduce Det Nominal, representing “A cat”, to NP.</p><h3>Step 3. Build the object noun phrase</h3><p>mouse is Noun. Reduce it to Nominal. Reduce “the” + “mouse”, now Det Nominal, to NP.</p><h3>Step 4. Build the verb phrase</h3><p>“chased” is Verb and “the mouse” is NP. Reduce Verb NP to VP.</p><h3>Step 5. Build the sentence</h3><p>The remaining constituents are NP (“A cat”) and VP (“chased the mouse”). Apply S → NP VP in reverse to obtain S. Every input token is used exactly once.</p><figure><svg viewBox=\"0 0 820 350\" role=\"img\" aria-label=\"Bottom-up parse tree for A cat chased the mouse\" style=\"width:100%;max-width:820px;background:#f4f8f7\"><line x1=\"400\" y1=\"38\" x2=\"190\" y2=\"65\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"400\" y1=\"38\" x2=\"610\" y2=\"65\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"190\" y1=\"93\" x2=\"85\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"190\" y1=\"93\" x2=\"260\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"610\" y1=\"93\" x2=\"485\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"610\" y1=\"93\" x2=\"700\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"260\" y1=\"153\" x2=\"260\" y2=\"185\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"700\" y1=\"153\" x2=\"630\" y2=\"185\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"700\" y1=\"153\" x2=\"760\" y2=\"185\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"760\" y1=\"213\" x2=\"760\" y2=\"245\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"85\" y1=\"153\" x2=\"85\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"260\" y1=\"213\" x2=\"260\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"485\" y1=\"153\" x2=\"485\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"630\" y1=\"213\" x2=\"630\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"760\" y1=\"273\" x2=\"760\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><text x=\"400\" y=\"30\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">S</text><text x=\"190\" y=\"85\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"610\" y=\"85\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"85\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"260\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Nominal</text><text x=\"485\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Verb</text><text x=\"700\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"260\" y=\"205\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Noun</text><text x=\"630\" y=\"205\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"760\" y=\"205\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Nominal</text><text x=\"760\" y=\"265\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Noun</text><text x=\"85\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">A</text><text x=\"260\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">cat</text><text x=\"485\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">chased</text><text x=\"630\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">the</text><text x=\"760\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">mouse</text></svg><figcaption>Bottom-up parse tree for A cat chased the mouse.</figcaption></figure><p><strong>Final answer:</strong> [S [NP [Det A] [Nominal [Noun cat]]] [VP [Verb chased] [NP [Det the] [Nominal [Noun mouse]]]]].</p><p class=\"memory\"><strong>Yaad rakho:</strong> Bottom-up: words se phrases, phrases se S. Top-down: S se words.</p>","m2":false,"units":"1,4","marks":10},{"id":"final-2025-q3b","title":"Q3B · Co-occurrence matrix and cosine","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the given paragraph: The teacher wrote on the board. The students listened to the teacher. The board was full of notes. The student asked a question. The teacher answered from the book.<br>Target words: teacher, student, board, book.<br>Context words: wrote, listened, notes, question.<br>i. Construct a co-occurrence matrix for the target and context words. Take the window size as one whole sentence.<br>ii. Evaluate the similarity between the vectors of the target words “teacher-student” and “teacher-board” using the cosine similarity.<br>iii. Plot the target word vectors by considering only two dimensions: “wrote” and “notes”. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Five sentences, four target rows and four context columns. Treat students and student as the same target lemma, and count each target–context pair once when both occur in a sentence.</p><h3>To find</h3><p>The 4 × 4 sentence-window co-occurrence matrix, two cosine similarities and the requested 2-D plot.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/05bf57345047ff24.svg\" alt=\"M_{ij}=\\sum_{s=1}^{5}\\mathbf{1}[\\text{target}_i\\text{ and context}_j\\text{ occur in sentence }s]\" style=\"width:51.246ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The indicator is 1 when both words appear in that sentence and 0 otherwise. Each matrix row is the target word’s vector: its list of four context counts.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75e740509c95134b.svg\" alt=\"\\cos(\\mathbf a,\\mathbf b)=\\frac{\\mathbf a\\cdot\\mathbf b}{\\|\\mathbf a\\|\\|\\mathbf b\\|}\" style=\"width:19.752ex;height:5.271ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The dot product multiplies corresponding coordinates and adds them. The length is the square root of the sum of squared coordinates. Cosine compares directions while allowing different vector lengths.</p><h3>Solution</h3><h3>Step 1. Record the contribution of each sentence</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Targets present</th><th>Relevant context</th><th>Counts added</th></tr></thead><tbody><tr><td>1</td><td>teacher, board</td><td>wrote</td><td>teacher–wrote +1; board–wrote +1</td></tr><tr><td>2</td><td>student, teacher</td><td>listened</td><td>student–listened +1; teacher–listened +1</td></tr><tr><td>3</td><td>board</td><td>notes</td><td>board–notes +1</td></tr><tr><td>4</td><td>student</td><td>question</td><td>student–question +1</td></tr><tr><td>5</td><td>teacher, book</td><td>none</td><td>No requested context count</td></tr></tbody></table></div><h3>Step 2. Construct every requested column</h3><div class=\"table-wrap\"><table><thead><tr><th>Target</th><th>wrote</th><th>listened</th><th>notes</th><th>question</th></tr></thead><tbody><tr><td>teacher</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>student</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>board</td><td>1</td><td>0</td><td>1</td><td>0</td></tr><tr><td>book</td><td>0</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 3. Calculate teacher–student</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5ac5a4d62f663029.svg\" alt=\"\\mathbf t\\cdot\\mathbf s=(1)(0)+(1)(1)+(0)(0)+(0)(1)=1\" style=\"width:42.267ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ae259d10b965e91c.svg\" alt=\"\\|\\mathbf t\\|=\\sqrt{1^2+1^2+0^2+0^2}=\\sqrt2\" style=\"width:31.449ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6a3ba3507695e199.svg\" alt=\"\\|\\mathbf s\\|=\\sqrt{0^2+1^2+0^2+1^2}=\\sqrt2\" style=\"width:31.465ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/eea3730ff7194b51.svg\" alt=\"\\cos(\\mathbf t,\\mathbf s)=\\frac1{\\sqrt2\\sqrt2}=\\frac12=0.5\" style=\"width:29.019ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Calculate teacher–board</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/786f2eeb23b20d27.svg\" alt=\"\\mathbf t\\cdot\\mathbf b=(1)(1)+(1)(0)+(0)(1)+(0)(0)=1\" style=\"width:42.685ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b579713956a7c270.svg\" alt=\"\\|\\mathbf b\\|=\\sqrt{1^2+0^2+1^2+0^2}=\\sqrt2\" style=\"width:31.884ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15909e375167f411.svg\" alt=\"\\cos(\\mathbf t,\\mathbf b)=\\frac1{\\sqrt2\\sqrt2}=0.5\" style=\"width:24.294ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Select only the two requested plot coordinates</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>x = wrote</th><th>y = notes</th></tr></thead><tbody><tr><td>teacher</td><td>1</td><td>0</td></tr><tr><td>student</td><td>0</td><td>0</td></tr><tr><td>board</td><td>1</td><td>1</td></tr><tr><td>book</td><td>0</td><td>0</td></tr></tbody></table></div><figure><svg viewBox=\"0 0 550 310\" role=\"img\" aria-label=\"Target word vectors plotted on two labelled axes\" style=\"width:100%;max-width:550px;background:#f4f8f7\"><path d=\"M70 250H495 M70 250V25\" stroke=\"#516d64\" fill=\"none\" stroke-width=\"2\"/><text x=\"70\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"50\" y=\"255\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"240\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"50\" y=\"165\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"410\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">2</text><text x=\"50\" y=\"75\" text-anchor=\"middle\" font-size=\"15\">2</text><circle cx=\"240\" cy=\"250\" r=\"6\" fill=\"#166b55\"/><text x=\"250\" y=\"238\" font-size=\"16\" fill=\"#153e34\">teacher</text><circle cx=\"70\" cy=\"250\" r=\"6\" fill=\"#166b55\"/><text x=\"80\" y=\"238\" font-size=\"16\" fill=\"#153e34\">student, book</text><circle cx=\"240\" cy=\"160\" r=\"6\" fill=\"#166b55\"/><text x=\"250\" y=\"148\" font-size=\"16\" fill=\"#153e34\">board</text><text x=\"280\" y=\"305\" text-anchor=\"middle\" font-size=\"16\">wrote</text><text x=\"15\" y=\"20\" font-size=\"16\">notes</text></svg><figcaption>The plot uses only the requested two coordinates; cosine uses all context columns.</figcaption></figure><h3>Final answer</h3><p>Both requested cosine similarities are <strong>0.5</strong>. Student and book overlap at the origin of the 2-D projection, but their complete four-dimensional vectors differ. The book row is zero, so a cosine involving book would be undefined without an explicit convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Har sentence mein target aur context saath? Ek count. Cosine ke liye poori row lo, plot ke liye sirf do columns.</p>","m2":false,"units":"5","marks":10},{"id":"final-2025-q4a","title":"Q4A · Three preprocessing techniques","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain any three basic text preprocessing techniques used in Natural Language Processing (NLP). Discuss the purpose of each technique and illustrate them with suitable examples. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Text preprocessing transforms raw text into a representation suitable for a chosen NLP task. The best steps depend on the task; removing information indiscriminately can reduce performance.</p><h3>1. Tokenization</h3><p>Tokenization divides text into units called tokens, such as words, subwords or sentences. These units are required for counting words and building many model inputs. “The cats are sleeping.” can become [The, cats, are, sleeping, .] under a punctuation-preserving word tokenizer. A different tokenizer may split contractions or punctuation differently, so the convention must be consistent during training and prediction.</p><h3>2. Lowercasing</h3><p>Lowercasing maps uppercase letters to lowercase so that variants such as “Book”, “BOOK” and “book” can share one feature. This reduces vocabulary duplication in a case-insensitive search system. However, “US” and “us” are different, and capitals help NER recognise names. Therefore lowercasing should be chosen according to the application.</p><h3>3. Lemmatization</h3><p>Lemmatization maps an inflected word to its dictionary base form, often using its POS and context. Examples: cats → cat; running/VBG → run; better/JJR → good. It allows a search for “run” to match relevant inflections. A stemmer instead uses simpler truncation rules and can produce a non-word stem; lemmatization is linguistically informed and can need more processing.</p><h3>Combined example</h3><div class=\"table-wrap\"><table><thead><tr><th>Stage</th><th>Representation</th></tr></thead><tbody><tr><td>Raw</td><td>The cats are running.</td></tr><tr><td>Tokenized</td><td>The | cats | are | running | .</td></tr><tr><td>Lowercased</td><td>the | cats | are | running | .</td></tr><tr><td>Lemmatized with correct POS</td><td>the | cat | be | run | .</td></tr></tbody></table></div><p>These steps do not automatically remove stop words or punctuation. Those are separate choices. For sentiment analysis, preserve negation such as “not”; for syntax parsing, function words and word order are often essential.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Preprocess task dekh ke karo: har word ko blindly delete mat karo.</p>","m2":false,"units":"2","marks":10},{"id":"final-2025-q4b","title":"Q4B · HMM emission, transition and sequence","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following POS tagged corpus. Apply Hidden Markov Model (HMM) approach to:<br>1. Cat/Noun chase/Verb mice/Noun<br>2. The/Det dog/Noun runs/Verb<br>3. A/Det cat/Noun eats/Verb cheese/Noun<br>i. Construct the emission probability matrix.<br>ii. Construct the transmission probability matrix.<br>iii. Calculate the probability of sequence of events: The/Det cat/Noun eats/Verb mice/Noun.<br>Note: Include start and end characters for all the sentences. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged sequence</th></tr></thead><tbody><tr><td>1</td><td>cat/Noun chase/Verb mice/Noun</td></tr><tr><td>2</td><td>the/Det dog/Noun runs/Verb</td></tr><tr><td>3</td><td>a/Det cat/Noun eats/Verb cheese/Noun</td></tr></tbody></table></div><p>Test words: the cat eats mice. Given tag sequence: Det → Noun → Verb → Noun. Include Start and End for all sentences. Lowercase the corpus so sentence-initial Cat and cat are one word.</p><h3>To find</h3><p>Emission probabilities, transition probabilities and the joint probability of the specified tag-and-word sequence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a732ea965eb9fa65.svg\" alt=\"P(w\\mid t)=\\frac{C(t,w)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>An emission probability asks: among tokens carrying this tag t, what fraction are the word w?</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/791852c27a57a918.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i,t_j)}{\\sum_k C(t_i,t_k)}\" style=\"width:24.245ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A transition probability asks: among transitions leaving tag tᵢ, what fraction go to tⱼ? Include End in the outgoing counts. The paper says “transmission”; the standard HMM term is transition.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c8c4a0c66e131a8f.svg\" alt=\"P(\\mathbf w,\\mathbf t)=P(t_1\\mid\\mathrm{Start})\\prod_{i=1}^{n}P(w_i\\mid t_i)\\prod_{i=2}^{n}P(t_i\\mid t_{i-1})P(\\mathrm{End}\\mid t_n)\" style=\"width:60.981ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Count tokens for each tag</h3><p>Det has 2 tokens; Noun has 5 tokens; Verb has 3 tokens. The repeated noun cat occurs twice with Noun; every other displayed noun occurs once. The three verb types each occur once.</p><h3>Step 2. Build the emission matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag / word</th><th>a</th><th>cat</th><th>chase</th><th>cheese</th><th>dog</th><th>eats</th><th>mice</th><th>runs</th><th>the</th></tr></thead><tbody><tr><td>Det</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1/2</td></tr><tr><td>Noun</td><td>0</td><td>2/5</td><td>0</td><td>1/5</td><td>1/5</td><td>0</td><td>1/5</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>1/3</td><td>0</td></tr></tbody></table></div><p>Each row sums to one. A zero means no occurrence under that tag in this unsmoothed training corpus; no add-one smoothing was requested.</p><h3>Step 3. Write the three tag chains</h3><p>Start → Noun → Verb → Noun → End<br>Start → Det → Noun → Verb → End<br>Start → Det → Noun → Verb → Noun → End</p><h3>Step 4. Count outgoing transitions</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>To Det</th><th>To Noun</th><th>To Verb</th><th>To End</th><th>Outgoing total</th></tr></thead><tbody><tr><td>Start</td><td>2</td><td>1</td><td>0</td><td>0</td><td>3</td></tr><tr><td>Det</td><td>0</td><td>2</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3</td><td>2</td><td>5</td></tr><tr><td>Verb</td><td>0</td><td>2</td><td>0</td><td>1</td><td>3</td></tr></tbody></table></div><h3>Step 5. Divide each row by its outgoing total</h3><div class=\"table-wrap\"><table><thead><tr><th>From / To</th><th>Det</th><th>Noun</th><th>Verb</th><th>End</th></tr></thead><tbody><tr><td>Start</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3/5</td><td>2/5</td></tr><tr><td>Verb</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td></tr></tbody></table></div><p>End is terminal, so it has no estimated outgoing row. The four nonterminal rows each sum to one.</p><h3>Step 6. Choose the factors for the given sequence</h3><div class=\"table-wrap\"><table><thead><tr><th>Event in order</th><th>Probability</th></tr></thead><tbody><tr><td>Start → Det</td><td>2/3</td></tr><tr><td>Det emits the</td><td>1/2</td></tr><tr><td>Det → Noun</td><td>1</td></tr><tr><td>Noun emits cat</td><td>2/5</td></tr><tr><td>Noun → Verb</td><td>3/5</td></tr><tr><td>Verb emits eats</td><td>1/3</td></tr><tr><td>Verb → Noun</td><td>2/3</td></tr><tr><td>Noun emits mice</td><td>1/5</td></tr><tr><td>Noun → End</td><td>2/5</td></tr></tbody></table></div><h3>Step 7. Multiply, including the end transition</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7b611360d98ac780.svg\" alt=\"P=\\frac23\\times\\frac12\\times1\\times\\frac25\\times\\frac35\\times\\frac13\\times\\frac23\\times\\frac15\\times\\frac25\" style=\"width:44.987ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. Start → Det</td><td><span class=\"math-inline\"><img src=\"math/b32eeb64b6ce8d87.svg\" alt=\"1\\times\\frac{2}{3}=\\frac{2}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. Det emits the</td><td><span class=\"math-inline\"><img src=\"math/0e0cb943fc030998.svg\" alt=\"\\frac{2}{3}\\times\\frac{1}{2}=\\frac{1}{3}\" style=\"width:11.169ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. Det → Noun</td><td><span class=\"math-inline\"><img src=\"math/3b61cadbe8860930.svg\" alt=\"\\frac{1}{3}\\times1=\\frac{1}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. Noun emits cat</td><td><span class=\"math-inline\"><img src=\"math/8e3868104c41a9da.svg\" alt=\"\\frac{1}{3}\\times\\frac{2}{5}=\\frac{2}{15}\" style=\"width:11.969ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. Noun → Verb</td><td><span class=\"math-inline\"><img src=\"math/69517c6e474a3048.svg\" alt=\"\\frac{2}{15}\\times\\frac{3}{5}=\\frac{2}{25}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. Verb emits eats</td><td><span class=\"math-inline\"><img src=\"math/3bb8a5077b206779.svg\" alt=\"\\frac{2}{25}\\times\\frac{1}{3}=\\frac{2}{75}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>7. Verb → Noun</td><td><span class=\"math-inline\"><img src=\"math/1a1bff7a79a3effd.svg\" alt=\"\\frac{2}{75}\\times\\frac{2}{3}=\\frac{4}{225}\" style=\"width:13.569ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>8. Noun emits mice</td><td><span class=\"math-inline\"><img src=\"math/55f13fa2c61c6016.svg\" alt=\"\\frac{4}{225}\\times\\frac{1}{5}=\\frac{4}{1125}\" style=\"width:15.168ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>9. Noun → End</td><td><span class=\"math-inline\"><img src=\"math/391357e72bb5bd3d.svg\" alt=\"\\frac{4}{1125}\\times\\frac{2}{5}=\\frac{8}{5625}\" style=\"width:15.968ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/236caebf4a4b2830.svg\" alt=\"P=\\frac8{5625}\\approx0.0014222222\" style=\"width:26.326ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>Joint sequence probability = 8/5625 ≈ 0.0014222222.</strong> This is the probability of the specified words and tags together. It is not the probability of the word sequence summed over every possible tag path.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Tag se tag = transition; tag se word = emission. Dono alternate multiply, end ko mat bhoolo.</p><p><strong>Boundary reminder:</strong> The initial factor is P(Det | Start) = 2/3, based on three sentence starts, and the final factor is P(End | Noun) = 2/5. The overall fraction of Det tokens, 2/10, is not the start probability. Using it and omitting End, as in the handwritten key’s last line, computes a different quantity.</p>","m2":true,"units":"4","marks":10},{"id":"final-2025-q5a","title":"Q5A · TF–IDF matrix","html":"<div class=\"question\" style=\"font-weight:700\">Question. For the following two sentences:<br>Sentence A: “The student read a science book in the library”<br>Sentence B: “The teacher read a history book in the classroom”<br>1. Construct the TF-IDF matrix for these sentences after removing the stop words {The, a, in}.<br>2. Identify and comment on the important terms in each sentence based on their TF-IDF scores. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Two documents, N = 2. Remove the listed stop words case-insensitively, so both “The” and “the” are removed. Use raw count TF and natural-log IDF, the convention used in the course key.</p><h3>To find</h3><p>The term-by-document TF–IDF matrix and the terms that distinguish each sentence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0a5cfe1defbb82d.svg\" alt=\"\\mathrm{TF}(t,d)=C(t,d),\\qquad \\mathrm{IDF}(t)=\\ln\\frac{N}{\\mathrm{df}(t)}\" style=\"width:40.45ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/555e615abfdacbc0.svg\" alt=\"\\mathrm{TFIDF}(t,d)=\\mathrm{TF}(t,d)\\,\\mathrm{IDF}(t)\" style=\"width:29.758ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(t,d) is the number of occurrences of term t in document d. df(t) is the number of documents containing t, not its total token count. N is the number of documents. IDF downweights terms shared by many documents.</p><h3>Solution</h3><h3>Step 1. Clean and list the tokens</h3><p>A: student, read, science, book, library.<br>B: teacher, read, history, book, classroom. Each retained token appears once in its sentence.</p><h3>Step 2. Fix one common vocabulary order</h3><p>student, read, science, book, library, teacher, history, classroom. Each row must refer to the same term in both documents.</p><h3>Step 3. Count document frequency and calculate IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term type</th><th>df</th><th>IDF calculation</th></tr></thead><tbody><tr><td>read, book</td><td>2</td><td>ln(2/2) = ln(1) = 0</td></tr><tr><td>Every other term</td><td>1</td><td>ln(2/1) = ln(2) ≈ 0.693147</td></tr></tbody></table></div><p>A term absent from a document has TF = 0. A present term has TF = 1 here.</p><h3>Step 4. Multiply TF by IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>TF in A</th><th>TF in B</th><th>IDF</th><th>TF–IDF A</th><th>TF–IDF B</th></tr></thead><tbody><tr><td>student</td><td>1</td><td>0</td><td>0.693147</td><td>0.693147</td><td>0</td></tr><tr><td>read</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>science</td><td>1</td><td>0</td><td>0.693147</td><td>0.693147</td><td>0</td></tr><tr><td>book</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>library</td><td>1</td><td>0</td><td>0.693147</td><td>0.693147</td><td>0</td></tr><tr><td>teacher</td><td>0</td><td>1</td><td>0.693147</td><td>0</td><td>0.693147</td></tr><tr><td>history</td><td>0</td><td>1</td><td>0.693147</td><td>0</td><td>0.693147</td></tr><tr><td>classroom</td><td>0</td><td>1</td><td>0.693147</td><td>0</td><td>0.693147</td></tr></tbody></table></div><h3>Step 5. Interpret the weights</h3><p>A is distinguished by student, science and library. B is distinguished by teacher, history and classroom. “read” and “book” have zero IDF in this tiny unsmoothed two-document collection because they appear in every document; that does not mean those words are meaningless in English.</p><h3>Final answer</h3><p>All six document-specific terms receive <strong>0.693147</strong> in their own document and 0 in the other. Shared read and book receive 0 in both.</p><p class=\"memory\"><strong>Yaad rakho:</strong> TF: is document mein kitni baar? IDF: kitne documents mein common? Rare-across-documents term ko zyada weight.</p><p>If normalized TF is explicitly requested, divide each present-token count by five; each nonzero weight becomes 0.693147/5 = 0.1386294. Do not silently switch conventions.</p>","m2":false,"units":"2","marks":10},{"id":"final-2025-q5b","title":"Q5B · Naïve Bayes word-sense classification","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the sentence: “The bat hit the ball hard on the cricket field.” Two possible senses of “bat”: Sense 1: Bat (Sports equipment – cricket/baseball); Sense 2: Bat (Nocturnal flying mammal).<br><div class=\"table-wrap\"><table><thead><tr><th>Sentence ID</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>ball, cricket, score, stadium</td><td>Sports</td></tr><tr><td>2</td><td>night, cave, wings, fly</td><td>Animal</td></tr><tr><td>3</td><td>player, run, match, bat</td><td>Sports</td></tr><tr><td>4</td><td>nocturnal, vampire, insect</td><td>Animal</td></tr><tr><td>5</td><td>team, field, bowl, bat</td><td>Sports</td></tr><tr><td>6</td><td>dark, flying, cave, night</td><td>Animal</td></tr></tbody></table></div>a) Using the Naïve Bayes algorithm, classify the sense of “bat” in the given sentence. Apply Laplace Smoothing wherever applicable.<br>b) Discuss the significance of Laplace Smoothing in Naïve Bayes Classification. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>There are three Sports examples and three Animal examples. Treat training context lists as bag-of-words token counts. Exclude the ambiguous target “bat” from the test context. Use the fixed training vocabulary; ignore out-of-vocabulary test words hit and hard. The usable test features are ball, cricket and field.</p><h3>To find</h3><p>The posterior-score comparison for Sports and Animal, and the role of smoothing.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab6d19b2902f96bb.svg\" alt=\"\\mathrm{score}(s)=P(s)\\prod_{w\\in\\mathrm{context}}P(w\\mid s)\" style=\"width:31.469ex;height:4.819ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/df7198279b2281ba.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}\" style=\"width:23.102ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>P(s) is the class prior, C(w,s) counts occurrences of context word w in class s, Nₛ is the total number of context tokens in that class and V is the shared vocabulary size. Conditional independence lets us multiply word probabilities. The common denominator P(context) is unnecessary when only comparing classes.</p><h3>Solution</h3><h3>Step 1. Calculate the priors</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/979bfbb6524dbd77.svg\" alt=\"P(S)=\\frac36=0.5,\\qquad P(A)=\\frac36=0.5\" style=\"width:37.71ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 2. Count class tokens and vocabulary</h3><p>Sports has 4 + 4 + 4 = 12 tokens. Animal has 4 + 3 + 4 = 11 tokens. The shared training vocabulary has 20 distinct words: ball, cricket, score, stadium, player, run, match, bat, team, field, bowl, night, cave, wings, fly, nocturnal, vampire, insect, dark, flying. “bat”, “night” and “cave” repeat but count only once each towards V.</p><h3>Step 3. Look up each usable context word</h3><div class=\"table-wrap\"><table><thead><tr><th>Feature</th><th>Sports count</th><th>Animal count</th><th>P(word | Sports)</th><th>P(word | Animal)</th></tr></thead><tbody><tr><td>ball</td><td>1</td><td>0</td><td>(1+1)/(12+20) = 2/32</td><td>(0+1)/(11+20) = 1/31</td></tr><tr><td>cricket</td><td>1</td><td>0</td><td>2/32</td><td>1/31</td></tr><tr><td>field</td><td>1</td><td>0</td><td>2/32</td><td>1/31</td></tr></tbody></table></div><h3>Step 4. Multiply the Sports score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a90c8cf82da50b4f.svg\" alt=\"\\mathrm{score}(S)=0.5\\times\\frac2{32}\\times\\frac2{32}\\times\\frac2{32}=0.0001220703125\" style=\"width:51.601ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Multiply the Animal score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/118f04dc70642898.svg\" alt=\"\\mathrm{score}(A)=0.5\\times\\frac1{31}\\times\\frac1{31}\\times\\frac1{31}\\approx0.00001678359236\" style=\"width:52.969ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Compare the scores</h3><p>0.0001220703125 is greater than 0.00001678359236. Therefore select Sports. Optional normalization gives P(Sports | retained features) ≈ 0.87913; normalization is not needed for the decision.</p><h3>Final answer</h3><p>The intended sense is <strong>bat as sports equipment</strong>. Ball, cricket and field favour that sense.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pehle class prior, phir har context-word likelihood multiply; bigger score wali sense choose karo.</p><h3>Why Laplace smoothing matters</h3><p>Without smoothing, all three test features have zero count in Animal. One zero factor makes the entire class score zero, even if other evidence could support that class. Add-one smoothing assigns nonzero probability to every word in the defined vocabulary and redistributes probability mass. It does not mean every unseen word outside the vocabulary can be inserted without changing the vocabulary model.</p><h3>If following the supplied paper key exactly</h3><p>The key also multiplies probabilities for hit and hard using the same denominators 32 and 31. That convention produces Sports = 1.19209290 × 10⁻⁷ and Animal ≈ 1.74647163 × 10⁻⁸, again selecting Sports. Its treatment of out-of-vocabulary words is not a normalized fixed-vocabulary model. State your feature convention clearly; the complete calculation above uses a consistent fixed training vocabulary.</p>","m2":true,"units":"5","marks":10},{"id":"final-2025-q6a","title":"Q6A · Coreference, pronouns and Word2Vec","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Differentiate between co-reference resolution and pronoun resolution with suitable examples.<br>ii. Explain the working principle of the Continuous Bag of Words (CBOW) model and Skipgram model in Word2Vec. Illustrate how it predicts the target word from its surrounding context. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Coreference and pronoun resolution</h3><p><strong>Coreference resolution</strong> groups expressions that refer to the same entity, including names, descriptions and pronouns. <strong>Pronoun resolution</strong> identifies the referent of a pronoun; it is narrower in scope.</p><div class=\"table-wrap\"><table><thead><tr><th>Expression / task</th><th>Example</th></tr></thead><tbody><tr><td>Coreference cluster</td><td>“Dr Rao arrived. The surgeon opened her bag.” → {Dr Rao, the surgeon, her}</td></tr><tr><td>Pronoun resolution</td><td>For the same text, resolve “her” to Dr Rao.</td></tr><tr><td>Difference</td><td>Resolving the description “the surgeon” is coreference work even when no pronoun is involved.</td></tr></tbody></table></div><h3>ii. Word2Vec</h3><p>Word2Vec learns dense word embeddings by predicting words from local context. A dense embedding is a short learned list of real numbers for a word; words used in similar contexts can obtain related vectors. CBOW and Skip-gram use opposite prediction directions.</p><div class=\"table-wrap\"><table><thead><tr><th>Feature</th><th>CBOW</th><th>Skip-gram</th></tr></thead><tbody><tr><td>Input</td><td>Surrounding context words</td><td>One centre word</td></tr><tr><td>Prediction target</td><td>The centre word</td><td>Surrounding context words</td></tr><tr><td>Training example</td><td>[the, cat, on, the] → sat</td><td>sat → the; sat → cat; sat → on; sat → the</td></tr><tr><td>Representation</td><td>Combine context embeddings, often by averaging</td><td>Use the centre-word embedding for each context prediction</td></tr></tbody></table></div><p>Example sentence: “The cat sat on the mat.” With a radius-two window around sat, the context is [The, cat, on, the]. In CBOW, obtain the four context embeddings, average or sum them, calculate scores for vocabulary words, and train the model to assign high probability to sat. In Skip-gram, use sat as input and create four centre–context training pairs.</p><div class=\"flow\"><span class=\"flow-box\">CBOW: nearby words</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">combine embeddings</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">predict centre word</span></div><div class=\"flow\"><span class=\"flow-box\">Skip-gram: centre word</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">its embedding</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">predict nearby words</span></div><p>Training adjusts embedding parameters to improve prediction; the final word vectors are the learned representation. Thus the question’s phrase “predicts the target word from surrounding context” describes CBOW specifically; Skip-gram reverses that direction.</p><p class=\"memory\"><strong>Yaad rakho:</strong> CBOW: neighbours se centre. Skip-gram: centre se neighbours.</p>","m2":false,"units":"5,6","marks":10},{"id":"final-2025-q6b","title":"Q6B · Hobbs: Ravi and Suresh","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain Hobb’s Algorithm. Discuss the steps with help of example and state its limitation.<br>ii. Sentence: Ravi met Suresh at the station after he arrived from Delhi. Using Hobbs’ algorithm, determine the most likely antecedent of the pronoun “he”. Show the steps of traversal according to the algorithm. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Method</h3><p><strong>Hobbs’ algorithm</strong> is a syntax-based pronoun-resolution procedure that searches constituency parse trees in a specified order. It proposes noun phrases as antecedents and filters incompatible candidates, for example by number and gender agreement.</p><p><strong>Read the tree labels first:</strong> NP means noun phrase; S means sentence/clause; VP means verb phrase. X is the current NP or S search node, and p is the upward path used to reach it. Breadth-first means shallower nodes before deeper nodes; left-to-right fixes the order at the same depth. An N-bar (N′) node is the noun-centred part of an NP in a parse using that label.</p><h3>Complete ordered procedure</h3><ol><li><strong>Locate the pronoun.</strong> Start at the NP immediately dominating the pronoun: the smallest NP containing it.</li><li><strong>Make the first climb.</strong> Move upward to the first NP or S above the starting NP. Call it X and record the path p.</li><li><strong>Search initially to the left.</strong> Traverse branches below X to the left of p, breadth-first and left-to-right. Propose an NP only if another NP or S lies between that candidate and X. Check agreement and other applicable constraints for each proposed candidate; accept the first eligible compatible one.</li><li><strong>Check the highest sentence.</strong> If X is the highest S and no candidate has been accepted, search previous sentence trees, most recent first. In each, traverse breadth-first and left-to-right and propose NPs. Accept the first eligible compatible candidate; if the available context contains none, report no resolved antecedent.</li><li><strong>Otherwise climb again.</strong> Move from X to the next NP or S above it. Make that node the new X and record the new upward path p.</li><li><strong>Test a higher NP.</strong> If the new X is an NP, propose X only when p did not pass through its nominal N-bar child. Apply the same compatibility checks. Use the labels in the supplied parse; do not invent a missing N-bar branch.</li><li><strong>Search left again.</strong> Traverse the new X’s branches to the left of p, breadth-first and left-to-right, proposing NPs. The extra intervening-NP/S requirement in Step 3 belongs to the initial search.</li><li><strong>Search permitted right branches.</strong> If X is an S, traverse branches to the right of p, breadth-first and left-to-right, but do not descend below any NP or S encountered. Propose the encountered eligible NPs and test their compatibility.</li><li><strong>Repeat or finish.</strong> Return to Step 4 until a compatible candidate is accepted or the available sentence trees are exhausted. Record the candidate order and why each candidate was accepted or rejected.</li></ol><p><strong>Why the initial restriction matters:</strong> in “John saw him”, the subject NP John is directly under the clause S, with no additional NP or S between them. Step 3 therefore does not propose John as the ordinary local antecedent of him. A reflexive such as himself is a different grammatical case. The worked question below shows the specific parse and traversal; selecting an antecedent is not simply choosing the nearest name.</p><h3>ii. Apply the method</h3><p><strong>Given:</strong> the pronoun he occurs as the subject of the subordinate clause “after he arrived from Delhi”. Assume that this clause is attached to the main verb phrase. The relevant main-clause NPs are Ravi, Suresh and the station.</p><p><strong>To find:</strong> the first eligible singular-male antecedent in Hobbs’ syntactic search order.</p><pre tabindex=\"0\" aria-label=\"Assumed constituent tree for Ravi, Suresh and he\">S (main)\n├── NP: Ravi                    ← first higher-left candidate\n└── VP\n    ├── VP: met [NP Suresh] at [NP the station]\n    └── SBAR: after\n        └── S (embedded)        ← first X\n            ├── NP: he          ← start\n            └── VP: arrived from Delhi</pre><h3>Step 1. Start at the pronoun NP</h3><p>Locate NP “he” inside the after-clause. Move to that clause’s S node. No earlier noun phrase in this small clause provides a candidate.</p><h3>Step 2. Move to the higher sentence</h3><p>The embedded S is not the highest S, so Step 5 climbs through SBAR and VP to the main S. Step 7 now searches to the left of that new path. This is the later left search, so the extra initial-search restriction from Step 3 is not imposed again.</p><h3>Step 3. Examine candidates in structural order</h3><p>The main subject NP Ravi is encountered before the deeper object NP Suresh in the relevant breadth-first search. Ravi is singular and compatible with “he”. “the station” would fail the ordinary person constraint.</p><h3>Step 4. Choose the first compatible candidate</h3><p>Select Ravi under the assumed parse and agreement settings. Suresh remains a possible interpretation in ordinary language, but the syntactic preference chooses Ravi first.</p><h3>Limitations</h3><ul><li>The result depends on the accuracy and attachment choices of the parse tree.</li><li>Syntactic ordering alone does not model all semantic plausibility, discourse focus or world knowledge.</li><li>Agreement can eliminate candidates but cannot distinguish two compatible male singular people.</li><li>Long-distance references and sentences with multiple possible parses can remain ambiguous.</li></ul><p><strong>Final answer:</strong> Hobbs’ syntactic preference is <strong>Ravi</strong> for this analysis. This is an algorithmic selection, not proof of the speaker’s intended referent.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Nearest naam blindly nahi: tree ki search order aur agreement follow karo.</p>","m2":false,"units":"6","marks":10},{"id":"final-2025-q7a","title":"Q7A · Text classification pipeline","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain the working of text classification in Natural Language Processing (NLP) and discuss the key steps involved in building a text classification system in context of real-world applications such as spam detection or news categorization. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Text classification</strong> assigns one or more predefined labels to a document or message based on its content. In spam detection the labels may be spam and not-spam; in news categorization they may be sports, business and politics.</p><div class=\"flow\"><span class=\"flow-box\">Labelled text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Prepare and split data</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Represent text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Train classifier</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Evaluate</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Classify new text</span></div><ol><li><strong>Define the labels and task.</strong> Decide whether each text gets one label or multiple labels. Establish what counts as spam so annotators use a consistent rule.</li><li><strong>Collect and label representative examples.</strong> Gather messages from the intended application and assign reliable labels. Include enough examples of each class and protect private information.</li><li><strong>Split training, validation and test data.</strong> Use training data to learn, validation data to choose settings and an untouched test set for final evaluation. Keep duplicate or closely related texts from leaking between splits.</li><li><strong>Preprocess consistently.</strong> Tokenize and normalize only as appropriate. In spam detection, URLs, currency symbols and capitalisation may contain useful information.</li><li><strong>Create features.</strong> A classical baseline uses BoW or TF–IDF. A neural system may use embeddings or a pretrained contextual model. Fit the vocabulary and IDF on training data only.</li><li><strong>Train a classifier.</strong> For example, multinomial Naïve Bayes estimates class priors and word likelihoods; logistic regression learns a decision boundary. Training uses the labelled examples.</li><li><strong>Evaluate.</strong> Inspect a confusion matrix, precision, recall and F1 as well as accuracy. False spam flags may hide legitimate mail, so the costs of errors matter.</li><li><strong>Deploy and monitor.</strong> Apply the same preprocessing and feature mapping to new texts. Monitor changing vocabulary and error patterns, and retrain when suitable new labelled data becomes available.</li></ol><h3>Example prediction</h3><p>A message such as “Claim your free prize now” is transformed into its feature representation. The classifier compares the evidence for the two labels and outputs spam if its decision score crosses the chosen threshold. The label comes from learned patterns; the mere presence of one word should not be treated as a universally correct rule.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Labelled examples → features → model → evaluation → new text ka label.</p>","m2":false,"units":"7","marks":10},{"id":"final-2025-q7b","title":"Q7B · Corpora and Jaccard similarity","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Differentiate between a flat text corpus and an annotated corpus, and discuss how each can be applied in various NLP tasks with suitable examples.<br>ii. Explain a real-world scenario where the Jaccard Similarity measure is more appropriate than Euclidean or Manhattan distance, and justify why Jaccard is the best choice in that case. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Flat and annotated corpora</h3><p>A <strong>corpus</strong> is a collection of language data. A flat text corpus stores text without the linguistic labels needed by a particular task. An annotated corpus adds labels or structure such as POS tags, entity spans, parse trees or sentence sentiment.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Flat text corpus</th><th>Annotated corpus</th></tr></thead><tbody><tr><td>Example</td><td>A collection of plain news articles</td><td>The same articles with PERSON/ORG spans marked</td></tr><tr><td>Information</td><td>The original text and possibly simple metadata</td><td>Text plus explicit task-related linguistic labels</td></tr><tr><td>Applications</td><td>Word frequency, collocations and unsupervised language-model training</td><td>Supervised POS tagging, NER or parser training and evaluation</td></tr><tr><td>Preparation</td><td>Relatively inexpensive to gather, but still needs cleaning</td><td>Requires annotation guidelines, labour and quality checks</td></tr></tbody></table></div><p>“Flat” describes the lack of the annotations being discussed, not an absence of all file organization. Both corpus types may still have document boundaries and metadata.</p><h3>ii. Jaccard in a set-based application</h3><p>Consider recommending articles using their topic-tag sets. Article A has {AI, NLP, ethics}; article B has {AI, NLP, healthcare}. We care about overlap among present tags, not how many irrelevant tags are absent from both.</p><h3>Given</h3><p>A = {AI, NLP, ethics}; B = {AI, NLP, healthcare}.</p><h3>To find</h3><p>The fraction of distinct present tags shared by the articles.</p><h3>Formula and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0eeb7c5512da08e8.svg\" alt=\"J(A,B)=\\frac{|A\\cap B|}{|A\\cup B|}\" style=\"width:18.811ex;height:5.471ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The intersection counts common items; the union counts all distinct items present in either set.</p><h3>Step 1. Find common tags</h3><p>A ∩ B = {AI, NLP}, so the intersection size is 2.</p><h3>Step 2. Find all distinct present tags</h3><p>A ∪ B = {AI, NLP, ethics, healthcare}, so the union size is 4.</p><h3>Step 3. Divide</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b91de05a3cafb1a8.svg\" alt=\"J(A,B)=\\frac24=0.5\" style=\"width:18.665ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Jaccard directly measures proportional overlap and ignores joint absences. Euclidean or Manhattan distance on binary tag vectors counts mismatches but does not by itself normalize by the union size. If frequency or magnitude were meaningful, those distance measures could be more appropriate. Here, membership-only tags and sparse sets make Jaccard a suitable choice.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Jaccard: common present items / total distinct present items.</p>","m2":false,"units":"2,3","marks":10}]},{"id":"reexam-2026","title":"Solved re-exam · February 2026","unit":"PYQ","scope":"Actual re-examination · 9 February 2026 · 100 marks · 3 hours","sections":[{"id":"reexam-2026-q1a","title":"Q1A · Generic NLP pipeline","html":"<div class=\"question\" style=\"font-weight:700\">Question. Draw block diagram of generic NLP pipeline and explain the task associated with each block. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>An NLP pipeline is an ordered workflow that transforms language data into a task-specific result. The exact components depend on the application; a generic supervised pipeline is shown below.</p><div class=\"flow\"><span class=\"flow-box\">Collect text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Clean and preprocess</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Represent text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Train / apply model</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Evaluate and deliver output</span></div><div class=\"table-wrap\"><table><thead><tr><th>Block</th><th>Task</th><th>Example for sentiment analysis</th></tr></thead><tbody><tr><td>Data acquisition</td><td>Collect representative text and any required labels</td><td>Reviews labelled positive or negative</td></tr><tr><td>Cleaning and preprocessing</td><td>Handle noise, tokenize and normalize appropriately</td><td>Remove HTML while preserving “not”</td></tr><tr><td>Text representation</td><td>Convert tokens into usable model features</td><td>TF–IDF values or contextual embeddings</td></tr><tr><td>Modeling</td><td>Learn patterns from training data and predict new labels</td><td>Train a classifier on labelled review features</td></tr><tr><td>Evaluation</td><td>Measure performance on unseen held-out data and inspect errors</td><td>Precision, recall, F1 and confusion matrix</td></tr><tr><td>Deployment and feedback</td><td>Deliver predictions and monitor changing data</td><td>Show review sentiment and monitor new product vocabulary</td></tr></tbody></table></div><p>Training/validation/test separation must precede fitting the learned preprocessing and feature statistics. New inputs must use the same feature mapping as training. Not every task uses every linguistic level explicitly: a modern end-to-end model may combine several operations internally.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Text lo → prepare karo → numbers banao → model lagao → result check aur use karo.</p>","m2":false,"units":"1","marks":5},{"id":"reexam-2026-q1b","title":"Q1B · Content and function words","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Define function words and content words.<br>ii. Which category (function words and content words) belong to open class and closed class? Justify your answer.<br>iii. For the sentence “The small cat is sleeping under the tree”, identify the function words and content words. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Content words</strong> carry much of a sentence’s lexical meaning, usually including nouns, main verbs, adjectives and many adverbs. <strong>Function words</strong> primarily express grammatical relationships, including determiners, prepositions, conjunctions, pronouns and auxiliary verbs.</p><div class=\"table-wrap\"><table><thead><tr><th>Category</th><th>Typical class</th><th>Reason</th></tr></thead><tbody><tr><td>Content words</td><td>Open class</td><td>New nouns, verbs and adjectives enter the language readily, such as new technology names</td></tr><tr><td>Function words</td><td>Closed class</td><td>The grammatical inventory is relatively stable; new determiners or pronouns are much less frequently added</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Role in this sentence</th><th>Category</th></tr></thead><tbody><tr><td>The</td><td>Determiner</td><td>Function</td></tr><tr><td>small</td><td>Adjective</td><td>Content</td></tr><tr><td>cat</td><td>Noun</td><td>Content</td></tr><tr><td>is</td><td>Auxiliary supporting progressive tense</td><td>Function</td></tr><tr><td>sleeping</td><td>Main verb</td><td>Content</td></tr><tr><td>under</td><td>Preposition</td><td>Function</td></tr><tr><td>the</td><td>Determiner</td><td>Function</td></tr><tr><td>tree</td><td>Noun</td><td>Content</td></tr></tbody></table></div><p><strong>Final answer:</strong> content words = small, cat, sleeping, tree; function words = The, is, under, the. “is” is auxiliary here; a word’s role must be judged in context. “Closed” means relatively resistant to new members, not that change is logically impossible.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Content words scene batate hain; function words grammar ka connection banate hain.</p>","m2":true,"units":"4","marks":5},{"id":"reexam-2026-q1c","title":"Q1C · Word2Vec and GloVe","html":"<div class=\"question\" style=\"font-weight:700\">Question. Differentiate between word2vec and GloVe in terms of their learning strategies. Which type of corpus would be more suitable for each method, and why? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>Both Word2Vec and GloVe learn dense word vectors from distributional information: words occurring in related contexts tend to receive related representations. They differ mainly in the training objective and how corpus co-occurrence evidence is used.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Word2Vec</th><th>GloVe</th></tr></thead><tbody><tr><td>Learning strategy</td><td>Predictive: CBOW predicts a centre word; Skip-gram predicts nearby words</td><td>Count-based objective fitted to global word–context co-occurrence statistics</td></tr><tr><td>Training evidence</td><td>Local context windows converted into prediction examples</td><td>A corpus-wide co-occurrence matrix and relationships among counts</td></tr><tr><td>Parameters learned</td><td>Word/context embeddings that make context predictions accurate</td><td>Word/context embeddings and biases that fit weighted log co-occurrence counts</td></tr><tr><td>Corpus considerations</td><td>Large token sequences with useful local context, including domain-specific text</td><td>A sufficiently large corpus from which reliable global co-occurrence statistics can be collected</td></tr></tbody></table></div><p>For a domain such as medicine, either method can benefit from a representative medical corpus. Word2Vec is convenient when generating local training windows directly from a stream of tokens. GloVe is natural when a global sparse co-occurrence matrix can be constructed and stored. Corpus size, domain match, preprocessing and available compute matter; there is no rule that Word2Vec requires informal text while GloVe requires formal text.</p><p>Both standard forms produce one static vector per vocabulary word, so multiple senses are blended. They do not automatically provide a different vector for the same word in each sentence.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Word2Vec predicts local neighbours; GloVe fits global co-occurrence counts.</p>","m2":false,"units":"5","marks":5},{"id":"reexam-2026-q1d","title":"Q1D · Anaphora, cataphora and coreference","html":"<div class=\"question\" style=\"font-weight:700\">Question. Differentiate between cataphora and anaphora in terms of direction of reference. How coreference resolution is different from anaphora reference? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Anaphora</strong> points backward to an expression or information introduced earlier. <strong>Cataphora</strong> points forward to an expression introduced later.</p><div class=\"table-wrap\"><table><thead><tr><th>Relation</th><th>Example</th><th>Direction</th></tr></thead><tbody><tr><td>Anaphora</td><td>“Riya arrived. She smiled.” She refers to the earlier Riya.</td><td>Backward</td></tr><tr><td>Cataphora</td><td>“Before she spoke, Riya checked the microphone.” She refers to the later Riya.</td><td>Forward</td></tr></tbody></table></div><p><strong>Coreference</strong> means two or more expressions refer to the same entity. Coreference resolution groups such expressions, regardless of whether they are names, descriptions or pronouns and regardless of which is mentioned first.</p><p>For “Dr Sen arrived. The surgeon smiled. She waved,” {Dr Sen, the surgeon, She} is a coreference cluster. The latter two mentions are also backward-looking references. Coreference is an identity relation; anaphora describes a dependency on prior discourse and is not always identity. For example, “I bought a house. The roof leaks” contains a bridging reference: the roof depends on the house for interpretation, but roof and house are not the same entity.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Ana = pehle ki taraf; cata = aage ki taraf; coreference = same entity.</p>","m2":false,"units":"6","marks":5},{"id":"reexam-2026-q2a","title":"Q2A · NLP tasks and syntax versus semantics","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Discuss five different tasks associated with Natural Language Processing.<br>ii. Compare and contrast syntactic analysis and semantic analysis in NLP. Support your explanation with examples. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Five NLP tasks</h3><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>What it does</th><th>Example</th></tr></thead><tbody><tr><td>Machine translation</td><td>Expresses source-language content in a target language</td><td>English “Good morning” → Hindi greeting</td></tr><tr><td>Sentiment analysis</td><td>Identifies the opinion or attitude expressed</td><td>“The service was excellent” → positive sentiment</td></tr><tr><td>Named Entity Recognition</td><td>Finds and types entity spans</td><td>“Asha joined Google” → PERSON and ORGANIZATION</td></tr><tr><td>Question answering</td><td>Returns an answer supported by a question’s relevant information</td><td>From a passage, identify who discovered a described result</td></tr><tr><td>Text classification</td><td>Assigns predefined category labels</td><td>Classify an email as spam or legitimate</td></tr></tbody></table></div><h3>ii. Syntactic and semantic analysis</h3><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Syntactic analysis</th><th>Semantic analysis</th></tr></thead><tbody><tr><td>Main question</td><td>How are words grammatically organised?</td><td>What do the words and sentence mean?</td></tr><tr><td>Typical output</td><td>POS tags, constituency or dependency structure</td><td>Word senses, semantic relations or a meaning representation</td></tr><tr><td>Knowledge used</td><td>Grammar rules and structural patterns</td><td>Lexical meaning, context and semantic constraints</td></tr><tr><td>Example</td><td>Identify “The boy” as subject NP and “ate an apple” as VP</td><td>Interpret the boy as eater and apple as the thing eaten</td></tr></tbody></table></div><p>“Colourless green ideas sleep furiously” can have a plausible English grammatical structure while remaining semantically unusual. Syntax alone therefore does not guarantee ordinary meaning. Conversely, “boy eat apple yesterday” conveys a possible event despite grammatical errors.</p><p>The analyses support each other. In “I saw the man with a telescope,” syntactic PP attachment determines which meaning is available, and semantic knowledge can help choose a plausible attachment. A full NLP system often needs both.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Syntax = sentence ka structure; semantics = us structure ka meaning.</p>","m2":false,"units":"1,4,5","marks":10},{"id":"reexam-2026-q2b","title":"Q2B · Laplace smoothing on a second corpus","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following training corpus:<br>1. cats chase mice in the garden<br>2. dogs bark loudly at night<br>3. birds sing in the morning<br>4. children play games in the park<br>Using a bigram language model with Laplace smoothing, evaluate the probability of the test sentence: “cats bark in the park.” Assume &lt;s&gt; and &lt;/s&gt; as start and end of the sentence. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><ul><li>cats chase mice in the garden</li><li>dogs bark loudly at night</li><li>birds sing in the morning</li><li>children play games in the park</li></ul><p>Test: cats bark in the park. Add one start token &lt;s&gt; and one end token &lt;/s&gt; to every training and test sentence.</p><h3>To find</h3><p>The Laplace-smoothed bigram probability of the complete test sentence, including its end token.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0167293b8abe1cce.svg\" alt=\"P_{+1}(w_i\\mid w_{i-1})=\\frac{C(w_{i-1},w_i)+1}{C(w_{i-1})+V}\" style=\"width:33.254ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(previous,current) counts that adjacent pair in the training corpus. C(previous) counts its occurrences as a history. V is the vocabulary size. Add-one smoothing is necessary because an unseen pair must not force the whole sentence probability to zero.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/09cc94e28baa5a90.svg\" alt=\"P(w_1,\\ldots,w_n,\\langle/s\\rangle\\mid\\langle s\\rangle)=\\prod_{i=1}^{n+1}P(w_i\\mid w_{i-1})\" style=\"width:42.048ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Fix the token and vocabulary convention</h3><p>Lowercase words and remove the final punctuation. The supplied course key counts both boundary tokens in V. Following that convention: at, bark, birds, cats, chase, children, dogs, games, garden, in, loudly, mice, morning, night, park, play, sing, the, &lt;s&gt;, &lt;/s&gt; gives <strong>V = 20</strong>. The start marker supplies history; it is not an extra probability factor before the first word.</p><h3>Step 2. List every required transition</h3><p>The complete test chain is &lt;s&gt; → cats → bark → in → the → park → &lt;/s&gt;.</p><h3>Step 3. Count first, then add one</h3><div class=\"table-wrap\"><table><thead><tr><th>Required bigram</th><th>History count</th><th>Pair count</th><th>Smoothed probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → cats</td><td>4</td><td>1</td><td>(1+1)/(4+20) = 1/12</td></tr><tr><td>cats → bark</td><td>1</td><td>0</td><td>(0+1)/(1+20) = 1/21</td></tr><tr><td>bark → in</td><td>1</td><td>0</td><td>(0+1)/(1+20) = 1/21</td></tr><tr><td>in → the</td><td>3</td><td>3</td><td>(3+1)/(3+20) = 4/23</td></tr><tr><td>the → park</td><td>3</td><td>1</td><td>(1+1)/(3+20) = 2/23</td></tr><tr><td>park → &lt;/s&gt;</td><td>1</td><td>1</td><td>(1+1)/(1+20) = 2/21</td></tr></tbody></table></div><p>Count only adjacent words, never words that merely appear in the same sentence. The unseen pairs have count zero, so their numerator becomes one.</p><h3>Step 4. Multiply all six probabilities</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/661dddaa8d668f4e.svg\" alt=\"P=\\frac{2}{24}\\times\\frac{1}{21}\\times\\frac{1}{21}\\times\\frac{4}{23}\\times\\frac{2}{23}\\times\\frac{2}{21}\" style=\"width:38.092ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. &lt;s&gt; → cats</td><td><span class=\"math-inline\"><img src=\"math/9cf9ede86d758f1a.svg\" alt=\"1\\times\\frac{1}{12}=\\frac{1}{12}\" style=\"width:12.105ex;height:2.737ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. cats → bark</td><td><span class=\"math-inline\"><img src=\"math/15653088bc649e84.svg\" alt=\"\\frac{1}{12}\\times\\frac{1}{21}=\\frac{1}{252}\" style=\"width:14.368ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. bark → in</td><td><span class=\"math-inline\"><img src=\"math/bc2636bde4d927d0.svg\" alt=\"\\frac{1}{252}\\times\\frac{1}{21}=\\frac{1}{5292}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. in → the</td><td><span class=\"math-inline\"><img src=\"math/5be8f2428aa87996.svg\" alt=\"\\frac{1}{5292}\\times\\frac{4}{23}=\\frac{1}{30429}\" style=\"width:17.568ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. the → park</td><td><span class=\"math-inline\"><img src=\"math/5c01b946da36062b.svg\" alt=\"\\frac{1}{30429}\\times\\frac{2}{23}=\\frac{2}{699867}\" style=\"width:19.168ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. park → &lt;/s&gt;</td><td><span class=\"math-inline\"><img src=\"math/aa10a9e9b5ec1f5a.svg\" alt=\"\\frac{2}{699867}\\times\\frac{2}{21}=\\frac{4}{14697207}\" style=\"width:21.568ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/84afc176da8ea9ec.svg\" alt=\"P=\\frac{4}{14697207}\\approx 2.72160554\\times10^{-7}\" style=\"width:35.849ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Interpret the result</h3><p>This is a joint sentence probability, so a small value is normal. Do not add transition probabilities; each word must occur in sequence, so the chain multiplies them.</p><h3>Final answer</h3><p><strong>P ≈ 2.72160554 × 10<sup>-7</sup></strong> with the stated course vocabulary convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pair count mein 1 jodo, previous-word count mein V; phir saare fractions multiply karo.</p><p><strong>Convention note:</strong> Some implementations exclude &lt;s&gt; from the predicted vocabulary. Their V is one smaller and their numerical probability differs. In an exam, state V explicitly and follow the convention specified in the question or class solution.</p>","m2":true,"units":"3","marks":10},{"id":"reexam-2026-q3a","title":"Q3A · Top-down parsing","html":"<div class=\"question\" style=\"font-weight:700\">Question. In the context of natural language processing, explain the concept of top-down and bottom-up parsing approaches. Apply top-down syntax parsing approach to the sentence “The tall boy saw a girl in the park.” and draw a parse tree using the CFG grammar rules:<br>S → NP VP; NP → Det Adj N | Det N; VP → V NP | VP PP; PP → P NP.<br>Lexicon: Det → {the | a}; Adj → {tall}; N → {boy | girl | park}; V → {saw}; P → {in}. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Top-down</th><th>Bottom-up</th></tr></thead><tbody><tr><td>Start</td><td>The start symbol S</td><td>The input words</td></tr><tr><td>Operation</td><td>Expand a nonterminal using grammar productions</td><td>Combine words and constituents using productions in reverse</td></tr><tr><td>Success</td><td>Leaves match the complete input</td><td>All input is reduced to S</td></tr><tr><td>Possible difficulty</td><td>Naive recursive descent can loop on left recursion or need backtracking</td><td>A naive shift-reduce parser may face shift/reduce conflicts</td></tr></tbody></table></div><h3>Given</h3><p>The sentence contains the tokens the / tall / boy / saw / a / girl / in / the / park. Lowercase the initial “The” to match the lexicon. The full stop is punctuation outside the listed grammar.</p><h3>To find</h3><p>A derivation beginning at S and a parse tree matching the whole sentence.</p><h3>Rule: which one and why</h3><p>A context-free production replaces one nonterminal with its right-hand sequence. A top-down derivation begins at S and expands the desired structure. The supplied grammar attaches the PP through VP → VP PP; it does not provide NP → NP PP.</p><h3>Step 1. Expand the sentence</h3><p>S ⇒ NP VP. Choose NP → Det Adj N for “the tall boy”.</p><h3>Step 2. Match the subject words</h3><p>Det ⇒ the, Adj ⇒ tall, N ⇒ boy. The remaining material must be generated by VP.</p><h3>Step 3. Allow a verb phrase followed by a PP</h3><p>Expand the outer VP using VP → VP PP. Then expand the inner VP using VP → V NP. This finite derivation selects the recursive rule once.</p><h3>Step 4. Match the verb and object</h3><p>V ⇒ saw. Choose NP → Det N, then Det ⇒ a and N ⇒ girl.</p><h3>Step 5. Expand the prepositional phrase</h3><p>PP ⇒ P NP. P ⇒ in. NP ⇒ Det N, with Det ⇒ the and N ⇒ park.</p><h3>Step 6. Check the complete leaf order</h3><p>The leaves read “the tall boy saw a girl in the park”, exactly the normalized input. The PP “in the park” attaches to the VP under this supplied grammar.</p><figure><svg viewBox=\"0 0 820 350\" role=\"img\" aria-label=\"Top-down parse tree showing the PP attached to VP\" style=\"width:100%;max-width:820px;background:#f4f8f7\"><line x1=\"370\" y1=\"38\" x2=\"150\" y2=\"60\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"370\" y1=\"38\" x2=\"560\" y2=\"60\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"55\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"135\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"215\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"560\" y1=\"88\" x2=\"420\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"560\" y1=\"88\" x2=\"650\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"420\" y1=\"143\" x2=\"350\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"420\" y1=\"143\" x2=\"470\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"650\" y1=\"143\" x2=\"575\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"650\" y1=\"143\" x2=\"705\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"470\" y1=\"198\" x2=\"440\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"470\" y1=\"198\" x2=\"500\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"705\" y1=\"198\" x2=\"660\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"705\" y1=\"198\" x2=\"750\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"55\" y1=\"143\" x2=\"55\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"135\" y1=\"143\" x2=\"135\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"215\" y1=\"143\" x2=\"215\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"350\" y1=\"198\" x2=\"350\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"440\" y1=\"248\" x2=\"440\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"500\" y1=\"248\" x2=\"500\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"575\" y1=\"198\" x2=\"575\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"660\" y1=\"248\" x2=\"660\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"750\" y1=\"248\" x2=\"750\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><text x=\"370\" y=\"30\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">S</text><text x=\"150\" y=\"80\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"560\" y=\"80\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"55\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"135\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Adj</text><text x=\"215\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"420\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"650\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">PP</text><text x=\"350\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">V</text><text x=\"470\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"575\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">P</text><text x=\"705\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"440\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"500\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"660\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"750\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"55\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">The</text><text x=\"135\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">tall</text><text x=\"215\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">boy</text><text x=\"350\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">saw</text><text x=\"440\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">a</text><text x=\"500\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">girl</text><text x=\"575\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">in</text><text x=\"660\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">the</text><text x=\"750\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">park</text></svg><figcaption>Top-down parse tree showing the PP attached to VP.</figcaption></figure><h3>Complete derivation</h3><p>S ⇒ NP VP ⇒ Det Adj N VP ⇒ the tall boy VP ⇒ the tall boy VP PP ⇒ the tall boy V NP PP ⇒ the tall boy saw Det N PP ⇒ the tall boy saw a girl P NP ⇒ the tall boy saw a girl in Det N ⇒ the tall boy saw a girl in the park.</p><p><strong>Implementation caution:</strong> VP → VP PP is left-recursive. A naive recursive-descent implementation may loop; it must transform or otherwise handle the grammar. A valid finite top-down derivation, as shown above, still exists.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Rule jo diya hai wahi use karo: yahan “in the park” VP ka part hai.</p>","m2":true,"units":"4","marks":10},{"id":"reexam-2026-q3b","title":"Q3B · Lesk word-sense disambiguation","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the sentence: “The bank can ensure your deposits are safe.” The word “bank” has the following two possible senses (WordNet-style glosses):<br>Bank₁: Sloping land especially beside a body of water.<br>Bank₂: A financial institution that accepts deposits and channels the money into lending activities.<br>i. Apply the LESK algorithm to determine the correct sense of the word “bank” in the given sentence. Show the steps clearly.<br>ii. Briefly discuss limitations of the LESK algorithm in handling ambiguous words in real-world contexts. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Context sentence and the two supplied dictionary glosses. Use a simplified Lesk method: lowercase, remove function words, exclude the target bank and compare distinct content-word overlap. Do not add synonyms that the question does not supply.</p><h3>To find</h3><p>Which candidate gloss has the greatest overlap with the local context.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6ad61c84bee7b920.svg\" alt=\"\\mathrm{score}(s)=|C\\cap G_s|,\\qquad \\hat s=\\arg\\max_s\\mathrm{score}(s)\" style=\"width:44.428ex;height:3.457ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C is the set of context content words. Gₛ is the content-word set of the gloss for sense s. The intersection contains words appearing in both; its size is the score. This is an overlap count, not a probability.</p><h3>Solution</h3><h3>Step 1. Prepare the context</h3><p>Remove The, can, your, are and the target bank. A reasonable content set is C = {ensure, deposits, safe}. If “can” is retained under another fixed stop-list it matches neither gloss and does not change the result.</p><h3>Step 2. Prepare Bank₁’s gloss</h3><p>G₁ = {sloping, land, especially, beside, body, water}. There is no shared word with {ensure, deposits, safe}.</p><h3>Step 3. Calculate Bank₁’s score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bdca68bf983394ca.svg\" alt=\"C\\cap G_1=\\varnothing,\\qquad \\mathrm{score}(1)=0\" style=\"width:29.266ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Prepare Bank₂’s gloss and count overlap</h3><p>G₂ = {financial, institution, accepts, deposits, channels, money, lending, activities}. The shared word is deposits.</p><h3>Step 5. Calculate Bank₂’s score and select</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0107901b24c804b2.svg\" alt=\"C\\cap G_2=\\{\\mathrm{deposits}\\},\\qquad \\mathrm{score}(2)=1\" style=\"width:37.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>1 > 0, so choose the financial-institution sense.</p><h3>Final answer</h3><p><strong>Bank₂: financial institution.</strong> The explicit overlap “deposits” supports this choice.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Lesk: context aur har meaning ki definition mein common words count karo; highest overlap choose karo.</p><h3>ii. Limitations</h3><ul><li>Short contexts or short glosses may produce no overlaps or ties.</li><li>Exact word matching misses related words and synonyms, such as deposit versus savings, unless an extension is defined.</li><li>Irrelevant frequent words can create misleading overlaps if preprocessing is poor.</li><li>Dictionary glosses may omit a domain-specific sense or fail to express the context’s wording.</li><li>Simplified Lesk uses limited local information and may miss discourse or real-world knowledge.</li></ul><p>Lemmatization, richer glosses and semantic similarity can improve variants, but the exact variant and tie-breaking rule should be stated.</p>","m2":true,"units":"5","marks":10},{"id":"reexam-2026-q4a","title":"Q4A · Bag of Words and three cosine similarities","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following three documents:<br>Document A: “The dog chased the cat.”<br>Document B: “The cat chased the mouse.”<br>Document C: “The dog ran after the cat.”<br>Using the Bag of Words (BoW) model, represent each document as a vector after removing the stop words {The, by, was}.<br>i. Construct the term-document matrix.<br>ii. Compute the cosine similarity between each pair of documents (A–B, A–C, and B–C).<br>iii. Interpret and comment on the results obtained in terms of document similarity. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Three documents. Lowercase and remove punctuation. Remove the specified stop words case-insensitively; “the” is removed everywhere. Keep “after” because it is not in the supplied stop list. Use raw word counts.</p><h3>To find</h3><p>A common-vocabulary count matrix, three cosine values and their interpretation.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0f69259be30dd3d0.svg\" alt=\"\\mathrm{BoW}_j(d)=C(v_j,d)\" style=\"width:19.466ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>vⱼ is vocabulary term j. The coordinate stores its count in document d; order in the sentence is not retained.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d47266edc91f0bb5.svg\" alt=\"\\cos(\\mathbf a,\\mathbf b)=\\frac{\\sum_j a_jb_j}{\\sqrt{\\sum_j a_j^2}\\sqrt{\\sum_j b_j^2}}\" style=\"width:28.501ex;height:7.827ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Clean each document</h3><p>A: dog chased cat.<br>B: cat chased mouse.<br>C: dog ran after cat.</p><h3>Step 2. Fix vocabulary and matrix</h3><p>Vocabulary: dog, chased, cat, mouse, ran, after.</p><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>A</th><th>B</th><th>C</th></tr></thead><tbody><tr><td>dog</td><td>1</td><td>0</td><td>1</td></tr><tr><td>chased</td><td>1</td><td>1</td><td>0</td></tr><tr><td>cat</td><td>1</td><td>1</td><td>1</td></tr><tr><td>mouse</td><td>0</td><td>1</td><td>0</td></tr><tr><td>ran</td><td>0</td><td>0</td><td>1</td></tr><tr><td>after</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><p>A = [1,1,1,0,0,0]; B = [0,1,1,1,0,0]; C = [1,0,1,0,1,1].</p><h3>Step 3. Calculate vector lengths</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0319d5a65cf344a9.svg\" alt=\"\\|A\\|=\\sqrt{1^2+1^2+1^2}=\\sqrt3\" style=\"width:27.25ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f3f38c6241a4b948.svg\" alt=\"\\|B\\|=\\sqrt{1^2+1^2+1^2}=\\sqrt3\" style=\"width:27.271ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a3902ff8f18f763e.svg\" alt=\"\\|C\\|=\\sqrt{1^2+1^2+1^2+1^2}=2\" style=\"width:30.228ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Calculate A–B</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7b652d0c42b280a1.svg\" alt=\"A\\cdot B=(1)(0)+(1)(1)+(1)(1)+(0)(1)+(0)(0)+(0)(0)=2\" style=\"width:60.739ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/905c4c3c1ff47cfe.svg\" alt=\"\\cos(A,B)=\\frac2{\\sqrt3\\sqrt3}=\\frac23\\approx0.666667\" style=\"width:36.051ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Calculate A–C</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0add9a13e11f4556.svg\" alt=\"A\\cdot C=(1)(1)+(1)(0)+(1)(1)+(0)(0)+(0)(1)+(0)(1)=2\" style=\"width:60.742ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/13f584cbebce7216.svg\" alt=\"\\cos(A,C)=\\frac2{\\sqrt3\\cdot2}=\\frac1{\\sqrt3}\\approx0.577350\" style=\"width:37.687ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Calculate B–C</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/00d6bb1eb81ee107.svg\" alt=\"B\\cdot C=(0)(1)+(1)(0)+(1)(1)+(1)(0)+(0)(1)+(0)(1)=1\" style=\"width:60.762ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b9b3f31b850daf8d.svg\" alt=\"\\cos(B,C)=\\frac1{\\sqrt3\\cdot2}\\approx0.288675\" style=\"width:30.634ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>A–B = 0.666667; A–C = 0.577350; B–C = 0.288675.</strong> A and B have the highest lexical overlap under this representation. B and C share only cat. BoW similarity reflects token overlap, not full semantic equivalence or word order.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same vocabulary order rakho. Corresponding counts multiply-add; phir dono lengths se divide.</p>","m2":false,"units":"2","marks":10},{"id":"reexam-2026-q4b","title":"Q4B · A second HMM sequence","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following POS tagged corpus. Apply Hidden Markov Model (HMM) approach to:<br>1. Dog/Noun eats/Verb bread/Noun<br>2. The/Det cat/Noun sleeps/Verb<br>3. A/Det dog/Noun eats/Verb fish/Noun<br>i. Construct the emission probability matrix.<br>ii. Construct the transmission probability matrix.<br>iii. Calculate the probability of the given sequence of events: The/Det dog/Noun eats/Verb bread/Noun.<br>Note: Include start and end characters for all the sentences. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>The repeated verb eats has a different emission count from the final paper; recalculate it rather than copying the previous numerical result.</p><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged sequence</th></tr></thead><tbody><tr><td>1</td><td>dog/Noun eats/Verb bread/Noun</td></tr><tr><td>2</td><td>the/Det cat/Noun sleeps/Verb</td></tr><tr><td>3</td><td>a/Det dog/Noun eats/Verb fish/Noun</td></tr></tbody></table></div><p>Lowercase the corpus. Test sequence: the/Det dog/Noun eats/Verb bread/Noun. Add Start and End markers.</p><h3>To find</h3><p>Emission and transition matrices, then the probability of the supplied tagged sequence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a732ea965eb9fa65.svg\" alt=\"P(w\\mid t)=\\frac{C(t,w)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8da165d58e49419c.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i,t_j)}{\\sum_kC(t_i,t_k)}\" style=\"width:24.245ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Emission divides the word’s tag-specific count by the total tokens with that tag. Transition divides the tag-pair count by all transitions leaving the previous tag, including End.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/054557fae74f519d.svg\" alt=\"P(\\mathbf w,\\mathbf t)=P(t_1\\mid\\mathrm{Start})\\prod_iP(w_i\\mid t_i)\\prod_{i=2}^{n}P(t_i\\mid t_{i-1})P(\\mathrm{End}\\mid t_n)\" style=\"width:60.981ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Count tag totals and word frequencies</h3><p>Det: the=1, a=1, total2. Noun: dog=2, bread=1, cat=1, fish=1, total5. Verb: eats=2, sleeps=1, total3.</p><h3>Step 2. Construct emission matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag / word</th><th>a</th><th>bread</th><th>cat</th><th>dog</th><th>eats</th><th>fish</th><th>sleeps</th><th>the</th></tr></thead><tbody><tr><td>Det</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1/2</td></tr><tr><td>Noun</td><td>0</td><td>1/5</td><td>1/5</td><td>2/5</td><td>0</td><td>1/5</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>0</td><td>0</td><td>0</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td><td>0</td></tr></tbody></table></div><h3>Step 3. Count transitions from the three chains</h3><p>Start → Noun → Verb → Noun → End<br>Start → Det → Noun → Verb → End<br>Start → Det → Noun → Verb → Noun → End</p><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Det count</th><th>Noun count</th><th>Verb count</th><th>End count</th><th>Total</th></tr></thead><tbody><tr><td>Start</td><td>2</td><td>1</td><td>0</td><td>0</td><td>3</td></tr><tr><td>Det</td><td>0</td><td>2</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3</td><td>2</td><td>5</td></tr><tr><td>Verb</td><td>0</td><td>2</td><td>0</td><td>1</td><td>3</td></tr></tbody></table></div><h3>Step 4. Divide outgoing counts</h3><div class=\"table-wrap\"><table><thead><tr><th>From / to</th><th>Det</th><th>Noun</th><th>Verb</th><th>End</th></tr></thead><tbody><tr><td>Start</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3/5</td><td>2/5</td></tr><tr><td>Verb</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td></tr></tbody></table></div><p>All nonterminal rows sum to one. No smoothing is requested.</p><h3>Step 5. Write every sequence factor</h3><div class=\"table-wrap\"><table><thead><tr><th>Event</th><th>Probability</th></tr></thead><tbody><tr><td>Start → Det</td><td>2/3</td></tr><tr><td>Det emits the</td><td>1/2</td></tr><tr><td>Det → Noun</td><td>1</td></tr><tr><td>Noun emits dog</td><td>2/5</td></tr><tr><td>Noun → Verb</td><td>3/5</td></tr><tr><td>Verb emits eats</td><td>2/3</td></tr><tr><td>Verb → Noun</td><td>2/3</td></tr><tr><td>Noun emits bread</td><td>1/5</td></tr><tr><td>Noun → End</td><td>2/5</td></tr></tbody></table></div><h3>Step 6. Multiply all factors</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2931148a79074475.svg\" alt=\"P=\\frac23\\times\\frac12\\times1\\times\\frac25\\times\\frac35\\times\\frac23\\times\\frac23\\times\\frac15\\times\\frac25\" style=\"width:44.987ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. Start → Det</td><td><span class=\"math-inline\"><img src=\"math/b32eeb64b6ce8d87.svg\" alt=\"1\\times\\frac{2}{3}=\\frac{2}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. Det emits the</td><td><span class=\"math-inline\"><img src=\"math/0e0cb943fc030998.svg\" alt=\"\\frac{2}{3}\\times\\frac{1}{2}=\\frac{1}{3}\" style=\"width:11.169ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. Det → Noun</td><td><span class=\"math-inline\"><img src=\"math/3b61cadbe8860930.svg\" alt=\"\\frac{1}{3}\\times1=\\frac{1}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. Noun emits dog</td><td><span class=\"math-inline\"><img src=\"math/8e3868104c41a9da.svg\" alt=\"\\frac{1}{3}\\times\\frac{2}{5}=\\frac{2}{15}\" style=\"width:11.969ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. Noun → Verb</td><td><span class=\"math-inline\"><img src=\"math/69517c6e474a3048.svg\" alt=\"\\frac{2}{15}\\times\\frac{3}{5}=\\frac{2}{25}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. Verb emits eats</td><td><span class=\"math-inline\"><img src=\"math/e9a1944302b07ad1.svg\" alt=\"\\frac{2}{25}\\times\\frac{2}{3}=\\frac{4}{75}\" style=\"width:12.769ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>7. Verb → Noun</td><td><span class=\"math-inline\"><img src=\"math/a35b29cd9dbe9b05.svg\" alt=\"\\frac{4}{75}\\times\\frac{2}{3}=\\frac{8}{225}\" style=\"width:13.569ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>8. Noun emits bread</td><td><span class=\"math-inline\"><img src=\"math/3a78d82833b21a72.svg\" alt=\"\\frac{8}{225}\\times\\frac{1}{5}=\\frac{8}{1125}\" style=\"width:15.168ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>9. Noun → End</td><td><span class=\"math-inline\"><img src=\"math/2baf230e35df5c28.svg\" alt=\"\\frac{8}{1125}\\times\\frac{2}{5}=\\frac{16}{5625}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d4673af7839c15e4.svg\" alt=\"P=\\frac{16}{5625}\\approx0.0028444444\" style=\"width:26.326ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>P = 16/5625 ≈ 0.0028444444</strong> for these words and specified tags jointly. The two occurrences of eats give P(eats | Verb) = 2/3.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same tag structure ho sakta hai, lekin word emission counts dobara count karna.</p><p><strong>Boundary reminder:</strong> Include P(Det | Start) = 2/3 and P(End | Noun) = 2/5. The handwritten key’s final line instead inserts the overall Det fraction 2/10 and omits End; the complete boundary-aware probability requested here is 0.0028444444.</p>","m2":true,"units":"4","marks":10},{"id":"reexam-2026-q5a","title":"Q5A · Why TF–IDF is useful","html":"<div class=\"question\" style=\"font-weight:700\">Question. Justify with an appropriate example the importance of TF-IDF technique in the document representation and information retrieval task. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>TF–IDF</strong> represents each document using weights that combine within-document term frequency with how unusual a term is across the collection. It supports information retrieval by giving larger weight to terms that are frequent in a document but not present in every document.</p><h3>Given</h3><p>Use three short documents: D₁ = “solar energy solar”; D₂ = “wind energy”; D₃ = “energy policy”. Use raw-count TF and natural-log unsmoothed IDF. N = 3.</p><h3>To find</h3><p>A TF–IDF representation illustrating why distinctive terms help retrieve relevant documents.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/341f27f737ff351a.svg\" alt=\"\\mathrm{TFIDF}(t,d)=C(t,d)\\ln\\frac{N}{\\mathrm{df}(t)}\" style=\"width:29.702ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C counts occurrences within a document; df counts documents containing the term. The logarithm reduces the scale of very large rarity ratios.</p><h3>Solution</h3><h3>Step 1. Count term occurrences</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>D₁</th><th>D₂</th><th>D₃</th><th>df</th></tr></thead><tbody><tr><td>solar</td><td>2</td><td>0</td><td>0</td><td>1</td></tr><tr><td>energy</td><td>1</td><td>1</td><td>1</td><td>3</td></tr><tr><td>wind</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>policy</td><td>0</td><td>0</td><td>1</td><td>1</td></tr></tbody></table></div><h3>Step 2. Calculate IDF</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/faa332781751eb0a.svg\" alt=\"\\mathrm{IDF}(solar)=\\mathrm{IDF}(wind)=\\mathrm{IDF}(policy)=\\ln3\\approx1.098612\" style=\"width:57.122ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3ca0cca554234bcd.svg\" alt=\"\\mathrm{IDF}(energy)=\\ln(3/3)=0\" style=\"width:26.663ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 3. Multiply each count by its IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>D₁ weight</th><th>D₂ weight</th><th>D₃ weight</th></tr></thead><tbody><tr><td>solar</td><td>2 × 1.098612 = 2.197224</td><td>0</td><td>0</td></tr><tr><td>energy</td><td>0</td><td>0</td><td>0</td></tr><tr><td>wind</td><td>0</td><td>1.098612</td><td>0</td></tr><tr><td>policy</td><td>0</td><td>0</td><td>1.098612</td></tr></tbody></table></div><h3>Step 4. Connect the representation to retrieval</h3><p>A query containing “solar” matches D₁’s high solar coordinate. A query containing “wind” matches D₂. “energy” alone cannot distinguish these documents under this unsmoothed collection because it occurs in all three. A retrieval system can compare query and document vectors, commonly by cosine similarity.</p><h3>Final answer</h3><p>TF–IDF preserves distinctive lexical evidence and reduces dominance by collection-wide frequent terms. D₁ is most relevant to a solar query under these features.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Document mein frequent + collection mein rare = high TF–IDF.</p><h3>Strengths and limits</h3><p>The representation is sparse, interpretable and useful as a fast baseline. However, basic TF–IDF ignores word order and does not recognise synonyms or multiple word senses automatically. Its weights depend on the collection and on the chosen TF/IDF convention. Fit IDF on training or indexed documents, not on a hidden test set.</p>","m2":false,"units":"2","marks":10},{"id":"reexam-2026-q5b","title":"Q5B · Sentence-window vectors and cosine","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the paragraph: The farmer planted seeds in the soil. The rain watered the soil. The sun helped the plants grow. The farmer harvested the plants. The soil became rich and fertile.<br>Target words: farmer, soil, sun, plant.<br>Context words: plant, water, grow, harvest.<br>i. Construct a co-occurrence matrix for the target and context words. Take the window size as one whole sentence.<br>ii. Evaluate the similarity between the vectors of the target words “farmer-soil”, “farmer-sun”, and “farmer-plant” using the cosine similarity.<br>iii. Plot the target word vectors by considering only two dimensions: “planted” and “harvested”. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Five sentence windows. For alignment with the supplied matrix, target plant means the noun plants, occurring in sentences 3 and 4. Context plant covers planted and plants; watered → water; harvested → harvest. Count a target–context pair once per sentence in which both are present, including the plant–plant sentence-presence diagonal.</p><h3>To find</h3><p>The target–context matrix, three cosine similarities and a two-coordinate plot.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/888eadfcee94dff3.svg\" alt=\"M_{ij}=\\sum_s\\mathbf1[\\text{target}_i\\text{ and context}_j\\text{ present in }s]\" style=\"width:44.273ex;height:4.767ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d47266edc91f0bb5.svg\" alt=\"\\cos(\\mathbf a,\\mathbf b)=\\frac{\\sum_j a_jb_j}{\\sqrt{\\sum_j a_j^2}\\sqrt{\\sum_j b_j^2}}\" style=\"width:28.501ex;height:7.827ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>This is a sentence-presence matrix, not a position-based sliding window that excludes a token from its own context. Stating the convention is necessary because those alternatives give a different diagonal.</p><h3>Solution</h3><h3>Step 1. Normalize and identify each sentence’s contribution</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Targets present</th><th>Context lemmas present</th></tr></thead><tbody><tr><td>1</td><td>farmer, soil</td><td>plant</td></tr><tr><td>2</td><td>soil</td><td>water</td></tr><tr><td>3</td><td>sun, plant</td><td>plant, grow</td></tr><tr><td>4</td><td>farmer, plant</td><td>plant, harvest</td></tr><tr><td>5</td><td>soil</td><td>none</td></tr></tbody></table></div><h3>Step 2. Fill all matrix rows</h3><div class=\"table-wrap\"><table><thead><tr><th>Target</th><th>plant</th><th>water</th><th>grow</th><th>harvest</th></tr></thead><tbody><tr><td>farmer</td><td>2</td><td>0</td><td>0</td><td>1</td></tr><tr><td>soil</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>sun</td><td>1</td><td>0</td><td>1</td><td>0</td></tr><tr><td>plant</td><td>2</td><td>0</td><td>1</td><td>1</td></tr></tbody></table></div><p>Farmer meets context plant in sentences 1 and 4. Soil meets plant in sentence 1 and water in sentence 2. Sun meets plant and grow in sentence 3. The noun plant occurs in sentences 3 and 4, producing its last row.</p><h3>Step 3. Compute farmer–soil</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9a19db4a92763869.svg\" alt=\"\\mathbf f\\cdot\\mathbf s=(2)(1)+(0)(1)+(0)(0)+(1)(0)=2\" style=\"width:42.278ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1c307e5c2f60d4e.svg\" alt=\"\\|\\mathbf f\\|=\\sqrt{2^2+0^2+0^2+1^2}=\\sqrt5,\\quad\\|\\mathbf s\\|=\\sqrt2\" style=\"width:44.097ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d552a0f1e7f606d.svg\" alt=\"\\cos(\\mathbf f,\\mathbf s)=\\frac2{\\sqrt{10}}\\approx0.632456\" style=\"width:27.613ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Compute farmer–sun</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/46e846a5d9fa6557.svg\" alt=\"\\mathbf f\\cdot\\mathbf u=(2)(1)+(0)(0)+(0)(1)+(1)(0)=2\" style=\"width:42.697ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5eb8385d74c2a577.svg\" alt=\"\\|\\mathbf u\\|=\\sqrt2,\\quad\\cos(\\mathbf f,\\mathbf u)=\\frac2{\\sqrt{10}}\\approx0.632456\" style=\"width:41.086ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Compute farmer–plant</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3c4e8c9a3d5b0e2a.svg\" alt=\"\\mathbf f\\cdot\\mathbf p=(2)(2)+(0)(0)+(0)(1)+(1)(1)=5\" style=\"width:42.697ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/65e703346d258ca7.svg\" alt=\"\\|\\mathbf p\\|=\\sqrt{2^2+0^2+1^2+1^2}=\\sqrt6\" style=\"width:31.884ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1f1082cbeeb42e0.svg\" alt=\"\\cos(\\mathbf f,\\mathbf p)=\\frac5{\\sqrt{30}}\\approx0.912871\" style=\"width:28.031ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Plot the requested two coordinates</h3><p>Interpret the axis names planted and harvested as their normalized context features plant and harvest. Farmer=(2,1), soil=(1,0), sun=(1,0), plant=(2,1). Farmer and plant overlap; soil and sun overlap.</p><figure><svg viewBox=\"0 0 550 310\" role=\"img\" aria-label=\"Target word vectors plotted on two labelled axes\" style=\"width:100%;max-width:550px;background:#f4f8f7\"><path d=\"M70 250H495 M70 250V25\" stroke=\"#516d64\" fill=\"none\" stroke-width=\"2\"/><text x=\"70\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"50\" y=\"255\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"240\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"50\" y=\"165\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"410\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">2</text><text x=\"50\" y=\"75\" text-anchor=\"middle\" font-size=\"15\">2</text><circle cx=\"410\" cy=\"160\" r=\"6\" fill=\"#166b55\"/><text x=\"420\" y=\"148\" font-size=\"16\" fill=\"#153e34\">farmer, plant</text><circle cx=\"240\" cy=\"250\" r=\"6\" fill=\"#166b55\"/><text x=\"250\" y=\"238\" font-size=\"16\" fill=\"#153e34\">soil, sun</text><text x=\"280\" y=\"305\" text-anchor=\"middle\" font-size=\"16\">plant (planted)</text><text x=\"15\" y=\"20\" font-size=\"16\">harvest (harvested)</text></svg><figcaption>The plot uses only the requested two coordinates; cosine uses all context columns.</figcaption></figure><h3>Final answer</h3><p>Using the stated noun-target convention: <strong>farmer–soil = 0.632456, farmer–sun = 0.632456, farmer–plant = 0.912871.</strong></p><p class=\"memory\"><strong>Yaad rakho:</strong> Plant noun aur plant verb ko same maana ya separate? Pehle convention likho, phir count karo.</p><h3>Two details that prevent an incorrect answer</h3><p><strong>Arithmetic:</strong> 5/√30 = 0.912871; the source key’s printed approximation 0.9444 does not equal its own fraction. Keep the exact fraction until the last step.</p><p><strong>Normalization:</strong> If the question instead requires all noun and verb forms of plant to be merged as targets, sentence 1 also contains the plant target. Its row becomes [3,0,1,1], and farmer–plant becomes 7/√55 ≈ 0.943880. The paper leaves this choice unstated; the main worked solution explicitly uses the noun-target interpretation that reproduces its supplied matrix.</p>","m2":false,"units":"5","marks":10},{"id":"reexam-2026-q6a","title":"Q6A · Pronoun approaches and lexical relations","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Briefly describe any two approaches to pronoun resolution and mention one advantage of each.<br>ii. Describe the difference between Homonymy and Synonymy with suitable examples. Discuss how these two relations differently affect natural language processing applications? <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Two approaches to pronoun resolution</h3><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>How it works</th><th>Advantage</th></tr></thead><tbody><tr><td>Rule-based / syntactic</td><td>Uses parse structure, agreement, recency and linguistic constraints. Hobbs’ algorithm searches parse trees for eligible antecedents.</td><td>Interpretable: a proposed antecedent can be traced to explicit rules.</td></tr><tr><td>Statistical or neural</td><td>Learns candidate–pronoun compatibility or whole-document coreference patterns from labelled examples, using context and linguistic features or contextual embeddings.</td><td>Can learn interactions and contextual cues that are difficult to enumerate as hand-written rules.</td></tr></tbody></table></div><p>For “Asha dropped the glass because it was slippery,” a system should evaluate candidate referents and context rather than merely choose the most recent noun. Rules can constrain number and syntax; learned models can use compatibility patterns, though neither approach is guaranteed to resolve every ambiguity.</p><h3>ii. Homonymy and synonymy</h3><div class=\"table-wrap\"><table><thead><tr><th>Relation</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Homonymy</td><td>Same spelling or sound, unrelated meanings</td><td>bank as financial institution versus bank as river edge</td></tr><tr><td>Synonymy</td><td>Different words with the same or closely related meanings in a context</td><td>car and automobile; big and large</td></tr></tbody></table></div><p>Homonymy creates an ambiguity problem: a search for bank may retrieve finance or rivers. WSD uses context to choose the intended sense. Synonymy creates a vocabulary-matching problem: a document saying automobile may be relevant to a query saying car. Query expansion or semantic representations can improve recall by connecting related terms.</p><p>The remedies differ. Do not merge unrelated homonym senses simply because their spelling matches. Do not insist on exact surface-form matching when different words express the same concept. Synonyms are also context-sensitive: “big mistake” and “large mistake” are not always equally natural.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Homonym: same word-form, different meaning. Synonym: different words, similar meaning.</p>","m2":false,"units":"5,6","marks":10},{"id":"reexam-2026-q6b","title":"Q6B · Hobbs: Ramesh and Shyam","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain Hobbs’ Algorithm for pronoun resolution. State its main steps and limitations.<br>ii. Apply Hobbs’ Algorithm to the sentence: “When Ramesh gave Shyam a book, he smiled.” Identify the antecedent of “he” by showing traversal steps. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Hobbs’ algorithm</strong> is a syntax-based pronoun-resolution procedure that searches constituency parse trees in a specified order. It proposes noun phrases as antecedents and filters incompatible candidates, for example by number and gender agreement.</p><p><strong>Read the tree labels first:</strong> NP means noun phrase; S means sentence/clause; VP means verb phrase. X is the current NP or S search node, and p is the upward path used to reach it. Breadth-first means shallower nodes before deeper nodes; left-to-right fixes the order at the same depth. An N-bar (N′) node is the noun-centred part of an NP in a parse using that label.</p><h3>Complete ordered procedure</h3><ol><li><strong>Locate the pronoun.</strong> Start at the NP immediately dominating the pronoun: the smallest NP containing it.</li><li><strong>Make the first climb.</strong> Move upward to the first NP or S above the starting NP. Call it X and record the path p.</li><li><strong>Search initially to the left.</strong> Traverse branches below X to the left of p, breadth-first and left-to-right. Propose an NP only if another NP or S lies between that candidate and X. Check agreement and other applicable constraints for each proposed candidate; accept the first eligible compatible one.</li><li><strong>Check the highest sentence.</strong> If X is the highest S and no candidate has been accepted, search previous sentence trees, most recent first. In each, traverse breadth-first and left-to-right and propose NPs. Accept the first eligible compatible candidate; if the available context contains none, report no resolved antecedent.</li><li><strong>Otherwise climb again.</strong> Move from X to the next NP or S above it. Make that node the new X and record the new upward path p.</li><li><strong>Test a higher NP.</strong> If the new X is an NP, propose X only when p did not pass through its nominal N-bar child. Apply the same compatibility checks. Use the labels in the supplied parse; do not invent a missing N-bar branch.</li><li><strong>Search left again.</strong> Traverse the new X’s branches to the left of p, breadth-first and left-to-right, proposing NPs. The extra intervening-NP/S requirement in Step 3 belongs to the initial search.</li><li><strong>Search permitted right branches.</strong> If X is an S, traverse branches to the right of p, breadth-first and left-to-right, but do not descend below any NP or S encountered. Propose the encountered eligible NPs and test their compatibility.</li><li><strong>Repeat or finish.</strong> Return to Step 4 until a compatible candidate is accepted or the available sentence trees are exhausted. Record the candidate order and why each candidate was accepted or rejected.</li></ol><p><strong>Why the initial restriction matters:</strong> in “John saw him”, the subject NP John is directly under the clause S, with no additional NP or S between them. Step 3 therefore does not propose John as the ordinary local antecedent of him. A reflexive such as himself is a different grammatical case. The worked question below shows the specific parse and traversal; selecting an antecedent is not simply choosing the nearest name.</p><h3>Given</h3><p>The pronoun he is the subject of the main clause. The preceding subordinate clause is “When Ramesh gave Shyam a book”. Assume the temporal clause attaches to the whole main sentence.</p><h3>To find</h3><p>The first suitable antecedent in the left-to-right breadth-first search of the preceding clause.</p><pre tabindex=\"0\" aria-label=\"Assumed constituent tree for Ramesh, Shyam and he\">S (main)                        ← first X\n├── SBAR: When\n│   └── S (embedded)             ← intervening S\n│       ├── NP: Ramesh           ← first candidate\n│       └── VP\n│           ├── V: gave\n│           ├── NP: Shyam\n│           └── NP: a book\n├── NP: he                      ← start\n└── VP: smiled</pre><h3>Step 1. Locate the pronoun NP</h3><p>Start at NP “he” and move upward to its S ancestor. Record the path from he.</p><h3>Step 2. Search branches before the pronoun</h3><p>The initial when-clause lies to the left of the path. Apply Step 3: its embedded S lies between each of its noun phrases and the main S, so these NPs satisfy the initial intervening-NP/S requirement. Traverse left-to-right and breadth-first.</p><h3>Step 3. Propose noun phrases</h3><p>The subject NP Ramesh is encountered before the deeper object NP Shyam and object NP a book. Ramesh agrees with the assumed singular-male pronoun.</p><h3>Step 4. Accept the first compatible antecedent</h3><p>Select Ramesh. Shyam is also a semantically possible referent in ordinary discourse, but the algorithm’s stated syntactic preference selects Ramesh first.</p><h3>Limitations</h3><ul><li>Requires a suitable and accurate constituency parse.</li><li>Agreement information may be unknown or insufficient when several people match.</li><li>Ignores much of the event semantics, discourse focus and world knowledge.</li><li>An ambiguous parse or different attachment can change candidate order.</li></ul><p><strong>Final answer:</strong> <strong>Ramesh</strong>, under the shown parse and ordinary agreement assumptions. A syntactic preference is not a guarantee about the author’s intended meaning.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Left branches ko breadth-first dekho; pehla eligible matching NP choose karo.</p>","m2":false,"units":"6","marks":10},{"id":"reexam-2026-q7a","title":"Q7A · Information retrieval","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain the concept of Information Retrieval, highlighting its role in Recommender Systems and Search Engines.<br>ii. Discuss the various steps involved in the Information Retrieval process. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Concept and roles</h3><p><strong>Information Retrieval (IR)</strong> finds and ranks documents or other information objects relevant to a user’s information need. A query is the user’s expression of that need. IR typically returns a ranked set of items; information extraction instead identifies structured facts or fields inside those items.</p><div class=\"table-wrap\"><table><thead><tr><th>Application</th><th>Role of IR</th><th>Example</th></tr></thead><tbody><tr><td>Search engine</td><td>Matches a submitted query against a large indexed collection and ranks candidate pages</td><td>A search for “symptoms of dehydration” returns relevant health pages</td></tr><tr><td>Recommender system</td><td>Retrieves candidate items using a user profile, recent activity or a content representation; a later model may personalize ranking</td><td>Retrieve articles similar to topics the user reads</td></tr></tbody></table></div><p>Retrieval is a component of many recommenders; recommendation also involves preferences, feedback, novelty and business constraints. A recommender need not wait for an explicit textual query.</p><h3>ii. Retrieval process</h3><div class=\"flow\"><span class=\"flow-box\">Collect</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Preprocess</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Index</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Process query</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Retrieve candidates</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Rank</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Evaluate</span></div><ol><li><strong>Collect and define documents.</strong> Crawl or ingest documents, record metadata and remove unwanted duplicates.</li><li><strong>Preprocess.</strong> Tokenize and normalize using rules suitable for both documents and queries. Preserve task-relevant information.</li><li><strong>Build representations and an index.</strong> An inverted index maps each term to the documents containing it; a dense retrieval system stores vector representations.</li><li><strong>Process the query.</strong> Apply compatible tokenization, spelling handling or expansion, then obtain query features.</li><li><strong>Retrieve candidates.</strong> Use the index to identify potentially relevant documents efficiently.</li><li><strong>Score and rank.</strong> A lexical method may use TF–IDF/BM25-style evidence; a semantic method compares representations. Rank scores estimate relevance rather than proving correctness.</li><li><strong>Present results.</strong> Return titles, snippets and links, possibly with filtering or diversification.</li><li><strong>Evaluate and update.</strong> Use relevance judgments and measures such as precision, recall or ranking metrics. Refresh the index as documents change.</li></ol><p>Example: for “solar energy storage”, an inverted index retrieves documents containing those terms; a ranking function rewards useful matches. A semantic system may also retrieve relevant material using related terms such as batteries.</p><p class=\"memory\"><strong>Yaad rakho:</strong> IR mein relevant document dhoondho aur rank karo; extraction mein document ke andar facts nikalo.</p>","m2":false,"units":"7","marks":10},{"id":"reexam-2026-q7b","title":"Q7B · Gutenberg corpus and normalization","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Discuss how the Gutenberg Corpus can be utilized for various text analysis tasks in Natural Language Processing?<br>ii. Explain the importance of text normalization in Natural Language Processing (NLP). Illustrate your answer with a suitable example of an application where text normalization plays a crucial role. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Using the Gutenberg corpus</h3><p>The Gutenberg corpus provides literary texts, commonly used through tools such as NLTK’s Gutenberg collection. It supplies naturally occurring sentences and longer documents for exploring language patterns. The available subset and licensing should be checked before reuse in a new distribution.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Use of the corpus</th></tr></thead><tbody><tr><td>Frequency and vocabulary study</td><td>Count tokens and word types, inspect common words and compare lexical diversity across texts</td></tr><tr><td>Concordances and collocations</td><td>View a word in context and discover words that occur near each other</td></tr><tr><td>N-gram language modeling</td><td>Estimate unigram or bigram counts and compare sequence probabilities</td></tr><tr><td>Stylistic or authorship analysis</td><td>Compare sentence lengths, vocabulary and function-word patterns across authors</td></tr><tr><td>Text preprocessing experiments</td><td>Study the effect of tokenization, case normalization and lemmatization on counts</td></tr></tbody></table></div><p>A sound workflow selects files, inspects encoding and boundaries, tokenizes consistently, computes the relevant statistics and interprets them against corpus composition. Literary text is not automatically representative of chat, medical records or present-day search queries; domain mismatch matters.</p><h3>ii. Text normalization</h3><p><strong>Normalization</strong> converts selected surface variants into a consistent form so that equivalent expressions do not unnecessarily produce different features. Possible steps include case folding, whitespace cleanup, Unicode normalization, contraction expansion and lemmatization. Choose these according to the task.</p><h3>Example: product search</h3><ol><li>Raw query: “  RUNNING   shoes ”. Product description: “Comfortable run shoes”.</li><li>Trim extra whitespace and apply consistent case: “running shoes”.</li><li>If the application chooses lemmatization, running → run. The query and the indexed description now share the intended run and shoes features.</li><li>Apply the same normalization to stored documents and future queries, otherwise matching remains inconsistent.</li></ol><p>Normalization reduces avoidable vocabulary variation and can improve recall. It must preserve distinctions important to the task: lowercasing US to us may lose meaning, and removing “not” can reverse sentiment. Aggressive stemming or synonym replacement can create incorrect matches.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same meaning ke surface variants ko consistent banao; useful meaning delete mat karo.</p>","m2":false,"units":"2,3","marks":10}]},{"id":"legacy-r25","title":"2025-02-21 · re-exam · recovered AI paper","unit":"PYQ","scope":"Previous examination · complete worked answers","sections":[{"id":"q1a","title":"Q1a · BoW and one-hot encoding","html":"<div class=\"question\"><strong>Question. Explain Bag of Words and one-hot encoding with appropriate examples.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>Bag of words (BoW) represents a document by the counts of vocabulary terms, discarding their positions.</strong> A binary BoW variant stores only presence/absence; a count BoW stores frequencies. State which is used.</p><div class=\"math-display\"><img src=\"math/b587e59a2f7e4537.svg\" alt=\"x_{d,j}=C(v_j,d).\" style=\"width:14.67ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/8bfe4f4285f4b225.svg\" alt=\"x_{d,j}\" style=\"width:3.418ex;height:1.666ex\" loading=\"lazy\" decoding=\"async\"></span> is document <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>'s coordinate for vocabulary term <span class=\"math-inline\"><img src=\"math/f032d29fd7d0f0b5.svg\" alt=\"v_j\" style=\"width:1.944ex;height:1.668ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/4c241e4d8abb2427.svg\" alt=\"C(v_j,d)\" style=\"width:7.606ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span> is its occurrence count.</p><p>A <strong>bag of n-grams</strong> uses short contiguous token sequences as features. Bigrams can distinguish “not good” from “good”, but increasing n enlarges the vocabulary and creates more rare features.</p><div class=\"example\"><p><strong>Question. Build count and binary BoW for D1=“cat cat dog” and D2=“dog fish”. Use vocabulary [cat,dog,fish] and no stopword removal.</strong></p><div class=\"given\"><h4>Given</h4><p>Two tokenized documents, fixed vocabulary order.</p><h4>To find</h4><p>Count vectors and binary vectors.</p></div><h4>Formula and why it applies</h4><p>Count BoW uses <span class=\"math-inline\"><img src=\"math/4c241e4d8abb2427.svg\" alt=\"C(v_j,d)\" style=\"width:7.606ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>. Binary BoW is 1 when that count is positive and 0 otherwise.</p><div class=\"step\"><h4>Step 1. D1 counts</h4><p>cat=2, dog=1, fish=0 → [2,1,0].</p></div><div class=\"step\"><h4>Step 2. D2 counts</h4><p>cat=0, dog=1, fish=1 → [0,1,1].</p></div><div class=\"step\"><h4>Step 3. Convert to presence</h4><p>D1 [1,1,0]; D2 [0,1,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Count rows [2,1,0], [0,1,1]; binary rows [1,1,0], [0,1,1].</p></div><div class=\"example\"><p><strong>Question. After lowercasing and removing {is,a,means}, obtain BoW vectors for D1=“Continuous learning is learning lifetime”, D2=“Continuous learning means lifetime learning”, D3=“Learning is a good practice”. Use [continuous,good,learning,lifetime,practice].</strong></p><div class=\"given\"><h4>Given</h4><p>Three documents and exact stopword set from the supplied slides.</p><h4>To find</h4><p>The document–term count matrix.</p></div><h4>Formula and why it applies</h4><p>Remove only the listed stopwords, then count every remaining token in the fixed column order.</p><div class=\"step\"><h4>Step 1. Clean D1</h4><p>[continuous,learning,learning,lifetime] → [1,0,2,1,0].</p></div><div class=\"step\"><h4>Step 2. Clean D2</h4><p>[continuous,learning,lifetime,learning] → [1,0,2,1,0].</p></div><div class=\"step\"><h4>Step 3. Clean D3</h4><p>[learning,good,practice] → [0,1,1,0,1].</p></div><div class=\"step\"><h4>Step 4. Compare D1 and D2</h4><p>They have identical BoW vectors despite different original wording/order.</p></div><p class=\"answer\"><strong>Answer.</strong> Rows [1,0,2,1,0], [1,0,2,1,0], [0,1,1,0,1].</p></div><div class=\"example\"><p><strong>Question. Build a bag of bigrams for “not good but not bad” with vocabulary [not good,good but,but not,not bad]. Do not add sentence boundary tokens.</strong></p><div class=\"given\"><h4>Given</h4><p>Five tokens; use adjacent pairs, stride 1.</p><h4>To find</h4><p>The bigram count vector.</p></div><h4>Formula and why it applies</h4><p>A sequence of <span class=\"math-inline\"><img src=\"math/c16b65225745dbd1.svg\" alt=\"L\" style=\"width:1.541ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> tokens has <span class=\"math-inline\"><img src=\"math/8c8ba2cc6117f74c.svg\" alt=\"L-1\" style=\"width:5.438ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> adjacent bigrams when no boundaries are added.</p><div class=\"step\"><h4>Step 1. Enumerate pairs</h4><p>(not,good), (good,but), (but,not), (not,bad).</p></div><div class=\"step\"><h4>Step 2. Count each vocabulary bigram</h4><p>Each appears once.</p></div><div class=\"step\"><h4>Step 3. Write vector</h4><p>[1,1,1,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Four bigram features, each with count 1.</p></div><p class=\"cue\">BoW: order bhool, word-count rakh. Bag of bigrams: neighbouring word-pair count.</p><p><strong>Label encoding</strong> assigns each category or word a unique integer ID. <strong>One-hot encoding</strong> assigns a length-<span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> vector with one 1 at the word's vocabulary position and zeros elsewhere.</p><div class=\"math-display\"><img src=\"math/47e78a40b0a5b0bd.svg\" alt=\"\\operatorname{onehot}(w)_j=\\begin{cases}1,&amp;j=\\operatorname{index}(w)\\\\0,&amp;\\text{otherwise.}\\end{cases}\" style=\"width:32.3ex;height:5.428ex\" loading=\"lazy\" decoding=\"async\"></div><p>The index is an ID, not a meaning score. One-hot represents one token/category; a multiword document generally needs multiple token vectors or an aggregation scheme.</p><div class=\"example\"><p><strong>Question. Encode “dog cat dog” using vocabulary [cat,dog,fish], IDs starting at 0. Give label IDs and a one-hot vector for every token.</strong></p><div class=\"given\"><h4>Given</h4><p>cat→0, dog→1, fish→2. Vector columns have the same order.</p><h4>To find</h4><p>The ID sequence and three one-hot rows.</p></div><h4>Formula and why it applies</h4><p>Replace each word by its ID for labels; set its vocabulary position to 1 for one-hot.</p><div class=\"step\"><h4>Step 1. Label IDs</h4><p>dog→1, cat→0, dog→1 → [1,0,1].</p></div><div class=\"step\"><h4>Step 2. First dog</h4><p>[0,1,0].</p></div><div class=\"step\"><h4>Step 3. Cat</h4><p>[1,0,0].</p></div><div class=\"step\"><h4>Step 4. Second dog</h4><p>[0,1,0]. Repeated tokens keep the same representation.</p></div><p class=\"answer\"><strong>Answer.</strong> IDs [1,0,1]; one-hot rows [0,1,0], [1,0,0], [0,1,0].</p></div><div class=\"example\"><p><strong>Question. Encode the city sequence Mumbai, Delhi, Mumbai, Pune using vocabulary [Delhi,Mumbai,Pune] and label IDs starting at 1.</strong></p><div class=\"given\"><h4>Given</h4><p>Delhi→1, Mumbai→2, Pune→3.</p><h4>To find</h4><p>IDs and one-hot rows.</p></div><h4>Formula and why it applies</h4><p>One-hot uses three coordinates regardless of whether label IDs begin at 0 or 1.</p><div class=\"step\"><h4>Step 1. IDs</h4><p>[2,1,2,3].</p></div><div class=\"step\"><h4>Step 2. Mumbai rows</h4><p>Each Mumbai → [0,1,0].</p></div><div class=\"step\"><h4>Step 3. Delhi and Pune</h4><p>Delhi→[1,0,0]; Pune→[0,0,1].</p></div><p class=\"answer\"><strong>Answer.</strong> Rows [0,1,0], [1,0,0], [0,1,0], [0,0,1].</p></div><div class=\"example\"><p><strong>Question. One-hot encode categories [red,green,blue] for a linear regression with an intercept. Then give dummy coding after dropping blue.</strong></p><div class=\"given\"><h4>Given</h4><p>Full column order [red,green,blue]. Blue is the baseline.</p><h4>To find</h4><p>Full and reduced codes.</p></div><h4>Formula and why it applies</h4><p>Full one-hot rows sum to 1. With an intercept this creates a linear dependency; dropping one category column gives k−1 independent dummy indicators.</p><div class=\"step\"><h4>Step 1. Full encoding</h4><table><thead><tr><th>Category</th><th>red</th><th>green</th><th>blue</th></tr></thead><tbody><tr><td>red</td><td>1</td><td>0</td><td>0</td></tr><tr><td>green</td><td>0</td><td>1</td><td>0</td></tr><tr><td>blue</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Drop blue column</h4><table><thead><tr><th>Category</th><th>red</th><th>green</th></tr></thead><tbody><tr><td>red</td><td>1</td><td>0</td></tr><tr><td>green</td><td>0</td><td>1</td></tr><tr><td>blue</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 3. Interpret zero row</h4><p>[0,0] now identifies the baseline blue, not missing data.</p></div><p class=\"answer\"><strong>Answer.</strong> Full width 3; reduced dummy width 2. Dropping a column is model-dependent, not a requirement for every neural embedding input.</p></div><p><strong>Limitations:</strong> one-hot is large and sparse and does not express semantic similarity. Unseen words need a defined unknown-token or vocabulary-update policy. Label IDs are compact but should not be treated as an ordered scalar feature for nominal words.</p><p class=\"cue\">Label = ID number. One-hot = us ID ke box mein 1, baaki 0.</p>","m2":false,"units":"2","marks":null,"sourcePages":[1],"historical":true},{"id":"q1b","title":"Q1b · Lesk WSD","html":"<div class=\"question\"><strong>Question. Discuss Lesk word-sense disambiguation with a suitable example.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>Lesk is a knowledge-based WSD method that chooses senses whose dictionary descriptions have the greatest overlap with contextual evidence.</strong> Original Lesk compares definitions of neighbouring words' senses. A common simplified version compares each target-sense gloss directly with the sentence context. State which version you use.</p><h3>Simplified Lesk procedure</h3><ol><li>Remove the target word from the context; tokenize and normalize the remaining content words.</li><li>Obtain the gloss for each candidate sense and apply the same normalization.</li><li>Count shared words between the context and each gloss.</li><li>Select the sense with maximum overlap. If scores tie, report the tie or use a specified tie-break rule.</li></ol><div class=\"math-display\"><img src=\"math/691fb54513999f0d.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|,\\qquad s^*=\\arg\\max_s\\operatorname{score}(s)\" style=\"width:45.416ex;height:3.321ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b5a9729b8c25c0f7.svg\" alt=\"C\" style=\"width:1.719ex;height:1.645ex\" loading=\"lazy\" decoding=\"async\"></span> is the set of context words, <span class=\"math-inline\"><img src=\"math/a5684e27b28daffa.svg\" alt=\"G_s\" style=\"width:2.716ex;height:1.95ex\" loading=\"lazy\" decoding=\"async\"></span> the set of words in sense <span class=\"math-inline\"><img src=\"math/92329599456283d6.svg\" alt=\"s\" style=\"width:1.061ex;height:1.023ex\" loading=\"lazy\" decoding=\"async\"></span>'s gloss, <span class=\"math-inline\"><img src=\"math/c7de95563fc530c3.svg\" alt=\"\\cap\" style=\"width:1.509ex;height:1.403ex\" loading=\"lazy\" decoding=\"async\"></span> means common elements, <span class=\"math-inline\"><img src=\"math/468f3b6d2f1b95a0.svg\" alt=\"|\\cdot|\" style=\"width:2.892ex;height:2.26ex\" loading=\"lazy\" decoding=\"async\"></span> means count, and <span class=\"math-inline\"><img src=\"math/dfccac0c4f581832.svg\" alt=\"\\arg\\max\" style=\"width:7.737ex;height:1.491ex\" loading=\"lazy\" decoding=\"async\"></span> means “the sense giving the largest score”. This version counts unique matching words once.</p><div class=\"example\"><p><strong>Question. Use simplified Lesk to disambiguate “bank” in “The river water rose near the bank.” Use C = {river, water, rose, near}; financial gloss = {institution, money, deposit}; river gloss = {land, river, water, edge}.</strong></p><div class=\"given\"><h4>Given</h4><p>The normalized context and two gloss sets are given. Count exact shared words.</p><h4>To find</h4><p>The score of each sense and the selected meaning.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> because the task specifies context–gloss overlap.</p><div class=\"step\"><h4>Step 1. Compare the financial sense</h4><p>No word occurs in both {river, water, rose, near} and {institution, money, deposit}. Overlap = {}.</p></div><div class=\"step\"><h4>Step 2. Count the financial score</h4><p><span class=\"math-inline\"><img src=\"math/bdc75dbcd361db69.svg\" alt=\"\\operatorname{score}(F)=0\" style=\"width:12.522ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compare the river sense</h4><p>Shared words are {river, water}. “Rose” and “near” are not in the gloss.</p></div><div class=\"step\"><h4>Step 4. Count and select</h4><p><span class=\"math-inline\"><img src=\"math/384740febd8dd4b0.svg\" alt=\"\\operatorname{score}(R)=2\" style=\"width:12.544ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Since <span class=\"math-inline\"><img src=\"math/6e25b81ec200909a.svg\" alt=\"2&gt;0\" style=\"width:5.28ex;height:1.597ex\" loading=\"lazy\" decoding=\"async\"></span>, choose the river-edge sense.</p></div><p class=\"answer\"><strong>Answer.</strong> Bank means land beside a river.</p></div><div class=\"example\"><p><strong>Question. Use simplified Lesk for “The dog barked loudly.” Treat barked as bark. Context C = {dog, loudly}; sound gloss = {sharp, cry, dog}; tree gloss = {outer, covering, tree}; ship gloss = {sailing, ship}.</strong></p><div class=\"given\"><h4>Given</h4><p>Three glosses and normalized context {dog, loudly}.</p><h4>To find</h4><p>Select the sense of bark.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/a0d33079bc4a9aaa.svg\" alt=\"\\operatorname{score}(s)=|C\\cap G_s|\" style=\"width:18.965ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Lemmatization lets barked match the target lemma bark; it does not create additional overlap words.</p><div class=\"step\"><h4>Step 1. Sound sense</h4><p>Intersection = {dog}; score = 1.</p></div><div class=\"step\"><h4>Step 2. Tree sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 3. Ship sense</h4><p>Intersection = {}; score = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>The sound sense has the unique maximum: 1 &gt; 0.</p></div><p class=\"answer\"><strong>Answer.</strong> Bark is the dog's cry.</p></div><div class=\"example\"><p><strong>Question. Apply definition–definition Lesk to “pine cone”. Pine senses: P1 = {evergreen, tree, needle, leaf}; P2 = {waste, sorrow, illness}. Cone senses: C1 = {solid, shape, circular}; C2 = {fruit, evergreen, tree}.</strong></p><div class=\"given\"><h4>Given</h4><p>Two candidate senses for each word. Tokens are already normalized; tree and trees would be reduced to the same form if necessary.</p><h4>To find</h4><p>The most compatible pair of senses.</p></div><h4>Formula and why it applies</h4><p>Use <span class=\"math-inline\"><img src=\"math/bb2259d0f8a3b048.svg\" alt=\"|G_{P_i}\\cap G_{C_j}|\" style=\"width:10.997ex;height:2.506ex\" loading=\"lazy\" decoding=\"async\"></span> for every pair because this is original-style gloss–gloss comparison.</p><div class=\"step\"><h4>Step 1. P1 with C1</h4><p>No shared word → 0.</p></div><div class=\"step\"><h4>Step 2. P1 with C2</h4><p>Shared {evergreen, tree} → 2.</p></div><div class=\"step\"><h4>Step 3. P2 with each cone sense</h4><p>P2–C1 has no overlap → 0; P2–C2 has no overlap → 0.</p></div><div class=\"step\"><h4>Step 4. Choose the best pair</h4><p>The four scores are 0, 2, 0, 0. Maximum 2 belongs to P1–C2.</p></div><p class=\"answer\"><strong>Answer.</strong> Pine is the evergreen tree; cone is its fruit-like reproductive structure.</p></div><p><strong>Limitations:</strong> exact overlap misses synonyms, short glosses may produce zeros, and different preprocessing choices change the score. Extended Lesk may include related synset definitions or longer phrase overlaps; do not silently substitute it for a simple question.</p><p class=\"cue\">Lesk: context aur dictionary mein common words gino; sabse bada overlap jeeta.</p>","m2":false,"units":"5","marks":null,"sourcePages":[1],"historical":true},{"id":"q1c","title":"Q1c · Syntax parsing approaches","html":"<div class=\"question\"><strong>Question. Explain syntax parsing and compare top-down and bottom-up approaches.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>A context-free grammar (CFG)</strong> specifies a language using production rules whose left side is a single nonterminal. Formally, G=(N,Σ,R,S): N is the set of nonterminals, Σ the terminal vocabulary, R the production rules, and S the start symbol. A rule can expand its nonterminal regardless of the neighboring symbols; that is the meaning of “context-free”.</p><div class=\"table-wrap\"><table><thead><tr><th>Concept</th><th>Plain explanation</th><th>Example</th></tr></thead><tbody><tr><td>Terminal</td><td>A word at a leaf; it is not expanded further</td><td>the, girl, read</td></tr><tr><td>Nonterminal</td><td>A grammatical category that can be expanded</td><td>S, NP, VP, Det, N, V</td></tr><tr><td>Production</td><td>A permitted replacement</td><td>S → NP VP</td></tr><tr><td>Start symbol</td><td>Category for a complete sentence</td><td>S</td></tr><tr><td>Lexicon</td><td>Word-to-category rules</td><td>N → girl | paper</td></tr><tr><td>Derivation</td><td>Sequence of rule applications</td><td>S ⇒ NP VP ⇒ Det N VP ⇒ …</td></tr><tr><td>Parse tree</td><td>Hierarchical picture of those expansions</td><td>Root S, internal phrases, word leaves</td></tr></tbody></table></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/08274dbc564789d5.svg\" alt=\"S\\to NP\\ VP,\\quad NP\\to Det\\ N,\\quad VP\\to V\\ NP\" style=\"width:45.747ex;height:2.034ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read S→NP VP as “a sentence can contain a noun phrase followed by a verb phrase”. It does not mean subtraction or multiplication. A vertical bar in a grammar rule means alternatives: Det→the | a allows either the or a. This is different from the probability bar meaning “given”.</p><div class=\"flow\"><div class=\"node\">S: the whole sentence</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: the girl  +  VP: read the paper</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP→Det N; VP→V NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Leaves in order: the / girl / read / the / paper</div></div><p><strong>A constituent</strong> is a group of words that acts as a grammatical unit, such as “the girl”. <strong>Syntactic parsing</strong> assigns a grammatical structure to an input sentence using a grammar. It can support grammar checking, information extraction, translation and later semantic analysis. Failure under one restricted grammar means that grammar could not derive the sentence; it does not necessarily prove the sentence is invalid English.</p><p><strong>A treebank</strong> is a corpus annotated with parse trees. It supplies training/evaluation structures for parsers and lets linguists study recurring syntactic patterns. A tagged corpus gives word tags; a treebank additionally records relationships among phrases.</p><div class=\"table-wrap\"><table><thead><tr><th>Representation</th><th>Example information retained</th></tr></thead><tbody><tr><td>Bag of words</td><td>Words occur, but word order/grammar is lost</td></tr><tr><td>POS tags</td><td>Each word's local grammatical category</td></tr><tr><td>Chunks</td><td>Short phrase boundaries</td></tr><tr><td>Parse tree</td><td>Nested constituent structure of the whole sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Grammar rule ek expansion instruction hai: S ko NP aur VP mein kholo.</p><p><strong>Top-down parsing</strong> starts at the grammar's start symbol S and expands nonterminals until the leaves match the input words in order. <strong>Recursive descent</strong> commonly implements each nonterminal as a procedure that tries its productions. It builds from the root toward the leaves.</p><div class=\"flow\"><div class=\"node\">Start with S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose an allowed S production</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Expand its next nonterminal</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match the resulting terminal to the input</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Continue, or backtrack if the choice fails</div></div><p><strong>Algorithm.</strong> Start with S as the current goal. Choose a production for the leftmost unexpanded nonterminal. Replace that nonterminal by the production's right side. If a terminal appears, compare it with the next input token. If it matches, consume the token; if it does not, reject that branch and try another production. Accept only when the complete input is consumed and all grammar goals are satisfied.</p><p>A <strong>leftmost derivation</strong> always expands the leftmost remaining nonterminal first. Top-down parsing can make guesses that the actual words cannot support, so it may need backtracking. A naive recursive-descent parser can loop on left-recursive rules such as NP→NP PP unless the grammar or algorithm is changed. Predictive LL(1) parsing chooses productions using one lookahead token when the grammar permits; not every English CFG is LL(1).</p><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>Begins with</th><th>Direction</th><th>Common difficulty</th></tr></thead><tbody><tr><td>Top-down</td><td>Start symbol S</td><td>Root to word leaves</td><td>Predictions that do not match input; left recursion</td></tr><tr><td>Bottom-up</td><td>Actual input tokens</td><td>Leaves to root S</td><td>Reductions that cannot contribute to a complete sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Top-down: sentence ka structure pehle, words tak neeche aao.</p><p><strong>Bottom-up parsing</strong> starts from the input tokens and combines them into larger constituents until the start symbol is reached. A <strong>shift-reduce parser</strong> maintains a stack of recognized material and a list of remaining input tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Action</th><th>Exact operation</th><th>Example</th></tr></thead><tbody><tr><td>Shift</td><td>Move the next input token onto the stack</td><td>Stack: the; remaining input: dog runs</td></tr><tr><td>Reduce</td><td>Replace a suffix of the stack matching a rule's RHS with its LHS</td><td>Det N becomes NP using NP→Det N</td></tr><tr><td>Accept</td><td>Stack is S and input is exhausted</td><td>Stack: S; input: empty</td></tr><tr><td>Fail/backtrack</td><td>Chosen reductions cannot complete a parse</td><td>A noun reading of book blocks an imperative parse</td></tr></tbody></table></div><p>Reduction uses a production in reverse: the grammar NP→Det N expands an NP top-down, but reduces Det N into NP bottom-up. The stack's <strong>rightmost item is its top</strong> in the traces below. Each row shows the state <strong>after</strong> the listed action, avoiding an off-by-one mismatch between actions and stack contents.</p><p>A lexical reduction such as N→dog still counts as a reduction. Do not skip the sequence from word to category to phrase when the question asks for a complete trace. Backtracking means returning to an earlier choice and trying another applicable rule, not changing the original input.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Shift = input se stack. Reduce = chhote pieces se bada grammatical unit.</p>","m2":false,"units":"4","marks":null,"sourcePages":[1],"historical":true},{"id":"q1d","title":"Q1d · NLU versus NLG and applications","html":"<div class=\"question\"><strong>Question. Compare Natural Language Understanding and Natural Language Generation. List real-world NLP applications that use these concepts.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>Natural language understanding (NLU)</strong> maps language into an interpretation useful for a task: intents, entities, semantic relations or another meaning representation. <strong>Natural language generation (NLG)</strong> produces human-language output from data, a representation or another source.</p><div class=\"flow\"><div class=\"node\">“Book a ticket to Pune tomorrow.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">NLU: intent=book; destination=Pune; date=tomorrow</div><span aria-hidden=\"true\">→</span><div class=\"node\">Application: search available journeys</div><span aria-hidden=\"true\">→</span><div class=\"node\">NLG: “Here are the available journeys to Pune.”</div></div><table><thead><tr><th>Feature</th><th>NLU</th><th>NLG</th></tr></thead><tbody><tr><td>Direction</td><td>Language → interpretation</td><td>Data/representation → language</td></tr><tr><td>Main concern</td><td>Meaning, intent, ambiguity</td><td>Content choice, organization, fluent wording</td></tr><tr><td>Example</td><td>Find destination in a request</td><td>Write the booking confirmation</td></tr><tr><td>Common failure</td><td>Wrong destination or sense</td><td>Unclear, unsupported or ungrammatical output</td></tr></tbody></table><h3>NLG stages in a classical pipeline</h3><ol><li><strong>Content determination:</strong> choose facts to communicate.</li><li><strong>Data interpretation:</strong> identify relationships or trends.</li><li><strong>Document planning:</strong> organize facts in a useful order.</li><li><strong>Sentence aggregation:</strong> combine related facts without repetition.</li><li><strong>Lexical and grammatical realization:</strong> choose words and construct grammatical sentences.</li><li><strong>Presentation:</strong> format the generated message for its audience.</li></ol><p>For a weather report, facts {city=Pune, temperature=28°C, rain=yes} can become “Pune will have rain with a temperature of 28°C.” NLU would instead extract facts or intent from an incoming language message.</p><p class=\"cue\">NLU = language se meaning andar. NLG = data se language bahar.</p><p>A question-answering assistant interprets intent/entities through NLU and composes an answer through NLG. Translation interprets source meaning and generates a target-language sequence. A customer-support system classifies requests and generates a contextual reply.</p>","m2":false,"units":"1,7","marks":null,"sourcePages":[1],"historical":true},{"id":"q2a","title":"Q2a · TF–IDF cosine after a fixed stoplist","html":"<div class=\"question\"><strong>Question. For “The cat sat on the mat.”, “The dog barked at the cat.” and “I love my dog and my cat.” remove stopwords {I,the,on,my,at,and}; construct TF–IDF and calculate cosine similarity between the first two documents.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Original text</th></tr></thead><tbody><tr><td>1</td><td>The cat sat on the mat.</td></tr><tr><td>2</td><td>The dog barked at the cat.</td></tr><tr><td>3</td><td>I love my dog and my cat.</td></tr></tbody></table></div><p>Stopwords: at, my, i, on, the, and</p><h3>To find</h3><p>BoW, IDF and TF–IDF plus requested cosine</p><h3>Formula: which one and why</h3><p>Use lowercase alphabetic tokens and exactly the stated stoplist. If no stoplist is supplied, retain function words. Adopt raw-count TF and natural-log IDF; the paper does not prescribe another TF/log convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd85ae95ce50c427.svg\" alt=\"\\mathrm{TFIDF}(w,d)=c(w,d)\\ln\\frac{N}{\\mathrm{df}(w)}\" style=\"width:31.372ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A term shared by all N documents has IDF ln(1)=0. Counts and TF–IDF weights are different representations.</p><h3>Step 1. Tokenize each document</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Tokens</th></tr></thead><tbody><tr><td>1</td><td>cat, sat, mat</td></tr><tr><td>2</td><td>dog, barked, cat</td></tr><tr><td>3</td><td>love, dog, cat</td></tr></tbody></table></div><h3>Step 2. Fix the vocabulary order</h3><p>barked, cat, dog, love, mat, sat</p><h3>Step 3. Count occurrences (Bag of Words)</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>barked</th><th>cat</th><th>dog</th><th>love</th><th>mat</th><th>sat</th></tr></thead><tbody><tr><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td></tr><tr><td>2</td><td>1</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3</td><td>0</td><td>1</td><td>1</td><td>1</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 4. Calculate document frequency and IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>df</th><th>N / df</th><th>ln(N/df)</th></tr></thead><tbody><tr><td>barked</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>cat</td><td>3</td><td>1</td><td>0.000000000</td></tr><tr><td>dog</td><td>2</td><td>3/2</td><td>0.405465108</td></tr><tr><td>love</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>mat</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>sat</td><td>1</td><td>3</td><td>1.098612289</td></tr></tbody></table></div><h3>Step 5. Multiply each TF by its IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>barked</th><th>cat</th><th>dog</th><th>love</th><th>mat</th><th>sat</th></tr></thead><tbody><tr><td>1</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>1.098612</td></tr><tr><td>2</td><td>1.098612</td><td>0.000000</td><td>0.405465</td><td>0.000000</td><td>0.000000</td><td>0.000000</td></tr><tr><td>3</td><td>0.000000</td><td>0.000000</td><td>0.405465</td><td>1.098612</td><td>0.000000</td><td>0.000000</td></tr></tbody></table></div><h3>Step 6. Calculate cosine from these same TF–IDF rows</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/789b38cafe4954af.svg\" alt=\"\\cos(u,v)=\\frac{\\sum_i u_i v_i}{\\sqrt{\\sum_i u_i^2}\\sqrt{\\sum_i v_i^2}}\" style=\"width:28.191ex;height:7.518ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Coordinate products: 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.000000000</p><p>Dot product=0.000000000; squared norms=2.413897922, 1.371350915. Cosine=0.000000000</p><h3>Final answer</h3><p>The final table is the TF–IDF matrix in the declared vocabulary order. A different explicitly stated log base rescales all IDFs; length-normalized TF changes each document scale.</p><p>Cosine is 0.0. Shared words whose IDF is zero contribute nothing to the TF–IDF dot product.</p><h3>Which terms are prominent?</h3><p>D1: sat and mat have IDF ln3; D2: barked has ln3 and dog has ln(3/2); D3: love has ln3 and dog has ln(3/2). Cat occurs in all three documents and has zero unsmoothed IDF. Thus shared cat does not make D1/D2 TF–IDF cosine positive.</p>","m2":false,"units":"2","marks":10,"sourcePages":[1,2],"historical":true},{"id":"q2b","title":"Q2b · Weather Naive Bayes","html":"<div class=\"question\"><strong>Question. Use the supplied class/conditional probabilities to predict Play Tennis for Outlook=Sunny, Temperature=Cool, Humidity=High, Windy=True.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Prior</th><th>Sunny</th><th>Cool</th><th>High</th><th>True</th></tr></thead><tbody><tr><td>Yes</td><td>9/14</td><td>2/9</td><td>3/9</td><td>3/9</td><td>3/9</td></tr><tr><td>No</td><td>5/14</td><td>3/5</td><td>1/5</td><td>4/5</td><td>3/5</td></tr></tbody></table></div><h3>To find</h3><p>Compare the Yes and No class scores.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/300d051b2a893047.svg\" alt=\"\\mathrm{score}(c)=P(c)P(Sunny\\mid c)P(Cool\\mid c)P(High\\mid c)P(True\\mid c)\" style=\"width:61.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Multiply the Yes factors</h3><p>9/14 × 2/9 × 3/9 × 3/9 × 3/9 = 1/189 = 0.005291005</p><h3>Step 2. Multiply the No factors</h3><p>5/14 × 3/5 × 1/5 × 4/5 × 3/5 = 18/875 = 0.020571429</p><h3>Step 3. Compare and normalize</h3><p>Yes=0.204582651, No=0.795417349</p><h3>Final answer</h3><p><strong>Predict No.</strong> Apply the supplied categorical probabilities directly; adding vocabulary smoothing would solve a different problem.</p>","m2":false,"units":"7","marks":10,"sourcePages":[2],"historical":true},{"id":"q3a","title":"Q3a · Coreference and anaphora","html":"<div class=\"question\"><strong>Question. Explain coreference and anaphoric reference with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Pragmatic analysis</strong> interprets an utterance using its situation and the speaker’s intended meaning. <strong>Discourse analysis</strong> studies how utterances connect across a text or conversation. Syntax and literal word meanings alone cannot settle every interpretation.</p><table><thead><tr><th>Text</th><th>Literal content</th><th>Contextual interpretation</th></tr></thead><tbody><tr><td>“Can you close the window?”</td><td>A question about ability.</td><td>Usually a polite request.</td></tr><tr><td>“Meera bought a laptop. It was expensive.”</td><td>Two sentences.</td><td>“It” connects the second sentence to the laptop.</td></tr><tr><td>“Meet me here tomorrow.”</td><td>An instruction.</td><td>Me, here and tomorrow depend on speaker, place and date.</td></tr></tbody></table><h3>Reference, mention and antecedent</h3><p>A <strong>referring expression</strong> points to an entity; a <strong>mention</strong> is its occurrence in the text. Its <strong>referent</strong> is the entity being discussed. An <strong>antecedent</strong> is a preceding expression used to interpret a later referring expression. Reference resolution identifies the intended referent. Coreference resolution groups mentions that refer to the same entity.</p><div class=\"flow\"><div class=\"node\">“Meera”<small>name mention</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Person entity<small>same referent</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">“she” / “the engineer”<small>other mentions</small></div></div><table><thead><tr><th>Concept</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Anaphora</td><td>Reference back to something introduced earlier.</td><td>“Riya arrived. She sat down.” She → Riya.</td></tr><tr><td>Cataphora</td><td>Reference forward to a later expression.</td><td>“Before she spoke, Riya checked the microphone.” she → Riya.</td></tr><tr><td>Exophora</td><td>Reference to the situation outside the text.</td><td>“Put it there”, said while pointing.</td></tr><tr><td>Coreference</td><td>Two or more mentions refer to the same entity.</td><td>“Dr Rao”, “the lecturer”, “she”.</td></tr><tr><td>Pronoun resolution</td><td>Find the referent of a pronoun.</td><td>Resolve “it” in “The laptop stopped because it overheated.”</td></tr></tbody></table><p>Coreference is broader than pronoun resolution: repeated names and descriptions also form a chain. Anaphora describes direction/dependence; coreference describes identity. In “I bought a car. The engine is noisy”, engine is related to the car but is not the same entity.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Reference = kiski baat? Coreference = alag mentions, same entity. Pronoun resolution = he/she/it kis se linked?</p><h3>Cohesion, coherence and discourse markers</h3>\n<p><strong>Cohesion</strong> is the explicit linguistic linking of a text through reference, repeated or related words, conjunctions and other devices. In “Rita bought a book. She read it”, she and it connect the second sentence to Rita and the book.</p>\n<p><strong>Coherence</strong> is the conceptual unity that makes a discourse meaningful. “The road flooded, so the match was cancelled” presents a plausible cause and consequence. A reader relates the propositions using context and knowledge.</p>\n<p><strong>Discourse markers</strong> signal relationships or organize speech: however signals contrast; therefore signals a result; first and next signal sequence; for example introduces an illustration.</p>\n<p>These concepts differ: “I like apples. Therefore the moon is square” has a linking word but no sensible inference. A connector alone does not guarantee coherence.</p>\n<p><strong>Yaad rakho:</strong> Cohesion = words se link; coherence = meaning se link; marker = relation ka signal.</p><h3>A practical resolution procedure</h3><p>First detect the pronoun and candidate noun phrases. Eliminate candidates inconsistent with person, number, grammatical binding or relevant semantic constraints. Rank the surviving candidates using syntactic prominence, recency and discourse context. Preserve ambiguity if the available evidence does not decide.</p><table><thead><tr><th>Approach</th><th>How it works</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>Rule based / syntactic</td><td>Use parse trees, agreement and explicit search order; Hobbs is a classic example.</td><td>Can explain each decision without labelled training data.</td><td>Parsing errors and world knowledge gaps cause errors.</td></tr><tr><td>Salience based</td><td>Score candidates using recency, subjecthood and other discourse features; select the strongest compatible candidate.</td><td>Captures the tendency to refer again to prominent entities.</td><td>Feature weights and competing candidates can mislead.</td></tr><tr><td>Supervised statistical</td><td>Learn candidate/pronoun compatibility from labelled examples.</td><td>Combines many features from data.</td><td>Needs representative annotated examples.</td></tr><tr><td>Neural / contextual</td><td>Encode the surrounding text and score mention pairs or antecedents.</td><td>Can learn contextual patterns and long-range dependencies.</td><td>Needs data/compute and can still make confident mistakes.</td></tr></tbody></table><section class=\"example\"><h3>Worked analysis 1 · number and semantics</h3><p class=\"question\">Resolve “they” in: “Riya put the books on the shelf because they were heavy.”</p><div class=\"given\"><strong>Given</strong><p>Candidates: Riya (singular person), books (plural objects), shelf (singular object); pronoun they is plural here.</p><strong>To find</strong><p>The antecedent and a justified resolution procedure.</p></div><h3>Formula and why it applies</h3><p>Use number agreement first, then semantic compatibility. There is no multiplication formula in this linguistic task.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. List candidates</h4><p>Riya, the books, the shelf.</p></div><div class=\"step\"><h4>Step 2. Apply number agreement</h4><p>Riya and shelf are singular. Books is plural, matching they.</p></div><div class=\"step\"><h4>Step 3. Check meaning</h4><p>Books can be heavy; the causal explanation fits carrying/placing books.</p></div><div class=\"answer\">“They” refers to “the books”.</div></section><section class=\"example\"><h3>Worked analysis 2 · a complete coreference chain</h3><p class=\"question\">Identify the coreference chain in: “Dr Sen entered. The surgeon greeted Ravi. She opened her notebook.”</p><div class=\"given\"><strong>Given</strong><p>Mentions: Dr Sen, the surgeon, Ravi, she, her, her notebook. Assume the surgeon is Dr Sen and she/her refers to that surgeon.</p><strong>To find</strong><p>The person chain, and a mention that must not be placed in it.</p></div><h3>Formula and why it applies</h3><p>Group expressions by identity of referent; a possessive expression and the owned object are different entities.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Link the name and description</h4><p>Dr Sen and the surgeon denote the same person under the given context.</p></div><div class=\"step\"><h4>Step 2. Link the pronouns</h4><p>She and her refer to the surgeon.</p></div><div class=\"step\"><h4>Step 3. Keep the notebook separate</h4><p>“Her notebook” is an object owned by the person; it is not the person herself.</p></div><div class=\"answer\">Person chain: {Dr Sen, the surgeon, She, her}. “Her notebook” is a separate object mention.</div></section><section class=\"example\"><h3>Worked analysis 3 · honest ambiguity</h3><p class=\"question\">Discuss the pronoun in: “Asha called Nisha after she finished work.”</p><div class=\"given\"><strong>Given</strong><p>Both named candidates are singular; the sentence gives no further context.</p><strong>To find</strong><p>Whether one referent is logically guaranteed.</p></div><h3>Formula and why it applies</h3><p>Agreement filters incompatible candidates but cannot always select between equally compatible candidates.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Check agreement</h4><p>Both Asha and Nisha are compatible with she.</p></div><div class=\"step\"><h4>Step 2. Check the event</h4><p>Either person could have finished work.</p></div><div class=\"step\"><h4>Step 3. State the limitation</h4><p>A heuristic may prefer a candidate, but grammar and this sentence alone do not prove the intended referent.</p></div><div class=\"answer\">Ambiguous without further context. State any heuristic and parse assumption before giving its preferred candidate.</div></section>","m2":false,"units":"6","marks":5,"sourcePages":[2],"historical":true},{"id":"q3b","title":"Q3b · Cohesion, coherence and discourse markers","html":"<div class=\"question\"><strong>Question. Explain cohesion, coherence and discourse markers.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Pragmatic analysis</strong> interprets an utterance using its situation and the speaker’s intended meaning. <strong>Discourse analysis</strong> studies how utterances connect across a text or conversation. Syntax and literal word meanings alone cannot settle every interpretation.</p><table><thead><tr><th>Text</th><th>Literal content</th><th>Contextual interpretation</th></tr></thead><tbody><tr><td>“Can you close the window?”</td><td>A question about ability.</td><td>Usually a polite request.</td></tr><tr><td>“Meera bought a laptop. It was expensive.”</td><td>Two sentences.</td><td>“It” connects the second sentence to the laptop.</td></tr><tr><td>“Meet me here tomorrow.”</td><td>An instruction.</td><td>Me, here and tomorrow depend on speaker, place and date.</td></tr></tbody></table><h3>Reference, mention and antecedent</h3><p>A <strong>referring expression</strong> points to an entity; a <strong>mention</strong> is its occurrence in the text. Its <strong>referent</strong> is the entity being discussed. An <strong>antecedent</strong> is a preceding expression used to interpret a later referring expression. Reference resolution identifies the intended referent. Coreference resolution groups mentions that refer to the same entity.</p><div class=\"flow\"><div class=\"node\">“Meera”<small>name mention</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Person entity<small>same referent</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">“she” / “the engineer”<small>other mentions</small></div></div><table><thead><tr><th>Concept</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Anaphora</td><td>Reference back to something introduced earlier.</td><td>“Riya arrived. She sat down.” She → Riya.</td></tr><tr><td>Cataphora</td><td>Reference forward to a later expression.</td><td>“Before she spoke, Riya checked the microphone.” she → Riya.</td></tr><tr><td>Exophora</td><td>Reference to the situation outside the text.</td><td>“Put it there”, said while pointing.</td></tr><tr><td>Coreference</td><td>Two or more mentions refer to the same entity.</td><td>“Dr Rao”, “the lecturer”, “she”.</td></tr><tr><td>Pronoun resolution</td><td>Find the referent of a pronoun.</td><td>Resolve “it” in “The laptop stopped because it overheated.”</td></tr></tbody></table><p>Coreference is broader than pronoun resolution: repeated names and descriptions also form a chain. Anaphora describes direction/dependence; coreference describes identity. In “I bought a car. The engine is noisy”, engine is related to the car but is not the same entity.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Reference = kiski baat? Coreference = alag mentions, same entity. Pronoun resolution = he/she/it kis se linked?</p><h3>Cohesion, coherence and discourse markers</h3>\n<p><strong>Cohesion</strong> is the explicit linguistic linking of a text through reference, repeated or related words, conjunctions and other devices. In “Rita bought a book. She read it”, she and it connect the second sentence to Rita and the book.</p>\n<p><strong>Coherence</strong> is the conceptual unity that makes a discourse meaningful. “The road flooded, so the match was cancelled” presents a plausible cause and consequence. A reader relates the propositions using context and knowledge.</p>\n<p><strong>Discourse markers</strong> signal relationships or organize speech: however signals contrast; therefore signals a result; first and next signal sequence; for example introduces an illustration.</p>\n<p>These concepts differ: “I like apples. Therefore the moon is square” has a linking word but no sensible inference. A connector alone does not guarantee coherence.</p>\n<p><strong>Yaad rakho:</strong> Cohesion = words se link; coherence = meaning se link; marker = relation ka signal.</p><h3>Definitions and examples requested in this part</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Cohesion</td><td>Explicit language links connecting text: pronouns, repetition, conjunctions, lexical ties</td><td>Rita bought a book. She read it. She/it refer back to Rita/book.</td></tr><tr><td>Coherence</td><td>Conceptual unity and plausible relations making the text meaningful</td><td>The road flooded, so the match was cancelled: cause and consequence connect the propositions.</td></tr><tr><td>Discourse marker</td><td>Expression signalling relation or organizing the discourse</td><td>however=contrast; therefore=result; first/next=sequence; for example=illustration</td></tr></tbody></table></div><p>“I like apples. Therefore the moon is square” contains a connector but lacks a sensible inference: surface cohesion does not guarantee coherence.</p>","m2":false,"units":"6","marks":5,"sourcePages":[2],"historical":true},{"id":"q3c","title":"Q3c · Question answering system","html":"<div class=\"question\"><strong>Question. Explain a question-answering system with its architecture and an example.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Question answering (QA) returns an answer to a natural-language question using available evidence or knowledge.</strong> Information retrieval usually returns ranked documents; QA must identify the requested information and deliver the answer. A relevant document is useful evidence but is not automatically the answer.</p><h3>Question types and answer types</h3><table><thead><tr><th>Question</th><th>Expected answer type</th><th>Required operation</th></tr></thead><tbody><tr><td>Who founded the company?</td><td>Person or organisation</td><td>Find the founder relation</td></tr><tr><td>When did the museum open?</td><td>Date/time</td><td>Locate the opening date</td></tr><tr><td>Where is the campus?</td><td>Location</td><td>Locate the campus-location relation</td></tr><tr><td>How many books were issued?</td><td>Quantity</td><td>Read or compute the stated count</td></tr><tr><td>Why was the train cancelled?</td><td>Reason/explanation</td><td>Find the causal evidence</td></tr><tr><td>Is the office open on Sunday?</td><td>Yes/no with evidence</td><td>Check the relevant schedule statement</td></tr></tbody></table><p><strong>Closed-domain QA</strong> operates within a restricted area such as a university handbook. <strong>Open-domain QA</strong> addresses a wider range of subjects and usually needs broad retrieval. <strong>Extractive QA</strong> selects a span from a passage. <strong>Generative QA</strong> constructs answer text; it still must preserve the evidence and avoid unsupported details.</p><div class=\"flow\"><div class=\"node\">Question analysis</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evidence retrieval</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Passage/record understanding</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Answer selection or composition</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Support check</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Present answer</div></div><h3>Explain each module</h3><table><thead><tr><th>Module</th><th>What happens</th><th>Why it matters</th></tr></thead><tbody><tr><td>Question analysis</td><td>Identify topic, intent, constraints and answer type.</td><td>When asks for a time, not a place.</td></tr><tr><td>Retrieval</td><td>Find a relevant passage or structured fact.</td><td>Reduces the search space.</td></tr><tr><td>Evidence understanding</td><td>Parse relations, resolve references and ambiguous words.</td><td>The correct date must belong to the correct event.</td></tr><tr><td>Answer formation</td><td>Extract a span or compose a short supported response.</td><td>Turns a document into an actual answer.</td></tr><tr><td>Verification</td><td>Check whether every claimed detail follows from evidence.</td><td>Prevents filling gaps by guessing.</td></tr><tr><td>Presentation</td><td>Return a concise answer with suitable context.</td><td>Avoids dumping unrelated text.</td></tr></tbody></table><section class=\"example\"><h3>Worked application 1 · extract the correct fact</h3><p class=\"question\"><strong>Question. Given “The City Museum opened in 1998 in Pune. It was renovated in 2016”, answer “When did the museum open?” Show the QA stages.</strong></p><div class=\"given\"><h4>Given</h4><p>A two-sentence passage. Dates 1998 and 2016 refer to different events.</p><h4>To find</h4><p>The opening date, not the renovation date.</p></div><h4>Method and why it applies</h4><p>Use extractive QA: identify the requested event and expected date type, then choose the span linked to that event.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Analyse the question</h4><p>When requires a date/time answer. The event is opening; the entity is the City Museum.</p></div><div class=\"step\"><h4>Step 2. Retrieve the relevant sentence</h4><p>The first sentence mentions the museum and its opening. The second sentence discusses renovation.</p></div><div class=\"step\"><h4>Step 3. Identify event–date relations</h4><table><thead><tr><th>Event</th><th>Date</th></tr></thead><tbody><tr><td>opened</td><td>1998</td></tr><tr><td>renovated</td><td>2016</td></tr></tbody></table></div><div class=\"step\"><h4>Step 4. Select the answer span</h4><p>1998 is attached to opened, so select the four-character year span 1998.</p></div><div class=\"step\"><h4>Step 5. Reject the distractor</h4><p>2016 is also a date, but it answers a different question: when was the museum renovated?</p></div><div class=\"step\"><h4>Step 6. Present the answer</h4><p>“The museum opened in 1998.”</p></div><div class=\"answer\"><strong>Answer.</strong> 1998. Matching only the answer type date would be insufficient without matching the event.</div></section><section class=\"example\"><h3>Worked application 2 · resolve a pronoun before answering</h3><p class=\"question\"><strong>Question. Given “Mira joined Orion Labs in 2022. She became its research lead in 2024”, answer “Who became Orion Labs' research lead, and when?”</strong></p><div class=\"given\"><h4>Given</h4><p>The passage contains the name Mira, pronoun She, organisation Orion Labs and possessive its. Assume the normal reading that She refers to Mira and its to Orion Labs.</p><h4>To find</h4><p>The person and the date of becoming research lead.</p></div><h4>Method and why it applies</h4><p>Combine reference resolution with relation extraction. The question asks for two fields, both tied to the promotion/role event.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify requested fields</h4><p>Who → person; when → date. The relation is became research lead of Orion Labs.</p></div><div class=\"step\"><h4>Step 2. Resolve mentions</h4><table><thead><tr><th>Mention</th><th>Referent</th></tr></thead><tbody><tr><td>She</td><td>Mira</td></tr><tr><td>its</td><td>Orion Labs</td></tr></tbody></table></div><div class=\"step\"><h4>Step 3. Read the target event</h4><p>After resolution, the second sentence states that Mira became Orion Labs' research lead in 2024.</p></div><div class=\"step\"><h4>Step 4. Distinguish the dates</h4><p>2022 belongs to joining the organisation. 2024 belongs to becoming research lead.</p></div><div class=\"step\"><h4>Step 5. Compose a supported answer</h4><p>“Mira became Orion Labs' research lead in 2024.”</p></div><div class=\"step\"><h4>Step 6. Verify completeness</h4><p>The answer supplies both requested fields and does not add an unsupported department, qualification or reason.</p></div><div class=\"answer\"><strong>Answer.</strong> Mira, in 2024. Reference resolution connects the second sentence to the named person and organisation.</div></section><section class=\"example\"><h3>Worked application 3 · detect insufficient evidence</h3><p class=\"question\"><strong>Question. A handbook excerpt states “The library opens at 8 a.m. on weekdays.” A user asks “At what time does it close on Sunday?” Explain the correct QA response.</strong></p><div class=\"given\"><h4>Given</h4><p>Only the opening time for weekdays is supplied. No closing time or Sunday schedule is present.</p><h4>To find</h4><p>Whether an answer is supported and how to handle the missing information.</p></div><h4>Method and why it applies</h4><p>Compare every question constraint against the evidence. Topic overlap with library is not sufficient: time type and day must also match.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Extract the question constraints</h4><table><thead><tr><th>Constraint</th><th>Requested</th></tr></thead><tbody><tr><td>Entity</td><td>Library</td></tr><tr><td>Event</td><td>Closing</td></tr><tr><td>Day</td><td>Sunday</td></tr><tr><td>Answer type</td><td>Time</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Extract the supplied fact</h4><p>Entity=library; event=opening; day=weekdays; time=8 a.m.</p></div><div class=\"step\"><h4>Step 3. Identify mismatches</h4><p>Opening is not closing. Weekdays do not supply a Sunday schedule.</p></div><div class=\"step\"><h4>Step 4. Avoid the unsupported substitution</h4><p>Do not answer 8 a.m. just because it is the only time in the passage.</p></div><div class=\"step\"><h4>Step 5. Return an evidence-limited response</h4><p>“The excerpt does not state the library's Sunday closing time.” A system with further retrieval can search a relevant schedule.</p></div><div class=\"step\"><h4>Step 6. State the benefit</h4><p>The system avoids converting a relevant-looking number into an incorrect answer.</p></div><div class=\"answer\"><strong>Answer.</strong> No Sunday closing time is supported by the excerpt. Report insufficient evidence or retrieve the missing schedule.</div></section><h3>Advantages, limits and evaluation</h3><table><thead><tr><th>Design choice</th><th>Benefit</th><th>Limitation</th></tr></thead><tbody><tr><td>Extractive answer</td><td>The returned wording comes directly from evidence.</td><td>The answer may require combining sentences or may not be present as one span.</td></tr><tr><td>Generative answer</td><td>Can combine supported facts into a readable response.</td><td>Can introduce unsupported information unless carefully checked.</td></tr><tr><td>Closed-domain collection</td><td>Controlled terminology and relevant resources.</td><td>Cannot answer facts outside its knowledge source.</td></tr><tr><td>Broad retrieval</td><td>Wider question coverage.</td><td>Irrelevant, outdated or conflicting sources can be retrieved.</td></tr></tbody></table><p>Evaluate <strong>exact match</strong> when a canonical answer string is expected, <strong>token overlap/F1</strong> when wording may vary, and <strong>factual correctness and completeness</strong> when answers are composed. An answer can be grammatically fluent but wrong. Questions with no answer in the evidence should be included in evaluation so the system's restraint is also tested.</p><p>For a longer exam answer, define QA, distinguish it from retrieval, explain answer types and system variants, draw the pipeline, work through a passage including distractors, and discuss ambiguity, missing evidence and evaluation. A list of chatbot names is not a QA design.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Question ka entity + event + constraint match karo. Passage mein koi bhi number mil gaya matlab answer nahi.</p>","m2":false,"units":"7","marks":10,"sourcePages":[2],"historical":true},{"id":"q4a","title":"Q4a · NLP pipeline","html":"<div class=\"question\"><strong>Question. Explain the stages of an NLP pipeline.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>An NLP pipeline is an organized sequence of operations that transforms raw language into a task output and checks whether that output is useful.</strong> Not every task needs every cleaning operation.</p><div class=\"flow\"><div class=\"node\">Data acquisition</div><span aria-hidden=\"true\">→</span><div class=\"node\">Preprocessing</div><span aria-hidden=\"true\">→</span><div class=\"node\">Feature representation</div><span aria-hidden=\"true\">→</span><div class=\"node\">Model</div><span aria-hidden=\"true\">→</span><div class=\"node\">Evaluation</div><span aria-hidden=\"true\">→</span><div class=\"node\">Deployment and monitoring</div></div><ol><li><strong>Data acquisition:</strong> collect relevant text and, when needed, labels.</li><li><strong>Cleaning and preprocessing:</strong> handle markup, tokenize, normalize and decide which information to retain.</li><li><strong>Feature engineering:</strong> represent text numerically using BoW, TF–IDF or embeddings.</li><li><strong>Modelling:</strong> apply rules or train a statistical/neural model.</li><li><strong>Evaluation:</strong> test on held-out data using task-appropriate measures.</li><li><strong>Deployment:</strong> make the system available, log suitable feedback and monitor errors or data changes.</li></ol><h3>Concrete spam-filter example</h3><p>Collect labelled emails → separate train/test data → tokenize text while preserving meaningful terms → fit vocabulary and IDF on training data → train classifier → evaluate spam detection on the held-out set → deploy an email service filter → monitor legitimate emails wrongly blocked.</p><p><strong>Intrinsic evaluation</strong> measures model/task quality, such as precision, recall or tagging accuracy. <strong>Extrinsic evaluation</strong> measures effect in the wider application, such as whether users find answers faster. A higher internal metric does not automatically guarantee a better user outcome.</p><p><strong>Data leakage:</strong> learning vocabulary statistics, labels or preprocessing decisions from the test set can make reported performance too optimistic. Fit learned transformations on training data, then apply them to validation/test data.</p><p class=\"cue\">Collect → clean → numbers → model → test → use. Test data ko training ki information mat banao.</p><p><strong>Definition.</strong> NLP is the study of computational methods for analyzing, understanding and generating human language. The pipeline diagram above turns raw language into a task-specific prediction or generated response.</p>","m2":false,"units":"1","marks":5,"sourcePages":[2],"historical":true},{"id":"q4b","title":"Q4b · Morphology and syntax","html":"<div class=\"question\"><strong>Question. Explain the importance of morphology and syntax in NLP.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>A phoneme</strong> is a sound unit that can distinguish meanings in a language, such as the /p/ and /b/ contrast in “pat” and “bat”. A phoneme is a sound, not necessarily one alphabet letter. <strong>A morpheme</strong> is the smallest meaning-bearing grammatical unit: cats = cat + plural -s; unhappy = un- + happy.</p><p><strong>A lexeme</strong> is an abstract vocabulary item grouping its inflected forms: write, writes, wrote and writing belong to WRITE. A <strong>phrase</strong> is a group of words functioning together; a <strong>clause</strong> normally contains a predicate and its associated participants; a <strong>sentence</strong> expresses a complete grammatical unit.</p><table><thead><tr><th>Level</th><th>What it analyses</th><th>Concrete example</th></tr></thead><tbody><tr><td>Phonetics / phonology</td><td>Physical sounds / sound patterns in a language</td><td>Distinguish bat from pat</td></tr><tr><td>Morphology / lexical analysis</td><td>Word structure and lexical items</td><td>un + help + ful → unhelpful</td></tr><tr><td>Syntax</td><td>Grammatical arrangement and relationships</td><td>The dog chased the cat: subject, verb, object</td></tr><tr><td>Semantics</td><td>Meaning of words and composed expressions</td><td>The dog is the chaser; the cat is chased</td></tr><tr><td>Discourse</td><td>Connections across sentences</td><td>“Riya arrived. She smiled.” → She refers to Riya</td></tr><tr><td>Pragmatics</td><td>Intended meaning in the situation</td><td>“It is cold here” may request closing the window</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">word forms</div><span aria-hidden=\"true\">→</span><div class=\"node\">grammatical structure</div><span aria-hidden=\"true\">→</span><div class=\"node\">sentence meaning</div><span aria-hidden=\"true\">→</span><div class=\"node\">cross-sentence context</div><span aria-hidden=\"true\">→</span><div class=\"node\">speaker intention</div></div><h3>Three worked interpretations</h3><p><strong>“The cats are sleeping.”</strong> Morphology identifies cat + s as plural. Syntax connects “cats” to “are sleeping”. Semantics represents animals engaged in sleeping.</p><p><strong>“Aman bought a laptop. It was expensive.”</strong> Sentence-level syntax alone does not identify “it”. Discourse connects “it” to the laptop across the sentence boundary.</p><p><strong>“Wonderful, another power cut!”</strong> The word wonderful is positive literally, but situational context can indicate sarcasm and frustration. This is a pragmatic interpretation.</p><p>The analysis levels are conceptual descriptions. Modern systems may learn several jointly rather than executing a compulsory separate module for every level.</p><p class=\"cue\">Morphology = word ke andar; syntax = sentence ka structure; semantics = meaning; discourse = sentences ka link; pragmatics = intention.</p><p>Morphology analyzes internal word structure: unreadable→un+read+able, cats→cat+plural. Syntax analyzes how words combine: subject–verb–object relations distinguish “dog bites man” from “man bites dog”. Morphological normalization supports vocabulary matching; syntax preserves grammatical relations needed for parsing, extraction and translation.</p><p>Translation needs morphological number/tense agreement and target-language word order. Sentiment needs syntax to distinguish “not good” from “good” and morphology to relate disappointed/disappointing to their base form without discarding the negative meaning.</p>","m2":false,"units":"1","marks":5,"sourcePages":[2],"historical":true},{"id":"q4c","title":"Q4c · Most probable bigram continuations","html":"<div class=\"question\"><strong>Question. Train on &lt;s&gt; I love programming &lt;/s&gt;; &lt;s&gt; Programming is fun &lt;/s&gt;; &lt;s&gt; I love coding &lt;/s&gt;; &lt;s&gt; Coding is great &lt;/s&gt;. Predict next tokens for &lt;s&gt; I love ..., &lt;s&gt; programming ..., &lt;s&gt; coding ... using a bigram model.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>&lt;s&gt; I love programming &lt;/s&gt;<br>&lt;s&gt; Programming is fun &lt;/s&gt;<br>&lt;s&gt; I love coding &lt;/s&gt;<br>&lt;s&gt; Coding is great &lt;/s&gt;</p><h3>To find</h3><p>Most probable next token for each prefix.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bd18c85b739d1cb7.svg\" alt=\"P(w\\mid h)=\\frac{c(h,w)}{\\sum_v c(h,v)}\" style=\"width:22.157ex;height:5.573ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Lowercase lexical tokens; include sentence-end as an observed next token. Bigram prediction uses only the last token of the prefix.</p><h3>Step 1. Count each adjacent pair separately within sentences</h3><div class=\"table-wrap\"><table><thead><tr><th>Bigram</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt; → coding</td><td>1</td></tr><tr><td>&lt;s&gt; → i</td><td>2</td></tr><tr><td>&lt;s&gt; → programming</td><td>1</td></tr><tr><td>coding → &lt;/s&gt;</td><td>1</td></tr><tr><td>coding → is</td><td>1</td></tr><tr><td>fun → &lt;/s&gt;</td><td>1</td></tr><tr><td>great → &lt;/s&gt;</td><td>1</td></tr><tr><td>i → love</td><td>2</td></tr><tr><td>is → fun</td><td>1</td></tr><tr><td>is → great</td><td>1</td></tr><tr><td>love → coding</td><td>1</td></tr><tr><td>love → programming</td><td>1</td></tr><tr><td>programming → &lt;/s&gt;</td><td>1</td></tr><tr><td>programming → is</td><td>1</td></tr></tbody></table></div><h3>Step 2. Continue &lt;s&gt; I love</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate</th><th>Count / history count</th><th>Probability</th></tr></thead><tbody><tr><td>coding</td><td>1/2</td><td>0.500000</td></tr><tr><td>programming</td><td>1/2</td><td>0.500000</td></tr></tbody></table></div><p>Highest: programming, coding. This is a tie; no tie-break rule is supplied.</p><h3>Step 3. Continue &lt;s&gt; programming</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate</th><th>Count / history count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;/s&gt;</td><td>1/2</td><td>0.500000</td></tr><tr><td>is</td><td>1/2</td><td>0.500000</td></tr></tbody></table></div><p>Highest: &lt;/s&gt;, is. This is a tie; no tie-break rule is supplied.</p><h3>Step 4. Continue &lt;s&gt; coding</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate</th><th>Count / history count</th><th>Probability</th></tr></thead><tbody><tr><td>&lt;/s&gt;</td><td>1/2</td><td>0.500000</td></tr><tr><td>is</td><td>1/2</td><td>0.500000</td></tr></tbody></table></div><p>Highest: &lt;/s&gt;, is. This is a tie; no tie-break rule is supplied.</p><h3>Final answer</h3><p>&lt;s&gt; I love → programming or coding<br>&lt;s&gt; programming → &lt;/s&gt; or is<br>&lt;s&gt; coding → &lt;/s&gt; or is</p><p>If an examiner explicitly restricts the answer to a lexical word, exclude END and state that restricted candidate set. Do not silently remove an END tie.</p>","m2":false,"units":"3","marks":10,"sourcePages":[2,3],"historical":true},{"id":"q5a","title":"Q5a · Preprocess the NLP passage","html":"<div class=\"question\"><strong>Question. Perform the requested text preprocessing on: “Natural Language Processing (NLP) is a field of artificial intelligence that focuses on the interaction between computers and humans through natural language. The ultimate objective of NLP is to read, decipher, understand, and make sense of human languages in a valuable way.” Remove the supplied stopwords {is,a,of,that,on,I,the,and,to,in}.</strong> <span class=\"marks\">[6 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Stage</th><th>Result</th></tr></thead><tbody><tr><td>Sentence segmentation</td><td>Natural Language Processing (NLP) is a field of artificial intelligence that focuses on the interaction between computers and humans through natural language.<br>The ultimate objective of NLP is to read, decipher, understand, and make sense of human languages in a valuable way.</td></tr><tr><td>Word tokens (punctuation omitted)</td><td>Natural, Language, Processing, NLP, is, a, field, of, artificial, intelligence, that, focuses, on, the, interaction, between, computers, and, humans, through, natural, language, The, ultimate, objective, of, NLP, is, to, read, decipher, understand, and, make, sense, of, human, languages, in, a, valuable, way</td></tr><tr><td>Lowercase</td><td>natural, language, processing, nlp, is, a, field, of, artificial, intelligence, that, focuses, on, the, interaction, between, computers, and, humans, through, natural, language, the, ultimate, objective, of, nlp, is, to, read, decipher, understand, and, make, sense, of, human, languages, in, a, valuable, way</td></tr><tr><td>Declared stoplist</td><td>a, and, i, in, is, of, on, that, the, to</td></tr><tr><td>After exact stop removal</td><td>natural, language, processing, nlp, field, artificial, intelligence, focuses, interaction, between, computers, humans, through, natural, language, ultimate, objective, nlp, read, decipher, understand, make, sense, human, languages, valuable, way</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Why it is useful</th></tr></thead><tbody><tr><td>Sentence segmentation</td><td>Defines separate units for parsing and prevents counts from crossing sentence boundaries.</td></tr><tr><td>Lowercasing</td><td>Merges case variants when capitalization is not needed; retain original case for NER when useful.</td></tr><tr><td>Stop removal</td><td>Can remove frequent low-information words for a bag-of-words retrieval task; it is task-dependent and can damage negation/grammar.</td></tr><tr><td>Tokenization</td><td>Defines the units whose counts/features are computed; punctuation and abbreviation conventions must be consistent.</td></tr></tbody></table></div>","m2":false,"units":"2","marks":6,"sourcePages":[3],"historical":true},{"id":"q5b","title":"Q5b · Stemming and lemmatization tools","html":"<div class=\"question\"><strong>Question. Differentiate stemming and lemmatization, naming two approaches/tools for each.</strong> <span class=\"marks\">[4 marks]</span></div><h3>Answer</h3><p><strong>Stemming</strong> applies string-based rules, often stripping suffixes, to reduce related forms to a stem. The result need not be a valid dictionary word. <strong>Lemmatization</strong> uses vocabulary and morphological analysis, often with POS information, to return a dictionary lemma.</p><table><thead><tr><th>Criterion</th><th>Stemming</th><th>Lemmatization</th></tr></thead><tbody><tr><td>Basis</td><td>Surface form/suffix rules</td><td>Lexicon and morphological/POS analysis</td></tr><tr><td>Output</td><td>May be nonword, e.g. studi</td><td>Dictionary form, e.g. study</td></tr><tr><td>Context/POS</td><td>Usually little or none</td><td>Often important</td></tr><tr><td>Irregular forms</td><td>May miss went→go</td><td>Can map went→go with verb analysis</td></tr><tr><td>Cost</td><td>Generally simpler</td><td>Usually more linguistic processing</td></tr></tbody></table><p>Porter applies a sequence of suffix-removal rules subject to conditions; Snowball provides related language-specific stemming algorithms; Lancaster is often more aggressive; regex stemming uses explicit patterns; Lovins is another established stemming approach. Exact output depends on the algorithm and implementation.</p><h3>Three worked reductions</h3><ol><li><strong>studies, studying:</strong> an English stemmer may yield studi/study depending on the rule sequence; verb lemmatization aims at study. State the exact algorithm if exact outputs are asked.</li><li><strong>better:</strong> adjective-aware lemmatization can map it to good; naïve suffix removal cannot infer that irregular relation.</li><li><strong>saw:</strong> as a past-tense verb it can become see; as a cutting-tool noun it remains saw. POS and context matter.</li></ol><p><strong>Over-stemming</strong> merges forms that should remain distinct; <strong>under-stemming</strong> fails to merge related forms. Normalization can increase recall in search while losing useful distinctions, so it is a task-dependent choice.</p><p class=\"cue\">Stem = rules se cut; lemma = dictionary form, meaning/POS ka dhyan.</p><p>Examples of stemmers: Porter and Lancaster (Snowball is another). Examples of lemmatization tools: WordNet lemmatizer with POS information and spaCy’s language-specific lemmatizer. Outputs depend on language and supplied POS; better→good requires lexical knowledge, unlike simple suffix cutting.</p>","m2":false,"units":"2","marks":4,"sourcePages":[3],"historical":true},{"id":"q5c","title":"Q5c · Hobbs on John and Mary","html":"<div class=\"question\"><strong>Question. Explain Hobbs’ algorithm and resolve the pronouns in “John gave a book to Mary after he finished reading it.”</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Hobbs’ algorithm is a syntax-based procedure that searches constituent parse trees in a fixed order for a compatible noun-phrase antecedent of a pronoun.</strong> The tree determines which candidates are proposed first. Agreement and other relevant constraints determine whether a proposed candidate can be accepted.</p><p>It is not simply the rule “choose the closest noun”. A nearby noun may have the wrong number, may be syntactically ineligible, or may be visited after a structurally more prominent noun. The algorithm produces a preference under the supplied parse; ambiguous language can still require context.</p><h3>The tree vocabulary you need</h3><table><thead><tr><th>Term</th><th>Meaning</th><th>Example</th></tr></thead><tbody><tr><td>NP</td><td>Noun phrase: a phrase referring to an entity</td><td>the student; Anita; they</td></tr><tr><td>S</td><td>A sentence/clause node</td><td>the node containing a subject and predicate</td></tr><tr><td>VP</td><td>Verb phrase</td><td>told Ravi that she should revise</td></tr><tr><td>X</td><td>The NP or S node currently being searched</td><td>An algorithm label, not a word</td></tr><tr><td>Path p</td><td>The branch travelled upward from the pronoun/previous X</td><td>Used to distinguish left and right subtrees</td></tr><tr><td>N-bar (N′)</td><td>The noun-centred part of an NP in a grammar using that label</td><td>The nominal-child test depends on the given tree</td></tr><tr><td>Breadth-first</td><td>Visit shallower nodes before deeper ones</td><td>Level 1 before level 2</td></tr><tr><td>Left-to-right</td><td>Visit equally deep nodes in their written/tree order</td><td>Earlier left branch before right branch</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">Locate pronoun NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Climb to NP/S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Propose candidates in tree order</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Check compatibility</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Accept or continue searching</div></div><h3>The complete search procedure</h3><div class=\"step\"><h4>Step 1. Start at the pronoun</h4><p>Locate the NP immediately dominating the pronoun. “Dominating” means containing it as a descendant in the tree.</p></div><div class=\"step\"><h4>Step 2. Climb to the first NP or S</h4><p>Move upward to the first NP or S above that starting NP. Call this node X. Keep the upward path p.</p></div><div class=\"step\"><h4>Step 3. Search the left branches initially</h4><p>Below X, traverse branches to the left of p breadth-first and left-to-right. At this initial search, propose an NP only if another NP or S lies between that candidate and X. Test proposed candidates for the required agreement and constraints.</p></div><div class=\"step\"><h4>Step 4. If X is the highest sentence node, inspect earlier sentences</h4><p>Search previous sentence trees from most recent to oldest. Within each, use breadth-first, left-to-right order to propose NPs. Accept the first eligible compatible candidate, or report that no candidate was found in the available context.</p></div><div class=\"step\"><h4>Step 5. Otherwise climb again</h4><p>Move from X to the next NP or S above it. Record this new X and the path followed during the climb.</p></div><div class=\"step\"><h4>Step 6. Apply the higher-NP test</h4><p>If the new X is an NP, propose X when the path did not pass through its nominal N-bar child. Use the given parse labels; do not invent an N-bar branch missing from the question's structure.</p></div><div class=\"step\"><h4>Step 7. Search its left branches</h4><p>Traverse branches below the new X to the left of the path, breadth-first and left-to-right, proposing NPs. The special intervening-NP/S restriction belongs to the initial search in Step 3.</p></div><div class=\"step\"><h4>Step 8. If X is S, search the permitted right branches</h4><p>Search branches to the right of the path breadth-first and left-to-right. Do not descend below an encountered NP or S. Propose eligible NP candidates there.</p></div><div class=\"step\"><h4>Step 9. Repeat or stop</h4><p>Return to the highest-S check and continue the climb/search procedure until a compatible candidate is accepted or the available trees are exhausted. Record the candidate order rather than only writing an unexplained name.</p></div><h3>Why the first left search has an extra condition</h3><p>In a simple clause such as “John saw him”, the subject NP John is directly under the clause S. There is no extra NP or S between John and that S. The initial-search restriction therefore prevents casually selecting John as the ordinary local antecedent of him. Compare the reflexive “John saw himself”, which is a different grammatical case; do not treat every pronoun type as interchangeable.</p><section class=\"example\"><h3>Worked tree 1 · move to the previous sentence</h3><p class=\"question\"><strong>Question. Apply Hobbs’ search to “The student arrived. She smiled.” Assume the student is compatible with she.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree: [S [NP The student] [VP arrived]]. Current tree: [S [NP She] [VP smiled]].</p><h4>To find</h4><p>The selected antecedent and the search path.</p></div><h4>Method and why it applies</h4><p>Use the supplied constituent trees. The current sentence has no earlier candidate, so the highest-S rule activates previous-sentence search.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw both sentence structures</h4><pre aria-label=\"Two constituent trees\">Previous sentence             Current sentence\nS                             S\n├── NP: The student            ├── NP: She ← start\n└── VP: arrived                └── VP: smiled</pre></div><div class=\"step\"><h4>Step 2. Locate and climb</h4><p>Start at NP She. Its first higher NP/S is the current S. Set X to that S.</p></div><div class=\"step\"><h4>Step 3. Search left of the path</h4><p>She is the leftmost subject. No NP lies to its left in the current sentence.</p></div><div class=\"step\"><h4>Step 4. Use the highest-S rule</h4><p>This X is the highest S. Inspect the immediately preceding sentence tree.</p></div><div class=\"step\"><h4>Step 5. Propose its first NP</h4><p>Breadth-first, left-to-right finds NP The student.</p></div><div class=\"step\"><h4>Step 6. Check compatibility and accept</h4><p>The question stipulates that the student agrees with she. Accept this candidate.</p></div><div class=\"answer\"><strong>Answer.</strong> She refers to the student under the supplied assumptions.</div></section><section class=\"example\"><h3>Worked tree 2 · reject an incompatible subject</h3><p class=\"question\"><strong>Question. Resolve they in “Riya spoke to the students. They laughed.” Use a previous-sentence search and interpret they as plural.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree has subject NP Riya, then VP spoke [PP to [NP the students]]. Current subject is NP They.</p><h4>To find</h4><p>The candidate order and accepted antecedent.</p></div><h4>Method and why it applies</h4><p>Breadth-first search favours a shallow subject, but agreement must still be applied; a first candidate is not automatically a valid answer.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw the useful part of the previous tree</h4><pre aria-label=\"Riya and the students constituent tree\">S\n├── NP: Riya                 ← candidate 1\n└── VP\n    ├── V: spoke\n    └── PP\n        ├── P: to\n        └── NP: the students ← candidate 2</pre></div><div class=\"step\"><h4>Step 2. Search the current sentence</h4><p>From NP They climb to its S; there is no earlier NP in “They laughed”. This is the highest S, so move to the previous tree.</p></div><div class=\"step\"><h4>Step 3. Visit Riya first</h4><p>Riya is the shallower leftmost NP. Under the stated plural interpretation, this singular candidate fails number agreement.</p></div><div class=\"step\"><h4>Step 4. Visit the students</h4><p>Continue breadth-first. The next relevant NP is the students.</p></div><div class=\"step\"><h4>Step 5. Apply number agreement</h4><p>Students is plural and is an eligible candidate. It matches plural they.</p></div><div class=\"step\"><h4>Step 6. State the resolution</h4><p>Accept the students. The method did not simply accept the first noun it saw.</p></div><div class=\"answer\"><strong>Answer.</strong> They → the students. Candidate order: Riya rejected; the students accepted.</div></section><section class=\"example\"><h3>Worked tree 3 · climb out of an embedded clause</h3><p class=\"question\"><strong>Question. Resolve she in “Anita told Ravi that she should revise.” Assume Anita is compatible with she and Ravi is not. Use the displayed parse.</strong></p><div class=\"given\"><h4>Given</h4><p>The pronoun is the subject of an embedded S inside the main VP.</p><h4>To find</h4><p>The preferred antecedent found by the climb and left-branch search.</p></div><h4>Method and why it applies</h4><p>The embedded clause has no left candidate. Climbing to the main S exposes its subject Anita as the first suitable higher-level candidate.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Show the clause structure</h4><pre aria-label=\"Embedded clause pronoun tree\">S (main)\n├── NP: Anita                  ← accepted candidate\n└── VP\n    ├── V: told\n    ├── NP: Ravi\n    └── SBAR: that\n        └── S (embedded)       ← first X\n            ├── NP: she        ← start\n            └── VP: should revise</pre></div><div class=\"step\"><h4>Step 2. Start inside the embedded clause</h4><p>From NP she climb to the embedded S. There is no candidate to the left of she within this embedded S.</p></div><div class=\"step\"><h4>Step 3. Climb to the next NP/S</h4><p>The embedded S is not the highest S. Move upward through SBAR and VP to the main S. These intermediate nodes are not NP/S search nodes.</p></div><div class=\"step\"><h4>Step 4. Search left of the upward path</h4><p>At the main S, the subject NP Anita is a shallow left candidate. The object Ravi is deeper within the VP. Breadth-first order proposes Anita first.</p></div><div class=\"step\"><h4>Step 5. Check the stated compatibility</h4><p>Anita is compatible with she by the question's assumption. Accept it; no need to choose a later incompatible candidate.</p></div><div class=\"step\"><h4>Step 6. Give the result and its limit</h4><p>This is the algorithm's result under the displayed parse and agreement assumptions. It does not prove the intention of every speaker using an otherwise ambiguous sentence.</p></div><div class=\"answer\"><strong>Answer.</strong> She → Anita under the stated tree and compatibility information.</div></section><h3>Advantages, limitations and a complete exam answer</h3><table><thead><tr><th>Advantages</th><th>Limitations</th></tr></thead><tbody><tr><td>Explicit candidate order makes the decision traceable.</td><td>Wrong parse structure can produce the wrong search order.</td></tr><tr><td>Requires no labelled coreference-training corpus for its basic rules.</td><td>World knowledge and discourse intention may override syntactic preference.</td></tr><tr><td>Uses structure rather than only surface distance.</td><td>Some ambiguous, long-distance or unusual constructions need additional treatment.</td></tr></tbody></table><p>For a longer answer, write the definition, inputs, tree notation, ordered algorithm, one labelled tree with a candidate table, final antecedent, and limitations. In a worked question show separately: candidate → why proposed → agreement result → accept/reject. Do not equate the selected candidate with a logically guaranteed interpretation when the sentence is ambiguous.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Tree order candidate deta hai; agreement usko allow/reject karta hai. Nearest noun automatically answer nahi.</p><h3>Apply to this sentence</h3><ol><li>Build the main clause with subject NP John; VP gave contains object NP a book and PP to Mary; the after-clause has subject he and object it under reading.</li><li>For he, ascend from its NP to the governing S/NP and traverse candidate NPs to the left using the Hobbs breadth-first search. Test number/person/gender and binding compatibility.</li><li>John is an earlier singular human candidate. Under the intended conventional name-gender reading, he→John. Mary is not chosen merely because it is nearer. Names alone do not establish real-world gender; this is the ordinary exercise reading.</li><li>For it, the inanimate singular a book is compatible with reading; John and Mary are human mentions. Resolve it→a book.</li><li>Final interpretation: John gave the book after John finished reading the book. The trees/candidate order guide the search; semantic compatibility is also needed.</li></ol><h3>The four requested properties</h3><div class=\"table-wrap\"><table><thead><tr><th>Property</th><th>What it means</th><th>Apply here</th></tr></thead><tbody><tr><td>Binding</td><td>Syntactic restrictions on reference; ordinary personal pronouns and reflexives have different local-antecedent requirements</td><td>Do not mechanically link every nearby NP; he in an after/because clause can refer outside that local clause.</td></tr><tr><td>Gender agreement</td><td>Candidate must match the pronoun under available linguistic/contextual knowledge</td><td>John/he is the exercise’s conventional reading; professor/student do not provide gender by themselves.</td></tr><tr><td>Distance</td><td>Token, syntactic or sentence separation between pronoun and candidate</td><td>Closer candidates may be preferred, but cannot override incompatibility or Hobbs search order.</td></tr><tr><td>Recency</td><td>Recently mentioned discourse entities are often more salient</td><td>Mary/student is later than John/professor, but recency is a preference, not a guaranteed antecedent rule.</td></tr></tbody></table></div><p>Reference resolution preserves who performed each action; without it an extraction or QA system could wrongly attribute the reading to Mary. John is the first suitable main-clause subject under the declared parse; the inanimate book fails human he compatibility.</p>","m2":false,"units":"6","marks":10,"sourcePages":[3],"historical":true},{"id":"q6a","title":"Q6a · Corpora and acquisition","html":"<div class=\"question\"><strong>Question. Explain types, characteristics and acquisition of text corpora.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A corpus is a collection of language data assembled for study or computational use.</strong> Its plural is corpora. A corpus can contain books, news, reviews or conversations. It need not be labelled. <strong>Annotation</strong> adds linguistic information such as POS tags, entities, parse structures or sense labels.</p><table><thead><tr><th>Structure</th><th>Meaning</th><th>Use</th></tr></thead><tbody><tr><td>Plain</td><td>Collection without category labels</td><td>Word counts, language modelling</td></tr><tr><td>Categorized</td><td>Documents grouped by genre/topic</td><td>Classification</td></tr><tr><td>Overlapping categories</td><td>One document has several categories</td><td>Multi-topic news</td></tr><tr><td>Temporal</td><td>Documents indexed by time</td><td>Language change</td></tr><tr><td>Annotated</td><td>Linguistic labels attached</td><td>Tagging, parsing, WSD</td></tr><tr><td>Parallel</td><td>Aligned texts in different languages</td><td>Translation</td></tr></tbody></table><p>A <strong>tagset</strong> is the allowed label inventory. A <strong>treebank</strong> is a corpus annotated with syntax trees. <strong>Metadata</strong> records source, date, genre, language, annotation method and limitations. A common benchmark supports comparison under shared data and evaluation conditions.</p><p><strong>Raw example:</strong> “Riya works in Pune.” <strong>POS annotation:</strong> Riya/PROPN works/VERB in/ADP Pune/PROPN. <strong>NER annotation:</strong> Riya/PERSON, Pune/LOCATION. Each annotation answers a different task.</p><p>A good corpus is relevant to its domain, sufficiently representative, consistently annotated and appropriately split. More data alone do not repair duplicated examples, incorrect labels or a mismatch between training and real use.</p><p class=\"cue\">Corpus=text collection. Annotation=text ke saath labels. Metadata=collection ki information.</p><table><thead><tr><th>Resource</th><th>Contents</th><th>Typical use</th></tr></thead><tbody><tr><td>Gutenberg selection</td><td>Literary/book texts</td><td>Long-form language and vocabulary</td></tr><tr><td>Web text</td><td>Informal domain-specific text</td><td>Study usage beyond edited books</td></tr><tr><td>Chat corpus</td><td>Conversational posts</td><td>Dialogue, informal forms</td></tr><tr><td>Brown</td><td>English texts across genres</td><td>Genre comparison</td></tr><tr><td>Reuters</td><td>News with topic labels</td><td>Text classification; overlapping topics</td></tr><tr><td>Inaugural</td><td>Speeches indexed by time</td><td>Vocabulary change across years</td></tr><tr><td>Wordlist</td><td>Words/names/stopwords</td><td>Lexical filtering</td></tr><tr><td>Pronouncing dictionary</td><td>Words and phonetic forms</td><td>Speech, stress, rhyme</td></tr></tbody></table><p><strong>Gutenberg versus web/chat:</strong> book language does not represent every spelling or conversational pattern in messages. <strong>Brown versus Reuters:</strong> Brown emphasizes genres; Reuters news can have overlapping topic labels. <strong>Inaugural addresses:</strong> dates provide a time dimension.</p><p>Corpus sizes depend on version, subset and tokenization. Explain their purpose and structure rather than assuming a historical count is a permanent property.</p><p class=\"cue\">Gutenberg=books; web/chat=informal; Brown=genres; Reuters=news topics; Inaugural=time.</p><p><strong>Data acquisition</strong> obtains language examples relevant to the task from existing data, public resources or appropriate new collection. Product instrumentation can gather useful feedback. Supervised learning additionally needs an annotation process when labels are absent.</p><p><strong>Data augmentation</strong> creates training variants intended to preserve the correct label. It is not simply changing words arbitrarily.</p><table><thead><tr><th>Method</th><th>Procedure</th><th>Caution</th></tr></thead><tbody><tr><td>Synonym replacement</td><td>Use suitable synonyms for selected words</td><td>Choose the right sense</td></tr><tr><td>Back translation</td><td>Translate to another language and back</td><td>May change meanings/entities</td></tr><tr><td>TF–IDF-informed replacement</td><td>Protect informative words while varying others</td><td>Do not remove label-bearing clues</td></tr><tr><td>Bigram flipping</td><td>Swap adjacent words</td><td>Can break grammar or meaning</td></tr><tr><td>Entity replacement</td><td>Replace by same-type entity</td><td>Must preserve the task label</td></tr><tr><td>Noise injection</td><td>Simulate typos/keyboard errors</td><td>Match expected noise</td></tr><tr><td>Active learning</td><td>Select informative cases for human labels</td><td>This acquires labels; it is not synthetic text</td></tr></tbody></table><h3>Three label decisions</h3><p>“The film is good”→“The film is excellent” may preserve a positive sentiment label. “The film is not good”→“The film is good” reverses the label and is not valid label-preserving augmentation. “Flights to Pune”→“Flights to Mumbai” may preserve a travel-topic label but changes the destination label.</p><p>Split train/test data before creating related augmented variants. Otherwise near-duplicates can leak between sets and produce misleading evaluation. Keep a representative evaluation set of genuine examples.</p><p class=\"cue\">Sentence badal sakta hai; required correct label nahi. Label badla toh augmentation invalid.</p><h3>Corpus structure diagram</h3><pre>Corpus\n├─ Documents (plain collection)\n│  └─ Sentences → tokens\n├─ Categories → document IDs (one or overlapping labels)\n├─ Dates → document IDs (temporal collection)\n├─ Annotations → token spans / tags / parse trees\n└─ Parallel pairs → aligned source and target sentences</pre><p>An annotated corpus attaches linguistic labels to the raw text: e.g. Rita/PROPN runs/VERB. A wordlist is a lexical inventory without full discourse context; a Gutenberg corpus contains books; web/chat corpora contain informal online language. Their structures determine which evidence can be queried.</p>","m2":false,"units":"3","marks":10,"sourcePages":[4],"historical":true},{"id":"q6b","title":"Q6b · HMM components and estimates","html":"<div class=\"question\"><strong>Question. Explain HMM components, the number of possible tag sequences and limitations. Construct transition and emission tables for the supplied Alice/Bob/They/The-cat tagged corpus.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A Hidden Markov Model (HMM)</strong> is a probabilistic sequence model in which the underlying state sequence is unobserved, while each state emits an observed item. For POS tagging, words are observed and their grammatical tags are hidden. The task is to infer a suitable tag sequence from the words.</p><div class=\"flow\"><div class=\"node\">Hidden: Noun</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Hidden: Verb</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Hidden: Noun</div></div><div class=\"flow\"><div class=\"node\">Observed: birds</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Observed: eat</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Observed: seeds</div></div><p>Horizontal state-to-state links are <strong>transitions</strong>. The relation from each hidden state to its observed word is an <strong>emission</strong>. A transition P(V|N) asks how often a verb tag follows a noun tag. An emission P(eat|V) asks how often the observed word eat appears among verb-tagged tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Component</th><th>Notation</th><th>Meaning</th></tr></thead><tbody><tr><td>State set</td><td>S={N,V,…}</td><td>Possible hidden tags.</td></tr><tr><td>Observation vocabulary</td><td>O={birds,eat,seeds,…}</td><td>Visible word tokens.</td></tr><tr><td>Initial distribution</td><td>πⱼ=P(t₁=j)</td><td>Probability of starting in tag j.</td></tr><tr><td>Transition matrix</td><td>aᵢⱼ=P(tₖ=j|tₖ₋₁=i)</td><td>Probability of next tag j after i.</td></tr><tr><td>Emission matrix</td><td>bⱼ(w)=P(w|tag j)</td><td>Probability that state j emits word w.</td></tr></tbody></table></div><p>Two basic assumptions are used: the current hidden state depends only on the previous hidden state, and the current observation depends only on the current hidden state. A standard first-order HMM therefore does not explicitly condition an emitted word on the whole sentence.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e8849ce22bc4d03e.svg\" alt=\"P(t_{1:T},w_{1:T})=\\pi_{t_1}b_{t_1}(w_1)\\prod_{k=2}^{T}a_{t_{k-1},t_k}b_{t_k}(w_k)\" style=\"width:40.971ex;height:6.775ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Read the formula as <strong>start × first emission × transition × emission × transition × emission…</strong>. There are T emission factors and T−1 transitions, plus one initial factor. If the question supplies an explicit end-state probability, multiply that too. Do not invent an end factor when the model has none.</p><p><strong>Three different questions.</strong> (1) Scoring a specified tag path uses the joint product above. (2) Finding the probability of the observed words sums scores over all possible tag paths. (3) Finding the best tag path maximizes the path score, typically using Viterbi. A joint path score is not a normalized posterior P(tags|words).</p><p class=\"cue\"><strong>Yaad rakho:</strong> Transition = tag se agla tag. Emission = tag se visible word.</p><p>If each of T observed words can receive any of N tags, there are N choices at each position. Thus the total number of complete tag sequences is N multiplied by itself T times. This counts possible assignments before grammar rules or zero probabilities eliminate any.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/014ed66c3c0df2b1.svg\" alt=\"\\text{Number of tag sequences}=N^T\" style=\"width:30.626ex;height:2.484ex\" loading=\"lazy\" decoding=\"async\"></div></div><section class=\"example\"><p class=\"question\"><strong>Question. A four-word sentence is tagged using three possible POS tags per word. How many complete tag sequences are possible?</strong></p><div class=\"given\"><h4>Given</h4><p>N=3 possible tags per position; T=4 word positions.</p><h4>To find</h4><p>The number of tag sequences.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Every independent position contributes a factor of three choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Write one factor per position</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d7b06b7e39ae0a5.svg\" alt=\"M=3\\times3\\times3\\times3\" style=\"width:18.217ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Multiply</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6570633fef12ecb5.svg\" alt=\"3\\times3=9,\\quad9\\times3=27,\\quad27\\times3=81\" style=\"width:37.46ex;height:1.968ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 81 possible tag sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. A five-word sentence has two candidate tags per word. Count its tag sequences.</strong></p><div class=\"given\"><h4>Given</h4><p>N=2; T=5.</p><h4>To find</h4><p>M.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0496ec54e0350270.svg\" alt=\"M=N^T\" style=\"width:8.841ex;height:2.203ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The length is the exponent, not a multiplier.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Substitute</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/e0b25a2374d09c2d.svg\" alt=\"M=2^5\" style=\"width:7.514ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Evaluate</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/85ec03497588b6d5.svg\" alt=\"2\\times2\\times2\\times2\\times2=32\" style=\"width:21.998ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 32 possible sequences.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using 45 possible tags, compare the number of tag sequences for sentences of length 2 and 3.</strong></p><div class=\"given\"><h4>Given</h4><p>N=45. First T=2, then T=3.</p><h4>To find</h4><p>Both counts and the growth factor.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0806abcd5d0a43e.svg\" alt=\"M_2=45^2,\\quad M_3=45^3\" style=\"width:22.167ex;height:2.439ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Adding one position multiplies the possibilities by the number of tag choices.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Two words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/672617aa8909800b.svg\" alt=\"45^2=2025\" style=\"width:10.792ex;height:2.185ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Three words</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/96a0c5c55e4f8048.svg\" alt=\"45^3=2025\\times45=91125\" style=\"width:24.493ex;height:2.184ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Compare</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3daee8fcfcc1adea.svg\" alt=\"91125/2025=45\" style=\"width:16.592ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> 2 words: 2025 paths. 3 words: 91125 paths. One additional word multiplies the count by 45.</div></section><p>The slides introduce Viterbi to avoid enumerating every path. It reuses the best prefix score for each ending state. For a dense first-order HMM, it needs O(TN²) recurrence work instead of enumerating N<sup>T</sup> complete paths.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Choices per word ki power = sentence length.</p><h3>Exact corpus calculation</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Given tags</th></tr></thead><tbody><tr><td>Alice will eat cookies</td><td>N M V N</td></tr><tr><td>Bob can drink tea</td><td>N M V N</td></tr><tr><td>They will watch movies</td><td>Pronoun M V N</td></tr><tr><td>The cat is sleeping</td><td>Det N V V</td></tr></tbody></table></div><h3>To find</h3><p>Emission and transition tables</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9a06539e1ddc3c75.svg\" alt=\"P(w\\mid t)=\\frac{c(t,w)}{c(t)}\" style=\"width:17.977ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d9ef5a8985e2f56.svg\" alt=\"P(t_j\\mid t_i)=\\frac{c(t_i,t_j)}{\\sum_kc(t_i,t_k)}\" style=\"width:23.506ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The second formula is the declared no-END convention. Reset at sentence boundaries; never create a transition from the last word of one training sentence to the first of the next.</p><h3>Step 1. Count emissions</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Total occurrences</th><th>Alice</th><th>will</th><th>eat</th><th>cookies</th><th>Bob</th><th>can</th><th>drink</th><th>tea</th><th>They</th><th>watch</th><th>movies</th><th>The</th><th>cat</th><th>is</th><th>sleeping</th></tr></thead><tbody><tr><td>N</td><td>6</td><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>M</td><td>3</td><td>0</td><td>2</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>V</td><td>5</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td></tr><tr><td>Pronoun</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 2. Divide each emission by its tag count</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Alice</th><th>will</th><th>eat</th><th>cookies</th><th>Bob</th><th>can</th><th>drink</th><th>tea</th><th>They</th><th>watch</th><th>movies</th><th>The</th><th>cat</th><th>is</th><th>sleeping</th></tr></thead><tbody><tr><td>N</td><td>1/6</td><td>0</td><td>0</td><td>1/6</td><td>1/6</td><td>0</td><td>0</td><td>1/6</td><td>0</td><td>0</td><td>1/6</td><td>0</td><td>1/6</td><td>0</td><td>0</td></tr><tr><td>M</td><td>0</td><td>2/3</td><td>0</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/5</td><td>0</td><td>0</td><td>0</td><td>1/5</td><td>0</td><td>0</td><td>1/5</td><td>0</td><td>0</td><td>0</td><td>1/5</td><td>1/5</td></tr><tr><td>Pronoun</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 3. Count transitions inside each sentence</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Outgoing transitions</th><th>Sentence-final count</th><th>N</th><th>M</th><th>V</th><th>Pronoun</th><th>Det</th></tr></thead><tbody><tr><td>N</td><td>3</td><td>3</td><td>0</td><td>2</td><td>1</td><td>0</td><td>0</td></tr><tr><td>M</td><td>3</td><td>0</td><td>0</td><td>0</td><td>3</td><td>0</td><td>0</td></tr><tr><td>V</td><td>4</td><td>1</td><td>3</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Pronoun</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 4. Convert to a transition table</h3><div class=\"table-wrap\"><table><thead><tr><th>From / to</th><th>N</th><th>M</th><th>V</th><th>Pronoun</th><th>Det</th></tr></thead><tbody><tr><td>N</td><td>0</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>V</td><td>3/4</td><td>0</td><td>1/4</td><td>0</td><td>0</td></tr><tr><td>Pronoun</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><p>Here sentence-final tags are excluded from the no-END outgoing denominator. If END is explicitly modeled, divide all tag→tag and tag→END counts by the total tag count instead; the row then includes END. Do not mix denominators.</p><h3>Final answer</h3><p>The two displayed probability tables are the estimated HMM. Zero means unobserved without smoothing, not logically impossible.</p><p>For T tokens and K possible tags per token, exhaustive assignments number K^T before constraints; the paper does not supply a single test length for a specific numerical total. HMM assumptions limit long-range context, first-order transitions and emission independence; sparsity and unknown words require smoothing or other handling. The supplied tag is for is and sleeping is V, so both count as V even though finer linguistic tagsets distinguish auxiliaries/participles.</p>","m2":false,"units":"4","marks":10,"sourcePages":[4],"historical":true},{"id":"q7a","title":"Q7a · Word classes, chunking and chinking","html":"<div class=\"question\"><strong>Question. Explain open/closed word classes, chunking and chinking with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Part-of-speech (POS) tagging</strong> assigns a grammatical category to every word token in context, such as noun, verb, adjective or determiner. It is a sequence-labeling task: the input is a sequence of words, and the output is a tag for each word. A tag describes the word's role in this sentence, not its meaning in every possible sentence.</p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Role</th><th>Example in context</th></tr></thead><tbody><tr><td>NN / NNS</td><td>Singular / plural common noun</td><td>a book / two books</td></tr><tr><td>NNP</td><td>Proper noun</td><td>Mary, Mumbai</td></tr><tr><td>VB / VBD / VBZ</td><td>Base / past / third-person singular verb</td><td>read / read / reads</td></tr><tr><td>JJ</td><td>Adjective</td><td>the red book</td></tr><tr><td>RB</td><td>Adverb</td><td>runs quickly</td></tr><tr><td>DT</td><td>Determiner</td><td>the, a, this</td></tr><tr><td>IN</td><td>Preposition or subordinating conjunction</td><td>on the table</td></tr><tr><td>PRP</td><td>Personal pronoun</td><td>she, they</td></tr><tr><td>MD</td><td>Modal auxiliary</td><td>can, will, should</td></tr></tbody></table></div><p><strong>Open classes</strong> readily accept new content words: nouns, verbs, adjectives and adverbs. Examples include chatbot and livestream. <strong>Closed classes</strong> contain comparatively stable grammatical/function words: determiners, pronouns, prepositions and conjunctions. These are tendencies, not a claim that language never changes.</p><div class=\"flow\"><div class=\"node\">Input: Book that flight</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context: an imperative request</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Output: Book/VB that/DT flight/NN</div></div><p>Compare “hand me that <strong>book</strong>”: book is a noun here. Similarly, “I <strong>can</strong> swim” has can/MD, while “the <strong>can</strong> is empty” has can/NN. The spelling stays the same; neighboring words and sentence structure change the correct tag. This is <strong>POS ambiguity</strong>.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged interpretation</th><th>Reason</th></tr></thead><tbody><tr><td>They watch birds.</td><td>They/PRP watch/VBP birds/NNS</td><td>watch is the action.</td></tr><tr><td>The watch stopped.</td><td>The/DT watch/NN stopped/VBD</td><td>watch is the object that stopped.</td></tr><tr><td>She has a light bag.</td><td>She/PRP has/VBZ a/DT light/JJ bag/NN</td><td>light describes bag.</td></tr><tr><td>Light the lamp.</td><td>Light/VB the/DT lamp/NN</td><td>Light is an imperative verb.</td></tr></tbody></table></div><p>POS tags support parsing, named entity recognition, question answering, sentiment analysis and word-sense disambiguation. They do not by themselves identify every entity or fully resolve meaning.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka naam same ho sakta hai; sentence mein uska kaam tag decide karta hai.</p><p><strong>Chunking</strong>, also called shallow parsing, groups adjacent tagged words into meaningful non-overlapping units, commonly noun phrases. It usually identifies local phrase boundaries without producing the complete hierarchical structure of a sentence. <strong>Chinking</strong> removes specified tokens from an existing candidate chunk, splitting or trimming it.</p><div class=\"flow\"><div class=\"node\">The/DT small/JJ cat/NN sat/VBD on/IN the/DT mat/NN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [The small cat]</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Outside: sat on</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [the mat]</div></div><p>A POS tagger labels individual words. A chunker groups words into phrases. A full parser shows how phrases relate recursively to form the entire sentence. These are related tasks with different outputs.</p><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>POS tagging</td><td>The small cat</td><td>The/DT small/JJ cat/NN</td></tr><tr><td>NP chunking</td><td>Tagged tokens</td><td>[NP The small cat]</td></tr><tr><td>Chinking</td><td>A broad candidate chunk</td><td>Remove verbs/prepositions, keep noun-phrase segments</td></tr><tr><td>Full parsing</td><td>Sentence + grammar</td><td>A nested tree with sentence, noun phrase and verb phrase nodes</td></tr></tbody></table></div><p><strong>Rule-based chunking</strong> uses tag patterns. Statistical or learned chunkers infer boundaries from labeled examples. A useful NP rule is an optional determiner, followed by zero or more adjectives, followed by a noun. In NLTK-style notation: <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;}</code>. Here ? means zero or one occurrence; * means zero or more; + means one or more when used. The braces mean “form a chunk around the matched sequence”.</p><section class=\"example\"><p class=\"question\"><strong>Question. Apply the NP rule optional DT, zero or more JJ, then one NN to “The/DT quick/JJ brown/JJ fox/NN jumps/VBZ over/IN the/DT lazy/JJ dog/NN”.</strong></p><div class=\"given\"><h4>Given</h4><p>Tagged input is supplied. Rule: DT? JJ* NN.</p><h4>To find</h4><p>All noun-phrase chunks.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The rule groups a noun with its preceding determiner and adjectives; a verb or preposition does not match this NP pattern.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start at The</h5><p>The matches optional DT; quick and brown both match JJ*; fox matches NN.</p></div><div class=\"step\"><h5>Step 2. Form the first NP</h5><p><strong>[NP The quick brown fox]</strong></p></div><div class=\"step\"><h5>Step 3. Skip nonmatching tokens</h5><p>jumps/VBZ and over/IN do not satisfy the NP pattern.</p></div><div class=\"step\"><h5>Step 4. Match the second NP</h5><p>the is DT, lazy is JJ, dog is NN: <strong>[NP the lazy dog]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> [NP The quick brown fox] jumps over [NP the lazy dog].</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using NP → DT? JJ* NN, identify the chunks in “bright/JJ stars/NN shine/VBP and/CC a/DT moon/NN glows/VBZ”. Use the supplied tags exactly.</strong></p><div class=\"given\"><h4>Given</h4><p>Input tags label stars as NN for this exercise. Rule requires optional DT, zero or more JJ, then NN.</p><h4>To find</h4><p>The matched NP spans.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The optional determiner may be absent and the adjective repetition may be empty.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Match bright stars</h5><p>No determiner is present, which DT? permits. bright matches JJ; stars matches NN.</p></div><div class=\"step\"><h5>Step 2. Inspect shine and and</h5><p>VBP and CC fall outside the NP rule.</p></div><div class=\"step\"><h5>Step 3. Match a moon</h5><p>a matches DT; no adjective is present; moon matches NN.</p></div><div class=\"answer\"><strong>Final answer.</strong> Chunks are [NP bright stars] and [NP a moon]. With ordinary Penn tagging, stars is usually NNS; broaden the noun pattern to include NNS when that tag is used.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Begin with one candidate chunk containing “The/DT cat/NN sat/VBD on/IN the/DT mat/NN”. Chink out verbs and prepositions. Show the remaining chunks.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial candidate: [The cat sat on the mat]. Remove tags VBD and IN.</p><h4>To find</h4><p>The chunk segments after exclusion.</p></div><h4>Formula and why it applies</h4><p>Chinking removes matched tokens from the existing chunk.</p><p>Removing the middle verb/preposition region divides the original candidate into two remaining contiguous spans.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the tokens to remove</h5><p>sat is VBD and on is IN.</p></div><div class=\"step\"><h5>Step 2. Remove those tokens from chunk membership</h5><p>The remaining token groups are “The cat” and “the mat”. sat and on still exist in the sentence; they are simply outside these chunks.</p></div><div class=\"step\"><h5>Step 3. Write the final chunked sentence</h5><p><strong>[The cat]</strong> sat on <strong>[the mat]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> Two chunks remain: The cat; the mat.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Chunking = andar group karo; chinking = unwanted tokens ko group se bahar karo.</p></section>","m2":false,"units":"4","marks":5,"sourcePages":[4],"historical":true},{"id":"q7b","title":"Q7b · Named entity recognition","html":"<div class=\"question\"><strong>Question. Explain named-entity recognition and its approaches with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Named Entity Recognition (NER)</strong> identifies text spans referring to entities and assigns their types, such as PERSON, ORGANIZATION and LOCATION. Many practical schemas also include DATE, TIME, MONEY or domain-specific types. The exact allowed labels depend on the application's annotation scheme.</p><p>NER has two parts: <strong>boundary detection</strong> finds where the entity starts and ends; <strong>classification</strong> assigns the appropriate type. A multiword name should normally be one entity span: “New York” is a location span, not two unrelated location decisions.</p><div class=\"flow\"><div class=\"node\">Text: Mary joined Google in New York on Monday.</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Mary → PERSON</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Google → ORGANIZATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New York → LOCATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Monday → DATE</div></div><p>Not every noun is a named entity. In “a developer works at Google”, developer is an ordinary job description while Google is a named organization. A specialized HR system may define a JOB_TITLE category, but it must state that schema explicitly. NER identifies mentions; entity linking is the separate task of connecting a mention to a unique database identity.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>POS</td><td>What grammatical role does this token have?</td><td>Google/NNP</td></tr><tr><td>Chunking</td><td>Which adjacent words form a phrase?</td><td>[NP a skilled developer]</td></tr><tr><td>NER</td><td>Which span names an entity, and of what type?</td><td>[Google] ORGANIZATION</td></tr><tr><td>Entity linking</td><td>Which real entity does this mention denote?</td><td>Connect Paris to the intended city or person record</td></tr></tbody></table></div><p><strong>Applications.</strong> NER structures search results and documents, extracts organizations/people from news, routes support tickets by product or organization, supports recommendation, and extracts specialized entities from healthcare or legal text. Context is essential: “Apple released a laptop” names an organization, while “she ate an apple” describes fruit.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER mein do kaam: naam kahan se kahan tak, aur kis category ka.</p><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>How it works</th><th>Example</th><th>Main limitation</th></tr></thead><tbody><tr><td>Dictionary / gazetteer</td><td>Match text against lists of known names</td><td>A city list includes Mumbai and Pune</td><td>New names, spelling variants and ambiguous names are missed</td></tr><tr><td>Rule-based</td><td>Use word shapes, regular expressions and context</td><td>A title such as Dr. followed by a name-like span suggests PERSON</td><td>Manual maintenance; exceptions and domain/language dependence</td></tr><tr><td>Machine learning</td><td>Learn a labeling rule from annotated examples using features</td><td>Capitalization, suffixes, POS and surrounding words help a classifier/CRF</td><td>Requires labeled data and useful features</td></tr><tr><td>Deep learning</td><td>Learn contextual word/character representations and predict labels</td><td>A contextual sequence encoder labels multiword entity spans</td><td>Training/domain dependence and resource demands</td></tr></tbody></table></div><p>A <strong>pattern-based rule</strong> examines the form of text, such as an email pattern or a date format. A <strong>context-based rule</strong> examines neighboring words: “Dr.” can support a following PERSON span, while “headquartered in” can support a following LOCATION span. Capitalization alone is insufficient because sentence-initial common nouns are also capitalized.</p><p>A dictionary may find “May” as a person's name, but “in May” may refer to a month. A learned model uses surrounding evidence to disambiguate. Hybrid systems can combine dictionaries, rules and learned models; these categories are practical tools rather than mutually exclusive restrictions.</p><p><strong>Preprocessing for NER.</strong> Tokenize while preserving token offsets and useful capitalization. Blindly removing capital letters or stopwords before recognition can damage names such as “Bank of India”. NER output should preserve the original span so the reader can locate it in the input.</p><p><strong>Exam-ready 3-mark answer.</strong> NER locates named-entity spans and classifies them into categories such as person, organization and location. A dictionary-based approach matches known name lists; a rule-based approach uses patterns or context; machine-learning and deep-learning approaches learn entity decisions from labeled data and representations. For example, in “Mary works at Google in Mumbai”, Mary is PERSON, Google is ORGANIZATION and Mumbai is LOCATION.</p>","m2":false,"units":"4","marks":5,"sourcePages":[4],"historical":true},{"id":"q7c","title":"Q7c · Co-occurrence with inconsistent requested comparisons","html":"<div class=\"question\"><strong>Question. Construct a whole-sentence co-occurrence matrix for: The bird flew across the sky. The cat watched the bird. The flowers grew in the garden. The bird rested on the tree. The cat slept near the tree. Targets={bird,cat,garden,flowers}; contexts={sky,tree,garden,slept}. The printed follow-up asks dot products boy–dog and boy–sun and a plot on kicked/field dimensions.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Use the exact target/context lists above.</p><h3>To find</h3><p>Construct the supported matrix and identify which later requests are undefined.</p><h3>Formula: which one and why</h3><p>Count ordered target-token/context-token pairs in the same sentence, excluding the target token itself. A single garden occurrence cannot co-occur with itself. If a classroom convention uses sentence-level presence including diagonal, only garden→garden changes from0to1; state that choice.</p><h3>Step 1. Enumerate contributions and sum</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Target occurrences</th><th>Context occurrences</th></tr></thead><tbody><tr><td>1</td><td>bird</td><td>sky</td></tr><tr><td>2</td><td>cat, bird</td><td></td></tr><tr><td>3</td><td>flowers, garden</td><td>garden</td></tr><tr><td>4</td><td>bird</td><td>tree</td></tr><tr><td>5</td><td>cat</td><td>slept, tree</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Target / context</th><th>sky</th><th>tree</th><th>garden</th><th>slept</th></tr></thead><tbody><tr><td>bird</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>cat</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>garden</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>flowers</td><td>0</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div><h3>Step 2. Check requested names before multiplying</h3><p>boy,dog,sun are not target rows; kicked,field are not context columns. Therefore the requested dot products and plot cannot be calculated from the supplied matrix. Zero vectors for invented words would not repair the missing givens.</p><h3>Step 3. Clearly labelled corrected illustration</h3><p>If the follow-up were changed to bird–cat and bird–flowers, using the displayed rows: bird·cat=1×0+1×1+0×0+0×1=1; bird·flowers=1×0+1×0+0×1+0×0=0. A sky/tree plot would use bird(1,1),cat(0,1),garden(0,0),flowers(0,0). These substitutions are teaching examples, not printed instructions.</p><h3>Final answer</h3><p><strong>The original matrix is solved; its requested boy/dog/sun comparisons and kicked/field plot are not well-defined.</strong> Ask for corrected target/context names rather than inventing a numerical answer.</p><p><strong>Source / convention note.</strong> Source defect: follow-up names belong to another corpus. Exact supported matrix is complete; unsupported parts are explicitly unresolved from the original data.</p>","m2":false,"units":"5","marks":10,"sourcePages":[5],"historical":true}]},{"id":"legacy-f24","title":"2024-12-03 · final · recovered AI paper","unit":"PYQ","scope":"Previous examination · complete worked answers","sections":[{"id":"q1a","title":"Q1a · TF–IDF in retrieval","html":"<div class=\"question\"><strong>Question. Write TF–IDF expressions and explain their role in information retrieval.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>TF–IDF weights a term highly when it is frequent in a particular document but uncommon across the corpus.</strong> The supplied Unit 2 slides use normalized term frequency and base-10 inverse document frequency:</p><div class=\"math-display\"><img src=\"math/deca468dd207619e.svg\" alt=\"\\operatorname{TF}(t,d)=\\frac{C(t,d)}{N_d}\" style=\"width:18.362ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/dd1eb7f26551c5f0.svg\" alt=\"\\operatorname{IDF}(t)=\\log_{10}\\frac{D}{\\operatorname{df}(t)}\" style=\"width:20.345ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c3205280fe205579.svg\" alt=\"\\operatorname{TFIDF}(t,d)=\\operatorname{TF}(t,d)\\operatorname{IDF}(t).\" style=\"width:30.386ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/716cbce384bea429.svg\" alt=\"N_d\" style=\"width:2.836ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the document's token count after the specified preprocessing; <span class=\"math-inline\"><img src=\"math/62ef1c41dad1fbc8.svg\" alt=\"D\" style=\"width:1.873ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is number of documents; <span class=\"math-inline\"><img src=\"math/92f4a76a32f5c806.svg\" alt=\"\\operatorname{df}(t)\" style=\"width:4.676ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of documents containing the term at least once. A word repeated ten times in one document contributes one to document frequency.</p><p><strong>Why the log?</strong> It compresses the ratio's scale. If a term occurs in all documents, <span class=\"math-inline\"><img src=\"math/2d65862ad68e4d56.svg\" alt=\"D/df=1\" style=\"width:9.574ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, so IDF=0 under this unsmoothed convention. Other libraries use smoothed IDF, different TF or normalization. Use the question's formula; do not silently substitute a library default.</p><div class=\"example\"><p><strong>Question. A corpus contains 10 documents. The word model appears in 2 documents and occurs 3 times in a 12-token document. Compute TF, IDF and TF–IDF using the slide convention.</strong></p><div class=\"given\"><h4>Given</h4><p>D=10, df(model)=2, C(model,d)=3, Nd=12; log base 10.</p><h4>To find</h4><p>The TF–IDF weight.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>, then multiply.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/51ccdc5dee01783f.svg\" alt=\"3/12=0.25\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Document ratio</h4><p><span class=\"math-inline\"><img src=\"math/e03ff475f4b9e538.svg\" alt=\"10/2=5\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. IDF</h4><p><span class=\"math-inline\"><img src=\"math/35a02628576f1000.svg\" alt=\"\\log_{10}5\\approx0.698970\" style=\"width:17.752ex;height:2.151ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Weight</h4><p><span class=\"math-inline\"><img src=\"math/f8ed981eba287429.svg\" alt=\"0.25\\times0.698970\\approx0.174743\" style=\"width:26.9ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> TF=0.25, IDF≈0.698970, TF–IDF≈0.174743.</p></div><div class=\"example\"><p><strong>Question. A term occurs 4 times in a 20-token document and is present in all 8 corpus documents. Calculate its TF–IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>C=4, Nd=20, D=8, df=8.</p><h4>To find</h4><p>Its weight under unsmoothed base-10 IDF.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/b0de7a9a9a0c728c.svg\" alt=\"4/20=0.2\" style=\"width:10.433ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. IDF</h4><p><span class=\"math-inline\"><img src=\"math/9a61d3220cb1a861.svg\" alt=\"\\log_{10}(8/8)=\\log_{10}1=0\" style=\"width:23.186ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/97ff1a04375e7994.svg\" alt=\"0.2\\times0=0\" style=\"width:10.937ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Weight 0: this term does not distinguish documents under this convention.</p></div><div class=\"example\"><p><strong>Question. Find TF–IDF vectors for D1=“cat cat dog”, D2=“dog fish”, D3=“cat fish fish”, using [cat,dog,fish], normalized TF and log10 IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>No further preprocessing. Each term occurs in exactly two of the three documents.</p><h4>To find</h4><p>All three vectors.</p></div><h4>Formula and why it applies</h4><p>First count df by documents, then compute each document's TF, then multiply by its term's IDF.</p><div class=\"step\"><h4>Step 1. Common IDF</h4><p><span class=\"math-inline\"><img src=\"math/a912b37fed2477fc.svg\" alt=\"D=3\" style=\"width:6.022ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/8279f303c7e95ae1.svg\" alt=\"df(cat)=df(dog)=df(fish)=2\" style=\"width:33.461ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Each IDF <span class=\"math-inline\"><img src=\"math/fdd435a4274ddcc4.svg\" alt=\"=\\log_{10}(3/2)\\approx0.176091\" style=\"width:23.786ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. D1 term frequencies</h4><p>Length 3 → <span class=\"math-inline\"><img src=\"math/33108c032f375ccc.svg\" alt=\"[2/3,1/3,0]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. D1 weights</h4><p><span class=\"math-inline\"><img src=\"math/a969ee9cc56b474e.svg\" alt=\"[(2/3)0.176091,(1/3)0.176091,0]\\approx[0.117394,0.058697,0]\" style=\"width:56.317ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. D2 weights</h4><p>Length 2; TF <span class=\"math-inline\"><img src=\"math/3a45dfb5933f8388.svg\" alt=\"[0,1/2,1/2]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/42c4ea9d39b355c1.svg\" alt=\"\\approx[0,0.088046,0.088046]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. D3 weights</h4><p>Length 3; TF <span class=\"math-inline\"><img src=\"math/b75534a4556b2589.svg\" alt=\"[1/3,0,2/3]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/f530e35b75352a92.svg\" alt=\"\\approx[0.058697,0,0.117394]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> D1≈[0.117394,0.058697,0]; D2≈[0,0.088046,0.088046]; D3≈[0.058697,0,0.117394].</p></div><p class=\"cue\">TF: iss document mein kitna. IDF: poore corpus mein kitna rare. Dono multiply.</p><p><strong>Information retrieval (IR)</strong> locates and ranks items relevant to an information need, usually expressed as a query. The collection may contain documents, product descriptions or scientific papers. Retrieval estimates relevance; it does not itself establish that every retrieved claim is true.</p><div class=\"flow\"><div class=\"node\">Documents → cleaning</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Build index</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Query → same representation</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match & rank</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Return relevant results</div></div><h3>The inverted index</h3><p>An inverted index maps a term to the documents containing it, often with positions or counts. For D1 “cats drink milk” and D2 “dogs drink water”, the posting list for drink is {D1,D2}, while milk maps only to D1. This avoids rescanning every document for every query.</p><table><thead><tr><th>Term</th><th>Posting list</th></tr></thead><tbody><tr><td>cats</td><td>D1</td></tr><tr><td>drink</td><td>D1, D2</td></tr><tr><td>milk</td><td>D1</td></tr><tr><td>dogs</td><td>D2</td></tr><tr><td>water</td><td>D2</td></tr></tbody></table><h3>Matching and ranking</h3><p>Boolean retrieval combines term membership using AND, OR and NOT. Vector-space retrieval represents documents and queries as weighted vectors, for example with TF-IDF, and compares them with cosine similarity. Learned retrieval can use dense embeddings for meaning-based matching. The representation used at query time must be compatible with the document index.</p><h3>Search engines and recommendation</h3><p>A search engine receives an explicit query and ranks matching indexed pages. A recommender may derive an implicit query from a user’s liked items or profile and retrieve similar candidates. Both require candidate retrieval and ranking, but the source of the information need differs.</p><h3>Evaluate the results</h3><p>For retrieval, TP is the number of retrieved relevant documents, FP retrieved irrelevant documents, and FN relevant documents not retrieved. Precision and recall use the same formulas as classification. Ranking measures also consider the positions of relevant items; a relevant result at rank 1 is more useful than one far below.</p><section class=\"example\"><h3>Retrieval evaluation</h3><p class=\"question\">A search system retrieves 8 documents; 6 are relevant. There are 10 relevant documents in the collection. Find precision, recall and F1.</p><div class=\"given\"><strong>Given</strong><p>Retrieved=8; relevant retrieved=6; all relevant=10.</p><strong>To find</strong><p>P, R and F1.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/58a11f3930a42815.svg\" alt=\"P=\\frac{\\text{relevant retrieved}}{\\text{retrieved}},\\quad R=\\frac{\\text{relevant retrieved}}{\\text{all relevant}}\" style=\"width:49.316ex;height:4.676ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4743421649dff6a6.svg\" alt=\"F_1=\\frac{2PR}{P+R}\" style=\"width:12.637ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>The denominator is 8 for precision and 10 for recall because they ask different questions.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the confusion counts</h4><p>TP=6; FP=8−6=2; FN=10−6=4.</p></div><div class=\"step\"><h4>Step 2. Precision</h4><div class=\"math-display\"><img src=\"math/6a30a7f6694209de.svg\" alt=\"P=\\frac68=0.75\" style=\"width:13.883ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Recall</h4><div class=\"math-display\"><img src=\"math/402ac41b5040dfdd.svg\" alt=\"R=\\frac6{10}=0.6\" style=\"width:13.901ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. F1</h4><div class=\"math-display\"><img src=\"math/aedd722bd9955777.svg\" alt=\"F_1=\\frac{2(0.75)(0.6)}{0.75+0.6}=\\frac{0.9}{1.35}=\\frac23\\approx0.666667\" style=\"width:42.764ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision=0.75, recall=0.60, F1≈0.666667.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Precision: jo laaye, unmein kitne sahi? Recall: jo sahi the, unmein kitne laaye?</p>","m2":false,"units":"2,7","marks":null,"sourcePages":[1],"historical":true},{"id":"q1b","title":"Q1b · NER and approaches","html":"<div class=\"question\"><strong>Question. Explain NER with examples and approaches.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>Named Entity Recognition (NER)</strong> identifies text spans referring to entities and assigns their types, such as PERSON, ORGANIZATION and LOCATION. Many practical schemas also include DATE, TIME, MONEY or domain-specific types. The exact allowed labels depend on the application's annotation scheme.</p><p>NER has two parts: <strong>boundary detection</strong> finds where the entity starts and ends; <strong>classification</strong> assigns the appropriate type. A multiword name should normally be one entity span: “New York” is a location span, not two unrelated location decisions.</p><div class=\"flow\"><div class=\"node\">Text: Mary joined Google in New York on Monday.</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Mary → PERSON</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Google → ORGANIZATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New York → LOCATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Monday → DATE</div></div><p>Not every noun is a named entity. In “a developer works at Google”, developer is an ordinary job description while Google is a named organization. A specialized HR system may define a JOB_TITLE category, but it must state that schema explicitly. NER identifies mentions; entity linking is the separate task of connecting a mention to a unique database identity.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>POS</td><td>What grammatical role does this token have?</td><td>Google/NNP</td></tr><tr><td>Chunking</td><td>Which adjacent words form a phrase?</td><td>[NP a skilled developer]</td></tr><tr><td>NER</td><td>Which span names an entity, and of what type?</td><td>[Google] ORGANIZATION</td></tr><tr><td>Entity linking</td><td>Which real entity does this mention denote?</td><td>Connect Paris to the intended city or person record</td></tr></tbody></table></div><p><strong>Applications.</strong> NER structures search results and documents, extracts organizations/people from news, routes support tickets by product or organization, supports recommendation, and extracts specialized entities from healthcare or legal text. Context is essential: “Apple released a laptop” names an organization, while “she ate an apple” describes fruit.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER mein do kaam: naam kahan se kahan tak, aur kis category ka.</p><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>How it works</th><th>Example</th><th>Main limitation</th></tr></thead><tbody><tr><td>Dictionary / gazetteer</td><td>Match text against lists of known names</td><td>A city list includes Mumbai and Pune</td><td>New names, spelling variants and ambiguous names are missed</td></tr><tr><td>Rule-based</td><td>Use word shapes, regular expressions and context</td><td>A title such as Dr. followed by a name-like span suggests PERSON</td><td>Manual maintenance; exceptions and domain/language dependence</td></tr><tr><td>Machine learning</td><td>Learn a labeling rule from annotated examples using features</td><td>Capitalization, suffixes, POS and surrounding words help a classifier/CRF</td><td>Requires labeled data and useful features</td></tr><tr><td>Deep learning</td><td>Learn contextual word/character representations and predict labels</td><td>A contextual sequence encoder labels multiword entity spans</td><td>Training/domain dependence and resource demands</td></tr></tbody></table></div><p>A <strong>pattern-based rule</strong> examines the form of text, such as an email pattern or a date format. A <strong>context-based rule</strong> examines neighboring words: “Dr.” can support a following PERSON span, while “headquartered in” can support a following LOCATION span. Capitalization alone is insufficient because sentence-initial common nouns are also capitalized.</p><p>A dictionary may find “May” as a person's name, but “in May” may refer to a month. A learned model uses surrounding evidence to disambiguate. Hybrid systems can combine dictionaries, rules and learned models; these categories are practical tools rather than mutually exclusive restrictions.</p><p><strong>Preprocessing for NER.</strong> Tokenize while preserving token offsets and useful capitalization. Blindly removing capital letters or stopwords before recognition can damage names such as “Bank of India”. NER output should preserve the original span so the reader can locate it in the input.</p><p><strong>Exam-ready 3-mark answer.</strong> NER locates named-entity spans and classifies them into categories such as person, organization and location. A dictionary-based approach matches known name lists; a rule-based approach uses patterns or context; machine-learning and deep-learning approaches learn entity decisions from labeled data and representations. For example, in “Mary works at Google in Mumbai”, Mary is PERSON, Google is ORGANIZATION and Mumbai is LOCATION.</p>","m2":false,"units":"4","marks":null,"sourcePages":[1],"historical":true},{"id":"q1c","title":"Q1c · Skip-gram and CBOW","html":"<div class=\"question\"><strong>Question. Explain Skip-gram and CBOW.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>","m2":false,"units":"5","marks":null,"sourcePages":[1],"historical":true},{"id":"q1d","title":"Q1d · Pragmatics and discourse","html":"<div class=\"question\"><strong>Question. Explain pragmatics and discourse in NLP.</strong> <span class=\"marks\">[individual allocation not printed; Q1 totals 20]</span></div><h3>Answer</h3><p><strong>Pragmatic analysis</strong> interprets an utterance using its situation and the speaker’s intended meaning. <strong>Discourse analysis</strong> studies how utterances connect across a text or conversation. Syntax and literal word meanings alone cannot settle every interpretation.</p><table><thead><tr><th>Text</th><th>Literal content</th><th>Contextual interpretation</th></tr></thead><tbody><tr><td>“Can you close the window?”</td><td>A question about ability.</td><td>Usually a polite request.</td></tr><tr><td>“Meera bought a laptop. It was expensive.”</td><td>Two sentences.</td><td>“It” connects the second sentence to the laptop.</td></tr><tr><td>“Meet me here tomorrow.”</td><td>An instruction.</td><td>Me, here and tomorrow depend on speaker, place and date.</td></tr></tbody></table><h3>Reference, mention and antecedent</h3><p>A <strong>referring expression</strong> points to an entity; a <strong>mention</strong> is its occurrence in the text. Its <strong>referent</strong> is the entity being discussed. An <strong>antecedent</strong> is a preceding expression used to interpret a later referring expression. Reference resolution identifies the intended referent. Coreference resolution groups mentions that refer to the same entity.</p><div class=\"flow\"><div class=\"node\">“Meera”<small>name mention</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Person entity<small>same referent</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">“she” / “the engineer”<small>other mentions</small></div></div><table><thead><tr><th>Concept</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Anaphora</td><td>Reference back to something introduced earlier.</td><td>“Riya arrived. She sat down.” She → Riya.</td></tr><tr><td>Cataphora</td><td>Reference forward to a later expression.</td><td>“Before she spoke, Riya checked the microphone.” she → Riya.</td></tr><tr><td>Exophora</td><td>Reference to the situation outside the text.</td><td>“Put it there”, said while pointing.</td></tr><tr><td>Coreference</td><td>Two or more mentions refer to the same entity.</td><td>“Dr Rao”, “the lecturer”, “she”.</td></tr><tr><td>Pronoun resolution</td><td>Find the referent of a pronoun.</td><td>Resolve “it” in “The laptop stopped because it overheated.”</td></tr></tbody></table><p>Coreference is broader than pronoun resolution: repeated names and descriptions also form a chain. Anaphora describes direction/dependence; coreference describes identity. In “I bought a car. The engine is noisy”, engine is related to the car but is not the same entity.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Reference = kiski baat? Coreference = alag mentions, same entity. Pronoun resolution = he/she/it kis se linked?</p><h3>Cohesion, coherence and discourse markers</h3>\n<p><strong>Cohesion</strong> is the explicit linguistic linking of a text through reference, repeated or related words, conjunctions and other devices. In “Rita bought a book. She read it”, she and it connect the second sentence to Rita and the book.</p>\n<p><strong>Coherence</strong> is the conceptual unity that makes a discourse meaningful. “The road flooded, so the match was cancelled” presents a plausible cause and consequence. A reader relates the propositions using context and knowledge.</p>\n<p><strong>Discourse markers</strong> signal relationships or organize speech: however signals contrast; therefore signals a result; first and next signal sequence; for example introduces an illustration.</p>\n<p>These concepts differ: “I like apples. Therefore the moon is square” has a linking word but no sensible inference. A connector alone does not guarantee coherence.</p>\n<p><strong>Yaad rakho:</strong> Cohesion = words se link; coherence = meaning se link; marker = relation ka signal.</p>","m2":false,"units":"6","marks":null,"sourcePages":[1],"historical":true},{"id":"q2a","title":"Q2a · Six preprocessing operations","html":"<div class=\"question\"><strong>Question. Explain lowercasing, tokenization, stopword removal, stemming, lemmatization and POS tagging with examples.</strong> <span class=\"marks\">[6 marks]</span></div><h3>Answer</h3><p><strong>Tokenization divides text into units called tokens for further processing.</strong> A token may be a word, punctuation mark, character or subword, depending on the tokenizer. <strong>Sentence segmentation</strong> identifies sentence boundaries. Tokenization is not necessarily just splitting on spaces.</p><table><thead><tr><th>Method</th><th>Example</th><th>Trade-off</th></tr></thead><tbody><tr><td>Word</td><td>“cats sleep” → [cats,sleep]</td><td>Easy to interpret; unfamiliar words can be unseen tokens</td></tr><tr><td>Character</td><td>cat → [c,a,t]</td><td>Handles spelling units; creates longer sequences</td></tr><tr><td>Subword</td><td>unhappiness → pieces such as [un,happi,ness] in an illustrative vocabulary</td><td>Balances vocabulary size and rare-word representation</td></tr><tr><td>Sentence</td><td>“Birds fly. Fish swim.” → two sentences</td><td>Abbreviations and punctuation complicate boundaries</td></tr></tbody></table><p>Actual subword splits depend on the learned vocabulary; the example is illustrative, not a universal tokenizer output. Word segmentation is especially important where spaces do not reliably separate words or in compound-rich languages.</p><div class=\"example\"><p><strong>Question. Tokenize “Dr. Rao can't come today.” into words and punctuation under this rule: preserve Dr. and can't as whole tokens, and split only the final full stop.</strong></p><div class=\"given\"><h4>Given</h4><p>The tokenization rule is explicitly supplied.</p><h4>To find</h4><p>The resulting token sequence.</p></div><h4>Formula and why it applies</h4><p>Apply the stated boundary rule; do not assume every period or apostrophe is a split point.</p><div class=\"step\"><h4>Step 1. Handle abbreviation</h4><p>Dr. remains one token.</p></div><div class=\"step\"><h4>Step 2. Handle contraction</h4><p>can't remains one token.</p></div><div class=\"step\"><h4>Step 3. Write sequence</h4><p>[Dr., Rao, can't, come, today, .]</p></div><p class=\"answer\"><strong>Answer.</strong> 6 tokens under the specified rule. Another tokenizer may legitimately produce a different sequence.</p></div><h3>Three difficult cases</h3><p><strong>New York</strong> may be two tokens but one named entity. <strong>3.14</strong> should not normally end a sentence at the decimal point. <strong>don't</strong> may remain whole or split into do + n't, depending on the tokenizer. Always state the convention when calculating counts.</p><p class=\"cue\">Token = chosen unit. Space split ko universal rule mat samajh.</p><p><strong>Normalization reduces superficial variation so comparable forms can be processed consistently.</strong> Common operations include lowercasing, Unicode normalization, appropriate spelling correction, contraction handling, and optional stemming or lemmatization.</p><p><strong>Stopwords</strong> are frequent words selected for removal for a particular task, such as the or a. Removing them may reduce feature size, but removing not, no or nor can destroy sentiment meaning. Punctuation can convey sentence boundaries, emotion or mathematical structure. Lowercasing can erase differences such as US versus us.</p><div class=\"example\"><p><strong>Question. Preprocess “The CATS are not sleeping!!!” by lowercasing, removing punctuation, removing only stopwords {the,are}, and lemmatizing plural cats→cat and sleeping→sleep.</strong></p><div class=\"given\"><h4>Given</h4><p>Operations and stopword set are fixed. Do not remove not.</p><h4>To find</h4><p>The final token list.</p></div><h4>Formula and why it applies</h4><p>Apply the requested operations in order, keeping a visible intermediate result after each transformation.</p><div class=\"step\"><h4>Step 1. Lowercase</h4><p>the cats are not sleeping!!!</p></div><div class=\"step\"><h4>Step 2. Tokenize and remove punctuation</h4><p>[the,cats,are,not,sleeping]</p></div><div class=\"step\"><h4>Step 3. Remove specified stopwords</h4><p>Remove the and are → [cats,not,sleeping].</p></div><div class=\"step\"><h4>Step 4. Lemmatize</h4><p>cats→cat; sleeping→sleep → [cat,not,sleep].</p></div><p class=\"answer\"><strong>Answer.</strong> [cat,not,sleep]. The negative meaning is retained.</p></div><h3>Task decides preprocessing</h3><p>For a simple keyword-retrieval model, removing selected function words can help. For machine translation, question answering, grammar analysis or transformer input, aggressive removal may discard necessary syntax or violate the model's expected input format. Emoji can carry sentiment; convert or retain them when relevant instead of always deleting them.</p><p class=\"cue\">Clean karna = useful signal bachake noise hatao. Har word/punctuation delete karna cleaning nahi.</p><p><strong>Stemming</strong> applies string-based rules, often stripping suffixes, to reduce related forms to a stem. The result need not be a valid dictionary word. <strong>Lemmatization</strong> uses vocabulary and morphological analysis, often with POS information, to return a dictionary lemma.</p><table><thead><tr><th>Criterion</th><th>Stemming</th><th>Lemmatization</th></tr></thead><tbody><tr><td>Basis</td><td>Surface form/suffix rules</td><td>Lexicon and morphological/POS analysis</td></tr><tr><td>Output</td><td>May be nonword, e.g. studi</td><td>Dictionary form, e.g. study</td></tr><tr><td>Context/POS</td><td>Usually little or none</td><td>Often important</td></tr><tr><td>Irregular forms</td><td>May miss went→go</td><td>Can map went→go with verb analysis</td></tr><tr><td>Cost</td><td>Generally simpler</td><td>Usually more linguistic processing</td></tr></tbody></table><p>Porter applies a sequence of suffix-removal rules subject to conditions; Snowball provides related language-specific stemming algorithms; Lancaster is often more aggressive; regex stemming uses explicit patterns; Lovins is another established stemming approach. Exact output depends on the algorithm and implementation.</p><h3>Three worked reductions</h3><ol><li><strong>studies, studying:</strong> an English stemmer may yield studi/study depending on the rule sequence; verb lemmatization aims at study. State the exact algorithm if exact outputs are asked.</li><li><strong>better:</strong> adjective-aware lemmatization can map it to good; naïve suffix removal cannot infer that irregular relation.</li><li><strong>saw:</strong> as a past-tense verb it can become see; as a cutting-tool noun it remains saw. POS and context matter.</li></ol><p><strong>Over-stemming</strong> merges forms that should remain distinct; <strong>under-stemming</strong> fails to merge related forms. Normalization can increase recall in search while losing useful distinctions, so it is a task-dependent choice.</p><p class=\"cue\">Stem = rules se cut; lemma = dictionary form, meaning/POS ka dhyan.</p><p><strong>Part-of-speech (POS) tagging</strong> assigns a grammatical category to every word token in context, such as noun, verb, adjective or determiner. It is a sequence-labeling task: the input is a sequence of words, and the output is a tag for each word. A tag describes the word's role in this sentence, not its meaning in every possible sentence.</p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Role</th><th>Example in context</th></tr></thead><tbody><tr><td>NN / NNS</td><td>Singular / plural common noun</td><td>a book / two books</td></tr><tr><td>NNP</td><td>Proper noun</td><td>Mary, Mumbai</td></tr><tr><td>VB / VBD / VBZ</td><td>Base / past / third-person singular verb</td><td>read / read / reads</td></tr><tr><td>JJ</td><td>Adjective</td><td>the red book</td></tr><tr><td>RB</td><td>Adverb</td><td>runs quickly</td></tr><tr><td>DT</td><td>Determiner</td><td>the, a, this</td></tr><tr><td>IN</td><td>Preposition or subordinating conjunction</td><td>on the table</td></tr><tr><td>PRP</td><td>Personal pronoun</td><td>she, they</td></tr><tr><td>MD</td><td>Modal auxiliary</td><td>can, will, should</td></tr></tbody></table></div><p><strong>Open classes</strong> readily accept new content words: nouns, verbs, adjectives and adverbs. Examples include chatbot and livestream. <strong>Closed classes</strong> contain comparatively stable grammatical/function words: determiners, pronouns, prepositions and conjunctions. These are tendencies, not a claim that language never changes.</p><div class=\"flow\"><div class=\"node\">Input: Book that flight</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context: an imperative request</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Output: Book/VB that/DT flight/NN</div></div><p>Compare “hand me that <strong>book</strong>”: book is a noun here. Similarly, “I <strong>can</strong> swim” has can/MD, while “the <strong>can</strong> is empty” has can/NN. The spelling stays the same; neighboring words and sentence structure change the correct tag. This is <strong>POS ambiguity</strong>.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged interpretation</th><th>Reason</th></tr></thead><tbody><tr><td>They watch birds.</td><td>They/PRP watch/VBP birds/NNS</td><td>watch is the action.</td></tr><tr><td>The watch stopped.</td><td>The/DT watch/NN stopped/VBD</td><td>watch is the object that stopped.</td></tr><tr><td>She has a light bag.</td><td>She/PRP has/VBZ a/DT light/JJ bag/NN</td><td>light describes bag.</td></tr><tr><td>Light the lamp.</td><td>Light/VB the/DT lamp/NN</td><td>Light is an imperative verb.</td></tr></tbody></table></div><p>POS tags support parsing, named entity recognition, question answering, sentiment analysis and word-sense disambiguation. They do not by themselves identify every entity or fully resolve meaning.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka naam same ho sakta hai; sentence mein uska kaam tag decide karta hai.</p>","m2":false,"units":"2,4","marks":6,"sourcePages":[1],"historical":true},{"id":"q2b","title":"Q2b · Lexical similarity and cosine","html":"<div class=\"question\"><strong>Question. Explain the need for lexical similarity and illustrate cosine similarity.</strong> <span class=\"marks\">[4 marks]</span></div><h3>Answer</h3><p>Similarity supports retrieval, clustering, duplicate detection and semantic matching. Choose a representation first: character overlap measures spelling; context embeddings approximate semantic relatedness. An illustrative cosine computation follows; these vectors are chosen to explain the method, not given exam data.</p><h3>Given</h3><p>u=[1, 1, 0]; v=[1, 0, 1]</p><h3>To find</h3><p>Cosine similarity in the given coordinate order.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bcd9c35430c84240.svg\" alt=\"\\cos(u,v)=\\frac{u\\cdot v}{\\|u\\|\\|v\\|}\" style=\"width:19.114ex;height:4.704ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Multiply matching coordinates</h3><p>1×1 + 1×0 + 0×1 = 1</p><h3>Step 2. Calculate both squared lengths</h3><p>u: 1² + 1² + 0² = 2; v: 1² + 0² + 1² = 2</p><h3>Step 3. Take square roots and divide</h3><p>1 / (√2 × √2) = 0.500000000</p><h3>Final answer</h3><p><strong>Cosine=0.500000000.</strong> This measures direction, not a probability.</p>","m2":false,"units":"2,5","marks":4,"sourcePages":[1],"historical":true},{"id":"q2c","title":"Q2c · Animal categorical Naive Bayes","html":"<div class=\"question\"><strong>Question. Using the printed20-animal training table, classify an animal with Give Birth=Yes, Can Fly=No, Live in Water=Yes, Have Legs=No. Treat Name only as an identifier.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Rows below follow the source order: Human, Python, Salmon, Whale, Frog, Komodo, Bat, Pigeon, Cat, Leopard Shark, Turtle, Penguin, Porcupine, Eel, Salamander, Gila Monster, Platypus, Owl, Dolphin, Eagle. The source assigns Leopard Shark to Non-mammals and Platypus to Mammals; retain those labels.</p><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Give Birth</th><th>Can Fly</th><th>Live in Water</th><th>Have Legs</th><th>Class</th></tr></thead><tbody><tr><td>Yes</td><td>No</td><td>No</td><td>Yes</td><td>Mammals</td></tr><tr><td>No</td><td>No</td><td>No</td><td>No</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>Yes</td><td>No</td><td>Non-mammals</td></tr><tr><td>Yes</td><td>No</td><td>Yes</td><td>No</td><td>Mammals</td></tr><tr><td>No</td><td>No</td><td>Sometimes</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>No</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>Yes</td><td>Yes</td><td>No</td><td>Yes</td><td>Mammals</td></tr><tr><td>No</td><td>Yes</td><td>No</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>Yes</td><td>No</td><td>No</td><td>Yes</td><td>Mammals</td></tr><tr><td>Yes</td><td>No</td><td>Yes</td><td>No</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>Sometimes</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>Sometimes</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>Yes</td><td>No</td><td>No</td><td>Yes</td><td>Mammals</td></tr><tr><td>No</td><td>No</td><td>Yes</td><td>No</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>Sometimes</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>No</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>No</td><td>No</td><td>No</td><td>Yes</td><td>Mammals</td></tr><tr><td>No</td><td>Yes</td><td>No</td><td>Yes</td><td>Non-mammals</td></tr><tr><td>Yes</td><td>No</td><td>Yes</td><td>No</td><td>Mammals</td></tr><tr><td>No</td><td>Yes</td><td>No</td><td>Yes</td><td>Non-mammals</td></tr></tbody></table></div><p>Test: {'Give Birth': 'Yes', 'Can Fly': 'No', 'Live in Water': 'Yes', 'Have Legs': 'No'}</p><h3>To find</h3><p>Class under categorical Naive Bayes.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0ec49ccf4b6243b5.svg\" alt=\"\\mathrm{score}(c)=P(c)\\prod_jP(x_j\\mid c)\" style=\"width:27.226ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use empirical categorical frequencies, not a multinomial word model. No likelihood is zero for the requested test, so unsmoothed estimates are sufficient. Each feature contributes once; ignore names/identifiers as predictors.</p><h3>Step 1. Count examples in each class</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Count</th><th>Prior</th></tr></thead><tbody><tr><td>Mammals</td><td>7</td><td>7/20</td></tr><tr><td>Non-mammals</td><td>13</td><td>13/20</td></tr></tbody></table></div><h3>Step 2. Count each requested feature within each class and multiply</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>n</th><th>Prior</th><th>Give Birth</th><th>Can Fly</th><th>Live in Water</th><th>Have Legs</th><th>Exact product</th><th>Decimal product</th></tr></thead><tbody><tr><td>Mammals</td><td>7</td><td>7/20</td><td>6/7</td><td>6/7</td><td>2/7</td><td>2/7</td><td>36/1715</td><td>0.020991253644</td></tr><tr><td>Non-mammals</td><td>13</td><td>13/20</td><td>1/13</td><td>10/13</td><td>3/13</td><td>4/13</td><td>6/2197</td><td>0.002730996814</td></tr></tbody></table></div><h3>Step 3. Normalize for a posterior if wanted</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Score / score sum</th></tr></thead><tbody><tr><td>Mammals</td><td>0.884876150</td></tr><tr><td>Non-mammals</td><td>0.115123850</td></tr></tbody></table></div><h3>Final answer</h3><p><strong>Predicted class: Mammals.</strong> The independence assumption is conditional on class, not a claim that these biological/weather features are truly independent.</p>","m2":false,"units":"7","marks":10,"sourcePages":[2],"historical":true},{"id":"q3a","title":"Q3a · Hobbs and ambiguous professor–student reference","html":"<div class=\"question\"><strong>Question. Explain Hobbs’ algorithm, including binding, gender, distance and recency. Resolve “The professor advised the student because she was struggling.”</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Hobbs’ algorithm is a syntax-based procedure that searches constituent parse trees in a fixed order for a compatible noun-phrase antecedent of a pronoun.</strong> The tree determines which candidates are proposed first. Agreement and other relevant constraints determine whether a proposed candidate can be accepted.</p><p>It is not simply the rule “choose the closest noun”. A nearby noun may have the wrong number, may be syntactically ineligible, or may be visited after a structurally more prominent noun. The algorithm produces a preference under the supplied parse; ambiguous language can still require context.</p><h3>The tree vocabulary you need</h3><table><thead><tr><th>Term</th><th>Meaning</th><th>Example</th></tr></thead><tbody><tr><td>NP</td><td>Noun phrase: a phrase referring to an entity</td><td>the student; Anita; they</td></tr><tr><td>S</td><td>A sentence/clause node</td><td>the node containing a subject and predicate</td></tr><tr><td>VP</td><td>Verb phrase</td><td>told Ravi that she should revise</td></tr><tr><td>X</td><td>The NP or S node currently being searched</td><td>An algorithm label, not a word</td></tr><tr><td>Path p</td><td>The branch travelled upward from the pronoun/previous X</td><td>Used to distinguish left and right subtrees</td></tr><tr><td>N-bar (N′)</td><td>The noun-centred part of an NP in a grammar using that label</td><td>The nominal-child test depends on the given tree</td></tr><tr><td>Breadth-first</td><td>Visit shallower nodes before deeper ones</td><td>Level 1 before level 2</td></tr><tr><td>Left-to-right</td><td>Visit equally deep nodes in their written/tree order</td><td>Earlier left branch before right branch</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">Locate pronoun NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Climb to NP/S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Propose candidates in tree order</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Check compatibility</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Accept or continue searching</div></div><h3>The complete search procedure</h3><div class=\"step\"><h4>Step 1. Start at the pronoun</h4><p>Locate the NP immediately dominating the pronoun. “Dominating” means containing it as a descendant in the tree.</p></div><div class=\"step\"><h4>Step 2. Climb to the first NP or S</h4><p>Move upward to the first NP or S above that starting NP. Call this node X. Keep the upward path p.</p></div><div class=\"step\"><h4>Step 3. Search the left branches initially</h4><p>Below X, traverse branches to the left of p breadth-first and left-to-right. At this initial search, propose an NP only if another NP or S lies between that candidate and X. Test proposed candidates for the required agreement and constraints.</p></div><div class=\"step\"><h4>Step 4. If X is the highest sentence node, inspect earlier sentences</h4><p>Search previous sentence trees from most recent to oldest. Within each, use breadth-first, left-to-right order to propose NPs. Accept the first eligible compatible candidate, or report that no candidate was found in the available context.</p></div><div class=\"step\"><h4>Step 5. Otherwise climb again</h4><p>Move from X to the next NP or S above it. Record this new X and the path followed during the climb.</p></div><div class=\"step\"><h4>Step 6. Apply the higher-NP test</h4><p>If the new X is an NP, propose X when the path did not pass through its nominal N-bar child. Use the given parse labels; do not invent an N-bar branch missing from the question's structure.</p></div><div class=\"step\"><h4>Step 7. Search its left branches</h4><p>Traverse branches below the new X to the left of the path, breadth-first and left-to-right, proposing NPs. The special intervening-NP/S restriction belongs to the initial search in Step 3.</p></div><div class=\"step\"><h4>Step 8. If X is S, search the permitted right branches</h4><p>Search branches to the right of the path breadth-first and left-to-right. Do not descend below an encountered NP or S. Propose eligible NP candidates there.</p></div><div class=\"step\"><h4>Step 9. Repeat or stop</h4><p>Return to the highest-S check and continue the climb/search procedure until a compatible candidate is accepted or the available trees are exhausted. Record the candidate order rather than only writing an unexplained name.</p></div><h3>Why the first left search has an extra condition</h3><p>In a simple clause such as “John saw him”, the subject NP John is directly under the clause S. There is no extra NP or S between John and that S. The initial-search restriction therefore prevents casually selecting John as the ordinary local antecedent of him. Compare the reflexive “John saw himself”, which is a different grammatical case; do not treat every pronoun type as interchangeable.</p><section class=\"example\"><h3>Worked tree 1 · move to the previous sentence</h3><p class=\"question\"><strong>Question. Apply Hobbs’ search to “The student arrived. She smiled.” Assume the student is compatible with she.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree: [S [NP The student] [VP arrived]]. Current tree: [S [NP She] [VP smiled]].</p><h4>To find</h4><p>The selected antecedent and the search path.</p></div><h4>Method and why it applies</h4><p>Use the supplied constituent trees. The current sentence has no earlier candidate, so the highest-S rule activates previous-sentence search.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw both sentence structures</h4><pre aria-label=\"Two constituent trees\">Previous sentence             Current sentence\nS                             S\n├── NP: The student            ├── NP: She ← start\n└── VP: arrived                └── VP: smiled</pre></div><div class=\"step\"><h4>Step 2. Locate and climb</h4><p>Start at NP She. Its first higher NP/S is the current S. Set X to that S.</p></div><div class=\"step\"><h4>Step 3. Search left of the path</h4><p>She is the leftmost subject. No NP lies to its left in the current sentence.</p></div><div class=\"step\"><h4>Step 4. Use the highest-S rule</h4><p>This X is the highest S. Inspect the immediately preceding sentence tree.</p></div><div class=\"step\"><h4>Step 5. Propose its first NP</h4><p>Breadth-first, left-to-right finds NP The student.</p></div><div class=\"step\"><h4>Step 6. Check compatibility and accept</h4><p>The question stipulates that the student agrees with she. Accept this candidate.</p></div><div class=\"answer\"><strong>Answer.</strong> She refers to the student under the supplied assumptions.</div></section><section class=\"example\"><h3>Worked tree 2 · reject an incompatible subject</h3><p class=\"question\"><strong>Question. Resolve they in “Riya spoke to the students. They laughed.” Use a previous-sentence search and interpret they as plural.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree has subject NP Riya, then VP spoke [PP to [NP the students]]. Current subject is NP They.</p><h4>To find</h4><p>The candidate order and accepted antecedent.</p></div><h4>Method and why it applies</h4><p>Breadth-first search favours a shallow subject, but agreement must still be applied; a first candidate is not automatically a valid answer.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw the useful part of the previous tree</h4><pre aria-label=\"Riya and the students constituent tree\">S\n├── NP: Riya                 ← candidate 1\n└── VP\n    ├── V: spoke\n    └── PP\n        ├── P: to\n        └── NP: the students ← candidate 2</pre></div><div class=\"step\"><h4>Step 2. Search the current sentence</h4><p>From NP They climb to its S; there is no earlier NP in “They laughed”. This is the highest S, so move to the previous tree.</p></div><div class=\"step\"><h4>Step 3. Visit Riya first</h4><p>Riya is the shallower leftmost NP. Under the stated plural interpretation, this singular candidate fails number agreement.</p></div><div class=\"step\"><h4>Step 4. Visit the students</h4><p>Continue breadth-first. The next relevant NP is the students.</p></div><div class=\"step\"><h4>Step 5. Apply number agreement</h4><p>Students is plural and is an eligible candidate. It matches plural they.</p></div><div class=\"step\"><h4>Step 6. State the resolution</h4><p>Accept the students. The method did not simply accept the first noun it saw.</p></div><div class=\"answer\"><strong>Answer.</strong> They → the students. Candidate order: Riya rejected; the students accepted.</div></section><section class=\"example\"><h3>Worked tree 3 · climb out of an embedded clause</h3><p class=\"question\"><strong>Question. Resolve she in “Anita told Ravi that she should revise.” Assume Anita is compatible with she and Ravi is not. Use the displayed parse.</strong></p><div class=\"given\"><h4>Given</h4><p>The pronoun is the subject of an embedded S inside the main VP.</p><h4>To find</h4><p>The preferred antecedent found by the climb and left-branch search.</p></div><h4>Method and why it applies</h4><p>The embedded clause has no left candidate. Climbing to the main S exposes its subject Anita as the first suitable higher-level candidate.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Show the clause structure</h4><pre aria-label=\"Embedded clause pronoun tree\">S (main)\n├── NP: Anita                  ← accepted candidate\n└── VP\n    ├── V: told\n    ├── NP: Ravi\n    └── SBAR: that\n        └── S (embedded)       ← first X\n            ├── NP: she        ← start\n            └── VP: should revise</pre></div><div class=\"step\"><h4>Step 2. Start inside the embedded clause</h4><p>From NP she climb to the embedded S. There is no candidate to the left of she within this embedded S.</p></div><div class=\"step\"><h4>Step 3. Climb to the next NP/S</h4><p>The embedded S is not the highest S. Move upward through SBAR and VP to the main S. These intermediate nodes are not NP/S search nodes.</p></div><div class=\"step\"><h4>Step 4. Search left of the upward path</h4><p>At the main S, the subject NP Anita is a shallow left candidate. The object Ravi is deeper within the VP. Breadth-first order proposes Anita first.</p></div><div class=\"step\"><h4>Step 5. Check the stated compatibility</h4><p>Anita is compatible with she by the question's assumption. Accept it; no need to choose a later incompatible candidate.</p></div><div class=\"step\"><h4>Step 6. Give the result and its limit</h4><p>This is the algorithm's result under the displayed parse and agreement assumptions. It does not prove the intention of every speaker using an otherwise ambiguous sentence.</p></div><div class=\"answer\"><strong>Answer.</strong> She → Anita under the stated tree and compatibility information.</div></section><h3>Advantages, limitations and a complete exam answer</h3><table><thead><tr><th>Advantages</th><th>Limitations</th></tr></thead><tbody><tr><td>Explicit candidate order makes the decision traceable.</td><td>Wrong parse structure can produce the wrong search order.</td></tr><tr><td>Requires no labelled coreference-training corpus for its basic rules.</td><td>World knowledge and discourse intention may override syntactic preference.</td></tr><tr><td>Uses structure rather than only surface distance.</td><td>Some ambiguous, long-distance or unusual constructions need additional treatment.</td></tr></tbody></table><p>For a longer answer, write the definition, inputs, tree notation, ordered algorithm, one labelled tree with a candidate table, final antecedent, and limitations. In a worked question show separately: candidate → why proposed → agreement result → accept/reject. Do not equate the selected candidate with a logically guaranteed interpretation when the sentence is ambiguous.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Tree order candidate deta hai; agreement usko allow/reject karta hai. Nearest noun automatically answer nahi.</p><p><strong>The intended antecedent is not uniquely determined by the printed sentence.</strong> Both professor and student can be singular female people; neither noun supplies gender. Structural Hobbs search can propose the matrix subject professor early, while the causal meaning of advice because of struggling often supports student. Distance/recency favouring student is a preference, not proof.</p><ol><li>Parse subject NP the professor, object NP the student, subordinate-clause subject she.</li><li>Generate structurally accessible earlier NPs through the Hobbs ascent and breadth-first leftward search.</li><li>Check grammatical number/person and binding constraints. Both candidates can pass here; she is not a reflexive.</li><li>Gender/world knowledge is unavailable, so do not invent either person’s gender.</li><li>Use broader discourse to select. Without it, report professor/student ambiguity; explain that contextual interpretation often prefers student but the syntax-only algorithm does not guarantee that intent.</li></ol><p><strong>Source / convention note.</strong> Pronoun referent is ambiguous without extra gender/discourse information; structural algorithm preference is separated from semantic interpretation.</p><h3>The four requested properties</h3><div class=\"table-wrap\"><table><thead><tr><th>Property</th><th>What it means</th><th>Apply here</th></tr></thead><tbody><tr><td>Binding</td><td>Syntactic restrictions on reference; ordinary personal pronouns and reflexives have different local-antecedent requirements</td><td>Do not mechanically link every nearby NP; he in an after/because clause can refer outside that local clause.</td></tr><tr><td>Gender agreement</td><td>Candidate must match the pronoun under available linguistic/contextual knowledge</td><td>John/he is the exercise’s conventional reading; professor/student do not provide gender by themselves.</td></tr><tr><td>Distance</td><td>Token, syntactic or sentence separation between pronoun and candidate</td><td>Closer candidates may be preferred, but cannot override incompatibility or Hobbs search order.</td></tr><tr><td>Recency</td><td>Recently mentioned discourse entities are often more salient</td><td>Mary/student is later than John/professor, but recency is a preference, not a guaranteed antecedent rule.</td></tr></tbody></table></div>","m2":false,"units":"6","marks":10,"sourcePages":[2],"historical":true},{"id":"q3b","title":"Q3b · Classification and sentiment in industry","html":"<div class=\"question\"><strong>Question. Discuss real-world text classification and sentiment analysis, with examples showing decision-making and customer engagement.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Text classification</strong> assigns a document to one or more predefined categories. Spam detection usually uses two classes; news classification may use several topics. In single-label multiclass classification, choose one of several categories. In multilabel classification, several labels may apply to the same document.</p><div class=\"flow\"><div class=\"node\">Define labels</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Prepare labelled examples</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Train representation + model</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evaluate on unseen text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Predict new labels</div></div><h3>An exam-ready pipeline</h3><table><thead><tr><th>Stage</th><th>What you do</th><th>Why it matters</th></tr></thead><tbody><tr><td>Task definition</td><td>Decide what counts as spam or which news topics exist.</td><td>Unclear labels create inconsistent training data.</td></tr><tr><td>Data collection and annotation</td><td>Collect representative examples and assign correct labels.</td><td>The model learns from these examples.</td></tr><tr><td>Split data</td><td>Separate training, validation and test data.</td><td>Test examples must not influence training choices.</td></tr><tr><td>Preprocess</td><td>Tokenize and normalise where suitable; retain meaningful negation.</td><td>Reduce irrelevant variation without deleting signal.</td></tr><tr><td>Represent</td><td>Use BoW, TF-IDF or learned embeddings.</td><td>Models need numerical features.</td></tr><tr><td>Train</td><td>Fit Naive Bayes, logistic regression or another appropriate model.</td><td>Learn how features predict categories.</td></tr><tr><td>Evaluate</td><td>Measure relevant precision, recall and F1 on held-out examples.</td><td>Accuracy alone may hide poor minority-class performance.</td></tr><tr><td>Deploy and monitor</td><td>Apply the same preprocessing and monitor changing language.</td><td>Incoming data can differ from old examples.</td></tr></tbody></table><p>Naive Bayes is especially useful for hand calculations. With a bag-of-words representation, its class score is the prior multiplied by the conditional probability of each token; repeated tokens repeat the factor. The “naive” assumption is conditional independence of features given the class, not that words are independent in real language.</p><div class=\"math-display\"><img src=\"math/6dd9b21835eaff13.svg\" alt=\"s(c)=P(c)\\prod_{w\\in V}P(w\\mid c)^{C(w,d)}\" style=\"width:28.469ex;height:4.928ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>C(w,d) counts word w in document d. C(w,c) counts it in training documents belonging to class c. N<sub>c</sub> is the total token count for class c. Add-one smoothing adds one to every vocabulary count and therefore adds |V| to the denominator. This is the same arithmetic taught for WSD, with document classes instead of senses.</p><section class=\"example\"><h3>Worked classification · two-token message</h3><p class=\"question\">A spam classifier has vocabulary {win, prize, meeting}. Priors are P(spam)=P(ham)=0.5. Spam token counts are [3,2,0]; ham counts are [0,0,5]. With add-one smoothing, classify “win prize”.</p><div class=\"given\"><strong>Given</strong><p>|V|=3; N(spam)=5; N(ham)=5; message has win once and prize once.</p><strong>To find</strong><p>Class scores and predicted label.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/81645a009f312045.svg\" alt=\"s(c)=P(c)P(\\text{win}\\mid c)P(\\text{prize}\\mid c)\" style=\"width:32.21ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>The model is multinomial Naive Bayes; multiply the two token likelihoods and the class prior.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compute the smoothed denominators</h4><div class=\"math-display\"><img src=\"math/7e931d91ea22e68e.svg\" alt=\"5+3=8\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Compute spam likelihoods</h4><div class=\"math-display\"><img src=\"math/724a47033195de19.svg\" alt=\"P(\\text{win}\\mid S)=\\frac{3+1}{8}=\\frac12\" style=\"width:24.509ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fc2cdb5225a070b5.svg\" alt=\"P(\\text{prize}\\mid S)=\\frac{2+1}{8}=\\frac38\" style=\"width:25.772ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute ham likelihoods</h4><div class=\"math-display\"><img src=\"math/4134fa5958e2a1ed.svg\" alt=\"P(\\text{win}\\mid H)=P(\\text{prize}\\mid H)=\\frac{0+1}{8}=\\frac18\" style=\"width:40.213ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Multiply the spam score</h4><div class=\"math-display\"><img src=\"math/79f02eee2a0a5ddb.svg\" alt=\"s(S)=\\frac12\\times\\frac12\\times\\frac38=\\frac{3}{32}=0.09375\" style=\"width:35.918ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Multiply the ham score</h4><div class=\"math-display\"><img src=\"math/05ad87647bbe0b7d.svg\" alt=\"s(H)=\\frac12\\times\\frac18\\times\\frac18=\\frac{1}{128}=0.0078125\" style=\"width:39.861ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Compare</h4><p>0.09375 > 0.0078125. These are unnormalised scores; the label is chosen by the larger score.</p></div><div class=\"answer\">Predicted label: spam.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Class prior × har word ki class-likelihood; sabse bada score wins.</p></section><p><strong>Sentiment analysis</strong> identifies expressed opinion or attitude, often as positive, negative or neutral. Document-level analysis labels a complete text; sentence-level analysis labels a sentence; aspect-level analysis attaches sentiment to a specific feature or entity.</p><table><thead><tr><th>Review</th><th>Useful interpretation</th></tr></thead><tbody><tr><td>“The display is excellent, but the battery is poor.”</td><td>Display: positive; battery: negative. One overall label loses this distinction.</td></tr><tr><td>“The service is not good.”</td><td>Negative: negation changes good. Removing not can reverse the intended meaning.</td></tr><tr><td>“Great, another two-hour delay.”</td><td>Likely sarcasm: literal positive word alone is insufficient.</td></tr></tbody></table><h3>Approaches</h3><p><strong>Lexicon based:</strong> look up sentiment scores, combine them, and apply stated handling for negation/intensifiers. It is interpretable but fragile with context and sarcasm. <strong>Supervised:</strong> learn a mapping from labelled text features to sentiment labels. <strong>Neural/contextual:</strong> learn or use contextual representations to capture word interactions, then fine-tune a sentiment classifier. None guarantees correct interpretation of every review.</p><section class=\"example\"><h3>A specified lexicon calculation</h3><p class=\"question\">Use good = +2, excellent = +3 and slow = −2. A “not” immediately before a sentiment word reverses its score. Score “The support was not good but the delivery was excellent and slow.”</p><div class=\"given\"><strong>Given</strong><p>Three sentiment words; not modifies good only; sum word scores under the stated rule.</p><strong>To find</strong><p>Total sentiment score and label, taking positive totals as positive.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/f9356cb0249ff14a.svg\" alt=\"S=\\sum_i s_i\" style=\"width:9.921ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div><p>Apply the given negation rule before summing. This is a simplified specified model, not a universal linguistic rule.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify sentiment words</h4><p>good, excellent and slow.</p></div><div class=\"step\"><h4>Step 2. Apply negation</h4><div class=\"math-display\"><img src=\"math/b751e154a1c1b2a0.svg\" alt=\"s(\\text{not good})=-2\" style=\"width:17.216ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Add the contributions</h4><div class=\"math-display\"><img src=\"math/76ffe09c2be2d0ce.svg\" alt=\"S=-2+3-2=-1\" style=\"width:21.07ex;height:1.781ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Map score to label</h4><p>The sum is negative.</p></div><div class=\"answer\">Total score = −1; negative under this rule.</div></section><div class=\"table-wrap\"><table><thead><tr><th>Industry</th><th>Concrete input and output</th><th>Useful decision / limitation</th></tr></thead><tbody><tr><td>Retail</td><td>Review→topic and sentiment</td><td>Route delivery complaints; sarcasm/negation may mislead</td></tr><tr><td>Banking</td><td>Customer message→card/fraud/loan intent</td><td>Route to the correct team; a model flag is not proof of fraud</td></tr><tr><td>Healthcare</td><td>Feedback→service-quality topics</td><td>Detect recurring appointment issues; protect patient identifiers</td></tr><tr><td>Media</td><td>Article→topic; public responses→sentiment</td><td>Organize feeds and monitor reaction; sampling bias prevents treating posts as a census</td></tr></tbody></table></div>","m2":false,"units":"7","marks":10,"sourcePages":[3],"historical":true},{"id":"q4a","title":"Q4a · Top-down syntax tree","html":"<div class=\"question\"><strong>Question. Explain the need for syntax parsing; compare top-down and bottom-up parsing. Parse “the cat chased the dog” using S→NP VP, NP→Det N, VP→V NP, Det→the, N→cat|dog, V→chased|saw.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Top-down parsing</strong> starts at the grammar's start symbol S and expands nonterminals until the leaves match the input words in order. <strong>Recursive descent</strong> commonly implements each nonterminal as a procedure that tries its productions. It builds from the root toward the leaves.</p><div class=\"flow\"><div class=\"node\">Start with S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Choose an allowed S production</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Expand its next nonterminal</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match the resulting terminal to the input</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Continue, or backtrack if the choice fails</div></div><p><strong>Algorithm.</strong> Start with S as the current goal. Choose a production for the leftmost unexpanded nonterminal. Replace that nonterminal by the production's right side. If a terminal appears, compare it with the next input token. If it matches, consume the token; if it does not, reject that branch and try another production. Accept only when the complete input is consumed and all grammar goals are satisfied.</p><p>A <strong>leftmost derivation</strong> always expands the leftmost remaining nonterminal first. Top-down parsing can make guesses that the actual words cannot support, so it may need backtracking. A naive recursive-descent parser can loop on left-recursive rules such as NP→NP PP unless the grammar or algorithm is changed. Predictive LL(1) parsing chooses productions using one lookahead token when the grammar permits; not every English CFG is LL(1).</p><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>Begins with</th><th>Direction</th><th>Common difficulty</th></tr></thead><tbody><tr><td>Top-down</td><td>Start symbol S</td><td>Root to word leaves</td><td>Predictions that do not match input; left recursion</td></tr><tr><td>Bottom-up</td><td>Actual input tokens</td><td>Leaves to root S</td><td>Reductions that cannot contribute to a complete sentence</td></tr></tbody></table></div><p class=\"cue\"><strong>Yaad rakho:</strong> Top-down: sentence ka structure pehle, words tak neeche aao.</p><p><strong>Bottom-up parsing</strong> starts from the input tokens and combines them into larger constituents until the start symbol is reached. A <strong>shift-reduce parser</strong> maintains a stack of recognized material and a list of remaining input tokens.</p><div class=\"table-wrap\"><table><thead><tr><th>Action</th><th>Exact operation</th><th>Example</th></tr></thead><tbody><tr><td>Shift</td><td>Move the next input token onto the stack</td><td>Stack: the; remaining input: dog runs</td></tr><tr><td>Reduce</td><td>Replace a suffix of the stack matching a rule's RHS with its LHS</td><td>Det N becomes NP using NP→Det N</td></tr><tr><td>Accept</td><td>Stack is S and input is exhausted</td><td>Stack: S; input: empty</td></tr><tr><td>Fail/backtrack</td><td>Chosen reductions cannot complete a parse</td><td>A noun reading of book blocks an imperative parse</td></tr></tbody></table></div><p>Reduction uses a production in reverse: the grammar NP→Det N expands an NP top-down, but reduces Det N into NP bottom-up. The stack's <strong>rightmost item is its top</strong> in the traces below. Each row shows the state <strong>after</strong> the listed action, avoiding an off-by-one mismatch between actions and stack contents.</p><p>A lexical reduction such as N→dog still counts as a reduction. Do not skip the sequence from word to category to phrase when the question asks for a complete trace. Backtracking means returning to an earlier choice and trying another applicable rule, not changing the original input.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Shift = input se stack. Reduce = chhote pieces se bada grammatical unit.</p><h3>Exact top-down derivation</h3><ol><li>S</li><li>NP VP</li><li>Det N VP</li><li>the N VP</li><li>the cat VP</li><li>the cat V NP</li><li>the cat chased NP</li><li>the cat chased Det N</li><li>the cat chased the N</li><li>the cat chased the dog</li></ol><div style=\"overflow:auto\"><figure><svg viewBox=\"0 0 430 318\" role=\"img\" aria-label=\"Constituent parse tree\" style=\"width:100%;min-width:400px\"><line x1=\"55.0\" y1=\"165\" x2=\"55.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"95.0\" y1=\"100\" x2=\"55.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"165\" x2=\"135.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"95.0\" y1=\"100\" x2=\"135.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"215.0\" y1=\"35\" x2=\"95.0\" y2=\"76\" stroke=\"#718c85\"/><line x1=\"215.0\" y1=\"165\" x2=\"215.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"100\" x2=\"215.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"230\" x2=\"295.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"335.0\" y1=\"165\" x2=\"295.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"375.0\" y1=\"230\" x2=\"375.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"335.0\" y1=\"165\" x2=\"375.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"100\" x2=\"335.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"215.0\" y1=\"35\" x2=\"295.0\" y2=\"76\" stroke=\"#718c85\"/><text x=\"215.0\" y=\"28\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">S</text><text x=\"95.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"55.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Det</text><text x=\"55.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">the</text><text x=\"135.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">N</text><text x=\"135.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">cat</text><text x=\"295.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VP</text><text x=\"215.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">V</text><text x=\"215.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">chased</text><text x=\"335.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"295.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Det</text><text x=\"295.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">the</text><text x=\"375.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">N</text><text x=\"375.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">dog</text></svg><figcaption>[S [NP [Det the] [N cat]] [VP [V chased] [NP [Det the] [N dog]]]]</figcaption></figure></div><p>Parsing assigns constituent structure and grammatical relationships for extraction, translation and ambiguity resolution. Top-down expands from S toward input; bottom-up combines observed tokens toward S. This derivation uses only supplied rules.</p>","m2":false,"units":"4","marks":10,"sourcePages":[3],"historical":true},{"id":"q4b","title":"Q4b · Data acquisition and four augmentation methods","html":"<div class=\"question\"><strong>Question. Explain NLP data acquisition, why augmentation is needed, and any four augmentation methods.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Data acquisition</strong> obtains language examples relevant to the task from existing data, public resources or appropriate new collection. Product instrumentation can gather useful feedback. Supervised learning additionally needs an annotation process when labels are absent.</p><p><strong>Data augmentation</strong> creates training variants intended to preserve the correct label. It is not simply changing words arbitrarily.</p><table><thead><tr><th>Method</th><th>Procedure</th><th>Caution</th></tr></thead><tbody><tr><td>Synonym replacement</td><td>Use suitable synonyms for selected words</td><td>Choose the right sense</td></tr><tr><td>Back translation</td><td>Translate to another language and back</td><td>May change meanings/entities</td></tr><tr><td>TF–IDF-informed replacement</td><td>Protect informative words while varying others</td><td>Do not remove label-bearing clues</td></tr><tr><td>Bigram flipping</td><td>Swap adjacent words</td><td>Can break grammar or meaning</td></tr><tr><td>Entity replacement</td><td>Replace by same-type entity</td><td>Must preserve the task label</td></tr><tr><td>Noise injection</td><td>Simulate typos/keyboard errors</td><td>Match expected noise</td></tr><tr><td>Active learning</td><td>Select informative cases for human labels</td><td>This acquires labels; it is not synthetic text</td></tr></tbody></table><h3>Three label decisions</h3><p>“The film is good”→“The film is excellent” may preserve a positive sentiment label. “The film is not good”→“The film is good” reverses the label and is not valid label-preserving augmentation. “Flights to Pune”→“Flights to Mumbai” may preserve a travel-topic label but changes the destination label.</p><p>Split train/test data before creating related augmented variants. Otherwise near-duplicates can leak between sets and produce misleading evaluation. Keep a representative evaluation set of genuine examples.</p><p class=\"cue\">Sentence badal sakta hai; required correct label nahi. Label badla toh augmentation invalid.</p><div class=\"table-wrap\"><table><thead><tr><th>Method</th><th>Example</th><th>Required label check</th></tr></thead><tbody><tr><td>Synonym replacement</td><td>good film→excellent film</td><td>Replacement must preserve sense and sentiment</td></tr><tr><td>Back-translation</td><td>English→French→English paraphrase</td><td>Check negation, entity and factual preservation</td></tr><tr><td>Contextual paraphrasing</td><td>The delivery was late→The package arrived late</td><td>Do not change class or named facts</td></tr><tr><td>Controlled noise / perturbation</td><td>Small realistic spelling error or punctuation variation</td><td>Appropriate only if target should remain unchanged</td></tr></tbody></table></div><p>Acquire licensed/public datasets, commissioned annotation, surveys/user-consented logs or permitted scraping. Augment training data only after splitting to avoid near-duplicate leakage into validation/test. More synthetic examples do not guarantee better generalization.</p>","m2":false,"units":"3","marks":10,"sourcePages":[3],"historical":true},{"id":"q5a","title":"Q5a · Feature engineering, BoW and Euclidean","html":"<div class=\"question\"><strong>Question. Explain text feature engineering and list vectorization approaches. For the three sentences below remove stopwords {is,that,are,to,and}, create vocabulary and BoW, then compute Euclidean distance between sentences1and2: “Natural Language Processing is fascinating”; “I love Natural Language processing and like to study Natural Language”; “I like things that are fascinating”.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Feature engineering converts text into informative model inputs. Common approaches: one-hot, BoW, bag of n-grams, TF–IDF and dense embeddings. This question specifically requests count-based BoW, so do not use TF–IDF in its distance.</p><h3>Given</h3><p>Use lowercase lexical tokens and the exact printed stoplist; I remains because it is not a stopword here.</p><h3>To find</h3><p>Vocabulary, count matrix and distance D1–D2.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4df9d01057f7efb0.svg\" alt=\"d_E(u,v)=\\sqrt{\\sum_i(u_i-v_i)^2}\" style=\"width:25.72ex;height:5.566ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Tokenize and remove the exact stoplist</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Retained tokens</th></tr></thead><tbody><tr><td>1</td><td>natural, language, processing, fascinating</td></tr><tr><td>2</td><td>i, love, natural, language, processing, like, study, natural, language</td></tr><tr><td>3</td><td>i, like, things, fascinating</td></tr></tbody></table></div><h3>Step 2. Fix vocabulary and count repeats</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>fascinating</th><th>i</th><th>language</th><th>like</th><th>love</th><th>natural</th><th>processing</th><th>study</th><th>things</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>2</td><td>0</td><td>1</td><td>2</td><td>1</td><td>1</td><td>2</td><td>1</td><td>1</td><td>0</td></tr><tr><td>3</td><td>1</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><h3>Step 3. Subtract coordinates</h3><p>[1, -1, -1, -1, -1, -1, 0, -1, 0]</p><h3>Step 4. Square, sum and take the root</h3><p>1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 0 = 7; √7 = 2.645751311</p><h3>Final answer</h3><p><strong>Euclidean distance=2.645751311.</strong> Natural and Language each occur twice in sentence2; preserve both counts.</p>","m2":false,"units":"2","marks":10,"sourcePages":[3],"historical":true},{"id":"q5b","title":"Q5b · WSD approaches and uses","html":"<div class=\"question\"><strong>Question. Explain WSD, its approaches and applications.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Word sense disambiguation (WSD) is the task of selecting the intended sense of an ambiguous word in its context from a set of possible senses.</strong> The output is a sense label, not a different replacement word.</p><div class=\"flow\"><div class=\"node\">Input: “He grilled the bass.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">Candidate senses: fish / low sound</div><span aria-hidden=\"true\">→</span><div class=\"node\">Context: grilled</div><span aria-hidden=\"true\">→</span><div class=\"node\">Output: fish sense</div></div><p>The <strong>target word</strong> is the ambiguous word. The <strong>context</strong> is the surrounding evidence. The <strong>sense inventory</strong> lists candidate meanings, often using WordNet. A <strong>feature</strong> is a usable clue: nearby word, position, part-of-speech tag or a phrase.</p><table><thead><tr><th>Approach</th><th>What it needs</th><th>How it decides</th><th>Limitation</th></tr></thead><tbody><tr><td>Knowledge based</td><td>Dictionary, thesaurus or semantic graph</td><td>Definition overlap, category evidence or graph scores</td><td>Short definitions and missing knowledge</td></tr><tr><td>Supervised</td><td>Examples already labelled with senses</td><td>Learns context → sense mapping</td><td>Labelling cost, limited rare-sense examples</td></tr><tr><td>Semi-supervised</td><td>Small labelled set plus unlabelled data</td><td>Bootstraps from reliable seed examples</td><td>Early errors can spread</td></tr><tr><td>Unsupervised sense induction</td><td>Unlabelled contextual occurrences</td><td>Clusters similar contexts</td><td>Clusters are not automatically named dictionary senses</td></tr><tr><td>Neural/contextual</td><td>Learned word/context representations</td><td>Predicts or compares a context representation</td><td>Needs suitable data/model and evaluation</td></tr></tbody></table><p><strong>Bag-of-words features</strong> record nearby words while ignoring exact positions. <strong>Collocational features</strong> preserve a positional phrase such as “river bank”, “bank account”, “chocolate bar” or “bar exam”.</p><h3>Why WSD matters</h3><p>Machine translation needs the correct target-language meaning; information retrieval should distinguish river-bank travel from banking services; text-to-speech may need different pronunciations for “bass”; information extraction should avoid connecting entities through the wrong relation.</p><p class=\"cue\">WSD: same spelling ke options mein context dekh ke sahi meaning select.</p>","m2":false,"units":"5","marks":5,"sourcePages":[3],"historical":true},{"id":"q5c","title":"Q5c · Discourse analysis of a conversation","html":"<div class=\"question\"><strong>Question. Analyze coherence, cohesion, topic structure, information flow and discourse markers: Speaker1 “I went to the store to buy some milk.” Speaker2 “Was it crowded?” Speaker1 “Yes, I had to wait in line for10minutes.” Speaker3 “I was going to attend the meeting, but I got stuck in traffic.”</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Feature</th><th>Evidence and explanation</th></tr></thead><tbody><tr><td>Coherence</td><td>First3turns form a meaningful store/crowding/waiting exchange. The meeting/traffic turn shifts topic without an explicit bridge; local relevance is weaker.</td></tr><tr><td>Cohesion</td><td>it refers to the store; Yes answers the preceding question; first-person I shifts referent with each speaker.</td></tr><tr><td>Topic structure</td><td>Store visit→crowding→wait; then new topic of meeting attendance and traffic.</td></tr><tr><td>Information flow</td><td>Known store is followed by new question crowding, then new evidence10-minute wait. The last turn introduces separate plans and obstacle.</td></tr><tr><td>Discourse markers</td><td>Yes signals affirmation; but signals contrast between intention and obstructing traffic. “To buy” states purpose, not merely temporal order.</td></tr></tbody></table></div><p>Cohesion is explicit linguistic linkage; coherence is meaningful conceptual connection. A conversation can contain grammatical connectors and still have a poorly connected topic shift.</p>","m2":false,"units":"6","marks":5,"sourcePages":[4],"historical":true},{"id":"q6a","title":"Q6a · Henry bigram continuations","html":"<div class=\"question\"><strong>Question. From the seven supplied training sentences below, predict the most probable next token for &lt;s&gt; Do ..., &lt;s&gt; I like ..., and &lt;s&gt; I ... using bigrams.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>&lt;s&gt; I am Henry &lt;/s&gt;<br>&lt;s&gt; I like college &lt;/s&gt;<br>&lt;s&gt; Do Henry like college &lt;/s&gt;<br>&lt;s&gt; Henry I am &lt;/s&gt;<br>&lt;s&gt; Do I like Henry &lt;/s&gt;<br>&lt;s&gt; Do I like college &lt;/s&gt;<br>&lt;s&gt; I do like Henry &lt;/s&gt;</p><h3>To find</h3><p>Most probable next token for each prefix.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bd18c85b739d1cb7.svg\" alt=\"P(w\\mid h)=\\frac{c(h,w)}{\\sum_v c(h,v)}\" style=\"width:22.157ex;height:5.573ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Retain case exactly; include sentence-end as an observed next token. Bigram prediction uses only the last token of the prefix.</p><h3>Step 1. Count each adjacent pair separately within sentences</h3><div class=\"table-wrap\"><table><thead><tr><th>Bigram</th><th>Count</th></tr></thead><tbody><tr><td>&lt;s&gt; → Do</td><td>3</td></tr><tr><td>&lt;s&gt; → Henry</td><td>1</td></tr><tr><td>&lt;s&gt; → I</td><td>3</td></tr><tr><td>Do → Henry</td><td>1</td></tr><tr><td>Do → I</td><td>2</td></tr><tr><td>Henry → &lt;/s&gt;</td><td>3</td></tr><tr><td>Henry → I</td><td>1</td></tr><tr><td>Henry → like</td><td>1</td></tr><tr><td>I → am</td><td>2</td></tr><tr><td>I → do</td><td>1</td></tr><tr><td>I → like</td><td>3</td></tr><tr><td>am → &lt;/s&gt;</td><td>1</td></tr><tr><td>am → Henry</td><td>1</td></tr><tr><td>college → &lt;/s&gt;</td><td>3</td></tr><tr><td>do → like</td><td>1</td></tr><tr><td>like → Henry</td><td>2</td></tr><tr><td>like → college</td><td>3</td></tr></tbody></table></div><h3>Step 2. Continue &lt;s&gt; Do</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate</th><th>Count / history count</th><th>Probability</th></tr></thead><tbody><tr><td>Henry</td><td>1/3</td><td>0.333333</td></tr><tr><td>I</td><td>2/3</td><td>0.666667</td></tr></tbody></table></div><p>Highest: I. </p><h3>Step 3. Continue &lt;s&gt; I like</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate</th><th>Count / history count</th><th>Probability</th></tr></thead><tbody><tr><td>Henry</td><td>2/5</td><td>0.400000</td></tr><tr><td>college</td><td>3/5</td><td>0.600000</td></tr></tbody></table></div><p>Highest: college. </p><h3>Step 4. Continue &lt;s&gt; I</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate</th><th>Count / history count</th><th>Probability</th></tr></thead><tbody><tr><td>am</td><td>2/6</td><td>0.333333</td></tr><tr><td>do</td><td>1/6</td><td>0.166667</td></tr><tr><td>like</td><td>3/6</td><td>0.500000</td></tr></tbody></table></div><p>Highest: like. </p><h3>Final answer</h3><p>&lt;s&gt; Do → I<br>&lt;s&gt; I like → college<br>&lt;s&gt; I → like</p><p>If an examiner explicitly restricts the answer to a lexical word, exclude END and state that restricted candidate set. Do not silently remove an END tie.</p><p><strong>Source / convention note.</strong> Case is retained as printed: Do and do are distinct. The corpus is not silently grammatically corrected.</p>","m2":false,"units":"3","marks":10,"sourcePages":[4],"historical":true},{"id":"q6b","title":"Q6b · Five linguistic levels","html":"<div class=\"question\"><strong>Question. Explain the contribution of phonology, morphology, syntax, semantics and pragmatics to language understanding.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>A phoneme</strong> is a sound unit that can distinguish meanings in a language, such as the /p/ and /b/ contrast in “pat” and “bat”. A phoneme is a sound, not necessarily one alphabet letter. <strong>A morpheme</strong> is the smallest meaning-bearing grammatical unit: cats = cat + plural -s; unhappy = un- + happy.</p><p><strong>A lexeme</strong> is an abstract vocabulary item grouping its inflected forms: write, writes, wrote and writing belong to WRITE. A <strong>phrase</strong> is a group of words functioning together; a <strong>clause</strong> normally contains a predicate and its associated participants; a <strong>sentence</strong> expresses a complete grammatical unit.</p><table><thead><tr><th>Level</th><th>What it analyses</th><th>Concrete example</th></tr></thead><tbody><tr><td>Phonetics / phonology</td><td>Physical sounds / sound patterns in a language</td><td>Distinguish bat from pat</td></tr><tr><td>Morphology / lexical analysis</td><td>Word structure and lexical items</td><td>un + help + ful → unhelpful</td></tr><tr><td>Syntax</td><td>Grammatical arrangement and relationships</td><td>The dog chased the cat: subject, verb, object</td></tr><tr><td>Semantics</td><td>Meaning of words and composed expressions</td><td>The dog is the chaser; the cat is chased</td></tr><tr><td>Discourse</td><td>Connections across sentences</td><td>“Riya arrived. She smiled.” → She refers to Riya</td></tr><tr><td>Pragmatics</td><td>Intended meaning in the situation</td><td>“It is cold here” may request closing the window</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">word forms</div><span aria-hidden=\"true\">→</span><div class=\"node\">grammatical structure</div><span aria-hidden=\"true\">→</span><div class=\"node\">sentence meaning</div><span aria-hidden=\"true\">→</span><div class=\"node\">cross-sentence context</div><span aria-hidden=\"true\">→</span><div class=\"node\">speaker intention</div></div><h3>Three worked interpretations</h3><p><strong>“The cats are sleeping.”</strong> Morphology identifies cat + s as plural. Syntax connects “cats” to “are sleeping”. Semantics represents animals engaged in sleeping.</p><p><strong>“Aman bought a laptop. It was expensive.”</strong> Sentence-level syntax alone does not identify “it”. Discourse connects “it” to the laptop across the sentence boundary.</p><p><strong>“Wonderful, another power cut!”</strong> The word wonderful is positive literally, but situational context can indicate sarcasm and frustration. This is a pragmatic interpretation.</p><p>The analysis levels are conceptual descriptions. Modern systems may learn several jointly rather than executing a compulsory separate module for every level.</p><p class=\"cue\">Morphology = word ke andar; syntax = sentence ka structure; semantics = meaning; discourse = sentences ka link; pragmatics = intention.</p>","m2":false,"units":"1","marks":5,"sourcePages":[4],"historical":true},{"id":"q6c","title":"Q6c · NLU and NLG working together","html":"<div class=\"question\"><strong>Question. Explain how NLU and NLG work together for meaningful human–machine communication.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Natural language understanding (NLU)</strong> maps language into an interpretation useful for a task: intents, entities, semantic relations or another meaning representation. <strong>Natural language generation (NLG)</strong> produces human-language output from data, a representation or another source.</p><div class=\"flow\"><div class=\"node\">“Book a ticket to Pune tomorrow.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">NLU: intent=book; destination=Pune; date=tomorrow</div><span aria-hidden=\"true\">→</span><div class=\"node\">Application: search available journeys</div><span aria-hidden=\"true\">→</span><div class=\"node\">NLG: “Here are the available journeys to Pune.”</div></div><table><thead><tr><th>Feature</th><th>NLU</th><th>NLG</th></tr></thead><tbody><tr><td>Direction</td><td>Language → interpretation</td><td>Data/representation → language</td></tr><tr><td>Main concern</td><td>Meaning, intent, ambiguity</td><td>Content choice, organization, fluent wording</td></tr><tr><td>Example</td><td>Find destination in a request</td><td>Write the booking confirmation</td></tr><tr><td>Common failure</td><td>Wrong destination or sense</td><td>Unclear, unsupported or ungrammatical output</td></tr></tbody></table><h3>NLG stages in a classical pipeline</h3><ol><li><strong>Content determination:</strong> choose facts to communicate.</li><li><strong>Data interpretation:</strong> identify relationships or trends.</li><li><strong>Document planning:</strong> organize facts in a useful order.</li><li><strong>Sentence aggregation:</strong> combine related facts without repetition.</li><li><strong>Lexical and grammatical realization:</strong> choose words and construct grammatical sentences.</li><li><strong>Presentation:</strong> format the generated message for its audience.</li></ol><p>For a weather report, facts {city=Pune, temperature=28°C, rain=yes} can become “Pune will have rain with a temperature of 28°C.” NLU would instead extract facts or intent from an incoming language message.</p><p class=\"cue\">NLU = language se meaning andar. NLG = data se language bahar.</p>","m2":false,"units":"1","marks":5,"sourcePages":[4],"historical":true},{"id":"q7a","title":"Q7a · POS, chunks and boundary-aware HMM","html":"<div class=\"question\"><strong>Question. Define function/content words, chunking/chinking and POS applications. Construct transition and emission tables including start/end for: Book/Verb a/Det flight/Noun; Read/Verb the/Det book/Noun; The/Det book/Noun is/Modal-Verb green/Noun.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Part-of-speech (POS) tagging</strong> assigns a grammatical category to every word token in context, such as noun, verb, adjective or determiner. It is a sequence-labeling task: the input is a sequence of words, and the output is a tag for each word. A tag describes the word's role in this sentence, not its meaning in every possible sentence.</p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Role</th><th>Example in context</th></tr></thead><tbody><tr><td>NN / NNS</td><td>Singular / plural common noun</td><td>a book / two books</td></tr><tr><td>NNP</td><td>Proper noun</td><td>Mary, Mumbai</td></tr><tr><td>VB / VBD / VBZ</td><td>Base / past / third-person singular verb</td><td>read / read / reads</td></tr><tr><td>JJ</td><td>Adjective</td><td>the red book</td></tr><tr><td>RB</td><td>Adverb</td><td>runs quickly</td></tr><tr><td>DT</td><td>Determiner</td><td>the, a, this</td></tr><tr><td>IN</td><td>Preposition or subordinating conjunction</td><td>on the table</td></tr><tr><td>PRP</td><td>Personal pronoun</td><td>she, they</td></tr><tr><td>MD</td><td>Modal auxiliary</td><td>can, will, should</td></tr></tbody></table></div><p><strong>Open classes</strong> readily accept new content words: nouns, verbs, adjectives and adverbs. Examples include chatbot and livestream. <strong>Closed classes</strong> contain comparatively stable grammatical/function words: determiners, pronouns, prepositions and conjunctions. These are tendencies, not a claim that language never changes.</p><div class=\"flow\"><div class=\"node\">Input: Book that flight</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context: an imperative request</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Output: Book/VB that/DT flight/NN</div></div><p>Compare “hand me that <strong>book</strong>”: book is a noun here. Similarly, “I <strong>can</strong> swim” has can/MD, while “the <strong>can</strong> is empty” has can/NN. The spelling stays the same; neighboring words and sentence structure change the correct tag. This is <strong>POS ambiguity</strong>.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged interpretation</th><th>Reason</th></tr></thead><tbody><tr><td>They watch birds.</td><td>They/PRP watch/VBP birds/NNS</td><td>watch is the action.</td></tr><tr><td>The watch stopped.</td><td>The/DT watch/NN stopped/VBD</td><td>watch is the object that stopped.</td></tr><tr><td>She has a light bag.</td><td>She/PRP has/VBZ a/DT light/JJ bag/NN</td><td>light describes bag.</td></tr><tr><td>Light the lamp.</td><td>Light/VB the/DT lamp/NN</td><td>Light is an imperative verb.</td></tr></tbody></table></div><p>POS tags support parsing, named entity recognition, question answering, sentiment analysis and word-sense disambiguation. They do not by themselves identify every entity or fully resolve meaning.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka naam same ho sakta hai; sentence mein uska kaam tag decide karta hai.</p><p><strong>Chunking</strong>, also called shallow parsing, groups adjacent tagged words into meaningful non-overlapping units, commonly noun phrases. It usually identifies local phrase boundaries without producing the complete hierarchical structure of a sentence. <strong>Chinking</strong> removes specified tokens from an existing candidate chunk, splitting or trimming it.</p><div class=\"flow\"><div class=\"node\">The/DT small/JJ cat/NN sat/VBD on/IN the/DT mat/NN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [The small cat]</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Outside: sat on</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [the mat]</div></div><p>A POS tagger labels individual words. A chunker groups words into phrases. A full parser shows how phrases relate recursively to form the entire sentence. These are related tasks with different outputs.</p><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>POS tagging</td><td>The small cat</td><td>The/DT small/JJ cat/NN</td></tr><tr><td>NP chunking</td><td>Tagged tokens</td><td>[NP The small cat]</td></tr><tr><td>Chinking</td><td>A broad candidate chunk</td><td>Remove verbs/prepositions, keep noun-phrase segments</td></tr><tr><td>Full parsing</td><td>Sentence + grammar</td><td>A nested tree with sentence, noun phrase and verb phrase nodes</td></tr></tbody></table></div><p><strong>Rule-based chunking</strong> uses tag patterns. Statistical or learned chunkers infer boundaries from labeled examples. A useful NP rule is an optional determiner, followed by zero or more adjectives, followed by a noun. In NLTK-style notation: <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;}</code>. Here ? means zero or one occurrence; * means zero or more; + means one or more when used. The braces mean “form a chunk around the matched sequence”.</p><section class=\"example\"><p class=\"question\"><strong>Question. Apply the NP rule optional DT, zero or more JJ, then one NN to “The/DT quick/JJ brown/JJ fox/NN jumps/VBZ over/IN the/DT lazy/JJ dog/NN”.</strong></p><div class=\"given\"><h4>Given</h4><p>Tagged input is supplied. Rule: DT? JJ* NN.</p><h4>To find</h4><p>All noun-phrase chunks.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The rule groups a noun with its preceding determiner and adjectives; a verb or preposition does not match this NP pattern.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start at The</h5><p>The matches optional DT; quick and brown both match JJ*; fox matches NN.</p></div><div class=\"step\"><h5>Step 2. Form the first NP</h5><p><strong>[NP The quick brown fox]</strong></p></div><div class=\"step\"><h5>Step 3. Skip nonmatching tokens</h5><p>jumps/VBZ and over/IN do not satisfy the NP pattern.</p></div><div class=\"step\"><h5>Step 4. Match the second NP</h5><p>the is DT, lazy is JJ, dog is NN: <strong>[NP the lazy dog]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> [NP The quick brown fox] jumps over [NP the lazy dog].</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using NP → DT? JJ* NN, identify the chunks in “bright/JJ stars/NN shine/VBP and/CC a/DT moon/NN glows/VBZ”. Use the supplied tags exactly.</strong></p><div class=\"given\"><h4>Given</h4><p>Input tags label stars as NN for this exercise. Rule requires optional DT, zero or more JJ, then NN.</p><h4>To find</h4><p>The matched NP spans.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The optional determiner may be absent and the adjective repetition may be empty.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Match bright stars</h5><p>No determiner is present, which DT? permits. bright matches JJ; stars matches NN.</p></div><div class=\"step\"><h5>Step 2. Inspect shine and and</h5><p>VBP and CC fall outside the NP rule.</p></div><div class=\"step\"><h5>Step 3. Match a moon</h5><p>a matches DT; no adjective is present; moon matches NN.</p></div><div class=\"answer\"><strong>Final answer.</strong> Chunks are [NP bright stars] and [NP a moon]. With ordinary Penn tagging, stars is usually NNS; broaden the noun pattern to include NNS when that tag is used.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Begin with one candidate chunk containing “The/DT cat/NN sat/VBD on/IN the/DT mat/NN”. Chink out verbs and prepositions. Show the remaining chunks.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial candidate: [The cat sat on the mat]. Remove tags VBD and IN.</p><h4>To find</h4><p>The chunk segments after exclusion.</p></div><h4>Formula and why it applies</h4><p>Chinking removes matched tokens from the existing chunk.</p><p>Removing the middle verb/preposition region divides the original candidate into two remaining contiguous spans.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the tokens to remove</h5><p>sat is VBD and on is IN.</p></div><div class=\"step\"><h5>Step 2. Remove those tokens from chunk membership</h5><p>The remaining token groups are “The cat” and “the mat”. sat and on still exist in the sentence; they are simply outside these chunks.</p></div><div class=\"step\"><h5>Step 3. Write the final chunked sentence</h5><p><strong>[The cat]</strong> sat on <strong>[the mat]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> Two chunks remain: The cat; the mat.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Chunking = andar group karo; chinking = unwanted tokens ko group se bahar karo.</p></section><h3>Exact HMM table</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Supplied tags</th></tr></thead><tbody><tr><td>Book a flight</td><td>Verb Det Noun</td></tr><tr><td>Read the book</td><td>Verb Det Noun</td></tr><tr><td>The book is green</td><td>Det Noun Modal-Verb Noun</td></tr></tbody></table></div><h3>To find</h3><p>Transition and emission probability tables including START and END.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/204793f5263e1ae9.svg\" alt=\"a_{ij}=\\frac{c(t_i,t_j)}{c(t_i)},\\qquad b_i(w)=\\frac{c(t_i,w)}{c(t_i)}\" style=\"width:35.13ex;height:5.575ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>For START divide by sentence count. END has no outgoing or emission distribution. Keep the supplied tags even when their linguistic choice is unusual, and retain case-sensitive Book/book and The/the as printed.</p><h3>Step 1. Add boundary tags to every sentence</h3><p>START Verb Det Noun END<br>START Verb Det Noun END<br>START Det Noun Modal-Verb Noun END</p><h3>Step 2. Count transitions</h3><div class=\"table-wrap\"><table><thead><tr><th>From → to</th><th>Count</th></tr></thead><tbody><tr><td>START → Verb</td><td>2</td></tr><tr><td>Verb → Det</td><td>2</td></tr><tr><td>Det → Noun</td><td>3</td></tr><tr><td>Noun → END</td><td>3</td></tr><tr><td>START → Det</td><td>1</td></tr><tr><td>Noun → Modal-Verb</td><td>1</td></tr><tr><td>Modal-Verb → Noun</td><td>1</td></tr></tbody></table></div><h3>Step 3. Divide by each source tag count</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Denominator</th><th>Verb</th><th>Det</th><th>Noun</th><th>Modal-Verb</th><th>END</th></tr></thead><tbody><tr><td>START</td><td>3</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>2</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>3</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>4</td><td>0</td><td>0</td><td>0</td><td>1/4</td><td>3/4</td></tr><tr><td>Modal-Verb</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 4. Count and normalize emissions</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Count</th><th>Book</th><th>a</th><th>flight</th><th>Read</th><th>the</th><th>book</th><th>The</th><th>is</th><th>green</th></tr></thead><tbody><tr><td>Verb</td><td>2</td><td>1/2</td><td>0</td><td>0</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>3</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>4</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>0</td><td>1/2</td><td>0</td><td>0</td><td>1/4</td></tr><tr><td>Modal-Verb</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div><h3>Final answer</h3><p>Every nonterminal transition row sums to1 when END is included; every emission row sums to1. Boundary symbols do not emit lexical words.</p><p>POS applications include syntax parsing, disambiguation, lemmatization, chunking and extraction. For this numerical retain printed green=Noun and is=Modal-Verb even though ordinary linguistic tagging would differ; the task is estimation from supplied labels.</p><p><strong>Source / convention note.</strong> Printed tags are used as training data; START and END are explicitly required and included.</p>","m2":false,"units":"4","marks":10,"sourcePages":[5],"historical":true},{"id":"q7b","title":"Q7b · Co-occurrence, dot products and plot","html":"<div class=\"question\"><strong>Question. Define target words, context window, context words and co-occurrence matrix. For the printed boy/ball/dog/sun corpus below, use one whole sentence as the window; contexts={kicked,field,tree,ran}. Find boy·dog and boy·sun, plot on kicked/field dimensions and comment.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Target</strong> is the word whose row we represent. <strong>Context</strong> is an observed neighbouring word whose column we count. A <strong>window</strong> defines which tokens count as neighbours; here all other tokens in the same sentence. A <strong>co-occurrence matrix</strong> records those counts.</p><h3>Given</h3><p>The boy kicked the ball into the field. The dog barked at the boy. The sun was shining over the field. The boy ran after the dog. The ball rolled to the tree.</p><h3>To find</h3><p>Matrix, two dot products and the requested 2D coordinates.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/57c675782454b924.svg\" alt=\"u\\cdot v=\\sum_i u_iv_i\" style=\"width:14.558ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use lowercase token-pair counts within each sentence; do not cross sentence boundaries.</p><h3>Step 1. List contributions and build the matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Target occurrences</th><th>Context occurrences</th></tr></thead><tbody><tr><td>1</td><td>boy, ball</td><td>kicked, field</td></tr><tr><td>2</td><td>dog, boy</td><td></td></tr><tr><td>3</td><td>sun</td><td>field</td></tr><tr><td>4</td><td>boy, dog</td><td>ran</td></tr><tr><td>5</td><td>ball</td><td>tree</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Target / context</th><th>kicked</th><th>field</th><th>tree</th><th>ran</th></tr></thead><tbody><tr><td>boy</td><td>1</td><td>1</td><td>0</td><td>1</td></tr><tr><td>ball</td><td>1</td><td>1</td><td>1</td><td>0</td></tr><tr><td>dog</td><td>0</td><td>0</td><td>0</td><td>1</td></tr><tr><td>sun</td><td>0</td><td>1</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 2. Dot boy and dog</h3><p>[1, 1, 0, 1] · [0, 0, 0, 1] = 1×0 + 1×0 + 0×0 + 1×1 = 1</p><h3>Step 3. Dot boy and sun</h3><p>[1, 1, 0, 1] · [0, 1, 0, 0] = 1×0 + 1×1 + 0×0 + 1×0 = 1</p><h3>Step 4. Plot coordinates: kicked on x, field on y</h3><div class=\"table-wrap\"><table><thead><tr><th>Target</th><th>(x,y)</th></tr></thead><tbody><tr><td>boy</td><td>(1, 1)</td></tr><tr><td>ball</td><td>(1, 1)</td></tr><tr><td>dog</td><td>(0, 0)</td></tr><tr><td>sun</td><td>(0, 1)</td></tr></tbody></table></div><figure><svg viewBox=\"0 0 440 300\" role=\"img\" aria-label=\"Co-occurrence plot: dog at zero zero, sun at zero one, boy and ball at one one\"><path d=\"M70 30V240H400\" fill=\"none\" stroke=\"#234d43\"/><text x=\"365\" y=\"270\">kicked</text><text x=\"10\" y=\"28\">field</text><circle cx=\"70\" cy=\"240\" r=\"6\" fill=\"#275c50\"/><text x=\"82\" y=\"232\">dog (0,0)</text><circle cx=\"70\" cy=\"80\" r=\"6\" fill=\"#275c50\"/><text x=\"82\" y=\"70\">sun (0,1)</text><circle cx=\"280\" cy=\"80\" r=\"6\" fill=\"#275c50\"/><text x=\"225\" y=\"60\">boy, ball (1,1)</text></svg><figcaption>Two coordinates omit tree and ran, so boy and ball overlap here despite different full vectors.</figcaption></figure><h3>Final answer</h3><p><strong>boy·dog=1; boy·sun=1.</strong> Both share one counted context contribution. Dot-product similarity reflects this corpus and magnitude, not a claim that boy is equally semantically related to dog and sun in general.</p>","m2":false,"units":"5","marks":10,"sourcePages":[5],"historical":true}]},{"id":"legacy-r24","title":"2024-02-12 · re-exam · recovered AI paper","unit":"PYQ","scope":"Previous examination · complete worked answers","sections":[{"id":"q1a","title":"Q1a · Anaphora versus cataphora","html":"<div class=\"question\"><strong>Question. Compare anaphoric and cataphoric reference with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Pragmatic analysis</strong> interprets an utterance using its situation and the speaker’s intended meaning. <strong>Discourse analysis</strong> studies how utterances connect across a text or conversation. Syntax and literal word meanings alone cannot settle every interpretation.</p><table><thead><tr><th>Text</th><th>Literal content</th><th>Contextual interpretation</th></tr></thead><tbody><tr><td>“Can you close the window?”</td><td>A question about ability.</td><td>Usually a polite request.</td></tr><tr><td>“Meera bought a laptop. It was expensive.”</td><td>Two sentences.</td><td>“It” connects the second sentence to the laptop.</td></tr><tr><td>“Meet me here tomorrow.”</td><td>An instruction.</td><td>Me, here and tomorrow depend on speaker, place and date.</td></tr></tbody></table><h3>Reference, mention and antecedent</h3><p>A <strong>referring expression</strong> points to an entity; a <strong>mention</strong> is its occurrence in the text. Its <strong>referent</strong> is the entity being discussed. An <strong>antecedent</strong> is a preceding expression used to interpret a later referring expression. Reference resolution identifies the intended referent. Coreference resolution groups mentions that refer to the same entity.</p><div class=\"flow\"><div class=\"node\">“Meera”<small>name mention</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Person entity<small>same referent</small></div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">“she” / “the engineer”<small>other mentions</small></div></div><table><thead><tr><th>Concept</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Anaphora</td><td>Reference back to something introduced earlier.</td><td>“Riya arrived. She sat down.” She → Riya.</td></tr><tr><td>Cataphora</td><td>Reference forward to a later expression.</td><td>“Before she spoke, Riya checked the microphone.” she → Riya.</td></tr><tr><td>Exophora</td><td>Reference to the situation outside the text.</td><td>“Put it there”, said while pointing.</td></tr><tr><td>Coreference</td><td>Two or more mentions refer to the same entity.</td><td>“Dr Rao”, “the lecturer”, “she”.</td></tr><tr><td>Pronoun resolution</td><td>Find the referent of a pronoun.</td><td>Resolve “it” in “The laptop stopped because it overheated.”</td></tr></tbody></table><p>Coreference is broader than pronoun resolution: repeated names and descriptions also form a chain. Anaphora describes direction/dependence; coreference describes identity. In “I bought a car. The engine is noisy”, engine is related to the car but is not the same entity.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Reference = kiski baat? Coreference = alag mentions, same entity. Pronoun resolution = he/she/it kis se linked?</p><h3>Cohesion, coherence and discourse markers</h3>\n<p><strong>Cohesion</strong> is the explicit linguistic linking of a text through reference, repeated or related words, conjunctions and other devices. In “Rita bought a book. She read it”, she and it connect the second sentence to Rita and the book.</p>\n<p><strong>Coherence</strong> is the conceptual unity that makes a discourse meaningful. “The road flooded, so the match was cancelled” presents a plausible cause and consequence. A reader relates the propositions using context and knowledge.</p>\n<p><strong>Discourse markers</strong> signal relationships or organize speech: however signals contrast; therefore signals a result; first and next signal sequence; for example introduces an illustration.</p>\n<p>These concepts differ: “I like apples. Therefore the moon is square” has a linking word but no sensible inference. A connector alone does not guarantee coherence.</p>\n<p><strong>Yaad rakho:</strong> Cohesion = words se link; coherence = meaning se link; marker = relation ka signal.</p>","m2":false,"units":"6","marks":5,"sourcePages":[1],"historical":true},{"id":"q1b","title":"Q1b · Five corpora","html":"<div class=\"question\"><strong>Question. Define corpora and discuss any five corpora used in NLP.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>A corpus is a collection of language data assembled for study or computational use.</strong> Its plural is corpora. A corpus can contain books, news, reviews or conversations. It need not be labelled. <strong>Annotation</strong> adds linguistic information such as POS tags, entities, parse structures or sense labels.</p><table><thead><tr><th>Structure</th><th>Meaning</th><th>Use</th></tr></thead><tbody><tr><td>Plain</td><td>Collection without category labels</td><td>Word counts, language modelling</td></tr><tr><td>Categorized</td><td>Documents grouped by genre/topic</td><td>Classification</td></tr><tr><td>Overlapping categories</td><td>One document has several categories</td><td>Multi-topic news</td></tr><tr><td>Temporal</td><td>Documents indexed by time</td><td>Language change</td></tr><tr><td>Annotated</td><td>Linguistic labels attached</td><td>Tagging, parsing, WSD</td></tr><tr><td>Parallel</td><td>Aligned texts in different languages</td><td>Translation</td></tr></tbody></table><p>A <strong>tagset</strong> is the allowed label inventory. A <strong>treebank</strong> is a corpus annotated with syntax trees. <strong>Metadata</strong> records source, date, genre, language, annotation method and limitations. A common benchmark supports comparison under shared data and evaluation conditions.</p><p><strong>Raw example:</strong> “Riya works in Pune.” <strong>POS annotation:</strong> Riya/PROPN works/VERB in/ADP Pune/PROPN. <strong>NER annotation:</strong> Riya/PERSON, Pune/LOCATION. Each annotation answers a different task.</p><p>A good corpus is relevant to its domain, sufficiently representative, consistently annotated and appropriately split. More data alone do not repair duplicated examples, incorrect labels or a mismatch between training and real use.</p><p class=\"cue\">Corpus=text collection. Annotation=text ke saath labels. Metadata=collection ki information.</p><table><thead><tr><th>Resource</th><th>Contents</th><th>Typical use</th></tr></thead><tbody><tr><td>Gutenberg selection</td><td>Literary/book texts</td><td>Long-form language and vocabulary</td></tr><tr><td>Web text</td><td>Informal domain-specific text</td><td>Study usage beyond edited books</td></tr><tr><td>Chat corpus</td><td>Conversational posts</td><td>Dialogue, informal forms</td></tr><tr><td>Brown</td><td>English texts across genres</td><td>Genre comparison</td></tr><tr><td>Reuters</td><td>News with topic labels</td><td>Text classification; overlapping topics</td></tr><tr><td>Inaugural</td><td>Speeches indexed by time</td><td>Vocabulary change across years</td></tr><tr><td>Wordlist</td><td>Words/names/stopwords</td><td>Lexical filtering</td></tr><tr><td>Pronouncing dictionary</td><td>Words and phonetic forms</td><td>Speech, stress, rhyme</td></tr></tbody></table><p><strong>Gutenberg versus web/chat:</strong> book language does not represent every spelling or conversational pattern in messages. <strong>Brown versus Reuters:</strong> Brown emphasizes genres; Reuters news can have overlapping topic labels. <strong>Inaugural addresses:</strong> dates provide a time dimension.</p><p>Corpus sizes depend on version, subset and tokenization. Explain their purpose and structure rather than assuming a historical count is a permanent property.</p><p class=\"cue\">Gutenberg=books; web/chat=informal; Brown=genres; Reuters=news topics; Inaugural=time.</p>","m2":false,"units":"3","marks":5,"sourcePages":[1],"historical":true},{"id":"q1c","title":"Q1c · Linguistic foundations","html":"<div class=\"question\"><strong>Question. Define linguistic foundation and explain its importance in NLP.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>A phoneme</strong> is a sound unit that can distinguish meanings in a language, such as the /p/ and /b/ contrast in “pat” and “bat”. A phoneme is a sound, not necessarily one alphabet letter. <strong>A morpheme</strong> is the smallest meaning-bearing grammatical unit: cats = cat + plural -s; unhappy = un- + happy.</p><p><strong>A lexeme</strong> is an abstract vocabulary item grouping its inflected forms: write, writes, wrote and writing belong to WRITE. A <strong>phrase</strong> is a group of words functioning together; a <strong>clause</strong> normally contains a predicate and its associated participants; a <strong>sentence</strong> expresses a complete grammatical unit.</p><table><thead><tr><th>Level</th><th>What it analyses</th><th>Concrete example</th></tr></thead><tbody><tr><td>Phonetics / phonology</td><td>Physical sounds / sound patterns in a language</td><td>Distinguish bat from pat</td></tr><tr><td>Morphology / lexical analysis</td><td>Word structure and lexical items</td><td>un + help + ful → unhelpful</td></tr><tr><td>Syntax</td><td>Grammatical arrangement and relationships</td><td>The dog chased the cat: subject, verb, object</td></tr><tr><td>Semantics</td><td>Meaning of words and composed expressions</td><td>The dog is the chaser; the cat is chased</td></tr><tr><td>Discourse</td><td>Connections across sentences</td><td>“Riya arrived. She smiled.” → She refers to Riya</td></tr><tr><td>Pragmatics</td><td>Intended meaning in the situation</td><td>“It is cold here” may request closing the window</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">word forms</div><span aria-hidden=\"true\">→</span><div class=\"node\">grammatical structure</div><span aria-hidden=\"true\">→</span><div class=\"node\">sentence meaning</div><span aria-hidden=\"true\">→</span><div class=\"node\">cross-sentence context</div><span aria-hidden=\"true\">→</span><div class=\"node\">speaker intention</div></div><h3>Three worked interpretations</h3><p><strong>“The cats are sleeping.”</strong> Morphology identifies cat + s as plural. Syntax connects “cats” to “are sleeping”. Semantics represents animals engaged in sleeping.</p><p><strong>“Aman bought a laptop. It was expensive.”</strong> Sentence-level syntax alone does not identify “it”. Discourse connects “it” to the laptop across the sentence boundary.</p><p><strong>“Wonderful, another power cut!”</strong> The word wonderful is positive literally, but situational context can indicate sarcasm and frustration. This is a pragmatic interpretation.</p><p>The analysis levels are conceptual descriptions. Modern systems may learn several jointly rather than executing a compulsory separate module for every level.</p><p class=\"cue\">Morphology = word ke andar; syntax = sentence ka structure; semantics = meaning; discourse = sentences ka link; pragmatics = intention.</p>","m2":false,"units":"1","marks":5,"sourcePages":[1],"historical":true},{"id":"q1d","title":"Q1d · Five regex operators","html":"<div class=\"question\"><strong>Question. For word-pattern detection, explain: ^abc, abc$, [A-Z0-9], ed|ing|s, [abc].</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Pattern</th><th>Exact meaning</th><th>Positive example</th><th>Important distinction</th></tr></thead><tbody><tr><td>^abc</td><td>abc at start of the input/line under chosen mode</td><td>abcdef</td><td>Not abc anywhere</td></tr><tr><td>abc$</td><td>abc at end</td><td>xxabc</td><td>Not starts with abc</td></tr><tr><td>[A-Z0-9]</td><td>One uppercase ASCII letter or digit</td><td>Q or 7</td><td>One character, not the whole string</td></tr><tr><td>ed|ing|s</td><td>One of the alternatives ed, ing or s</td><td>matched ed</td><td>Without anchors this is not necessarily a suffix</td></tr><tr><td>[abc]</td><td>One a, b or c</td><td>b</td><td>Not the three-character string abc</td></tr></tbody></table></div><p>Use full-string matching when the entire string must satisfy a pattern; a search may find only a substring.</p>","m2":false,"units":"3","marks":5,"sourcePages":[1],"historical":true},{"id":"q2a","title":"Q2a · Wordlist puzzle and lexical resource","html":"<div class=\"question\"><strong>Question. Explain lexical resources. Solve the wordlist puzzle with letters E,G,I / V,R,V / O,N,L. Words must have at least four letters, contain centre R, use each tile at most once, and include at least one nine-letter word.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th></th><th>Column1</th><th>Column2</th><th>Column3</th></tr></thead><tbody><tr><td>Row1</td><td>E</td><td>G</td><td>I</td></tr><tr><td>Row2</td><td>V</td><td>R</td><td>V</td></tr><tr><td>Row3</td><td>O</td><td>N</td><td>L</td></tr></tbody></table></div><h3>To find</h3><p>Find valid words and explain how a wordlist corpus supplies the candidates.</p><h3>Formula: which one and why</h3><p>A lexical resource stores words and linguistic information. Filter an explicitly chosen dictionary by length, mandatory letter and a multiset of tile counts; duplicate V tiles permit two Vs.</p><h3>Step 1. Count available tiles</h3><p>E1,G1,I1,V2,R1,O1,N1,L1.</p><h3>Step 2. Apply all predicates</h3><p>For each lowercase dictionary word w: length(w)≥4; r occurs; for every letter c, count_w(c)≤count_tiles(c). Deduplicate dictionary entries.</p><h3>Step 3. Verify examples</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Reason</th></tr></thead><tbody><tr><td>revolving</td><td>9 letters: r e v o l v i n g; uses both V tiles and all others once</td></tr><tr><td>roving</td><td>6 letters, includes R, within tile counts</td></tr><tr><td>lover</td><td>5 letters, includes R</td></tr><tr><td>giver</td><td>5 letters, includes R</td></tr><tr><td>groin</td><td>5 letters, includes R</td></tr><tr><td>iron</td><td>4 letters, includes R</td></tr><tr><td>ring</td><td>4 letters, includes R</td></tr><tr><td>rove</td><td>4 letters, includes R</td></tr></tbody></table></div><h3>Step 4. Explain the requested count</h3><p>The count is the number of entries surviving those checks in the chosen wordlist. No wordlist/version is supplied, so a unique total cannot be stated. The examples above are verified examples, not an exhaustive dictionary.</p><h3>Final answer</h3><p><strong>REVOLVING</strong> is a valid nine-letter answer. Enumerate all other valid entries using the declared wordlist.</p><p><strong>Source / convention note.</strong> The dictionary is unspecified; an exact number of valid words would be fabricated.</p>","m2":false,"units":"3","marks":10,"sourcePages":[1,2],"historical":true},{"id":"q2b","title":"Q2b · NLP applications and limitations","html":"<div class=\"question\"><strong>Question. List NLP applications and explain limitations of NLP.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Natural language processing (NLP) is the field concerned with computational methods for analysing, interpreting and generating human language.</strong> Natural languages such as English, Hindi and Marathi evolved through human use; their meanings are not specified by the rigid rules of a programming language.</p><p>An NLP system may receive text, speech converted to text, or another linguistic representation. Its output depends on the task: a category, a tag for every word, a translated sentence, a ranked document list or a generated answer. It does not always “understand” in the human sense; its performance must be evaluated for the specific task.</p><table><thead><tr><th>Task</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>Sentiment analysis</td><td>“The service was excellent.”</td><td>Positive sentiment</td></tr><tr><td>Text classification</td><td>An email</td><td>Spam / not spam</td></tr><tr><td>POS tagging</td><td>“Birds fly.”</td><td>Birds/NOUN fly/VERB</td></tr><tr><td>Named entity recognition</td><td>“Asha joined Google in Mumbai.”</td><td>Asha: person; Google: organisation; Mumbai: location</td></tr><tr><td>Machine translation</td><td>A Hindi sentence</td><td>A corresponding English sentence</td></tr><tr><td>Information retrieval</td><td>A search query</td><td>Ranked relevant documents</td></tr><tr><td>Question answering</td><td>Question plus knowledge/context</td><td>An answer</td></tr><tr><td>Summarization</td><td>A long article</td><td>A shorter text preserving key information</td></tr></tbody></table><h3>How NLP relates to AI, ML and DL</h3><p><strong>AI</strong> is the broader study of systems performing tasks associated with intelligent behaviour. <strong>Machine learning</strong> learns patterns from data. <strong>Deep learning</strong> uses multiple trainable neural layers. NLP is an application/research field that can use hand-written rules, statistical ML or deep learning. Therefore, not every NLP system is a neural network.</p><p>Linguistics supplies knowledge about language structure. Statistics supplies uncertainty models. Computer science supplies algorithms, storage and efficient implementation. A practical NLP system combines these ideas.</p><p class=\"cue\">NLP = human language ko computational task mein badlo: label, meaning, search ya generated sentence.</p><p><strong>Ambiguity</strong> means an expression supports more than one interpretation. Good exam answers name the ambiguity and explain both readings.</p><table><thead><tr><th>Challenge</th><th>Example</th><th>Why a system can fail</th></tr></thead><tbody><tr><td>Lexical/sense ambiguity</td><td>bank: finance or river edge</td><td>One written word has several senses</td></tr><tr><td>Syntactic ambiguity</td><td>I saw the man with a telescope.</td><td>The telescope may modify saw or the man</td></tr><tr><td>Reference ambiguity</td><td>Riya told Neha that she won.</td><td>She may refer to either person without more context</td></tr><tr><td>Sarcasm</td><td>Great, another delay.</td><td>Literal positive word conveys frustration</td></tr><tr><td>Negation</td><td>The film was not good.</td><td>Dropping not reverses meaning</td></tr><tr><td>Domain shift</td><td>“Positive” in a medical report</td><td>Meaning/use differs by domain</td></tr><tr><td>Code mixing</td><td>Kal meeting reschedule karna.</td><td>Several languages and spelling conventions</td></tr><tr><td>Noisy text</td><td>tmrw, repeated letters, typos</td><td>Vocabulary/token boundaries become uncertain</td></tr><tr><td>Low-resource setting</td><td>Few labelled examples in a language</td><td>Models lack representative training evidence</td></tr><tr><td>Bias and privacy</td><td>Skewed data or personal details</td><td>Errors and harms can persist in deployed systems</td></tr></tbody></table><p><strong>Homophones</strong> sound alike but may differ in spelling (pair/pear). <strong>Homographs</strong> share spelling but can differ in meaning or pronunciation (lead the team / lead metal). These are different dimensions from syntactic ambiguity.</p><p>Long-distance dependencies, cultural knowledge, idioms, morphology and multilingual writing systems also complicate processing. For “kick the bucket”, literal word-by-word interpretation can miss the idiomatic meaning. For “The book that the students recommended is useful”, the verb is agrees with book across an intervening phrase.</p><p class=\"cue\">Exam mein challenge ka naam + ek sentence + dono meanings/actual failure likho.</p>","m2":false,"units":"1,7","marks":10,"sourcePages":[2],"historical":true},{"id":"q3a","title":"Q3a · Top-down restaurant parse","html":"<div class=\"question\"><strong>Question. Draw a top-down parse of “A restaurant serves dosas” using the printed grammar: S→NP VP | Aux NP VP | VP; NP→Pronoun | Proper-Noun | Det Nominal; Nominal→Noun | Nominal Noun | Nominal PP; VP→Verb | Verb NP | VP PP; PP→Prep NP. Lexicon: Det=A; Noun=restaurant,dosas; Verb=serves.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>As printed, this grammar cannot derive the complete sentence.</strong> The object dosas is a Noun, but NP has no rule for a bare Nominal/Noun. NP→Det Nominal would require a determiner before dosas that is absent.</p><h3>Clearly stated minimal repair</h3><p>Add NP→Nominal. The repaired top-down derivation is:</p><div class=\"table-wrap\"><table><thead><tr><th>Step</th><th>Sentential form</th></tr></thead><tbody><tr><td>1</td><td>S</td></tr><tr><td>2</td><td>NP VP</td></tr><tr><td>3</td><td>Det Nominal VP</td></tr><tr><td>4</td><td>A Noun VP</td></tr><tr><td>5</td><td>A restaurant Verb NP</td></tr><tr><td>6</td><td>A restaurant serves Nominal</td></tr><tr><td>7</td><td>A restaurant serves Noun</td></tr><tr><td>8</td><td>A restaurant serves dosas</td></tr></tbody></table></div><div style=\"overflow:auto\"><figure><svg viewBox=\"0 0 400 383\" role=\"img\" aria-label=\"Constituent parse tree\" style=\"width:100%;min-width:400px\"><line x1=\"55.0\" y1=\"165\" x2=\"55.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"95.0\" y1=\"100\" x2=\"55.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"230\" x2=\"135.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"165\" x2=\"135.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"95.0\" y1=\"100\" x2=\"135.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"175.0\" y1=\"35\" x2=\"95.0\" y2=\"76\" stroke=\"#718c85\"/><line x1=\"215.0\" y1=\"165\" x2=\"215.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"255.0\" y1=\"100\" x2=\"215.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"295\" x2=\"295.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"230\" x2=\"295.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"165\" x2=\"295.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"255.0\" y1=\"100\" x2=\"295.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"175.0\" y1=\"35\" x2=\"255.0\" y2=\"76\" stroke=\"#718c85\"/><text x=\"175.0\" y=\"28\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">S</text><text x=\"95.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"55.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Det</text><text x=\"55.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">A</text><text x=\"135.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Nominal</text><text x=\"135.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Noun</text><text x=\"135.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">restaurant</text><text x=\"255.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VP</text><text x=\"215.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Verb</text><text x=\"215.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">serves</text><text x=\"295.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"295.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Nominal</text><text x=\"295.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Noun</text><text x=\"295.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">dosas</text></svg><figcaption>[S [NP [Det A] [Nominal [Noun restaurant]]] [VP [Verb serves] [NP [Nominal [Noun dosas]]]]]</figcaption></figure></div><p>This tree uses the added rule only for the object. Do not silently pretend it is derivable under the original rule set. Left-recursive Nominal/VP alternatives require a terminating parser strategy; the displayed successful derivation chooses the needed finite branches.</p><p><strong>Source / convention note.</strong> Original CFG is incomplete for the given bare-plural object. Exact failure and explicit repaired derivation are both shown.</p>","m2":false,"units":"4","marks":10,"sourcePages":[2],"historical":true},{"id":"q3b","title":"Q3b · Preprocessing pipeline","html":"<div class=\"question\"><strong>Question. Explain basic preprocessing steps on a blob of text with an example and pipeline diagram.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>An NLP pipeline is an organized sequence of operations that transforms raw language into a task output and checks whether that output is useful.</strong> Not every task needs every cleaning operation.</p><div class=\"flow\"><div class=\"node\">Data acquisition</div><span aria-hidden=\"true\">→</span><div class=\"node\">Preprocessing</div><span aria-hidden=\"true\">→</span><div class=\"node\">Feature representation</div><span aria-hidden=\"true\">→</span><div class=\"node\">Model</div><span aria-hidden=\"true\">→</span><div class=\"node\">Evaluation</div><span aria-hidden=\"true\">→</span><div class=\"node\">Deployment and monitoring</div></div><ol><li><strong>Data acquisition:</strong> collect relevant text and, when needed, labels.</li><li><strong>Cleaning and preprocessing:</strong> handle markup, tokenize, normalize and decide which information to retain.</li><li><strong>Feature engineering:</strong> represent text numerically using BoW, TF–IDF or embeddings.</li><li><strong>Modelling:</strong> apply rules or train a statistical/neural model.</li><li><strong>Evaluation:</strong> test on held-out data using task-appropriate measures.</li><li><strong>Deployment:</strong> make the system available, log suitable feedback and monitor errors or data changes.</li></ol><h3>Concrete spam-filter example</h3><p>Collect labelled emails → separate train/test data → tokenize text while preserving meaningful terms → fit vocabulary and IDF on training data → train classifier → evaluate spam detection on the held-out set → deploy an email service filter → monitor legitimate emails wrongly blocked.</p><p><strong>Intrinsic evaluation</strong> measures model/task quality, such as precision, recall or tagging accuracy. <strong>Extrinsic evaluation</strong> measures effect in the wider application, such as whether users find answers faster. A higher internal metric does not automatically guarantee a better user outcome.</p><p><strong>Data leakage:</strong> learning vocabulary statistics, labels or preprocessing decisions from the test set can make reported performance too optimistic. Fit learned transformations on training data, then apply them to validation/test data.</p><p class=\"cue\">Collect → clean → numbers → model → test → use. Test data ko training ki information mat banao.</p><p><strong>Normalization reduces superficial variation so comparable forms can be processed consistently.</strong> Common operations include lowercasing, Unicode normalization, appropriate spelling correction, contraction handling, and optional stemming or lemmatization.</p><p><strong>Stopwords</strong> are frequent words selected for removal for a particular task, such as the or a. Removing them may reduce feature size, but removing not, no or nor can destroy sentiment meaning. Punctuation can convey sentence boundaries, emotion or mathematical structure. Lowercasing can erase differences such as US versus us.</p><div class=\"example\"><p><strong>Question. Preprocess “The CATS are not sleeping!!!” by lowercasing, removing punctuation, removing only stopwords {the,are}, and lemmatizing plural cats→cat and sleeping→sleep.</strong></p><div class=\"given\"><h4>Given</h4><p>Operations and stopword set are fixed. Do not remove not.</p><h4>To find</h4><p>The final token list.</p></div><h4>Formula and why it applies</h4><p>Apply the requested operations in order, keeping a visible intermediate result after each transformation.</p><div class=\"step\"><h4>Step 1. Lowercase</h4><p>the cats are not sleeping!!!</p></div><div class=\"step\"><h4>Step 2. Tokenize and remove punctuation</h4><p>[the,cats,are,not,sleeping]</p></div><div class=\"step\"><h4>Step 3. Remove specified stopwords</h4><p>Remove the and are → [cats,not,sleeping].</p></div><div class=\"step\"><h4>Step 4. Lemmatize</h4><p>cats→cat; sleeping→sleep → [cat,not,sleep].</p></div><p class=\"answer\"><strong>Answer.</strong> [cat,not,sleep]. The negative meaning is retained.</p></div><h3>Task decides preprocessing</h3><p>For a simple keyword-retrieval model, removing selected function words can help. For machine translation, question answering, grammar analysis or transformer input, aggressive removal may discard necessary syntax or violate the model's expected input format. Emoji can carry sentiment; convert or retain them when relevant instead of always deleting them.</p><p class=\"cue\">Clean karna = useful signal bachake noise hatao. Har word/punctuation delete karna cleaning nahi.</p><p><strong>Stemming</strong> applies string-based rules, often stripping suffixes, to reduce related forms to a stem. The result need not be a valid dictionary word. <strong>Lemmatization</strong> uses vocabulary and morphological analysis, often with POS information, to return a dictionary lemma.</p><table><thead><tr><th>Criterion</th><th>Stemming</th><th>Lemmatization</th></tr></thead><tbody><tr><td>Basis</td><td>Surface form/suffix rules</td><td>Lexicon and morphological/POS analysis</td></tr><tr><td>Output</td><td>May be nonword, e.g. studi</td><td>Dictionary form, e.g. study</td></tr><tr><td>Context/POS</td><td>Usually little or none</td><td>Often important</td></tr><tr><td>Irregular forms</td><td>May miss went→go</td><td>Can map went→go with verb analysis</td></tr><tr><td>Cost</td><td>Generally simpler</td><td>Usually more linguistic processing</td></tr></tbody></table><p>Porter applies a sequence of suffix-removal rules subject to conditions; Snowball provides related language-specific stemming algorithms; Lancaster is often more aggressive; regex stemming uses explicit patterns; Lovins is another established stemming approach. Exact output depends on the algorithm and implementation.</p><h3>Three worked reductions</h3><ol><li><strong>studies, studying:</strong> an English stemmer may yield studi/study depending on the rule sequence; verb lemmatization aims at study. State the exact algorithm if exact outputs are asked.</li><li><strong>better:</strong> adjective-aware lemmatization can map it to good; naïve suffix removal cannot infer that irregular relation.</li><li><strong>saw:</strong> as a past-tense verb it can become see; as a cutting-tool noun it remains saw. POS and context matter.</li></ol><p><strong>Over-stemming</strong> merges forms that should remain distinct; <strong>under-stemming</strong> fails to merge related forms. Normalization can increase recall in search while losing useful distinctions, so it is a task-dependent choice.</p><p class=\"cue\">Stem = rules se cut; lemma = dictionary form, meaning/POS ka dhyan.</p>","m2":false,"units":"2","marks":10,"sourcePages":[2],"historical":true},{"id":"q4a","title":"Q4a · Embeddings and Skip-gram","html":"<div class=\"question\"><strong>Question. Explain word embeddings and the steps in Skip-gram with a suitable diagram.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A sparse representation</strong> has many zero entries and often one coordinate per vocabulary item. BoW and TF–IDF are common sparse document representations. <strong>A dense embedding</strong> has comparatively few learned real-valued coordinates; one word's properties are spread across many coordinates.</p><table><thead><tr><th>Representation</th><th>What coordinates mean</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>One-hot</td><td>One identity position per vocabulary word</td><td>Unambiguous ID</td><td>Different words are orthogonal; no learned similarity</td></tr><tr><td>Count-based context vector</td><td>Context-word co-occurrence counts</td><td>Transparent corpus evidence</td><td>Large, sparse; frequent words may dominate</td></tr><tr><td>TF–IDF document vector</td><td>Weighted vocabulary terms</td><td>Useful retrieval weighting</td><td>Word order and contextual meaning are limited</td></tr><tr><td>Dense word embedding</td><td>Learned latent features</td><td>Compact semantic/syntactic relationships</td><td>Coordinates are not generally human-labelled features</td></tr></tbody></table><p><strong>Distributional</strong> describes learning from patterns of linguistic context. <strong>Distributed</strong> describes representing an item across multiple coordinates rather than a single active identity bit. These are related but different ideas. A one-hot ID alone does not learn distributional similarity.</p><h3>Model design choices</h3><p>Choose contexts (document, sentence, fixed window), weighting (raw counts, normalization, TF–IDF-like weighting or association scores), dimensionality reduction or learned embeddings, and a similarity measure. Cosine compares direction and is less affected by length than a raw dot product; Euclidean distance also reflects magnitude.</p><p class=\"cue\">Sparse = bahut zero. Dense = chhoti learned number-list. Similar context se useful similarity seekhte hain.</p><p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>","m2":false,"units":"5","marks":10,"sourcePages":[2],"historical":true},{"id":"q4b","title":"Q4b · POS, NER, chunking and TTR","html":"<div class=\"question\"><strong>Question. Define POS tagging, entity recognition, chunking and type-token ratio with examples.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Part-of-speech (POS) tagging</strong> assigns a grammatical category to every word token in context, such as noun, verb, adjective or determiner. It is a sequence-labeling task: the input is a sequence of words, and the output is a tag for each word. A tag describes the word's role in this sentence, not its meaning in every possible sentence.</p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Role</th><th>Example in context</th></tr></thead><tbody><tr><td>NN / NNS</td><td>Singular / plural common noun</td><td>a book / two books</td></tr><tr><td>NNP</td><td>Proper noun</td><td>Mary, Mumbai</td></tr><tr><td>VB / VBD / VBZ</td><td>Base / past / third-person singular verb</td><td>read / read / reads</td></tr><tr><td>JJ</td><td>Adjective</td><td>the red book</td></tr><tr><td>RB</td><td>Adverb</td><td>runs quickly</td></tr><tr><td>DT</td><td>Determiner</td><td>the, a, this</td></tr><tr><td>IN</td><td>Preposition or subordinating conjunction</td><td>on the table</td></tr><tr><td>PRP</td><td>Personal pronoun</td><td>she, they</td></tr><tr><td>MD</td><td>Modal auxiliary</td><td>can, will, should</td></tr></tbody></table></div><p><strong>Open classes</strong> readily accept new content words: nouns, verbs, adjectives and adverbs. Examples include chatbot and livestream. <strong>Closed classes</strong> contain comparatively stable grammatical/function words: determiners, pronouns, prepositions and conjunctions. These are tendencies, not a claim that language never changes.</p><div class=\"flow\"><div class=\"node\">Input: Book that flight</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Context: an imperative request</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Output: Book/VB that/DT flight/NN</div></div><p>Compare “hand me that <strong>book</strong>”: book is a noun here. Similarly, “I <strong>can</strong> swim” has can/MD, while “the <strong>can</strong> is empty” has can/NN. The spelling stays the same; neighboring words and sentence structure change the correct tag. This is <strong>POS ambiguity</strong>.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged interpretation</th><th>Reason</th></tr></thead><tbody><tr><td>They watch birds.</td><td>They/PRP watch/VBP birds/NNS</td><td>watch is the action.</td></tr><tr><td>The watch stopped.</td><td>The/DT watch/NN stopped/VBD</td><td>watch is the object that stopped.</td></tr><tr><td>She has a light bag.</td><td>She/PRP has/VBZ a/DT light/JJ bag/NN</td><td>light describes bag.</td></tr><tr><td>Light the lamp.</td><td>Light/VB the/DT lamp/NN</td><td>Light is an imperative verb.</td></tr></tbody></table></div><p>POS tags support parsing, named entity recognition, question answering, sentiment analysis and word-sense disambiguation. They do not by themselves identify every entity or fully resolve meaning.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Word ka naam same ho sakta hai; sentence mein uska kaam tag decide karta hai.</p><p><strong>Named Entity Recognition (NER)</strong> identifies text spans referring to entities and assigns their types, such as PERSON, ORGANIZATION and LOCATION. Many practical schemas also include DATE, TIME, MONEY or domain-specific types. The exact allowed labels depend on the application's annotation scheme.</p><p>NER has two parts: <strong>boundary detection</strong> finds where the entity starts and ends; <strong>classification</strong> assigns the appropriate type. A multiword name should normally be one entity span: “New York” is a location span, not two unrelated location decisions.</p><div class=\"flow\"><div class=\"node\">Text: Mary joined Google in New York on Monday.</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Mary → PERSON</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Google → ORGANIZATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New York → LOCATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Monday → DATE</div></div><p>Not every noun is a named entity. In “a developer works at Google”, developer is an ordinary job description while Google is a named organization. A specialized HR system may define a JOB_TITLE category, but it must state that schema explicitly. NER identifies mentions; entity linking is the separate task of connecting a mention to a unique database identity.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>POS</td><td>What grammatical role does this token have?</td><td>Google/NNP</td></tr><tr><td>Chunking</td><td>Which adjacent words form a phrase?</td><td>[NP a skilled developer]</td></tr><tr><td>NER</td><td>Which span names an entity, and of what type?</td><td>[Google] ORGANIZATION</td></tr><tr><td>Entity linking</td><td>Which real entity does this mention denote?</td><td>Connect Paris to the intended city or person record</td></tr></tbody></table></div><p><strong>Applications.</strong> NER structures search results and documents, extracts organizations/people from news, routes support tickets by product or organization, supports recommendation, and extracts specialized entities from healthcare or legal text. Context is essential: “Apple released a laptop” names an organization, while “she ate an apple” describes fruit.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER mein do kaam: naam kahan se kahan tak, aur kis category ka.</p><p><strong>Chunking</strong>, also called shallow parsing, groups adjacent tagged words into meaningful non-overlapping units, commonly noun phrases. It usually identifies local phrase boundaries without producing the complete hierarchical structure of a sentence. <strong>Chinking</strong> removes specified tokens from an existing candidate chunk, splitting or trimming it.</p><div class=\"flow\"><div class=\"node\">The/DT small/JJ cat/NN sat/VBD on/IN the/DT mat/NN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [The small cat]</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Outside: sat on</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [the mat]</div></div><p>A POS tagger labels individual words. A chunker groups words into phrases. A full parser shows how phrases relate recursively to form the entire sentence. These are related tasks with different outputs.</p><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>POS tagging</td><td>The small cat</td><td>The/DT small/JJ cat/NN</td></tr><tr><td>NP chunking</td><td>Tagged tokens</td><td>[NP The small cat]</td></tr><tr><td>Chinking</td><td>A broad candidate chunk</td><td>Remove verbs/prepositions, keep noun-phrase segments</td></tr><tr><td>Full parsing</td><td>Sentence + grammar</td><td>A nested tree with sentence, noun phrase and verb phrase nodes</td></tr></tbody></table></div><p><strong>Rule-based chunking</strong> uses tag patterns. Statistical or learned chunkers infer boundaries from labeled examples. A useful NP rule is an optional determiner, followed by zero or more adjectives, followed by a noun. In NLTK-style notation: <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;}</code>. Here ? means zero or one occurrence; * means zero or more; + means one or more when used. The braces mean “form a chunk around the matched sequence”.</p><section class=\"example\"><p class=\"question\"><strong>Question. Apply the NP rule optional DT, zero or more JJ, then one NN to “The/DT quick/JJ brown/JJ fox/NN jumps/VBZ over/IN the/DT lazy/JJ dog/NN”.</strong></p><div class=\"given\"><h4>Given</h4><p>Tagged input is supplied. Rule: DT? JJ* NN.</p><h4>To find</h4><p>All noun-phrase chunks.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The rule groups a noun with its preceding determiner and adjectives; a verb or preposition does not match this NP pattern.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start at The</h5><p>The matches optional DT; quick and brown both match JJ*; fox matches NN.</p></div><div class=\"step\"><h5>Step 2. Form the first NP</h5><p><strong>[NP The quick brown fox]</strong></p></div><div class=\"step\"><h5>Step 3. Skip nonmatching tokens</h5><p>jumps/VBZ and over/IN do not satisfy the NP pattern.</p></div><div class=\"step\"><h5>Step 4. Match the second NP</h5><p>the is DT, lazy is JJ, dog is NN: <strong>[NP the lazy dog]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> [NP The quick brown fox] jumps over [NP the lazy dog].</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using NP → DT? JJ* NN, identify the chunks in “bright/JJ stars/NN shine/VBP and/CC a/DT moon/NN glows/VBZ”. Use the supplied tags exactly.</strong></p><div class=\"given\"><h4>Given</h4><p>Input tags label stars as NN for this exercise. Rule requires optional DT, zero or more JJ, then NN.</p><h4>To find</h4><p>The matched NP spans.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The optional determiner may be absent and the adjective repetition may be empty.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Match bright stars</h5><p>No determiner is present, which DT? permits. bright matches JJ; stars matches NN.</p></div><div class=\"step\"><h5>Step 2. Inspect shine and and</h5><p>VBP and CC fall outside the NP rule.</p></div><div class=\"step\"><h5>Step 3. Match a moon</h5><p>a matches DT; no adjective is present; moon matches NN.</p></div><div class=\"answer\"><strong>Final answer.</strong> Chunks are [NP bright stars] and [NP a moon]. With ordinary Penn tagging, stars is usually NNS; broaden the noun pattern to include NNS when that tag is used.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Begin with one candidate chunk containing “The/DT cat/NN sat/VBD on/IN the/DT mat/NN”. Chink out verbs and prepositions. Show the remaining chunks.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial candidate: [The cat sat on the mat]. Remove tags VBD and IN.</p><h4>To find</h4><p>The chunk segments after exclusion.</p></div><h4>Formula and why it applies</h4><p>Chinking removes matched tokens from the existing chunk.</p><p>Removing the middle verb/preposition region divides the original candidate into two remaining contiguous spans.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the tokens to remove</h5><p>sat is VBD and on is IN.</p></div><div class=\"step\"><h5>Step 2. Remove those tokens from chunk membership</h5><p>The remaining token groups are “The cat” and “the mat”. sat and on still exist in the sentence; they are simply outside these chunks.</p></div><div class=\"step\"><h5>Step 3. Write the final chunked sentence</h5><p><strong>[The cat]</strong> sat on <strong>[the mat]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> Two chunks remain: The cat; the mat.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Chunking = andar group karo; chinking = unwanted tokens ko group se bahar karo.</p></section><p><strong>Type-token ratio</strong> = number of distinct tokens / total tokens. In “cats chase cats”, types={cats,chase}=2 and tokens=3, so TTR=2/3. This is an authored illustration of the definition, not extra paper data.</p>","m2":false,"units":"2,4","marks":10,"sourcePages":[2],"historical":true},{"id":"q5a","title":"Q5a · Lexical and vector semantics","html":"<div class=\"question\"><strong>Question. Explain lexical semantics and vector semantics with examples.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A lexical relation connects words or senses by a meaning relationship.</strong> State the relation and its direction before giving the example.</p><table><thead><tr><th>Relation</th><th>Exam definition</th><th>Examples and direction</th></tr></thead><tbody><tr><td>Homonymy</td><td>The same form has unrelated meanings.</td><td>bank: financial institution / river edge; bat: animal / sports implement</td></tr><tr><td>Polysemy</td><td>One lexical item has multiple related senses.</td><td>head: body part / head of a department; paper: material / article</td></tr><tr><td>Synonymy</td><td>Different words have identical or closely similar meanings in a specified sense.</td><td>sofa / couch; automobile / car</td></tr><tr><td>Antonymy</td><td>Words have opposite meanings.</td><td>hot / cold; alive / dead; buy / sell</td></tr><tr><td>Hyponymy</td><td>A more specific concept is a type of a more general one.</td><td>rose is a flower; car is a vehicle</td></tr><tr><td>Hypernymy</td><td>A broader concept includes a more specific one.</td><td>flower is a hypernym of rose</td></tr><tr><td>Meronymy</td><td>A concept is a part of another concept.</td><td>wheel is part of car; finger is part of hand</td></tr><tr><td>Holonymy</td><td>A concept is the whole containing a part.</td><td>car is a holonym of wheel</td></tr></tbody></table><h3>How to distinguish the commonly confused pairs</h3><p>For homonymy versus polysemy, ask whether the senses share an identifiable meaning. A river bank and a financial bank are unrelated. A financial bank and a blood bank share a repository/storage idea, illustrating polysemy in the supplied notes.</p><p>For hyponymy versus meronymy, use the sentence test: <strong>“X is a kind of Y”</strong> indicates hyponymy; <strong>“X is part of Y”</strong> indicates meronymy. A wheel is not a type of car.</p><table><thead><tr><th>Expression</th><th>Correct relation</th><th>Reason</th></tr></thead><tbody><tr><td>sparrow → bird</td><td>Hyponymy</td><td>A sparrow is a kind of bird</td></tr><tr><td>bird → sparrow</td><td>Hypernymy</td><td>Bird is the broader category</td></tr><tr><td>keyboard → computer</td><td>Meronymy</td><td>Keyboard is a component</td></tr><tr><td>computer → keyboard</td><td>Holonymy</td><td>Computer is the containing whole</td></tr><tr><td>mouth of a person / mouth of a river</td><td>Polysemy</td><td>Both senses share the idea of an opening; the river use is a related extension</td></tr></tbody></table><p>Synonyms are not always interchangeable in every context or register. “Big mistake” and “large mistake” can sound different even though big and large overlap in meaning. Antonyms can be gradable (hot/cold), complementary (alive/dead) or relational converses (buy/sell).</p><p class=\"cue\">HYPO = specific type; HYPER = bigger category. MERO = part; HOLO = whole.</p><p><strong>The distributional hypothesis states that words occurring in similar contexts tend to have similar meanings or semantic behaviour.</strong> “Cat” and “dog” often occur near pet, feed and animal. Their context patterns can therefore be represented and compared numerically.</p><p>A <strong>vector</strong> is an ordered list of numbers. Each position must have a fixed meaning. For context order [pet, food, road], cat=[4,3,0] means four co-occurrences with pet, three with food, none with road. A <strong>matrix</strong> stacks vectors as rows in a table.</p><p>A <strong>word–context co-occurrence matrix</strong> records how often a target word occurs with each context word under a specified context definition. A window may be a sentence, document, or a fixed number of neighbouring tokens. State its width, direction and whether targets count themselves.</p><div class=\"flow\"><div class=\"node\">Choose target words</div><span aria-hidden=\"true\">→</span><div class=\"node\">Choose context/window</div><span aria-hidden=\"true\">→</span><div class=\"node\">Count co-occurrences</div><span aria-hidden=\"true\">→</span><div class=\"node\">Store each row as a vector</div><span aria-hidden=\"true\">→</span><div class=\"node\">Compare vectors</div></div><div class=\"example\"><p><strong>Question. Build the symmetric co-occurrence matrix for “cats eat fish” using a window of one token on either side, no self-counts and vocabulary [cats,eat,fish].</strong></p><div class=\"given\"><h4>Given</h4><p>One sentence, one occurrence of each token. Left and right adjacent tokens are contexts.</p><h4>To find</h4><p>A 3×3 target-by-context count matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/e26c85d7637ed303.svg\" alt=\"X_{ij}\" style=\"width:3.272ex;height:2.211ex\" loading=\"lazy\" decoding=\"async\"></span> counts the number of times context word <span class=\"math-inline\"><img src=\"math/7a5268d94266eaaf.svg\" alt=\"j\" style=\"width:0.932ex;height:1.957ex\" loading=\"lazy\" decoding=\"async\"></span> occurs within the chosen window of target <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Target cats</h4><p>Only eat is adjacent. Row cats = [0,1,0].</p></div><div class=\"step\"><h4>Step 2. Target eat</h4><p>cats is left and fish is right. Row eat = [1,0,1].</p></div><div class=\"step\"><h4>Step 3. Target fish</h4><p>Only eat is adjacent. Row fish = [0,1,0].</p></div><div class=\"step\"><h4>Step 4. Assemble the matrix</h4><table><thead><tr><th>Target / context</th><th>cats</th><th>eat</th><th>fish</th></tr></thead><tbody><tr><td>cats</td><td>0</td><td>1</td><td>0</td></tr><tr><td>eat</td><td>1</td><td>0</td><td>1</td></tr><tr><td>fish</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> Rows are [0,1,0], [1,0,1], [0,1,0]. The symmetry follows from the symmetric window.</p></div><div class=\"example\"><p><strong>Question. Build a target–context matrix for sentences “cats eat fish” and “dogs eat fish”. Target words are cats and dogs; context columns [eat,fish]; use the entire sentence excluding the target.</strong></p><div class=\"given\"><h4>Given</h4><p>Each sentence contains one target. Count context token occurrences.</p><h4>To find</h4><p>Two context vectors.</p></div><h4>Formula and why it applies</h4><p>Count each context word in every sentence containing the target.</p><div class=\"step\"><h4>Step 1. Count cats contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 2. Count dogs contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 3. Compare</h4><p>Both targets have identical observed context patterns in this very small corpus.</p></div><p class=\"answer\"><strong>Answer.</strong> cats=[1,1], dogs=[1,1]. This corpus supplies no context evidence to distinguish them.</p></div><div class=\"example\"><p><strong>Question. For “a b a”, use a right-only window of one token. Build the matrix with rows/columns [a,b].</strong></p><div class=\"given\"><h4>Given</h4><p>Count directed target→next-word events, not both directions.</p><h4>To find</h4><p>The co-occurrence matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/584bbdf22ac0ea3c.svg\" alt=\"X_{ij}=C(\\text{target }i\\text{ immediately followed by }j)\" style=\"width:42.914ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. First target a</h4><p>Next token is b → add 1 to X(a,b).</p></div><div class=\"step\"><h4>Step 2. Target b</h4><p>Next token is a → add 1 to X(b,a).</p></div><div class=\"step\"><h4>Step 3. Final a</h4><p>No following token → no addition.</p></div><div class=\"step\"><h4>Step 4. Write matrix</h4><table><thead><tr><th>Target / next</th><th>a</th><th>b</th></tr></thead><tbody><tr><td>a</td><td>0</td><td>1</td></tr><tr><td>b</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> a=[0,1], b=[1,0]. A different context window would produce a different matrix.</p></div><p class=\"cue\">Word ka meaning: uske aas-paas kaunse words kitni baar aaye, uski number-list.</p>","m2":false,"units":"5","marks":10,"sourcePages":[3],"historical":true},{"id":"q5b","title":"Q5b · Classification label structures","html":"<div class=\"question\"><strong>Question. Compare binary, multiclass and multilabel supervised text classification with examples.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Type</th><th>Allowed output</th><th>Example</th><th>Typical output rule</th></tr></thead><tbody><tr><td>Binary</td><td>One of two labels</td><td>positive OR negative review</td><td>One sigmoid or two-class softmax</td></tr><tr><td>Multiclass</td><td>Exactly one of several labels</td><td>sport OR business OR science</td><td>Softmax over mutually exclusive classes</td></tr><tr><td>Multilabel</td><td>Zero, one or several labels</td><td>Article tagged technology AND finance</td><td>Independent sigmoid per label</td></tr></tbody></table></div><p>Multiclass and multilabel differ in whether labels may coexist, not merely in the number of labels. A loss and evaluation measure must match the task.</p>","m2":false,"units":"7","marks":10,"sourcePages":[3],"historical":true},{"id":"q6a","title":"Q6a · TF–IDF in document representation","html":"<div class=\"question\"><strong>Question. Explain TF–IDF in document representation and information retrieval with an example.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>TF–IDF weights a term highly when it is frequent in a particular document but uncommon across the corpus.</strong> The supplied Unit 2 slides use normalized term frequency and base-10 inverse document frequency:</p><div class=\"math-display\"><img src=\"math/deca468dd207619e.svg\" alt=\"\\operatorname{TF}(t,d)=\\frac{C(t,d)}{N_d}\" style=\"width:18.362ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/dd1eb7f26551c5f0.svg\" alt=\"\\operatorname{IDF}(t)=\\log_{10}\\frac{D}{\\operatorname{df}(t)}\" style=\"width:20.345ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c3205280fe205579.svg\" alt=\"\\operatorname{TFIDF}(t,d)=\\operatorname{TF}(t,d)\\operatorname{IDF}(t).\" style=\"width:30.386ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/716cbce384bea429.svg\" alt=\"N_d\" style=\"width:2.836ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the document's token count after the specified preprocessing; <span class=\"math-inline\"><img src=\"math/62ef1c41dad1fbc8.svg\" alt=\"D\" style=\"width:1.873ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is number of documents; <span class=\"math-inline\"><img src=\"math/92f4a76a32f5c806.svg\" alt=\"\\operatorname{df}(t)\" style=\"width:4.676ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of documents containing the term at least once. A word repeated ten times in one document contributes one to document frequency.</p><p><strong>Why the log?</strong> It compresses the ratio's scale. If a term occurs in all documents, <span class=\"math-inline\"><img src=\"math/2d65862ad68e4d56.svg\" alt=\"D/df=1\" style=\"width:9.574ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, so IDF=0 under this unsmoothed convention. Other libraries use smoothed IDF, different TF or normalization. Use the question's formula; do not silently substitute a library default.</p><div class=\"example\"><p><strong>Question. A corpus contains 10 documents. The word model appears in 2 documents and occurs 3 times in a 12-token document. Compute TF, IDF and TF–IDF using the slide convention.</strong></p><div class=\"given\"><h4>Given</h4><p>D=10, df(model)=2, C(model,d)=3, Nd=12; log base 10.</p><h4>To find</h4><p>The TF–IDF weight.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>, then multiply.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/51ccdc5dee01783f.svg\" alt=\"3/12=0.25\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Document ratio</h4><p><span class=\"math-inline\"><img src=\"math/e03ff475f4b9e538.svg\" alt=\"10/2=5\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. IDF</h4><p><span class=\"math-inline\"><img src=\"math/35a02628576f1000.svg\" alt=\"\\log_{10}5\\approx0.698970\" style=\"width:17.752ex;height:2.151ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Weight</h4><p><span class=\"math-inline\"><img src=\"math/f8ed981eba287429.svg\" alt=\"0.25\\times0.698970\\approx0.174743\" style=\"width:26.9ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> TF=0.25, IDF≈0.698970, TF–IDF≈0.174743.</p></div><div class=\"example\"><p><strong>Question. A term occurs 4 times in a 20-token document and is present in all 8 corpus documents. Calculate its TF–IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>C=4, Nd=20, D=8, df=8.</p><h4>To find</h4><p>Its weight under unsmoothed base-10 IDF.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/b0de7a9a9a0c728c.svg\" alt=\"4/20=0.2\" style=\"width:10.433ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. IDF</h4><p><span class=\"math-inline\"><img src=\"math/9a61d3220cb1a861.svg\" alt=\"\\log_{10}(8/8)=\\log_{10}1=0\" style=\"width:23.186ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/97ff1a04375e7994.svg\" alt=\"0.2\\times0=0\" style=\"width:10.937ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Weight 0: this term does not distinguish documents under this convention.</p></div><div class=\"example\"><p><strong>Question. Find TF–IDF vectors for D1=“cat cat dog”, D2=“dog fish”, D3=“cat fish fish”, using [cat,dog,fish], normalized TF and log10 IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>No further preprocessing. Each term occurs in exactly two of the three documents.</p><h4>To find</h4><p>All three vectors.</p></div><h4>Formula and why it applies</h4><p>First count df by documents, then compute each document's TF, then multiply by its term's IDF.</p><div class=\"step\"><h4>Step 1. Common IDF</h4><p><span class=\"math-inline\"><img src=\"math/a912b37fed2477fc.svg\" alt=\"D=3\" style=\"width:6.022ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/8279f303c7e95ae1.svg\" alt=\"df(cat)=df(dog)=df(fish)=2\" style=\"width:33.461ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Each IDF <span class=\"math-inline\"><img src=\"math/fdd435a4274ddcc4.svg\" alt=\"=\\log_{10}(3/2)\\approx0.176091\" style=\"width:23.786ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. D1 term frequencies</h4><p>Length 3 → <span class=\"math-inline\"><img src=\"math/33108c032f375ccc.svg\" alt=\"[2/3,1/3,0]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. D1 weights</h4><p><span class=\"math-inline\"><img src=\"math/a969ee9cc56b474e.svg\" alt=\"[(2/3)0.176091,(1/3)0.176091,0]\\approx[0.117394,0.058697,0]\" style=\"width:56.317ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. D2 weights</h4><p>Length 2; TF <span class=\"math-inline\"><img src=\"math/3a45dfb5933f8388.svg\" alt=\"[0,1/2,1/2]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/42c4ea9d39b355c1.svg\" alt=\"\\approx[0,0.088046,0.088046]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. D3 weights</h4><p>Length 3; TF <span class=\"math-inline\"><img src=\"math/b75534a4556b2589.svg\" alt=\"[1/3,0,2/3]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/f530e35b75352a92.svg\" alt=\"\\approx[0.058697,0,0.117394]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> D1≈[0.117394,0.058697,0]; D2≈[0,0.088046,0.088046]; D3≈[0.058697,0,0.117394].</p></div><p class=\"cue\">TF: iss document mein kitna. IDF: poore corpus mein kitna rare. Dono multiply.</p><p><strong>Information retrieval (IR)</strong> locates and ranks items relevant to an information need, usually expressed as a query. The collection may contain documents, product descriptions or scientific papers. Retrieval estimates relevance; it does not itself establish that every retrieved claim is true.</p><div class=\"flow\"><div class=\"node\">Documents → cleaning</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Build index</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Query → same representation</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match & rank</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Return relevant results</div></div><h3>The inverted index</h3><p>An inverted index maps a term to the documents containing it, often with positions or counts. For D1 “cats drink milk” and D2 “dogs drink water”, the posting list for drink is {D1,D2}, while milk maps only to D1. This avoids rescanning every document for every query.</p><table><thead><tr><th>Term</th><th>Posting list</th></tr></thead><tbody><tr><td>cats</td><td>D1</td></tr><tr><td>drink</td><td>D1, D2</td></tr><tr><td>milk</td><td>D1</td></tr><tr><td>dogs</td><td>D2</td></tr><tr><td>water</td><td>D2</td></tr></tbody></table><h3>Matching and ranking</h3><p>Boolean retrieval combines term membership using AND, OR and NOT. Vector-space retrieval represents documents and queries as weighted vectors, for example with TF-IDF, and compares them with cosine similarity. Learned retrieval can use dense embeddings for meaning-based matching. The representation used at query time must be compatible with the document index.</p><h3>Search engines and recommendation</h3><p>A search engine receives an explicit query and ranks matching indexed pages. A recommender may derive an implicit query from a user’s liked items or profile and retrieve similar candidates. Both require candidate retrieval and ranking, but the source of the information need differs.</p><h3>Evaluate the results</h3><p>For retrieval, TP is the number of retrieved relevant documents, FP retrieved irrelevant documents, and FN relevant documents not retrieved. Precision and recall use the same formulas as classification. Ranking measures also consider the positions of relevant items; a relevant result at rank 1 is more useful than one far below.</p><section class=\"example\"><h3>Retrieval evaluation</h3><p class=\"question\">A search system retrieves 8 documents; 6 are relevant. There are 10 relevant documents in the collection. Find precision, recall and F1.</p><div class=\"given\"><strong>Given</strong><p>Retrieved=8; relevant retrieved=6; all relevant=10.</p><strong>To find</strong><p>P, R and F1.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/58a11f3930a42815.svg\" alt=\"P=\\frac{\\text{relevant retrieved}}{\\text{retrieved}},\\quad R=\\frac{\\text{relevant retrieved}}{\\text{all relevant}}\" style=\"width:49.316ex;height:4.676ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4743421649dff6a6.svg\" alt=\"F_1=\\frac{2PR}{P+R}\" style=\"width:12.637ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>The denominator is 8 for precision and 10 for recall because they ask different questions.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the confusion counts</h4><p>TP=6; FP=8−6=2; FN=10−6=4.</p></div><div class=\"step\"><h4>Step 2. Precision</h4><div class=\"math-display\"><img src=\"math/6a30a7f6694209de.svg\" alt=\"P=\\frac68=0.75\" style=\"width:13.883ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Recall</h4><div class=\"math-display\"><img src=\"math/402ac41b5040dfdd.svg\" alt=\"R=\\frac6{10}=0.6\" style=\"width:13.901ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. F1</h4><div class=\"math-display\"><img src=\"math/aedd722bd9955777.svg\" alt=\"F_1=\\frac{2(0.75)(0.6)}{0.75+0.6}=\\frac{0.9}{1.35}=\\frac23\\approx0.666667\" style=\"width:42.764ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision=0.75, recall=0.60, F1≈0.666667.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Precision: jo laaye, unmein kitne sahi? Recall: jo sahi the, unmein kitne laaye?</p><p><strong>Source / convention note.</strong> The prompt requests an example but supplies no corpus. Numbers in the explanation are authored illustrations, not original numerical givens.</p>","m2":false,"units":"2,7","marks":10,"sourcePages":[3],"historical":true},{"id":"q6b","title":"Q6b · HMM tables and path","html":"<div class=\"question\"><strong>Question. For the four tagged sentences below construct transition and emission tables (3 marks each), then calculate Geeta/N will/M spot/V Rita/N using initial P(N)=0.5, P(M)=0.25, P(V)=0.25.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Given tags</th></tr></thead><tbody><tr><td>Rita can teach Will</td><td>N M V N</td></tr><tr><td>Spot will see Will</td><td>N M V N</td></tr><tr><td>Will Rita spot Geeta</td><td>N N V N</td></tr><tr><td>Geeta will pat Spot</td><td>N M V N</td></tr></tbody></table></div><p>Required path: Geeta will spot Rita / N M V N. Given initial probabilities: {'N': Fraction(1, 2), 'M': Fraction(1, 4), 'V': Fraction(1, 4)}</p><h3>To find</h3><p>Emission and transition tables and the specified tag-path joint probability</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9a06539e1ddc3c75.svg\" alt=\"P(w\\mid t)=\\frac{c(t,w)}{c(t)}\" style=\"width:17.977ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d9ef5a8985e2f56.svg\" alt=\"P(t_j\\mid t_i)=\\frac{c(t_i,t_j)}{\\sum_kc(t_i,t_k)}\" style=\"width:23.506ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The second formula is the declared no-END convention. Reset at sentence boundaries; never create a transition from the last word of one training sentence to the first of the next.</p><h3>Step 1. Count emissions</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Total occurrences</th><th>Rita</th><th>can</th><th>teach</th><th>Will</th><th>Spot</th><th>will</th><th>see</th><th>spot</th><th>Geeta</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>9</td><td>2</td><td>0</td><td>0</td><td>3</td><td>2</td><td>0</td><td>0</td><td>0</td><td>2</td><td>0</td></tr><tr><td>M</td><td>3</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>2</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>V</td><td>4</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td></tr></tbody></table></div><h3>Step 2. Divide each emission by its tag count</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Rita</th><th>can</th><th>teach</th><th>Will</th><th>Spot</th><th>will</th><th>see</th><th>spot</th><th>Geeta</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>2/9</td><td>0</td><td>0</td><td>1/3</td><td>2/9</td><td>0</td><td>0</td><td>0</td><td>2/9</td><td>0</td></tr><tr><td>M</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>0</td><td>2/3</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>0</td><td>0</td><td>1/4</td><td>1/4</td><td>0</td><td>1/4</td></tr></tbody></table></div><h3>Step 3. Count transitions inside each sentence</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Outgoing transitions</th><th>Sentence-final count</th><th>N</th><th>M</th><th>V</th></tr></thead><tbody><tr><td>N</td><td>5</td><td>4</td><td>1</td><td>3</td><td>1</td></tr><tr><td>M</td><td>3</td><td>0</td><td>0</td><td>0</td><td>3</td></tr><tr><td>V</td><td>4</td><td>0</td><td>4</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 4. Convert to a transition table</h3><div class=\"table-wrap\"><table><thead><tr><th>From / to</th><th>N</th><th>M</th><th>V</th></tr></thead><tbody><tr><td>N</td><td>1/5</td><td>3/5</td><td>1/5</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1</td></tr><tr><td>V</td><td>1</td><td>0</td><td>0</td></tr></tbody></table></div><p>Here sentence-final tags are excluded from the no-END outgoing denominator. If END is explicitly modeled, divide all tag→tag and tag→END counts by the total tag count instead; the row then includes END. Do not mix denominators.</p><h3>Step 5. Multiply the given path, in order</h3><div class=\"table-wrap\"><table><thead><tr><th>Factor</th><th>Probability</th><th>Running product</th></tr></thead><tbody><tr><td>Initial N</td><td>1/2</td><td>1 × 1/2 = 1/2</td></tr><tr><td>Emit Geeta</td><td>2/9</td><td>1/2 × 2/9 = 1/9</td></tr><tr><td>Transition N→M</td><td>3/5</td><td>1/9 × 3/5 = 1/15</td></tr><tr><td>Emit will</td><td>2/3</td><td>1/15 × 2/3 = 2/45</td></tr><tr><td>Transition M→V</td><td>1</td><td>2/45 × 1 = 2/45</td></tr><tr><td>Emit spot</td><td>1/4</td><td>2/45 × 1/4 = 1/90</td></tr><tr><td>Transition V→N</td><td>1</td><td>1/90 × 1 = 1/90</td></tr><tr><td>Emit Rita</td><td>2/9</td><td>1/90 × 2/9 = 1/405</td></tr></tbody></table></div><h3>Final answer</h3><p>The two displayed probability tables are the estimated HMM. Zero means unobserved without smoothing, not logically impossible.</p><p><strong>No-END path joint probability = 1/405 = 0.00246913580247.</strong> If a normalized END-state model is explicitly adopted instead, this complete terminated sequence has probability 4/6561 = 0.000609663161103. These are different model conventions, not contradictory answers.</p>","m2":false,"units":"4","marks":10,"sourcePages":[3],"historical":true},{"id":"q7a","title":"Q7a · Healthcare and finance applications","html":"<div class=\"question\"><strong>Question. Explain NLP use cases in healthcare and finance.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Domain / task</th><th>Input → method → useful output</th><th>Example and limit</th></tr></thead><tbody><tr><td>Healthcare: clinical extraction</td><td>Notes → entity/negation/relation extraction → diagnoses, medicines and doses</td><td>Distinguish no fever from fever; clinician review is needed</td></tr><tr><td>Healthcare: coding and search</td><td>Clinical text → classify/retrieve → candidate billing codes or evidence</td><td>Coding suggestions are not autonomous diagnoses</td></tr><tr><td>Healthcare: patient messaging</td><td>Patient question → intent + retrieval → approved explanation</td><td>Escalate uncertainty and emergencies; protect identifiers</td></tr><tr><td>Finance: sentiment/event analysis</td><td>News/filings → entities/events/sentiment → issuer-specific signals</td><td>Distinguish rumor from confirmed earnings; not guaranteed returns</td></tr><tr><td>Finance: document extraction</td><td>Reports/contracts → fields/relations → searchable structured records</td><td>Keep source spans and verify amounts/dates</td></tr><tr><td>Finance: customer support/compliance triage</td><td>Messages → intent/classification → routed cases or flagged text</td><td>Human investigation is required; a language flag is not proof of wrongdoing</td></tr></tbody></table></div><div class=\"flow\"><span class=\"flow-box\">Acquire permitted text</span> → <span class=\"flow-box\">Clean and preserve context</span> → <span class=\"flow-box\">Extract / classify / retrieve</span> → <span class=\"flow-box\">Evaluate on domain data</span> → <span class=\"flow-box\">Human-reviewed use</span></div>","m2":false,"units":"7","marks":10,"sourcePages":[4],"historical":true},{"id":"q7b","title":"Q7b · Naive Bayes sentiment","html":"<div class=\"question\"><strong>Question. Train Naive Bayes on: positive “amaze wonderful great”; “happy happy great”; “amaze great happy disgust”; “great happy wonderful”. Negative “disgust sad terrible great”; “sad terrible sad happy”. Predict sentence 7: “great happy disgust great”.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Training text</th><th>Class</th></tr></thead><tbody><tr><td>amaze wonderful great</td><td>positive</td></tr><tr><td>happy happy great</td><td>positive</td></tr><tr><td>amaze great happy disgust</td><td>positive</td></tr><tr><td>great happy wonderful</td><td>positive</td></tr><tr><td>disgust sad terrible great</td><td>negative</td></tr><tr><td>sad terrible sad happy</td><td>negative</td></tr></tbody></table></div><p>Test: great happy disgust great</p><h3>To find</h3><p>Classify the test using multinomial Naive Bayes.</p><h3>Formula: which one and why</h3><p>Assume add-one smoothing unless the question supplies probabilities. Keep repeated words as repeated factors. Use training vocabulary only; ignore out-of-vocabulary words unless an unknown-token model is defined.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad88d5fb5558250.svg\" alt=\"\\mathrm{score}(c)=P(c)\\prod_{w\\in V}\\left(\\frac{c(w,c)+1}{N_c+|V|}\\right)^{c(w,d)}\" style=\"width:38.427ex;height:6.664ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Vocabulary and class priors</h3><p>V = {amaze, disgust, great, happy, sad, terrible, wonderful}; |V|=7.</p><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Documents</th><th>Prior</th></tr></thead><tbody><tr><td>negative</td><td>2</td><td>1/3</td></tr><tr><td>positive</td><td>4</td><td>2/3</td></tr></tbody></table></div><h3>Step 2. Count every training word within each class</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Total tokens</th><th>amaze</th><th>disgust</th><th>great</th><th>happy</th><th>sad</th><th>terrible</th><th>wonderful</th></tr></thead><tbody><tr><td>negative</td><td>8</td><td>0</td><td>1</td><td>1</td><td>1</td><td>3</td><td>2</td><td>0</td></tr><tr><td>positive</td><td>13</td><td>2</td><td>1</td><td>4</td><td>4</td><td>0</td><td>0</td><td>2</td></tr></tbody></table></div><h3>Step 3. Count the test words</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th></tr></thead><tbody><tr><td>great</td><td>2</td></tr><tr><td>happy</td><td>1</td></tr><tr><td>disgust</td><td>1</td></tr></tbody></table></div><p>OOV words: none</p><h3>Step 4. Calculate likelihoods and multiply with the prior</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Prior</th><th>Individual factors</th><th>Exact score</th><th>Decimal score</th></tr></thead><tbody><tr><td>negative</td><td>1/3</td><td>great: (1+1)/(8+1×7) = 2/15, used 2 time(s); happy: (1+1)/(8+1×7) = 2/15, used 1 time(s); disgust: (1+1)/(8+1×7) = 2/15, used 1 time(s)</td><td>16/151875</td><td>0.000105349794239</td></tr><tr><td>positive</td><td>2/3</td><td>great: (4+1)/(13+1×7) = 1/4, used 2 time(s); happy: (4+1)/(13+1×7) = 1/4, used 1 time(s); disgust: (1+1)/(13+1×7) = 1/10, used 1 time(s)</td><td>1/960</td><td>0.00104166666667</td></tr></tbody></table></div><h3>Step 5. Compare and optionally normalize</h3><p>Normalized scores: negative = 0.091846802, positive = 0.908153198</p><p>Division by the same total does not change the winning class.</p><h3>Final answer</h3><p><strong>Predicted class: positive.</strong></p><p><strong>Yaad rakho:</strong> Count → prior → smoothed word chances → repeated factors → compare.</p>","m2":false,"units":"7","marks":10,"sourcePages":[4],"historical":true}]},{"id":"legacy-f23","title":"2023-12-01 · final · recovered AI paper","unit":"PYQ","scope":"Previous examination · complete worked answers","sections":[{"id":"q1a","title":"Q1a · WSD and pronoun resolution","html":"<div class=\"question\"><strong>Question. Define Word Sense Disambiguation and Pronoun Resolution. Give an example of each.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Word sense disambiguation (WSD) is the task of selecting the intended sense of an ambiguous word in its context from a set of possible senses.</strong> The output is a sense label, not a different replacement word.</p><div class=\"flow\"><div class=\"node\">Input: “He grilled the bass.”</div><span aria-hidden=\"true\">→</span><div class=\"node\">Candidate senses: fish / low sound</div><span aria-hidden=\"true\">→</span><div class=\"node\">Context: grilled</div><span aria-hidden=\"true\">→</span><div class=\"node\">Output: fish sense</div></div><p>The <strong>target word</strong> is the ambiguous word. The <strong>context</strong> is the surrounding evidence. The <strong>sense inventory</strong> lists candidate meanings, often using WordNet. A <strong>feature</strong> is a usable clue: nearby word, position, part-of-speech tag or a phrase.</p><table><thead><tr><th>Approach</th><th>What it needs</th><th>How it decides</th><th>Limitation</th></tr></thead><tbody><tr><td>Knowledge based</td><td>Dictionary, thesaurus or semantic graph</td><td>Definition overlap, category evidence or graph scores</td><td>Short definitions and missing knowledge</td></tr><tr><td>Supervised</td><td>Examples already labelled with senses</td><td>Learns context → sense mapping</td><td>Labelling cost, limited rare-sense examples</td></tr><tr><td>Semi-supervised</td><td>Small labelled set plus unlabelled data</td><td>Bootstraps from reliable seed examples</td><td>Early errors can spread</td></tr><tr><td>Unsupervised sense induction</td><td>Unlabelled contextual occurrences</td><td>Clusters similar contexts</td><td>Clusters are not automatically named dictionary senses</td></tr><tr><td>Neural/contextual</td><td>Learned word/context representations</td><td>Predicts or compares a context representation</td><td>Needs suitable data/model and evaluation</td></tr></tbody></table><p><strong>Bag-of-words features</strong> record nearby words while ignoring exact positions. <strong>Collocational features</strong> preserve a positional phrase such as “river bank”, “bank account”, “chocolate bar” or “bar exam”.</p><h3>Why WSD matters</h3><p>Machine translation needs the correct target-language meaning; information retrieval should distinguish river-bank travel from banking services; text-to-speech may need different pronunciations for “bass”; information extraction should avoid connecting entities through the wrong relation.</p><p class=\"cue\">WSD: same spelling ke options mein context dekh ke sahi meaning select.</p><p><strong>Pronoun resolution</strong> identifies the antecedent referred to by a pronoun. In “Rita arrived. She smiled”, she refers to Rita. WSD chooses a word meaning (bank as finance or river edge); pronoun resolution chooses a discourse entity.</p>","m2":false,"units":"5,6","marks":5,"sourcePages":[1],"historical":true},{"id":"q1b","title":"Q1b · WordNet and its hierarchy","html":"<div class=\"question\"><strong>Question. Define WordNet. Describe the WordNet hierarchy.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>WordNet is a lexical database that groups word senses into synonym sets called synsets and links them through semantic and lexical relations.</strong> It is a network of meanings, not merely a list of similar spellings.</p><p>A synset represents one concept. Its <strong>lemmas</strong> are the words that can express that concept. A <strong>gloss</strong> is a short definition, often accompanied by an example. An ambiguous word can occur in several synsets.</p><div class=\"flow\"><div class=\"node\">vehicle (general)</div><span aria-hidden=\"true\">→</span><div class=\"node\">car / automobile (same concept)</div><span aria-hidden=\"true\">→</span><div class=\"node\">sports car (specific)</div></div><p>This is a simplified teaching hierarchy, not a claim about every intermediate WordNet node. Going upward reaches hypernyms; going downward reaches hyponyms. Multiple parents can exist, so the structure need not be a single simple tree.</p><table><thead><tr><th>Operation</th><th>Meaning</th><th>Illustration</th></tr></thead><tbody><tr><td>Get senses of a word</td><td>Find candidate synsets</td><td>bank → financial sense, river-edge sense, …</td></tr><tr><td>Get lemmas</td><td>Find synonyms within one synset</td><td>car, automobile, motorcar</td></tr><tr><td>Get definition/examples</td><td>Read the gloss and uses</td><td>Choose the intended concept</td></tr><tr><td>Get hypernyms</td><td>Move to broader categories</td><td>car → vehicle</td></tr><tr><td>Get hyponyms</td><td>Move to narrower categories</td><td>vehicle → particular vehicle categories</td></tr><tr><td>Get meronyms/holonyms</td><td>Find part/whole links</td><td>car ↔ wheel</td></tr></tbody></table><h3>WordNet versus a thesaurus</h3><p>A thesaurus mainly groups related expressions for vocabulary lookup. WordNet explicitly distinguishes senses and labels relations such as hypernymy, hyponymy and meronymy. This supports WSD, query expansion, lexical similarity and semantic search.</p><h3>Three uses explained</h3><ol><li><strong>Search expansion:</strong> a query for “automobile” can retrieve relevant documents using “car”. Expansion should use the right sense.</li><li><strong>WSD:</strong> definitions of the senses of “bank” provide words that can be compared with the sentence context.</li><li><strong>Similarity:</strong> concepts near one another in an “is-a” hierarchy tend to be semantically related. Path-based measures depend on which senses were selected.</li></ol><p class=\"cue\">WordNet mein spelling ka group nahi—meaning ka synset, aur meanings ke beech labelled links.</p>","m2":false,"units":"5","marks":5,"sourcePages":[1],"historical":true},{"id":"q1c","title":"Q1c · Sentiment feature extraction","html":"<div class=\"question\"><strong>Question. Extract x₁ = log₁₀(word count), x₂ = count of positive lexicon words and x₃ = count of negative lexicon words from: “I was amazed at how the product quickly it arrived. The customer service was exceptional. The support team responded promptly and professionally. I was not sad with my decision. Overall, my experience with them was outstanding.” Positive lexicon={amazed,promptly,outstanding,great}; negative={horrible,sad,disgusting}.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>I was amazed at how the product quickly it arrived. The customer service was exceptional. The support team responded promptly and professionally. I was not sad with my decision. Overall, my experience with them was outstanding.</p><h3>To find</h3><p>The three numerical features.</p><h3>Formula: which one and why</h3><p>Use word tokens after stripping punctuation, keep stopwords, and match only the supplied lexicons. Raw lexicon counting does not automatically reverse a word under negation.</p><h3>Step 1. List and count every word</h3><div class=\"table-wrap\"><table><thead><tr><th>Position</th><th>Word</th></tr></thead><tbody><tr><td>1</td><td>i</td></tr><tr><td>2</td><td>was</td></tr><tr><td>3</td><td>amazed</td></tr><tr><td>4</td><td>at</td></tr><tr><td>5</td><td>how</td></tr><tr><td>6</td><td>the</td></tr><tr><td>7</td><td>product</td></tr><tr><td>8</td><td>quickly</td></tr><tr><td>9</td><td>it</td></tr><tr><td>10</td><td>arrived</td></tr><tr><td>11</td><td>the</td></tr><tr><td>12</td><td>customer</td></tr><tr><td>13</td><td>service</td></tr><tr><td>14</td><td>was</td></tr><tr><td>15</td><td>exceptional</td></tr><tr><td>16</td><td>the</td></tr><tr><td>17</td><td>support</td></tr><tr><td>18</td><td>team</td></tr><tr><td>19</td><td>responded</td></tr><tr><td>20</td><td>promptly</td></tr><tr><td>21</td><td>and</td></tr><tr><td>22</td><td>professionally</td></tr><tr><td>23</td><td>i</td></tr><tr><td>24</td><td>was</td></tr><tr><td>25</td><td>not</td></tr><tr><td>26</td><td>sad</td></tr><tr><td>27</td><td>with</td></tr><tr><td>28</td><td>my</td></tr><tr><td>29</td><td>decision</td></tr><tr><td>30</td><td>overall</td></tr><tr><td>31</td><td>my</td></tr><tr><td>32</td><td>experience</td></tr><tr><td>33</td><td>with</td></tr><tr><td>34</td><td>them</td></tr><tr><td>35</td><td>was</td></tr><tr><td>36</td><td>outstanding</td></tr></tbody></table></div><h3>Step 2. Apply the logarithm</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/82be852b42963d6b.svg\" alt=\"x_1=\\log_{10}36=1.556302501\" style=\"width:27.576ex;height:2.151ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 3. Count positive matches</h3><p>amazed, promptly, outstanding each occur once. great does not occur. x₂=3. exceptional is not in the supplied lexicon, so it is not counted.</p><h3>Step 4. Count negative matches</h3><p>sad occurs once; horrible and disgusting do not. x₃=1. The phrase “not sad” remains one raw negative-lexicon occurrence under the specified feature definition.</p><h3>Final answer</h3><p><strong>(x₁,x₂,x₃)=(1.556302501,3,1).</strong></p>","m2":false,"units":"2,7","marks":5,"sourcePages":[1,2],"historical":true},{"id":"q1d","title":"Q1d · Binary, multiclass and multilabel","html":"<div class=\"question\"><strong>Question. Compare binary, multiclass and multilabel supervised text classification with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Type</th><th>Allowed output</th><th>Example</th><th>Typical output rule</th></tr></thead><tbody><tr><td>Binary</td><td>One of two labels</td><td>positive OR negative review</td><td>One sigmoid or two-class softmax</td></tr><tr><td>Multiclass</td><td>Exactly one of several labels</td><td>sport OR business OR science</td><td>Softmax over mutually exclusive classes</td></tr><tr><td>Multilabel</td><td>Zero, one or several labels</td><td>Article tagged technology AND finance</td><td>Independent sigmoid per label</td></tr></tbody></table></div><p>Multiclass and multilabel differ in whether labels may coexist, not merely in the number of labels. A loss and evaluation measure must match the task.</p>","m2":false,"units":"7","marks":5,"sourcePages":[2],"historical":true},{"id":"q2a","title":"Q2a · Text corpus structure and applications","html":"<div class=\"question\"><strong>Question. Explain text-corpus structure and the applications of text corpora in NLP.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A corpus is a collection of language data assembled for study or computational use.</strong> Its plural is corpora. A corpus can contain books, news, reviews or conversations. It need not be labelled. <strong>Annotation</strong> adds linguistic information such as POS tags, entities, parse structures or sense labels.</p><table><thead><tr><th>Structure</th><th>Meaning</th><th>Use</th></tr></thead><tbody><tr><td>Plain</td><td>Collection without category labels</td><td>Word counts, language modelling</td></tr><tr><td>Categorized</td><td>Documents grouped by genre/topic</td><td>Classification</td></tr><tr><td>Overlapping categories</td><td>One document has several categories</td><td>Multi-topic news</td></tr><tr><td>Temporal</td><td>Documents indexed by time</td><td>Language change</td></tr><tr><td>Annotated</td><td>Linguistic labels attached</td><td>Tagging, parsing, WSD</td></tr><tr><td>Parallel</td><td>Aligned texts in different languages</td><td>Translation</td></tr></tbody></table><p>A <strong>tagset</strong> is the allowed label inventory. A <strong>treebank</strong> is a corpus annotated with syntax trees. <strong>Metadata</strong> records source, date, genre, language, annotation method and limitations. A common benchmark supports comparison under shared data and evaluation conditions.</p><p><strong>Raw example:</strong> “Riya works in Pune.” <strong>POS annotation:</strong> Riya/PROPN works/VERB in/ADP Pune/PROPN. <strong>NER annotation:</strong> Riya/PERSON, Pune/LOCATION. Each annotation answers a different task.</p><p>A good corpus is relevant to its domain, sufficiently representative, consistently annotated and appropriately split. More data alone do not repair duplicated examples, incorrect labels or a mismatch between training and real use.</p><p class=\"cue\">Corpus=text collection. Annotation=text ke saath labels. Metadata=collection ki information.</p><table><thead><tr><th>Resource</th><th>Contents</th><th>Typical use</th></tr></thead><tbody><tr><td>Gutenberg selection</td><td>Literary/book texts</td><td>Long-form language and vocabulary</td></tr><tr><td>Web text</td><td>Informal domain-specific text</td><td>Study usage beyond edited books</td></tr><tr><td>Chat corpus</td><td>Conversational posts</td><td>Dialogue, informal forms</td></tr><tr><td>Brown</td><td>English texts across genres</td><td>Genre comparison</td></tr><tr><td>Reuters</td><td>News with topic labels</td><td>Text classification; overlapping topics</td></tr><tr><td>Inaugural</td><td>Speeches indexed by time</td><td>Vocabulary change across years</td></tr><tr><td>Wordlist</td><td>Words/names/stopwords</td><td>Lexical filtering</td></tr><tr><td>Pronouncing dictionary</td><td>Words and phonetic forms</td><td>Speech, stress, rhyme</td></tr></tbody></table><p><strong>Gutenberg versus web/chat:</strong> book language does not represent every spelling or conversational pattern in messages. <strong>Brown versus Reuters:</strong> Brown emphasizes genres; Reuters news can have overlapping topic labels. <strong>Inaugural addresses:</strong> dates provide a time dimension.</p><p>Corpus sizes depend on version, subset and tokenization. Explain their purpose and structure rather than assuming a historical count is a permanent property.</p><p class=\"cue\">Gutenberg=books; web/chat=informal; Brown=genres; Reuters=news topics; Inaugural=time.</p><p>Word-sequence counts support n-gram language models and smoothing. POS-annotated sentences support supervised taggers. Sense-labelled contexts support Naive Bayes WSD. Word-context counts support distributional semantics and GloVe. Parallel aligned sentences support translation.</p><p>For a question asking the importance of corpora, give three points: empirical language evidence, examples for training/evaluation, and reproducible comparison. For an annotated-corpus question, define the added labels and give a concrete example. For resource comparisons, distinguish running text, lexical lists, pronunciation entries and semantic relations.</p><p class=\"cue\">Same text se task ke hisaab se counts, tags, senses ya context patterns nikaalte hain.</p>","m2":false,"units":"3","marks":10,"sourcePages":[2],"historical":true},{"id":"q2b","title":"Q2b · Lesk versus Walker and bank disambiguation","html":"<div class=\"question\"><strong>Question. Differentiate Lesk and Walker WSD. Calculate sense scores and disambiguate “bank” in “Money in this bank fetches an interest of 8% per annum.”</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>The Walker approach uses thesaurus categories as semantic evidence.</strong> Associate each candidate sense with a category. Count or weight context words that support that category. Choose the largest total.</p><div class=\"math-display\"><img src=\"math/9d7b8384c080650b.svg\" alt=\"\\operatorname{score}(s)=\\sum_{w\\in C} I(w,\\operatorname{category}(s))\" style=\"width:31.274ex;height:4.963ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/b186266d0d476166.svg\" alt=\"I=1\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span> if the supplied category mapping says the context word supports the sense, otherwise <span class=\"math-inline\"><img src=\"math/5fd951e2f99cd39c.svg\" alt=\"I=0\" style=\"width:5.289ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>. The summation symbol means add all those contributions. Weighted questions may replace 1 with a supplied weight. Category membership must be supplied or justified; it is not guessed from word frequency.</p><div class=\"example\"><p><strong>Question. Disambiguate bank using Walker scoring. Context words are money, interest, annum, fetch. The finance category supports money, interest and annum; the location category supports none of these words.</strong></p><div class=\"given\"><h4>Given</h4><p>Two categories: Finance and Location. Each supported word contributes 1.</p><h4>To find</h4><p>The two totals and selected bank sense.</p></div><h4>Formula and why it applies</h4><p>Sum the category indicators for each sense.</p><div class=\"step\"><h4>Step 1. Make a contribution table</h4><table><thead><tr><th>Word</th><th>Finance</th><th>Location</th></tr></thead><tbody><tr><td>money</td><td>1</td><td>0</td></tr><tr><td>interest</td><td>1</td><td>0</td></tr><tr><td>annum</td><td>1</td><td>0</td></tr><tr><td>fetch</td><td>0</td><td>0</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Add Finance</h4><p><span class=\"math-inline\"><img src=\"math/6a517f05661478a7.svg\" alt=\"1+1+1+0=3\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Location</h4><p><span class=\"math-inline\"><img src=\"math/79d13a087a88c477.svg\" alt=\"0+0+0+0=0\" style=\"width:16.97ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Select</h4><p>3 &gt; 0, so select the financial institution.</p></div><p class=\"answer\"><strong>Answer.</strong> Finance, with score 3 versus 0.</p></div><div class=\"example\"><p><strong>Question. Use Walker scoring for “The fisherman caught bass beside the lake.” Context {fisherman,caught,lake}. The Fish category contains all three clues; the Music category contains none.</strong></p><div class=\"given\"><h4>Given</h4><p>Fish and Music senses, binary category membership given.</p><h4>To find</h4><p>The correct bass sense.</p></div><h4>Formula and why it applies</h4><p>Score = sum of context-category matches.</p><div class=\"step\"><h4>Step 1. Record Fish matches</h4><p>fisherman → 1; caught → 1; lake → 1.</p></div><div class=\"step\"><h4>Step 2. Add Fish score</h4><p><span class=\"math-inline\"><img src=\"math/7e22dbf6b1c68d2b.svg\" alt=\"1+1+1=3\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Add Music score</h4><p><span class=\"math-inline\"><img src=\"math/f4ccd7a1f1f516c9.svg\" alt=\"0+0+0=0\" style=\"width:13.073ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Choose</h4><p>Fish has the larger score.</p></div><p class=\"answer\"><strong>Answer.</strong> Bass refers to a fish.</p></div><div class=\"example\"><p><strong>Question. Score “The player used a bat in the match.” Context {player,match}. Sport supports both words with weights 2 and 1; Animal supports neither. Use the supplied weighted Walker scheme.</strong></p><div class=\"given\"><h4>Given</h4><p>Sport weights {player:2, match:1}; Animal weights {player:0, match:0}.</p><h4>To find</h4><p>Weighted sense scores.</p></div><h4>Formula and why it applies</h4><p>Use the sum of supplied weights, not an unweighted count, because the question explicitly gives weights.</p><div class=\"step\"><h4>Step 1. Sport contribution of player</h4><p>Add 2.</p></div><div class=\"step\"><h4>Step 2. Sport contribution of match</h4><p>Add 1. Sport total = 2 + 1 = 3.</p></div><div class=\"step\"><h4>Step 3. Animal total</h4><p>0 + 0 = 0.</p></div><div class=\"step\"><h4>Step 4. Compare</h4><p>3 &gt; 0 selects the sporting implement.</p></div><p class=\"answer\"><strong>Answer.</strong> Bat is the sports implement.</p></div><p class=\"cue\">Walker: dictionary ke exact words nahi, context kis topic/category ko support karta hai woh count.</p><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Lesk</th><th>Walker/thesaurus method</th></tr></thead><tbody><tr><td>Evidence</td><td>Overlap of context with dictionary glosses</td><td>Context-word membership in semantic subject categories</td></tr><tr><td>Score</td><td>Number of shared normalized words</td><td>Number/weight of context words supporting each sense category</td></tr><tr><td>Dependency</td><td>Gloss definitions and preprocessing</td><td>Thesaurus categories and their assignments</td></tr></tbody></table></div><h3>Given</h3><p>Context is the printed sentence. No thesaurus category list is supplied.</p><h3>To find</h3><p>State the sense and give a transparent illustrative score.</p><h3>Formula: which one and why</h3><p>Declare the categories first; count only declared evidence. A numerical Walker score is not uniquely determined without the thesaurus assignments.</p><h3>Step 1. Choose explicit illustrative categories</h3><p>Assume money and interest belong to FINANCE; river, water and shore belong to RIVER. Ignore all other tokens as unassigned.</p><h3>Step 2. Count support</h3><div class=\"table-wrap\"><table><thead><tr><th>Candidate bank sense</th><th>Matching clues</th><th>Score</th></tr></thead><tbody><tr><td>Financial institution</td><td>money, interest</td><td>2</td></tr><tr><td>River edge</td><td>none</td><td>0</td></tr></tbody></table></div><h3>Step 3. Compare</h3><p>2 > 0, so choose the financial-institution sense under this stated assignment.</p><h3>Final answer</h3><p><strong>bank = financial institution.</strong> The score 2 versus 0 is conditional on the declared illustrative thesaurus, not supplied numerical data.</p><p><strong>Source / convention note.</strong> The original gives a sentence but no thesaurus/category mapping, so a unique numerical score cannot be recovered.</p>","m2":false,"units":"5","marks":10,"sourcePages":[2],"historical":true},{"id":"q3a","title":"Q3a · Hobbs algorithm and limitations","html":"<div class=\"question\"><strong>Question. Explain Hobbs’ algorithm with an example and state its limitations.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Hobbs’ algorithm is a syntax-based procedure that searches constituent parse trees in a fixed order for a compatible noun-phrase antecedent of a pronoun.</strong> The tree determines which candidates are proposed first. Agreement and other relevant constraints determine whether a proposed candidate can be accepted.</p><p>It is not simply the rule “choose the closest noun”. A nearby noun may have the wrong number, may be syntactically ineligible, or may be visited after a structurally more prominent noun. The algorithm produces a preference under the supplied parse; ambiguous language can still require context.</p><h3>The tree vocabulary you need</h3><table><thead><tr><th>Term</th><th>Meaning</th><th>Example</th></tr></thead><tbody><tr><td>NP</td><td>Noun phrase: a phrase referring to an entity</td><td>the student; Anita; they</td></tr><tr><td>S</td><td>A sentence/clause node</td><td>the node containing a subject and predicate</td></tr><tr><td>VP</td><td>Verb phrase</td><td>told Ravi that she should revise</td></tr><tr><td>X</td><td>The NP or S node currently being searched</td><td>An algorithm label, not a word</td></tr><tr><td>Path p</td><td>The branch travelled upward from the pronoun/previous X</td><td>Used to distinguish left and right subtrees</td></tr><tr><td>N-bar (N′)</td><td>The noun-centred part of an NP in a grammar using that label</td><td>The nominal-child test depends on the given tree</td></tr><tr><td>Breadth-first</td><td>Visit shallower nodes before deeper ones</td><td>Level 1 before level 2</td></tr><tr><td>Left-to-right</td><td>Visit equally deep nodes in their written/tree order</td><td>Earlier left branch before right branch</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">Locate pronoun NP</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Climb to NP/S</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Propose candidates in tree order</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Check compatibility</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Accept or continue searching</div></div><h3>The complete search procedure</h3><div class=\"step\"><h4>Step 1. Start at the pronoun</h4><p>Locate the NP immediately dominating the pronoun. “Dominating” means containing it as a descendant in the tree.</p></div><div class=\"step\"><h4>Step 2. Climb to the first NP or S</h4><p>Move upward to the first NP or S above that starting NP. Call this node X. Keep the upward path p.</p></div><div class=\"step\"><h4>Step 3. Search the left branches initially</h4><p>Below X, traverse branches to the left of p breadth-first and left-to-right. At this initial search, propose an NP only if another NP or S lies between that candidate and X. Test proposed candidates for the required agreement and constraints.</p></div><div class=\"step\"><h4>Step 4. If X is the highest sentence node, inspect earlier sentences</h4><p>Search previous sentence trees from most recent to oldest. Within each, use breadth-first, left-to-right order to propose NPs. Accept the first eligible compatible candidate, or report that no candidate was found in the available context.</p></div><div class=\"step\"><h4>Step 5. Otherwise climb again</h4><p>Move from X to the next NP or S above it. Record this new X and the path followed during the climb.</p></div><div class=\"step\"><h4>Step 6. Apply the higher-NP test</h4><p>If the new X is an NP, propose X when the path did not pass through its nominal N-bar child. Use the given parse labels; do not invent an N-bar branch missing from the question's structure.</p></div><div class=\"step\"><h4>Step 7. Search its left branches</h4><p>Traverse branches below the new X to the left of the path, breadth-first and left-to-right, proposing NPs. The special intervening-NP/S restriction belongs to the initial search in Step 3.</p></div><div class=\"step\"><h4>Step 8. If X is S, search the permitted right branches</h4><p>Search branches to the right of the path breadth-first and left-to-right. Do not descend below an encountered NP or S. Propose eligible NP candidates there.</p></div><div class=\"step\"><h4>Step 9. Repeat or stop</h4><p>Return to the highest-S check and continue the climb/search procedure until a compatible candidate is accepted or the available trees are exhausted. Record the candidate order rather than only writing an unexplained name.</p></div><h3>Why the first left search has an extra condition</h3><p>In a simple clause such as “John saw him”, the subject NP John is directly under the clause S. There is no extra NP or S between John and that S. The initial-search restriction therefore prevents casually selecting John as the ordinary local antecedent of him. Compare the reflexive “John saw himself”, which is a different grammatical case; do not treat every pronoun type as interchangeable.</p><section class=\"example\"><h3>Worked tree 1 · move to the previous sentence</h3><p class=\"question\"><strong>Question. Apply Hobbs’ search to “The student arrived. She smiled.” Assume the student is compatible with she.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree: [S [NP The student] [VP arrived]]. Current tree: [S [NP She] [VP smiled]].</p><h4>To find</h4><p>The selected antecedent and the search path.</p></div><h4>Method and why it applies</h4><p>Use the supplied constituent trees. The current sentence has no earlier candidate, so the highest-S rule activates previous-sentence search.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw both sentence structures</h4><pre aria-label=\"Two constituent trees\">Previous sentence             Current sentence\nS                             S\n├── NP: The student            ├── NP: She ← start\n└── VP: arrived                └── VP: smiled</pre></div><div class=\"step\"><h4>Step 2. Locate and climb</h4><p>Start at NP She. Its first higher NP/S is the current S. Set X to that S.</p></div><div class=\"step\"><h4>Step 3. Search left of the path</h4><p>She is the leftmost subject. No NP lies to its left in the current sentence.</p></div><div class=\"step\"><h4>Step 4. Use the highest-S rule</h4><p>This X is the highest S. Inspect the immediately preceding sentence tree.</p></div><div class=\"step\"><h4>Step 5. Propose its first NP</h4><p>Breadth-first, left-to-right finds NP The student.</p></div><div class=\"step\"><h4>Step 6. Check compatibility and accept</h4><p>The question stipulates that the student agrees with she. Accept this candidate.</p></div><div class=\"answer\"><strong>Answer.</strong> She refers to the student under the supplied assumptions.</div></section><section class=\"example\"><h3>Worked tree 2 · reject an incompatible subject</h3><p class=\"question\"><strong>Question. Resolve they in “Riya spoke to the students. They laughed.” Use a previous-sentence search and interpret they as plural.</strong></p><div class=\"given\"><h4>Given</h4><p>Previous tree has subject NP Riya, then VP spoke [PP to [NP the students]]. Current subject is NP They.</p><h4>To find</h4><p>The candidate order and accepted antecedent.</p></div><h4>Method and why it applies</h4><p>Breadth-first search favours a shallow subject, but agreement must still be applied; a first candidate is not automatically a valid answer.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Draw the useful part of the previous tree</h4><pre aria-label=\"Riya and the students constituent tree\">S\n├── NP: Riya                 ← candidate 1\n└── VP\n    ├── V: spoke\n    └── PP\n        ├── P: to\n        └── NP: the students ← candidate 2</pre></div><div class=\"step\"><h4>Step 2. Search the current sentence</h4><p>From NP They climb to its S; there is no earlier NP in “They laughed”. This is the highest S, so move to the previous tree.</p></div><div class=\"step\"><h4>Step 3. Visit Riya first</h4><p>Riya is the shallower leftmost NP. Under the stated plural interpretation, this singular candidate fails number agreement.</p></div><div class=\"step\"><h4>Step 4. Visit the students</h4><p>Continue breadth-first. The next relevant NP is the students.</p></div><div class=\"step\"><h4>Step 5. Apply number agreement</h4><p>Students is plural and is an eligible candidate. It matches plural they.</p></div><div class=\"step\"><h4>Step 6. State the resolution</h4><p>Accept the students. The method did not simply accept the first noun it saw.</p></div><div class=\"answer\"><strong>Answer.</strong> They → the students. Candidate order: Riya rejected; the students accepted.</div></section><section class=\"example\"><h3>Worked tree 3 · climb out of an embedded clause</h3><p class=\"question\"><strong>Question. Resolve she in “Anita told Ravi that she should revise.” Assume Anita is compatible with she and Ravi is not. Use the displayed parse.</strong></p><div class=\"given\"><h4>Given</h4><p>The pronoun is the subject of an embedded S inside the main VP.</p><h4>To find</h4><p>The preferred antecedent found by the climb and left-branch search.</p></div><h4>Method and why it applies</h4><p>The embedded clause has no left candidate. Climbing to the main S exposes its subject Anita as the first suitable higher-level candidate.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Show the clause structure</h4><pre aria-label=\"Embedded clause pronoun tree\">S (main)\n├── NP: Anita                  ← accepted candidate\n└── VP\n    ├── V: told\n    ├── NP: Ravi\n    └── SBAR: that\n        └── S (embedded)       ← first X\n            ├── NP: she        ← start\n            └── VP: should revise</pre></div><div class=\"step\"><h4>Step 2. Start inside the embedded clause</h4><p>From NP she climb to the embedded S. There is no candidate to the left of she within this embedded S.</p></div><div class=\"step\"><h4>Step 3. Climb to the next NP/S</h4><p>The embedded S is not the highest S. Move upward through SBAR and VP to the main S. These intermediate nodes are not NP/S search nodes.</p></div><div class=\"step\"><h4>Step 4. Search left of the upward path</h4><p>At the main S, the subject NP Anita is a shallow left candidate. The object Ravi is deeper within the VP. Breadth-first order proposes Anita first.</p></div><div class=\"step\"><h4>Step 5. Check the stated compatibility</h4><p>Anita is compatible with she by the question's assumption. Accept it; no need to choose a later incompatible candidate.</p></div><div class=\"step\"><h4>Step 6. Give the result and its limit</h4><p>This is the algorithm's result under the displayed parse and agreement assumptions. It does not prove the intention of every speaker using an otherwise ambiguous sentence.</p></div><div class=\"answer\"><strong>Answer.</strong> She → Anita under the stated tree and compatibility information.</div></section><h3>Advantages, limitations and a complete exam answer</h3><table><thead><tr><th>Advantages</th><th>Limitations</th></tr></thead><tbody><tr><td>Explicit candidate order makes the decision traceable.</td><td>Wrong parse structure can produce the wrong search order.</td></tr><tr><td>Requires no labelled coreference-training corpus for its basic rules.</td><td>World knowledge and discourse intention may override syntactic preference.</td></tr><tr><td>Uses structure rather than only surface distance.</td><td>Some ambiguous, long-distance or unusual constructions need additional treatment.</td></tr></tbody></table><p>For a longer answer, write the definition, inputs, tree notation, ordered algorithm, one labelled tree with a candidate table, final antecedent, and limitations. In a worked question show separately: candidate → why proposed → agreement result → accept/reject. Do not equate the selected candidate with a logically guaranteed interpretation when the sentence is ambiguous.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Tree order candidate deta hai; agreement usko allow/reject karta hai. Nearest noun automatically answer nahi.</p>","m2":false,"units":"6","marks":10,"sourcePages":[2],"historical":true},{"id":"q3b","title":"Q3b · Stemming and lemmatization","html":"<div class=\"question\"><strong>Question. Discuss the need for stemming, list different types of stemming, and differentiate stemming from lemmatization.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Stemming merges inflected/derived surface variants for matching and reduces vocabulary size. Types include rule/affix-removal stemmers (Porter, Snowball, Lancaster), dictionary/lookup stemmers, statistical stemmers and hybrid methods. More aggressive reduction increases both merging and overstemming risk.</p><p><strong>Stemming</strong> applies string-based rules, often stripping suffixes, to reduce related forms to a stem. The result need not be a valid dictionary word. <strong>Lemmatization</strong> uses vocabulary and morphological analysis, often with POS information, to return a dictionary lemma.</p><table><thead><tr><th>Criterion</th><th>Stemming</th><th>Lemmatization</th></tr></thead><tbody><tr><td>Basis</td><td>Surface form/suffix rules</td><td>Lexicon and morphological/POS analysis</td></tr><tr><td>Output</td><td>May be nonword, e.g. studi</td><td>Dictionary form, e.g. study</td></tr><tr><td>Context/POS</td><td>Usually little or none</td><td>Often important</td></tr><tr><td>Irregular forms</td><td>May miss went→go</td><td>Can map went→go with verb analysis</td></tr><tr><td>Cost</td><td>Generally simpler</td><td>Usually more linguistic processing</td></tr></tbody></table><p>Porter applies a sequence of suffix-removal rules subject to conditions; Snowball provides related language-specific stemming algorithms; Lancaster is often more aggressive; regex stemming uses explicit patterns; Lovins is another established stemming approach. Exact output depends on the algorithm and implementation.</p><h3>Three worked reductions</h3><ol><li><strong>studies, studying:</strong> an English stemmer may yield studi/study depending on the rule sequence; verb lemmatization aims at study. State the exact algorithm if exact outputs are asked.</li><li><strong>better:</strong> adjective-aware lemmatization can map it to good; naïve suffix removal cannot infer that irregular relation.</li><li><strong>saw:</strong> as a past-tense verb it can become see; as a cutting-tool noun it remains saw. POS and context matter.</li></ol><p><strong>Over-stemming</strong> merges forms that should remain distinct; <strong>under-stemming</strong> fails to merge related forms. Normalization can increase recall in search while losing useful distinctions, so it is a task-dependent choice.</p><p class=\"cue\">Stem = rules se cut; lemma = dictionary form, meaning/POS ka dhyan.</p>","m2":false,"units":"2","marks":10,"sourcePages":[2],"historical":true},{"id":"q4a","title":"Q4a · Lexical and vector semantics","html":"<div class=\"question\"><strong>Question. Explain lexical semantics and vector semantics with suitable examples.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A lexical relation connects words or senses by a meaning relationship.</strong> State the relation and its direction before giving the example.</p><table><thead><tr><th>Relation</th><th>Exam definition</th><th>Examples and direction</th></tr></thead><tbody><tr><td>Homonymy</td><td>The same form has unrelated meanings.</td><td>bank: financial institution / river edge; bat: animal / sports implement</td></tr><tr><td>Polysemy</td><td>One lexical item has multiple related senses.</td><td>head: body part / head of a department; paper: material / article</td></tr><tr><td>Synonymy</td><td>Different words have identical or closely similar meanings in a specified sense.</td><td>sofa / couch; automobile / car</td></tr><tr><td>Antonymy</td><td>Words have opposite meanings.</td><td>hot / cold; alive / dead; buy / sell</td></tr><tr><td>Hyponymy</td><td>A more specific concept is a type of a more general one.</td><td>rose is a flower; car is a vehicle</td></tr><tr><td>Hypernymy</td><td>A broader concept includes a more specific one.</td><td>flower is a hypernym of rose</td></tr><tr><td>Meronymy</td><td>A concept is a part of another concept.</td><td>wheel is part of car; finger is part of hand</td></tr><tr><td>Holonymy</td><td>A concept is the whole containing a part.</td><td>car is a holonym of wheel</td></tr></tbody></table><h3>How to distinguish the commonly confused pairs</h3><p>For homonymy versus polysemy, ask whether the senses share an identifiable meaning. A river bank and a financial bank are unrelated. A financial bank and a blood bank share a repository/storage idea, illustrating polysemy in the supplied notes.</p><p>For hyponymy versus meronymy, use the sentence test: <strong>“X is a kind of Y”</strong> indicates hyponymy; <strong>“X is part of Y”</strong> indicates meronymy. A wheel is not a type of car.</p><table><thead><tr><th>Expression</th><th>Correct relation</th><th>Reason</th></tr></thead><tbody><tr><td>sparrow → bird</td><td>Hyponymy</td><td>A sparrow is a kind of bird</td></tr><tr><td>bird → sparrow</td><td>Hypernymy</td><td>Bird is the broader category</td></tr><tr><td>keyboard → computer</td><td>Meronymy</td><td>Keyboard is a component</td></tr><tr><td>computer → keyboard</td><td>Holonymy</td><td>Computer is the containing whole</td></tr><tr><td>mouth of a person / mouth of a river</td><td>Polysemy</td><td>Both senses share the idea of an opening; the river use is a related extension</td></tr></tbody></table><p>Synonyms are not always interchangeable in every context or register. “Big mistake” and “large mistake” can sound different even though big and large overlap in meaning. Antonyms can be gradable (hot/cold), complementary (alive/dead) or relational converses (buy/sell).</p><p class=\"cue\">HYPO = specific type; HYPER = bigger category. MERO = part; HOLO = whole.</p><p><strong>The distributional hypothesis states that words occurring in similar contexts tend to have similar meanings or semantic behaviour.</strong> “Cat” and “dog” often occur near pet, feed and animal. Their context patterns can therefore be represented and compared numerically.</p><p>A <strong>vector</strong> is an ordered list of numbers. Each position must have a fixed meaning. For context order [pet, food, road], cat=[4,3,0] means four co-occurrences with pet, three with food, none with road. A <strong>matrix</strong> stacks vectors as rows in a table.</p><p>A <strong>word–context co-occurrence matrix</strong> records how often a target word occurs with each context word under a specified context definition. A window may be a sentence, document, or a fixed number of neighbouring tokens. State its width, direction and whether targets count themselves.</p><div class=\"flow\"><div class=\"node\">Choose target words</div><span aria-hidden=\"true\">→</span><div class=\"node\">Choose context/window</div><span aria-hidden=\"true\">→</span><div class=\"node\">Count co-occurrences</div><span aria-hidden=\"true\">→</span><div class=\"node\">Store each row as a vector</div><span aria-hidden=\"true\">→</span><div class=\"node\">Compare vectors</div></div><div class=\"example\"><p><strong>Question. Build the symmetric co-occurrence matrix for “cats eat fish” using a window of one token on either side, no self-counts and vocabulary [cats,eat,fish].</strong></p><div class=\"given\"><h4>Given</h4><p>One sentence, one occurrence of each token. Left and right adjacent tokens are contexts.</p><h4>To find</h4><p>A 3×3 target-by-context count matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/e26c85d7637ed303.svg\" alt=\"X_{ij}\" style=\"width:3.272ex;height:2.211ex\" loading=\"lazy\" decoding=\"async\"></span> counts the number of times context word <span class=\"math-inline\"><img src=\"math/7a5268d94266eaaf.svg\" alt=\"j\" style=\"width:0.932ex;height:1.957ex\" loading=\"lazy\" decoding=\"async\"></span> occurs within the chosen window of target <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Target cats</h4><p>Only eat is adjacent. Row cats = [0,1,0].</p></div><div class=\"step\"><h4>Step 2. Target eat</h4><p>cats is left and fish is right. Row eat = [1,0,1].</p></div><div class=\"step\"><h4>Step 3. Target fish</h4><p>Only eat is adjacent. Row fish = [0,1,0].</p></div><div class=\"step\"><h4>Step 4. Assemble the matrix</h4><table><thead><tr><th>Target / context</th><th>cats</th><th>eat</th><th>fish</th></tr></thead><tbody><tr><td>cats</td><td>0</td><td>1</td><td>0</td></tr><tr><td>eat</td><td>1</td><td>0</td><td>1</td></tr><tr><td>fish</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> Rows are [0,1,0], [1,0,1], [0,1,0]. The symmetry follows from the symmetric window.</p></div><div class=\"example\"><p><strong>Question. Build a target–context matrix for sentences “cats eat fish” and “dogs eat fish”. Target words are cats and dogs; context columns [eat,fish]; use the entire sentence excluding the target.</strong></p><div class=\"given\"><h4>Given</h4><p>Each sentence contains one target. Count context token occurrences.</p><h4>To find</h4><p>Two context vectors.</p></div><h4>Formula and why it applies</h4><p>Count each context word in every sentence containing the target.</p><div class=\"step\"><h4>Step 1. Count cats contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 2. Count dogs contexts</h4><p>In its sentence: eat occurs once, fish once → [1,1].</p></div><div class=\"step\"><h4>Step 3. Compare</h4><p>Both targets have identical observed context patterns in this very small corpus.</p></div><p class=\"answer\"><strong>Answer.</strong> cats=[1,1], dogs=[1,1]. This corpus supplies no context evidence to distinguish them.</p></div><div class=\"example\"><p><strong>Question. For “a b a”, use a right-only window of one token. Build the matrix with rows/columns [a,b].</strong></p><div class=\"given\"><h4>Given</h4><p>Count directed target→next-word events, not both directions.</p><h4>To find</h4><p>The co-occurrence matrix.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/584bbdf22ac0ea3c.svg\" alt=\"X_{ij}=C(\\text{target }i\\text{ immediately followed by }j)\" style=\"width:42.914ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. First target a</h4><p>Next token is b → add 1 to X(a,b).</p></div><div class=\"step\"><h4>Step 2. Target b</h4><p>Next token is a → add 1 to X(b,a).</p></div><div class=\"step\"><h4>Step 3. Final a</h4><p>No following token → no addition.</p></div><div class=\"step\"><h4>Step 4. Write matrix</h4><table><thead><tr><th>Target / next</th><th>a</th><th>b</th></tr></thead><tbody><tr><td>a</td><td>0</td><td>1</td></tr><tr><td>b</td><td>1</td><td>0</td></tr></tbody></table></div><p class=\"answer\"><strong>Answer.</strong> a=[0,1], b=[1,0]. A different context window would produce a different matrix.</p></div><p class=\"cue\">Word ka meaning: uske aas-paas kaunse words kitni baar aaye, uski number-list.</p>","m2":false,"units":"5","marks":10,"sourcePages":[2],"historical":true},{"id":"q4b","title":"Q4b · Three-document TF–IDF","html":"<div class=\"question\"><strong>Question. Calculate TF–IDF for: (1) Inflation increased unemployment (2) Company increased sales (3) Fear increased pulse.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Original text</th></tr></thead><tbody><tr><td>1</td><td>Inflation increased unemployment</td></tr><tr><td>2</td><td>Company increased sales</td></tr><tr><td>3</td><td>Fear increased pulse</td></tr></tbody></table></div><p>Stopwords: none supplied</p><h3>To find</h3><p>BoW, IDF and TF–IDF</p><h3>Formula: which one and why</h3><p>Use lowercase alphabetic tokens and exactly the stated stoplist. If no stoplist is supplied, retain function words. Adopt raw-count TF and natural-log IDF; the paper does not prescribe another TF/log convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd85ae95ce50c427.svg\" alt=\"\\mathrm{TFIDF}(w,d)=c(w,d)\\ln\\frac{N}{\\mathrm{df}(w)}\" style=\"width:31.372ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A term shared by all N documents has IDF ln(1)=0. Counts and TF–IDF weights are different representations.</p><h3>Step 1. Tokenize each document</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Tokens</th></tr></thead><tbody><tr><td>1</td><td>inflation, increased, unemployment</td></tr><tr><td>2</td><td>company, increased, sales</td></tr><tr><td>3</td><td>fear, increased, pulse</td></tr></tbody></table></div><h3>Step 2. Fix the vocabulary order</h3><p>company, fear, increased, inflation, pulse, sales, unemployment</p><h3>Step 3. Count occurrences (Bag of Words)</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>company</th><th>fear</th><th>increased</th><th>inflation</th><th>pulse</th><th>sales</th><th>unemployment</th></tr></thead><tbody><tr><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td></tr><tr><td>2</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td></tr><tr><td>3</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 4. Calculate document frequency and IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>df</th><th>N / df</th><th>ln(N/df)</th></tr></thead><tbody><tr><td>company</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>fear</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>increased</td><td>3</td><td>1</td><td>0.000000000</td></tr><tr><td>inflation</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>pulse</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>sales</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>unemployment</td><td>1</td><td>3</td><td>1.098612289</td></tr></tbody></table></div><h3>Step 5. Multiply each TF by its IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>company</th><th>fear</th><th>increased</th><th>inflation</th><th>pulse</th><th>sales</th><th>unemployment</th></tr></thead><tbody><tr><td>1</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>0.000000</td><td>0.000000</td><td>1.098612</td></tr><tr><td>2</td><td>1.098612</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>0.000000</td></tr><tr><td>3</td><td>0.000000</td><td>1.098612</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>0.000000</td><td>0.000000</td></tr></tbody></table></div><h3>Final answer</h3><p>The final table is the TF–IDF matrix in the declared vocabulary order. A different explicitly stated log base rescales all IDFs; length-normalized TF changes each document scale.</p>","m2":false,"units":"2","marks":10,"sourcePages":[2],"historical":true},{"id":"q5a","title":"Q5a · Word embeddings and CBOW","html":"<div class=\"question\"><strong>Question. Elaborate word embeddings. Explain the steps in CBOW with a suitable diagram.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A sparse representation</strong> has many zero entries and often one coordinate per vocabulary item. BoW and TF–IDF are common sparse document representations. <strong>A dense embedding</strong> has comparatively few learned real-valued coordinates; one word's properties are spread across many coordinates.</p><table><thead><tr><th>Representation</th><th>What coordinates mean</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>One-hot</td><td>One identity position per vocabulary word</td><td>Unambiguous ID</td><td>Different words are orthogonal; no learned similarity</td></tr><tr><td>Count-based context vector</td><td>Context-word co-occurrence counts</td><td>Transparent corpus evidence</td><td>Large, sparse; frequent words may dominate</td></tr><tr><td>TF–IDF document vector</td><td>Weighted vocabulary terms</td><td>Useful retrieval weighting</td><td>Word order and contextual meaning are limited</td></tr><tr><td>Dense word embedding</td><td>Learned latent features</td><td>Compact semantic/syntactic relationships</td><td>Coordinates are not generally human-labelled features</td></tr></tbody></table><p><strong>Distributional</strong> describes learning from patterns of linguistic context. <strong>Distributed</strong> describes representing an item across multiple coordinates rather than a single active identity bit. These are related but different ideas. A one-hot ID alone does not learn distributional similarity.</p><h3>Model design choices</h3><p>Choose contexts (document, sentence, fixed window), weighting (raw counts, normalization, TF–IDF-like weighting or association scores), dimensionality reduction or learned embeddings, and a similarity measure. Cosine compares direction and is less affected by length than a raw dot product; Euclidean distance also reflects magnitude.</p><p class=\"cue\">Sparse = bahut zero. Dense = chhoti learned number-list. Similar context se useful similarity seekhte hain.</p><p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>","m2":false,"units":"5","marks":10,"sourcePages":[3],"historical":true},{"id":"q5b","title":"Q5b · HMM tables and given path","html":"<div class=\"question\"><strong>Question. For the four tagged sentences below, construct transition (3 marks) and emission (3 marks) tables. Calculate the path Geeta/N will/M spot/V Rita/N, given initial P(N)=0.5, P(M)=0.25, P(V)=0.25 (4 marks).</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Given tags</th></tr></thead><tbody><tr><td>Rita can teach Will</td><td>N M V N</td></tr><tr><td>Spot will see Will</td><td>N M V N</td></tr><tr><td>Will Rita spot Geeta</td><td>N N V N</td></tr><tr><td>Geeta will pat Spot</td><td>N M V N</td></tr></tbody></table></div><p>Required path: Geeta will spot Rita / N M V N. Given initial probabilities: {'N': Fraction(1, 2), 'M': Fraction(1, 4), 'V': Fraction(1, 4)}</p><h3>To find</h3><p>Emission and transition tables and the specified tag-path joint probability</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9a06539e1ddc3c75.svg\" alt=\"P(w\\mid t)=\\frac{c(t,w)}{c(t)}\" style=\"width:17.977ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1d9ef5a8985e2f56.svg\" alt=\"P(t_j\\mid t_i)=\\frac{c(t_i,t_j)}{\\sum_kc(t_i,t_k)}\" style=\"width:23.506ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The second formula is the declared no-END convention. Reset at sentence boundaries; never create a transition from the last word of one training sentence to the first of the next.</p><h3>Step 1. Count emissions</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Total occurrences</th><th>Rita</th><th>can</th><th>teach</th><th>Will</th><th>Spot</th><th>will</th><th>see</th><th>spot</th><th>Geeta</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>9</td><td>2</td><td>0</td><td>0</td><td>3</td><td>2</td><td>0</td><td>0</td><td>0</td><td>2</td><td>0</td></tr><tr><td>M</td><td>3</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>2</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>V</td><td>4</td><td>0</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td></tr></tbody></table></div><h3>Step 2. Divide each emission by its tag count</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Rita</th><th>can</th><th>teach</th><th>Will</th><th>Spot</th><th>will</th><th>see</th><th>spot</th><th>Geeta</th><th>pat</th></tr></thead><tbody><tr><td>N</td><td>2/9</td><td>0</td><td>0</td><td>1/3</td><td>2/9</td><td>0</td><td>0</td><td>0</td><td>2/9</td><td>0</td></tr><tr><td>M</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>0</td><td>2/3</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td>V</td><td>0</td><td>0</td><td>1/4</td><td>0</td><td>0</td><td>0</td><td>1/4</td><td>1/4</td><td>0</td><td>1/4</td></tr></tbody></table></div><h3>Step 3. Count transitions inside each sentence</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Outgoing transitions</th><th>Sentence-final count</th><th>N</th><th>M</th><th>V</th></tr></thead><tbody><tr><td>N</td><td>5</td><td>4</td><td>1</td><td>3</td><td>1</td></tr><tr><td>M</td><td>3</td><td>0</td><td>0</td><td>0</td><td>3</td></tr><tr><td>V</td><td>4</td><td>0</td><td>4</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 4. Convert to a transition table</h3><div class=\"table-wrap\"><table><thead><tr><th>From / to</th><th>N</th><th>M</th><th>V</th></tr></thead><tbody><tr><td>N</td><td>1/5</td><td>3/5</td><td>1/5</td></tr><tr><td>M</td><td>0</td><td>0</td><td>1</td></tr><tr><td>V</td><td>1</td><td>0</td><td>0</td></tr></tbody></table></div><p>Here sentence-final tags are excluded from the no-END outgoing denominator. If END is explicitly modeled, divide all tag→tag and tag→END counts by the total tag count instead; the row then includes END. Do not mix denominators.</p><h3>Step 5. Multiply the given path, in order</h3><div class=\"table-wrap\"><table><thead><tr><th>Factor</th><th>Probability</th><th>Running product</th></tr></thead><tbody><tr><td>Initial N</td><td>1/2</td><td>1 × 1/2 = 1/2</td></tr><tr><td>Emit Geeta</td><td>2/9</td><td>1/2 × 2/9 = 1/9</td></tr><tr><td>Transition N→M</td><td>3/5</td><td>1/9 × 3/5 = 1/15</td></tr><tr><td>Emit will</td><td>2/3</td><td>1/15 × 2/3 = 2/45</td></tr><tr><td>Transition M→V</td><td>1</td><td>2/45 × 1 = 2/45</td></tr><tr><td>Emit spot</td><td>1/4</td><td>2/45 × 1/4 = 1/90</td></tr><tr><td>Transition V→N</td><td>1</td><td>1/90 × 1 = 1/90</td></tr><tr><td>Emit Rita</td><td>2/9</td><td>1/90 × 2/9 = 1/405</td></tr></tbody></table></div><h3>Final answer</h3><p>The two displayed probability tables are the estimated HMM. Zero means unobserved without smoothing, not logically impossible.</p><p><strong>No-END path joint probability = 1/405 = 0.00246913580247.</strong> If a normalized END-state model is explicitly adopted instead, this complete terminated sequence has probability 4/6561 = 0.000609663161103. These are different model conventions, not contradictory answers.</p>","m2":false,"units":"4","marks":10,"sourcePages":[3],"historical":true},{"id":"q6a","title":"Q6a · Text classification pipeline","html":"<div class=\"question\"><strong>Question. Explain the text-classification pipeline in detail with a suitable block diagram.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Text classification</strong> assigns a document to one or more predefined categories. Spam detection usually uses two classes; news classification may use several topics. In single-label multiclass classification, choose one of several categories. In multilabel classification, several labels may apply to the same document.</p><div class=\"flow\"><div class=\"node\">Define labels</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Prepare labelled examples</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Train representation + model</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evaluate on unseen text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Predict new labels</div></div><h3>An exam-ready pipeline</h3><table><thead><tr><th>Stage</th><th>What you do</th><th>Why it matters</th></tr></thead><tbody><tr><td>Task definition</td><td>Decide what counts as spam or which news topics exist.</td><td>Unclear labels create inconsistent training data.</td></tr><tr><td>Data collection and annotation</td><td>Collect representative examples and assign correct labels.</td><td>The model learns from these examples.</td></tr><tr><td>Split data</td><td>Separate training, validation and test data.</td><td>Test examples must not influence training choices.</td></tr><tr><td>Preprocess</td><td>Tokenize and normalise where suitable; retain meaningful negation.</td><td>Reduce irrelevant variation without deleting signal.</td></tr><tr><td>Represent</td><td>Use BoW, TF-IDF or learned embeddings.</td><td>Models need numerical features.</td></tr><tr><td>Train</td><td>Fit Naive Bayes, logistic regression or another appropriate model.</td><td>Learn how features predict categories.</td></tr><tr><td>Evaluate</td><td>Measure relevant precision, recall and F1 on held-out examples.</td><td>Accuracy alone may hide poor minority-class performance.</td></tr><tr><td>Deploy and monitor</td><td>Apply the same preprocessing and monitor changing language.</td><td>Incoming data can differ from old examples.</td></tr></tbody></table><p>Naive Bayes is especially useful for hand calculations. With a bag-of-words representation, its class score is the prior multiplied by the conditional probability of each token; repeated tokens repeat the factor. The “naive” assumption is conditional independence of features given the class, not that words are independent in real language.</p><div class=\"math-display\"><img src=\"math/6dd9b21835eaff13.svg\" alt=\"s(c)=P(c)\\prod_{w\\in V}P(w\\mid c)^{C(w,d)}\" style=\"width:28.469ex;height:4.928ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>C(w,d) counts word w in document d. C(w,c) counts it in training documents belonging to class c. N<sub>c</sub> is the total token count for class c. Add-one smoothing adds one to every vocabulary count and therefore adds |V| to the denominator. This is the same arithmetic taught for WSD, with document classes instead of senses.</p><section class=\"example\"><h3>Worked classification · two-token message</h3><p class=\"question\">A spam classifier has vocabulary {win, prize, meeting}. Priors are P(spam)=P(ham)=0.5. Spam token counts are [3,2,0]; ham counts are [0,0,5]. With add-one smoothing, classify “win prize”.</p><div class=\"given\"><strong>Given</strong><p>|V|=3; N(spam)=5; N(ham)=5; message has win once and prize once.</p><strong>To find</strong><p>Class scores and predicted label.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/81645a009f312045.svg\" alt=\"s(c)=P(c)P(\\text{win}\\mid c)P(\\text{prize}\\mid c)\" style=\"width:32.21ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>The model is multinomial Naive Bayes; multiply the two token likelihoods and the class prior.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compute the smoothed denominators</h4><div class=\"math-display\"><img src=\"math/7e931d91ea22e68e.svg\" alt=\"5+3=8\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Compute spam likelihoods</h4><div class=\"math-display\"><img src=\"math/724a47033195de19.svg\" alt=\"P(\\text{win}\\mid S)=\\frac{3+1}{8}=\\frac12\" style=\"width:24.509ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fc2cdb5225a070b5.svg\" alt=\"P(\\text{prize}\\mid S)=\\frac{2+1}{8}=\\frac38\" style=\"width:25.772ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute ham likelihoods</h4><div class=\"math-display\"><img src=\"math/4134fa5958e2a1ed.svg\" alt=\"P(\\text{win}\\mid H)=P(\\text{prize}\\mid H)=\\frac{0+1}{8}=\\frac18\" style=\"width:40.213ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Multiply the spam score</h4><div class=\"math-display\"><img src=\"math/79f02eee2a0a5ddb.svg\" alt=\"s(S)=\\frac12\\times\\frac12\\times\\frac38=\\frac{3}{32}=0.09375\" style=\"width:35.918ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Multiply the ham score</h4><div class=\"math-display\"><img src=\"math/05ad87647bbe0b7d.svg\" alt=\"s(H)=\\frac12\\times\\frac18\\times\\frac18=\\frac{1}{128}=0.0078125\" style=\"width:39.861ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Compare</h4><p>0.09375 > 0.0078125. These are unnormalised scores; the label is chosen by the larger score.</p></div><div class=\"answer\">Predicted label: spam.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Class prior × har word ki class-likelihood; sabse bada score wins.</p></section>","m2":false,"units":"7","marks":10,"sourcePages":[3],"historical":true},{"id":"q6b","title":"Q6b · VSM, TF and IDF in retrieval","html":"<div class=\"question\"><strong>Question. Define Vector Space Model, Term Frequency and Inverse Document Frequency with reference to information retrieval.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A vocabulary</strong> is the ordered collection of distinct terms allowed by a representation. Its order defines what every coordinate means. A <strong>vector</strong> is simply an ordered number-list. A <strong>document–term matrix</strong> puts one document in each row and one vocabulary term in each column.</p><p>With vocabulary [cat,dog,fish], the count vector [2,0,1] means cat appears twice, dog zero times and fish once. With [dog,cat,fish], the same text becomes [0,2,1]. A vector without its vocabulary order is incomplete.</p><table><thead><tr><th>Document</th><th>cat</th><th>dog</th><th>fish</th></tr></thead><tbody><tr><td>cat cat fish</td><td>2</td><td>0</td><td>1</td></tr><tr><td>dog fish</td><td>0</td><td>1</td><td>1</td></tr></tbody></table><p><strong>Nominal categories</strong> have no inherent order, such as cities. <strong>Ordinal categories</strong> do have an order, such as low &lt; medium &lt; high. Assigning arbitrary word IDs does not create meaningful numerical distances between words.</p><p class=\"cue\">Vector ka har box ek fixed word ka hai. Pehle column order fix, phir numbers.</p><p><strong>TF–IDF weights a term highly when it is frequent in a particular document but uncommon across the corpus.</strong> The supplied Unit 2 slides use normalized term frequency and base-10 inverse document frequency:</p><div class=\"math-display\"><img src=\"math/deca468dd207619e.svg\" alt=\"\\operatorname{TF}(t,d)=\\frac{C(t,d)}{N_d}\" style=\"width:18.362ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/dd1eb7f26551c5f0.svg\" alt=\"\\operatorname{IDF}(t)=\\log_{10}\\frac{D}{\\operatorname{df}(t)}\" style=\"width:20.345ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c3205280fe205579.svg\" alt=\"\\operatorname{TFIDF}(t,d)=\\operatorname{TF}(t,d)\\operatorname{IDF}(t).\" style=\"width:30.386ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/716cbce384bea429.svg\" alt=\"N_d\" style=\"width:2.836ex;height:1.901ex\" loading=\"lazy\" decoding=\"async\"></span> is the document's token count after the specified preprocessing; <span class=\"math-inline\"><img src=\"math/62ef1c41dad1fbc8.svg\" alt=\"D\" style=\"width:1.873ex;height:1.545ex\" loading=\"lazy\" decoding=\"async\"></span> is number of documents; <span class=\"math-inline\"><img src=\"math/92f4a76a32f5c806.svg\" alt=\"\\operatorname{df}(t)\" style=\"width:4.676ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> is the number of documents containing the term at least once. A word repeated ten times in one document contributes one to document frequency.</p><p><strong>Why the log?</strong> It compresses the ratio's scale. If a term occurs in all documents, <span class=\"math-inline\"><img src=\"math/2d65862ad68e4d56.svg\" alt=\"D/df=1\" style=\"width:9.574ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, so IDF=0 under this unsmoothed convention. Other libraries use smoothed IDF, different TF or normalization. Use the question's formula; do not silently substitute a library default.</p><div class=\"example\"><p><strong>Question. A corpus contains 10 documents. The word model appears in 2 documents and occurs 3 times in a 12-token document. Compute TF, IDF and TF–IDF using the slide convention.</strong></p><div class=\"given\"><h4>Given</h4><p>D=10, df(model)=2, C(model,d)=3, Nd=12; log base 10.</p><h4>To find</h4><p>The TF–IDF weight.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>, then multiply.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/51ccdc5dee01783f.svg\" alt=\"3/12=0.25\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Document ratio</h4><p><span class=\"math-inline\"><img src=\"math/e03ff475f4b9e538.svg\" alt=\"10/2=5\" style=\"width:8.673ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. IDF</h4><p><span class=\"math-inline\"><img src=\"math/35a02628576f1000.svg\" alt=\"\\log_{10}5\\approx0.698970\" style=\"width:17.752ex;height:2.151ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Weight</h4><p><span class=\"math-inline\"><img src=\"math/f8ed981eba287429.svg\" alt=\"0.25\\times0.698970\\approx0.174743\" style=\"width:26.9ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> TF=0.25, IDF≈0.698970, TF–IDF≈0.174743.</p></div><div class=\"example\"><p><strong>Question. A term occurs 4 times in a 20-token document and is present in all 8 corpus documents. Calculate its TF–IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>C=4, Nd=20, D=8, df=8.</p><h4>To find</h4><p>Its weight under unsmoothed base-10 IDF.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/9db57785102d90fc.svg\" alt=\"TF=C/N_d\" style=\"width:11.992ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/b7c5a7e09e1e5ec5.svg\" alt=\"IDF=\\log_{10}(D/df)\" style=\"width:19.59ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. TF</h4><p><span class=\"math-inline\"><img src=\"math/b0de7a9a9a0c728c.svg\" alt=\"4/20=0.2\" style=\"width:10.433ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. IDF</h4><p><span class=\"math-inline\"><img src=\"math/9a61d3220cb1a861.svg\" alt=\"\\log_{10}(8/8)=\\log_{10}1=0\" style=\"width:23.186ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Multiply</h4><p><span class=\"math-inline\"><img src=\"math/97ff1a04375e7994.svg\" alt=\"0.2\\times0=0\" style=\"width:10.937ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Weight 0: this term does not distinguish documents under this convention.</p></div><div class=\"example\"><p><strong>Question. Find TF–IDF vectors for D1=“cat cat dog”, D2=“dog fish”, D3=“cat fish fish”, using [cat,dog,fish], normalized TF and log10 IDF.</strong></p><div class=\"given\"><h4>Given</h4><p>No further preprocessing. Each term occurs in exactly two of the three documents.</p><h4>To find</h4><p>All three vectors.</p></div><h4>Formula and why it applies</h4><p>First count df by documents, then compute each document's TF, then multiply by its term's IDF.</p><div class=\"step\"><h4>Step 1. Common IDF</h4><p><span class=\"math-inline\"><img src=\"math/a912b37fed2477fc.svg\" alt=\"D=3\" style=\"width:6.022ex;height:1.731ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/8279f303c7e95ae1.svg\" alt=\"df(cat)=df(dog)=df(fish)=2\" style=\"width:33.461ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Each IDF <span class=\"math-inline\"><img src=\"math/fdd435a4274ddcc4.svg\" alt=\"=\\log_{10}(3/2)\\approx0.176091\" style=\"width:23.786ex;height:2.278ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. D1 term frequencies</h4><p>Length 3 → <span class=\"math-inline\"><img src=\"math/33108c032f375ccc.svg\" alt=\"[2/3,1/3,0]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. D1 weights</h4><p><span class=\"math-inline\"><img src=\"math/a969ee9cc56b474e.svg\" alt=\"[(2/3)0.176091,(1/3)0.176091,0]\\approx[0.117394,0.058697,0]\" style=\"width:56.317ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. D2 weights</h4><p>Length 2; TF <span class=\"math-inline\"><img src=\"math/3a45dfb5933f8388.svg\" alt=\"[0,1/2,1/2]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/42c4ea9d39b355c1.svg\" alt=\"\\approx[0,0.088046,0.088046]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. D3 weights</h4><p>Length 3; TF <span class=\"math-inline\"><img src=\"math/b75534a4556b2589.svg\" alt=\"[1/3,0,2/3]\" style=\"width:11.189ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Vector <span class=\"math-inline\"><img src=\"math/f530e35b75352a92.svg\" alt=\"\\approx[0.058697,0,0.117394]\" style=\"width:23.885ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> D1≈[0.117394,0.058697,0]; D2≈[0,0.088046,0.088046]; D3≈[0.058697,0,0.117394].</p></div><p class=\"cue\">TF: iss document mein kitna. IDF: poore corpus mein kitna rare. Dono multiply.</p><p><strong>Information retrieval (IR)</strong> locates and ranks items relevant to an information need, usually expressed as a query. The collection may contain documents, product descriptions or scientific papers. Retrieval estimates relevance; it does not itself establish that every retrieved claim is true.</p><div class=\"flow\"><div class=\"node\">Documents → cleaning</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Build index</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Query → same representation</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Match & rank</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Return relevant results</div></div><h3>The inverted index</h3><p>An inverted index maps a term to the documents containing it, often with positions or counts. For D1 “cats drink milk” and D2 “dogs drink water”, the posting list for drink is {D1,D2}, while milk maps only to D1. This avoids rescanning every document for every query.</p><table><thead><tr><th>Term</th><th>Posting list</th></tr></thead><tbody><tr><td>cats</td><td>D1</td></tr><tr><td>drink</td><td>D1, D2</td></tr><tr><td>milk</td><td>D1</td></tr><tr><td>dogs</td><td>D2</td></tr><tr><td>water</td><td>D2</td></tr></tbody></table><h3>Matching and ranking</h3><p>Boolean retrieval combines term membership using AND, OR and NOT. Vector-space retrieval represents documents and queries as weighted vectors, for example with TF-IDF, and compares them with cosine similarity. Learned retrieval can use dense embeddings for meaning-based matching. The representation used at query time must be compatible with the document index.</p><h3>Search engines and recommendation</h3><p>A search engine receives an explicit query and ranks matching indexed pages. A recommender may derive an implicit query from a user’s liked items or profile and retrieve similar candidates. Both require candidate retrieval and ranking, but the source of the information need differs.</p><h3>Evaluate the results</h3><p>For retrieval, TP is the number of retrieved relevant documents, FP retrieved irrelevant documents, and FN relevant documents not retrieved. Precision and recall use the same formulas as classification. Ranking measures also consider the positions of relevant items; a relevant result at rank 1 is more useful than one far below.</p><section class=\"example\"><h3>Retrieval evaluation</h3><p class=\"question\">A search system retrieves 8 documents; 6 are relevant. There are 10 relevant documents in the collection. Find precision, recall and F1.</p><div class=\"given\"><strong>Given</strong><p>Retrieved=8; relevant retrieved=6; all relevant=10.</p><strong>To find</strong><p>P, R and F1.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/58a11f3930a42815.svg\" alt=\"P=\\frac{\\text{relevant retrieved}}{\\text{retrieved}},\\quad R=\\frac{\\text{relevant retrieved}}{\\text{all relevant}}\" style=\"width:49.316ex;height:4.676ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/4743421649dff6a6.svg\" alt=\"F_1=\\frac{2PR}{P+R}\" style=\"width:12.637ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>The denominator is 8 for precision and 10 for recall because they ask different questions.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Identify the confusion counts</h4><p>TP=6; FP=8−6=2; FN=10−6=4.</p></div><div class=\"step\"><h4>Step 2. Precision</h4><div class=\"math-display\"><img src=\"math/6a30a7f6694209de.svg\" alt=\"P=\\frac68=0.75\" style=\"width:13.883ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Recall</h4><div class=\"math-display\"><img src=\"math/402ac41b5040dfdd.svg\" alt=\"R=\\frac6{10}=0.6\" style=\"width:13.901ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. F1</h4><div class=\"math-display\"><img src=\"math/aedd722bd9955777.svg\" alt=\"F_1=\\frac{2(0.75)(0.6)}{0.75+0.6}=\\frac{0.9}{1.35}=\\frac23\\approx0.666667\" style=\"width:42.764ex;height:5.041ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision=0.75, recall=0.60, F1≈0.666667.</div></section><p class=\"cue\"><strong>Yaad rakho:</strong> Precision: jo laaye, unmein kitne sahi? Recall: jo sahi the, unmein kitne laaye?</p>","m2":false,"units":"2,7","marks":10,"sourcePages":[3],"historical":true}]},{"id":"legacy-r23","title":"2023-01-30 · re-exam · recovered AI paper","unit":"PYQ","scope":"Previous examination · complete worked answers","sections":[{"id":"q1a","title":"Q1a · Normalization changes vocabulary","html":"<div class=\"question\"><strong>Question. “The vocabulary of a corpus remains the same before and after normalization.” State true or false and justify with an example.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>False in general.</strong> Vocabulary is the set of distinct tokens under a chosen tokenizer. In “Cats cats running”, raw case-sensitive vocabulary={Cats,cats,running}, size3. Lowercase merges Cats/cats: {cats,running}, size2. Lemmatization may yield {cat,run}; stopword removal can remove entries. For an already normalized corpus the set may happen to remain unchanged, so the correct claim is that normalization can change it, not that it always must.</p>","m2":false,"units":"2","marks":5,"sourcePages":[1],"historical":true},{"id":"q1b","title":"Q1b · Good corpus characteristics","html":"<div class=\"question\"><strong>Question. State the characteristics of a good corpus.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>A useful corpus is suited to its task and population: representative genres/languages, adequate size and diversity, balanced or intentionally documented sampling, reliable consistent annotations, clean encoding/tokenization, metadata and provenance, legal/ethical permission, documented train/test splits, and versioned reproducibility. “Large” alone does not imply representative. Example: a medical-tagging corpus needs clinical language and negation annotation; only movie reviews would be unsuitable.</p>","m2":false,"units":"3","marks":5,"sourcePages":[1],"historical":true},{"id":"q1c","title":"Q1c · Word2Vec versus Doc2Vec","html":"<div class=\"question\"><strong>Question. Differentiate Word2Vec and Doc2Vec.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Word2Vec</th><th>Doc2Vec</th></tr></thead><tbody><tr><td>Representation</td><td>One learned vector per word type</td><td>Learns document/paragraph vectors as well as, in variants, word vectors</td></tr><tr><td>Training</td><td>CBOW predicts centre from context; Skip-gram predicts context from centre</td><td>PV-DM combines document/context to predict words; PV-DBOW predicts sampled words from document ID</td></tr><tr><td>Unit</td><td>Word/token type</td><td>Sentence, paragraph or document</td></tr><tr><td>New text</td><td>Retrieve known word vectors; combine via a separate pooling choice</td><td>Infer a new document vector while learned model weights stay fixed</td></tr><tr><td>Use</td><td>Word similarity, features</td><td>Document similarity, retrieval or classification</td></tr></tbody></table></div><p>Averaging Word2Vec word vectors is a possible document representation, but it is not the Doc2Vec training algorithm. This older paper names Doc2Vec explicitly; the current course names word and sentence embeddings but does not explicitly list Doc2Vec.</p>","m2":false,"units":"5","marks":5,"sourcePages":[1],"historical":true},{"id":"q1d","title":"Q1d · Ambiguity in NLP","html":"<div class=\"question\"><strong>Question. Explain the types of ambiguity in NLP with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Ambiguity</strong> means an expression supports more than one interpretation. Good exam answers name the ambiguity and explain both readings.</p><table><thead><tr><th>Challenge</th><th>Example</th><th>Why a system can fail</th></tr></thead><tbody><tr><td>Lexical/sense ambiguity</td><td>bank: finance or river edge</td><td>One written word has several senses</td></tr><tr><td>Syntactic ambiguity</td><td>I saw the man with a telescope.</td><td>The telescope may modify saw or the man</td></tr><tr><td>Reference ambiguity</td><td>Riya told Neha that she won.</td><td>She may refer to either person without more context</td></tr><tr><td>Sarcasm</td><td>Great, another delay.</td><td>Literal positive word conveys frustration</td></tr><tr><td>Negation</td><td>The film was not good.</td><td>Dropping not reverses meaning</td></tr><tr><td>Domain shift</td><td>“Positive” in a medical report</td><td>Meaning/use differs by domain</td></tr><tr><td>Code mixing</td><td>Kal meeting reschedule karna.</td><td>Several languages and spelling conventions</td></tr><tr><td>Noisy text</td><td>tmrw, repeated letters, typos</td><td>Vocabulary/token boundaries become uncertain</td></tr><tr><td>Low-resource setting</td><td>Few labelled examples in a language</td><td>Models lack representative training evidence</td></tr><tr><td>Bias and privacy</td><td>Skewed data or personal details</td><td>Errors and harms can persist in deployed systems</td></tr></tbody></table><p><strong>Homophones</strong> sound alike but may differ in spelling (pair/pear). <strong>Homographs</strong> share spelling but can differ in meaning or pronunciation (lead the team / lead metal). These are different dimensions from syntactic ambiguity.</p><p>Long-distance dependencies, cultural knowledge, idioms, morphology and multilingual writing systems also complicate processing. For “kick the bucket”, literal word-by-word interpretation can miss the idiomatic meaning. For “The book that the students recommended is useful”, the verb is agrees with book across an intervening phrase.</p><p class=\"cue\">Exam mein challenge ka naam + ek sentence + dono meanings/actual failure likho.</p><p><strong>Structural ambiguity</strong> occurs when a sentence has more than one valid parse tree. In “I saw the man with a telescope”, the prepositional phrase “with a telescope” can attach to saw (the instrument I used) or to the man (the man possessing the telescope). The words and their order stay the same, but the grouping changes.</p><div class=\"table-wrap\"><table><thead><tr><th>Reading</th><th>Attachment</th><th>Meaning</th></tr></thead><tbody><tr><td>I [saw the man] [with a telescope]</td><td>PP modifies VP</td><td>I used a telescope to see the man.</td></tr><tr><td>I saw [the man with a telescope]</td><td>PP modifies NP</td><td>The man had a telescope.</td></tr></tbody></table></div><p>A parser may need context, probabilities or semantic constraints to choose between trees. A plain CFG describes permitted structures but does not itself assign a probability to each tree. Do not invent rule probabilities for an ordinary CFG question.</p><p>Lexical ambiguity also matters: book can be a noun or verb. In “Book the flight”, the imperative analysis begins S→VP, followed by VP→V NP. A parser that initially chooses book as a noun may reach a dead end and must try another permitted analysis.</p><p class=\"cue\"><strong>Yaad rakho:</strong> Same words, alag grouping → alag meaning.</p>","m2":false,"units":"1,4","marks":5,"sourcePages":[1],"historical":true},{"id":"q2a","title":"Q2a · Normalize the Tanisha–Simran passage","html":"<div class=\"question\"><strong>Question. Perform sentence segmentation, word tokenization, stopword removal, lowercasing and stemming on the following paragraph; show vocabulary before and after: “Tanisha and Simran are best friends. They play together with other friends. Tanisha likes to play badminton but Simran prefers to play online games. Tanisha wants to be a badminton player. Simran wants to become an online gamer.”</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>No stoplist/stemmer is specified. For a reproducible answer choose stoplist {and,are,they,with,other,to,but,be,a,an} after lowercase; use the Porter stemmer. Other declared lists produce different valid counts.</p><div class=\"table-wrap\"><table><thead><tr><th>Stage</th><th>Result</th></tr></thead><tbody><tr><td>Sentence segmentation</td><td>Tanisha and Simran are best friends.<br>They play together with other friends.<br>Tanisha likes to play badminton but Simran prefers to play online games.<br>Tanisha wants to be a badminton player.<br>Simran wants to become an online gamer.</td></tr><tr><td>Word tokens (punctuation omitted)</td><td>Tanisha, and, Simran, are, best, friends, They, play, together, with, other, friends, Tanisha, likes, to, play, badminton, but, Simran, prefers, to, play, online, games, Tanisha, wants, to, be, a, badminton, player, Simran, wants, to, become, an, online, gamer</td></tr><tr><td>Lowercase</td><td>tanisha, and, simran, are, best, friends, they, play, together, with, other, friends, tanisha, likes, to, play, badminton, but, simran, prefers, to, play, online, games, tanisha, wants, to, be, a, badminton, player, simran, wants, to, become, an, online, gamer</td></tr><tr><td>Declared stoplist</td><td>a, an, and, are, be, but, other, they, to, with</td></tr><tr><td>After exact stop removal</td><td>tanisha, simran, best, friends, play, together, friends, tanisha, likes, play, badminton, simran, prefers, play, online, games, tanisha, wants, badminton, player, simran, wants, become, online, gamer</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Retained word</th><th>Porter stem</th></tr></thead><tbody><tr><td>tanisha</td><td>tanisha</td></tr><tr><td>simran</td><td>simran</td></tr><tr><td>best</td><td>best</td></tr><tr><td>friends</td><td>friend</td></tr><tr><td>play</td><td>play</td></tr><tr><td>together</td><td>togeth</td></tr><tr><td>likes</td><td>like</td></tr><tr><td>badminton</td><td>badminton</td></tr><tr><td>prefers</td><td>prefer</td></tr><tr><td>online</td><td>onlin</td></tr><tr><td>games</td><td>game</td></tr><tr><td>wants</td><td>want</td></tr><tr><td>player</td><td>player</td></tr><tr><td>become</td><td>becom</td></tr><tr><td>gamer</td><td>gamer</td></tr></tbody></table></div><p>Full final token sequence: tanisha, simran, best, friend, play, togeth, friend, tanisha, like, play, badminton, simran, prefer, play, onlin, game, tanisha, want, badminton, player, simran, want, becom, onlin, gamer</p><p>Raw case-sensitive vocabulary (25): Simran, Tanisha, They, a, an, and, are, badminton, be, become, best, but, friends, gamer, games, likes, online, other, play, player, prefers, to, together, wants, with. After lowercase only: 25 distinct words. Final stem vocabulary (15): badminton, becom, best, friend, game, gamer, like, onlin, play, player, prefer, simran, tanisha, togeth, want.</p><p><strong>Source / convention note.</strong> Stoplist and stemming algorithm are choices, not supplied numerical givens; both are stated.</p>","m2":false,"units":"2","marks":10,"sourcePages":[1,2],"historical":true},{"id":"q2b","title":"Q2b · Text vectorization alternatives","html":"<div class=\"question\"><strong>Question. Define word embeddings and explain one-hot, Bag of Words, bag of n-grams and TF–IDF with advantages and disadvantages.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A sparse representation</strong> has many zero entries and often one coordinate per vocabulary item. BoW and TF–IDF are common sparse document representations. <strong>A dense embedding</strong> has comparatively few learned real-valued coordinates; one word's properties are spread across many coordinates.</p><table><thead><tr><th>Representation</th><th>What coordinates mean</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>One-hot</td><td>One identity position per vocabulary word</td><td>Unambiguous ID</td><td>Different words are orthogonal; no learned similarity</td></tr><tr><td>Count-based context vector</td><td>Context-word co-occurrence counts</td><td>Transparent corpus evidence</td><td>Large, sparse; frequent words may dominate</td></tr><tr><td>TF–IDF document vector</td><td>Weighted vocabulary terms</td><td>Useful retrieval weighting</td><td>Word order and contextual meaning are limited</td></tr><tr><td>Dense word embedding</td><td>Learned latent features</td><td>Compact semantic/syntactic relationships</td><td>Coordinates are not generally human-labelled features</td></tr></tbody></table><p><strong>Distributional</strong> describes learning from patterns of linguistic context. <strong>Distributed</strong> describes representing an item across multiple coordinates rather than a single active identity bit. These are related but different ideas. A one-hot ID alone does not learn distributional similarity.</p><h3>Model design choices</h3><p>Choose contexts (document, sentence, fixed window), weighting (raw counts, normalization, TF–IDF-like weighting or association scores), dimensionality reduction or learned embeddings, and a similarity measure. Cosine compares direction and is less affected by length than a raw dot product; Euclidean distance also reflects magnitude.</p><p class=\"cue\">Sparse = bahut zero. Dense = chhoti learned number-list. Similar context se useful similarity seekhte hain.</p><div class=\"table-wrap\"><table><thead><tr><th>Method</th><th>Construction and example</th><th>Strength</th><th>Limitation</th></tr></thead><tbody><tr><td>One-hot</td><td>One1in vocabulary coordinate: cat=(1,0,0)</td><td>Simple unique identity</td><td>Sparse; all distinct words equally distant</td></tr><tr><td>BoW</td><td>Counts per vocabulary coordinate</td><td>Simple interpretable frequency</td><td>Loses order and context</td></tr><tr><td>Bag of n-grams</td><td>Counts contiguous word groups, e.g. not good</td><td>Retains local order/phrases</td><td>Vocabulary grows; sparse unseen phrases</td></tr><tr><td>TF–IDF</td><td>Term frequency weighted by inverse document frequency</td><td>Downweights ubiquitous terms for retrieval</td><td>No contextual meaning; depends on corpus statistics</td></tr></tbody></table></div><p>Dense learned embeddings differ from these sparse count encodings: similarity may reflect learned context. Explain the representation before computing any metric.</p>","m2":false,"units":"2,5","marks":10,"sourcePages":[2],"historical":true},{"id":"q3a","title":"Q3a · Semantics, pragmatics and two ambiguities","html":"<div class=\"question\"><strong>Question. Differentiate semantics and pragmatics. Explain ambiguity in “Time flies like an arrow” and “He crushed the key to my heart”.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Semantics</strong> concerns conventional meaning and composition; <strong>pragmatics</strong> interprets an utterance using speaker intention and situation. “It is cold here” can semantically report temperature and pragmatically request closing a window.</p><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Readings / cause</th></tr></thead><tbody><tr><td>Time flies like an arrow</td><td>Ordinary reading: time(N) flies(V), with like an arrow as comparison. Alternative imperative: time(V) the flies(N) as one times an arrow; lexical-category and structural ambiguity.</td></tr><tr><td>He crushed the key to my heart</td><td>Literal key/crushing versus figurative destruction of affection or emotional access. Lexical/semantic ambiguity and metaphor need pragmatic context; there is no supplied situation proving a single intended reading.</td></tr></tbody></table></div>","m2":false,"units":"1,5,6","marks":10,"sourcePages":[2],"historical":true},{"id":"q3b","title":"Q3b · Naive Bayes text classifier","html":"<div class=\"question\"><strong>Question. Explain Naive Bayes text classification with a suitable example.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>The paper supplies no numerical training corpus for this part. The following clearly labelled illustrative corpus demonstrates the complete calculation.</p><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Training text</th><th>Class</th></tr></thead><tbody><tr><td>Chinese Beijing Chinese</td><td>yes</td></tr><tr><td>Chinese Chinese Shanghai</td><td>yes</td></tr><tr><td>Chinese Macao</td><td>yes</td></tr><tr><td>Tokyo Japan Chinese</td><td>no</td></tr></tbody></table></div><p>Test: Chinese Chinese Chinese Tokyo Japan</p><h3>To find</h3><p>Classify the test using multinomial Naive Bayes.</p><h3>Formula: which one and why</h3><p>Assume add-one smoothing unless the question supplies probabilities. Keep repeated words as repeated factors. Use training vocabulary only; ignore out-of-vocabulary words unless an unknown-token model is defined.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad88d5fb5558250.svg\" alt=\"\\mathrm{score}(c)=P(c)\\prod_{w\\in V}\\left(\\frac{c(w,c)+1}{N_c+|V|}\\right)^{c(w,d)}\" style=\"width:38.427ex;height:6.664ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Vocabulary and class priors</h3><p>V = {beijing, chinese, japan, macao, shanghai, tokyo}; |V|=6.</p><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Documents</th><th>Prior</th></tr></thead><tbody><tr><td>no</td><td>1</td><td>1/4</td></tr><tr><td>yes</td><td>3</td><td>3/4</td></tr></tbody></table></div><h3>Step 2. Count every training word within each class</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Total tokens</th><th>beijing</th><th>chinese</th><th>japan</th><th>macao</th><th>shanghai</th><th>tokyo</th></tr></thead><tbody><tr><td>no</td><td>3</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td></tr><tr><td>yes</td><td>8</td><td>1</td><td>5</td><td>0</td><td>1</td><td>1</td><td>0</td></tr></tbody></table></div><h3>Step 3. Count the test words</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th></tr></thead><tbody><tr><td>chinese</td><td>3</td></tr><tr><td>tokyo</td><td>1</td></tr><tr><td>japan</td><td>1</td></tr></tbody></table></div><p>OOV words: none</p><h3>Step 4. Calculate likelihoods and multiply with the prior</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Prior</th><th>Individual factors</th><th>Exact score</th><th>Decimal score</th></tr></thead><tbody><tr><td>no</td><td>1/4</td><td>chinese: (1+1)/(3+1×6) = 2/9, used 3 time(s); tokyo: (1+1)/(3+1×6) = 2/9, used 1 time(s); japan: (1+1)/(3+1×6) = 2/9, used 1 time(s)</td><td>8/59049</td><td>0.000135480702467</td></tr><tr><td>yes</td><td>3/4</td><td>chinese: (5+1)/(8+1×6) = 3/7, used 3 time(s); tokyo: (0+1)/(8+1×6) = 1/14, used 1 time(s); japan: (0+1)/(8+1×6) = 1/14, used 1 time(s)</td><td>81/268912</td><td>0.000301213779973</td></tr></tbody></table></div><h3>Step 5. Compare and optionally normalize</h3><p>Normalized scores: no = 0.310241388, yes = 0.689758612</p><p>Division by the same total does not change the winning class.</p><h3>Final answer</h3><p><strong>Predicted class: yes.</strong></p><p><strong>Yaad rakho:</strong> Count → prior → smoothed word chances → repeated factors → compare.</p><p><strong>Source / convention note.</strong> Chinese corpus is an authored/reused teaching illustration here; it is actual given data in F22 Q5b, not this prompt.</p>","m2":false,"units":"7","marks":10,"sourcePages":[2],"historical":true},{"id":"q4a","title":"Q4a · Jaccard, cosine and Euclidean without preprocessing","html":"<div class=\"question\"><strong>Question. Explain Jaccard, cosine and Euclidean measures. Calculate them without preprocessing for D₁=“Data is the new oil of the digital economy” and D₂=“Data is a new oil”.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Use exactly the given case and words; do not remove stopwords.</p><h3>To find</h3><p>Three measures in explicitly stated representations.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/862c39e0f08fa618.svg\" alt=\"J(A,B)=\\frac{|A\\cap B|}{|A\\cup B|},\\quad d_E(u,v)=\\sqrt{\\sum_i(u_i-v_i)^2}\" style=\"width:47.8ex;height:6.029ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Jaccard uses sets of distinct tokens. Cosine and Euclidean use raw-count BoW vectors in one shared order; do not secretly turn repeated the into a single count.</p><h3>Step 1. Build the common vocabulary and counts</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Data</th><th>is</th><th>the</th><th>new</th><th>oil</th><th>of</th><th>digital</th><th>economy</th><th>a</th></tr></thead><tbody><tr><td>D1</td><td>1</td><td>1</td><td>2</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>0</td></tr><tr><td>D2</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><h3>Step 2. Jaccard sets</h3><p>Intersection={Data,is,new,oil}, size4; union size9. J=4/9=0.444444; Jaccard distance=1−J=5/9.</p><h3>Step 3. Cosine</h3><p>Dot product=4. D1 squared length=1+1+4+1+1+1+1+1=11; D2 squared length=5. Cosine=4/√55=0.539359890.</p><h3>Step 4. Euclidean</h3><p>Coordinate differences: [0, 0, 2, 0, 0, 1, 1, 1, -1]. Sum of squares=8. Distance=√8=2.828427125. Smaller distance means greater proximity; this is a distance, not a probability.</p><h3>Final answer</h3><p><strong>Jaccard=0.444444; cosine=0.539360; Euclidean distance=2.828427.</strong></p>","m2":false,"units":"2","marks":10,"sourcePages":[2],"historical":true},{"id":"q4b","title":"Q4b · CBOW and Skip-gram","html":"<div class=\"question\"><strong>Question. Explain the CBOW and Skip-gram architectures.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>","m2":false,"units":"5","marks":10,"sourcePages":[2],"historical":true},{"id":"q5a","title":"Q5a · Password regex","html":"<div class=\"question\"><strong>Question. Write a regex for an 8–15 character password containing letters and digits, at least one uppercase letter and at least one special character from !%@*, with no other characters.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><code>^(?=.{8,15}$)(?=.*[A-Z])(?=.*[0-9])(?=.*[!%@*])[A-Za-z0-9!%@*]+$</code></p><div class=\"table-wrap\"><table><thead><tr><th>Part</th><th>Purpose</th></tr></thead><tbody><tr><td>(?=.{8,15}$)</td><td>Length8–15</td></tr><tr><td>(?=.*[A-Z])</td><td>At least one uppercase; this also meets the letter requirement</td></tr><tr><td>(?=.*[0-9])</td><td>At least one digit</td></tr><tr><td>(?=.*[!%@*])</td><td>At least one permitted special</td></tr><tr><td>[A-Za-z0-9!%@*]+</td><td>Only permitted characters, including lowercase if desired</td></tr></tbody></table></div><p>Use full-string matching. Abcdef1! passes; abcdef1! fails uppercase, Abcdefgh fails digit/special, Abc1! is too short, Abcdef1# contains forbidden #. A lowercase character is not separately required by the printed conditions.</p>","m2":false,"units":"3","marks":10,"sourcePages":[2,3],"historical":true},{"id":"q5b","title":"Q5b · Two NLP applications","html":"<div class=\"question\"><strong>Question. Briefly explain any two applications of NLP.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>1. Machine translation</h3><p>Translate meaning from source to target language using a model conditioned on the source sequence. Example: English “Where is the station?” to Hindi; word order and ambiguity require context. Train on parallel corpora and evaluate adequacy/fluency.</p><h3>2. Information extraction</h3><p>Convert text into structured entities and relations. Example: “Acme acquired Beta in 2022” becomes acquirer=Acme, acquired=Beta, year=2022. Pipeline: tokenize → NER → relation extraction → validate output with source spans.</p>","m2":false,"units":"7","marks":10,"sourcePages":[3],"historical":true},{"id":"q6a","title":"Q6a · Mention-pair model","html":"<div class=\"question\"><strong>Question. Explain the mention-pair model for reference resolution.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>A mention is a span referring to an entity. A mention-pair model classifies a pair (earlier candidate antecedent, later mention) as coreferent or not. Pairwise decisions are subsequently linked into entity clusters; a positive score alone does not ensure globally consistent clusters.</p><div class=\"flow\"><span class=\"flow-box\">Detect mentions</span> → <span class=\"flow-box\">Generate earlier candidate pairs</span> → <span class=\"flow-box\">Extract pair features</span> → <span class=\"flow-box\">Score same-entity relation</span> → <span class=\"flow-box\">Select/link antecedents</span> → <span class=\"flow-box\">Form entity clusters</span></div><ol><li>Text: “Rita bought a car. She likes it.” Detect Rita, a car, She, it.</li><li>For She, compare (Rita,She) and (a car,She). Features include person/number compatibility, animate type, syntactic role, sentence distance and lexical agreement.</li><li>Rita–She has compatible singular human features; car–She fails the ordinary inanimate reading. Select Rita.</li><li>For it, compare earlier mentions: car–it is singular/inanimate and contextually fits likes. Cluster {Rita,She} and {a car,it}.</li><li>Train a classifier on labelled mention pairs; at prediction, choose a sufficiently supported antecedent or leave a new entity. Avoid reflexive/binding violations and document leakage during evaluation.</li></ol><p>Advantages: interpretable pair features and supervised learning. Limitations: quadratic candidate growth, error propagation from mention detection, non-transitive pair predictions, and weak long-range/world-knowledge reasoning. A greedy nearest-candidate choice is not the same as a learned mention-pair model.</p>","m2":false,"units":"6","marks":10,"sourcePages":[3],"historical":true},{"id":"q6b","title":"Q6b · Classification evaluation including ROC/AUC","html":"<div class=\"question\"><strong>Question. Explain accuracy, precision, recall, F1 score, ROC and AUC.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Evaluation compares predicted results with known answers. A <strong>true positive</strong> is a correctly predicted positive; a <strong>false positive</strong> is a negative item predicted positive; a <strong>false negative</strong> is a missed positive; a <strong>true negative</strong> is a correctly rejected negative.</p><div class=\"math-display\"><img src=\"math/d9fa10a04601a634.svg\" alt=\"\\text{Precision}=\\frac{TP}{TP+FP}\" style=\"width:22.439ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/65330df51cf428ee.svg\" alt=\"\\text{Recall}=\\frac{TP}{TP+FN}\" style=\"width:19.837ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fa461c3c89d25a66.svg\" alt=\"F_1=\\frac{2PR}{P+R}=\\frac{2TP}{2TP+FP+FN}\" style=\"width:33.701ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/c35bcbb3c320de01.svg\" alt=\"\\text{Accuracy}=\\frac{TP+TN}{TP+TN+FP+FN}\" style=\"width:35.482ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Precision asks how many predicted positives were correct. Recall asks how many actual positives were found. F1 balances them by a harmonic mean. If a denominator is zero, state the convention rather than dividing by zero.</p><section class=\"example\"><h3>Example 1 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=6, FP=2, FN=4, TN=8. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=6; FP=2; FN=4; TN=8.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/16635e3dc332a6fb.svg\" alt=\"P=\\frac{6}{6+2}=0.750000\" style=\"width:22.304ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/a1b816258848d9dc.svg\" alt=\"R=\\frac{6}{6+4}=0.600000\" style=\"width:22.323ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/2de5ef4a0ac69e0e.svg\" alt=\"F_1=\\frac{12}{12+2+4}=0.666667\" style=\"width:28.076ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/8934313942e2b516.svg\" alt=\"A=\\frac{6+8}{6+2+4+8}=0.700000\" style=\"width:30.096ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 0.7500; recall 0.6000; F1 0.6667; accuracy 0.7000.</div></section><section class=\"example\"><h3>Example 2 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=9, FP=3, FN=1, TN=7. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=9; FP=3; FN=1; TN=7.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/97b392f1812900f2.svg\" alt=\"P=\\frac{9}{9+3}=0.750000\" style=\"width:22.304ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/eec2430e01f99107.svg\" alt=\"R=\\frac{9}{9+1}=0.900000\" style=\"width:22.323ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/b58f8dd0b3cf6f35.svg\" alt=\"F_1=\\frac{18}{18+3+1}=0.818182\" style=\"width:28.076ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/df21b30335e9b090.svg\" alt=\"A=\\frac{9+7}{9+3+1+7}=0.800000\" style=\"width:30.096ex;height:4.796ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 0.7500; recall 0.9000; F1 0.8182; accuracy 0.8000.</div></section><section class=\"example\"><h3>Example 3 · evaluate a classifier</h3><p class=\"question\">A binary text classifier gives TP=4, FP=0, FN=4, TN=12. Compute precision, recall, F1 and accuracy.</p><div class=\"given\"><strong>Given</strong><p>TP=4; FP=0; FN=4; TN=12.</p><strong>To find</strong><p>Four evaluation measures.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/409ab1514075c74b.svg\" alt=\"P=\\frac{TP}{TP+FP},\\quad R=\\frac{TP}{TP+FN}\" style=\"width:33.922ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/6a365832b41faf96.svg\" alt=\"F_1=\\frac{2TP}{2TP+FP+FN},\\quad A=\\frac{TP+TN}{TP+FP+FN+TN}\" style=\"width:54.773ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div><p>Use predicted positives in precision, actual positives in recall, and all examples in accuracy.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Precision</h4><div class=\"math-display\"><img src=\"math/f133094efa30d271.svg\" alt=\"P=\\frac{4}{4+0}=1.000000\" style=\"width:22.304ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Recall</h4><div class=\"math-display\"><img src=\"math/656d499e455af020.svg\" alt=\"R=\\frac{4}{4+4}=0.500000\" style=\"width:22.323ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. F1</h4><div class=\"math-display\"><img src=\"math/a2397b5600ed6ed2.svg\" alt=\"F_1=\\frac{8}{8+0+4}=0.666667\" style=\"width:26.945ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Accuracy</h4><div class=\"math-display\"><img src=\"math/1cc17a482eb72469.svg\" alt=\"A=\\frac{4+12}{4+0+4+12}=0.800000\" style=\"width:31.227ex;height:4.799ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"answer\">Precision 1.0000; recall 0.5000; F1 0.6667; accuracy 0.8000.</div></section><h3>ROC and AUC</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/81a0419dccf2b651.svg\" alt=\"\\mathrm{TPR}=\\frac{TP}{TP+FN},\\qquad\\mathrm{FPR}=\\frac{FP}{FP+TN}\" style=\"width:42.601ex;height:4.812ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A classifier produces scores. Sweep the decision threshold; at each threshold calculate TPR and FPR. Plot FPR horizontally and TPR vertically. AUC is the area under that curve, equivalently the probability that a randomly chosen positive has a higher score than a randomly chosen negative (ties conventionally contribute half). AUC1 is perfect ranking;0.5 is chance ranking. This evaluates ranking over thresholds, not the accuracy at one threshold.</p><div class=\"table-wrap\"><table><thead><tr><th>Illustrative threshold</th><th>TPR</th><th>FPR</th></tr></thead><tbody><tr><td>Above all scores</td><td>0</td><td>0</td></tr><tr><td>Middle threshold</td><td>0.8</td><td>0.2</td></tr><tr><td>Below all scores</td><td>1</td><td>1</td></tr></tbody></table></div><p>For straight segments through (0,0),(.2,.8),(1,1), trapezoid area=.2×(0+.8)/2+.8×(.8+1)/2=.08+.72=.80. These points illustrate integration; they are not supplied exam data. Precision–recall may be more informative for rare positives.</p>","m2":false,"units":"7","marks":10,"sourcePages":[3],"historical":true},{"id":"q7a","title":"Q7a · Organization and facility mentions","html":"<div class=\"question\"><strong>Question. Identify organization and facility mentions in this White House visitor passage using the supplied ACE categories: “After the 9/11 attacks, the system changed radically. Now, anyone who wants to tour the White House must apply through the office of his or her representative in Congress, which forwards the names to the White House for clearance. Once they get the green light, visitors show up at the appointed time on 15th Street between E and F Streets and join the line to enter through the southeast gate. Anyone who has flown on an airline in recent years will recognize the familiar territory of identity checks and electronic scans, although you do get to keep your shoes on. At the head of the line, rangers from the National Park Service check photo IDs against a list of names.”</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Mention in order</th><th>Type</th><th>Reason</th></tr></thead><tbody><tr><td>White House (tour)</td><td>FAC</td><td>Physical building being toured</td></tr><tr><td>office of his or her representative</td><td>ORG under administrative-office reading</td><td>Staff/organizational office receiving applications; no visit to the physical office is described</td></tr><tr><td>Congress</td><td>ORG</td><td>Legislative organization</td></tr><tr><td>White House (clearance)</td><td>ORG</td><td>Institution/staff granting clearance, a metonymic use</td></tr><tr><td>15th Street</td><td>FAC</td><td>Transport infrastructure</td></tr><tr><td>E and F Streets</td><td>FAC (two coordinated streets)</td><td>Roads, not organizations</td></tr><tr><td>southeast gate</td><td>FAC</td><td>Physical entrance component</td></tr><tr><td>an airline</td><td>ORG generic mention</td><td>Organization operating flights; generic, not a proper named company</td></tr><tr><td>National Park Service</td><td>ORG</td><td>Government agency</td></tr></tbody></table></div><p>The prompt uses ACE entity mentions: nominal/generic mentions can be included, unlike a named-only tagger. 9/11 is an event/date mention, not ORG/FAC; visitors and rangers are people. If a narrower classroom guideline asks only named entities, omit the generic office/airline/gate spans and explicitly state that convention. Context decides whether White House means building or administration.</p><p><strong>Source / convention note.</strong> Boundary and generic-mention decisions depend on the provided ACE annotation convention; the answer distinguishes them from a named-only interpretation.</p>","m2":false,"units":"4","marks":10,"sourcePages":[3,4],"historical":true},{"id":"q7b","title":"Q7b · Tagging and two complete parse trees","html":"<div class=\"question\"><strong>Question. Explain POS tagging. Tag and parse (1) John and Mary bought a refrigerator with three doors. (2) It was purchased from a very small store near their house.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>POS tagging assigns grammatical categories in context; constituency parsing groups those words hierarchically. Here with three doors modifies refrigerator; near their house modifies store. These attachments fit the natural reading; the paper gives no fixed CFG.</p><p><code>John/NNP and/CC Mary/NNP bought/VBD a/DT refrigerator/NN with/IN three/CD doors/NNS</code></p><div style=\"overflow:auto\"><figure><svg viewBox=\"0 0 750 448\" role=\"img\" aria-label=\"Constituent parse tree\" style=\"width:100%;min-width:400px\"><line x1=\"55.0\" y1=\"165\" x2=\"55.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"100\" x2=\"55.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"165\" x2=\"135.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"100\" x2=\"135.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"215.0\" y1=\"165\" x2=\"215.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"100\" x2=\"215.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"375.0\" y1=\"35\" x2=\"135.0\" y2=\"76\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"165\" x2=\"295.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"495.0\" y1=\"100\" x2=\"295.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"375.0\" y1=\"230\" x2=\"375.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"165\" x2=\"375.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"455.0\" y1=\"230\" x2=\"455.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"165\" x2=\"455.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"295\" x2=\"535.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"230\" x2=\"535.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"360\" x2=\"615.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"655.0\" y1=\"295\" x2=\"615.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"695.0\" y1=\"360\" x2=\"695.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"655.0\" y1=\"295\" x2=\"695.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"230\" x2=\"655.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"165\" x2=\"615.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"495.0\" y1=\"100\" x2=\"535.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"375.0\" y1=\"35\" x2=\"495.0\" y2=\"76\" stroke=\"#718c85\"/><text x=\"375.0\" y=\"28\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">S</text><text x=\"135.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"55.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NNP</text><text x=\"55.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">John</text><text x=\"135.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">CC</text><text x=\"135.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">and</text><text x=\"215.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NNP</text><text x=\"215.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">Mary</text><text x=\"495.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VP</text><text x=\"295.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VBD</text><text x=\"295.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">bought</text><text x=\"535.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"375.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">DT</text><text x=\"375.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">a</text><text x=\"455.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NN</text><text x=\"455.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">refrigerator</text><text x=\"615.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">PP</text><text x=\"535.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">IN</text><text x=\"535.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">with</text><text x=\"655.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"615.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">CD</text><text x=\"615.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">three</text><text x=\"695.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NNS</text><text x=\"695.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">doors</text></svg><figcaption>[S [NP [NNP John] [CC and] [NNP Mary]] [VP [VBD bought] [NP [DT a] [NN refrigerator] [PP [IN with] [NP [CD three] [NNS doors]]]]]]</figcaption></figure></div><p><code>It/PRP was/VBD purchased/VBN from/IN a/DT very/RB small/JJ store/NN near/IN their/PRP$ house/NN</code></p><div style=\"overflow:auto\"><figure><svg viewBox=\"0 0 910 578\" role=\"img\" aria-label=\"Constituent parse tree\" style=\"width:100%;min-width:400px\"><line x1=\"55.0\" y1=\"165\" x2=\"55.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"55.0\" y1=\"100\" x2=\"55.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"455.0\" y1=\"35\" x2=\"55.0\" y2=\"76\" stroke=\"#718c85\"/><line x1=\"135.0\" y1=\"165\" x2=\"135.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"495.0\" y1=\"100\" x2=\"135.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"215.0\" y1=\"230\" x2=\"215.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"165\" x2=\"215.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"295.0\" y1=\"295\" x2=\"295.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"575.0\" y1=\"230\" x2=\"295.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"375.0\" y1=\"360\" x2=\"375.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"295\" x2=\"375.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"455.0\" y1=\"425\" x2=\"455.0\" y2=\"466\" stroke=\"#718c85\"/><line x1=\"495.0\" y1=\"360\" x2=\"455.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"425\" x2=\"535.0\" y2=\"466\" stroke=\"#718c85\"/><line x1=\"495.0\" y1=\"360\" x2=\"535.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"295\" x2=\"495.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"360\" x2=\"615.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"295\" x2=\"615.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"695.0\" y1=\"425\" x2=\"695.0\" y2=\"466\" stroke=\"#718c85\"/><line x1=\"775.0\" y1=\"360\" x2=\"695.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"775.0\" y1=\"490\" x2=\"775.0\" y2=\"531\" stroke=\"#718c85\"/><line x1=\"815.0\" y1=\"425\" x2=\"775.0\" y2=\"466\" stroke=\"#718c85\"/><line x1=\"855.0\" y1=\"490\" x2=\"855.0\" y2=\"531\" stroke=\"#718c85\"/><line x1=\"815.0\" y1=\"425\" x2=\"855.0\" y2=\"466\" stroke=\"#718c85\"/><line x1=\"775.0\" y1=\"360\" x2=\"815.0\" y2=\"401\" stroke=\"#718c85\"/><line x1=\"615.0\" y1=\"295\" x2=\"775.0\" y2=\"336\" stroke=\"#718c85\"/><line x1=\"575.0\" y1=\"230\" x2=\"615.0\" y2=\"271\" stroke=\"#718c85\"/><line x1=\"535.0\" y1=\"165\" x2=\"575.0\" y2=\"206\" stroke=\"#718c85\"/><line x1=\"495.0\" y1=\"100\" x2=\"535.0\" y2=\"141\" stroke=\"#718c85\"/><line x1=\"455.0\" y1=\"35\" x2=\"495.0\" y2=\"76\" stroke=\"#718c85\"/><text x=\"455.0\" y=\"28\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">S</text><text x=\"55.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"55.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">PRP</text><text x=\"55.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">It</text><text x=\"495.0\" y=\"93\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VP</text><text x=\"135.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VBD</text><text x=\"135.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">was</text><text x=\"535.0\" y=\"158\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VP</text><text x=\"215.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">VBN</text><text x=\"215.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">purchased</text><text x=\"575.0\" y=\"223\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">PP</text><text x=\"295.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">IN</text><text x=\"295.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">from</text><text x=\"615.0\" y=\"288\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"375.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">DT</text><text x=\"375.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">a</text><text x=\"495.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">ADJP</text><text x=\"455.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">RB</text><text x=\"455.0\" y=\"483\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">very</text><text x=\"535.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">JJ</text><text x=\"535.0\" y=\"483\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">small</text><text x=\"615.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NN</text><text x=\"615.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">store</text><text x=\"775.0\" y=\"353\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">PP</text><text x=\"695.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">IN</text><text x=\"695.0\" y=\"483\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">near</text><text x=\"815.0\" y=\"418\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NP</text><text x=\"775.0\" y=\"483\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">PRP$</text><text x=\"775.0\" y=\"548\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">their</text><text x=\"855.0\" y=\"483\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">NN</text><text x=\"855.0\" y=\"548\" text-anchor=\"middle\" fill=\"#173c35\" font-family=\"Arial\" font-size=\"16\">house</text></svg><figcaption>[S [NP [PRP It]] [VP [VBD was] [VP [VBN purchased] [PP [IN from] [NP [DT a] [ADJP [RB very] [JJ small]] [NN store] [PP [IN near] [NP [PRP$ their] [NN house]]]]]]]]</figcaption></figure></div><p>The first subject is coordinated; bought is past tense. The second VP is passive auxiliary was plus past participle purchased. Very modifies small, and their is a possessive determiner.</p>","m2":false,"units":"4","marks":10,"sourcePages":[4],"historical":true}]},{"id":"legacy-f22","title":"2022-11-22 · final · recovered AI paper","unit":"PYQ","scope":"Previous examination · complete worked answers","sections":[{"id":"q1a","title":"Q1a · Need and difficulties of NLP","html":"<div class=\"question\"><strong>Question. Explain the need for NLP and the difficulties in natural language processing.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Natural language processing (NLP) is the field concerned with computational methods for analysing, interpreting and generating human language.</strong> Natural languages such as English, Hindi and Marathi evolved through human use; their meanings are not specified by the rigid rules of a programming language.</p><p>An NLP system may receive text, speech converted to text, or another linguistic representation. Its output depends on the task: a category, a tag for every word, a translated sentence, a ranked document list or a generated answer. It does not always “understand” in the human sense; its performance must be evaluated for the specific task.</p><table><thead><tr><th>Task</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>Sentiment analysis</td><td>“The service was excellent.”</td><td>Positive sentiment</td></tr><tr><td>Text classification</td><td>An email</td><td>Spam / not spam</td></tr><tr><td>POS tagging</td><td>“Birds fly.”</td><td>Birds/NOUN fly/VERB</td></tr><tr><td>Named entity recognition</td><td>“Asha joined Google in Mumbai.”</td><td>Asha: person; Google: organisation; Mumbai: location</td></tr><tr><td>Machine translation</td><td>A Hindi sentence</td><td>A corresponding English sentence</td></tr><tr><td>Information retrieval</td><td>A search query</td><td>Ranked relevant documents</td></tr><tr><td>Question answering</td><td>Question plus knowledge/context</td><td>An answer</td></tr><tr><td>Summarization</td><td>A long article</td><td>A shorter text preserving key information</td></tr></tbody></table><h3>How NLP relates to AI, ML and DL</h3><p><strong>AI</strong> is the broader study of systems performing tasks associated with intelligent behaviour. <strong>Machine learning</strong> learns patterns from data. <strong>Deep learning</strong> uses multiple trainable neural layers. NLP is an application/research field that can use hand-written rules, statistical ML or deep learning. Therefore, not every NLP system is a neural network.</p><p>Linguistics supplies knowledge about language structure. Statistics supplies uncertainty models. Computer science supplies algorithms, storage and efficient implementation. A practical NLP system combines these ideas.</p><p class=\"cue\">NLP = human language ko computational task mein badlo: label, meaning, search ya generated sentence.</p><p><strong>Ambiguity</strong> means an expression supports more than one interpretation. Good exam answers name the ambiguity and explain both readings.</p><table><thead><tr><th>Challenge</th><th>Example</th><th>Why a system can fail</th></tr></thead><tbody><tr><td>Lexical/sense ambiguity</td><td>bank: finance or river edge</td><td>One written word has several senses</td></tr><tr><td>Syntactic ambiguity</td><td>I saw the man with a telescope.</td><td>The telescope may modify saw or the man</td></tr><tr><td>Reference ambiguity</td><td>Riya told Neha that she won.</td><td>She may refer to either person without more context</td></tr><tr><td>Sarcasm</td><td>Great, another delay.</td><td>Literal positive word conveys frustration</td></tr><tr><td>Negation</td><td>The film was not good.</td><td>Dropping not reverses meaning</td></tr><tr><td>Domain shift</td><td>“Positive” in a medical report</td><td>Meaning/use differs by domain</td></tr><tr><td>Code mixing</td><td>Kal meeting reschedule karna.</td><td>Several languages and spelling conventions</td></tr><tr><td>Noisy text</td><td>tmrw, repeated letters, typos</td><td>Vocabulary/token boundaries become uncertain</td></tr><tr><td>Low-resource setting</td><td>Few labelled examples in a language</td><td>Models lack representative training evidence</td></tr><tr><td>Bias and privacy</td><td>Skewed data or personal details</td><td>Errors and harms can persist in deployed systems</td></tr></tbody></table><p><strong>Homophones</strong> sound alike but may differ in spelling (pair/pear). <strong>Homographs</strong> share spelling but can differ in meaning or pronunciation (lead the team / lead metal). These are different dimensions from syntactic ambiguity.</p><p>Long-distance dependencies, cultural knowledge, idioms, morphology and multilingual writing systems also complicate processing. For “kick the bucket”, literal word-by-word interpretation can miss the idiomatic meaning. For “The book that the students recommended is useful”, the verb is agrees with book across an intervening phrase.</p><p class=\"cue\">Exam mein challenge ka naam + ek sentence + dono meanings/actual failure likho.</p>","m2":false,"units":"1","marks":5,"sourcePages":[1],"historical":true},{"id":"q1b","title":"Q1b · Levels of language analysis","html":"<div class=\"question\"><strong>Question. Explain the levels of language analysis with examples.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>A phoneme</strong> is a sound unit that can distinguish meanings in a language, such as the /p/ and /b/ contrast in “pat” and “bat”. A phoneme is a sound, not necessarily one alphabet letter. <strong>A morpheme</strong> is the smallest meaning-bearing grammatical unit: cats = cat + plural -s; unhappy = un- + happy.</p><p><strong>A lexeme</strong> is an abstract vocabulary item grouping its inflected forms: write, writes, wrote and writing belong to WRITE. A <strong>phrase</strong> is a group of words functioning together; a <strong>clause</strong> normally contains a predicate and its associated participants; a <strong>sentence</strong> expresses a complete grammatical unit.</p><table><thead><tr><th>Level</th><th>What it analyses</th><th>Concrete example</th></tr></thead><tbody><tr><td>Phonetics / phonology</td><td>Physical sounds / sound patterns in a language</td><td>Distinguish bat from pat</td></tr><tr><td>Morphology / lexical analysis</td><td>Word structure and lexical items</td><td>un + help + ful → unhelpful</td></tr><tr><td>Syntax</td><td>Grammatical arrangement and relationships</td><td>The dog chased the cat: subject, verb, object</td></tr><tr><td>Semantics</td><td>Meaning of words and composed expressions</td><td>The dog is the chaser; the cat is chased</td></tr><tr><td>Discourse</td><td>Connections across sentences</td><td>“Riya arrived. She smiled.” → She refers to Riya</td></tr><tr><td>Pragmatics</td><td>Intended meaning in the situation</td><td>“It is cold here” may request closing the window</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">word forms</div><span aria-hidden=\"true\">→</span><div class=\"node\">grammatical structure</div><span aria-hidden=\"true\">→</span><div class=\"node\">sentence meaning</div><span aria-hidden=\"true\">→</span><div class=\"node\">cross-sentence context</div><span aria-hidden=\"true\">→</span><div class=\"node\">speaker intention</div></div><h3>Three worked interpretations</h3><p><strong>“The cats are sleeping.”</strong> Morphology identifies cat + s as plural. Syntax connects “cats” to “are sleeping”. Semantics represents animals engaged in sleeping.</p><p><strong>“Aman bought a laptop. It was expensive.”</strong> Sentence-level syntax alone does not identify “it”. Discourse connects “it” to the laptop across the sentence boundary.</p><p><strong>“Wonderful, another power cut!”</strong> The word wonderful is positive literally, but situational context can indicate sarcasm and frustration. This is a pragmatic interpretation.</p><p>The analysis levels are conceptual descriptions. Modern systems may learn several jointly rather than executing a compulsory separate module for every level.</p><p class=\"cue\">Morphology = word ke andar; syntax = sentence ka structure; semantics = meaning; discourse = sentences ka link; pragmatics = intention.</p>","m2":false,"units":"1","marks":5,"sourcePages":[1],"historical":true},{"id":"q1c","title":"Q1c · Medical chatbot","html":"<div class=\"question\"><strong>Question. Briefly explain a medical chatbot and its NLP processing.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>A medical chatbot accepts a patient’s natural-language message and provides an appropriately bounded response, such as appointment information or approved health education. It must distinguish intents and preserve symptoms, negations and durations.</p><div class=\"flow\"><span class=\"flow-box\">Patient message</span> → <span class=\"flow-box\">Tokenization + intent/entity detection</span> → <span class=\"flow-box\">Retrieve approved information</span> → <span class=\"flow-box\">Generate grounded response</span> → <span class=\"flow-box\">Escalate to clinician when needed</span></div><p>Example: “I have no fever but a cough for three days” yields cough present, fever absent and duration three days. A safe administrative bot can suggest an appointment; it must not turn uncertain text into a definitive diagnosis. Evaluate intent accuracy, entity/negation accuracy, response correctness, privacy and escalation behaviour.</p>","m2":false,"units":"7","marks":5,"sourcePages":[1],"historical":true},{"id":"q1d","title":"Q1d · Sentiment with logistic regression","html":"<div class=\"question\"><strong>Question. Explain sentiment analysis using logistic regression with an example.</strong> <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>Binary logistic regression maps text features x to a probability:</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1bbea17565b5567a.svg\" alt=\"z=w^Tx+b,\\qquad P(y=1\\mid x)=\\sigma(z)=\\frac{1}{1+e^{-z}}\" style=\"width:47.722ex;height:4.774ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use positive-word count and negative-word count as an illustrative feature vector. With x=(2,1), w=(1,−1), b=0: z=1×2+(−1)×1=1; P(positive)=1/(1+e⁻¹)=0.731059. A declared 0.5 threshold predicts positive. Fit weights from labelled reviews by minimizing cross-entropy; the hand-chosen weights here only illustrate the computation.</p><div class=\"flow\"><span class=\"flow-box\">Labelled reviews</span> → <span class=\"flow-box\">Tokenize / vectorize</span> → <span class=\"flow-box\">Fit logistic weights</span> → <span class=\"flow-box\">Probability</span> → <span class=\"flow-box\">Threshold / class</span></div>","m2":false,"units":"7","marks":5,"sourcePages":[1],"historical":true},{"id":"q2a","title":"Q2a · CBOW and Skip-gram architecture","html":"<div class=\"question\"><strong>Question. Explain CBOW and Skip-gram with suitable architecture diagrams.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Word2Vec learns dense word embeddings by predicting words from nearby context.</strong> Its two common architectures are CBOW and skip-gram. A vocabulary ID or one-hot vector is the input representation; the learned embedding table converts that identity into a short trainable vector.</p><table><thead><tr><th>Architecture</th><th>Input</th><th>Prediction</th><th>Memory cue</th></tr></thead><tbody><tr><td>CBOW</td><td>Surrounding context words</td><td>Centre/target word</td><td>Context → centre</td></tr><tr><td>Skip-gram</td><td>Centre/target word</td><td>Surrounding words</td><td>Centre → context</td></tr></tbody></table><div class=\"flow\"><div class=\"node\">CBOW: the + sat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Average context embeddings</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: cat</div></div><div class=\"flow\"><div class=\"node\">Skip-gram: cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Embedding of cat</div><span aria-hidden=\"true\">→</span><div class=\"node\">Predict: the and sat</div></div><p>For vocabulary size <span class=\"math-inline\"><img src=\"math/0ef287f11eb0a00f.svg\" alt=\"V\" style=\"width:1.74ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> and embedding dimension <span class=\"math-inline\"><img src=\"math/a2ff71daba472383.svg\" alt=\"d\" style=\"width:1.176ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>, an input one-hot row is <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>; the input embedding matrix is <span class=\"math-inline\"><img src=\"math/f3392b41ba4b84ba.svg\" alt=\"V\\times d\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; the hidden row is <span class=\"math-inline\"><img src=\"math/689036be40a9e9d7.svg\" alt=\"1\\times d\" style=\"width:5.073ex;height:1.593ex\" loading=\"lazy\" decoding=\"async\"></span>; the output matrix is <span class=\"math-inline\"><img src=\"math/058d387c1daaff14.svg\" alt=\"d\\times V\" style=\"width:5.682ex;height:1.62ex\" loading=\"lazy\" decoding=\"async\"></span>; output scores are <span class=\"math-inline\"><img src=\"math/cad69b71ff59db43.svg\" alt=\"1\\times V\" style=\"width:5.637ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span>. Multiplying a one-hot row by the embedding matrix simply selects one row.</p><div class=\"math-display\"><img src=\"math/12d30b8166786ac1.svg\" alt=\"P(w_o\\mid w_i)=\\frac{\\exp(u_{w_o}^{T}v_{w_i})}{\\sum_{w\\in V}\\exp(u_w^{T}v_{w_i})}.\" style=\"width:32.125ex;height:6.112ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6e048d845033ae63.svg\" alt=\"v_{w_i}\" style=\"width:2.954ex;height:1.594ex\" loading=\"lazy\" decoding=\"async\"></span> is the input word embedding, <span class=\"math-inline\"><img src=\"math/388d7b079b70bcfd.svg\" alt=\"u_w\" style=\"width:2.627ex;height:1.357ex\" loading=\"lazy\" decoding=\"async\"></span> an output-context embedding, and the dot product is a compatibility score. Softmax turns all scores into probabilities that sum to one. Training increases the probability of observed context words. Negative sampling or hierarchical softmax can reduce computation in larger vocabularies; use the algorithm specified by the question.</p><div class=\"example\"><p><strong>Question. For the sentence “the cat sat on mat”, generate CBOW and skip-gram training data for centre word sat with a window of one token on each side.</strong></p><div class=\"given\"><h4>Given</h4><p>Tokens indexed 1 to 5: the, cat, sat, on, mat. Centre = sat.</p><h4>To find</h4><p>The CBOW example and the skip-gram pairs.</p></div><h4>Formula and why it applies</h4><p>CBOW predicts the centre from its neighbours; skip-gram predicts each neighbour from the centre.</p><div class=\"step\"><h4>Step 1. Identify neighbours</h4><p>Left neighbour = cat; right neighbour = on. “the” and “mat” are outside this window.</p></div><div class=\"step\"><h4>Step 2. CBOW example</h4><p>Input [cat,on] → target sat.</p></div><div class=\"step\"><h4>Step 3. Skip-gram examples</h4><p>(sat,cat) and (sat,on), with first item as input and second as predicted context.</p></div><p class=\"answer\"><strong>Answer.</strong> CBOW: [cat,on]→sat. Skip-gram: sat→cat and sat→on.</p></div><div class=\"example\"><p><strong>Question. The embeddings of context words cat and on are [1,2] and [3,0]. Compute the CBOW hidden vector using mean aggregation. Output vectors for [sat,ran] are [1,0] and [0,1]. Compute softmax probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>Context embeddings [1,2], [3,0]; mean aggregation; two candidate output vectors.</p><h4>To find</h4><p>The hidden vector, logits and probabilities.</p></div><h4>Formula and why it applies</h4><p>Mean context vector <span class=\"math-inline\"><img src=\"math/8d14d18bc7e6e64e.svg\" alt=\"h=(v_1+v_2)/2\" style=\"width:15.279ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. Logit <span class=\"math-inline\"><img src=\"math/3203e6549ee39a87.svg\" alt=\"z_w=u_w^Th\" style=\"width:9.333ex;height:2.481ex\" loading=\"lazy\" decoding=\"async\"></span>. Softmax <span class=\"math-inline\"><img src=\"math/5908df64ce67fd12.svg\" alt=\"P(w)=e^{z_w}/\\sum_j e^{z_j}\" style=\"width:18.731ex;height:2.669ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Add coordinates</h4><p><span class=\"math-inline\"><img src=\"math/5e48edec2b0848fd.svg\" alt=\"[1+3,\\,2+0]=[4,2]\" style=\"width:20.242ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Divide by number of words</h4><p><span class=\"math-inline\"><img src=\"math/24cc9ba7bac967c1.svg\" alt=\"h=[4/2,2/2]=[2,1]\" style=\"width:20.915ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Compute logits</h4><p><span class=\"math-inline\"><img src=\"math/5ce861a41af2767b.svg\" alt=\"z_{sat}=1(2)+0(1)=2\" style=\"width:21.39ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/fca7b5321c9a075e.svg\" alt=\"z_{ran}=0(2)+1(1)=1\" style=\"width:21.744ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Exponentials</h4><p><span class=\"math-inline\"><img src=\"math/9ebe22f13d18b3d6.svg\" alt=\"e^2\\approx7.389056\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>; sum <span class=\"math-inline\"><img src=\"math/9d4eb33e3fa2df52.svg\" alt=\"\\approx10.107338\" style=\"width:12.067ex;height:1.579ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 5. Divide</h4><p><span class=\"math-inline\"><img src=\"math/85b24a818aa9d900.svg\" alt=\"P(sat)\\approx0.731059\" style=\"width:18.099ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/efe53e94b12751a6.svg\" alt=\"P(ran)\\approx0.268941\" style=\"width:18.599ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> h=[2,1]; sat is more probable (0.731059).</p></div><div class=\"example\"><p><strong>Question. A skip-gram centre embedding is v=[1,−1]. Output embeddings for [eat,sleep,drive] are [1,1], [0,1], [1,0]. Calculate the predicted context probabilities.</strong></p><div class=\"given\"><h4>Given</h4><p>One centre vector and three output vectors; full softmax over these three words.</p><h4>To find</h4><p>Three logits and three probabilities.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/211ede92a411f755.svg\" alt=\"z_j=u_j^Tv\" style=\"width:8.621ex;height:2.874ex\" loading=\"lazy\" decoding=\"async\"></span>, then <span class=\"math-inline\"><img src=\"math/469b017eccd019fc.svg\" alt=\"P(j)=e^{z_j}/\\sum_k e^{z_k}\" style=\"width:17.997ex;height:2.36ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Eat dot product</h4><p><span class=\"math-inline\"><img src=\"math/4c1cadf015f2425f.svg\" alt=\"1(1)+1(-1)=0\" style=\"width:16.719ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Sleep and drive dot products</h4><p><span class=\"math-inline\"><img src=\"math/4e7aa48204aedcfe.svg\" alt=\"z_{sleep}=0(1)+1(-1)=-1\" style=\"width:26.259ex;height:2.347ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/ec8f12c38d59cf41.svg\" alt=\"z_{drive}=1(1)+0(-1)=1\" style=\"width:24.603ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Exponentiate and sum</h4><p><span class=\"math-inline\"><img src=\"math/edbc4e3eb26d26ce.svg\" alt=\"e^0=1\" style=\"width:6.19ex;height:2.072ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/985133cf5ad35907.svg\" alt=\"e^{-1}\\approx0.367879\" style=\"width:14.851ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>, <span class=\"math-inline\"><img src=\"math/ca9caa03620bfec2.svg\" alt=\"e^1\\approx2.718282\" style=\"width:13.607ex;height:1.937ex\" loading=\"lazy\" decoding=\"async\"></span>. Sum <span class=\"math-inline\"><img src=\"math/308d6aae3a132ab1.svg\" alt=\"\\approx4.086161\" style=\"width:10.936ex;height:1.581ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 4. Normalize</h4><p><span class=\"math-inline\"><img src=\"math/0be039cb18c2d44a.svg\" alt=\"P(eat)\\approx0.244728\" style=\"width:18.092ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/fe584f91a1ab5142.svg\" alt=\"P(sleep)\\approx0.090031\" style=\"width:20.006ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>; <span class=\"math-inline\"><img src=\"math/b3ad8b21b03e9eb1.svg\" alt=\"P(drive)\\approx0.665241\" style=\"width:20.153ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> drive has the highest probability in this toy learned model.</p></div><p><strong>Limitations:</strong> a standard static Word2Vec vector merges a word's senses; it has limited representation of subword morphology and out-of-vocabulary words; its local prediction objective does not directly fit a full global co-occurrence table. Similarity is learned from data and is not a guarantee of factual or causal understanding.</p><p class=\"cue\">CBOW = neighbours se missing centre. Skip-gram = centre se neighbours.</p>","m2":false,"units":"5","marks":10,"sourcePages":[1],"historical":true},{"id":"q2b","title":"Q2b · Seven regex constructions","html":"<div class=\"question\"><strong>Question. Define regular expressions and their uses. Write expressions for (i) all alphabetic strings, (ii) lowercase alphabetic strings ending in b, (iii) a/b strings where each a is immediately preceded and followed by b, (iv) consecutive repeated words, (v) a line starting with an integer and ending with a word, (vi) strings containing the whole words grotto and raven, (vii) capture the first English word, handling opening punctuation.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>A regular expression specifies a pattern for matching text. NLP uses it for token extraction, cleaning, validation and rule-based entities. The following uses a Python/PCRE-like engine with lookaheads and backreferences; these extended features go beyond a strictly finite-state regular language.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Pattern</th><th>Why it works</th></tr></thead><tbody><tr><td>All alphabetic strings</td><td><code>^[A-Za-z]+$</code></td><td>Only letters; + requires at least one. Use * if empty string is allowed.</td></tr><tr><td>Lowercase strings ending in b</td><td><code>^[a-z]*b$</code></td><td>The final b is mandatory.</td></tr><tr><td>a/b strings: every a surrounded by b</td><td><code>^(?!a)(?!.*aa)(?!.*a$)[ab]*$</code></td><td>Forbid starting a, adjacent aa, ending a. Then every a has a b on both sides.</td></tr><tr><td>Two consecutive identical words</td><td><code>\\b([A-Za-z]+)\\s+\\1\\b</code></td><td>Capture word, whitespace, same captured word. Case-sensitive unless ignore-case is enabled.</td></tr><tr><td>Start with integer; end with word</td><td><code>^[0-9]+\\b.*\\b[A-Za-z]+$</code></td><td>Same line; signed integers need optional [+-].</td></tr><tr><td>Whole grotto and whole raven anywhere</td><td><code>^(?=.*\\bgrotto\\b)(?=.*\\braven\\b).*$</code></td><td>Two positive lookaheads require both whole words. Dot excludes newlines unless DOTALL.</td></tr><tr><td>Capture first word despite opening punctuation</td><td><code>^[^A-Za-z]*([A-Za-z]+(?:[\\x27’][A-Za-z]+)*)</code></td><td>Group1 is first alphabetic word, with internal apostrophes allowed.</td></tr></tbody></table></div><p>Tests: b and bab pass rule3; a, ab, ba and baab fail. “Humbert Humbert” matches rule4; “the big bug” does not. “grottos raven” fails rule6. Regex word rules are practical ASCII conventions here, not a full linguistic tokenizer.</p>","m2":false,"units":"3","marks":10,"sourcePages":[1,2],"historical":true},{"id":"q3a","title":"Q3a · Text preprocessing","html":"<div class=\"question\"><strong>Question. Explain text preprocessing with applications and examples.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Tokenization divides text into units called tokens for further processing.</strong> A token may be a word, punctuation mark, character or subword, depending on the tokenizer. <strong>Sentence segmentation</strong> identifies sentence boundaries. Tokenization is not necessarily just splitting on spaces.</p><table><thead><tr><th>Method</th><th>Example</th><th>Trade-off</th></tr></thead><tbody><tr><td>Word</td><td>“cats sleep” → [cats,sleep]</td><td>Easy to interpret; unfamiliar words can be unseen tokens</td></tr><tr><td>Character</td><td>cat → [c,a,t]</td><td>Handles spelling units; creates longer sequences</td></tr><tr><td>Subword</td><td>unhappiness → pieces such as [un,happi,ness] in an illustrative vocabulary</td><td>Balances vocabulary size and rare-word representation</td></tr><tr><td>Sentence</td><td>“Birds fly. Fish swim.” → two sentences</td><td>Abbreviations and punctuation complicate boundaries</td></tr></tbody></table><p>Actual subword splits depend on the learned vocabulary; the example is illustrative, not a universal tokenizer output. Word segmentation is especially important where spaces do not reliably separate words or in compound-rich languages.</p><div class=\"example\"><p><strong>Question. Tokenize “Dr. Rao can't come today.” into words and punctuation under this rule: preserve Dr. and can't as whole tokens, and split only the final full stop.</strong></p><div class=\"given\"><h4>Given</h4><p>The tokenization rule is explicitly supplied.</p><h4>To find</h4><p>The resulting token sequence.</p></div><h4>Formula and why it applies</h4><p>Apply the stated boundary rule; do not assume every period or apostrophe is a split point.</p><div class=\"step\"><h4>Step 1. Handle abbreviation</h4><p>Dr. remains one token.</p></div><div class=\"step\"><h4>Step 2. Handle contraction</h4><p>can't remains one token.</p></div><div class=\"step\"><h4>Step 3. Write sequence</h4><p>[Dr., Rao, can't, come, today, .]</p></div><p class=\"answer\"><strong>Answer.</strong> 6 tokens under the specified rule. Another tokenizer may legitimately produce a different sequence.</p></div><h3>Three difficult cases</h3><p><strong>New York</strong> may be two tokens but one named entity. <strong>3.14</strong> should not normally end a sentence at the decimal point. <strong>don't</strong> may remain whole or split into do + n't, depending on the tokenizer. Always state the convention when calculating counts.</p><p class=\"cue\">Token = chosen unit. Space split ko universal rule mat samajh.</p><p><strong>Normalization reduces superficial variation so comparable forms can be processed consistently.</strong> Common operations include lowercasing, Unicode normalization, appropriate spelling correction, contraction handling, and optional stemming or lemmatization.</p><p><strong>Stopwords</strong> are frequent words selected for removal for a particular task, such as the or a. Removing them may reduce feature size, but removing not, no or nor can destroy sentiment meaning. Punctuation can convey sentence boundaries, emotion or mathematical structure. Lowercasing can erase differences such as US versus us.</p><div class=\"example\"><p><strong>Question. Preprocess “The CATS are not sleeping!!!” by lowercasing, removing punctuation, removing only stopwords {the,are}, and lemmatizing plural cats→cat and sleeping→sleep.</strong></p><div class=\"given\"><h4>Given</h4><p>Operations and stopword set are fixed. Do not remove not.</p><h4>To find</h4><p>The final token list.</p></div><h4>Formula and why it applies</h4><p>Apply the requested operations in order, keeping a visible intermediate result after each transformation.</p><div class=\"step\"><h4>Step 1. Lowercase</h4><p>the cats are not sleeping!!!</p></div><div class=\"step\"><h4>Step 2. Tokenize and remove punctuation</h4><p>[the,cats,are,not,sleeping]</p></div><div class=\"step\"><h4>Step 3. Remove specified stopwords</h4><p>Remove the and are → [cats,not,sleeping].</p></div><div class=\"step\"><h4>Step 4. Lemmatize</h4><p>cats→cat; sleeping→sleep → [cat,not,sleep].</p></div><p class=\"answer\"><strong>Answer.</strong> [cat,not,sleep]. The negative meaning is retained.</p></div><h3>Task decides preprocessing</h3><p>For a simple keyword-retrieval model, removing selected function words can help. For machine translation, question answering, grammar analysis or transformer input, aggressive removal may discard necessary syntax or violate the model's expected input format. Emoji can carry sentiment; convert or retain them when relevant instead of always deleting them.</p><p class=\"cue\">Clean karna = useful signal bachake noise hatao. Har word/punctuation delete karna cleaning nahi.</p><p><strong>Stemming</strong> applies string-based rules, often stripping suffixes, to reduce related forms to a stem. The result need not be a valid dictionary word. <strong>Lemmatization</strong> uses vocabulary and morphological analysis, often with POS information, to return a dictionary lemma.</p><table><thead><tr><th>Criterion</th><th>Stemming</th><th>Lemmatization</th></tr></thead><tbody><tr><td>Basis</td><td>Surface form/suffix rules</td><td>Lexicon and morphological/POS analysis</td></tr><tr><td>Output</td><td>May be nonword, e.g. studi</td><td>Dictionary form, e.g. study</td></tr><tr><td>Context/POS</td><td>Usually little or none</td><td>Often important</td></tr><tr><td>Irregular forms</td><td>May miss went→go</td><td>Can map went→go with verb analysis</td></tr><tr><td>Cost</td><td>Generally simpler</td><td>Usually more linguistic processing</td></tr></tbody></table><p>Porter applies a sequence of suffix-removal rules subject to conditions; Snowball provides related language-specific stemming algorithms; Lancaster is often more aggressive; regex stemming uses explicit patterns; Lovins is another established stemming approach. Exact output depends on the algorithm and implementation.</p><h3>Three worked reductions</h3><ol><li><strong>studies, studying:</strong> an English stemmer may yield studi/study depending on the rule sequence; verb lemmatization aims at study. State the exact algorithm if exact outputs are asked.</li><li><strong>better:</strong> adjective-aware lemmatization can map it to good; naïve suffix removal cannot infer that irregular relation.</li><li><strong>saw:</strong> as a past-tense verb it can become see; as a cutting-tool noun it remains saw. POS and context matter.</li></ol><p><strong>Over-stemming</strong> merges forms that should remain distinct; <strong>under-stemming</strong> fails to merge related forms. Normalization can increase recall in search while losing useful distinctions, so it is a task-dependent choice.</p><p class=\"cue\">Stem = rules se cut; lemma = dictionary form, meaning/POS ka dhyan.</p>","m2":false,"units":"2","marks":10,"sourcePages":[2],"historical":true},{"id":"q3b","title":"Q3b · Penn Treebank tagging","html":"<div class=\"question\"><strong>Question. Using Penn Treebank tags, tag every word and ignore punctuation: (1) It is a nice night. (2) This crap game is over a garage in Fifty-second Street. (3) Nobody ever takes the newspapers she sells. (4) I am sitting in Mindy’s restaurant putting on the gefilte fish, which is a dish I am very fond of. (5) What flights do you have from Milwaukee to Tampa?</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Read the role of each word in its sentence. Split possessive ’s into POS; punctuation has no requested tag. The original supplies a Penn-tag annex.</p><h3>Sentence 1</h3><p><code>It/PRP is/VBZ a/DT nice/JJ night/NN</code></p><h3>Sentence 2</h3><p><code>This/DT crap/NN game/NN is/VBZ over/IN a/DT garage/NN in/IN Fifty-second/JJ Street/NNP</code></p><h3>Sentence 3</h3><p><code>Nobody/NN ever/RB takes/VBZ the/DT newspapers/NNS she/PRP sells/VBZ</code></p><h3>Sentence 4</h3><p><code>I/PRP am/VBP sitting/VBG in/IN Mindy/NNP ’s/POS restaurant/NN putting/VBG on/RP the/DT gefilte/JJ fish/NN which/WDT is/VBZ a/DT dish/NN I/PRP am/VBP very/RB fond/JJ of/IN</code></p><h3>Sentence 5</h3><p><code>What/WDT flights/NNS do/VBP you/PRP have/VB from/IN Milwaukee/NNP to/IN Tampa/NNP</code></p><div class=\"table-wrap\"><table><thead><tr><th>Tag</th><th>Meaning</th><th>Why here</th></tr></thead><tbody><tr><td>PRP</td><td>Personal pronoun</td><td>It, I, she, you</td></tr><tr><td>DT / WDT</td><td>Determiner / wh-determiner</td><td>a/the versus What before flights; which relative modifier</td></tr><tr><td>VB/VBP/VBZ/VBG</td><td>Base/non-3sg-present/3sg-present/gerund-participle</td><td>have after do; am/do; is/takes; sitting/putting</td></tr><tr><td>NN/NNS/NNP</td><td>Common singular/plural/proper noun</td><td>game/newspapers/Milwaukee</td></tr><tr><td>IN/RP</td><td>Preposition or subordinator / particle</td><td>in/over/from; on in the idiomatic putting on reading</td></tr><tr><td>JJ/RB/POS</td><td>Adjective/adverb/possessive ending</td><td>nice/very/’s</td></tr></tbody></table></div><p>Annotation ambiguities: “crap” is a noun adjunct under NN; an adjectival analysis can use JJ. “Fifty-second” may be NNP within an official street name instead of JJ; “gefilte” can be a noun adjunct in some taggers. Explain the chosen contextual reading rather than claiming all taggers must agree.</p><p><strong>Source / convention note.</strong> Context-sensitive tags and possessive tokenization are explicitly stated; reasonable corpus guidelines can differ on noun adjuncts.</p>","m2":false,"units":"4","marks":10,"sourcePages":[2],"historical":true},{"id":"q4a","title":"Q4a · Mention-pair coreference","html":"<div class=\"question\"><strong>Question. Explain the mention-pair model with a detailed example.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>A mention is a span referring to an entity. A mention-pair model classifies a pair (earlier candidate antecedent, later mention) as coreferent or not. Pairwise decisions are subsequently linked into entity clusters; a positive score alone does not ensure globally consistent clusters.</p><div class=\"flow\"><span class=\"flow-box\">Detect mentions</span> → <span class=\"flow-box\">Generate earlier candidate pairs</span> → <span class=\"flow-box\">Extract pair features</span> → <span class=\"flow-box\">Score same-entity relation</span> → <span class=\"flow-box\">Select/link antecedents</span> → <span class=\"flow-box\">Form entity clusters</span></div><ol><li>Text: “Rita bought a car. She likes it.” Detect Rita, a car, She, it.</li><li>For She, compare (Rita,She) and (a car,She). Features include person/number compatibility, animate type, syntactic role, sentence distance and lexical agreement.</li><li>Rita–She has compatible singular human features; car–She fails the ordinary inanimate reading. Select Rita.</li><li>For it, compare earlier mentions: car–it is singular/inanimate and contextually fits likes. Cluster {Rita,She} and {a car,it}.</li><li>Train a classifier on labelled mention pairs; at prediction, choose a sufficiently supported antecedent or leave a new entity. Avoid reflexive/binding violations and document leakage during evaluation.</li></ol><p>Advantages: interpretable pair features and supervised learning. Limitations: quadratic candidate growth, error propagation from mention detection, non-transitive pair predictions, and weak long-range/world-knowledge reasoning. A greedy nearest-candidate choice is not the same as a learned mention-pair model.</p>","m2":false,"units":"6","marks":10,"sourcePages":[2],"historical":true},{"id":"q4b","title":"Q4b · Text classification pipeline","html":"<div class=\"question\"><strong>Question. Explain the text-classification pipeline with a diagram.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Text classification</strong> assigns a document to one or more predefined categories. Spam detection usually uses two classes; news classification may use several topics. In single-label multiclass classification, choose one of several categories. In multilabel classification, several labels may apply to the same document.</p><div class=\"flow\"><div class=\"node\">Define labels</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Prepare labelled examples</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Train representation + model</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Evaluate on unseen text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Predict new labels</div></div><h3>An exam-ready pipeline</h3><table><thead><tr><th>Stage</th><th>What you do</th><th>Why it matters</th></tr></thead><tbody><tr><td>Task definition</td><td>Decide what counts as spam or which news topics exist.</td><td>Unclear labels create inconsistent training data.</td></tr><tr><td>Data collection and annotation</td><td>Collect representative examples and assign correct labels.</td><td>The model learns from these examples.</td></tr><tr><td>Split data</td><td>Separate training, validation and test data.</td><td>Test examples must not influence training choices.</td></tr><tr><td>Preprocess</td><td>Tokenize and normalise where suitable; retain meaningful negation.</td><td>Reduce irrelevant variation without deleting signal.</td></tr><tr><td>Represent</td><td>Use BoW, TF-IDF or learned embeddings.</td><td>Models need numerical features.</td></tr><tr><td>Train</td><td>Fit Naive Bayes, logistic regression or another appropriate model.</td><td>Learn how features predict categories.</td></tr><tr><td>Evaluate</td><td>Measure relevant precision, recall and F1 on held-out examples.</td><td>Accuracy alone may hide poor minority-class performance.</td></tr><tr><td>Deploy and monitor</td><td>Apply the same preprocessing and monitor changing language.</td><td>Incoming data can differ from old examples.</td></tr></tbody></table><p>Naive Bayes is especially useful for hand calculations. With a bag-of-words representation, its class score is the prior multiplied by the conditional probability of each token; repeated tokens repeat the factor. The “naive” assumption is conditional independence of features given the class, not that words are independent in real language.</p><div class=\"math-display\"><img src=\"math/6dd9b21835eaff13.svg\" alt=\"s(c)=P(c)\\prod_{w\\in V}P(w\\mid c)^{C(w,d)}\" style=\"width:28.469ex;height:4.928ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>C(w,d) counts word w in document d. C(w,c) counts it in training documents belonging to class c. N<sub>c</sub> is the total token count for class c. Add-one smoothing adds one to every vocabulary count and therefore adds |V| to the denominator. This is the same arithmetic taught for WSD, with document classes instead of senses.</p><section class=\"example\"><h3>Worked classification · two-token message</h3><p class=\"question\">A spam classifier has vocabulary {win, prize, meeting}. Priors are P(spam)=P(ham)=0.5. Spam token counts are [3,2,0]; ham counts are [0,0,5]. With add-one smoothing, classify “win prize”.</p><div class=\"given\"><strong>Given</strong><p>|V|=3; N(spam)=5; N(ham)=5; message has win once and prize once.</p><strong>To find</strong><p>Class scores and predicted label.</p></div><h3>Formula and why it applies</h3><div class=\"math-display\"><img src=\"math/81645a009f312045.svg\" alt=\"s(c)=P(c)P(\\text{win}\\mid c)P(\\text{prize}\\mid c)\" style=\"width:32.21ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/9ccf47e73d1f48a3.svg\" alt=\"P(w\\mid c)=\\frac{C(w,c)+1}{N_c+|V|}\" style=\"width:22.939ex;height:5.473ex\" loading=\"lazy\" decoding=\"async\"></div><p>The model is multinomial Naive Bayes; multiply the two token likelihoods and the class prior.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Compute the smoothed denominators</h4><div class=\"math-display\"><img src=\"math/7e931d91ea22e68e.svg\" alt=\"5+3=8\" style=\"width:9.176ex;height:1.692ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 2. Compute spam likelihoods</h4><div class=\"math-display\"><img src=\"math/724a47033195de19.svg\" alt=\"P(\\text{win}\\mid S)=\\frac{3+1}{8}=\\frac12\" style=\"width:24.509ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div><div class=\"math-display\"><img src=\"math/fc2cdb5225a070b5.svg\" alt=\"P(\\text{prize}\\mid S)=\\frac{2+1}{8}=\\frac38\" style=\"width:25.772ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 3. Compute ham likelihoods</h4><div class=\"math-display\"><img src=\"math/4134fa5958e2a1ed.svg\" alt=\"P(\\text{win}\\mid H)=P(\\text{prize}\\mid H)=\\frac{0+1}{8}=\\frac18\" style=\"width:40.213ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 4. Multiply the spam score</h4><div class=\"math-display\"><img src=\"math/79f02eee2a0a5ddb.svg\" alt=\"s(S)=\\frac12\\times\\frac12\\times\\frac38=\\frac{3}{32}=0.09375\" style=\"width:35.918ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 5. Multiply the ham score</h4><div class=\"math-display\"><img src=\"math/05ad87647bbe0b7d.svg\" alt=\"s(H)=\\frac12\\times\\frac18\\times\\frac18=\\frac{1}{128}=0.0078125\" style=\"width:39.861ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"step\"><h4>Step 6. Compare</h4><p>0.09375 > 0.0078125. These are unnormalised scores; the label is chosen by the larger score.</p></div><div class=\"answer\">Predicted label: spam.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Class prior × har word ki class-likelihood; sabse bada score wins.</p></section>","m2":false,"units":"7","marks":10,"sourcePages":[2],"historical":true},{"id":"q5a","title":"Q5a · Corpora and structure","html":"<div class=\"question\"><strong>Question. Define a corpus. Explain corpus types, characteristics and structure.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>A corpus is a collection of language data assembled for study or computational use.</strong> Its plural is corpora. A corpus can contain books, news, reviews or conversations. It need not be labelled. <strong>Annotation</strong> adds linguistic information such as POS tags, entities, parse structures or sense labels.</p><table><thead><tr><th>Structure</th><th>Meaning</th><th>Use</th></tr></thead><tbody><tr><td>Plain</td><td>Collection without category labels</td><td>Word counts, language modelling</td></tr><tr><td>Categorized</td><td>Documents grouped by genre/topic</td><td>Classification</td></tr><tr><td>Overlapping categories</td><td>One document has several categories</td><td>Multi-topic news</td></tr><tr><td>Temporal</td><td>Documents indexed by time</td><td>Language change</td></tr><tr><td>Annotated</td><td>Linguistic labels attached</td><td>Tagging, parsing, WSD</td></tr><tr><td>Parallel</td><td>Aligned texts in different languages</td><td>Translation</td></tr></tbody></table><p>A <strong>tagset</strong> is the allowed label inventory. A <strong>treebank</strong> is a corpus annotated with syntax trees. <strong>Metadata</strong> records source, date, genre, language, annotation method and limitations. A common benchmark supports comparison under shared data and evaluation conditions.</p><p><strong>Raw example:</strong> “Riya works in Pune.” <strong>POS annotation:</strong> Riya/PROPN works/VERB in/ADP Pune/PROPN. <strong>NER annotation:</strong> Riya/PERSON, Pune/LOCATION. Each annotation answers a different task.</p><p>A good corpus is relevant to its domain, sufficiently representative, consistently annotated and appropriately split. More data alone do not repair duplicated examples, incorrect labels or a mismatch between training and real use.</p><p class=\"cue\">Corpus=text collection. Annotation=text ke saath labels. Metadata=collection ki information.</p><table><thead><tr><th>Resource</th><th>Contents</th><th>Typical use</th></tr></thead><tbody><tr><td>Gutenberg selection</td><td>Literary/book texts</td><td>Long-form language and vocabulary</td></tr><tr><td>Web text</td><td>Informal domain-specific text</td><td>Study usage beyond edited books</td></tr><tr><td>Chat corpus</td><td>Conversational posts</td><td>Dialogue, informal forms</td></tr><tr><td>Brown</td><td>English texts across genres</td><td>Genre comparison</td></tr><tr><td>Reuters</td><td>News with topic labels</td><td>Text classification; overlapping topics</td></tr><tr><td>Inaugural</td><td>Speeches indexed by time</td><td>Vocabulary change across years</td></tr><tr><td>Wordlist</td><td>Words/names/stopwords</td><td>Lexical filtering</td></tr><tr><td>Pronouncing dictionary</td><td>Words and phonetic forms</td><td>Speech, stress, rhyme</td></tr></tbody></table><p><strong>Gutenberg versus web/chat:</strong> book language does not represent every spelling or conversational pattern in messages. <strong>Brown versus Reuters:</strong> Brown emphasizes genres; Reuters news can have overlapping topic labels. <strong>Inaugural addresses:</strong> dates provide a time dimension.</p><p>Corpus sizes depend on version, subset and tokenization. Explain their purpose and structure rather than assuming a historical count is a permanent property.</p><p class=\"cue\">Gutenberg=books; web/chat=informal; Brown=genres; Reuters=news topics; Inaugural=time.</p><p>Corpus readers expose several views. <strong>raw</strong> returns a character string, <strong>words</strong> returns token occurrences, and <strong>sents</strong> returns a list of sentences where each sentence contains tokens.</p><table><thead><tr><th>Conceptual method</th><th>Returned view</th><th>Its length counts</th></tr></thead><tbody><tr><td>fileids()</td><td>Document IDs</td><td>Files</td></tr><tr><td>raw(fileid)</td><td>Character string</td><td>Characters</td></tr><tr><td>words(fileid)</td><td>Token list</td><td>Token occurrences</td></tr><tr><td>sents(fileid)</td><td>Sentence lists</td><td>Sentences</td></tr><tr><td>categories()</td><td>Genre/topic labels</td><td>Categories</td></tr><tr><td>tagged_words(fileid)</td><td>Word–tag pairs</td><td>Annotated tokens</td></tr></tbody></table><div class=\"example\"><p><strong>Question. For sentence lists [the,cat,sleeps,.] and [the,dog,runs,.], count all tokens, sentences and lowercase alphabetic word types.</strong></p><div class=\"given\"><h4>Given</h4><p>Punctuation is included in token count but excluded from word types.</p><h4>To find</h4><p>For sentence lists [the,cat,sleeps,.] and [the,dog,runs,.], count all tokens, sentences and lowercase alphabetic word types.</p></div><h4>Formula and why it applies</h4><p>Count every token occurrence, then distinct alphabetic forms. Different counting rules give different totals.</p><div class=\"step\"><h4>Step 1. Token count</h4><p>4+4=8.</p></div><div class=\"step\"><h4>Step 2. Sentence count</h4><p>Two outer lists → 2.</p></div><div class=\"step\"><h4>Step 3. Types</h4><p>{the,cat,sleeps,dog,runs} → 5.</p></div><p class=\"answer\"><strong>Answer.</strong> 8 tokens, 2 sentences, 5 word types.</p></div><p>For “Cats run. Dogs sleep.”, a reader may return six tokens including two periods, but only four alphabetic word tokens. State the convention before calculating TTR or probabilities.</p><p class=\"cue\">raw=characters, words=tokens, sents=sentences. Teen alag counts.</p>","m2":false,"units":"3","marks":10,"sourcePages":[2],"historical":true},{"id":"q5b","title":"Q5b · Multinomial Naive Bayes","html":"<div class=\"question\"><strong>Question. Explain Naive Bayes for text classification. Using the four documents below, classify “Chinese Chinese Chinese Tokyo Japan”: Chinese Beijing Chinese=yes; Chinese Chinese Shanghai=yes; Chinese Macao=yes; Tokyo Japan Chinese=no.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Multinomial NB assumes token draws are conditionally independent given the class; it combines the class prior and class-specific word probabilities. Repeated Chinese contributes its likelihood three times.</p><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Training text</th><th>Class</th></tr></thead><tbody><tr><td>Chinese Beijing Chinese</td><td>yes</td></tr><tr><td>Chinese Chinese Shanghai</td><td>yes</td></tr><tr><td>Chinese Macao</td><td>yes</td></tr><tr><td>Tokyo Japan Chinese</td><td>no</td></tr></tbody></table></div><p>Test: Chinese Chinese Chinese Tokyo Japan</p><h3>To find</h3><p>Classify the test using multinomial Naive Bayes.</p><h3>Formula: which one and why</h3><p>Assume add-one smoothing unless the question supplies probabilities. Keep repeated words as repeated factors. Use training vocabulary only; ignore out-of-vocabulary words unless an unknown-token model is defined.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad88d5fb5558250.svg\" alt=\"\\mathrm{score}(c)=P(c)\\prod_{w\\in V}\\left(\\frac{c(w,c)+1}{N_c+|V|}\\right)^{c(w,d)}\" style=\"width:38.427ex;height:6.664ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Vocabulary and class priors</h3><p>V = {beijing, chinese, japan, macao, shanghai, tokyo}; |V|=6.</p><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Documents</th><th>Prior</th></tr></thead><tbody><tr><td>no</td><td>1</td><td>1/4</td></tr><tr><td>yes</td><td>3</td><td>3/4</td></tr></tbody></table></div><h3>Step 2. Count every training word within each class</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Total tokens</th><th>beijing</th><th>chinese</th><th>japan</th><th>macao</th><th>shanghai</th><th>tokyo</th></tr></thead><tbody><tr><td>no</td><td>3</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td></tr><tr><td>yes</td><td>8</td><td>1</td><td>5</td><td>0</td><td>1</td><td>1</td><td>0</td></tr></tbody></table></div><h3>Step 3. Count the test words</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Count</th></tr></thead><tbody><tr><td>chinese</td><td>3</td></tr><tr><td>tokyo</td><td>1</td></tr><tr><td>japan</td><td>1</td></tr></tbody></table></div><p>OOV words: none</p><h3>Step 4. Calculate likelihoods and multiply with the prior</h3><div class=\"table-wrap\"><table><thead><tr><th>Class</th><th>Prior</th><th>Individual factors</th><th>Exact score</th><th>Decimal score</th></tr></thead><tbody><tr><td>no</td><td>1/4</td><td>chinese: (1+1)/(3+1×6) = 2/9, used 3 time(s); tokyo: (1+1)/(3+1×6) = 2/9, used 1 time(s); japan: (1+1)/(3+1×6) = 2/9, used 1 time(s)</td><td>8/59049</td><td>0.000135480702467</td></tr><tr><td>yes</td><td>3/4</td><td>chinese: (5+1)/(8+1×6) = 3/7, used 3 time(s); tokyo: (0+1)/(8+1×6) = 1/14, used 1 time(s); japan: (0+1)/(8+1×6) = 1/14, used 1 time(s)</td><td>81/268912</td><td>0.000301213779973</td></tr></tbody></table></div><h3>Step 5. Compare and optionally normalize</h3><p>Normalized scores: no = 0.310241388, yes = 0.689758612</p><p>Division by the same total does not change the winning class.</p><h3>Final answer</h3><p><strong>Predicted class: yes.</strong></p><p><strong>Yaad rakho:</strong> Count → prior → smoothed word chances → repeated factors → compare.</p>","m2":false,"units":"7","marks":10,"sourcePages":[2,3],"historical":true},{"id":"q6a","title":"Q6a · GloVe","html":"<div class=\"question\"><strong>Question. Explain GloVe word embeddings.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>GloVe (Global Vectors) learns word embeddings by fitting weighted relationships in a global word–context co-occurrence matrix.</strong> Word2Vec uses local prediction examples; GloVe uses aggregate counts directly in its objective.</p><div class=\"math-display\"><img src=\"math/678c585ed4cafa14.svg\" alt=\"X_i=\\sum_k X_{ik},\\qquad P_{ik}=\\frac{X_{ik}}{X_i}.\" style=\"width:29.365ex;height:5.825ex\" loading=\"lazy\" decoding=\"async\"></div><p><span class=\"math-inline\"><img src=\"math/6053336a6b0040cd.svg\" alt=\"X_{ik}\" style=\"width:3.447ex;height:1.902ex\" loading=\"lazy\" decoding=\"async\"></span> is how often context word <span class=\"math-inline\"><img src=\"math/1dc6f9b1a0213681.svg\" alt=\"k\" style=\"width:1.179ex;height:1.595ex\" loading=\"lazy\" decoding=\"async\"></span> appears around target <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/e51016ac22dc64d1.svg\" alt=\"X_i\" style=\"width:2.613ex;height:1.902ex\" loading=\"lazy\" decoding=\"async\"></span> is the total of row <span class=\"math-inline\"><img src=\"math/3c3a2b02c199adb2.svg\" alt=\"i\" style=\"width:0.781ex;height:1.52ex\" loading=\"lazy\" decoding=\"async\"></span>. <span class=\"math-inline\"><img src=\"math/737c2c9c574f2ad5.svg\" alt=\"P_{ik}\" style=\"width:3.026ex;height:1.902ex\" loading=\"lazy\" decoding=\"async\"></span> is the resulting context probability.</p><p>The ratio <span class=\"math-inline\"><img src=\"math/330098eff375745b.svg\" alt=\"P(k\\mid i)/P(k\\mid j)\" style=\"width:15.892ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span> helps identify how a probe context differs between two words. For targets ice and steam, a probe such as solid should favour ice; gas should favour steam; a probe shared similarly by both gives a ratio near one. These are data tendencies, not universal numerical identities.</p><div class=\"example\"><p><strong>Question. For context solid, ice has count 12 out of row total 20; steam has count 2 out of row total 40. Compute P(solid|ice), P(solid|steam) and their ratio.</strong></p><div class=\"given\"><h4>Given</h4><p>X(ice,solid)=12, X(ice)=20; X(steam,solid)=2, X(steam)=40.</p><h4>To find</h4><p>Two conditional probabilities and the ice/steam ratio.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/1b6f3de99376d438.svg\" alt=\"P(k\\mid i)=X_{ik}/X_i\" style=\"width:17.512ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>, and <span class=\"math-inline\"><img src=\"math/f8639f057ec07b30.svg\" alt=\"R=P(k\\mid ice)/P(k\\mid steam)\" style=\"width:27.843ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Ice probability</h4><p><span class=\"math-inline\"><img src=\"math/b553cd0f20af7e2a.svg\" alt=\"12/20=0.6\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Steam probability</h4><p><span class=\"math-inline\"><img src=\"math/a23f9c2192e787e1.svg\" alt=\"2/40=0.05\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Ratio</h4><p><span class=\"math-inline\"><img src=\"math/4a1735e84fe18a45.svg\" alt=\"0.6/0.05=12\" style=\"width:13.325ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> The probe solid is 12 times as probable in ice's context under these counts.</p></div><div class=\"example\"><p><strong>Question. For probe water, ice and steam both have row total 50. Counts are 10 and 10. Calculate the ratio.</strong></p><div class=\"given\"><h4>Given</h4><p>Both probabilities use a denominator of 50.</p><h4>To find</h4><p>The probability ratio.</p></div><h4>Formula and why it applies</h4><p>Use row-normalized counts before taking the ratio.</p><div class=\"step\"><h4>Step 1. Ice probability</h4><p><span class=\"math-inline\"><img src=\"math/2d17e669222fac35.svg\" alt=\"10/50=0.2\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Steam probability</h4><p><span class=\"math-inline\"><img src=\"math/2d17e669222fac35.svg\" alt=\"10/50=0.2\" style=\"width:11.565ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Divide</h4><p><span class=\"math-inline\"><img src=\"math/468ec9ecee826ded.svg\" alt=\"0.2/0.2=1\" style=\"width:11.062ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Ratio 1: this probe does not distinguish the targets in this toy data.</p></div><div class=\"example\"><p><strong>Question. For probe gas, counts are 1/100 around ice and 20/100 around steam. Compute the ice-to-steam ratio.</strong></p><div class=\"given\"><h4>Given</h4><p>Conditional counts have the same row denominator.</p><h4>To find</h4><p>The ratio and interpretation.</p></div><h4>Formula and why it applies</h4><p><span class=\"math-inline\"><img src=\"math/efe28e7e3bde3014.svg\" alt=\"R=P(gas\\mid ice)/P(gas\\mid steam)\" style=\"width:32.16ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p><div class=\"step\"><h4>Step 1. Ice probability</h4><p><span class=\"math-inline\"><img src=\"math/fa188fed61277d35.svg\" alt=\"1/100=0.01\" style=\"width:12.696ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 2. Steam probability</h4><p><span class=\"math-inline\"><img src=\"math/4373563868df4a11.svg\" alt=\"20/100=0.2\" style=\"width:12.696ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><div class=\"step\"><h4>Step 3. Ratio</h4><p><span class=\"math-inline\"><img src=\"math/4ed5ae8db66197fd.svg\" alt=\"0.01/0.2=0.05\" style=\"width:15.085ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></span>.</p></div><p class=\"answer\"><strong>Answer.</strong> Ratio 0.05, so gas is much more strongly associated with steam.</p></div><p class=\"cue\">Ratio >1: pehla word favoured. <1: doosra. ≈1: probe dono mein similar.</p>","m2":false,"units":"5","marks":10,"sourcePages":[3],"historical":true},{"id":"q6b","title":"Q6b · BoW and TF–IDF movie corpus","html":"<div class=\"question\"><strong>Question. Find Bag of Words and TF–IDF for: “This movie is very scary and long”; “This movie is not scary and is slow”; “This movie is spooky and good”.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Original text</th></tr></thead><tbody><tr><td>1</td><td>This movie is very scary and long</td></tr><tr><td>2</td><td>This movie is not scary and is slow</td></tr><tr><td>3</td><td>This movie is spooky and good</td></tr></tbody></table></div><p>Stopwords: none supplied</p><h3>To find</h3><p>BoW, IDF and TF–IDF</p><h3>Formula: which one and why</h3><p>Use lowercase alphabetic tokens and exactly the stated stoplist. If no stoplist is supplied, retain function words. Adopt raw-count TF and natural-log IDF; the paper does not prescribe another TF/log convention.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/fd85ae95ce50c427.svg\" alt=\"\\mathrm{TFIDF}(w,d)=c(w,d)\\ln\\frac{N}{\\mathrm{df}(w)}\" style=\"width:31.372ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A term shared by all N documents has IDF ln(1)=0. Counts and TF–IDF weights are different representations.</p><h3>Step 1. Tokenize each document</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>Tokens</th></tr></thead><tbody><tr><td>1</td><td>this, movie, is, very, scary, and, long</td></tr><tr><td>2</td><td>this, movie, is, not, scary, and, is, slow</td></tr><tr><td>3</td><td>this, movie, is, spooky, and, good</td></tr></tbody></table></div><h3>Step 2. Fix the vocabulary order</h3><p>and, good, is, long, movie, not, scary, slow, spooky, this, very</p><h3>Step 3. Count occurrences (Bag of Words)</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>and</th><th>good</th><th>is</th><th>long</th><th>movie</th><th>not</th><th>scary</th><th>slow</th><th>spooky</th><th>this</th><th>very</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td></tr><tr><td>2</td><td>1</td><td>0</td><td>2</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>0</td><td>1</td><td>0</td></tr><tr><td>3</td><td>1</td><td>1</td><td>1</td><td>0</td><td>1</td><td>0</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td></tr></tbody></table></div><h3>Step 4. Calculate document frequency and IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>df</th><th>N / df</th><th>ln(N/df)</th></tr></thead><tbody><tr><td>and</td><td>3</td><td>1</td><td>0.000000000</td></tr><tr><td>good</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>is</td><td>3</td><td>1</td><td>0.000000000</td></tr><tr><td>long</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>movie</td><td>3</td><td>1</td><td>0.000000000</td></tr><tr><td>not</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>scary</td><td>2</td><td>3/2</td><td>0.405465108</td></tr><tr><td>slow</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>spooky</td><td>1</td><td>3</td><td>1.098612289</td></tr><tr><td>this</td><td>3</td><td>1</td><td>0.000000000</td></tr><tr><td>very</td><td>1</td><td>3</td><td>1.098612289</td></tr></tbody></table></div><h3>Step 5. Multiply each TF by its IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Document</th><th>and</th><th>good</th><th>is</th><th>long</th><th>movie</th><th>not</th><th>scary</th><th>slow</th><th>spooky</th><th>this</th><th>very</th></tr></thead><tbody><tr><td>1</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>0.000000</td><td>0.000000</td><td>0.405465</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td></tr><tr><td>2</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>0.405465</td><td>1.098612</td><td>0.000000</td><td>0.000000</td><td>0.000000</td></tr><tr><td>3</td><td>0.000000</td><td>1.098612</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>0.000000</td><td>1.098612</td><td>0.000000</td><td>0.000000</td></tr></tbody></table></div><h3>Final answer</h3><p>The final table is the TF–IDF matrix in the declared vocabulary order. A different explicitly stated log base rescales all IDFs; length-normalized TF changes each document scale.</p>","m2":false,"units":"2","marks":10,"sourcePages":[3],"historical":true},{"id":"q7a","title":"Q7a · Information extraction, chunking and NER","html":"<div class=\"question\"><strong>Question. Explain information-extraction architecture with a diagram. Explain chunking and named-entity recognition with examples.</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Information extraction (IE) converts unstructured language into structured information such as named entities, relations and events.</strong> A structured output has explicit fields or records that can be stored, searched or analysed. IE is broader than NER: finding two names does not yet determine how those entities are related.</p><h3>The three levels of extracted information</h3><table><thead><tr><th>Level</th><th>What it identifies</th><th>Example</th></tr></thead><tbody><tr><td>Entity extraction / NER</td><td>A span and its entity type</td><td>Asha → person; Orbit Labs → organisation</td></tr><tr><td>Relation extraction</td><td>A labelled connection between entities</td><td>works-for(Asha, Orbit Labs)</td></tr><tr><td>Event extraction</td><td>An occurrence with roles and attributes</td><td>Joining: employee=Asha, employer=Orbit Labs, date=2025</td></tr></tbody></table><p>An <strong>entity</strong> is a participant such as a person or organisation. A <strong>relation</strong> links participants. An <strong>event</strong> describes something that happened, may happen or did not happen. An <strong>event role</strong> names a participant's function: buyer, seller, employee, employer, location or time. These labels must follow the chosen extraction schema.</p><div class=\"flow\"><div class=\"node\">Raw text</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Sentence/token processing</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Entity spans + types</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Reference resolution</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Relations and event roles</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Normalize and store records</div></div><h3>An extraction pipeline explained</h3><table><thead><tr><th>Step</th><th>Operation</th><th>Reason</th></tr></thead><tbody><tr><td>Specify schema</td><td>Choose fields and allowed relations/events.</td><td>A system needs to know what records it is building.</td></tr><tr><td>Preprocess</td><td>Segment sentences and tokenize without losing useful structure.</td><td>Locate expressions and boundaries.</td></tr><tr><td>Recognise entities</td><td>Find spans and assign types.</td><td>Names can contain several words.</td></tr><tr><td>Resolve references</td><td>Link pronouns/descriptions to the right entities.</td><td>Two mentions may denote one participant.</td></tr><tr><td>Extract links/events</td><td>Use patterns, syntax or learned models.</td><td>Co-occurrence alone does not identify a relationship.</td></tr><tr><td>Handle qualifiers</td><td>Preserve negation, time and uncertainty.</td><td>Not hired differs from hired.</td></tr><tr><td>Normalize</td><td>Standardize dates, names or quantities where justified.</td><td>Equivalent forms should be comparable.</td></tr><tr><td>Store/evaluate</td><td>Save records and compare them with annotated answers.</td><td>Wrong links matter even if entity names are correct.</td></tr></tbody></table><section class=\"example\"><h3>Worked application 1 · turn a sentence into a record</h3><p class=\"question\"><strong>Question. Extract entities and a joining event from “Asha joined Orbit Labs in Mumbai on 3 May 2025.” Use fields person, organisation, location, event and date.</strong></p><div class=\"given\"><h4>Given</h4><p>One affirmative sentence; Orbit Labs is an organisation and Mumbai is a location.</p><h4>To find</h4><p>Entity spans/types and one structured joining record.</p></div><h4>Method and why it applies</h4><p>Find the complete entity spans, then assign their roles using the verb joined and its grammatical context.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Mark entity spans</h4><table><thead><tr><th>Span</th><th>Type</th></tr></thead><tbody><tr><td>Asha</td><td>Person</td></tr><tr><td>Orbit Labs</td><td>Organisation</td></tr><tr><td>Mumbai</td><td>Location</td></tr><tr><td>3 May 2025</td><td>Date</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Identify the event trigger</h4><p>Joined signals a joining event. The subject Asha is the joining person; Orbit Labs is the joined organisation.</p></div><div class=\"step\"><h4>Step 3. Attach contextual fields</h4><p>In Mumbai supplies a location associated with the stated joining event. On 3 May 2025 supplies its date. Do not infer the company's permanent headquarters from this sentence alone.</p></div><div class=\"step\"><h4>Step 4. Normalize the date</h4><p>The unambiguous date can be stored as 2025-05-03 while preserving its original text.</p></div><div class=\"step\"><h4>Step 5. Build the record</h4><table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td>event</td><td>joining</td></tr><tr><td>person</td><td>Asha</td></tr><tr><td>organisation</td><td>Orbit Labs</td></tr><tr><td>location</td><td>Mumbai</td></tr><tr><td>date</td><td>2025-05-03</td></tr></tbody></table></div><div class=\"step\"><h4>Step 6. State the information limit</h4><p>The sentence supports a joining event on that date. By itself it does not prove that Asha still works there indefinitely.</p></div><div class=\"answer\"><strong>Answer.</strong> A joining record for Asha and Orbit Labs at the stated location/date, with complete entity spans preserved.</div></section><section class=\"example\"><h3>Worked application 2 · direction of a relation matters</h3><p class=\"question\"><strong>Question. From “Nova acquired Luma for ₹50 crore in 2025”, extract an acquisition event with buyer, acquired organisation, amount and year.</strong></p><div class=\"given\"><h4>Given</h4><p>Nova and Luma are organisation names. The active verb is acquired; no seller is named.</p><h4>To find</h4><p>A correctly directed acquisition record.</p></div><h4>Method and why it applies</h4><p>Use grammatical roles to identify buyer and acquired organisation. Merely returning the unordered pair {Nova,Luma} loses the event direction.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Recognise participant entities</h4><p>Nova is the subject organisation; Luma is the object organisation.</p></div><div class=\"step\"><h4>Step 2. Locate the trigger</h4><p>Acquired identifies an acquisition event.</p></div><div class=\"step\"><h4>Step 3. Assign roles</h4><table><thead><tr><th>Role</th><th>Entity</th></tr></thead><tbody><tr><td>Buyer/acquirer</td><td>Nova</td></tr><tr><td>Acquired organisation</td><td>Luma</td></tr></tbody></table></div><div class=\"step\"><h4>Step 4. Extract amount and time</h4><p>Amount text=₹50 crore; year=2025. Currency and magnitude belong together; do not drop crore or replace it by lakh.</p></div><div class=\"step\"><h4>Step 5. Create the record</h4><table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td>event</td><td>acquisition</td></tr><tr><td>buyer</td><td>Nova</td></tr><tr><td>acquired_organisation</td><td>Luma</td></tr><tr><td>amount</td><td>INR 50 crore</td></tr><tr><td>year</td><td>2025</td></tr><tr><td>seller</td><td>Not stated</td></tr></tbody></table></div><div class=\"step\"><h4>Step 6. Reject an unsupported inference</h4><p>The sentence does not name the former owner/seller. Luma is the acquired organisation, not automatically the seller.</p></div><div class=\"answer\"><strong>Answer.</strong> Acquisition(buyer=Nova, acquired organisation=Luma, amount=INR 50 crore, year=2025). Seller remains unspecified.</div></section><section class=\"example\"><h3>Worked application 3 · reference, negation and time</h3><p class=\"question\"><strong>Question. Extract employment-related events from “Ravi joined Vega in 2021. He left the company in 2024. He did not join Orion.” Keep event type, person, organisation, date and polarity.</strong></p><div class=\"given\"><h4>Given</h4><p>He refers to Ravi; the company refers to Vega. The last sentence explicitly negates joining Orion.</p><h4>To find</h4><p>A structured event list without claiming an unsupported current employer.</p></div><h4>Method and why it applies</h4><p>Resolve references, identify each event separately and preserve whether it is affirmed or negated.</p><h3>Solution</h3><div class=\"step\"><h4>Step 1. Resolve the repeated mentions</h4><table><thead><tr><th>Mention</th><th>Referent</th></tr></thead><tbody><tr><td>He in sentence 2</td><td>Ravi</td></tr><tr><td>the company</td><td>Vega</td></tr><tr><td>He in sentence 3</td><td>Ravi</td></tr></tbody></table></div><div class=\"step\"><h4>Step 2. Extract the first event</h4><p>Joining; person=Ravi; organisation=Vega; date=2021; polarity=affirmed.</p></div><div class=\"step\"><h4>Step 3. Extract the second event</h4><p>Leaving; person=Ravi; organisation=Vega; date=2024; polarity=affirmed.</p></div><div class=\"step\"><h4>Step 4. Extract the third statement</h4><p>Joining; person=Ravi; organisation=Orion; date=not stated; polarity=negated. This must not create an affirmative employment relation with Orion.</p></div><div class=\"step\"><h4>Step 5. Write the event table</h4><table><thead><tr><th>Event</th><th>Person</th><th>Organisation</th><th>Date</th><th>Polarity</th></tr></thead><tbody><tr><td>joining</td><td>Ravi</td><td>Vega</td><td>2021</td><td>Affirmed</td></tr><tr><td>leaving</td><td>Ravi</td><td>Vega</td><td>2024</td><td>Affirmed</td></tr><tr><td>joining</td><td>Ravi</td><td>Orion</td><td>Not stated</td><td>Negated</td></tr></tbody></table></div><div class=\"step\"><h4>Step 6. Interpret current status cautiously</h4><p>The text says that Ravi left Vega and did not join Orion. It supplies no other current employer. Do not fill that field by guessing.</p></div><div class=\"answer\"><strong>Answer.</strong> Three qualified event statements, including a negated Orion joining. No current employer can be established from this text.</div></section><h3>Approaches and their trade-offs</h3><table><thead><tr><th>Approach</th><th>Mechanism</th><th>Advantage</th><th>Limitation</th></tr></thead><tbody><tr><td>Dictionary/rule based</td><td>Match known names, trigger words and patterns such as person joined organisation.</td><td>Transparent and useful in a narrow domain.</td><td>New names, paraphrases and complex syntax can escape patterns.</td></tr><tr><td>Supervised statistical</td><td>Learn entity/relation/event labels from annotated examples and features.</td><td>Combines several cues consistently.</td><td>Requires representative labels and careful feature design.</td></tr><tr><td>Neural/contextual</td><td>Use contextual representations to classify spans and links or generate a structured record.</td><td>Can capture paraphrases and broader context.</td><td>May still invent or misassign fields; schema and factual checks remain necessary.</td></tr></tbody></table><p>Applications include extracting company events from news, conditions/treatments from clinical text, skills from resumes and attributes from product descriptions. Extraction quality is measured against annotated records: an entity match can require the correct span and type; a relation match additionally requires the correct participants and direction. Precision measures how many extracted records are correct; recall measures how many gold records were found.</p><p>For a 10-mark answer, begin with the definition and structured output, distinguish NER/relation/event extraction, draw and explain the pipeline, work through a record with roles and qualifiers, compare approaches, then state evaluation and limitations. “Extract keywords” alone is too narrow: keywords do not necessarily represent a factual relation.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER naam pakadta hai; relation kaun-kisse jodta hai; event kya hua batata hai. Negation aur date mat girao.</p><p><strong>Chunking</strong>, also called shallow parsing, groups adjacent tagged words into meaningful non-overlapping units, commonly noun phrases. It usually identifies local phrase boundaries without producing the complete hierarchical structure of a sentence. <strong>Chinking</strong> removes specified tokens from an existing candidate chunk, splitting or trimming it.</p><div class=\"flow\"><div class=\"node\">The/DT small/JJ cat/NN sat/VBD on/IN the/DT mat/NN</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [The small cat]</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Outside: sat on</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">NP: [the mat]</div></div><p>A POS tagger labels individual words. A chunker groups words into phrases. A full parser shows how phrases relate recursively to form the entire sentence. These are related tasks with different outputs.</p><div class=\"table-wrap\"><table><thead><tr><th>Operation</th><th>Input</th><th>Output</th></tr></thead><tbody><tr><td>POS tagging</td><td>The small cat</td><td>The/DT small/JJ cat/NN</td></tr><tr><td>NP chunking</td><td>Tagged tokens</td><td>[NP The small cat]</td></tr><tr><td>Chinking</td><td>A broad candidate chunk</td><td>Remove verbs/prepositions, keep noun-phrase segments</td></tr><tr><td>Full parsing</td><td>Sentence + grammar</td><td>A nested tree with sentence, noun phrase and verb phrase nodes</td></tr></tbody></table></div><p><strong>Rule-based chunking</strong> uses tag patterns. Statistical or learned chunkers infer boundaries from labeled examples. A useful NP rule is an optional determiner, followed by zero or more adjectives, followed by a noun. In NLTK-style notation: <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;}</code>. Here ? means zero or one occurrence; * means zero or more; + means one or more when used. The braces mean “form a chunk around the matched sequence”.</p><section class=\"example\"><p class=\"question\"><strong>Question. Apply the NP rule optional DT, zero or more JJ, then one NN to “The/DT quick/JJ brown/JJ fox/NN jumps/VBZ over/IN the/DT lazy/JJ dog/NN”.</strong></p><div class=\"given\"><h4>Given</h4><p>Tagged input is supplied. Rule: DT? JJ* NN.</p><h4>To find</h4><p>All noun-phrase chunks.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The rule groups a noun with its preceding determiner and adjectives; a verb or preposition does not match this NP pattern.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Start at The</h5><p>The matches optional DT; quick and brown both match JJ*; fox matches NN.</p></div><div class=\"step\"><h5>Step 2. Form the first NP</h5><p><strong>[NP The quick brown fox]</strong></p></div><div class=\"step\"><h5>Step 3. Skip nonmatching tokens</h5><p>jumps/VBZ and over/IN do not satisfy the NP pattern.</p></div><div class=\"step\"><h5>Step 4. Match the second NP</h5><p>the is DT, lazy is JJ, dog is NN: <strong>[NP the lazy dog]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> [NP The quick brown fox] jumps over [NP the lazy dog].</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Using NP → DT? JJ* NN, identify the chunks in “bright/JJ stars/NN shine/VBP and/CC a/DT moon/NN glows/VBZ”. Use the supplied tags exactly.</strong></p><div class=\"given\"><h4>Given</h4><p>Input tags label stars as NN for this exercise. Rule requires optional DT, zero or more JJ, then NN.</p><h4>To find</h4><p>The matched NP spans.</p></div><h4>Formula and why it applies</h4><p><code>NP → DT? JJ* NN</code></p><p>The optional determiner may be absent and the adjective repetition may be empty.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Match bright stars</h5><p>No determiner is present, which DT? permits. bright matches JJ; stars matches NN.</p></div><div class=\"step\"><h5>Step 2. Inspect shine and and</h5><p>VBP and CC fall outside the NP rule.</p></div><div class=\"step\"><h5>Step 3. Match a moon</h5><p>a matches DT; no adjective is present; moon matches NN.</p></div><div class=\"answer\"><strong>Final answer.</strong> Chunks are [NP bright stars] and [NP a moon]. With ordinary Penn tagging, stars is usually NNS; broaden the noun pattern to include NNS when that tag is used.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. Begin with one candidate chunk containing “The/DT cat/NN sat/VBD on/IN the/DT mat/NN”. Chink out verbs and prepositions. Show the remaining chunks.</strong></p><div class=\"given\"><h4>Given</h4><p>Initial candidate: [The cat sat on the mat]. Remove tags VBD and IN.</p><h4>To find</h4><p>The chunk segments after exclusion.</p></div><h4>Formula and why it applies</h4><p>Chinking removes matched tokens from the existing chunk.</p><p>Removing the middle verb/preposition region divides the original candidate into two remaining contiguous spans.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Locate the tokens to remove</h5><p>sat is VBD and on is IN.</p></div><div class=\"step\"><h5>Step 2. Remove those tokens from chunk membership</h5><p>The remaining token groups are “The cat” and “the mat”. sat and on still exist in the sentence; they are simply outside these chunks.</p></div><div class=\"step\"><h5>Step 3. Write the final chunked sentence</h5><p><strong>[The cat]</strong> sat on <strong>[the mat]</strong>.</p></div><div class=\"answer\"><strong>Final answer.</strong> Two chunks remain: The cat; the mat.</div><p class=\"cue\"><strong>Yaad rakho:</strong> Chunking = andar group karo; chinking = unwanted tokens ko group se bahar karo.</p></section><p><strong>Named Entity Recognition (NER)</strong> identifies text spans referring to entities and assigns their types, such as PERSON, ORGANIZATION and LOCATION. Many practical schemas also include DATE, TIME, MONEY or domain-specific types. The exact allowed labels depend on the application's annotation scheme.</p><p>NER has two parts: <strong>boundary detection</strong> finds where the entity starts and ends; <strong>classification</strong> assigns the appropriate type. A multiword name should normally be one entity span: “New York” is a location span, not two unrelated location decisions.</p><div class=\"flow\"><div class=\"node\">Text: Mary joined Google in New York on Monday.</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Mary → PERSON</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Google → ORGANIZATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">New York → LOCATION</div><span class=\"arrow\" aria-hidden=\"true\">→</span><div class=\"node\">Monday → DATE</div></div><p>Not every noun is a named entity. In “a developer works at Google”, developer is an ordinary job description while Google is a named organization. A specialized HR system may define a JOB_TITLE category, but it must state that schema explicitly. NER identifies mentions; entity linking is the separate task of connecting a mention to a unique database identity.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Question it answers</th><th>Example</th></tr></thead><tbody><tr><td>POS</td><td>What grammatical role does this token have?</td><td>Google/NNP</td></tr><tr><td>Chunking</td><td>Which adjacent words form a phrase?</td><td>[NP a skilled developer]</td></tr><tr><td>NER</td><td>Which span names an entity, and of what type?</td><td>[Google] ORGANIZATION</td></tr><tr><td>Entity linking</td><td>Which real entity does this mention denote?</td><td>Connect Paris to the intended city or person record</td></tr></tbody></table></div><p><strong>Applications.</strong> NER structures search results and documents, extracts organizations/people from news, routes support tickets by product or organization, supports recommendation, and extracts specialized entities from healthcare or legal text. Context is essential: “Apple released a laptop” names an organization, while “she ate an apple” describes fruit.</p><p class=\"cue\"><strong>Yaad rakho:</strong> NER mein do kaam: naam kahan se kahan tak, aur kis category ka.</p>","m2":false,"units":"4,7","marks":10,"sourcePages":[3],"historical":true},{"id":"q7b","title":"Q7b · Distributional hypothesis and cosine","html":"<div class=\"question\"><strong>Question. Justify “You shall know a word by the company it keeps.” Calculate cosine similarity of w₁=[0.2,0.1,0.3,0.4] and w₂=[0.3,0,0.2,0.5].</strong> <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Words occurring in similar contexts often have related meanings; vectors encode their context distributions. This is a statistical tendency, not proof that every similar-context pair is synonymous—antonyms can share contexts too.</p><h3>Given</h3><p>u=[0.2, 0.1, 0.3, 0.4]; v=[0.3, 0, 0.2, 0.5]</p><h3>To find</h3><p>Cosine similarity in the given coordinate order.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bcd9c35430c84240.svg\" alt=\"\\cos(u,v)=\\frac{u\\cdot v}{\\|u\\|\\|v\\|}\" style=\"width:19.114ex;height:4.704ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 1. Multiply matching coordinates</h3><p>0.2×0.3 + 0.1×0 + 0.3×0.2 + 0.4×0.5 = 0.32</p><h3>Step 2. Calculate both squared lengths</h3><p>u: 0.2² + 0.1² + 0.3² + 0.4² = 0.30000000000000004; v: 0.3² + 0² + 0.2² + 0.5² = 0.38</p><h3>Step 3. Take square roots and divide</h3><p>0.32 / (√0.30000000000000004 × √0.38) = 0.947758204</p><h3>Final answer</h3><p><strong>Cosine=0.947758204.</strong> This measures direction, not a probability.</p>","m2":false,"units":"5","marks":10,"sourcePages":[3],"historical":true}]}],"mocks":[{"id":"timed-final-2025","title":"Timed practice · Solved final paper · December 2025","unit":"PYQ","scope":"TEE · actual previous paper · 100 marks · 180 minutes","sections":[{"id":"instructions","title":"Write the whole paper under exam conditions","html":"<p>Use this actual previous paper as a three-hour, 100-mark practice paper. Q1 is compulsory (20 marks); choose any four full questions from Q2–Q7 (20 marks each). Each original question and its complete answer follow. Read the question, write your answer in your notebook, then compare the working below it.</p><p>Budget roughly 36 minutes per attempted 20-mark question, including its subparts. Start each full question on a fresh page, as the supplied papers instruct. This is an old paper used for timed practice, not a forecast of the next TEE.</p>"},{"id":"final-2025-q1a","title":"Q1A · NLU and NLG","html":"<div class=\"question\" style=\"font-weight:700\">Question. Differentiate between Natural Language Understanding (NLU) and Natural Language Generation (NLG) in NLP with suitable examples. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Natural Language Understanding (NLU)</strong> interprets language to identify its meaning, intent and relevant information. <strong>Natural Language Generation (NLG)</strong> produces language that expresses information in a useful form.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>NLU</th><th>NLG</th></tr></thead><tbody><tr><td>Direction</td><td>Language → meaning or structured information</td><td>Meaning or structured information → language</td></tr><tr><td>Typical input</td><td>A user utterance, document or sentence</td><td>Facts, a database record, a prompt or a representation</td></tr><tr><td>Typical output</td><td>Intent, entities, sentiment or a semantic representation</td><td>A sentence, explanation, summary or dialogue response</td></tr><tr><td>Main difficulty</td><td>Resolving ambiguity and context</td><td>Choosing accurate content and producing coherent, fluent wording</td></tr></tbody></table></div><h3>Example: a weather assistant</h3><p>User: “Will it rain in Mumbai tomorrow?” NLU recognises a weather-query intent, the location Mumbai and the date tomorrow. After a weather service supplies the forecast, NLG produces “Rain is likely in Mumbai tomorrow; carry an umbrella.”</p><div class=\"flow\"><span class=\"flow-box\">User language</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">NLU: identify request</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Retrieve forecast</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">NLG: express answer</span></div><p>The two functions often work together in a chatbot. Understanding the request and wording the reply are separate tasks; fluent generation alone does not prove correct understanding.</p><p class=\"memory\"><strong>Yaad rakho:</strong> NLU mein meaning nikalo; NLG mein meaning ko sentence banao.</p>","m2":false,"units":"1","marks":5},{"id":"final-2025-q1b","title":"Q1B · Chunking and chinking","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain the concepts of chunking and chinking in Natural Language Processing (NLP). Discuss how Part-of-Speech (POS) tagging supports these processes, and illustrate your explanation with a suitable example. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Chunking</strong> groups adjacent tagged words into shallow phrases, such as noun phrases, without building a complete sentence parse. <strong>Chinking</strong> removes a specified sequence of tags or words from a chunk, splitting a larger candidate chunk when required.</p><h3>POS tags provide the pattern</h3><p>A POS tag describes a grammatical category: DT = determiner, JJ = adjective, NN = singular noun, VBD = past-tense verb and IN = preposition. A noun-phrase rule can be written as <code>NP: {&lt;DT&gt;?&lt;JJ&gt;*&lt;NN&gt;+}</code>: an optional determiner, zero or more adjectives, followed by one or more nouns.</p><h3>Worked example</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>The</th><th>small</th><th>cat</th><th>sat</th><th>on</th><th>the</th><th>mat</th></tr></thead><tbody><tr><td>Tag</td><td>DT</td><td>JJ</td><td>NN</td><td>VBD</td><td>IN</td><td>DT</td><td>NN</td></tr></tbody></table></div><p>Applying the NP rule gives <strong>[The small cat] sat on [the mat]</strong>. The first chunk contains DT–JJ–NN; the second contains DT–NN. “sat on” is not included because it does not match the noun-phrase rule.</p><p>For chinking, begin with one broad chunk: <strong>[The small cat sat on the mat]</strong>. Remove the VBD and IN sequence “sat on”, for example with <code>}&lt;VBD|IN&gt;+{</code>. The result is <strong>[The small cat] sat on [the mat]</strong>.</p><p>POS tagging therefore supplies grammatical labels; chunking uses labels to select phrases, while chinking uses labels to exclude unwanted material. Incorrect tags can lead to incorrect chunks.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Chunking = phrase ko jodo; chinking = beech ka unwanted part nikalo.</p>","m2":true,"units":"4","marks":5},{"id":"final-2025-q1c","title":"Q1C · Hyponymy, hypernymy and WSD","html":"<div class=\"question\" style=\"font-weight:700\">Question. Define hyponymy and hypernymy with suitable linguistic examples. How can hypernymy be applied in Word Sense Disambiguation (WSD) to resolve the correct meaning of polysemous words? Provide an example? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Hyponymy</strong> is the “is-a-kind-of” relation from a specific concept to a broader concept. <strong>Hypernymy</strong> is the inverse relation from the broader concept to the specific one. “Rose” is a hyponym of “flower”; “flower” is a hypernym of “rose”.</p><div class=\"flow\"><span class=\"flow-box\">rose / tulip</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">flower</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">plant</span></div><p>The arrow points towards a broader category. Hyponymy is not a part–whole relation: a wheel is part of a car, but it is not a kind of car.</p><h3>Using the hierarchy for WSD</h3><p>WSD selects the intended sense of a word from its context. Obtain candidate senses from a lexical resource such as WordNet, inspect their hypernym chains, and favour the chain most compatible with nearby words.</p><ol><li>Sentence: “The mouse clicked the icon.”</li><li>Candidate 1: mouse → rodent → mammal → animal. Candidate 2: mouse → pointing device → computer peripheral.</li><li>The context words “clicked” and “icon” belong to the computer-use domain. They support the device hierarchy, rather than the animal hierarchy.</li><li>Select the computer-pointing-device sense. In “The mouse ate cheese,” the animal hierarchy is more compatible.</li></ol><p>Hypernym evidence supplies semantic generalisation; it is a useful signal rather than a guarantee, because short or unusual contexts may still be ambiguous.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Hyponym specific hai; hypernym uska bada category hai.</p>","m2":true,"units":"5","marks":5},{"id":"final-2025-q1d","title":"Q1D · Pragmatics and discourse","html":"<div class=\"question\" style=\"font-weight:700\">Question. Compare pragmatic and discourse analysis with the help of appropriate examples. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Pragmatic analysis</strong> interprets an utterance using the situation, speaker intention, shared knowledge and conversational expectations. <strong>Discourse analysis</strong> studies how multiple utterances form a connected text or conversation.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Pragmatic analysis</th><th>Discourse analysis</th></tr></thead><tbody><tr><td>Focus</td><td>Intended meaning in context</td><td>Relationships and coherence across utterances</td></tr><tr><td>Useful information</td><td>Speaker, listener, place, time and common knowledge</td><td>Previous sentences, entities, topics and rhetorical relations</td></tr><tr><td>Typical tasks</td><td>Interpret requests, implicatures and deixis</td><td>Resolve references and analyse cohesion, coherence and discourse structure</td></tr><tr><td>Example</td><td>“It is cold here” may be a request to close a window</td><td>“Riya bought a book. She read it.” links She to Riya and it to book</td></tr></tbody></table></div><p>In “Can you pass the salt?”, literal syntax asks about ability; pragmatic interpretation usually identifies a polite request. In “The road flooded. Therefore, the school closed,” discourse analysis identifies a cause–result link between the sentences.</p><p>The levels interact: resolving “she” across a conversation may require both earlier text and real-world context. They are complementary rather than mutually exclusive.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pragmatics: bolne ka intention. Discourse: sentences ka connection.</p>","m2":false,"units":"6","marks":5},{"id":"final-2025-q2a","title":"Q2A · Morpheme, lexeme and NER","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Differentiate between Morpheme and Lexeme with examples.<br>ii. Discuss the significance of NER in three different NLP applications. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Morpheme and lexeme</h3><p>A <strong>morpheme</strong> is the smallest linguistic unit that contributes meaning or grammatical function. A <strong>lexeme</strong> is an abstract vocabulary item representing a family of inflected word forms.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Morpheme</th><th>Lexeme</th></tr></thead><tbody><tr><td>Unit</td><td>A meaningful component of a word</td><td>An abstract dictionary vocabulary item</td></tr><tr><td>Examples</td><td>un-, happy, -ness; cat and plural -s</td><td>RUN covers run, runs, ran and running</td></tr><tr><td>Independence</td><td>Free morphemes can stand alone; bound morphemes cannot</td><td>A lexeme is realised through one or more word forms</td></tr><tr><td>NLP relevance</td><td>Morphological segmentation, stemming and analysis</td><td>Lemmatization and lexical meaning</td></tr></tbody></table></div><p>“Cats” contains two morphemes: cat + plural -s. “cat” and “cats” are forms of the lexeme CAT. “Unhappiness” can be segmented into un + happy + ness, although its spelling changes at the boundary. A morpheme and a syllable are different: syllables concern pronunciation, while morphemes concern meaning or grammar.</p><h3>ii. Named Entity Recognition in applications</h3><p><strong>NER</strong> locates spans that name entities and assigns types such as PERSON, ORGANIZATION, LOCATION, DATE or domain-specific categories.</p><div class=\"table-wrap\"><table><thead><tr><th>Application</th><th>Entities and example</th><th>Why NER matters</th></tr></thead><tbody><tr><td>News information extraction</td><td>“Asha joined Infosys in Pune.” → Asha/PERSON, Infosys/ORG, Pune/LOCATION</td><td>Creates searchable people–organisation–location records and supports later relation extraction</td></tr><tr><td>Healthcare document processing</td><td>Find disease, drug and dosage spans in a clinical note</td><td>Supports record indexing and medication extraction; specialist labels and validation are required</td></tr><tr><td>Customer support and commerce</td><td>Extract product names, dates and order identifiers from “My Pixel arrived damaged on Monday.”</td><td>Routes complaints, links the correct product and fills structured support fields</td></tr></tbody></table></div><p>NER answers “Which entity spans occur here, and what type are they?” It does not by itself establish every relation between those entities or resolve all names to unique real-world identities.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Morpheme = word ka meaningful piece; lexeme = word family. NER = naam dhoondho aur type do.</p>","m2":false,"units":"1,4","marks":10},{"id":"final-2025-q2b","title":"Q2B · Laplace-smoothed bigram probability","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following training corpus:<br>1. artists paint murals in city<br>2. musicians play songs in city<br>3. painters paint murals on walls<br>4. signs are near city<br>Using a bigram language model with Laplace smoothing, evaluate the probability of the test sentence: “artists paint murals near city”. Assume the &lt;s&gt; and &lt;/s&gt; for each sentence. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><ul><li>artists paint murals in city</li><li>musicians play songs in city</li><li>painters paint murals on walls</li><li>signs are near city</li></ul><p>Test: artists paint murals near city. Add one start token &lt;s&gt; and one end token &lt;/s&gt; to every training and test sentence.</p><h3>To find</h3><p>The Laplace-smoothed bigram probability of the complete test sentence, including its end token.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0167293b8abe1cce.svg\" alt=\"P_{+1}(w_i\\mid w_{i-1})=\\frac{C(w_{i-1},w_i)+1}{C(w_{i-1})+V}\" style=\"width:33.254ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(previous,current) counts that adjacent pair in the training corpus. C(previous) counts its occurrences as a history. V is the vocabulary size. Add-one smoothing is necessary because an unseen pair must not force the whole sentence probability to zero.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/09cc94e28baa5a90.svg\" alt=\"P(w_1,\\ldots,w_n,\\langle/s\\rangle\\mid\\langle s\\rangle)=\\prod_{i=1}^{n+1}P(w_i\\mid w_{i-1})\" style=\"width:42.048ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Fix the token and vocabulary convention</h3><p>Lowercase words and remove the final punctuation. The supplied course key counts both boundary tokens in V. Following that convention: are, artists, city, in, murals, musicians, near, on, paint, painters, play, signs, songs, walls, &lt;s&gt;, &lt;/s&gt; gives <strong>V = 16</strong>. The start marker supplies history; it is not an extra probability factor before the first word.</p><h3>Step 2. List every required transition</h3><p>The complete test chain is &lt;s&gt; → artists → paint → murals → near → city → &lt;/s&gt;.</p><h3>Step 3. Count first, then add one</h3><div class=\"table-wrap\"><table><thead><tr><th>Required bigram</th><th>History count</th><th>Pair count</th><th>Smoothed probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → artists</td><td>4</td><td>1</td><td>(1+1)/(4+16) = 1/10</td></tr><tr><td>artists → paint</td><td>1</td><td>1</td><td>(1+1)/(1+16) = 2/17</td></tr><tr><td>paint → murals</td><td>2</td><td>2</td><td>(2+1)/(2+16) = 1/6</td></tr><tr><td>murals → near</td><td>2</td><td>0</td><td>(0+1)/(2+16) = 1/18</td></tr><tr><td>near → city</td><td>1</td><td>1</td><td>(1+1)/(1+16) = 2/17</td></tr><tr><td>city → &lt;/s&gt;</td><td>3</td><td>3</td><td>(3+1)/(3+16) = 4/19</td></tr></tbody></table></div><p>Count only adjacent words, never words that merely appear in the same sentence. The unseen pairs have count zero, so their numerator becomes one.</p><h3>Step 4. Multiply all six probabilities</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/62ad7b9fcca8c7b7.svg\" alt=\"P=\\frac{2}{20}\\times\\frac{2}{17}\\times\\frac{3}{18}\\times\\frac{1}{18}\\times\\frac{2}{17}\\times\\frac{4}{19}\" style=\"width:38.092ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. &lt;s&gt; → artists</td><td><span class=\"math-inline\"><img src=\"math/8fc51cfa0d4d18ef.svg\" alt=\"1\\times\\frac{1}{10}=\\frac{1}{10}\" style=\"width:12.105ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. artists → paint</td><td><span class=\"math-inline\"><img src=\"math/11b6a388c4744fa9.svg\" alt=\"\\frac{1}{10}\\times\\frac{2}{17}=\\frac{1}{85}\" style=\"width:13.569ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. paint → murals</td><td><span class=\"math-inline\"><img src=\"math/3123e759352a19f6.svg\" alt=\"\\frac{1}{85}\\times\\frac{1}{6}=\\frac{1}{510}\" style=\"width:13.569ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. murals → near</td><td><span class=\"math-inline\"><img src=\"math/8396eb2fae42ff25.svg\" alt=\"\\frac{1}{510}\\times\\frac{1}{18}=\\frac{1}{9180}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. near → city</td><td><span class=\"math-inline\"><img src=\"math/6b756a42abed1715.svg\" alt=\"\\frac{1}{9180}\\times\\frac{2}{17}=\\frac{1}{78030}\" style=\"width:17.568ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. city → &lt;/s&gt;</td><td><span class=\"math-inline\"><img src=\"math/c4371974205f854f.svg\" alt=\"\\frac{1}{78030}\\times\\frac{4}{19}=\\frac{2}{741285}\" style=\"width:19.168ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8bf61abdfc6b7956.svg\" alt=\"P=\\frac{2}{741285}\\approx 2.69801763\\times10^{-6}\" style=\"width:33.587ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Interpret the result</h3><p>This is a joint sentence probability, so a small value is normal. Do not add transition probabilities; each word must occur in sequence, so the chain multiplies them.</p><h3>Final answer</h3><p><strong>P ≈ 2.69801763 × 10<sup>-6</sup></strong> with the stated course vocabulary convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pair count mein 1 jodo, previous-word count mein V; phir saare fractions multiply karo.</p><p><strong>Convention note:</strong> Some implementations exclude &lt;s&gt; from the predicted vocabulary. Their V is one smaller and their numerical probability differs. In an exam, state V explicitly and follow the convention specified in the question or class solution.</p>","m2":true,"units":"3","marks":10},{"id":"final-2025-q3a","title":"Q3A · Ambiguity and bottom-up parsing","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain the various types of ambiguities encountered in Natural Language Processing (NLP). Illustrate each type with suitable examples.<br>ii. Compare top-down and bottom-up parsing and apply bottom-up syntax parsing approach to the sentence “A cat chased the mouse” and draw a parse tree using the grammar rules:<br>S → NP VP; NP → Pronoun | Proper-Noun | Det Nominal; Nominal → Noun | Nominal Noun | Nominal PP; VP → Verb | Verb NP | VP PP; PP → Prep NP.<br>Lexicon: Det → {A, the}; Noun → {cat, mouse}; Verb → {chased}. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Types of ambiguity</h3><p>Ambiguity exists when the same language expression permits more than one interpretation. The correct interpretation usually requires grammatical, semantic or contextual evidence.</p><div class=\"table-wrap\"><table><thead><tr><th>Type</th><th>Meaning</th><th>Example and readings</th></tr></thead><tbody><tr><td>Lexical</td><td>One word has multiple meanings</td><td>“She visited the bank”: financial institution or riverbank</td></tr><tr><td>Syntactic</td><td>The sentence permits different structural attachments</td><td>“I saw the man with a telescope”: I used the telescope, or the man had it</td></tr><tr><td>Semantic / scope</td><td>A structured sentence permits different interpretations</td><td>“Every student read a book”: one shared book, or possibly a different book per student</td></tr><tr><td>Referential</td><td>A referring expression has more than one candidate referent</td><td>“Asha told Riya that she won”: she could refer to Asha or Riya</td></tr><tr><td>Pragmatic</td><td>Intention depends on the situation</td><td>“Can you open the door?” can ask about ability or request an action</td></tr></tbody></table></div><h3>ii. Parsing approaches</h3><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Top-down</th><th>Bottom-up</th></tr></thead><tbody><tr><td>Start</td><td>The start symbol S</td><td>The input words</td></tr><tr><td>Operation</td><td>Expand a nonterminal using grammar productions</td><td>Combine words and constituents using productions in reverse</td></tr><tr><td>Success</td><td>Leaves match the complete input</td><td>All input is reduced to S</td></tr><tr><td>Possible difficulty</td><td>Naive recursive descent can loop on left recursion or need backtracking</td><td>A naive shift-reduce parser may face shift/reduce conflicts</td></tr></tbody></table></div><h3>Given</h3><p>The five tokens are A / cat / chased / the / mouse. The supplied grammar permits determiner + nominal noun phrases and a verb + noun phrase verb phrase.</p><h3>To find</h3><p>A bottom-up sequence of reductions and a parse tree whose root is S and whose leaves preserve the input order.</p><h3>Rule: which one and why</h3><p>A production A → B C permits B C to be reduced to A. Bottom-up parsing begins with the words; lexical rules assign their categories, and phrase rules combine those categories.</p><h3>Step 1. Assign lexical categories</h3><p>A → Det; cat → Noun; chased → Verb; the → Det; mouse → Noun.</p><h3>Step 2. Build the first noun phrase</h3><p>cat is Noun. Reduce Noun to Nominal using Nominal → Noun. Then reduce Det Nominal, representing “A cat”, to NP.</p><h3>Step 3. Build the object noun phrase</h3><p>mouse is Noun. Reduce it to Nominal. Reduce “the” + “mouse”, now Det Nominal, to NP.</p><h3>Step 4. Build the verb phrase</h3><p>“chased” is Verb and “the mouse” is NP. Reduce Verb NP to VP.</p><h3>Step 5. Build the sentence</h3><p>The remaining constituents are NP (“A cat”) and VP (“chased the mouse”). Apply S → NP VP in reverse to obtain S. Every input token is used exactly once.</p><figure><svg viewBox=\"0 0 820 350\" role=\"img\" aria-label=\"Bottom-up parse tree for A cat chased the mouse\" style=\"width:100%;max-width:820px;background:#f4f8f7\"><line x1=\"400\" y1=\"38\" x2=\"190\" y2=\"65\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"400\" y1=\"38\" x2=\"610\" y2=\"65\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"190\" y1=\"93\" x2=\"85\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"190\" y1=\"93\" x2=\"260\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"610\" y1=\"93\" x2=\"485\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"610\" y1=\"93\" x2=\"700\" y2=\"125\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"260\" y1=\"153\" x2=\"260\" y2=\"185\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"700\" y1=\"153\" x2=\"630\" y2=\"185\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"700\" y1=\"153\" x2=\"760\" y2=\"185\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"760\" y1=\"213\" x2=\"760\" y2=\"245\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"85\" y1=\"153\" x2=\"85\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"260\" y1=\"213\" x2=\"260\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"485\" y1=\"153\" x2=\"485\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"630\" y1=\"213\" x2=\"630\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"760\" y1=\"273\" x2=\"760\" y2=\"300\" stroke=\"#758f86\" stroke-width=\"2\"/><text x=\"400\" y=\"30\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">S</text><text x=\"190\" y=\"85\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"610\" y=\"85\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"85\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"260\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Nominal</text><text x=\"485\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Verb</text><text x=\"700\" y=\"145\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"260\" y=\"205\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Noun</text><text x=\"630\" y=\"205\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"760\" y=\"205\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Nominal</text><text x=\"760\" y=\"265\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Noun</text><text x=\"85\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">A</text><text x=\"260\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">cat</text><text x=\"485\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">chased</text><text x=\"630\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">the</text><text x=\"760\" y=\"320\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">mouse</text></svg><figcaption>Bottom-up parse tree for A cat chased the mouse.</figcaption></figure><p><strong>Final answer:</strong> [S [NP [Det A] [Nominal [Noun cat]]] [VP [Verb chased] [NP [Det the] [Nominal [Noun mouse]]]]].</p><p class=\"memory\"><strong>Yaad rakho:</strong> Bottom-up: words se phrases, phrases se S. Top-down: S se words.</p>","m2":false,"units":"1,4","marks":10},{"id":"final-2025-q3b","title":"Q3B · Co-occurrence matrix and cosine","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the given paragraph: The teacher wrote on the board. The students listened to the teacher. The board was full of notes. The student asked a question. The teacher answered from the book.<br>Target words: teacher, student, board, book.<br>Context words: wrote, listened, notes, question.<br>i. Construct a co-occurrence matrix for the target and context words. Take the window size as one whole sentence.<br>ii. Evaluate the similarity between the vectors of the target words “teacher-student” and “teacher-board” using the cosine similarity.<br>iii. Plot the target word vectors by considering only two dimensions: “wrote” and “notes”. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Five sentences, four target rows and four context columns. Treat students and student as the same target lemma, and count each target–context pair once when both occur in a sentence.</p><h3>To find</h3><p>The 4 × 4 sentence-window co-occurrence matrix, two cosine similarities and the requested 2-D plot.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/05bf57345047ff24.svg\" alt=\"M_{ij}=\\sum_{s=1}^{5}\\mathbf{1}[\\text{target}_i\\text{ and context}_j\\text{ occur in sentence }s]\" style=\"width:51.246ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The indicator is 1 when both words appear in that sentence and 0 otherwise. Each matrix row is the target word’s vector: its list of four context counts.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75e740509c95134b.svg\" alt=\"\\cos(\\mathbf a,\\mathbf b)=\\frac{\\mathbf a\\cdot\\mathbf b}{\\|\\mathbf a\\|\\|\\mathbf b\\|}\" style=\"width:19.752ex;height:5.271ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The dot product multiplies corresponding coordinates and adds them. The length is the square root of the sum of squared coordinates. Cosine compares directions while allowing different vector lengths.</p><h3>Solution</h3><h3>Step 1. Record the contribution of each sentence</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Targets present</th><th>Relevant context</th><th>Counts added</th></tr></thead><tbody><tr><td>1</td><td>teacher, board</td><td>wrote</td><td>teacher–wrote +1; board–wrote +1</td></tr><tr><td>2</td><td>student, teacher</td><td>listened</td><td>student–listened +1; teacher–listened +1</td></tr><tr><td>3</td><td>board</td><td>notes</td><td>board–notes +1</td></tr><tr><td>4</td><td>student</td><td>question</td><td>student–question +1</td></tr><tr><td>5</td><td>teacher, book</td><td>none</td><td>No requested context count</td></tr></tbody></table></div><h3>Step 2. Construct every requested column</h3><div class=\"table-wrap\"><table><thead><tr><th>Target</th><th>wrote</th><th>listened</th><th>notes</th><th>question</th></tr></thead><tbody><tr><td>teacher</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>student</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>board</td><td>1</td><td>0</td><td>1</td><td>0</td></tr><tr><td>book</td><td>0</td><td>0</td><td>0</td><td>0</td></tr></tbody></table></div><h3>Step 3. Calculate teacher–student</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5ac5a4d62f663029.svg\" alt=\"\\mathbf t\\cdot\\mathbf s=(1)(0)+(1)(1)+(0)(0)+(0)(1)=1\" style=\"width:42.267ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ae259d10b965e91c.svg\" alt=\"\\|\\mathbf t\\|=\\sqrt{1^2+1^2+0^2+0^2}=\\sqrt2\" style=\"width:31.449ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6a3ba3507695e199.svg\" alt=\"\\|\\mathbf s\\|=\\sqrt{0^2+1^2+0^2+1^2}=\\sqrt2\" style=\"width:31.465ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/eea3730ff7194b51.svg\" alt=\"\\cos(\\mathbf t,\\mathbf s)=\\frac1{\\sqrt2\\sqrt2}=\\frac12=0.5\" style=\"width:29.019ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Calculate teacher–board</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/786f2eeb23b20d27.svg\" alt=\"\\mathbf t\\cdot\\mathbf b=(1)(1)+(1)(0)+(0)(1)+(0)(0)=1\" style=\"width:42.685ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b579713956a7c270.svg\" alt=\"\\|\\mathbf b\\|=\\sqrt{1^2+0^2+1^2+0^2}=\\sqrt2\" style=\"width:31.884ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/15909e375167f411.svg\" alt=\"\\cos(\\mathbf t,\\mathbf b)=\\frac1{\\sqrt2\\sqrt2}=0.5\" style=\"width:24.294ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Select only the two requested plot coordinates</h3><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>x = wrote</th><th>y = notes</th></tr></thead><tbody><tr><td>teacher</td><td>1</td><td>0</td></tr><tr><td>student</td><td>0</td><td>0</td></tr><tr><td>board</td><td>1</td><td>1</td></tr><tr><td>book</td><td>0</td><td>0</td></tr></tbody></table></div><figure><svg viewBox=\"0 0 550 310\" role=\"img\" aria-label=\"Target word vectors plotted on two labelled axes\" style=\"width:100%;max-width:550px;background:#f4f8f7\"><path d=\"M70 250H495 M70 250V25\" stroke=\"#516d64\" fill=\"none\" stroke-width=\"2\"/><text x=\"70\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"50\" y=\"255\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"240\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"50\" y=\"165\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"410\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">2</text><text x=\"50\" y=\"75\" text-anchor=\"middle\" font-size=\"15\">2</text><circle cx=\"240\" cy=\"250\" r=\"6\" fill=\"#166b55\"/><text x=\"250\" y=\"238\" font-size=\"16\" fill=\"#153e34\">teacher</text><circle cx=\"70\" cy=\"250\" r=\"6\" fill=\"#166b55\"/><text x=\"80\" y=\"238\" font-size=\"16\" fill=\"#153e34\">student, book</text><circle cx=\"240\" cy=\"160\" r=\"6\" fill=\"#166b55\"/><text x=\"250\" y=\"148\" font-size=\"16\" fill=\"#153e34\">board</text><text x=\"280\" y=\"305\" text-anchor=\"middle\" font-size=\"16\">wrote</text><text x=\"15\" y=\"20\" font-size=\"16\">notes</text></svg><figcaption>The plot uses only the requested two coordinates; cosine uses all context columns.</figcaption></figure><h3>Final answer</h3><p>Both requested cosine similarities are <strong>0.5</strong>. Student and book overlap at the origin of the 2-D projection, but their complete four-dimensional vectors differ. The book row is zero, so a cosine involving book would be undefined without an explicit convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Har sentence mein target aur context saath? Ek count. Cosine ke liye poori row lo, plot ke liye sirf do columns.</p>","m2":false,"units":"5","marks":10},{"id":"final-2025-q4a","title":"Q4A · Three preprocessing techniques","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain any three basic text preprocessing techniques used in Natural Language Processing (NLP). Discuss the purpose of each technique and illustrate them with suitable examples. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>Text preprocessing transforms raw text into a representation suitable for a chosen NLP task. The best steps depend on the task; removing information indiscriminately can reduce performance.</p><h3>1. Tokenization</h3><p>Tokenization divides text into units called tokens, such as words, subwords or sentences. These units are required for counting words and building many model inputs. “The cats are sleeping.” can become [The, cats, are, sleeping, .] under a punctuation-preserving word tokenizer. A different tokenizer may split contractions or punctuation differently, so the convention must be consistent during training and prediction.</p><h3>2. Lowercasing</h3><p>Lowercasing maps uppercase letters to lowercase so that variants such as “Book”, “BOOK” and “book” can share one feature. This reduces vocabulary duplication in a case-insensitive search system. However, “US” and “us” are different, and capitals help NER recognise names. Therefore lowercasing should be chosen according to the application.</p><h3>3. Lemmatization</h3><p>Lemmatization maps an inflected word to its dictionary base form, often using its POS and context. Examples: cats → cat; running/VBG → run; better/JJR → good. It allows a search for “run” to match relevant inflections. A stemmer instead uses simpler truncation rules and can produce a non-word stem; lemmatization is linguistically informed and can need more processing.</p><h3>Combined example</h3><div class=\"table-wrap\"><table><thead><tr><th>Stage</th><th>Representation</th></tr></thead><tbody><tr><td>Raw</td><td>The cats are running.</td></tr><tr><td>Tokenized</td><td>The | cats | are | running | .</td></tr><tr><td>Lowercased</td><td>the | cats | are | running | .</td></tr><tr><td>Lemmatized with correct POS</td><td>the | cat | be | run | .</td></tr></tbody></table></div><p>These steps do not automatically remove stop words or punctuation. Those are separate choices. For sentiment analysis, preserve negation such as “not”; for syntax parsing, function words and word order are often essential.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Preprocess task dekh ke karo: har word ko blindly delete mat karo.</p>","m2":false,"units":"2","marks":10},{"id":"final-2025-q4b","title":"Q4B · HMM emission, transition and sequence","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following POS tagged corpus. Apply Hidden Markov Model (HMM) approach to:<br>1. Cat/Noun chase/Verb mice/Noun<br>2. The/Det dog/Noun runs/Verb<br>3. A/Det cat/Noun eats/Verb cheese/Noun<br>i. Construct the emission probability matrix.<br>ii. Construct the transmission probability matrix.<br>iii. Calculate the probability of sequence of events: The/Det cat/Noun eats/Verb mice/Noun.<br>Note: Include start and end characters for all the sentences. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged sequence</th></tr></thead><tbody><tr><td>1</td><td>cat/Noun chase/Verb mice/Noun</td></tr><tr><td>2</td><td>the/Det dog/Noun runs/Verb</td></tr><tr><td>3</td><td>a/Det cat/Noun eats/Verb cheese/Noun</td></tr></tbody></table></div><p>Test words: the cat eats mice. Given tag sequence: Det → Noun → Verb → Noun. Include Start and End for all sentences. Lowercase the corpus so sentence-initial Cat and cat are one word.</p><h3>To find</h3><p>Emission probabilities, transition probabilities and the joint probability of the specified tag-and-word sequence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a732ea965eb9fa65.svg\" alt=\"P(w\\mid t)=\\frac{C(t,w)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>An emission probability asks: among tokens carrying this tag t, what fraction are the word w?</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/791852c27a57a918.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i,t_j)}{\\sum_k C(t_i,t_k)}\" style=\"width:24.245ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>A transition probability asks: among transitions leaving tag tᵢ, what fraction go to tⱼ? Include End in the outgoing counts. The paper says “transmission”; the standard HMM term is transition.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c8c4a0c66e131a8f.svg\" alt=\"P(\\mathbf w,\\mathbf t)=P(t_1\\mid\\mathrm{Start})\\prod_{i=1}^{n}P(w_i\\mid t_i)\\prod_{i=2}^{n}P(t_i\\mid t_{i-1})P(\\mathrm{End}\\mid t_n)\" style=\"width:60.981ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Count tokens for each tag</h3><p>Det has 2 tokens; Noun has 5 tokens; Verb has 3 tokens. The repeated noun cat occurs twice with Noun; every other displayed noun occurs once. The three verb types each occur once.</p><h3>Step 2. Build the emission matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag / word</th><th>a</th><th>cat</th><th>chase</th><th>cheese</th><th>dog</th><th>eats</th><th>mice</th><th>runs</th><th>the</th></tr></thead><tbody><tr><td>Det</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1/2</td></tr><tr><td>Noun</td><td>0</td><td>2/5</td><td>0</td><td>1/5</td><td>1/5</td><td>0</td><td>1/5</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>0</td><td>1/3</td><td>0</td><td>1/3</td><td>0</td></tr></tbody></table></div><p>Each row sums to one. A zero means no occurrence under that tag in this unsmoothed training corpus; no add-one smoothing was requested.</p><h3>Step 3. Write the three tag chains</h3><p>Start → Noun → Verb → Noun → End<br>Start → Det → Noun → Verb → End<br>Start → Det → Noun → Verb → Noun → End</p><h3>Step 4. Count outgoing transitions</h3><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>To Det</th><th>To Noun</th><th>To Verb</th><th>To End</th><th>Outgoing total</th></tr></thead><tbody><tr><td>Start</td><td>2</td><td>1</td><td>0</td><td>0</td><td>3</td></tr><tr><td>Det</td><td>0</td><td>2</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3</td><td>2</td><td>5</td></tr><tr><td>Verb</td><td>0</td><td>2</td><td>0</td><td>1</td><td>3</td></tr></tbody></table></div><h3>Step 5. Divide each row by its outgoing total</h3><div class=\"table-wrap\"><table><thead><tr><th>From / To</th><th>Det</th><th>Noun</th><th>Verb</th><th>End</th></tr></thead><tbody><tr><td>Start</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3/5</td><td>2/5</td></tr><tr><td>Verb</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td></tr></tbody></table></div><p>End is terminal, so it has no estimated outgoing row. The four nonterminal rows each sum to one.</p><h3>Step 6. Choose the factors for the given sequence</h3><div class=\"table-wrap\"><table><thead><tr><th>Event in order</th><th>Probability</th></tr></thead><tbody><tr><td>Start → Det</td><td>2/3</td></tr><tr><td>Det emits the</td><td>1/2</td></tr><tr><td>Det → Noun</td><td>1</td></tr><tr><td>Noun emits cat</td><td>2/5</td></tr><tr><td>Noun → Verb</td><td>3/5</td></tr><tr><td>Verb emits eats</td><td>1/3</td></tr><tr><td>Verb → Noun</td><td>2/3</td></tr><tr><td>Noun emits mice</td><td>1/5</td></tr><tr><td>Noun → End</td><td>2/5</td></tr></tbody></table></div><h3>Step 7. Multiply, including the end transition</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7b611360d98ac780.svg\" alt=\"P=\\frac23\\times\\frac12\\times1\\times\\frac25\\times\\frac35\\times\\frac13\\times\\frac23\\times\\frac15\\times\\frac25\" style=\"width:44.987ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. Start → Det</td><td><span class=\"math-inline\"><img src=\"math/b32eeb64b6ce8d87.svg\" alt=\"1\\times\\frac{2}{3}=\\frac{2}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. Det emits the</td><td><span class=\"math-inline\"><img src=\"math/0e0cb943fc030998.svg\" alt=\"\\frac{2}{3}\\times\\frac{1}{2}=\\frac{1}{3}\" style=\"width:11.169ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. Det → Noun</td><td><span class=\"math-inline\"><img src=\"math/3b61cadbe8860930.svg\" alt=\"\\frac{1}{3}\\times1=\\frac{1}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. Noun emits cat</td><td><span class=\"math-inline\"><img src=\"math/8e3868104c41a9da.svg\" alt=\"\\frac{1}{3}\\times\\frac{2}{5}=\\frac{2}{15}\" style=\"width:11.969ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. Noun → Verb</td><td><span class=\"math-inline\"><img src=\"math/69517c6e474a3048.svg\" alt=\"\\frac{2}{15}\\times\\frac{3}{5}=\\frac{2}{25}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. Verb emits eats</td><td><span class=\"math-inline\"><img src=\"math/3bb8a5077b206779.svg\" alt=\"\\frac{2}{25}\\times\\frac{1}{3}=\\frac{2}{75}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>7. Verb → Noun</td><td><span class=\"math-inline\"><img src=\"math/1a1bff7a79a3effd.svg\" alt=\"\\frac{2}{75}\\times\\frac{2}{3}=\\frac{4}{225}\" style=\"width:13.569ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>8. Noun emits mice</td><td><span class=\"math-inline\"><img src=\"math/55f13fa2c61c6016.svg\" alt=\"\\frac{4}{225}\\times\\frac{1}{5}=\\frac{4}{1125}\" style=\"width:15.168ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>9. Noun → End</td><td><span class=\"math-inline\"><img src=\"math/391357e72bb5bd3d.svg\" alt=\"\\frac{4}{1125}\\times\\frac{2}{5}=\\frac{8}{5625}\" style=\"width:15.968ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/236caebf4a4b2830.svg\" alt=\"P=\\frac8{5625}\\approx0.0014222222\" style=\"width:26.326ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>Joint sequence probability = 8/5625 ≈ 0.0014222222.</strong> This is the probability of the specified words and tags together. It is not the probability of the word sequence summed over every possible tag path.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Tag se tag = transition; tag se word = emission. Dono alternate multiply, end ko mat bhoolo.</p><p><strong>Boundary reminder:</strong> The initial factor is P(Det | Start) = 2/3, based on three sentence starts, and the final factor is P(End | Noun) = 2/5. The overall fraction of Det tokens, 2/10, is not the start probability. Using it and omitting End, as in the handwritten key’s last line, computes a different quantity.</p>","m2":true,"units":"4","marks":10},{"id":"final-2025-q5a","title":"Q5A · TF–IDF matrix","html":"<div class=\"question\" style=\"font-weight:700\">Question. For the following two sentences:<br>Sentence A: “The student read a science book in the library”<br>Sentence B: “The teacher read a history book in the classroom”<br>1. Construct the TF-IDF matrix for these sentences after removing the stop words {The, a, in}.<br>2. Identify and comment on the important terms in each sentence based on their TF-IDF scores. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Two documents, N = 2. Remove the listed stop words case-insensitively, so both “The” and “the” are removed. Use raw count TF and natural-log IDF, the convention used in the course key.</p><h3>To find</h3><p>The term-by-document TF–IDF matrix and the terms that distinguish each sentence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b0a5cfe1defbb82d.svg\" alt=\"\\mathrm{TF}(t,d)=C(t,d),\\qquad \\mathrm{IDF}(t)=\\ln\\frac{N}{\\mathrm{df}(t)}\" style=\"width:40.45ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/555e615abfdacbc0.svg\" alt=\"\\mathrm{TFIDF}(t,d)=\\mathrm{TF}(t,d)\\,\\mathrm{IDF}(t)\" style=\"width:29.758ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(t,d) is the number of occurrences of term t in document d. df(t) is the number of documents containing t, not its total token count. N is the number of documents. IDF downweights terms shared by many documents.</p><h3>Solution</h3><h3>Step 1. Clean and list the tokens</h3><p>A: student, read, science, book, library.<br>B: teacher, read, history, book, classroom. Each retained token appears once in its sentence.</p><h3>Step 2. Fix one common vocabulary order</h3><p>student, read, science, book, library, teacher, history, classroom. Each row must refer to the same term in both documents.</p><h3>Step 3. Count document frequency and calculate IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term type</th><th>df</th><th>IDF calculation</th></tr></thead><tbody><tr><td>read, book</td><td>2</td><td>ln(2/2) = ln(1) = 0</td></tr><tr><td>Every other term</td><td>1</td><td>ln(2/1) = ln(2) ≈ 0.693147</td></tr></tbody></table></div><p>A term absent from a document has TF = 0. A present term has TF = 1 here.</p><h3>Step 4. Multiply TF by IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>TF in A</th><th>TF in B</th><th>IDF</th><th>TF–IDF A</th><th>TF–IDF B</th></tr></thead><tbody><tr><td>student</td><td>1</td><td>0</td><td>0.693147</td><td>0.693147</td><td>0</td></tr><tr><td>read</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>science</td><td>1</td><td>0</td><td>0.693147</td><td>0.693147</td><td>0</td></tr><tr><td>book</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>library</td><td>1</td><td>0</td><td>0.693147</td><td>0.693147</td><td>0</td></tr><tr><td>teacher</td><td>0</td><td>1</td><td>0.693147</td><td>0</td><td>0.693147</td></tr><tr><td>history</td><td>0</td><td>1</td><td>0.693147</td><td>0</td><td>0.693147</td></tr><tr><td>classroom</td><td>0</td><td>1</td><td>0.693147</td><td>0</td><td>0.693147</td></tr></tbody></table></div><h3>Step 5. Interpret the weights</h3><p>A is distinguished by student, science and library. B is distinguished by teacher, history and classroom. “read” and “book” have zero IDF in this tiny unsmoothed two-document collection because they appear in every document; that does not mean those words are meaningless in English.</p><h3>Final answer</h3><p>All six document-specific terms receive <strong>0.693147</strong> in their own document and 0 in the other. Shared read and book receive 0 in both.</p><p class=\"memory\"><strong>Yaad rakho:</strong> TF: is document mein kitni baar? IDF: kitne documents mein common? Rare-across-documents term ko zyada weight.</p><p>If normalized TF is explicitly requested, divide each present-token count by five; each nonzero weight becomes 0.693147/5 = 0.1386294. Do not silently switch conventions.</p>","m2":false,"units":"2","marks":10},{"id":"final-2025-q5b","title":"Q5B · Naïve Bayes word-sense classification","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the sentence: “The bat hit the ball hard on the cricket field.” Two possible senses of “bat”: Sense 1: Bat (Sports equipment – cricket/baseball); Sense 2: Bat (Nocturnal flying mammal).<br><div class=\"table-wrap\"><table><thead><tr><th>Sentence ID</th><th>Context words</th><th>Sense</th></tr></thead><tbody><tr><td>1</td><td>ball, cricket, score, stadium</td><td>Sports</td></tr><tr><td>2</td><td>night, cave, wings, fly</td><td>Animal</td></tr><tr><td>3</td><td>player, run, match, bat</td><td>Sports</td></tr><tr><td>4</td><td>nocturnal, vampire, insect</td><td>Animal</td></tr><tr><td>5</td><td>team, field, bowl, bat</td><td>Sports</td></tr><tr><td>6</td><td>dark, flying, cave, night</td><td>Animal</td></tr></tbody></table></div>a) Using the Naïve Bayes algorithm, classify the sense of “bat” in the given sentence. Apply Laplace Smoothing wherever applicable.<br>b) Discuss the significance of Laplace Smoothing in Naïve Bayes Classification. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>There are three Sports examples and three Animal examples. Treat training context lists as bag-of-words token counts. Exclude the ambiguous target “bat” from the test context. Use the fixed training vocabulary; ignore out-of-vocabulary test words hit and hard. The usable test features are ball, cricket and field.</p><h3>To find</h3><p>The posterior-score comparison for Sports and Animal, and the role of smoothing.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ab6d19b2902f96bb.svg\" alt=\"\\mathrm{score}(s)=P(s)\\prod_{w\\in\\mathrm{context}}P(w\\mid s)\" style=\"width:31.469ex;height:4.819ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/df7198279b2281ba.svg\" alt=\"P(w\\mid s)=\\frac{C(w,s)+1}{N_s+V}\" style=\"width:23.102ex;height:5.211ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>P(s) is the class prior, C(w,s) counts occurrences of context word w in class s, Nₛ is the total number of context tokens in that class and V is the shared vocabulary size. Conditional independence lets us multiply word probabilities. The common denominator P(context) is unnecessary when only comparing classes.</p><h3>Solution</h3><h3>Step 1. Calculate the priors</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/979bfbb6524dbd77.svg\" alt=\"P(S)=\\frac36=0.5,\\qquad P(A)=\\frac36=0.5\" style=\"width:37.71ex;height:4.636ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 2. Count class tokens and vocabulary</h3><p>Sports has 4 + 4 + 4 = 12 tokens. Animal has 4 + 3 + 4 = 11 tokens. The shared training vocabulary has 20 distinct words: ball, cricket, score, stadium, player, run, match, bat, team, field, bowl, night, cave, wings, fly, nocturnal, vampire, insect, dark, flying. “bat”, “night” and “cave” repeat but count only once each towards V.</p><h3>Step 3. Look up each usable context word</h3><div class=\"table-wrap\"><table><thead><tr><th>Feature</th><th>Sports count</th><th>Animal count</th><th>P(word | Sports)</th><th>P(word | Animal)</th></tr></thead><tbody><tr><td>ball</td><td>1</td><td>0</td><td>(1+1)/(12+20) = 2/32</td><td>(0+1)/(11+20) = 1/31</td></tr><tr><td>cricket</td><td>1</td><td>0</td><td>2/32</td><td>1/31</td></tr><tr><td>field</td><td>1</td><td>0</td><td>2/32</td><td>1/31</td></tr></tbody></table></div><h3>Step 4. Multiply the Sports score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a90c8cf82da50b4f.svg\" alt=\"\\mathrm{score}(S)=0.5\\times\\frac2{32}\\times\\frac2{32}\\times\\frac2{32}=0.0001220703125\" style=\"width:51.601ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Multiply the Animal score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/118f04dc70642898.svg\" alt=\"\\mathrm{score}(A)=0.5\\times\\frac1{31}\\times\\frac1{31}\\times\\frac1{31}\\approx0.00001678359236\" style=\"width:52.969ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Compare the scores</h3><p>0.0001220703125 is greater than 0.00001678359236. Therefore select Sports. Optional normalization gives P(Sports | retained features) ≈ 0.87913; normalization is not needed for the decision.</p><h3>Final answer</h3><p>The intended sense is <strong>bat as sports equipment</strong>. Ball, cricket and field favour that sense.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pehle class prior, phir har context-word likelihood multiply; bigger score wali sense choose karo.</p><h3>Why Laplace smoothing matters</h3><p>Without smoothing, all three test features have zero count in Animal. One zero factor makes the entire class score zero, even if other evidence could support that class. Add-one smoothing assigns nonzero probability to every word in the defined vocabulary and redistributes probability mass. It does not mean every unseen word outside the vocabulary can be inserted without changing the vocabulary model.</p><h3>If following the supplied paper key exactly</h3><p>The key also multiplies probabilities for hit and hard using the same denominators 32 and 31. That convention produces Sports = 1.19209290 × 10⁻⁷ and Animal ≈ 1.74647163 × 10⁻⁸, again selecting Sports. Its treatment of out-of-vocabulary words is not a normalized fixed-vocabulary model. State your feature convention clearly; the complete calculation above uses a consistent fixed training vocabulary.</p>","m2":true,"units":"5","marks":10},{"id":"final-2025-q6a","title":"Q6A · Coreference, pronouns and Word2Vec","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Differentiate between co-reference resolution and pronoun resolution with suitable examples.<br>ii. Explain the working principle of the Continuous Bag of Words (CBOW) model and Skipgram model in Word2Vec. Illustrate how it predicts the target word from its surrounding context. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Coreference and pronoun resolution</h3><p><strong>Coreference resolution</strong> groups expressions that refer to the same entity, including names, descriptions and pronouns. <strong>Pronoun resolution</strong> identifies the referent of a pronoun; it is narrower in scope.</p><div class=\"table-wrap\"><table><thead><tr><th>Expression / task</th><th>Example</th></tr></thead><tbody><tr><td>Coreference cluster</td><td>“Dr Rao arrived. The surgeon opened her bag.” → {Dr Rao, the surgeon, her}</td></tr><tr><td>Pronoun resolution</td><td>For the same text, resolve “her” to Dr Rao.</td></tr><tr><td>Difference</td><td>Resolving the description “the surgeon” is coreference work even when no pronoun is involved.</td></tr></tbody></table></div><h3>ii. Word2Vec</h3><p>Word2Vec learns dense word embeddings by predicting words from local context. A dense embedding is a short learned list of real numbers for a word; words used in similar contexts can obtain related vectors. CBOW and Skip-gram use opposite prediction directions.</p><div class=\"table-wrap\"><table><thead><tr><th>Feature</th><th>CBOW</th><th>Skip-gram</th></tr></thead><tbody><tr><td>Input</td><td>Surrounding context words</td><td>One centre word</td></tr><tr><td>Prediction target</td><td>The centre word</td><td>Surrounding context words</td></tr><tr><td>Training example</td><td>[the, cat, on, the] → sat</td><td>sat → the; sat → cat; sat → on; sat → the</td></tr><tr><td>Representation</td><td>Combine context embeddings, often by averaging</td><td>Use the centre-word embedding for each context prediction</td></tr></tbody></table></div><p>Example sentence: “The cat sat on the mat.” With a radius-two window around sat, the context is [The, cat, on, the]. In CBOW, obtain the four context embeddings, average or sum them, calculate scores for vocabulary words, and train the model to assign high probability to sat. In Skip-gram, use sat as input and create four centre–context training pairs.</p><div class=\"flow\"><span class=\"flow-box\">CBOW: nearby words</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">combine embeddings</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">predict centre word</span></div><div class=\"flow\"><span class=\"flow-box\">Skip-gram: centre word</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">its embedding</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">predict nearby words</span></div><p>Training adjusts embedding parameters to improve prediction; the final word vectors are the learned representation. Thus the question’s phrase “predicts the target word from surrounding context” describes CBOW specifically; Skip-gram reverses that direction.</p><p class=\"memory\"><strong>Yaad rakho:</strong> CBOW: neighbours se centre. Skip-gram: centre se neighbours.</p>","m2":false,"units":"5,6","marks":10},{"id":"final-2025-q6b","title":"Q6B · Hobbs: Ravi and Suresh","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain Hobb’s Algorithm. Discuss the steps with help of example and state its limitation.<br>ii. Sentence: Ravi met Suresh at the station after he arrived from Delhi. Using Hobbs’ algorithm, determine the most likely antecedent of the pronoun “he”. Show the steps of traversal according to the algorithm. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Method</h3><p><strong>Hobbs’ algorithm</strong> is a syntax-based pronoun-resolution procedure that searches constituency parse trees in a specified order. It proposes noun phrases as antecedents and filters incompatible candidates, for example by number and gender agreement.</p><p><strong>Read the tree labels first:</strong> NP means noun phrase; S means sentence/clause; VP means verb phrase. X is the current NP or S search node, and p is the upward path used to reach it. Breadth-first means shallower nodes before deeper nodes; left-to-right fixes the order at the same depth. An N-bar (N′) node is the noun-centred part of an NP in a parse using that label.</p><h3>Complete ordered procedure</h3><ol><li><strong>Locate the pronoun.</strong> Start at the NP immediately dominating the pronoun: the smallest NP containing it.</li><li><strong>Make the first climb.</strong> Move upward to the first NP or S above the starting NP. Call it X and record the path p.</li><li><strong>Search initially to the left.</strong> Traverse branches below X to the left of p, breadth-first and left-to-right. Propose an NP only if another NP or S lies between that candidate and X. Check agreement and other applicable constraints for each proposed candidate; accept the first eligible compatible one.</li><li><strong>Check the highest sentence.</strong> If X is the highest S and no candidate has been accepted, search previous sentence trees, most recent first. In each, traverse breadth-first and left-to-right and propose NPs. Accept the first eligible compatible candidate; if the available context contains none, report no resolved antecedent.</li><li><strong>Otherwise climb again.</strong> Move from X to the next NP or S above it. Make that node the new X and record the new upward path p.</li><li><strong>Test a higher NP.</strong> If the new X is an NP, propose X only when p did not pass through its nominal N-bar child. Apply the same compatibility checks. Use the labels in the supplied parse; do not invent a missing N-bar branch.</li><li><strong>Search left again.</strong> Traverse the new X’s branches to the left of p, breadth-first and left-to-right, proposing NPs. The extra intervening-NP/S requirement in Step 3 belongs to the initial search.</li><li><strong>Search permitted right branches.</strong> If X is an S, traverse branches to the right of p, breadth-first and left-to-right, but do not descend below any NP or S encountered. Propose the encountered eligible NPs and test their compatibility.</li><li><strong>Repeat or finish.</strong> Return to Step 4 until a compatible candidate is accepted or the available sentence trees are exhausted. Record the candidate order and why each candidate was accepted or rejected.</li></ol><p><strong>Why the initial restriction matters:</strong> in “John saw him”, the subject NP John is directly under the clause S, with no additional NP or S between them. Step 3 therefore does not propose John as the ordinary local antecedent of him. A reflexive such as himself is a different grammatical case. The worked question below shows the specific parse and traversal; selecting an antecedent is not simply choosing the nearest name.</p><h3>ii. Apply the method</h3><p><strong>Given:</strong> the pronoun he occurs as the subject of the subordinate clause “after he arrived from Delhi”. Assume that this clause is attached to the main verb phrase. The relevant main-clause NPs are Ravi, Suresh and the station.</p><p><strong>To find:</strong> the first eligible singular-male antecedent in Hobbs’ syntactic search order.</p><pre tabindex=\"0\" aria-label=\"Assumed constituent tree for Ravi, Suresh and he\">S (main)\n├── NP: Ravi                    ← first higher-left candidate\n└── VP\n    ├── VP: met [NP Suresh] at [NP the station]\n    └── SBAR: after\n        └── S (embedded)        ← first X\n            ├── NP: he          ← start\n            └── VP: arrived from Delhi</pre><h3>Step 1. Start at the pronoun NP</h3><p>Locate NP “he” inside the after-clause. Move to that clause’s S node. No earlier noun phrase in this small clause provides a candidate.</p><h3>Step 2. Move to the higher sentence</h3><p>The embedded S is not the highest S, so Step 5 climbs through SBAR and VP to the main S. Step 7 now searches to the left of that new path. This is the later left search, so the extra initial-search restriction from Step 3 is not imposed again.</p><h3>Step 3. Examine candidates in structural order</h3><p>The main subject NP Ravi is encountered before the deeper object NP Suresh in the relevant breadth-first search. Ravi is singular and compatible with “he”. “the station” would fail the ordinary person constraint.</p><h3>Step 4. Choose the first compatible candidate</h3><p>Select Ravi under the assumed parse and agreement settings. Suresh remains a possible interpretation in ordinary language, but the syntactic preference chooses Ravi first.</p><h3>Limitations</h3><ul><li>The result depends on the accuracy and attachment choices of the parse tree.</li><li>Syntactic ordering alone does not model all semantic plausibility, discourse focus or world knowledge.</li><li>Agreement can eliminate candidates but cannot distinguish two compatible male singular people.</li><li>Long-distance references and sentences with multiple possible parses can remain ambiguous.</li></ul><p><strong>Final answer:</strong> Hobbs’ syntactic preference is <strong>Ravi</strong> for this analysis. This is an algorithmic selection, not proof of the speaker’s intended referent.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Nearest naam blindly nahi: tree ki search order aur agreement follow karo.</p>","m2":false,"units":"6","marks":10},{"id":"final-2025-q7a","title":"Q7A · Text classification pipeline","html":"<div class=\"question\" style=\"font-weight:700\">Question. Explain the working of text classification in Natural Language Processing (NLP) and discuss the key steps involved in building a text classification system in context of real-world applications such as spam detection or news categorization. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Text classification</strong> assigns one or more predefined labels to a document or message based on its content. In spam detection the labels may be spam and not-spam; in news categorization they may be sports, business and politics.</p><div class=\"flow\"><span class=\"flow-box\">Labelled text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Prepare and split data</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Represent text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Train classifier</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Evaluate</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Classify new text</span></div><ol><li><strong>Define the labels and task.</strong> Decide whether each text gets one label or multiple labels. Establish what counts as spam so annotators use a consistent rule.</li><li><strong>Collect and label representative examples.</strong> Gather messages from the intended application and assign reliable labels. Include enough examples of each class and protect private information.</li><li><strong>Split training, validation and test data.</strong> Use training data to learn, validation data to choose settings and an untouched test set for final evaluation. Keep duplicate or closely related texts from leaking between splits.</li><li><strong>Preprocess consistently.</strong> Tokenize and normalize only as appropriate. In spam detection, URLs, currency symbols and capitalisation may contain useful information.</li><li><strong>Create features.</strong> A classical baseline uses BoW or TF–IDF. A neural system may use embeddings or a pretrained contextual model. Fit the vocabulary and IDF on training data only.</li><li><strong>Train a classifier.</strong> For example, multinomial Naïve Bayes estimates class priors and word likelihoods; logistic regression learns a decision boundary. Training uses the labelled examples.</li><li><strong>Evaluate.</strong> Inspect a confusion matrix, precision, recall and F1 as well as accuracy. False spam flags may hide legitimate mail, so the costs of errors matter.</li><li><strong>Deploy and monitor.</strong> Apply the same preprocessing and feature mapping to new texts. Monitor changing vocabulary and error patterns, and retrain when suitable new labelled data becomes available.</li></ol><h3>Example prediction</h3><p>A message such as “Claim your free prize now” is transformed into its feature representation. The classifier compares the evidence for the two labels and outputs spam if its decision score crosses the chosen threshold. The label comes from learned patterns; the mere presence of one word should not be treated as a universally correct rule.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Labelled examples → features → model → evaluation → new text ka label.</p>","m2":false,"units":"7","marks":10},{"id":"final-2025-q7b","title":"Q7B · Corpora and Jaccard similarity","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Differentiate between a flat text corpus and an annotated corpus, and discuss how each can be applied in various NLP tasks with suitable examples.<br>ii. Explain a real-world scenario where the Jaccard Similarity measure is more appropriate than Euclidean or Manhattan distance, and justify why Jaccard is the best choice in that case. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Flat and annotated corpora</h3><p>A <strong>corpus</strong> is a collection of language data. A flat text corpus stores text without the linguistic labels needed by a particular task. An annotated corpus adds labels or structure such as POS tags, entity spans, parse trees or sentence sentiment.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Flat text corpus</th><th>Annotated corpus</th></tr></thead><tbody><tr><td>Example</td><td>A collection of plain news articles</td><td>The same articles with PERSON/ORG spans marked</td></tr><tr><td>Information</td><td>The original text and possibly simple metadata</td><td>Text plus explicit task-related linguistic labels</td></tr><tr><td>Applications</td><td>Word frequency, collocations and unsupervised language-model training</td><td>Supervised POS tagging, NER or parser training and evaluation</td></tr><tr><td>Preparation</td><td>Relatively inexpensive to gather, but still needs cleaning</td><td>Requires annotation guidelines, labour and quality checks</td></tr></tbody></table></div><p>“Flat” describes the lack of the annotations being discussed, not an absence of all file organization. Both corpus types may still have document boundaries and metadata.</p><h3>ii. Jaccard in a set-based application</h3><p>Consider recommending articles using their topic-tag sets. Article A has {AI, NLP, ethics}; article B has {AI, NLP, healthcare}. We care about overlap among present tags, not how many irrelevant tags are absent from both.</p><h3>Given</h3><p>A = {AI, NLP, ethics}; B = {AI, NLP, healthcare}.</p><h3>To find</h3><p>The fraction of distinct present tags shared by the articles.</p><h3>Formula and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0eeb7c5512da08e8.svg\" alt=\"J(A,B)=\\frac{|A\\cap B|}{|A\\cup B|}\" style=\"width:18.811ex;height:5.471ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The intersection counts common items; the union counts all distinct items present in either set.</p><h3>Step 1. Find common tags</h3><p>A ∩ B = {AI, NLP}, so the intersection size is 2.</p><h3>Step 2. Find all distinct present tags</h3><p>A ∪ B = {AI, NLP, ethics, healthcare}, so the union size is 4.</p><h3>Step 3. Divide</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b91de05a3cafb1a8.svg\" alt=\"J(A,B)=\\frac24=0.5\" style=\"width:18.665ex;height:4.588ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Jaccard directly measures proportional overlap and ignores joint absences. Euclidean or Manhattan distance on binary tag vectors counts mismatches but does not by itself normalize by the union size. If frequency or magnitude were meaningful, those distance measures could be more appropriate. Here, membership-only tags and sparse sets make Jaccard a suitable choice.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Jaccard: common present items / total distinct present items.</p>","m2":false,"units":"2,3","marks":10}]},{"id":"timed-reexam-2026","title":"Timed practice · Solved re-exam · February 2026","unit":"PYQ","scope":"TEE · actual previous paper · 100 marks · 180 minutes","sections":[{"id":"instructions","title":"Write the whole paper under exam conditions","html":"<p>Use this actual previous paper as a three-hour, 100-mark practice paper. Q1 is compulsory (20 marks); choose any four full questions from Q2–Q7 (20 marks each). Each original question and its complete answer follow. Read the question, write your answer in your notebook, then compare the working below it.</p><p>Budget roughly 36 minutes per attempted 20-mark question, including its subparts. Start each full question on a fresh page, as the supplied papers instruct. This is an old paper used for timed practice, not a forecast of the next TEE.</p>"},{"id":"reexam-2026-q1a","title":"Q1A · Generic NLP pipeline","html":"<div class=\"question\" style=\"font-weight:700\">Question. Draw block diagram of generic NLP pipeline and explain the task associated with each block. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>An NLP pipeline is an ordered workflow that transforms language data into a task-specific result. The exact components depend on the application; a generic supervised pipeline is shown below.</p><div class=\"flow\"><span class=\"flow-box\">Collect text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Clean and preprocess</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Represent text</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Train / apply model</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Evaluate and deliver output</span></div><div class=\"table-wrap\"><table><thead><tr><th>Block</th><th>Task</th><th>Example for sentiment analysis</th></tr></thead><tbody><tr><td>Data acquisition</td><td>Collect representative text and any required labels</td><td>Reviews labelled positive or negative</td></tr><tr><td>Cleaning and preprocessing</td><td>Handle noise, tokenize and normalize appropriately</td><td>Remove HTML while preserving “not”</td></tr><tr><td>Text representation</td><td>Convert tokens into usable model features</td><td>TF–IDF values or contextual embeddings</td></tr><tr><td>Modeling</td><td>Learn patterns from training data and predict new labels</td><td>Train a classifier on labelled review features</td></tr><tr><td>Evaluation</td><td>Measure performance on unseen held-out data and inspect errors</td><td>Precision, recall, F1 and confusion matrix</td></tr><tr><td>Deployment and feedback</td><td>Deliver predictions and monitor changing data</td><td>Show review sentiment and monitor new product vocabulary</td></tr></tbody></table></div><p>Training/validation/test separation must precede fitting the learned preprocessing and feature statistics. New inputs must use the same feature mapping as training. Not every task uses every linguistic level explicitly: a modern end-to-end model may combine several operations internally.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Text lo → prepare karo → numbers banao → model lagao → result check aur use karo.</p>","m2":false,"units":"1","marks":5},{"id":"reexam-2026-q1b","title":"Q1B · Content and function words","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Define function words and content words.<br>ii. Which category (function words and content words) belong to open class and closed class? Justify your answer.<br>iii. For the sentence “The small cat is sleeping under the tree”, identify the function words and content words. <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Content words</strong> carry much of a sentence’s lexical meaning, usually including nouns, main verbs, adjectives and many adverbs. <strong>Function words</strong> primarily express grammatical relationships, including determiners, prepositions, conjunctions, pronouns and auxiliary verbs.</p><div class=\"table-wrap\"><table><thead><tr><th>Category</th><th>Typical class</th><th>Reason</th></tr></thead><tbody><tr><td>Content words</td><td>Open class</td><td>New nouns, verbs and adjectives enter the language readily, such as new technology names</td></tr><tr><td>Function words</td><td>Closed class</td><td>The grammatical inventory is relatively stable; new determiners or pronouns are much less frequently added</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>Word</th><th>Role in this sentence</th><th>Category</th></tr></thead><tbody><tr><td>The</td><td>Determiner</td><td>Function</td></tr><tr><td>small</td><td>Adjective</td><td>Content</td></tr><tr><td>cat</td><td>Noun</td><td>Content</td></tr><tr><td>is</td><td>Auxiliary supporting progressive tense</td><td>Function</td></tr><tr><td>sleeping</td><td>Main verb</td><td>Content</td></tr><tr><td>under</td><td>Preposition</td><td>Function</td></tr><tr><td>the</td><td>Determiner</td><td>Function</td></tr><tr><td>tree</td><td>Noun</td><td>Content</td></tr></tbody></table></div><p><strong>Final answer:</strong> content words = small, cat, sleeping, tree; function words = The, is, under, the. “is” is auxiliary here; a word’s role must be judged in context. “Closed” means relatively resistant to new members, not that change is logically impossible.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Content words scene batate hain; function words grammar ka connection banate hain.</p>","m2":true,"units":"4","marks":5},{"id":"reexam-2026-q1c","title":"Q1C · Word2Vec and GloVe","html":"<div class=\"question\" style=\"font-weight:700\">Question. Differentiate between word2vec and GloVe in terms of their learning strategies. Which type of corpus would be more suitable for each method, and why? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p>Both Word2Vec and GloVe learn dense word vectors from distributional information: words occurring in related contexts tend to receive related representations. They differ mainly in the training objective and how corpus co-occurrence evidence is used.</p><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Word2Vec</th><th>GloVe</th></tr></thead><tbody><tr><td>Learning strategy</td><td>Predictive: CBOW predicts a centre word; Skip-gram predicts nearby words</td><td>Count-based objective fitted to global word–context co-occurrence statistics</td></tr><tr><td>Training evidence</td><td>Local context windows converted into prediction examples</td><td>A corpus-wide co-occurrence matrix and relationships among counts</td></tr><tr><td>Parameters learned</td><td>Word/context embeddings that make context predictions accurate</td><td>Word/context embeddings and biases that fit weighted log co-occurrence counts</td></tr><tr><td>Corpus considerations</td><td>Large token sequences with useful local context, including domain-specific text</td><td>A sufficiently large corpus from which reliable global co-occurrence statistics can be collected</td></tr></tbody></table></div><p>For a domain such as medicine, either method can benefit from a representative medical corpus. Word2Vec is convenient when generating local training windows directly from a stream of tokens. GloVe is natural when a global sparse co-occurrence matrix can be constructed and stored. Corpus size, domain match, preprocessing and available compute matter; there is no rule that Word2Vec requires informal text while GloVe requires formal text.</p><p>Both standard forms produce one static vector per vocabulary word, so multiple senses are blended. They do not automatically provide a different vector for the same word in each sentence.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Word2Vec predicts local neighbours; GloVe fits global co-occurrence counts.</p>","m2":false,"units":"5","marks":5},{"id":"reexam-2026-q1d","title":"Q1D · Anaphora, cataphora and coreference","html":"<div class=\"question\" style=\"font-weight:700\">Question. Differentiate between cataphora and anaphora in terms of direction of reference. How coreference resolution is different from anaphora reference? <span class=\"marks\">[5 marks]</span></div><h3>Answer</h3><p><strong>Anaphora</strong> points backward to an expression or information introduced earlier. <strong>Cataphora</strong> points forward to an expression introduced later.</p><div class=\"table-wrap\"><table><thead><tr><th>Relation</th><th>Example</th><th>Direction</th></tr></thead><tbody><tr><td>Anaphora</td><td>“Riya arrived. She smiled.” She refers to the earlier Riya.</td><td>Backward</td></tr><tr><td>Cataphora</td><td>“Before she spoke, Riya checked the microphone.” She refers to the later Riya.</td><td>Forward</td></tr></tbody></table></div><p><strong>Coreference</strong> means two or more expressions refer to the same entity. Coreference resolution groups such expressions, regardless of whether they are names, descriptions or pronouns and regardless of which is mentioned first.</p><p>For “Dr Sen arrived. The surgeon smiled. She waved,” {Dr Sen, the surgeon, She} is a coreference cluster. The latter two mentions are also backward-looking references. Coreference is an identity relation; anaphora describes a dependency on prior discourse and is not always identity. For example, “I bought a house. The roof leaks” contains a bridging reference: the roof depends on the house for interpretation, but roof and house are not the same entity.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Ana = pehle ki taraf; cata = aage ki taraf; coreference = same entity.</p>","m2":false,"units":"6","marks":5},{"id":"reexam-2026-q2a","title":"Q2A · NLP tasks and syntax versus semantics","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Discuss five different tasks associated with Natural Language Processing.<br>ii. Compare and contrast syntactic analysis and semantic analysis in NLP. Support your explanation with examples. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Five NLP tasks</h3><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>What it does</th><th>Example</th></tr></thead><tbody><tr><td>Machine translation</td><td>Expresses source-language content in a target language</td><td>English “Good morning” → Hindi greeting</td></tr><tr><td>Sentiment analysis</td><td>Identifies the opinion or attitude expressed</td><td>“The service was excellent” → positive sentiment</td></tr><tr><td>Named Entity Recognition</td><td>Finds and types entity spans</td><td>“Asha joined Google” → PERSON and ORGANIZATION</td></tr><tr><td>Question answering</td><td>Returns an answer supported by a question’s relevant information</td><td>From a passage, identify who discovered a described result</td></tr><tr><td>Text classification</td><td>Assigns predefined category labels</td><td>Classify an email as spam or legitimate</td></tr></tbody></table></div><h3>ii. Syntactic and semantic analysis</h3><div class=\"table-wrap\"><table><thead><tr><th>Basis</th><th>Syntactic analysis</th><th>Semantic analysis</th></tr></thead><tbody><tr><td>Main question</td><td>How are words grammatically organised?</td><td>What do the words and sentence mean?</td></tr><tr><td>Typical output</td><td>POS tags, constituency or dependency structure</td><td>Word senses, semantic relations or a meaning representation</td></tr><tr><td>Knowledge used</td><td>Grammar rules and structural patterns</td><td>Lexical meaning, context and semantic constraints</td></tr><tr><td>Example</td><td>Identify “The boy” as subject NP and “ate an apple” as VP</td><td>Interpret the boy as eater and apple as the thing eaten</td></tr></tbody></table></div><p>“Colourless green ideas sleep furiously” can have a plausible English grammatical structure while remaining semantically unusual. Syntax alone therefore does not guarantee ordinary meaning. Conversely, “boy eat apple yesterday” conveys a possible event despite grammatical errors.</p><p>The analyses support each other. In “I saw the man with a telescope,” syntactic PP attachment determines which meaning is available, and semantic knowledge can help choose a plausible attachment. A full NLP system often needs both.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Syntax = sentence ka structure; semantics = us structure ka meaning.</p>","m2":false,"units":"1,4,5","marks":10},{"id":"reexam-2026-q2b","title":"Q2B · Laplace smoothing on a second corpus","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following training corpus:<br>1. cats chase mice in the garden<br>2. dogs bark loudly at night<br>3. birds sing in the morning<br>4. children play games in the park<br>Using a bigram language model with Laplace smoothing, evaluate the probability of the test sentence: “cats bark in the park.” Assume &lt;s&gt; and &lt;/s&gt; as start and end of the sentence. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><ul><li>cats chase mice in the garden</li><li>dogs bark loudly at night</li><li>birds sing in the morning</li><li>children play games in the park</li></ul><p>Test: cats bark in the park. Add one start token &lt;s&gt; and one end token &lt;/s&gt; to every training and test sentence.</p><h3>To find</h3><p>The Laplace-smoothed bigram probability of the complete test sentence, including its end token.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0167293b8abe1cce.svg\" alt=\"P_{+1}(w_i\\mid w_{i-1})=\\frac{C(w_{i-1},w_i)+1}{C(w_{i-1})+V}\" style=\"width:33.254ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C(previous,current) counts that adjacent pair in the training corpus. C(previous) counts its occurrences as a history. V is the vocabulary size. Add-one smoothing is necessary because an unseen pair must not force the whole sentence probability to zero.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/09cc94e28baa5a90.svg\" alt=\"P(w_1,\\ldots,w_n,\\langle/s\\rangle\\mid\\langle s\\rangle)=\\prod_{i=1}^{n+1}P(w_i\\mid w_{i-1})\" style=\"width:42.048ex;height:6.712ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Fix the token and vocabulary convention</h3><p>Lowercase words and remove the final punctuation. The supplied course key counts both boundary tokens in V. Following that convention: at, bark, birds, cats, chase, children, dogs, games, garden, in, loudly, mice, morning, night, park, play, sing, the, &lt;s&gt;, &lt;/s&gt; gives <strong>V = 20</strong>. The start marker supplies history; it is not an extra probability factor before the first word.</p><h3>Step 2. List every required transition</h3><p>The complete test chain is &lt;s&gt; → cats → bark → in → the → park → &lt;/s&gt;.</p><h3>Step 3. Count first, then add one</h3><div class=\"table-wrap\"><table><thead><tr><th>Required bigram</th><th>History count</th><th>Pair count</th><th>Smoothed probability</th></tr></thead><tbody><tr><td>&lt;s&gt; → cats</td><td>4</td><td>1</td><td>(1+1)/(4+20) = 1/12</td></tr><tr><td>cats → bark</td><td>1</td><td>0</td><td>(0+1)/(1+20) = 1/21</td></tr><tr><td>bark → in</td><td>1</td><td>0</td><td>(0+1)/(1+20) = 1/21</td></tr><tr><td>in → the</td><td>3</td><td>3</td><td>(3+1)/(3+20) = 4/23</td></tr><tr><td>the → park</td><td>3</td><td>1</td><td>(1+1)/(3+20) = 2/23</td></tr><tr><td>park → &lt;/s&gt;</td><td>1</td><td>1</td><td>(1+1)/(1+20) = 2/21</td></tr></tbody></table></div><p>Count only adjacent words, never words that merely appear in the same sentence. The unseen pairs have count zero, so their numerator becomes one.</p><h3>Step 4. Multiply all six probabilities</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/661dddaa8d668f4e.svg\" alt=\"P=\\frac{2}{24}\\times\\frac{1}{21}\\times\\frac{1}{21}\\times\\frac{4}{23}\\times\\frac{2}{23}\\times\\frac{2}{21}\" style=\"width:38.092ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. &lt;s&gt; → cats</td><td><span class=\"math-inline\"><img src=\"math/9cf9ede86d758f1a.svg\" alt=\"1\\times\\frac{1}{12}=\\frac{1}{12}\" style=\"width:12.105ex;height:2.737ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. cats → bark</td><td><span class=\"math-inline\"><img src=\"math/15653088bc649e84.svg\" alt=\"\\frac{1}{12}\\times\\frac{1}{21}=\\frac{1}{252}\" style=\"width:14.368ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. bark → in</td><td><span class=\"math-inline\"><img src=\"math/bc2636bde4d927d0.svg\" alt=\"\\frac{1}{252}\\times\\frac{1}{21}=\\frac{1}{5292}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. in → the</td><td><span class=\"math-inline\"><img src=\"math/5be8f2428aa87996.svg\" alt=\"\\frac{1}{5292}\\times\\frac{4}{23}=\\frac{1}{30429}\" style=\"width:17.568ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. the → park</td><td><span class=\"math-inline\"><img src=\"math/5c01b946da36062b.svg\" alt=\"\\frac{1}{30429}\\times\\frac{2}{23}=\\frac{2}{699867}\" style=\"width:19.168ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. park → &lt;/s&gt;</td><td><span class=\"math-inline\"><img src=\"math/aa10a9e9b5ec1f5a.svg\" alt=\"\\frac{2}{699867}\\times\\frac{2}{21}=\\frac{4}{14697207}\" style=\"width:21.568ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/84afc176da8ea9ec.svg\" alt=\"P=\\frac{4}{14697207}\\approx 2.72160554\\times10^{-7}\" style=\"width:35.849ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Interpret the result</h3><p>This is a joint sentence probability, so a small value is normal. Do not add transition probabilities; each word must occur in sequence, so the chain multiplies them.</p><h3>Final answer</h3><p><strong>P ≈ 2.72160554 × 10<sup>-7</sup></strong> with the stated course vocabulary convention.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Pair count mein 1 jodo, previous-word count mein V; phir saare fractions multiply karo.</p><p><strong>Convention note:</strong> Some implementations exclude &lt;s&gt; from the predicted vocabulary. Their V is one smaller and their numerical probability differs. In an exam, state V explicitly and follow the convention specified in the question or class solution.</p>","m2":true,"units":"3","marks":10},{"id":"reexam-2026-q3a","title":"Q3A · Top-down parsing","html":"<div class=\"question\" style=\"font-weight:700\">Question. In the context of natural language processing, explain the concept of top-down and bottom-up parsing approaches. Apply top-down syntax parsing approach to the sentence “The tall boy saw a girl in the park.” and draw a parse tree using the CFG grammar rules:<br>S → NP VP; NP → Det Adj N | Det N; VP → V NP | VP PP; PP → P NP.<br>Lexicon: Det → {the | a}; Adj → {tall}; N → {boy | girl | park}; V → {saw}; P → {in}. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><div class=\"table-wrap\"><table><thead><tr><th>Aspect</th><th>Top-down</th><th>Bottom-up</th></tr></thead><tbody><tr><td>Start</td><td>The start symbol S</td><td>The input words</td></tr><tr><td>Operation</td><td>Expand a nonterminal using grammar productions</td><td>Combine words and constituents using productions in reverse</td></tr><tr><td>Success</td><td>Leaves match the complete input</td><td>All input is reduced to S</td></tr><tr><td>Possible difficulty</td><td>Naive recursive descent can loop on left recursion or need backtracking</td><td>A naive shift-reduce parser may face shift/reduce conflicts</td></tr></tbody></table></div><h3>Given</h3><p>The sentence contains the tokens the / tall / boy / saw / a / girl / in / the / park. Lowercase the initial “The” to match the lexicon. The full stop is punctuation outside the listed grammar.</p><h3>To find</h3><p>A derivation beginning at S and a parse tree matching the whole sentence.</p><h3>Rule: which one and why</h3><p>A context-free production replaces one nonterminal with its right-hand sequence. A top-down derivation begins at S and expands the desired structure. The supplied grammar attaches the PP through VP → VP PP; it does not provide NP → NP PP.</p><h3>Step 1. Expand the sentence</h3><p>S ⇒ NP VP. Choose NP → Det Adj N for “the tall boy”.</p><h3>Step 2. Match the subject words</h3><p>Det ⇒ the, Adj ⇒ tall, N ⇒ boy. The remaining material must be generated by VP.</p><h3>Step 3. Allow a verb phrase followed by a PP</h3><p>Expand the outer VP using VP → VP PP. Then expand the inner VP using VP → V NP. This finite derivation selects the recursive rule once.</p><h3>Step 4. Match the verb and object</h3><p>V ⇒ saw. Choose NP → Det N, then Det ⇒ a and N ⇒ girl.</p><h3>Step 5. Expand the prepositional phrase</h3><p>PP ⇒ P NP. P ⇒ in. NP ⇒ Det N, with Det ⇒ the and N ⇒ park.</p><h3>Step 6. Check the complete leaf order</h3><p>The leaves read “the tall boy saw a girl in the park”, exactly the normalized input. The PP “in the park” attaches to the VP under this supplied grammar.</p><figure><svg viewBox=\"0 0 820 350\" role=\"img\" aria-label=\"Top-down parse tree showing the PP attached to VP\" style=\"width:100%;max-width:820px;background:#f4f8f7\"><line x1=\"370\" y1=\"38\" x2=\"150\" y2=\"60\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"370\" y1=\"38\" x2=\"560\" y2=\"60\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"55\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"135\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"150\" y1=\"88\" x2=\"215\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"560\" y1=\"88\" x2=\"420\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"560\" y1=\"88\" x2=\"650\" y2=\"115\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"420\" y1=\"143\" x2=\"350\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"420\" y1=\"143\" x2=\"470\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"650\" y1=\"143\" x2=\"575\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"650\" y1=\"143\" x2=\"705\" y2=\"170\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"470\" y1=\"198\" x2=\"440\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"470\" y1=\"198\" x2=\"500\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"705\" y1=\"198\" x2=\"660\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"705\" y1=\"198\" x2=\"750\" y2=\"220\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"55\" y1=\"143\" x2=\"55\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"135\" y1=\"143\" x2=\"135\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"215\" y1=\"143\" x2=\"215\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"350\" y1=\"198\" x2=\"350\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"440\" y1=\"248\" x2=\"440\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"500\" y1=\"248\" x2=\"500\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"575\" y1=\"198\" x2=\"575\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"660\" y1=\"248\" x2=\"660\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><line x1=\"750\" y1=\"248\" x2=\"750\" y2=\"295\" stroke=\"#758f86\" stroke-width=\"2\"/><text x=\"370\" y=\"30\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">S</text><text x=\"150\" y=\"80\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"560\" y=\"80\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"55\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"135\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Adj</text><text x=\"215\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"420\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">VP</text><text x=\"650\" y=\"135\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">PP</text><text x=\"350\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">V</text><text x=\"470\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"575\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">P</text><text x=\"705\" y=\"190\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">NP</text><text x=\"440\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"500\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"660\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">Det</text><text x=\"750\" y=\"240\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">N</text><text x=\"55\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">The</text><text x=\"135\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">tall</text><text x=\"215\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">boy</text><text x=\"350\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">saw</text><text x=\"440\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">a</text><text x=\"500\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">girl</text><text x=\"575\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">in</text><text x=\"660\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">the</text><text x=\"750\" y=\"315\" text-anchor=\"middle\" font-size=\"18\" fill=\"#153e34\" font-family=\"Arial\">park</text></svg><figcaption>Top-down parse tree showing the PP attached to VP.</figcaption></figure><h3>Complete derivation</h3><p>S ⇒ NP VP ⇒ Det Adj N VP ⇒ the tall boy VP ⇒ the tall boy VP PP ⇒ the tall boy V NP PP ⇒ the tall boy saw Det N PP ⇒ the tall boy saw a girl P NP ⇒ the tall boy saw a girl in Det N ⇒ the tall boy saw a girl in the park.</p><p><strong>Implementation caution:</strong> VP → VP PP is left-recursive. A naive recursive-descent implementation may loop; it must transform or otherwise handle the grammar. A valid finite top-down derivation, as shown above, still exists.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Rule jo diya hai wahi use karo: yahan “in the park” VP ka part hai.</p>","m2":true,"units":"4","marks":10},{"id":"reexam-2026-q3b","title":"Q3B · Lesk word-sense disambiguation","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the sentence: “The bank can ensure your deposits are safe.” The word “bank” has the following two possible senses (WordNet-style glosses):<br>Bank₁: Sloping land especially beside a body of water.<br>Bank₂: A financial institution that accepts deposits and channels the money into lending activities.<br>i. Apply the LESK algorithm to determine the correct sense of the word “bank” in the given sentence. Show the steps clearly.<br>ii. Briefly discuss limitations of the LESK algorithm in handling ambiguous words in real-world contexts. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Context sentence and the two supplied dictionary glosses. Use a simplified Lesk method: lowercase, remove function words, exclude the target bank and compare distinct content-word overlap. Do not add synonyms that the question does not supply.</p><h3>To find</h3><p>Which candidate gloss has the greatest overlap with the local context.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/6ad61c84bee7b920.svg\" alt=\"\\mathrm{score}(s)=|C\\cap G_s|,\\qquad \\hat s=\\arg\\max_s\\mathrm{score}(s)\" style=\"width:44.428ex;height:3.457ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C is the set of context content words. Gₛ is the content-word set of the gloss for sense s. The intersection contains words appearing in both; its size is the score. This is an overlap count, not a probability.</p><h3>Solution</h3><h3>Step 1. Prepare the context</h3><p>Remove The, can, your, are and the target bank. A reasonable content set is C = {ensure, deposits, safe}. If “can” is retained under another fixed stop-list it matches neither gloss and does not change the result.</p><h3>Step 2. Prepare Bank₁’s gloss</h3><p>G₁ = {sloping, land, especially, beside, body, water}. There is no shared word with {ensure, deposits, safe}.</p><h3>Step 3. Calculate Bank₁’s score</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bdca68bf983394ca.svg\" alt=\"C\\cap G_1=\\varnothing,\\qquad \\mathrm{score}(1)=0\" style=\"width:29.266ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Prepare Bank₂’s gloss and count overlap</h3><p>G₂ = {financial, institution, accepts, deposits, channels, money, lending, activities}. The shared word is deposits.</p><h3>Step 5. Calculate Bank₂’s score and select</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0107901b24c804b2.svg\" alt=\"C\\cap G_2=\\{\\mathrm{deposits}\\},\\qquad \\mathrm{score}(2)=1\" style=\"width:37.712ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>1 > 0, so choose the financial-institution sense.</p><h3>Final answer</h3><p><strong>Bank₂: financial institution.</strong> The explicit overlap “deposits” supports this choice.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Lesk: context aur har meaning ki definition mein common words count karo; highest overlap choose karo.</p><h3>ii. Limitations</h3><ul><li>Short contexts or short glosses may produce no overlaps or ties.</li><li>Exact word matching misses related words and synonyms, such as deposit versus savings, unless an extension is defined.</li><li>Irrelevant frequent words can create misleading overlaps if preprocessing is poor.</li><li>Dictionary glosses may omit a domain-specific sense or fail to express the context’s wording.</li><li>Simplified Lesk uses limited local information and may miss discourse or real-world knowledge.</li></ul><p>Lemmatization, richer glosses and semantic similarity can improve variants, but the exact variant and tie-breaking rule should be stated.</p>","m2":true,"units":"5","marks":10},{"id":"reexam-2026-q4a","title":"Q4A · Bag of Words and three cosine similarities","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following three documents:<br>Document A: “The dog chased the cat.”<br>Document B: “The cat chased the mouse.”<br>Document C: “The dog ran after the cat.”<br>Using the Bag of Words (BoW) model, represent each document as a vector after removing the stop words {The, by, was}.<br>i. Construct the term-document matrix.<br>ii. Compute the cosine similarity between each pair of documents (A–B, A–C, and B–C).<br>iii. Interpret and comment on the results obtained in terms of document similarity. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Three documents. Lowercase and remove punctuation. Remove the specified stop words case-insensitively; “the” is removed everywhere. Keep “after” because it is not in the supplied stop list. Use raw word counts.</p><h3>To find</h3><p>A common-vocabulary count matrix, three cosine values and their interpretation.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0f69259be30dd3d0.svg\" alt=\"\\mathrm{BoW}_j(d)=C(v_j,d)\" style=\"width:19.466ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>vⱼ is vocabulary term j. The coordinate stores its count in document d; order in the sentence is not retained.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d47266edc91f0bb5.svg\" alt=\"\\cos(\\mathbf a,\\mathbf b)=\\frac{\\sum_j a_jb_j}{\\sqrt{\\sum_j a_j^2}\\sqrt{\\sum_j b_j^2}}\" style=\"width:28.501ex;height:7.827ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Clean each document</h3><p>A: dog chased cat.<br>B: cat chased mouse.<br>C: dog ran after cat.</p><h3>Step 2. Fix vocabulary and matrix</h3><p>Vocabulary: dog, chased, cat, mouse, ran, after.</p><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>A</th><th>B</th><th>C</th></tr></thead><tbody><tr><td>dog</td><td>1</td><td>0</td><td>1</td></tr><tr><td>chased</td><td>1</td><td>1</td><td>0</td></tr><tr><td>cat</td><td>1</td><td>1</td><td>1</td></tr><tr><td>mouse</td><td>0</td><td>1</td><td>0</td></tr><tr><td>ran</td><td>0</td><td>0</td><td>1</td></tr><tr><td>after</td><td>0</td><td>0</td><td>1</td></tr></tbody></table></div><p>A = [1,1,1,0,0,0]; B = [0,1,1,1,0,0]; C = [1,0,1,0,1,1].</p><h3>Step 3. Calculate vector lengths</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0319d5a65cf344a9.svg\" alt=\"\\|A\\|=\\sqrt{1^2+1^2+1^2}=\\sqrt3\" style=\"width:27.25ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/f3f38c6241a4b948.svg\" alt=\"\\|B\\|=\\sqrt{1^2+1^2+1^2}=\\sqrt3\" style=\"width:27.271ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a3902ff8f18f763e.svg\" alt=\"\\|C\\|=\\sqrt{1^2+1^2+1^2+1^2}=2\" style=\"width:30.228ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Calculate A–B</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/7b652d0c42b280a1.svg\" alt=\"A\\cdot B=(1)(0)+(1)(1)+(1)(1)+(0)(1)+(0)(0)+(0)(0)=2\" style=\"width:60.739ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/905c4c3c1ff47cfe.svg\" alt=\"\\cos(A,B)=\\frac2{\\sqrt3\\sqrt3}=\\frac23\\approx0.666667\" style=\"width:36.051ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Calculate A–C</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/0add9a13e11f4556.svg\" alt=\"A\\cdot C=(1)(1)+(1)(0)+(1)(1)+(0)(0)+(0)(1)+(0)(1)=2\" style=\"width:60.742ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/13f584cbebce7216.svg\" alt=\"\\cos(A,C)=\\frac2{\\sqrt3\\cdot2}=\\frac1{\\sqrt3}\\approx0.577350\" style=\"width:37.687ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Calculate B–C</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/00d6bb1eb81ee107.svg\" alt=\"B\\cdot C=(0)(1)+(1)(0)+(1)(1)+(1)(0)+(0)(1)+(0)(1)=1\" style=\"width:60.762ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b9b3f31b850daf8d.svg\" alt=\"\\cos(B,C)=\\frac1{\\sqrt3\\cdot2}\\approx0.288675\" style=\"width:30.634ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>A–B = 0.666667; A–C = 0.577350; B–C = 0.288675.</strong> A and B have the highest lexical overlap under this representation. B and C share only cat. BoW similarity reflects token overlap, not full semantic equivalence or word order.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same vocabulary order rakho. Corresponding counts multiply-add; phir dono lengths se divide.</p>","m2":false,"units":"2","marks":10},{"id":"reexam-2026-q4b","title":"Q4B · A second HMM sequence","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the following POS tagged corpus. Apply Hidden Markov Model (HMM) approach to:<br>1. Dog/Noun eats/Verb bread/Noun<br>2. The/Det cat/Noun sleeps/Verb<br>3. A/Det dog/Noun eats/Verb fish/Noun<br>i. Construct the emission probability matrix.<br>ii. Construct the transmission probability matrix.<br>iii. Calculate the probability of the given sequence of events: The/Det dog/Noun eats/Verb bread/Noun.<br>Note: Include start and end characters for all the sentences. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p>The repeated verb eats has a different emission count from the final paper; recalculate it rather than copying the previous numerical result.</p><h3>Given</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Tagged sequence</th></tr></thead><tbody><tr><td>1</td><td>dog/Noun eats/Verb bread/Noun</td></tr><tr><td>2</td><td>the/Det cat/Noun sleeps/Verb</td></tr><tr><td>3</td><td>a/Det dog/Noun eats/Verb fish/Noun</td></tr></tbody></table></div><p>Lowercase the corpus. Test sequence: the/Det dog/Noun eats/Verb bread/Noun. Add Start and End markers.</p><h3>To find</h3><p>Emission and transition matrices, then the probability of the supplied tagged sequence.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a732ea965eb9fa65.svg\" alt=\"P(w\\mid t)=\\frac{C(t,w)}{C(t)}\" style=\"width:18.717ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/8da165d58e49419c.svg\" alt=\"P(t_j\\mid t_i)=\\frac{C(t_i,t_j)}{\\sum_kC(t_i,t_k)}\" style=\"width:24.245ex;height:5.673ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Emission divides the word’s tag-specific count by the total tokens with that tag. Transition divides the tag-pair count by all transitions leaving the previous tag, including End.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/054557fae74f519d.svg\" alt=\"P(\\mathbf w,\\mathbf t)=P(t_1\\mid\\mathrm{Start})\\prod_iP(w_i\\mid t_i)\\prod_{i=2}^{n}P(t_i\\mid t_{i-1})P(\\mathrm{End}\\mid t_n)\" style=\"width:60.981ex;height:6.354ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Solution</h3><h3>Step 1. Count tag totals and word frequencies</h3><p>Det: the=1, a=1, total2. Noun: dog=2, bread=1, cat=1, fish=1, total5. Verb: eats=2, sleeps=1, total3.</p><h3>Step 2. Construct emission matrix</h3><div class=\"table-wrap\"><table><thead><tr><th>Tag / word</th><th>a</th><th>bread</th><th>cat</th><th>dog</th><th>eats</th><th>fish</th><th>sleeps</th><th>the</th></tr></thead><tbody><tr><td>Det</td><td>1/2</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>1/2</td></tr><tr><td>Noun</td><td>0</td><td>1/5</td><td>1/5</td><td>2/5</td><td>0</td><td>1/5</td><td>0</td><td>0</td></tr><tr><td>Verb</td><td>0</td><td>0</td><td>0</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td><td>0</td></tr></tbody></table></div><h3>Step 3. Count transitions from the three chains</h3><p>Start → Noun → Verb → Noun → End<br>Start → Det → Noun → Verb → End<br>Start → Det → Noun → Verb → Noun → End</p><div class=\"table-wrap\"><table><thead><tr><th>From</th><th>Det count</th><th>Noun count</th><th>Verb count</th><th>End count</th><th>Total</th></tr></thead><tbody><tr><td>Start</td><td>2</td><td>1</td><td>0</td><td>0</td><td>3</td></tr><tr><td>Det</td><td>0</td><td>2</td><td>0</td><td>0</td><td>2</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3</td><td>2</td><td>5</td></tr><tr><td>Verb</td><td>0</td><td>2</td><td>0</td><td>1</td><td>3</td></tr></tbody></table></div><h3>Step 4. Divide outgoing counts</h3><div class=\"table-wrap\"><table><thead><tr><th>From / to</th><th>Det</th><th>Noun</th><th>Verb</th><th>End</th></tr></thead><tbody><tr><td>Start</td><td>2/3</td><td>1/3</td><td>0</td><td>0</td></tr><tr><td>Det</td><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>Noun</td><td>0</td><td>0</td><td>3/5</td><td>2/5</td></tr><tr><td>Verb</td><td>0</td><td>2/3</td><td>0</td><td>1/3</td></tr></tbody></table></div><p>All nonterminal rows sum to one. No smoothing is requested.</p><h3>Step 5. Write every sequence factor</h3><div class=\"table-wrap\"><table><thead><tr><th>Event</th><th>Probability</th></tr></thead><tbody><tr><td>Start → Det</td><td>2/3</td></tr><tr><td>Det emits the</td><td>1/2</td></tr><tr><td>Det → Noun</td><td>1</td></tr><tr><td>Noun emits dog</td><td>2/5</td></tr><tr><td>Noun → Verb</td><td>3/5</td></tr><tr><td>Verb emits eats</td><td>2/3</td></tr><tr><td>Verb → Noun</td><td>2/3</td></tr><tr><td>Noun emits bread</td><td>1/5</td></tr><tr><td>Noun → End</td><td>2/5</td></tr></tbody></table></div><h3>Step 6. Multiply all factors</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2931148a79074475.svg\" alt=\"P=\\frac23\\times\\frac12\\times1\\times\\frac25\\times\\frac35\\times\\frac23\\times\\frac23\\times\\frac15\\times\\frac25\" style=\"width:44.987ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Start with subtotal 1. At each row, multiply the previous subtotal by exactly one next factor. Simplify the fraction after multiplication, but do not round it.</p><div class=\"table-wrap\"><table><thead><tr><th>Factor being included</th><th>Previous subtotal × next factor = new subtotal</th></tr></thead><tbody><tr><td>1. Start → Det</td><td><span class=\"math-inline\"><img src=\"math/b32eeb64b6ce8d87.svg\" alt=\"1\\times\\frac{2}{3}=\\frac{2}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>2. Det emits the</td><td><span class=\"math-inline\"><img src=\"math/0e0cb943fc030998.svg\" alt=\"\\frac{2}{3}\\times\\frac{1}{2}=\\frac{1}{3}\" style=\"width:11.169ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>3. Det → Noun</td><td><span class=\"math-inline\"><img src=\"math/3b61cadbe8860930.svg\" alt=\"\\frac{1}{3}\\times1=\\frac{1}{3}\" style=\"width:10.505ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>4. Noun emits dog</td><td><span class=\"math-inline\"><img src=\"math/8e3868104c41a9da.svg\" alt=\"\\frac{1}{3}\\times\\frac{2}{5}=\\frac{2}{15}\" style=\"width:11.969ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>5. Noun → Verb</td><td><span class=\"math-inline\"><img src=\"math/69517c6e474a3048.svg\" alt=\"\\frac{2}{15}\\times\\frac{3}{5}=\\frac{2}{25}\" style=\"width:12.769ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>6. Verb emits eats</td><td><span class=\"math-inline\"><img src=\"math/e9a1944302b07ad1.svg\" alt=\"\\frac{2}{25}\\times\\frac{2}{3}=\\frac{4}{75}\" style=\"width:12.769ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>7. Verb → Noun</td><td><span class=\"math-inline\"><img src=\"math/a35b29cd9dbe9b05.svg\" alt=\"\\frac{4}{75}\\times\\frac{2}{3}=\\frac{8}{225}\" style=\"width:13.569ex;height:2.79ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>8. Noun emits bread</td><td><span class=\"math-inline\"><img src=\"math/3a78d82833b21a72.svg\" alt=\"\\frac{8}{225}\\times\\frac{1}{5}=\\frac{8}{1125}\" style=\"width:15.168ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr><tr><td>9. Noun → End</td><td><span class=\"math-inline\"><img src=\"math/2baf230e35df5c28.svg\" alt=\"\\frac{8}{1125}\\times\\frac{2}{5}=\\frac{16}{5625}\" style=\"width:15.968ex;height:2.773ex\" loading=\"lazy\" decoding=\"async\"></span></td></tr></tbody></table></div><p>The last subtotal is the complete product. Only now convert the fraction to a decimal.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d4673af7839c15e4.svg\" alt=\"P=\\frac{16}{5625}\\approx0.0028444444\" style=\"width:26.326ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Final answer</h3><p><strong>P = 16/5625 ≈ 0.0028444444</strong> for these words and specified tags jointly. The two occurrences of eats give P(eats | Verb) = 2/3.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same tag structure ho sakta hai, lekin word emission counts dobara count karna.</p><p><strong>Boundary reminder:</strong> Include P(Det | Start) = 2/3 and P(End | Noun) = 2/5. The handwritten key’s final line instead inserts the overall Det fraction 2/10 and omits End; the complete boundary-aware probability requested here is 0.0028444444.</p>","m2":true,"units":"4","marks":10},{"id":"reexam-2026-q5a","title":"Q5A · Why TF–IDF is useful","html":"<div class=\"question\" style=\"font-weight:700\">Question. Justify with an appropriate example the importance of TF-IDF technique in the document representation and information retrieval task. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>TF–IDF</strong> represents each document using weights that combine within-document term frequency with how unusual a term is across the collection. It supports information retrieval by giving larger weight to terms that are frequent in a document but not present in every document.</p><h3>Given</h3><p>Use three short documents: D₁ = “solar energy solar”; D₂ = “wind energy”; D₃ = “energy policy”. Use raw-count TF and natural-log unsmoothed IDF. N = 3.</p><h3>To find</h3><p>A TF–IDF representation illustrating why distinctive terms help retrieve relevant documents.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/341f27f737ff351a.svg\" alt=\"\\mathrm{TFIDF}(t,d)=C(t,d)\\ln\\frac{N}{\\mathrm{df}(t)}\" style=\"width:29.702ex;height:5.247ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>C counts occurrences within a document; df counts documents containing the term. The logarithm reduces the scale of very large rarity ratios.</p><h3>Solution</h3><h3>Step 1. Count term occurrences</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>D₁</th><th>D₂</th><th>D₃</th><th>df</th></tr></thead><tbody><tr><td>solar</td><td>2</td><td>0</td><td>0</td><td>1</td></tr><tr><td>energy</td><td>1</td><td>1</td><td>1</td><td>3</td></tr><tr><td>wind</td><td>0</td><td>1</td><td>0</td><td>1</td></tr><tr><td>policy</td><td>0</td><td>0</td><td>1</td><td>1</td></tr></tbody></table></div><h3>Step 2. Calculate IDF</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/faa332781751eb0a.svg\" alt=\"\\mathrm{IDF}(solar)=\\mathrm{IDF}(wind)=\\mathrm{IDF}(policy)=\\ln3\\approx1.098612\" style=\"width:57.122ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3ca0cca554234bcd.svg\" alt=\"\\mathrm{IDF}(energy)=\\ln(3/3)=0\" style=\"width:26.663ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 3. Multiply each count by its IDF</h3><div class=\"table-wrap\"><table><thead><tr><th>Term</th><th>D₁ weight</th><th>D₂ weight</th><th>D₃ weight</th></tr></thead><tbody><tr><td>solar</td><td>2 × 1.098612 = 2.197224</td><td>0</td><td>0</td></tr><tr><td>energy</td><td>0</td><td>0</td><td>0</td></tr><tr><td>wind</td><td>0</td><td>1.098612</td><td>0</td></tr><tr><td>policy</td><td>0</td><td>0</td><td>1.098612</td></tr></tbody></table></div><h3>Step 4. Connect the representation to retrieval</h3><p>A query containing “solar” matches D₁’s high solar coordinate. A query containing “wind” matches D₂. “energy” alone cannot distinguish these documents under this unsmoothed collection because it occurs in all three. A retrieval system can compare query and document vectors, commonly by cosine similarity.</p><h3>Final answer</h3><p>TF–IDF preserves distinctive lexical evidence and reduces dominance by collection-wide frequent terms. D₁ is most relevant to a solar query under these features.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Document mein frequent + collection mein rare = high TF–IDF.</p><h3>Strengths and limits</h3><p>The representation is sparse, interpretable and useful as a fast baseline. However, basic TF–IDF ignores word order and does not recognise synonyms or multiple word senses automatically. Its weights depend on the collection and on the chosen TF/IDF convention. Fit IDF on training or indexed documents, not on a hidden test set.</p>","m2":false,"units":"2","marks":10},{"id":"reexam-2026-q5b","title":"Q5B · Sentence-window vectors and cosine","html":"<div class=\"question\" style=\"font-weight:700\">Question. Consider the paragraph: The farmer planted seeds in the soil. The rain watered the soil. The sun helped the plants grow. The farmer harvested the plants. The soil became rich and fertile.<br>Target words: farmer, soil, sun, plant.<br>Context words: plant, water, grow, harvest.<br>i. Construct a co-occurrence matrix for the target and context words. Take the window size as one whole sentence.<br>ii. Evaluate the similarity between the vectors of the target words “farmer-soil”, “farmer-sun”, and “farmer-plant” using the cosine similarity.<br>iii. Plot the target word vectors by considering only two dimensions: “planted” and “harvested”. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>Given</h3><p>Five sentence windows. For alignment with the supplied matrix, target plant means the noun plants, occurring in sentences 3 and 4. Context plant covers planted and plants; watered → water; harvested → harvest. Count a target–context pair once per sentence in which both are present, including the plant–plant sentence-presence diagonal.</p><h3>To find</h3><p>The target–context matrix, three cosine similarities and a two-coordinate plot.</p><h3>Formula: which one and why</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/888eadfcee94dff3.svg\" alt=\"M_{ij}=\\sum_s\\mathbf1[\\text{target}_i\\text{ and context}_j\\text{ present in }s]\" style=\"width:44.273ex;height:4.767ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/d47266edc91f0bb5.svg\" alt=\"\\cos(\\mathbf a,\\mathbf b)=\\frac{\\sum_j a_jb_j}{\\sqrt{\\sum_j a_j^2}\\sqrt{\\sum_j b_j^2}}\" style=\"width:28.501ex;height:7.827ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>This is a sentence-presence matrix, not a position-based sliding window that excludes a token from its own context. Stating the convention is necessary because those alternatives give a different diagonal.</p><h3>Solution</h3><h3>Step 1. Normalize and identify each sentence’s contribution</h3><div class=\"table-wrap\"><table><thead><tr><th>Sentence</th><th>Targets present</th><th>Context lemmas present</th></tr></thead><tbody><tr><td>1</td><td>farmer, soil</td><td>plant</td></tr><tr><td>2</td><td>soil</td><td>water</td></tr><tr><td>3</td><td>sun, plant</td><td>plant, grow</td></tr><tr><td>4</td><td>farmer, plant</td><td>plant, harvest</td></tr><tr><td>5</td><td>soil</td><td>none</td></tr></tbody></table></div><h3>Step 2. Fill all matrix rows</h3><div class=\"table-wrap\"><table><thead><tr><th>Target</th><th>plant</th><th>water</th><th>grow</th><th>harvest</th></tr></thead><tbody><tr><td>farmer</td><td>2</td><td>0</td><td>0</td><td>1</td></tr><tr><td>soil</td><td>1</td><td>1</td><td>0</td><td>0</td></tr><tr><td>sun</td><td>1</td><td>0</td><td>1</td><td>0</td></tr><tr><td>plant</td><td>2</td><td>0</td><td>1</td><td>1</td></tr></tbody></table></div><p>Farmer meets context plant in sentences 1 and 4. Soil meets plant in sentence 1 and water in sentence 2. Sun meets plant and grow in sentence 3. The noun plant occurs in sentences 3 and 4, producing its last row.</p><h3>Step 3. Compute farmer–soil</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9a19db4a92763869.svg\" alt=\"\\mathbf f\\cdot\\mathbf s=(2)(1)+(0)(1)+(0)(0)+(1)(0)=2\" style=\"width:42.278ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/a1c307e5c2f60d4e.svg\" alt=\"\\|\\mathbf f\\|=\\sqrt{2^2+0^2+0^2+1^2}=\\sqrt5,\\quad\\|\\mathbf s\\|=\\sqrt2\" style=\"width:44.097ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3d552a0f1e7f606d.svg\" alt=\"\\cos(\\mathbf f,\\mathbf s)=\\frac2{\\sqrt{10}}\\approx0.632456\" style=\"width:27.613ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 4. Compute farmer–sun</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/46e846a5d9fa6557.svg\" alt=\"\\mathbf f\\cdot\\mathbf u=(2)(1)+(0)(0)+(0)(1)+(1)(0)=2\" style=\"width:42.697ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5eb8385d74c2a577.svg\" alt=\"\\|\\mathbf u\\|=\\sqrt2,\\quad\\cos(\\mathbf f,\\mathbf u)=\\frac2{\\sqrt{10}}\\approx0.632456\" style=\"width:41.086ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 5. Compute farmer–plant</h3><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3c4e8c9a3d5b0e2a.svg\" alt=\"\\mathbf f\\cdot\\mathbf p=(2)(2)+(0)(0)+(0)(1)+(1)(1)=5\" style=\"width:42.697ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/65e703346d258ca7.svg\" alt=\"\\|\\mathbf p\\|=\\sqrt{2^2+0^2+1^2+1^2}=\\sqrt6\" style=\"width:31.884ex;height:3.086ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1f1082cbeeb42e0.svg\" alt=\"\\cos(\\mathbf f,\\mathbf p)=\\frac5{\\sqrt{30}}\\approx0.912871\" style=\"width:28.031ex;height:5.344ex\" loading=\"lazy\" decoding=\"async\"></div></div><h3>Step 6. Plot the requested two coordinates</h3><p>Interpret the axis names planted and harvested as their normalized context features plant and harvest. Farmer=(2,1), soil=(1,0), sun=(1,0), plant=(2,1). Farmer and plant overlap; soil and sun overlap.</p><figure><svg viewBox=\"0 0 550 310\" role=\"img\" aria-label=\"Target word vectors plotted on two labelled axes\" style=\"width:100%;max-width:550px;background:#f4f8f7\"><path d=\"M70 250H495 M70 250V25\" stroke=\"#516d64\" fill=\"none\" stroke-width=\"2\"/><text x=\"70\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"50\" y=\"255\" text-anchor=\"middle\" font-size=\"15\">0</text><text x=\"240\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"50\" y=\"165\" text-anchor=\"middle\" font-size=\"15\">1</text><text x=\"410\" y=\"275\" text-anchor=\"middle\" font-size=\"15\">2</text><text x=\"50\" y=\"75\" text-anchor=\"middle\" font-size=\"15\">2</text><circle cx=\"410\" cy=\"160\" r=\"6\" fill=\"#166b55\"/><text x=\"420\" y=\"148\" font-size=\"16\" fill=\"#153e34\">farmer, plant</text><circle cx=\"240\" cy=\"250\" r=\"6\" fill=\"#166b55\"/><text x=\"250\" y=\"238\" font-size=\"16\" fill=\"#153e34\">soil, sun</text><text x=\"280\" y=\"305\" text-anchor=\"middle\" font-size=\"16\">plant (planted)</text><text x=\"15\" y=\"20\" font-size=\"16\">harvest (harvested)</text></svg><figcaption>The plot uses only the requested two coordinates; cosine uses all context columns.</figcaption></figure><h3>Final answer</h3><p>Using the stated noun-target convention: <strong>farmer–soil = 0.632456, farmer–sun = 0.632456, farmer–plant = 0.912871.</strong></p><p class=\"memory\"><strong>Yaad rakho:</strong> Plant noun aur plant verb ko same maana ya separate? Pehle convention likho, phir count karo.</p><h3>Two details that prevent an incorrect answer</h3><p><strong>Arithmetic:</strong> 5/√30 = 0.912871; the source key’s printed approximation 0.9444 does not equal its own fraction. Keep the exact fraction until the last step.</p><p><strong>Normalization:</strong> If the question instead requires all noun and verb forms of plant to be merged as targets, sentence 1 also contains the plant target. Its row becomes [3,0,1,1], and farmer–plant becomes 7/√55 ≈ 0.943880. The paper leaves this choice unstated; the main worked solution explicitly uses the noun-target interpretation that reproduces its supplied matrix.</p>","m2":false,"units":"5","marks":10},{"id":"reexam-2026-q6a","title":"Q6A · Pronoun approaches and lexical relations","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Briefly describe any two approaches to pronoun resolution and mention one advantage of each.<br>ii. Describe the difference between Homonymy and Synonymy with suitable examples. Discuss how these two relations differently affect natural language processing applications? <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Two approaches to pronoun resolution</h3><div class=\"table-wrap\"><table><thead><tr><th>Approach</th><th>How it works</th><th>Advantage</th></tr></thead><tbody><tr><td>Rule-based / syntactic</td><td>Uses parse structure, agreement, recency and linguistic constraints. Hobbs’ algorithm searches parse trees for eligible antecedents.</td><td>Interpretable: a proposed antecedent can be traced to explicit rules.</td></tr><tr><td>Statistical or neural</td><td>Learns candidate–pronoun compatibility or whole-document coreference patterns from labelled examples, using context and linguistic features or contextual embeddings.</td><td>Can learn interactions and contextual cues that are difficult to enumerate as hand-written rules.</td></tr></tbody></table></div><p>For “Asha dropped the glass because it was slippery,” a system should evaluate candidate referents and context rather than merely choose the most recent noun. Rules can constrain number and syntax; learned models can use compatibility patterns, though neither approach is guaranteed to resolve every ambiguity.</p><h3>ii. Homonymy and synonymy</h3><div class=\"table-wrap\"><table><thead><tr><th>Relation</th><th>Definition</th><th>Example</th></tr></thead><tbody><tr><td>Homonymy</td><td>Same spelling or sound, unrelated meanings</td><td>bank as financial institution versus bank as river edge</td></tr><tr><td>Synonymy</td><td>Different words with the same or closely related meanings in a context</td><td>car and automobile; big and large</td></tr></tbody></table></div><p>Homonymy creates an ambiguity problem: a search for bank may retrieve finance or rivers. WSD uses context to choose the intended sense. Synonymy creates a vocabulary-matching problem: a document saying automobile may be relevant to a query saying car. Query expansion or semantic representations can improve recall by connecting related terms.</p><p>The remedies differ. Do not merge unrelated homonym senses simply because their spelling matches. Do not insist on exact surface-form matching when different words express the same concept. Synonyms are also context-sensitive: “big mistake” and “large mistake” are not always equally natural.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Homonym: same word-form, different meaning. Synonym: different words, similar meaning.</p>","m2":false,"units":"5,6","marks":10},{"id":"reexam-2026-q6b","title":"Q6B · Hobbs: Ramesh and Shyam","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain Hobbs’ Algorithm for pronoun resolution. State its main steps and limitations.<br>ii. Apply Hobbs’ Algorithm to the sentence: “When Ramesh gave Shyam a book, he smiled.” Identify the antecedent of “he” by showing traversal steps. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><p><strong>Hobbs’ algorithm</strong> is a syntax-based pronoun-resolution procedure that searches constituency parse trees in a specified order. It proposes noun phrases as antecedents and filters incompatible candidates, for example by number and gender agreement.</p><p><strong>Read the tree labels first:</strong> NP means noun phrase; S means sentence/clause; VP means verb phrase. X is the current NP or S search node, and p is the upward path used to reach it. Breadth-first means shallower nodes before deeper nodes; left-to-right fixes the order at the same depth. An N-bar (N′) node is the noun-centred part of an NP in a parse using that label.</p><h3>Complete ordered procedure</h3><ol><li><strong>Locate the pronoun.</strong> Start at the NP immediately dominating the pronoun: the smallest NP containing it.</li><li><strong>Make the first climb.</strong> Move upward to the first NP or S above the starting NP. Call it X and record the path p.</li><li><strong>Search initially to the left.</strong> Traverse branches below X to the left of p, breadth-first and left-to-right. Propose an NP only if another NP or S lies between that candidate and X. Check agreement and other applicable constraints for each proposed candidate; accept the first eligible compatible one.</li><li><strong>Check the highest sentence.</strong> If X is the highest S and no candidate has been accepted, search previous sentence trees, most recent first. In each, traverse breadth-first and left-to-right and propose NPs. Accept the first eligible compatible candidate; if the available context contains none, report no resolved antecedent.</li><li><strong>Otherwise climb again.</strong> Move from X to the next NP or S above it. Make that node the new X and record the new upward path p.</li><li><strong>Test a higher NP.</strong> If the new X is an NP, propose X only when p did not pass through its nominal N-bar child. Apply the same compatibility checks. Use the labels in the supplied parse; do not invent a missing N-bar branch.</li><li><strong>Search left again.</strong> Traverse the new X’s branches to the left of p, breadth-first and left-to-right, proposing NPs. The extra intervening-NP/S requirement in Step 3 belongs to the initial search.</li><li><strong>Search permitted right branches.</strong> If X is an S, traverse branches to the right of p, breadth-first and left-to-right, but do not descend below any NP or S encountered. Propose the encountered eligible NPs and test their compatibility.</li><li><strong>Repeat or finish.</strong> Return to Step 4 until a compatible candidate is accepted or the available sentence trees are exhausted. Record the candidate order and why each candidate was accepted or rejected.</li></ol><p><strong>Why the initial restriction matters:</strong> in “John saw him”, the subject NP John is directly under the clause S, with no additional NP or S between them. Step 3 therefore does not propose John as the ordinary local antecedent of him. A reflexive such as himself is a different grammatical case. The worked question below shows the specific parse and traversal; selecting an antecedent is not simply choosing the nearest name.</p><h3>Given</h3><p>The pronoun he is the subject of the main clause. The preceding subordinate clause is “When Ramesh gave Shyam a book”. Assume the temporal clause attaches to the whole main sentence.</p><h3>To find</h3><p>The first suitable antecedent in the left-to-right breadth-first search of the preceding clause.</p><pre tabindex=\"0\" aria-label=\"Assumed constituent tree for Ramesh, Shyam and he\">S (main)                        ← first X\n├── SBAR: When\n│   └── S (embedded)             ← intervening S\n│       ├── NP: Ramesh           ← first candidate\n│       └── VP\n│           ├── V: gave\n│           ├── NP: Shyam\n│           └── NP: a book\n├── NP: he                      ← start\n└── VP: smiled</pre><h3>Step 1. Locate the pronoun NP</h3><p>Start at NP “he” and move upward to its S ancestor. Record the path from he.</p><h3>Step 2. Search branches before the pronoun</h3><p>The initial when-clause lies to the left of the path. Apply Step 3: its embedded S lies between each of its noun phrases and the main S, so these NPs satisfy the initial intervening-NP/S requirement. Traverse left-to-right and breadth-first.</p><h3>Step 3. Propose noun phrases</h3><p>The subject NP Ramesh is encountered before the deeper object NP Shyam and object NP a book. Ramesh agrees with the assumed singular-male pronoun.</p><h3>Step 4. Accept the first compatible antecedent</h3><p>Select Ramesh. Shyam is also a semantically possible referent in ordinary discourse, but the algorithm’s stated syntactic preference selects Ramesh first.</p><h3>Limitations</h3><ul><li>Requires a suitable and accurate constituency parse.</li><li>Agreement information may be unknown or insufficient when several people match.</li><li>Ignores much of the event semantics, discourse focus and world knowledge.</li><li>An ambiguous parse or different attachment can change candidate order.</li></ul><p><strong>Final answer:</strong> <strong>Ramesh</strong>, under the shown parse and ordinary agreement assumptions. A syntactic preference is not a guarantee about the author’s intended meaning.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Left branches ko breadth-first dekho; pehla eligible matching NP choose karo.</p>","m2":false,"units":"6","marks":10},{"id":"reexam-2026-q7a","title":"Q7A · Information retrieval","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Explain the concept of Information Retrieval, highlighting its role in Recommender Systems and Search Engines.<br>ii. Discuss the various steps involved in the Information Retrieval process. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Concept and roles</h3><p><strong>Information Retrieval (IR)</strong> finds and ranks documents or other information objects relevant to a user’s information need. A query is the user’s expression of that need. IR typically returns a ranked set of items; information extraction instead identifies structured facts or fields inside those items.</p><div class=\"table-wrap\"><table><thead><tr><th>Application</th><th>Role of IR</th><th>Example</th></tr></thead><tbody><tr><td>Search engine</td><td>Matches a submitted query against a large indexed collection and ranks candidate pages</td><td>A search for “symptoms of dehydration” returns relevant health pages</td></tr><tr><td>Recommender system</td><td>Retrieves candidate items using a user profile, recent activity or a content representation; a later model may personalize ranking</td><td>Retrieve articles similar to topics the user reads</td></tr></tbody></table></div><p>Retrieval is a component of many recommenders; recommendation also involves preferences, feedback, novelty and business constraints. A recommender need not wait for an explicit textual query.</p><h3>ii. Retrieval process</h3><div class=\"flow\"><span class=\"flow-box\">Collect</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Preprocess</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Index</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Process query</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Retrieve candidates</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Rank</span> <span aria-hidden=\"true\">→</span> <span class=\"flow-box\">Evaluate</span></div><ol><li><strong>Collect and define documents.</strong> Crawl or ingest documents, record metadata and remove unwanted duplicates.</li><li><strong>Preprocess.</strong> Tokenize and normalize using rules suitable for both documents and queries. Preserve task-relevant information.</li><li><strong>Build representations and an index.</strong> An inverted index maps each term to the documents containing it; a dense retrieval system stores vector representations.</li><li><strong>Process the query.</strong> Apply compatible tokenization, spelling handling or expansion, then obtain query features.</li><li><strong>Retrieve candidates.</strong> Use the index to identify potentially relevant documents efficiently.</li><li><strong>Score and rank.</strong> A lexical method may use TF–IDF/BM25-style evidence; a semantic method compares representations. Rank scores estimate relevance rather than proving correctness.</li><li><strong>Present results.</strong> Return titles, snippets and links, possibly with filtering or diversification.</li><li><strong>Evaluate and update.</strong> Use relevance judgments and measures such as precision, recall or ranking metrics. Refresh the index as documents change.</li></ol><p>Example: for “solar energy storage”, an inverted index retrieves documents containing those terms; a ranking function rewards useful matches. A semantic system may also retrieve relevant material using related terms such as batteries.</p><p class=\"memory\"><strong>Yaad rakho:</strong> IR mein relevant document dhoondho aur rank karo; extraction mein document ke andar facts nikalo.</p>","m2":false,"units":"7","marks":10},{"id":"reexam-2026-q7b","title":"Q7B · Gutenberg corpus and normalization","html":"<div class=\"question\" style=\"font-weight:700\">Question. i. Discuss how the Gutenberg Corpus can be utilized for various text analysis tasks in Natural Language Processing?<br>ii. Explain the importance of text normalization in Natural Language Processing (NLP). Illustrate your answer with a suitable example of an application where text normalization plays a crucial role. <span class=\"marks\">[10 marks]</span></div><h3>Answer</h3><h3>i. Using the Gutenberg corpus</h3><p>The Gutenberg corpus provides literary texts, commonly used through tools such as NLTK’s Gutenberg collection. It supplies naturally occurring sentences and longer documents for exploring language patterns. The available subset and licensing should be checked before reuse in a new distribution.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Use of the corpus</th></tr></thead><tbody><tr><td>Frequency and vocabulary study</td><td>Count tokens and word types, inspect common words and compare lexical diversity across texts</td></tr><tr><td>Concordances and collocations</td><td>View a word in context and discover words that occur near each other</td></tr><tr><td>N-gram language modeling</td><td>Estimate unigram or bigram counts and compare sequence probabilities</td></tr><tr><td>Stylistic or authorship analysis</td><td>Compare sentence lengths, vocabulary and function-word patterns across authors</td></tr><tr><td>Text preprocessing experiments</td><td>Study the effect of tokenization, case normalization and lemmatization on counts</td></tr></tbody></table></div><p>A sound workflow selects files, inspects encoding and boundaries, tokenizes consistently, computes the relevant statistics and interprets them against corpus composition. Literary text is not automatically representative of chat, medical records or present-day search queries; domain mismatch matters.</p><h3>ii. Text normalization</h3><p><strong>Normalization</strong> converts selected surface variants into a consistent form so that equivalent expressions do not unnecessarily produce different features. Possible steps include case folding, whitespace cleanup, Unicode normalization, contraction expansion and lemmatization. Choose these according to the task.</p><h3>Example: product search</h3><ol><li>Raw query: “  RUNNING   shoes ”. Product description: “Comfortable run shoes”.</li><li>Trim extra whitespace and apply consistent case: “running shoes”.</li><li>If the application chooses lemmatization, running → run. The query and the indexed description now share the intended run and shoes features.</li><li>Apply the same normalization to stored documents and future queries, otherwise matching remains inconsistent.</li></ol><p>Normalization reduces avoidable vocabulary variation and can improve recall. It must preserve distinctions important to the task: lowercasing US to us may lose meaning, and removing “not” can reverse sentiment. Aggressive stemming or synonym replacement can create incorrect matches.</p><p class=\"memory\"><strong>Yaad rakho:</strong> Same meaning ke surface variants ko consistent banao; useful meaning delete mat karo.</p>","m2":false,"units":"2,3","marks":10}]}],"revision":[{"id":"tee-revision","title":"TEE · full-course revision","unit":0,"sections":[{"id":"all-units","title":"All seven units: final revision","html":"<p>TEE is 100 marks in 3 hours, scaled to 50 in the course total. Q1 is compulsory; choose any four of Q2–Q7. Each full question carries 20 marks. The two supplied 2025–26 papers follow this rule. Do not use the short M2 route as complete TEE preparation.</p><table><thead><tr><th>Unit</th><th>Must be able to explain</th><th>Must be able to work</th></tr></thead><tbody><tr><td>1</td><td>NLP levels, building blocks, NLU/NLG, approaches, pipeline and challenges</td><td>Classify ambiguity and identify linguistic units in examples.</td></tr><tr><td>2</td><td>Tokenization, case, stopwords, stemming/lemmatization, encoding, BoW/TF-IDF</td><td>Construct vectors; compute TF-IDF, cosine/Jaccard/Euclidean/Manhattan/Minkowski.</td></tr><tr><td>3</td><td>Corpora, annotation, dictionaries, regex, N-gram models and smoothing</td><td>List n-grams; count probabilities; smooth; compute sentence probability/perplexity.</td></tr><tr><td>4</td><td>POS approaches, HMM, chunking/chinking, CFG parsing, NER</td><td>Build emission/transition matrices; score paths; draw a tree; trace parser operations.</td></tr><tr><td>5</td><td>Lexical relations, WordNet, WSD, distributional/vector semantics, Word2Vec, GloVe</td><td>Lesk and NB; co-occurrence vectors; similarity; CBOW/Skip-gram examples.</td></tr><tr><td>6</td><td>Pragmatics/discourse, reference, coreference, pronouns, Hobbs and other approaches</td><td>Identify chains; show a tree traversal and state parse assumptions.</td></tr><tr><td>7</td><td>Classification, sentiment, spelling, translation, QA, IE, IR</td><td>Design an application pipeline; calculate relevant model/evaluation examples.</td></tr></tbody></table><h3>TEE revision sequence</h3><p>First revise the formula sheet and one full example per numerical family. Next read each unit’s definitions and comparisons. Then work one complete previous paper using its original choice rule. Finally revisit only the steps you got wrong, and read the other paper’s new question forms. Keep examples and diagrams beside definitions when revising; a term you cannot illustrate is not yet ready to explain.</p><p>For a 10-mark numerical, show the count table or matrix and the intermediate probabilities. For a 10-mark theory answer, organise definition, mechanism/steps, diagram/example, advantages and limitations around the actual question. Do not add unrelated paragraphs just to fill space.</p>"},{"id":"numerical-method","title":"Numerical answer framework","html":"<table><thead><tr><th>Question clue</th><th>Use this method</th><th>First thing to write</th></tr></thead><tbody><tr><td>“next word”, “sentence probability”</td><td>N-gram model</td><td>List the needed word transitions.</td></tr><tr><td>“unseen pair”, “Laplace”</td><td>Add-one smoothing</td><td>State V and count each history.</td></tr><tr><td>“perplexity”</td><td>Reciprocal Nth root</td><td>State P(test sequence) and N.</td></tr><tr><td>“transition/emission matrix”</td><td>HMM count estimation</td><td>Separate tag-to-tag counts from tag-to-word counts.</td></tr><tr><td>“given tag sequence”</td><td>HMM joint path</td><td>Initial × emission × transition × emission …</td></tr><tr><td>“best tag sequence”</td><td>Viterbi or enumerate tiny paths</td><td>Initialise one score per tag; retain predecessor maxima.</td></tr><tr><td>“gloss overlap”</td><td>Simplified Lesk</td><td>Preprocess context and glosses consistently.</td></tr><tr><td>“classify word sense with counts”</td><td>Naive Bayes WSD</td><td>Priors from examples, likelihoods from tokens.</td></tr><tr><td>“parse tree”</td><td>Given CFG + chosen parser</td><td>Show grammar expansions or stack reductions.</td></tr></tbody></table><h3>Errors that change the answer</h3><p>1. Dividing a conditional count by the whole corpus instead of its history count. 2. Adding 1 to the numerator without adding |V| to the denominator. 3. Forgetting the end transition. 4. Counting repeated words as new vocabulary types. 5. Using P(tag|word) in place of P(word|tag). 6. Calling an unnormalised score a posterior. 7. Silently mixing case, lemmatisation or boundary conventions.</p><h3>Short theory answer format</h3><p>For 2 marks: give the exact definition and one specific example or distinction. For 3 marks: add the mechanism or two ordered steps; include a small diagram/table where it carries information. The actual allocation is examiner-dependent, so these are writing guides, not an official marking scheme.</p>"}],"scope":"TEE · revision, not a replacement for full lessons"}],"about":[{"id":"pyq-analysis","title":"All recovered TEE papers · unit, topic and marks map","unit":"PYQ","sections":[{"id":"all-papers","title":"Latest and older papers: exact question map","html":"<h3>How to use this question map</h3><p>Start with the newest final and re-exam, then use older papers to practise variations. The table links each original lettered part to its complete worked answer. <strong>Repeated questions are history, not a prediction.</strong> A syllabus topic stays required even when no recovered paper asks it.</p><p><strong>Marks:</strong> 100 marks are attempted: compulsory Q1 (20), then any four other 20-mark questions. Most recovered papers offer140 marks; NLP December2023 offers120 because the complete original ends at Q6. A mixed question retains one mark allocation; its units are not counted as separate questions. Blank individual allocations remain unknown.</p><h3>2026-02-09 · re-exam · R26</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · NLP pipeline</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 1, 4 · Content and function words</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 5 · Word2Vec and GloVe</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 6 · Cataphora, anaphora and coreference</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 1 · Five NLP tasks; syntax and semantics</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q2a\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 3 · Add-one bigram sentence probability</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q2b\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 4 · Top-down CFG parsing</td><td>case</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q3a\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 5 · Lesk with supplied glosses</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q3b\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 2 · Bag of words and three cosine similarities</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 4 · HMM estimation and given tag-path joint probability</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 2 · Explain and illustrate TF-IDF</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 5 · Co-occurrence, cosine and normalized plot</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q5b\">Read question + answer</a> · Target/context normalization and sentence-presence convention stated; alternative target lemmatization has a separately calculated result.</td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 5, 6 · Pronoun-resolution methods; homonymy and synonymy</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q6a\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 6 · Hobbs antecedent traversal</td><td>case</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q6b\">Read question + answer</a> · Hobbs requires a parse and compatibility assumptions. The assumed parse and traversal order are disclosed.</td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 7 · Information-retrieval stages</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q7a\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 2, 3 · Gutenberg and text normalization</td><td>theory</td><td><a href=\"/nlp/#tee/papers/reexam-2026/reexam-2026-q7b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 2 parts, 15 known marks; Unit 1, 4: 1 parts, 5 known marks; Unit 5: 3 parts, 25 known marks; Unit 6: 2 parts, 15 known marks; Unit 3: 1 parts, 10 known marks; Unit 4: 2 parts, 20 known marks; Unit 2: 2 parts, 20 known marks; Unit 5, 6: 1 parts, 10 known marks; Unit 7: 1 parts, 10 known marks; Unit 2, 3: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2025-12-02 · final · F25</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · NLU versus NLG</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 4 · Chunking, chinking and POS</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 5 · Hyponymy/hypernymy and WSD</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 6 · Pragmatic and discourse analysis</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 1, 4 · Morpheme/lexeme and NER applications</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q2a\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 3 · Add-one bigram sentence probability</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q2b\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 1, 4 · Ambiguities and bottom-up CFG parse</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q3a\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 5 · Co-occurrence, cosine and vector plot</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q3b\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 2 · Three preprocessing techniques</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 4 · HMM estimation and given tag-path joint probability</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 2 · TF-IDF matrix</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 5 · Naive Bayes word-sense disambiguation</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q5b\">Read question + answer</a> · Fixed vocabulary/OOV treatment is stated; source-key OOV smoothing differs. Both conventions and their consequence are explained.</td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 5, 6 · Coreference/pronouns; CBOW and Skip-gram</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q6a\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 6 · Hobbs antecedent traversal</td><td>case</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q6b\">Read question + answer</a> · Hobbs requires a parse and compatibility assumptions. The assumed parse and traversal order are disclosed.</td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 7 · Document-classification pipeline</td><td>theory</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q7a\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 2, 3 · Corpus structures and Jaccard example</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/final-2025/final-2025-q7b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 1 parts, 5 known marks; Unit 4: 2 parts, 15 known marks; Unit 5: 3 parts, 25 known marks; Unit 6: 2 parts, 15 known marks; Unit 1, 4: 2 parts, 20 known marks; Unit 3: 1 parts, 10 known marks; Unit 2: 2 parts, 20 known marks; Unit 5, 6: 1 parts, 10 known marks; Unit 7: 1 parts, 10 known marks; Unit 2, 3: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2025-02-21 · re-exam · R25</h3><p>140 marks offered; 100 attempted. Q1 total20 is printed, but the four individual part allocations are blank. Do not infer5marks as if printed. Sixth PDF page is blank.</p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [not printed individually]</strong></td><td>Unit 2 · BoW and one-hot encoding</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [not printed individually]</strong></td><td>Unit 5 · Lesk WSD</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [not printed individually]</strong></td><td>Unit 4 · Syntax parsing approaches</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [not printed individually]</strong></td><td>Unit 1, 7 · NLU versus NLG and applications</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · TF–IDF cosine after a fixed stoplist</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q2a\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 7 · Weather Naive Bayes</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q2b\">Read question + answer</a></td></tr><tr><td><strong>Q3a [5]</strong></td><td>Unit 6 · Coreference and anaphora</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q3a\">Read question + answer</a></td></tr><tr><td><strong>Q3b [5]</strong></td><td>Unit 6 · Cohesion, coherence and discourse markers</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q3b\">Read question + answer</a></td></tr><tr><td><strong>Q3c [10]</strong></td><td>Unit 7 · Question answering system</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q3c\">Read question + answer</a></td></tr><tr><td><strong>Q4a [5]</strong></td><td>Unit 1 · NLP pipeline</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [5]</strong></td><td>Unit 1 · Morphology and syntax</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q4b\">Read question + answer</a></td></tr><tr><td><strong>Q4c [10]</strong></td><td>Unit 3 · Most probable bigram continuations</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q4c\">Read question + answer</a></td></tr><tr><td><strong>Q5a [6]</strong></td><td>Unit 2 · Preprocess the NLP passage</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [4]</strong></td><td>Unit 2 · Stemming and lemmatization tools</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q5b\">Read question + answer</a></td></tr><tr><td><strong>Q5c [10]</strong></td><td>Unit 6 · Hobbs on John and Mary</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q5c\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 3 · Corpora and acquisition</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q6a\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 4 · HMM components and estimates</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q6b\">Read question + answer</a></td></tr><tr><td><strong>Q7a [5]</strong></td><td>Unit 4 · Word classes, chunking and chinking</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q7a\">Read question + answer</a></td></tr><tr><td><strong>Q7b [5]</strong></td><td>Unit 4 · Named entity recognition</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q7b\">Read question + answer</a></td></tr><tr><td><strong>Q7c [10]</strong></td><td>Unit 5 · Co-occurrence with inconsistent requested comparisons</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r25/q7c\">Read question + answer</a> · Source defect: follow-up names belong to another corpus. Exact supported matrix is complete; unsupported parts are explicitly unresolved from the original data.</td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 2: 4 parts, 20 known marks + 1 parts with no individual mark printed; Unit 5: 2 parts, 10 known marks + 1 parts with no individual mark printed; Unit 4: 4 parts, 20 known marks + 1 parts with no individual mark printed; Unit 1, 7: 1 parts, 0 known marks + 1 parts with no individual mark printed; Unit 7: 2 parts, 20 known marks; Unit 6: 3 parts, 20 known marks; Unit 1: 2 parts, 10 known marks; Unit 3: 2 parts, 20 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2024-12-03 · final · F24</h3><p>140 marks offered; 100 attempted. Four Q1 part allocations are blank; their group totals20. Other printed lettered allocations determine each 20-mark main question.</p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [not printed individually]</strong></td><td>Unit 2, 7 · TF–IDF in retrieval</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [not printed individually]</strong></td><td>Unit 4 · NER and approaches</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [not printed individually]</strong></td><td>Unit 5 · Skip-gram and CBOW</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [not printed individually]</strong></td><td>Unit 6 · Pragmatics and discourse</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [6]</strong></td><td>Unit 2, 4 · Six preprocessing operations</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q2a\">Read question + answer</a></td></tr><tr><td><strong>Q2b [4]</strong></td><td>Unit 2, 5 · Lexical similarity and cosine</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q2b\">Read question + answer</a></td></tr><tr><td><strong>Q2c [10]</strong></td><td>Unit 7 · Animal categorical Naive Bayes</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q2c\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 6 · Hobbs and ambiguous professor–student reference</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q3a\">Read question + answer</a> · Pronoun referent is ambiguous without extra gender/discourse information; structural algorithm preference is separated from semantic interpretation.</td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 7 · Classification and sentiment in industry</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q3b\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 4 · Top-down syntax tree</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 3 · Data acquisition and four augmentation methods</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 2 · Feature engineering, BoW and Euclidean</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [5]</strong></td><td>Unit 5 · WSD approaches and uses</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q5b\">Read question + answer</a></td></tr><tr><td><strong>Q5c [5]</strong></td><td>Unit 6 · Discourse analysis of a conversation</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q5c\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 3 · Henry bigram continuations</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q6a\">Read question + answer</a> · Case is retained as printed: Do and do are distinct. The corpus is not silently grammatically corrected.</td></tr><tr><td><strong>Q6b [5]</strong></td><td>Unit 1 · Five linguistic levels</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q6b\">Read question + answer</a></td></tr><tr><td><strong>Q6c [5]</strong></td><td>Unit 1 · NLU and NLG working together</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q6c\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 4 · POS, chunks and boundary-aware HMM</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q7a\">Read question + answer</a> · Printed tags are used as training data; START and END are explicitly required and included.</td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 5 · Co-occurrence, dot products and plot</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f24/q7b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 2, 7: 1 parts, 0 known marks + 1 parts with no individual mark printed; Unit 4: 3 parts, 20 known marks + 1 parts with no individual mark printed; Unit 5: 3 parts, 15 known marks + 1 parts with no individual mark printed; Unit 6: 3 parts, 15 known marks + 1 parts with no individual mark printed; Unit 2, 4: 1 parts, 6 known marks; Unit 2, 5: 1 parts, 4 known marks; Unit 7: 2 parts, 20 known marks; Unit 3: 2 parts, 20 known marks; Unit 2: 1 parts, 10 known marks; Unit 1: 2 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2024-02-12 · re-exam · R24</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 6 · Anaphora versus cataphora</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 3 · Five corpora</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 1 · Linguistic foundations</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 3 · Five regex operators</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 3 · Wordlist puzzle and lexical resource</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q2a\">Read question + answer</a> · The dictionary is unspecified; an exact number of valid words would be fabricated.</td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 1, 7 · NLP applications and limitations</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q2b\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 4 · Top-down restaurant parse</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q3a\">Read question + answer</a> · Original CFG is incomplete for the given bare-plural object. Exact failure and explicit repaired derivation are both shown.</td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 2 · Preprocessing pipeline</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q3b\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 5 · Embeddings and Skip-gram</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 2, 4 · POS, NER, chunking and TTR</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 5 · Lexical and vector semantics</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 7 · Classification label structures</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q5b\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 2, 7 · TF–IDF in document representation</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q6a\">Read question + answer</a> · The prompt requests an example but supplies no corpus. Numbers in the explanation are authored illustrations, not original numerical givens.</td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 4 · HMM tables and path</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q6b\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 7 · Healthcare and finance applications</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q7a\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 7 · Naive Bayes sentiment</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r24/q7b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 6: 1 parts, 5 known marks; Unit 3: 3 parts, 20 known marks; Unit 1: 1 parts, 5 known marks; Unit 1, 7: 1 parts, 10 known marks; Unit 4: 2 parts, 20 known marks; Unit 2: 1 parts, 10 known marks; Unit 5: 2 parts, 20 known marks; Unit 2, 4: 1 parts, 10 known marks; Unit 7: 3 parts, 30 known marks; Unit 2, 7: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2023-12-01 · final · F23</h3><p>120 marks offered; 100 attempted. Original has six main questions on three pages: Q1 compulsory and any four of Q2–Q6. Offered total 120, attempted 100.</p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 5, 6 · WSD and pronoun resolution</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 5 · WordNet and its hierarchy</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 2, 7 · Sentiment feature extraction</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 7 · Binary, multiclass and multilabel</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 3 · Text corpus structure and applications</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q2a\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 5 · Lesk versus Walker and bank disambiguation</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q2b\">Read question + answer</a> · The original gives a sentence but no thesaurus/category mapping, so a unique numerical score cannot be recovered.</td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 6 · Hobbs algorithm and limitations</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q3a\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 2 · Stemming and lemmatization</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q3b\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 5 · Lexical and vector semantics</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 2 · Three-document TF–IDF</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 5 · Word embeddings and CBOW</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 4 · HMM tables and given path</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q5b\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 7 · Text classification pipeline</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q6a\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 2, 7 · VSM, TF and IDF in retrieval</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f23/q6b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 5, 6: 1 parts, 5 known marks; Unit 5: 4 parts, 35 known marks; Unit 2, 7: 2 parts, 15 known marks; Unit 7: 2 parts, 15 known marks; Unit 3: 1 parts, 10 known marks; Unit 6: 1 parts, 10 known marks; Unit 2: 2 parts, 20 known marks; Unit 4: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2023-01-30 · re-exam · R23</h3><p>140 marks offered; 100 attempted. Q1 header is unclear/conflicting [14/20], but all four parts print 5 marks each; sum=20. Main paper is 100 attempted marks.</p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 2 · Normalization changes vocabulary</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 3 · Good corpus characteristics</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 5 · Word2Vec versus Doc2Vec</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q1c\">Read question + answer</a> · legacy named-method extension; not separately named in current syllabus. Optional historical extension; not a separately prescribed current-syllabus method.</td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 1, 4 · Ambiguity in NLP</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · Normalize the Tanisha–Simran passage</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q2a\">Read question + answer</a> · Stoplist and stemming algorithm are choices, not supplied numerical givens; both are stated.</td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 2, 5 · Text vectorization alternatives</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q2b\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 1, 5, 6 · Semantics, pragmatics and two ambiguities</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q3a\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 7 · Naive Bayes text classifier</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q3b\">Read question + answer</a> · Chinese corpus is an authored/reused teaching illustration here; it is actual given data in F22 Q5b, not this prompt.</td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 2 · Jaccard, cosine and Euclidean without preprocessing</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 5 · CBOW and Skip-gram</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 3 · Password regex</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 7 · Two NLP applications</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q5b\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 6 · Mention-pair model</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q6a\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 7 · Classification evaluation including ROC/AUC</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q6b\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 4 · Organization and facility mentions</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q7a\">Read question + answer</a> · Boundary and generic-mention decisions depend on the provided ACE annotation convention; the answer distinguishes them from a named-only interpretation.</td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 4 · Tagging and two complete parse trees</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-r23/q7b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 2: 3 parts, 25 known marks; Unit 3: 2 parts, 15 known marks; Unit 5: 2 parts, 15 known marks; Unit 1, 4: 1 parts, 5 known marks; Unit 2, 5: 1 parts, 10 known marks; Unit 1, 5, 6: 1 parts, 10 known marks; Unit 7: 3 parts, 30 known marks; Unit 6: 1 parts, 10 known marks; Unit 4: 2 parts, 20 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><p><strong>Current-syllabus qualification:</strong> Q1c: historical named-method extension, excluded from current-only priority totals. The original whole-part marks remain visible so the paper is faithfully represented.</p><h3>2022-11-22 · final · F22</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · Need and difficulties of NLP</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q1a\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 1 · Levels of language analysis</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q1b\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 7 · Medical chatbot</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q1c\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 7 · Sentiment with logistic regression</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q1d\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 5 · CBOW and Skip-gram architecture</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q2a\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 3 · Seven regex constructions</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q2b\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2 · Text preprocessing</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q3a\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 4 · Penn Treebank tagging</td><td>case</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q3b\">Read question + answer</a> · Context-sensitive tags and possessive tokenization are explicitly stated; reasonable corpus guidelines can differ on noun adjuncts.</td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 6 · Mention-pair coreference</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q4a\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 7 · Text classification pipeline</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q4b\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 3 · Corpora and structure</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q5a\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 7 · Multinomial Naive Bayes</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q5b\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 5 · GloVe</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q6a\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 2 · BoW and TF–IDF movie corpus</td><td>numerical</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q6b\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 4, 7 · Information extraction, chunking and NER</td><td>theory</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q7a\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 5 · Distributional hypothesis and cosine</td><td>mixed</td><td><a href=\"/nlp/#tee/papers/legacy-f22/q7b\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 2 parts, 10 known marks; Unit 7: 4 parts, 30 known marks; Unit 5: 3 parts, 30 known marks; Unit 3: 2 parts, 20 known marks; Unit 2: 2 parts, 20 known marks; Unit 4: 1 parts, 10 known marks; Unit 6: 1 parts, 10 known marks; Unit 4, 7: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>Priority without skipping the syllabus</h3><p>The latest papers show the form and depth of questions, while the official current syllabus sets the learning scope. Authored drills, explanatory numbers and optional extensions are not counted as past questions. Source assumptions and ambiguous data are stated in their answers.</p>"}]},{"id":"scope","title":"Portion, paper pattern & sources","unit":0,"sections":[{"id":"sources","title":"What this NLP guide covers","html":"<p><strong>M2 portion confirmed by you:</strong> Unit 3 from PDF slide 62 to 160; Unit 4 complete (128 slides); Unit 5 slides 1–57. Slide 62 of Unit 3 starts N-grams. Slide 57 of Unit 5 completes the Naive Bayes WSD example. Vector-space models start on slide 58 and belong to TEE here.</p><p><strong>M2 pattern confirmed by you:</strong> both 2-mark questions compulsory; any two of the three 3-mark questions. Total attempted 10. Course policy gives one hour. Three newly authored, fully solved M2 practice papers use that pattern.</p><p><strong>TEE:</strong> all seven units of the official AY 2026–27 syllabus. The new ZIP supplies faculty slide packs for Units 1–5 plus a regular-expressions handout. Units 6–7 are syllabus-based explanations supplemented with the standard references below; their faculty slide packs were not supplied. The official syllabus includes GloVe and spelling correction, and both are retained even though the policy’s lecture table abbreviates them.</p><p><strong>Previous papers found:</strong> final exam dated 2 December 2025 and re-exam dated 9 February 2026, with answer keys, inside Semester V.zip. Programme copies were deduplicated. Every supplied question subpart is mapped to the current syllabus; no question was excluded as out of syllabus. Only wholly M2-eligible subparts appear in the M2 paper tab; mixed questions remain in the complete TEE papers.</p><p>The current syllabus lists course code 702AI0C037. The supplied policy and old papers use 702AI0C009; the policy also retains an older programme/semester header. Topic coverage follows the current official syllabus and your exact M2 cutoff, rather than treating the old header as a different course.</p><h3>Conventions that must stay visible</h3><p>Course bigram answer keys count both start and end symbols in vocabulary size. Worked PYQs state and follow that convention; other exercises state their own vocabulary explicitly. A start symbol is conditioning context, so alternative textbook conventions may exclude it from prediction vocabulary and produce a different smoothed number. HMM path scores and Naive Bayes class scores are labelled as unnormalised when applicable. Any normalisation, case-folding or lemmatisation assumption is stated before counting.</p><h3>Reading references</h3><ul class=\"source-list\"><li>Your uploaded course policy, official Semester V syllabus, five NLP slide packs and regular-expressions handout.</li><li>Your uploaded final and re-exam questions and answer keys (AY 2025–26).</li><li><a href=\"https://web.stanford.edu/~jurafsky/slp3/\" target=\"_blank\" rel=\"noopener\">Jurafsky & Martin · Speech and Language Processing</a> — terminology and standard methods.</li><li><a href=\"https://www.nltk.org/book/\" target=\"_blank\" rel=\"noopener\">NLTK Book</a> — corpus, tagging, parsing and information-extraction concepts.</li><li><a href=\"https://aclanthology.org/J01-4003.pdf\" target=\"_blank\" rel=\"noopener\">Tetreault · A Corpus-Based Evaluation of Centering and Pronoun Resolution</a> — precise Hobbs traversal.</li></ul><p>Examples are teaching problems unless explicitly identified by their paper and question number. Practice-paper marks indicate intended answer length, not an official forecast. Reading alone cannot guarantee a score; writing the solutions independently is what makes the procedures usable under exam time.</p><h3>TEE depth review · 10 October 2026</h3><p>The core TEE route retains the faculty topics CYK/CKY, grammar conversion, interpolation and Stupid Backoff. Add-k and HMM forward/posterior calculations are available separately under Optional extensions; they are not part of the core reading or formula sequence. The two TEE timed-practice entries reproduce the supplied actual papers and are not additional unseen mock papers.</p><p>Method references: <a href=\"https://web.stanford.edu/~jurafsky/slp3/A.pdf\" target=\"_blank\" rel=\"noopener\">Jurafsky and Martin: Hidden Markov Models</a>; <a href=\"https://web.stanford.edu/~jurafsky/slp3/E.pdf\" target=\"_blank\" rel=\"noopener\">Jurafsky and Martin: Constituency Parsing</a>. New numerical inputs and worked traces are teaching examples.</p>"},{"id":"videos","title":"Video companions in your NotebookLM","html":"<p>Your M2 notebook contains the exact three slide ranges and checked numerical teaching examples. The requested video topics are N-grams and Laplace smoothing, HMM/Viterbi, and Naive Bayes WSD. Use the written solutions here for the complete calculations.</p><p><a href=\"https://notebook.google.com/notebook/a270ef1e-c285-4d31-9db1-302090c5f8b1\" target=\"_blank\" rel=\"noopener\">Open your NLP M2 notebook →</a></p><p>The notebook is in your signed-in Google account. Video generation and availability are shown in its Studio panel. Generated narration is a supplementary explanation; the numerical results in this guide have been independently checked.</p>"}],"scope":"NLP · M2 and TEE · edition 3 October 2026"},{"id":"optional-extensions","title":"Optional extensions — after the TEE questions","unit":"Reference","scope":"Additional explanation; no corresponding question in the two supplied TEE papers. No exam marks are implied.","sections":[{"id":"add-k","title":"Add-k: preserve a normalized vocabulary row","html":"<p class=\"note\"><strong>Optional extension.</strong> Add-k is a supporting generalization of Laplace smoothing. The supplied TEE papers ask add-one bigram sentence probabilities, not an add-k calculation. Complete the actual solved papers first.</p><p><strong>Add-k smoothing generalizes add-one smoothing.</strong> Add the same positive pseudo-count k to each allowed outcome. There are V outcomes, so the total pseudo-count is kV. Setting k=1 recovers Laplace smoothing. A smaller k usually changes the original counts less; it is not automatically the best choice for every dataset.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/c1743621aeed43c4.svg\" alt=\"P_k(w\\mid h)=\\frac{C(h,w)+k}{C(h)+kV},\\qquad k&gt;0.\" style=\"width:35.896ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Use one fixed vocabulary, including an explicit unknown-word policy if needed. Choose k from training/validation evidence, not by fitting the final test results. Unigram smoothing uses N, the total token count, in place of C(h).</p><section class=\"example\"><p class=\"question\"><strong>Question. After history h, counts for the complete next-token vocabulary [a,b,c] are [3,1,0]. Calculate add-k probabilities for k=0.5 and check the row sum. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>C(h)=4; V=3; k=1/2; the zero-count word c is an allowed outcome.</p><h4>To find</h4><p>All three probabilities and their interpretation.</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/75aafa44d0208bdf.svg\" alt=\"P_k(w\\mid h)=\\frac{C(h,w)+k}{C(h)+kV}\" style=\"width:24.409ex;height:5.475ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>Smoothing must adjust the denominator for every pseudo-count added across the row.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Form the new total</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/82f30cc20819ed96.svg\" alt=\"4+(0.5)(3)=5.5.\" style=\"width:17.977ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate a</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/429115b3bdd79ba5.svg\" alt=\"P(a\\mid h)=\\frac{3+0.5}{5.5}=\\frac7{11}\\approx0.636364.\" style=\"width:37.115ex;height:4.661ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate b and c separately</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/4ad9b8ae622d15d2.svg\" alt=\"P(b\\mid h)=\\frac{1+0.5}{5.5}=\\frac3{11}\\approx0.272727.\" style=\"width:36.888ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5a6ab3e28bf5bbad.svg\" alt=\"P(c\\mid h)=\\frac{0+0.5}{5.5}=\\frac1{11}\\approx0.090909.\" style=\"width:36.897ex;height:4.638ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Check normalization</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/ba980a00aba773f0.svg\" alt=\"\\frac7{11}+\\frac3{11}+\\frac1{11}=1.\" style=\"width:20.082ex;height:4.611ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> The row is [7/11,3/11,1/11]. The unseen allowed outcome c receives positive probability, and the row remains a probability distribution.</div></section>"},{"id":"forward-probability","title":"Forward HMM: sum paths and normalize posteriors","html":"<p class=\"note\"><strong>Optional extension.</strong> Forward totals and tag-path posteriors are optional HMM extensions here. Both supplied TEE papers ask emission and transition matrices, then the joint probability of a given tag sequence. Complete the actual solved papers first.</p><p><strong>The forward algorithm finds the total probability of observations when the hidden path is unknown.</strong> Its cell αₜ(j) is the joint probability of the observed prefix o₁…oₜ and ending in hidden state j, summed over every earlier hidden path. It stores two totals per time step in the two-state example; it does not choose one winning predecessor.</p><div class=\"equation\"><div class=\"math-display\"><img src=\"math/69e9cae75f1bf784.svg\" alt=\"\\alpha_1(j)=\\pi_jb_j(o_1)\" style=\"width:15.944ex;height:2.363ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9c7ba7157770eec8.svg\" alt=\"\\alpha_t(j)=b_j(o_t)\\sum_i\\alpha_{t-1}(i)a_{ij}\" style=\"width:26.778ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/237f4e30ab6d371f.svg\" alt=\"P(O)=\\sum_j\\alpha_T(j).\" style=\"width:17.93ex;height:5.155ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>πⱼ is the first-state probability; aᵢⱼ is transition i→j; bⱼ(oₜ) is the probability that state j emits the current observation. Multiply each earlier total by its transition, <strong>add all incoming alternatives</strong>, then multiply by the current emission. With explicit END transitions, terminate using Σⱼ αT(j)aⱼ,END instead. Do not invent END factors in a fixed-length model that has none.</p><div class=\"table-wrap\"><table><thead><tr><th>Question</th><th>Operation</th><th>Output</th></tr></thead><tbody><tr><td>Given one hidden path and the words</td><td>Multiply its start, transitions and emissions</td><td>P(path, observations)</td></tr><tr><td>Find the best hidden path</td><td>Viterbi: maximum, with backpointers</td><td>Best path and its joint score</td></tr><tr><td>Find observation probability</td><td>Forward: sum incoming paths</td><td>P(observations)</td></tr><tr><td>Find a specified path posterior</td><td>Divide its joint score by P(observations)</td><td>P(path | observations)</td></tr></tbody></table></div><section class=\"example\"><p class=\"question\"><strong>Question. Use the HMM tables below to compute P(1,3,1) with the forward algorithm. Compare with the Viterbi path H,H,C whose joint score is 0.00672, then obtain that path’s posterior. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>Use H,C state order and the tables shown. Three observations are 1,3,1. There is no END state. </p><div class=\"table-wrap\"><table><thead><tr><th>Quantity</th><th>H</th><th>C</th></tr></thead><tbody><tr><td>Initial π</td><td>0.8</td><td>0.2</td></tr><tr><td>From H → next state</td><td>0.7</td><td>0.3</td></tr><tr><td>From C → next state</td><td>0.4</td><td>0.6</td></tr></tbody></table></div><div class=\"table-wrap\"><table><thead><tr><th>State</th><th>Emit 1</th><th>Emit 2</th><th>Emit 3</th></tr></thead><tbody><tr><td>H</td><td>0.2</td><td>0.4</td><td>0.4</td></tr><tr><td>C</td><td>0.5</td><td>0.4</td><td>0.1</td></tr></tbody></table></div><h4>To find</h4><p>Every forward cell, total observation probability, and P(H,H,C | 1,3,1).</p></div><h4>Formula and why it applies</h4><div class=\"equation\"><div class=\"math-display\"><img src=\"math/9c7ba7157770eec8.svg\" alt=\"\\alpha_t(j)=b_j(o_t)\\sum_i\\alpha_{t-1}(i)a_{ij}\" style=\"width:26.778ex;height:4.847ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>All hidden paths are mutually exclusive alternatives, so their scores must be added. Viterbi’s maximum answers a different question.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/5624ccfc45b5b3b0.svg\" alt=\"\\alpha_1(H)=0.8(0.2)=0.16,\\qquad\\alpha_1(C)=0.2(0.5)=0.10.\" style=\"width:53.48ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Sum incoming paths to H at observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/88c29e3099046db2.svg\" alt=\"\\alpha_2(H)=[0.16(0.7)+0.10(0.4)](0.4)\" style=\"width:35.246ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/758961ee3abb481e.svg\" alt=\"=[0.112+0.040](0.4)=0.0608.\" style=\"width:31.303ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Sum incoming paths to C at observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/16ff8201d135ae01.svg\" alt=\"\\alpha_2(C)=[0.16(0.3)+0.10(0.6)](0.1)\" style=\"width:34.956ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1f61deb821d3eda8.svg\" alt=\"=[0.048+0.060](0.1)=0.0108.\" style=\"width:31.303ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Calculate final H at observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/b06aab93d1b8d35f.svg\" alt=\"\\alpha_3(H)=[0.0608(0.7)+0.0108(0.4)](0.2)\" style=\"width:39.77ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3146e799c63b1663.svg\" alt=\"=[0.04256+0.00432](0.2)=0.009376.\" style=\"width:38.09ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Calculate final C at observation 1</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/48f64c6c6ce831b9.svg\" alt=\"\\alpha_3(C)=[0.0608(0.3)+0.0108(0.6)](0.5)\" style=\"width:39.481ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/58d25b69e54ff73f.svg\" alt=\"=[0.01824+0.00648](0.5)=0.01236.\" style=\"width:36.959ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 6. Add the final-state alternatives</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/55ab2780a51cb820.svg\" alt=\"P(1,3,1)=0.009376+0.01236=0.021736.\" style=\"width:42.805ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 7. Read the table as a trace</h5><div class=\"table-wrap\"><table><thead><tr><th>State / time</th><th>1: observe 1</th><th>2: observe 3</th><th>3: observe 1</th></tr></thead><tbody><tr><td>H</td><td>0.16</td><td>0.0608</td><td>0.009376</td></tr><tr><td>C</td><td>0.10</td><td>0.0108</td><td>0.01236</td></tr><tr><td>Column total</td><td>0.26</td><td>0.0716</td><td>0.021736</td></tr></tbody></table></div><p>For each new cell, draw arrows from both cells in the previous column. Along each arrow multiply by its transition; add the two contributions and multiply by the destination’s emission.</p></div><div class=\"step\"><h5>Step 8. Normalize the specified best path</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/2fa6cd41aa88e033.svg\" alt=\"P(H,H,C\\mid1,3,1)=\\frac{0.00672}{0.021736}=\\frac{840}{2717}\\approx0.309164.\" style=\"width:51.792ex;height:4.663ex\" loading=\"lazy\" decoding=\"async\"></div></div><p>The best single path has only part of the total mass. The remaining paths account for the rest.</p></div><div class=\"answer\"><strong>Final answer.</strong> P(observations)=0.021736. Viterbi selects H,H,C with joint score 0.00672; its posterior is about 0.309164, not 0.00672.</div></section><section class=\"example\"><p class=\"question\"><strong>Question. With the same explicitly listed HMM, find the probability of observations 3,1 by forward calculation and by enumerating all four hidden paths. [Authored worked example]</strong></p><h3>Answer</h3><div class=\"given\"><h4>Given</h4><p>π=(0.8,0.2); transition rows H=(0.7,0.3), C=(0.4,0.6); emissions H=(0.2,0.4,0.4), C=(0.5,0.4,0.1) for labels 1,2,3; no END factor.</p><h4>To find</h4><p>P(3,1), and an independent path-sum check.</p></div><h4>Formula and why it applies</h4><p>Forward reuses prefix totals. Exhaustive enumeration is practical for this two-position example and must give the same total.</p><h4>Solution</h4><div class=\"step\"><h5>Step 1. Initialize observation 3</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/1058f8c72f5016fb.svg\" alt=\"\\alpha_1(H)=0.8(0.4)=0.32,\\quad\\alpha_1(C)=0.2(0.1)=0.02.\" style=\"width:51.217ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 2. Calculate the second H cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/bb239a1f267ec561.svg\" alt=\"\\alpha_2(H)=[0.32(0.7)+0.02(0.4)](0.2)=0.0464.\" style=\"width:45.177ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 3. Calculate the second C cell</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/3af92aa3b08aa15a.svg\" alt=\"\\alpha_2(C)=[0.32(0.3)+0.02(0.6)](0.5)=0.054.\" style=\"width:43.756ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 4. Sum final cells</h5><div class=\"equation\"><div class=\"math-display\"><img src=\"math/260e76274f7db291.svg\" alt=\"P(3,1)=0.0464+0.054=0.1004.\" style=\"width:33.881ex;height:2.262ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"step\"><h5>Step 5. Enumerate each complete path</h5><div class=\"table-wrap\"><table><thead><tr><th>Path</th><th>Full multiplication</th><th>Joint score</th></tr></thead><tbody><tr><td>HH</td><td>0.8 × 0.4 × 0.7 × 0.2</td><td>0.0448</td></tr><tr><td>HC</td><td>0.8 × 0.4 × 0.3 × 0.5</td><td>0.048</td></tr><tr><td>CH</td><td>0.2 × 0.1 × 0.4 × 0.2</td><td>0.0016</td></tr><tr><td>CC</td><td>0.2 × 0.1 × 0.6 × 0.5</td><td>0.006</td></tr></tbody></table></div><div class=\"equation\"><div class=\"math-display\"><img src=\"math/073c637441080500.svg\" alt=\"0.0448+0.048+0.0016+0.006=0.1004.\" style=\"width:41.106ex;height:1.717ex\" loading=\"lazy\" decoding=\"async\"></div></div></div><div class=\"answer\"><strong>Final answer.</strong> Both methods give 0.1004. The largest single-path score is 0.048, which is smaller than the sum.</div></section><p>For K states and T observations, both dense forward and Viterbi recurrences take O(TK²) work. Forward needs only the preceding column for the probability total. Viterbi also stores backpointers to recover the path. Very long sequences need scaling or log-sum-exp for forward; ordinary logarithms alone do not turn a sum into a maximum.</p><p><strong>Yaad rakho:</strong> Viterbi = best raasta. Forward = saare raaston ka total. This is a supporting HMM extension, not an assertion that a separate forward-algorithm question appeared in the supplied papers.</p>"}]}]}},"routeAliases":{"tee/read/u3-smoothing-extensions/add-k":"tee/about/optional-extensions/add-k","tee/formulas/f-deep-u3-smoothing-extensions/add-k":"tee/about/optional-extensions/add-k","tee/read/u4-forward-cky/forward-probability":"tee/about/optional-extensions/forward-probability","tee/formulas/f-deep-u4-forward-cky/forward-probability":"tee/about/optional-extensions/forward-probability"}}
