Lecture 03 · N-grams
المحاضرة 03 · نماذج N-grams
The Berkeley Restaurant Tables
جداول مطعم بيركلي (Berkeley Restaurant)
P1 MUSTRead a bigram count table correctly, turn it into probabilities, and multiply out a full sentence without falling into the two traps that cost marks.
اقرأ جدول عدّات bigram قراءة صحيحة، وحوّله إلى احتمالات، واضرب جملة كاملة دون أن تقع في الفخّين اللذين يُفقدان الدرجات.
The corpus behind the tables
الـ corpus الذي تقوم عليه الجداول
Berkeley Restaurant Project (BERP) is a real spoken-dialog corpus of restaurant queries.
Berkeley Restaurant Project (BERP) هو corpus حقيقي من حوار منطوق، محتواه استفسارات عن المطاعم.
- 9332 user queries.
9332 استفساراً من المستخدمين.
- Vocabulary V ≈ 1446 word types after normalization.
حجم vocabulary: V ≈ 1446 من الـ word types بعد التطبيع.
- The bigram table is therefore 1446 × 1446. Almost every cell is zero.
إذن جدول الـ bigram حجمه 1446 × 1446، وتكاد كل خلية فيه تكون صفراً.
The slides print an 8 × 8 excerpt for the words i, want, to, eat, chinese, food, lunch, spend. Everything on this page is that excerpt, so stay aware of what it leaves out.
تطبع الشرائح مقتطفاً بحجم 8 × 8 للكلمات i، want، to، eat، chinese، food، lunch، spend. كل ما في هذه الصفحة هو ذلك المقتطف، فابقَ واعياً لما لا يظهر فيه.
How to read the bigram counts matrix
كيف تقرأ مصفوفة عدّات bigram
One rule, and it is the whole skill:
قاعدة واحدة، وهي كل المهارة المطلوبة:
تقول الصيغة إن الخلية الواقعة عند row = w₁ وcol = w₂ تساوي C(w₁ w₂)، أي عدّة الـ bigram. الصف هو الكلمة الأولى (السياق)، والعمود هو الكلمة الثانية (المتنبَّأ بها). اقرأ دائماً من الصف إلى العمود بهذا الترتيب.
يوضّح الرسم عملية البحث في الشبكة. الشريط الأفقي الملوّن هو الصف want، أي الكلمة الأولى، والشريط العمودي هو العمود to، أي الكلمة الثانية، وتقاطعهما هو الخلية 608. وفي الأسفل: C(want to) = 608 لكن C(to want) = 0. إذن المصفوفة ليست متناظرة، فتبديل الصف بالعمود يغيّر الرقم.
The excerpt, in full
المقتطف كاملاً
Rows are the first word. Columns are the second word. Zeros are in red.
الصفوف هي الكلمة الأولى، والأعمدة هي الكلمة الثانية، والأصفار بالأحمر.
| C(row, col) | i | want | to | eat | chinese | food | lunch | spend |
|---|---|---|---|---|---|---|---|---|
| i | 5 | 827 | 0 | 9 | 0 | 0 | 0 | 2 |
| want | 2 | 0 | 608 | 1 | 6 | 6 | 5 | 1 |
| to | 2 | 0 | 4 | 686 | 2 | 0 | 6 | 211 |
| eat | 0 | 0 | 2 | 0 | 16 | 2 | 42 | 0 |
| chinese | 1 | 0 | 0 | 0 | 0 | 82 | 1 | 0 |
| food | 15 | 0 | 15 | 0 | 1 | 4 | 0 | 0 |
| lunch | 2 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| spend | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
هذا هو جدول عدّات الـ bigram كاملاً. طريقة قراءته: الصف هو الكلمة الأولى في الـ bigram، والعمود هو الكلمة الثانية، والخلية عند تقاطعهما هي C(w₁ w₂). فمثلاً الصف want مع العمود to يعطي 608، أما الصف to مع العمود want فيعطي 0. وعند التطبيع إلى احتمال، المقام هو عدّة الـ unigram لكلمة الصف، أي C(w₁)، وليس مجموع الصف ولا أي شيء من العمود. هذه النقطة هي أكثر ما يُفقد الطلاب الدرجة في هذا السؤال.
32 of these 64 cells are already zero, and this is the densest corner of the matrix because these are the 8 most common words in the corpus.
32 من هذه الـ 64 خلية أصفار بالفعل، وهذه هي أكثف زاوية في المصفوفة كلها، لأن هذه الكلمات الثماني هي الأشيع في الـ corpus.
Comparison: the same two words, both orders
مقارنة: الكلمتان نفسهما، بالترتيبين
| Bigramالـ Bigram | Countالعدّ | Whyالسبب |
|---|---|---|
want to | 608 | "I want to eat" is the core query patternعبارة "I want to eat" هي النمط الأساسي للاستعلامات |
to want | 0 | never said in this corpusلم تُقل قط في هذا الـ corpus |
to spend | 211 | "how much do I want to spend""how much do I want to spend" |
spend to | 1 | almost neverتكاد لا تظهر أبداً |
food i | 15 | sentence boundary inside the corpus: "...food. I..."حدّ جملة داخل الـ corpus: "...food. I..." |
i food | 0 | not English word orderليس ترتيب كلمات إنجليزياً |
يأخذ الجدول ثلاثة أزواج ويقلب ترتيبها ليبرز عدم التناظر: want to = 608 مقابل to want = 0، وto spend = 211 مقابل spend to = 1، وfood i = 15 مقابل i food = 0. العمود الأخير يفسّر السبب في كل حالة: نمط الاستفسار الشائع، أو حدّ جملة داخل الـ corpus، أو كون الترتيب غير سليم في الإنجليزية.
Trap 1: the unigram counts are not the row sums
الفخ 1: عدّات unigram ليست مجاميع الصفوف
To normalize a row you divide by C(w₁), the unigram count of the row word. People reach for the row sum of the printed table. That is wrong.
لتطبيع صف تقسم على C(w₁)، أي عدّة الـ unigram لكلمة الصف. كثيرون يمدّون أيديهم إلى مجموع الصف المطبوع، وهذا خطأ.
| Row wordكلمة الصف | Sum of the 8 printed cellsمجموع الخلايا الـ 8 المطبوعة | True C(word)C(word) الحقيقي | Missingالمفقود |
|---|---|---|---|
i | 843 | 2533 | 1690 |
want | 629 | 927 | 298 |
to | 911 | 2417 | 1506 |
eat | 62 | 746 | 684 |
chinese | 84 | 158 | 74 |
food | 35 | 1093 | 1058 |
lunch | 3 | 341 | 338 |
spend | 2 | 278 | 276 |
يضع الجدول مجموع الخلايا الثماني المطبوعة بجانب العدّة الحقيقية C(word) لكل كلمة صف، والفرق بينهما في العمود الأخير. لاحظ الفجوة الهائلة: lunch مجموع صفه 3 وعدّته الحقيقية 341، وfood مجموعه 35 وعدّته 1093. استخدم دائماً عمود True C(word) كمقام، فهو وحده الصحيح.
The lunch row sums to 3, but C(lunch) = 341. The printed table shows 8 of 1446 columns, so 338 occurrences of lunch are followed by a word that is not in the excerpt. Divide by 3 and P(food|lunch) comes out as 0.33 instead of the correct 1/341 = 0.0029, off by a factor of 114.
مجموع صف lunch هو 3، لكن C(lunch) = 341. الجدول المطبوع يعرض 8 أعمدة من 1446، فـ 338 ظهوراً لكلمة lunch يتبعها كلمة ليست في المقتطف. لو قسمت على 3 لخرجت P(food|lunch) بقيمة 0.33 بدل الصحيح 1/341 = 0.0029، أي بخطأ قدره 114 ضعفاً.
In an exam, the unigram counts row must be given to you. If it is not, you need the complete matrix. Never invent it from a visible excerpt.
في الامتحان يجب أن يكون صف عدّات الـ unigram مُعطى لك. وإن لم يكن، فأنت بحاجة إلى المصفوفة الكاملة. لا تخترعه أبداً من مقتطف مرئي.
"Row sums lie, unigrams don't." The denominator always comes from the unigram row, never from adding up the cells you can see. A row sum only equals C(w₁) when the table shows every column in the vocabulary.
"Row sums lie, unigrams don't." أي مجاميع الصفوف تكذب والـ unigrams لا تكذب. المقام يأتي دائماً من صف الـ unigram، لا من جمع الخلايا التي تراها. ومجموع الصف لا يساوي C(w₁) إلا إذا كان الجدول يعرض كل أعمدة الـ vocabulary.
From counts to probabilities
من العدّات إلى الاحتمالات
Maximum likelihood estimate for a bigram. Divide the cell by the unigram count of the row word.
تقدير maximum likelihood لـ bigram: اقسم الخلية على عدّة الـ unigram لكلمة الصف.
البسط هو عدّة الـ bigram C(w₁ w₂) كما هي في الخلية، والمقام المظلّل هو C(w₁) فقط، أي عدّة كلمة الصف وحدها. انتبه أن w₂ لا تظهر في المقام إطلاقاً.
Each row of the counts table gets divided by one number, so each row of the probability table sums to 1 over the full 1446 columns (not over the 8 printed ones).
كل صف في جدول العدّات يُقسم على رقم واحد، فيكون مجموع كل صف في جدول الاحتمالات 1 على الأعمدة الـ 1446 كاملة، لا على الأعمدة الثماني المطبوعة.
Worked examples straight off the table
أمثلة محلولة مباشرة من الجدول
| Lookupالمطلوب | Cellالخلية | Divide byاقسم على | Probabilityالاحتمال |
|---|---|---|---|
| P(want | i) | C(i want) = 827 | C(i) = 2533 | 0.33 |
| P(to | want) | C(want to) = 608 | C(want) = 927 | 0.66 |
| P(eat | to) | C(to eat) = 686 | C(to) = 2417 | 0.28 |
| P(food | chinese) | C(chinese food) = 82 | C(chinese) = 158 | 0.52 |
| P(lunch | eat) | C(eat lunch) = 42 | C(eat) = 746 | 0.056 |
| P(spend | to) | C(to spend) = 211 | C(to) = 2417 | 0.087 |
| P(chinese | want) | C(want chinese) = 6 | C(want) = 927 | 0.0065 |
| P(i | i) | C(i i) = 5 | C(i) = 2533 | 0.002 |
يفكّك الجدول ثمانية بحوث مباشرة إلى ثلاث خطوات: الاحتمال المطلوب، ثم الخلية (البسط)، ثم المقسوم عليه (المقام). لاحظ أن المقام يتبع دائماً الكلمة المشروط عليها، أي كلمة الصف: P(to | want) = 608 / 927 = 0.66، وP(lunch | eat) = 42 / 746 = 0.056. غطِّ العمود الأخير وحاول إعادة إنتاجه بنفسك.
P(to | want) = C(want to) / C(want) = 608 / 927 = 0.6559... = 0.66 P(spend | to) = C(to spend) / C(to) = 211 / 2417 = 0.08729... = 0.087 P(chinese | want) = C(want chinese) / C(want) = 6 / 927 = 0.006472... = 0.0065
يعرض المقطع ثلاث عمليات قسمة بالتفصيل: P(to | want) = 608 / 927 = 0.6559 فتُقرَّب إلى 0.66، وP(spend | to) = 211 / 2417 = 0.08729 فتُقرَّب إلى 0.087، وP(chinese | want) = 6 / 927 = 0.006472 فتُقرَّب إلى 0.0065. اكتب خطواتك بهذا الشكل بالضبط في ورقة الامتحان.
Same numerator source every time (the cell), same denominator source every time (the unigram count of the row word).
مصدر البسط واحد في كل مرة (الخلية)، ومصدر المقام واحد في كل مرة (عدّة الـ unigram لكلمة الصف).
The full normalized bigram matrix
مصفوفة bigram المطبَّعة كاملة
Every cell above divided by its row's unigram count.
كل خلية في الجدول السابق مقسومة على عدّة الـ unigram الخاصة بصفها.
| P(col | row) | i | want | to | eat | chinese | food | lunch | spend |
|---|---|---|---|---|---|---|---|---|
| i | 0.002 | 0.33 | 0 | 0.0036 | 0 | 0 | 0 | 0.00079 |
| want | 0.0022 | 0 | 0.66 | 0.0011 | 0.0065 | 0.0065 | 0.0054 | 0.0011 |
| to | 0.00083 | 0 | 0.0017 | 0.28 | 0.00083 | 0 | 0.0025 | 0.087 |
| eat | 0 | 0 | 0.0027 | 0 | 0.021 | 0.0027 | 0.056 | 0 |
| chinese | 0.0063 | 0 | 0 | 0 | 0 | 0.52 | 0.0063 | 0 |
| food | 0.014 | 0 | 0.014 | 0 | 0.00091 | 0.0037 | 0 | 0 |
| lunch | 0.0059 | 0 | 0 | 0 | 0 | 0.0029 | 0 | 0 |
| spend | 0.0036 | 0 | 0.0036 | 0 | 0 | 0 | 0 | 0 |
هذه هي مصفوفة الاحتمالات المطبّعة، وتُقرأ بنفس الاتجاه: الصف هو الكلمة الأولى (الشرط)، والعمود هو الكلمة الثانية، فالخلية هي P(col | row). كل صف قُسِم على عدّة الـ unigram لكلمته هو. القيم الكبيرة هي الأنماط المتوقعة: P(to | want) = 0.66، وP(want | i) = 0.33، وP(eat | to) = 0.28، وP(food | chinese) = 0.52. والأصفار تبقى أصفاراً، لأن القسمة لا تحوّل صفراً إلى شيء.
Computing a sentence probability
حساب احتمال جملة
Bigram chain rule, with <s> at the front and </s> at the end.
chain rule لنموذج bigram، مع <s> في البداية و</s> في النهاية.
تتفكك الجملة إلى خمسة عوامل مضروبة. عدد العوامل يساوي عدد الكلمات زائد واحد، لأن إضافة <s> و</s> تخلق bigram إضافياً عند كل طرف. العاملان المظلّلان هما عاملا الحدود، وهما الوحيدان اللذان لا يمكن استخراجهما من الجدول.
Trap 2: not every factor comes from the table
الفخ 2: ليس كل عامل يأتي من الجدول
The 8 × 8 excerpt has no <s> row and no </s> column, so two of the five factors cannot be looked up. The slides supply them.
المقتطف بحجم 8 × 8 ليس فيه صف لـ <s> ولا عمود لـ </s>، فلا يمكن البحث عن عاملين من الخمسة. والشرائح تمدّك بهما جاهزين.
<s> row and no </s> column exist in the excerpt, so those two factors are given, not derived.لا يوجد صف <s> ولا عمود </s> في المقتطف، لذلك هذان العاملان معطيان وليسا مشتقين.يصطفّ في الرسم خمسة صناديق مضروبة في بعضها. الثلاثة الوسطى بلون واحد وتحتها لافتة read off the 8 × 8 table: P(want|i) = 827/2533، وP(chinese|want) = 6/927، وP(food|chinese) = 82/158. والصندوقان في الطرفين بلون آخر وتحتهما لافتة must be supplied to you: P(i|<s>) = 0.25 وP(</s>|food) = 0.68. إذن خمسة عوامل ومصدران مختلفان.
Values supplied by the slides for the boundary and out-of-excerpt factors:
القيم التي تعطيها الشرائح لعوامل الحدود والعوامل الخارجة عن المقتطف:
P(<s> i want chinese food </s>) = P(i|<s>) x P(want|i) x P(chinese|want) x P(food|chinese) x P(</s>|food) = 0.25 x 0.33 x 0.0065 x 0.52 x 0.68 step 1 0.25 x 0.33 = 0.0825 step 2 0.0825 x 0.0065 = 0.00053625 step 3 0.00053625 x 0.52 = 0.000278850 step 4 0.000278850 x 0.68 = 0.000189618 = 1.9 x 10^-4
يحسب المقطع الجملة كاملة خطوة بخطوة. العوامل الخمسة هي 0.25 و0.33 و0.0065 و0.52 و0.68، وتُضرب تراكمياً: 0.0825، ثم 0.00053625، ثم 0.000278850، ثم 0.000189618، فالناتج 1.9 x 10^-4. اضرب دائماً خطوة واحدة في كل مرة وأظهر الوسائط.
Note which factor does the damage: P(chinese|want) = 0.0065 alone divides the running product by about 154. One rare bigram dominates the whole sentence probability.
انظر أي عامل يُحدث الضرر: P(chinese|want) = 0.0065 وحده يقسم الحاصل المتراكم على نحو 154. فـ bigram نادر واحد يسيطر على احتمال الجملة كلها.
Why we use log probabilities
لماذا نستخدم log probabilities
Every factor is at most 1, so the product only ever shrinks. A 30-word sentence multiplies 31 small numbers together and the result underflows to 0 in floating point. The fix is to add logs instead of multiplying probabilities.
كل عامل أصغر من 1 أو يساويه، فحاصل الضرب لا يفعل شيئاً إلا أن يصغر. وجملة من 30 كلمة تضرب 31 رقماً صغيراً، فينزلق الناتج إلى 0 في حساب الفاصلة العائمة (underflow). والحل أن تجمع اللوغاريتمات بدل أن تضرب الاحتمالات.
تقول الصيغة إن حاصل ضرب الاحتمالات يساوي exp لمجموع لوغاريتماتها. الجزء المظلّل هو الجمع، وهو ما تحسبه فعلياً، ثم تُطبّق exp مرة واحدة في النهاية إن احتجت الاحتمال نفسه.
same sentence, in log space (natural log) ln 0.25 = -1.386 ln 0.33 = -1.109 ln 0.0065 = -5.036 ln 0.52 = -0.654 ln 0.68 = -0.386 ------------------ sum = -8.571 exp(-8.571) = 1.90 x 10^-4 matches the direct product
يأخذ المقطع الجملة نفسها في فضاء اللوغاريتم الطبيعي: ln 0.25 = -1.386، وln 0.33 = -1.109، وln 0.0065 = -5.036، وln 0.52 = -0.654، وln 0.68 = -0.386، فيكون المجموع -8.571، وexp(-8.571) = 1.90 x 10^-4، وهو مطابق لحاصل الضرب المباشر. لاحظ أن أكبر قيمة سلبية هي -5.036، وهي العامل النادر نفسه.
Add, do not multiply. The log-prob of a sentence is always negative, and a log-prob closer to zero means a more probable sentence.
اجمع ولا تضرب. وlog-prob الجملة سلبي دائماً، وكلما اقترب من الصفر كانت الجملة أكثر ترجيحاً.
Logs turn × into +. Adding 31 numbers near -5 is harmless. Multiplying 31 numbers near 0.006 is not. Logs are about underflow, nothing else. They do not rescue a zero: log 0 = −∞ and the sum stays −∞.
اللوغاريتمات تحوّل الضرب إلى جمع. جمع 31 رقماً قريباً من -5 لا ضرر فيه، أما ضرب 31 رقماً قريباً من 0.006 ففيه ضرر. اللوغاريتمات تخص underflow فقط ولا شيء غيره، وهي لا تنجّي من الصفر: log 0 = −∞ والمجموع يبقى سالب ما لا نهاية.
What bigrams actually capture
ما الذي تلتقطه الـ bigrams فعلاً
Local syntax
النحو المحلي
After to the likely next word is a verb: C(to eat) = 686, C(to spend) = 211.
بعد to تكون الكلمة التالية المرجّحة فعلاً: C(to eat) = 686، وC(to spend) = 211.
After eat the likely next word is a noun: C(eat lunch) = 42, C(eat chinese) = 16.
وبعد eat تكون الكلمة التالية المرجّحة اسماً: C(eat lunch) = 42، وC(eat chinese) = 16.
Task and domain
المهمة والمجال
P(want|i) = 0.33 is enormous. One in three times someone says i in this corpus, the next word is want. That is the shape of a restaurant assistant query, not of English in general.
قيمة P(want|i) = 0.33 ضخمة جداً. فمرة من كل ثلاث مرات يقول فيها أحدهم i في هذا الـ corpus، تكون الكلمة التالية want. هذه هيئة استفسار موجّه إلى مساعد مطاعم، وليست هيئة الإنجليزية عموماً.
World knowledge
المعرفة بالعالم
P(food|chinese) = 0.52 versus P(food|english) = 0.5 with P(english|want) = 0.0011 versus P(chinese|want) = 0.0065. The data says Berkeley diners ask about Chinese food about six times more often than English food.
قارن P(food|chinese) = 0.52 بـ P(food|english) = 0.5، وهما متقاربان، ثم قارن P(english|want) = 0.0011 بـ P(chinese|want) = 0.0065. تقول البيانات إن زوّار مطاعم Berkeley يسألون عن الطعام الصيني نحو ست مرات أكثر من سؤالهم عن الطعام الإنجليزي.
None of this is engineered. It falls out of counting, which is why counting works so well and also why the model inherits every bias in the corpus.
لا شيء من هذا مصنوع يدوياً، بل يسقط من العدّ وحده. ولهذا يعمل العدّ بهذه الجودة، ولهذا أيضاً يرث النموذج كل تحيّز موجود في الـ corpus.
Sparsity, and why smoothing exists
التناثر (Sparsity)، ولماذا يوجد smoothing
يحسب المقطع حجم المشكلة: 1446 × 1446 = 2,090,916 خلية، مقابل 9332 استفساراً تعطي بضعة عشرات من آلاف الـ bigram tokens فقط. النتيجة أن الغالبية الطاغية من الخلايا 0.
A zero cell means the MLE says "this word pair is impossible". Multiply one impossible factor into a sentence and the whole sentence probability becomes exactly 0.
الخلية الصفرية تعني أن MLE يقول إن هذا الزوج من الكلمات مستحيل. واضرب عاملاً مستحيلاً واحداً في جملة فيصبح احتمال الجملة كلها 0 بالضبط.
Zeros and underflow are two different problems with two different fixes.
الأصفار وunderflow مشكلتان مختلفتان لكل منهما حل مختلف.
- Underflow: the product gets too small for a float. Fix with log space.
Underflow: حاصل الضرب يصغر أكثر مما يحتمله الـ float. والحل log space.
- Zeros: an unseen bigram kills the product entirely. Fix with smoothing.
الأصفار: bigram لم يُرَ من قبل يقتل حاصل الضرب تماماً. والحل smoothing.
Log space does not fix zeros. Switching to logs turns a zero into negative infinity, which is just as fatal.
log space لا يحل مشكلة الأصفار. فالانتقال إلى اللوغاريتمات يحوّل الصفر إلى سالب ما لا نهاية، وهو قاتل بالقدر نفسه.
The whole procedure in order
الإجراء كله بالترتيب
- Add
<s>and</s>to the sentence. Count the factors: a sentence of n words gives n+1 bigram factors.أضف
<s>و</s>إلى الجملة، ثم عُدّ العوامل: جملة من n كلمة تعطي n+1 من عوامل الـ bigram. - For each factor, find the cell C(w₁ w₂) at row w₁, column w₂.
لكل عامل، ابحث عن الخلية C(w₁ w₂) عند الصف w₁ والعمود w₂.
- Divide by the unigram count C(w₁), taken from the given unigram row, never from a row sum.
اقسم على عدّة الـ unigram C(w₁)، مأخوذة من صف الـ unigram المُعطى، لا من مجموع صف أبداً.
- If a factor involves a word outside the printed excerpt (including the boundary tokens), use the value supplied in the question.
إن كان العامل يضم كلمة خارج المقتطف المطبوع (ومنها رموز الحدود)، فاستخدم القيمة المعطاة في السؤال.
- Multiply the factors, or add their logs and exponentiate at the end.
اضرب العوامل، أو اجمع لوغاريتماتها ثم طبّق exp في النهاية.
- Check for any zero factor. One zero means the answer is 0, and the real fix is smoothing.
تحقّق من وجود أي عامل صفري. فصفر واحد يعني أن الجواب 0، والحل الحقيقي هو smoothing.
Check yourself
اختبر نفسك
From the table, what is C(to spend) and what is C(spend to)?
من الجدول، ما قيمة C(to spend) وما قيمة C(spend to)؟
Row = first word. Row to, column spend gives 211. Row spend, column to gives 1. A bigram count matrix is never symmetric, since word order is the entire point. Option A is the standard mistake of treating the table like a co-occurrence matrix.
الجواب C. الصف هو الكلمة الأولى: الصف to مع العمود spend يعطي 211، والصف spend مع العمود to يعطي 1. ومصفوفة عدّات الـ bigram ليست متناظرة أبداً، لأن ترتيب الكلمات هو جوهر الموضوع. والخيار A هو الخطأ المعتاد في التعامل مع الجدول كأنه co-occurrence matrix.
You need P(food | lunch). The lunch row of the 8 × 8 excerpt sums to 3 and the cell for food is 1. C(lunch) = 341. What is the correct answer?
تحتاج P(food | lunch). مجموع صف lunch في المقتطف 8 × 8 هو 3، وخلية food فيه هي 1، وC(lunch) = 341. ما الجواب الصحيح؟
The denominator is always the unigram count of the row word, so 1/341 = 0.0029. Option A is the row-sum trap: the excerpt shows 8 of 1446 columns, so the row sum of 3 is nowhere near C(lunch) = 341. Option D divides by the column word's count, which is the wrong conditional entirely.
الجواب B. المقام دائماً هو عدّة الـ unigram لكلمة الصف، فيكون 1/341 = 0.0029. والخيار A هو فخّ مجموع الصف: المقتطف يعرض 8 أعمدة من 1446، فمجموع الصف 3 بعيد جداً عن C(lunch) = 341. والخيار D يقسم على عدّة كلمة العمود، وهذا احتمال شرطي مختلف تماماً.
Why must P(i | <s>) = 0.25 and P(</s> | food) = 0.68 be given to you rather than computed from the printed matrix?
لماذا يجب أن تُعطى لك P(i | <s>) = 0.25 وP(</s> | food) = 0.68 بدل أن تُحسب من المصفوفة المطبوعة؟
They are ordinary bigram probabilities over the full vocabulary, which includes the boundary tokens. The excerpt simply does not print the <s> row or the </s> column, so there is no cell to look up. Same reason english values are supplied: no english column is printed.
الجواب D. هما احتمالا bigram عاديان على الـ vocabulary الكامل الذي يضم رموز الحدود. المقتطف فقط لا يطبع صف <s> ولا عمود </s>، فلا توجد خلية للبحث فيها. وللسبب نفسه تُعطى قيم english: لا يوجد عمود مطبوع لها.
Computing P(<s> i want chinese food </s>) = 0.25 × 0.33 × 0.0065 × 0.52 × 0.68, which single factor is most responsible for the tiny final value of 1.9 × 10⁻⁴?
عند حساب P(<s> i want chinese food </s>) = 0.25 × 0.33 × 0.0065 × 0.52 × 0.68، أي عامل واحد هو المسؤول الأكبر عن صِغر الناتج النهائي 1.9 × 10⁻⁴؟
0.0065 divides the product by about 154 on its own, while the other four factors are all between 0.25 and 0.68. This is exactly the slide's point: a single rare bigram can drive the whole sentence probability down. Note that chinese being a plausible word after want does not save it, because want is followed by to two thirds of the time.
الجواب A. قيمة 0.0065 وحدها تقسم الحاصل على نحو 154، بينما العوامل الأربعة الأخرى كلها بين 0.25 و0.68. وهذا هو مقصد الشريحة بالضبط: bigram نادر واحد يكفي لجرّ احتمال الجملة كلها إلى الأسفل. ولاحظ أن كون chinese كلمة معقولة بعد want لا ينجّيها، لأن want يتبعها to في ثلثي الحالات.
A sentence contains one bigram whose count in the training data is 0. You switch the whole computation into log space. What happens?
جملة تحتوي على bigram واحد عدّته في بيانات التدريب 0، ثم نقلت الحساب كله إلى log space. ماذا يحدث؟
log 0 = -∞, and adding -∞ to anything stays -∞, so exp of the sum is still exactly 0. Log space solves underflow on long products of small numbers. It does nothing about zeros. The fix for zeros is smoothing, and with V = 1446 the 2.1 million cell matrix is mostly zeros, so you always need it.
الجواب C. log 0 = -∞، وجمع سالب ما لا نهاية مع أي شيء يبقى سالب ما لا نهاية، فـ exp المجموع يبقى 0 بالضبط. log space يحل underflow في حواصل الضرب الطويلة للأرقام الصغيرة، ولا يفعل شيئاً تجاه الأصفار. وحل الأصفار هو smoothing، ومع V = 1446 تكون المصفوفة ذات 2.1 مليون خلية أصفاراً في معظمها، فأنت محتاج إليه دائماً.