Lecture 03 · N-grams

المحاضرة 03 · نماذج N-grams

The Berkeley Restaurant Tables

جداول مطعم بيركلي (Berkeley Restaurant)

Slides 22–27الشرائح 22–27 P1 MUST

Read 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 حقيقي من حوار منطوق، محتواه استفسارات عن المطاعم.

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:

قاعدة واحدة، وهي كل المهارة المطلوبة:

cell(row = w₁, col = w₂) = C(w₁ w₂) row = the word that comes FIRST (the context) column = the word that comes SECOND (the prediction)

تقول الصيغة إن الخلية الواقعة عند row = w₁ وcol = w₂ تساوي C(w₁ w₂)، أي عدّة الـ bigram. الصف هو الكلمة الأولى (السياق)، والعمود هو الكلمة الثانية (المتنبَّأ بها). اقرأ دائماً من الصف إلى العمود بهذا الترتيب.

COLUMN = SECOND WORD ROW = FIRST WORD i want to eat i want to eat 582709 206081 204686 0020 C(want to) = 608   but   C(to want) = 0 the matrix is NOT symmetric
Row picks the context, column picks the next word. Swapping them changes the number.الصف يحدد السياق، والعمود يحدد الكلمة التالية. تبديلهما يغيّر الرقم.

يوضّح الرسم عملية البحث في الشبكة. الشريط الأفقي الملوّن هو الصف 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)iwanttoeatchinesefoodlunchspend
i5827090002
want2060816651
to204686206211
eat0020162420
chinese100008210
food1501501400
lunch20000100
spend10100000

هذا هو جدول عدّات الـ 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الـ BigramCountالعدّWhyالسبب
want to608"I want to eat" is the core query patternعبارة "I want to eat" هي النمط الأساسي للاستعلامات
to want0never said in this corpusلم تُقل قط في هذا الـ corpus
to spend211"how much do I want to spend""how much do I want to spend"
spend to1almost neverتكاد لا تظهر أبداً
food i15sentence boundary inside the corpus: "...food. I..."حدّ جملة داخل الـ corpus: "...food. I..."
i food0not 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المفقود
i84325331690
want629927298
to91124171506
eat62746684
chinese8415874
food3510931058
lunch3341338
spend2278276

يضع الجدول مجموع الخلايا الثماني المطبوعة بجانب العدّة الحقيقية C(word) لكل كلمة صف، والفرق بينهما في العمود الأخير. لاحظ الفجوة الهائلة: lunch مجموع صفه 3 وعدّته الحقيقية 341، وfood مجموعه 35 وعدّته 1093. استخدم دائماً عمود True C(word) كمقام، فهو وحده الصحيح.

Trapفخ

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 مُعطى لك. وإن لم يكن، فأنت بحاجة إلى المصفوفة الكاملة. لا تخترعه أبداً من مقتطف مرئي.

Memory hookخطّاف للذاكرة

"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 لكلمة الصف.

P(w2 | w1) = C(w1 w2)C(w1)

البسط هو عدّة الـ 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) = 827C(i) = 25330.33
P(to | want)C(want to) = 608C(want) = 9270.66
P(eat | to)C(to eat) = 686C(to) = 24170.28
P(food | chinese)C(chinese food) = 82C(chinese) = 1580.52
P(lunch | eat)C(eat lunch) = 42C(eat) = 7460.056
P(spend | to)C(to spend) = 211C(to) = 24170.087
P(chinese | want)C(want chinese) = 6C(want) = 9270.0065
P(i | i)C(i i) = 5C(i) = 25330.002

يفكّك الجدول ثمانية بحوث مباشرة إلى ثلاث خطوات: الاحتمال المطلوب، ثم الخلية (البسط)، ثم المقسوم عليه (المقام). لاحظ أن المقام يتبع دائماً الكلمة المشروط عليها، أي كلمة الصف: P(to | want) = 608 / 927 = 0.66، وP(lunch | eat) = 42 / 746 = 0.056. غطِّ العمود الأخير وحاول إعادة إنتاجه بنفسك.

Workedمثال محلول
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)iwanttoeatchinesefoodlunchspend
i0.0020.3300.00360000.00079
want0.002200.660.00110.00650.00650.00540.0011
to0.0008300.00170.280.0008300.00250.087
eat000.002700.0210.00270.0560
chinese0.006300000.520.00630
food0.01400.01400.000910.003700
lunch0.005900000.002900
spend0.003600.003600000

هذه هي مصفوفة الاحتمالات المطبّعة، وتُقرأ بنفس الاتجاه: الصف هو الكلمة الأولى (الشرط)، والعمود هو الكلمة الثانية، فالخلية هي 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> في النهاية.

P(<s> i want chinese food </s>) = P(i|<s>) · P(want|i) · P(chinese|want) · P(food|chinese) · P(</s>|food)

تتفكك الجملة إلى خمسة عوامل مضروبة. عدد العوامل يساوي عدد الكلمات زائد واحد، لأن إضافة <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>، فلا يمكن البحث عن عاملين من الخمسة. والشرائح تمدّك بهما جاهزين.

FIVE FACTORS, TWO DIFFERENT SOURCES P(i|<s>) 0.25 P(want|i) 827/2533 P(chinese|want) 6/927 P(food|chinese) 82/158 P(</s>|food) 0.68 × × × × read off the 8 × 8 table must be supplied to you
No <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(i|<s>) = 0.25 P(</s>|food) = 0.68 P(english|want) = 0.0011 P(food|english) = 0.5
Workedمثال محلول
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). والحل أن تجمع اللوغاريتمات بدل أن تضرب الاحتمالات.

p1 · p2 · … · pk = exp(log p1 + log p2 + … + log pk)

تقول الصيغة إن حاصل ضرب الاحتمالات يساوي exp لمجموع لوغاريتماتها. الجزء المظلّل هو الجمع، وهو ما تحسبه فعلياً، ثم تُطبّق exp مرة واحدة في النهاية إن احتجت الاحتمال نفسه.

Workedمثال محلول
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 الجملة سلبي دائماً، وكلما اقترب من الصفر كانت الجملة أكثر ترجيحاً.

Memory hookخطّاف للذاكرة

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 cells 9332 queries ≈ a few tens of thousands of bigram tokens → the overwhelming majority of cells are 0

يحسب المقطع حجم المشكلة: 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 بالضبط.

Trapفخ

Zeros and underflow are two different problems with two different fixes.

الأصفار وunderflow مشكلتان مختلفتان لكل منهما حل مختلف.

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

الإجراء كله بالترتيب

  1. 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.

  2. For each factor, find the cell C(w₁ w₂) at row w₁, column w₂.

    لكل عامل، ابحث عن الخلية C(w₁ w₂) عند الصف w₁ والعمود w₂.

  3. Divide by the unigram count C(w₁), taken from the given unigram row, never from a row sum.

    اقسم على عدّة الـ unigram C(w₁)، مأخوذة من صف الـ unigram المُعطى، لا من مجموع صف أبداً.

  4. If a factor involves a word outside the printed excerpt (including the boundary tokens), use the value supplied in the question.

    إن كان العامل يضم كلمة خارج المقتطف المطبوع (ومنها رموز الحدود)، فاستخدم القيمة المعطاة في السؤال.

  5. Multiply the factors, or add their logs and exponentiate at the end.

    اضرب العوامل، أو اجمع لوغاريتماتها ثم طبّق exp في النهاية.

  6. 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 مليون خلية أصفاراً في معظمها، فأنت محتاج إليه دائماً.