Lecture 03 · N-grams
المحاضرة 03 · نماذج N-grams
Maximum Likelihood Estimation
تقدير الاحتمال الأقصى (Maximum Likelihood Estimation)
P1 MUSTWhere the numbers come from: count, divide, and never put the wrong thing on the bottom.
من أين تأتي الأرقام: عُدّ، ثم اقسم، ولا تضع أبداً الشيء الخطأ في المقام.
MLE is two words: count and normalize
الـ MLE كلمتان: عُدّ ثم طبّع
Slide 16 gives the whole method in two bullets: estimate probabilities from relative frequency counts, and normalize so they sum to 1. Then the formula:
تختصر الشريحة 16 الطريقة كلها في نقطتين: قدّر الاحتمالات من relative frequency counts، ثم طبّق normalization حتى يصبح مجموعها 1. وبعدها تأتي الصيغة:
P(wn | wn−1) = C(wn−1, wn)C(wn−1)
In words: how many times did the pair appear, divided by how many times the first word appeared. "Maximum likelihood" sounds like it needs calculus. It does not. For this model the maximum-likelihood estimate is exactly the relative frequency, so the recipe is: count, divide, done.
بالكلمات: كم مرة ظهر الزوج معاً، مقسوماً على كم مرة ظهرت الكلمة الأولى. مصطلح "maximum likelihood" يوحي بأنك تحتاج تفاضلاً وتكاملاً، وهذا غير صحيح هنا. في هذا النموذج تحديداً يكون تقدير maximum likelihood مساوياً تماماً لـ relative frequency، فتصبح الوصفة: عُدّ، اقسم، انتهى.
Why the denominator is C(wn−1)
لماذا المقام هو C(wn−1)
Slide 17 exists only to answer this, because getting the denominator wrong is the most common arithmetic error in the whole lecture. The argument is three lines:
الشريحة 17 موجودة فقط للإجابة على هذا السؤال، لأن الخطأ في المقام هو أشهر خطأ حسابي في المحاضرة كلها. والبرهان ثلاثة أسطر:
- Every time the word wn−1 occurs, something follows it. Some word w comes next, even if that word is </s>.
في كل مرة تظهر الكلمة wn−1 يأتي بعدها شيء ما بالضرورة. هناك كلمة w تتبعها، ولو كانت تلك الكلمة هي </s> نفسها.
- So if you add up the counts of every bigram that starts with wn−1, you get back the number of times wn−1 occurred: Σw C(wn−1, w) = C(wn−1).
إذن لو جمعت counts كل bigram يبدأ بـ wn−1، يرجع لك عدد مرات ظهور wn−1 نفسه: Σw C(wn−1, w) = C(wn−1).
- Therefore dividing every such bigram count by C(wn−1) makes the numbers sum to exactly 1. The conditional distribution is normalized.
وبالتالي فإن قسمة كل bigram count من هذه على C(wn−1) تجعل مجموع الأرقام يساوي 1 بالضبط، أي أن conditional distribution صار موزوناً بشكل صحيح (normalized).
Put differently: C(wn−1) is the row total. Lay the bigram counts out as a matrix with the context word as the row and the next word as the column. Dividing a row by its own total is what turns counts into a probability distribution over the next word.
بصيغة أخرى: C(wn−1) هو مجموع الصف. ارسم bigram counts على شكل مصفوفة، فيها كلمة السياق هي الصف والكلمة التالية هي العمود. قسمة الصف على مجموعه الخاص هي بالضبط ما يحوّل counts إلى probability distribution على الكلمة التالية.
"The word after the bar goes on the bottom."
"الكلمة التي بعد الشرطة الرأسية تنزل إلى المقام."
For P(A | B), the thing after the vertical bar is B, so the denominator is C(B). Read the expression right to left and you have written the fraction.
في P(A | B)، ما يأتي بعد الشرطة الرأسية هو B، فيكون المقام C(B). اقرأ التعبير من اليمين إلى اليسار وستكون قد كتبت الكسر كما هو.
Check it: P(am | I) means am given I. I is after the bar. So the bottom is C(I). The top is the full bigram C(I, am). Never C(am) on the bottom.
تحقّق منها: P(am | I) تعني am بشرط I. وI هي التي بعد الشرطة، فالمقام هو C(I). والبسط هو bigram الكامل C(I, am). ولا تضع C(am) في المقام إطلاقاً.
"Chop the last word off the numerator and you get the denominator."
"اقطع الكلمة الأخيرة من البسط، فينتج لك المقام."
Numerator = the full n-gram, N words. Denominator = the same string with its final word deleted, N - 1 words. That is the entire structure of the general formula and it works for every order:
البسط = n-gram الكامل، أي N كلمة. والمقام = نفس السلسلة بعد حذف كلمتها الأخيرة، أي N - 1 كلمة. هذا هو كل بناء الصيغة العامة، وهو يصلح لأي order:
bigram : C(I am) / C(I) trigram : C(I am Sam) / C(I am) 4-gram : C(do not like green) / C(do not like)
If your numerator and denominator differ by anything other than one word at the right-hand end, you have made a mistake.
إذا اختلف بسطك ومقامك بأي شيء غير كلمة واحدة في الطرف الأيمن من السلسلة، فأنت قد أخطأت.
The toy corpus walkthrough
شرح الـ corpus الصغير خطوة بخطوة
Slide 18 gives a three-sentence corpus with boundary symbols already attached:
تعطي الشريحة 18 corpus من ثلاث جمل، مع رموز الحدود (boundary symbols) مضافة مسبقاً:
<s> I am Sam </s> <s> Sam I am </s> <s> I do not like green eggs and ham </s>
The slide's title renders as "Toy corpus: extitI am Sam". A \textit LaTeX command failed during typesetting, so the command name leaked into the text. It should read "Toy corpus: I am Sam". Harmless, ignore it, do not go looking for a token called extit.
عنوان الشريحة يظهر كـ "Toy corpus: extitI am Sam". السبب أن أمر \textit في LaTeX فشل عند التنسيق، فتسرّب اسم الأمر إلى النص. والصحيح أن تُقرأ "Toy corpus: I am Sam". الأمر غير مؤثر، فتجاهله ولا تبحث عن token اسمه extit.
Step 1: unigram counts
الخطوة 1: عدّات unigram
Count every token, boundary symbols included. Three sentences, so three of each boundary symbol.
عُدّ كل token، بما في ذلك رموز الحدود. ثلاث جمل، إذن ثلاث نسخ من كل رمز حدّ.
| Tokenالـ Token | Countالعدّ | Whereأين |
|---|---|---|
<s> | 3 | one per sentenceواحد لكل جملة |
</s> | 3 | one per sentenceواحد لكل جملة |
I | 3 | sentences 1, 2, 3الجمل 1 و2 و3 |
am | 2 | sentences 1, 2الجملتان 1 و2 |
Sam | 2 | sentences 1, 2الجملتان 1 و2 |
do, not, like, green, eggs, and, ham | 1 | sentence 3 only, each onceالجملة 3 فقط، كل منها مرة واحدة |
يعرض هذا الجدول unigram counts لكل token في corpus الصغير، مع ذكر الجمل التي ظهر فيها. ما يجب أن تلاحظه: رمزا الحدود لهما count يساوي 3 لأن عدد الجمل ثلاث، وI هي الكلمة الوحيدة التي ظهرت في الجمل الثلاث كلها فصار count لها 3، أما am وSam فكل منهما 2 فقط، وكلمات الجملة الثالثة كلها 1. هذه الأرقام هي المقامات التي ستستخدمها لاحقاً، فثبّتها جيداً.
C(Sam) = 2, not 3. Sam appears once in sentence 1 and once in sentence 2, and not at all in sentence 3, which ends with green eggs and ham. People misremember this corpus as having Sam in all three sentences and then get P(I | Sam) = 1/3 instead of the correct 1/2. Recount the actual corpus text, do not recall it.
C(Sam) = 2، وليست 3. كلمة Sam تظهر مرة في الجملة الأولى ومرة في الجملة الثانية، ولا تظهر مطلقاً في الجملة الثالثة التي تنتهي بـ green eggs and ham. كثير من الطلاب يتذكرون هذا corpus خطأً وكأن Sam في الجمل الثلاث، فيحصلون على P(I | Sam) = 1/3 بدلاً من الصحيح 1/2. أعد العدّ من نص corpus أمامك، ولا تعتمد على ذاكرتك.
Compare with C(I) = 3, which genuinely does appear in all three sentences. The two are easy to swap.
قارنها بـ C(I) = 3، فهذه فعلاً تظهر في الجمل الثلاث كلها. الخلط بين الرقمين سهل جداً، فاحفظ: I ثلاثة، Sam اثنان.
Step 2: the bigram count matrix
الخطوة 2: مصفوفة عدّات bigram
Row = context word, column = next word. The cell is the count of the column word following the row word. Notice the row totals.
الصف = كلمة السياق، والعمود = الكلمة التالية. والخلية هي count ظهور كلمة العمود بعد كلمة الصف. انتبه جيداً لمجاميع الصفوف.
| C(row, col) | I | am | Sam | do | </s> | Row total = C(row)مجموع الصف = C(row) |
|---|---|---|---|---|---|---|
<s> | 2 | 0 | 1 | 0 | 0 | 3 |
I | 0 | 2 | 0 | 1 | 0 | 3 |
am | 0 | 0 | 1 | 0 | 1 | 2 |
Sam | 1 | 0 | 0 | 0 | 1 | 2 |
هذه مصفوفة bigram counts لـ corpus الصغير: كل خلية هي عدد مرات ظهور كلمة العمود مباشرة بعد كلمة الصف، والعمود الأخير هو مجموع الصف. أهم ملاحظتان: أولاً، معظم الخلايا أصفار حتى في corpus بثلاث جمل فقط، وهذه بداية مشكلة sparsity. وثانياً، مجموع كل صف يساوي بالضبط unigram count لكلمة ذلك الصف، وهو المقام الذي ستقسم عليه.
The right-hand column is slide 17's claim made concrete: each row sums to the unigram count of the row word. Row <s> sums to 3 = C(<s>). Row am sums to 2 = C(am). That is why the row total is always the correct denominator.
العمود الأيمن هو ما تقوله الشريحة 17 مجسّداً بالأرقام: مجموع كل صف يساوي unigram count لكلمة الصف. صف <s> مجموعه 3 = C(<s>)، وصف am مجموعه 2 = C(am). ولهذا فإن مجموع الصف هو المقام الصحيح دائماً.
Slide 19 lists five probabilities from this corpus. Here is every one of them derived, with the division shown.
تسرد الشريحة 19 خمسة احتمالات من هذا corpus. وهنا اشتقاق كل واحد منها، مع إظهار القسمة خطوة بخطوة.
P(I | <s>) numerator C(<s> I) = 2 sentences 1 and 3 start with I denominator C(<s>) = 3 three sentences = 2 / 3 = 0.667 P(Sam | <s>) numerator C(<s> Sam) = 1 only sentence 2 starts with Sam denominator C(<s>) = 3 = 1 / 3 = 0.333 P(am | I) numerator C(I am) = 2 "I am" in sentence 1, "I am" in sentence 2 denominator C(I) = 3 I occurs three times = 2 / 3 = 0.667 P(do | I) numerator C(I do) = 1 "I do" in sentence 3 denominator C(I) = 3 = 1 / 3 = 0.333 P(</s> | Sam) numerator C(Sam </s>) = 1 sentence 1 ends "am Sam </s>" denominator C(Sam) = 2 Sam occurs twice = 1 / 2 = 0.5
Consistency check on row I: P(am | I) + P(do | I) = 2/3 + 1/3 = 1. The row is a complete distribution, nothing is missing. Do this check whenever you finish a row in an exam, it catches a wrong denominator instantly.
تحقّق من اتساق صف I: P(am | I) + P(do | I) = 2/3 + 1/3 = 1. الصف يمثل distribution كاملاً ولا ينقصه شيء. طبّق هذا الفحص كلما أنهيت صفاً في الامتحان، فهو يكشف المقام الخطأ فوراً.
Two more from the same matrix that the slide does not list but that an exam might ask for: P(Sam | am) = C(am Sam) / C(am) = 1/2 = 0.5, and P(I | Sam) = C(Sam I) / C(Sam) = 1/2 = 0.5.
واحتمالان إضافيان من المصفوفة نفسها لم تذكرهما الشريحة لكن الامتحان قد يطلبهما: P(Sam | am) = C(am Sam) / C(am) = 1/2 = 0.5، وP(I | Sam) = C(Sam I) / C(Sam) = 1/2 = 0.5.
The general n-gram formula, subscripts decoded
صيغة n-gram العامة، مع فك رموز المؤشرات السفلية
Slide 20 generalizes from bigrams to any order:
تعمّم الشريحة 20 الصيغة من bigram إلى أي order:
P(wn | wn−N+1:n−1) = C(wn−N+1:n)C(wn−N+1:n−1)
The slide's own gloss: "prefix in denominator, full n-gram in numerator". The subscripts look worse than they are. There are only two of them and they differ by one character:
وشرح الشريحة نفسه: "prefix in denominator, full n-gram in numerator"، أي prefix في المقام وn-gram الكامل في البسط. الرموز السفلية تبدو أصعب مما هي عليه: هي اثنان فقط، والفرق بينهما حرف واحد.
wn−N+1:n (numerator)(البسط)
Tokens from position n - N + 1 through position n, inclusive.
الـ tokens من الموضع n - N + 1 إلى الموضع n، والطرفان داخلان.
Length = n - (n - N + 1) + 1 = N tokens.
الطول = n - (n - N + 1) + 1 = N من tokens.
This is the full n-gram: the context plus the word being predicted. It ends at n.
هذا هو n-gram الكامل: السياق مضافاً إليه الكلمة المتوقَّعة. وينتهي عند الموضع n.
wn−N+1:n−1 (denominator)(المقام)
Same start, but it stops one position earlier, at n - 1.
نفس نقطة البداية، لكنه يتوقف قبل موضع واحد، أي عند n - 1.
Length = N - 1 tokens.
الطول = N - 1 من tokens.
This is the context or prefix. It is the numerator with the last token chopped off.
هذا هو السياق أو prefix، وهو البسط نفسه بعد قطع token الأخير منه.
So the only difference between top and bottom is the right endpoint: n on top, n - 1 on the bottom. That is the "chop the last word" mnemonic written in index notation.
إذن الفرق الوحيد بين البسط والمقام هو نقطة النهاية اليمنى: n في البسط، وn - 1 في المقام. وهذه هي قاعدة "اقطع الكلمة الأخيرة" نفسها مكتوبة بصيغة الفهارس.
Worked subscript table
جدول محلول للمؤشرات السفلية
Take the sentence I want to eat food and predict the word eat. Index the tokens first, because n is a position, not an order.
خُذ الجملة I want to eat food واطلب توقّع الكلمة eat. رقّم الـ tokens أولاً، لأن n هي موضع في الجملة وليست order النموذج.
I(1) want(2) to(3) eat(4) food(5)
the word being predicted is eat , so n = 4 , w = eat
n
Now vary the order N and read the subscripts off directly.
الآن غيّر order أي N، واقرأ الرموز السفلية مباشرة.
| N | Modelالنموذج | Context indices wn−N+1:n−1مؤشرات السياق wn−N+1:n−1 | Context words (denominator)كلمات السياق (المقام) | Full n-gram indices wn−N+1:nمؤشرات الـ n-gram الكامل wn−N+1:n | Full n-gram (numerator)الـ n-gram الكامل (البسط) | MLE estimateتقدير MLE |
|---|---|---|---|---|---|---|
| 2 | bigram | w3:3 | to |
w3:4 | to eat |
C(to eat) / C(to) |
| 3 | trigram | w2:3 | want to |
w2:4 | want to eat |
C(want to eat) / C(want to) |
| 4 | 4-gram | w1:3 | I want to |
w1:4 | I want to eat |
C(I want to eat) / C(I want to) |
يفكّ هذا الجدول الرموز السفلية لثلاث قيم من N مع تثبيت n = 4 أي الكلمة eat: لكل صف ترى فهارس السياق وكلماته (المقام)، وفهارس n-gram الكامل وكلماته (البسط)، ثم تقدير MLE النهائي. ما يجب أن تلاحظه: البسط ينتهي عند eat في كل صف، والمقام ينتهي عند to في كل صف، والشيء الوحيد المتحرك هو الحد الأيسر للنافذة الذي يرتدّ إلى الخلف كلما زاد N. ولاحظ أيضاً أن طول المقام دائماً N - 1 كلمة، فـ trigram يشترط على كلمتين فقط.
Arithmetic for the start index, since that is the part people fumble. With n = 4: for N = 2 the start is 4 - 2 + 1 = 3, for N = 3 it is 4 - 3 + 1 = 2, for N = 4 it is 4 - 4 + 1 = 1. Bigger order means the window reaches further back, exactly as it should.
حساب فهرس البداية، لأنه الموضع الذي يتعثر فيه الطلاب. عند n = 4: إذا كان N = 2 فالبداية 4 - 2 + 1 = 3، وإذا كان N = 3 فهي 4 - 3 + 1 = 2، وإذا كان N = 4 فهي 4 - 4 + 1 = 1. أي أن order الأكبر يجعل النافذة تمتد إلى الخلف أكثر، وهذا هو المنطقي تماماً.
Note what never changes: the numerator always ends at eat, and the denominator always ends one word earlier at to. Only the left edge of the window moves.
ولاحظ ما لا يتغير أبداً: البسط ينتهي دائماً عند eat، والمقام ينتهي دائماً بكلمة واحدة قبلها عند to. الحد الأيسر للنافذة هو وحده الذي يتحرك.
Three ways to lose marks on this formula, in order of how often they happen:
ثلاث طرق لخسارة الدرجات في هذه الصيغة، مرتبة بحسب تكرار حدوثها:
- Denominator = C(wn) instead of the context count. Writing P(am | I) = C(I am) / C(am). Use "the word after the bar goes on the bottom".
وضع المقام C(wn) بدلاً من count السياق. أي أن تكتب P(am | I) = C(I am) / C(am). استخدم القاعدة: "الكلمة التي بعد الشرطة تنزل إلى المقام".
- Confusing n with N. Lowercase n is the position in the sentence. Uppercase N is the order of the model. They appear in the same subscript and mean different things.
الخلط بين n وN. الحرف الصغير n هو الموضع داخل الجملة، والحرف الكبير N هو order النموذج. الحرفان يظهران في الرمز السفلي نفسه ومعناهما مختلف تماماً.
- Letting the window be N words of context. A trigram conditions on 2 words. Slide 20's denominator wn−N+1:n−1 has length N - 1, and the formula is the authority.
اعتبار نافذة السياق N كلمة. نموذج trigram يشترط على كلمتين فقط. مقام الشريحة 20 وهو wn−N+1:n−1 طوله N - 1، والصيغة هي المرجع عند أي شك.
Scaling up: the Berkeley Restaurant corpus
التوسع: corpus مطعم بيركلي (Berkeley Restaurant)
Slide 21 switches from the toy corpus to real data so that sparsity becomes visible. The three numbers from the slide:
تنتقل الشريحة 21 من corpus الصغير إلى بيانات حقيقية حتى تصبح مشكلة sparsity مرئية. والأرقام الثلاثة من الشريحة:
9332
User queries (sentences) in the corpus. A real dialogue corpus from a restaurant-recommendation system, but still small by modern standards.
عدد استعلامات المستخدمين (الجمل) في corpus. وهو dialogue corpus حقيقي من نظام للتوصية بالمطاعم، لكنه يبقى صغيراً بالمقاييس الحديثة.
V ≈ 1446
Vocabulary size after text normalization (lowercasing, punctuation stripped). Tiny, because the domain is narrow.
حجم vocabulary بعد text normalization (تحويل الحروف إلى صغيرة وإزالة علامات الترقيم). وهو حجم صغير جداً، لأن مجال الحديث ضيق ومحدد.
Mostly zero
أغلبها أصفار
Slide 21's third bullet: the bigram tables are extremely sparse, most entries are zero. This is the motivation for smoothing.
النقطة الثالثة في الشريحة 21: جداول bigram شديدة التفرّق (sparse)، ومعظم خلاياها أصفار. وهذا هو الدافع الأساسي لوجود smoothing.
Why "extremely sparse" is not an exaggeration. With V = 1446 types, the number of distinct bigrams the model has a parameter for is:
لماذا عبارة "شديد التفرّق" ليست مبالغة. عند V = 1446 من types، يكون عدد bigrams المختلفة التي يحتاج النموذج معاملاً لكل واحد منها:
V x V = 1446 x 1446 = 2,090,916 possible bigrams tokens available to fill them: 9332 sentences, roughly a handful of words each, so on the order of 10^5 bigram tokens observed 2,090,916 cells vs ~10^5 observations => the overwhelming majority of cells must be 0
Even if every observed bigram were distinct, you could fill at most a few percent of the matrix. Go up to trigrams and the parameter count becomes 14463 = 3,022,464,936, over three billion cells, from the same few thousand sentences. That is slide 20's closing bullet, "still sparse for large N", quantified.
حتى لو كان كل bigram مرصود مختلفاً عن الآخر، فأقصى ما يمكنك ملؤه هو نسبة ضئيلة من المصفوفة. وإذا صعدت إلى trigram يصبح عدد المعاملات 14463 = 3,022,464,936، أي أكثر من ثلاثة مليارات خلية، ومن نفس الآلاف القليلة من الجمل. هذا هو تجسيد النقطة الختامية في الشريحة 20: "still sparse for large N".
One real division from that corpus
قسمة حقيقية واحدة من ذلك الـ corpus
To see the method on real numbers, here is one bigram from the Berkeley Restaurant counts, using the same two-step recipe. The textbook reports C(to eat) = 686 and C(to) = 2417.
لترى الطريقة على أرقام حقيقية، هذا bigram واحد من counts مجموعة Berkeley Restaurant، بنفس الوصفة ذات الخطوتين. الكتاب يذكر أن C(to eat) = 686 وC(to) = 2417.
P(eat | to) = C(to eat) / C(to) = 686 / 2417 = 0.2838... ~ 0.28
Same formula, same mnemonic. to is after the bar, so C(to) is on the bottom. Chop eat off to eat and you get to. The next page builds the full matrix.
نفس الصيغة ونفس القاعدة. كلمة to هي التي بعد الشرطة، فيكون C(to) في المقام. واقطع eat من to eat فينتج لك to. والصفحة التالية تبني المصفوفة الكاملة.
Check yourself
اختبر نفسك
Using slide 18's toy corpus, what is P(I | Sam)?
باستخدام corpus الصغير في الشريحة 18، ما قيمة P(I | Sam)؟
B. C(Sam I) = 1, from sentence 2 ("<s> Sam I am </s>"), and C(Sam) = 2 because Sam appears in sentences 1 and 2 only. The third sentence ends with green eggs and ham, with no Sam in it. So 1/2. Answer A is what you get if you misremember C(Sam) as 3, which is the count of I, not of Sam. Recount the corpus rather than recalling it.
B. C(Sam I) = 1 من الجملة 2 ("<s> Sam I am </s>")، وC(Sam) = 2 لأن Sam تظهر في الجملتين 1 و2 فقط. الجملة الثالثة تنتهي بـ green eggs and ham ولا يوجد فيها Sam. إذن 1/2. الخيار A هو ما تحصل عليه إذا تذكرت C(Sam) خطأً على أنها 3، وهذا عدّ I وليس عدّ Sam. أعد عدّ الـ corpus بدل أن تعتمد على ذاكرتك.
For a bigram model, what is the denominator of the MLE estimate of P(wn | wn−1)?
في نموذج bigram، ما مقام تقدير MLE لـ P(wn | wn−1)؟
D. The word after the bar goes on the bottom. Slide 17 justifies it: all bigrams beginning with wn−1 sum to C(wn−1), so dividing by it normalizes the distribution over the next word. Answer A is the single most common error on this material. Answer B gives you the joint probability of the bigram, not the conditional.
D. الكلمة التي بعد الخط العمودي تذهب إلى المقام. والشريحة 17 تبرر ذلك: كل الـ bigrams التي تبدأ بـ wn−1 مجموعها C(wn−1)، فالقسمة عليه تطبّع التوزيع على الكلمة التالية. الخيار A هو أكثر خطأ شيوعاً في هذه المادة. والخيار B يعطيك الاحتمال المشترك للـ bigram، لا الاحتمال الشرطي.
In P(wn | wn−N+1:n−1) = C(wn−N+1:n) / C(wn−N+1:n−1), what distinguishes the numerator string from the denominator string?
في P(wn | wn−N+1:n−1) = C(wn−N+1:n) / C(wn−N+1:n−1)، ما الذي يميز سلسلة البسط عن سلسلة المقام؟
C. Both subscripts begin at n - N + 1. Only the right endpoint differs: n on top, n - 1 on the bottom. So the numerator is N words (the full n-gram) and the denominator is N - 1 words (the context). Answer D has it exactly backwards, which is the mistake that produces probabilities greater than 1. Answer A changes the wrong endpoint.
C. كلا المؤشرين السفليين يبدأ عند n - N + 1. الذي يختلف هو الطرف الأيمن فقط: n في البسط وn - 1 في المقام. إذن البسط N كلمة (الـ n-gram الكامل) والمقام N - 1 كلمة (السياق). الخيار D يعكس ذلك تماماً، وهو الخطأ الذي ينتج احتمالات أكبر من 1. والخيار A يغيّر الطرف الخطأ.
You are predicting eat in I want to eat food with a trigram model. What is the MLE estimate?
تتنبأ بالكلمة eat في I want to eat food بنموذج trigram. ما تقدير MLE؟
A. With n = 4 and N = 3, the full n-gram is w2:4 = "want to eat" and the context is w2:3 = "want to". Answer B slides the window one word to the right and predicts food instead of eat. Answer D chops a word off the wrong end of the numerator, keeping the last two words rather than the first two. Answer C predicts to, not eat.
A. مع n = 4 وN = 3، الـ n-gram الكامل هو w2:4 = "want to eat" والسياق هو w2:3 = "want to". الخيار B يزيح النافذة كلمة واحدة إلى اليمين فيتنبأ بـ food بدل eat. والخيار D يقطع كلمة من الطرف الخطأ للبسط، فيحتفظ بآخر كلمتين بدل أول كلمتين. والخيار C يتنبأ بـ to لا بـ eat.
The Berkeley Restaurant corpus has 9332 queries and V ≈ 1446. Why are its bigram tables described as extremely sparse?
في corpus مطعم بيركلي 9332 استعلاماً وV ≈ 1446. لماذا توصف جداول الـ bigram فيه بأنها متناثرة جداً (sparse)؟
B. 1446 × 1446 = 2,090,916 cells, against roughly 105 observed bigram tokens. Even in the best case you fill a tiny fraction, so zeros dominate. Answer C is wrong because unigram counts are the dense, easy part: sparsity bites as soon as you condition on context, and it gets worse with every increase in N. Answer A is wrong because the slide says V ≈ 1446 is the size after normalization.
B. 1446 × 1446 = 2,090,916 خلية، مقابل نحو 105 من الـ bigram tokens المرصودة. حتى في أفضل الأحوال لن تملأ إلا جزءاً ضئيلاً، فتهيمن الأصفار. الخيار C خاطئ لأن عدّات unigram هي الجزء الكثيف والسهل: التناثر يضرب بمجرد أن تشترط على سياق، ويزداد سوءاً مع كل زيادة في N. والخيار A خاطئ لأن الشريحة تقول إن V ≈ 1446 هو الحجم بعد التطبيع.