Lecture 04 · Word Embeddings
المحاضرة 04 · تضمينات الكلمات (Word Embeddings)
PMI and PPMI
PMI وPPMI
P1 MUSTThe weighting used on word-word matrices: how much more often do two words co-occur than chance would predict, and why we throw away every negative answer.
الوزن المستخدم مع مصفوفات كلمة مقابل كلمة: كم مرة يظهر زوج من الكلمات معاً أكثر مما تتوقعه المصادفة، ولماذا نتخلص من كل نتيجة سالبة.
You will be given a small joint-count matrix and asked for one PPMI cell. The whole task is bookkeeping: one joint probability, two marginals, one ratio, one log base 2, one max with 0. Do them in that order and nothing can go wrong.
سيُعطى لك جدول أعداد صغير ويُطلب منك خلية PPMI واحدة. المهمة كلها ترتيب خطوات: joint probability واحد، وmarginal اثنان، ونسبة واحدة، وlog بالأساس 2، ثم max مع 0. التزم بهذا الترتيب ولن يحدث خطأ.
What PMI asks
ما الذي يسأله PMI
tf-idf was for term-document matrices. PMI is for the term-context matrix, where both the rows and the columns are words.
tf-idf كان لمصفوفة term-document، أما PMI فهو لمصفوفة term-context، حيث الصفوف كلمات والأعمدة كلمات أيضاً.
Slide 53 states the question: do events x and y co-occur more than if they were independent?
تطرح الشريحة 53 السؤال: هل يظهر الحدثان x وy معاً أكثر مما لو كانا مستقلين؟
في الأعلى joint probability أي P(x, y)، وفي الأسفل حاصل ضرب الـ marginals أي P(x) P(y)، والـ log بالأساس 2. الـ marginals تأتي من مجموع الصف ومجموع العمود، كل منهما مقسوم على المجموع الكلي للمصفوفة. وفي PPMI تُحوَّل أي نتيجة سالبة إلى صفر.
For two words:
وللكلمتين:
الصيغة نفسها بأسماء الكلمات: في الأعلى احتمال ظهور word1 وword2 معاً، وفي الأسفل حاصل ضرب الـ marginal لكل منهما، والـ log بالأساس 2. وPPMI يقصّ السالب إلى صفر.
Read the fraction, not the log. The denominator P(x)P(y) is what the joint probability would be if the two words were statistically independent. That is the chance baseline. The numerator is what you actually observed.
اقرأ الكسر، لا الـ log. المقام P(x)P(y) هو ما كان سيكون عليه الاحتمال المشترك لو كانت الكلمتان مستقلتين إحصائياً، أي خط أساس المصادفة. والبسط هو ما رصدته فعلاً.
- Ratio > 1: they co-occur more than chance. PMI is positive.
النسبة > 1: تظهران معاً أكثر من المصادفة، فـ PMI موجب.
- Ratio = 1: exactly independent. PMI = log2(1) = 0.
النسبة = 1: استقلال تام، فـ PMI = log2(1) = 0.
- Ratio < 1: they co-occur less than chance. PMI is negative.
النسبة < 1: تظهران معاً أقل من المصادفة، فـ PMI سالب.
Credit on the slide goes to Church and Hanks, 1989.
تنسب الشريحة الفكرة إلى Church and Hanks, 1989.
Why PPMI, slide 54
لماذا PPMI، الشريحة 54
PMI ranges from −∞ to +∞. The slide's objection is only about the negative half, and this is the most likely conceptual question on the page.
مدى PMI من −∞ إلى +∞. واعتراض الشريحة على النصف السالب فقط، وهذا أرجح سؤال نظري في الصفحة.
A negative PMI claims two words co-occur less often than chance. To establish that reliably you need an enormous corpus. The slide gives the argument in numbers:
قيمة PMI السالبة تدّعي أن الكلمتين تظهران معاً أقل من المصادفة، وإثبات ذلك بثقة يحتاج corpus ضخماً جداً. والشريحة تعطي البرهان بالأرقام:
suppose P(w1) = 10^-6 and P(w2) = 10^-6 independence would predict P(w1) x P(w2) = 10^-6 x 10^-6 = 10^-12 to show that these words co-occur LESS than chance, you must show that the observed P(w1, w2) is reliably BELOW 10^-12. in a corpus of 10^9 words you expect the pair about 10^-3 times. you will observe it zero times whether or not the words repel each other. the data cannot distinguish the two cases.
يفترض المثال أن P(w1) = 10^-6 وP(w2) = 10^-6، فيتوقع الاستقلال P(w1) x P(w2) = 10^-12. ولإثبات أن الكلمتين تظهران معاً أقل من المصادفة تحتاج أن ترصد قيمة أدنى من 10^-12 بثقة. وفي corpus من 10^9 كلمة يكون التوقع نحو 10^-3 مرة، أي أنك ستشاهد الزوج صفر مرة سواء تنافرت الكلمتان أم لا، فالبيانات لا تفرّق بين الحالتين.
So the negative values are noise, not evidence. The slide adds a second reason: it is not even clear that people have good intuitions about "unrelatedness" in the first place.
فالقيم السالبة ضجيج لا دليل. وتضيف الشريحة سبباً ثانياً: ليس واضحاً أصلاً أن لدى البشر حدساً جيداً عن "unrelatedness" أي عدم الترابط.
The fix is blunt. Replace every negative PMI with 0.
الحل حاسم وبسيط: استبدل كل PMI سالب بصفر.
هذه صيغة PPMI: في الأعلى الاحتمال المشترك P(w1,w2)، وفي الأسفل حاصل ضرب الـ marginals P(w1)P(w2) (مجموع الصف ومجموع العمود، كل منهما على المجموع الكلي)، ثم log بالأساس 2، ثم max مع 0 الذي يقصّ أي سالب إلى صفر.
The slide 55 version writes the same thing as a case split, which is worth recognizing:
تكتب الشريحة 55 الشيء نفسه بصيغة حالتين، ويجدر أن تعرفها:
اقرأها هكذا: ppmiij يساوي pmiij إذا كان pmiij > 0، وإلا فهو 0. وهي نفس معنى max(pmi, 0).
PMI versus PPMI
PMI مقابل PPMI
| PMIPMI | PPMIPPMI | |
|---|---|---|
| Rangeالمدى | −∞ to +∞من −∞ إلى +∞ | 0 to +∞من 0 إلى +∞ |
| Means "unrelated"معنى "غير مرتبطتين" | value near 0قيمة قريبة من 0 | value near 0قيمة قريبة من 0 |
| Means "repels"معنى "تتنافران" | large negative valueقيمة سالبة كبيرة | cannot be expressed, clipped to 0لا يمكن التعبير عنه، يُقص إلى 0 |
| Reliability of negativesموثوقية القيم السالبة | poor without a huge corpusضعيفة بدون مدوّنة ضخمة | not an issue, they are discardedليست مشكلة، فهي تُهمَل |
| Matrix sparsityتناثر المصفوفة | dense, mostly small negativesكثيفة، معظمها قيم سالبة صغيرة | sparse, most cells are 0متناثرة، معظم الخلايا 0 |
| Used for word vectorsمستخدم لمتجهات الكلمات | rarelyنادراً | yes, this is the standardنعم، هذا هو المعيار |
يقارن الجدول PMI وPPMI: المدى (−∞ إلى +∞ مقابل 0 إلى +∞)، ومعنى "غير مترابط" (قيمة قريبة من الصفر في الاثنين)، ومعنى "متنافر" (سالب كبير في PMI، وغير قابل للتعبير عنه في PPMI لأنه يُقصّ إلى صفر)، وموثوقية السوالب، وتبعثر المصفوفة (PPMI متبعثرة ومعظم خلاياها أصفار)، والاستخدام في متجهات الكلمات حيث PPMI هو المعيار.
Note what PPMI costs you: it cannot represent repulsion at all. That is a deliberate trade. We give up an unreliable signal to get a cleaner, sparser matrix.
لاحظ ثمن PPMI: لا يستطيع التعبير عن التنافر إطلاقاً، وهذه مقايضة مقصودة. نتخلى عن إشارة غير موثوقة مقابل مصفوفة أنقى وأكثر تبعثراً.
The notation on slide 55
الرموز في الشريحة 55
Slide 55 moves from probabilities to a recipe for an actual matrix. Matrix F has W rows (words) and C columns (contexts). The cell fij is the number of times word wi occurs in context cj.
تنتقل الشريحة 55 من الاحتمالات إلى وصفة عملية لمصفوفة حقيقية. المصفوفة F فيها W صفاً (كلمات) وC عموداً (contexts). والخلية fij هي عدد مرات ظهور الكلمة wi في السياق cj.
Everything is a count divided by the grand total of all cells.
كل شيء هنا عدد مقسوم على المجموع الكلي لكل الخلايا.
الـ joint probability لخلية واحدة: الخلية fij في الأعلى، ومجموع كل خلايا المصفوفة في الأسفل.
الـ marginal للكلمة i: مجموع الصف كله في الأعلى، والمجموع الكلي (total) في الأسفل.
الـ marginal للسياق j: مجموع العمود كله في الأعلى، والمجموع الكلي نفسه في الأسفل.
التجميع النهائي: في الأعلى الاحتمال المشترك pij، وفي الأسفل حاصل ضرب الـ marginals pi* p*j، أي مجموع الصف ومجموع العمود كل منهما على المجموع الكلي، والـ log بالأساس 2، ثم ppmiij = max(pmiij, 0) يقصّ أي سالب إلى صفر.
The star means "summed over that index". pi* is the row marginal, p*j is the column marginal. The denominator total is the same single number everywhere: the sum of every cell in the matrix.
النجمة تعني "جُمع على هذا الدليل". فـ pi* هو marginal الصف، وp*j هو marginal العمود. والمقام total هو الرقم الواحد نفسه في كل مرة: مجموع كل خلايا المصفوفة.
يرسم المخطط المسار من اليسار إلى اليمين: count matrix أي fij، ثم القسمة على total لتحصل على joint probs أي pij. ومن المصفوفة نفسها يتفرّع صندوقان: row marginal وهو rowsum / total، وcolumn marginal وهو colsum / total. تتجمع الثلاثة في صندوق pmi وهو log2 لـ joint / (p(w) p(c))، ثم max(·,0) يوصلك إلى PPMI الذي لا ينزل تحت الصفر أبداً. والسطر الأخير يؤكد: مجموع كلي واحد يقسم كل شيء، الخلايا ومجاميع الصفوف ومجاميع الأعمدة.
The lecture's count matrix, slide 56
مصفوفة العدّات في المحاضرة، الشريحة 56
Four words as rows, five context words as columns. The last row and last column are the sums the slide prints for you.
أربع كلمات في الصفوف، وخمس كلمات سياق في الأعمدة. والصف الأخير والعمود الأخير هما المجاميع التي تطبعها الشريحة لك.
| fij | computer | data | result | pie | sugar | count(w) = row sumcount(w) = مجموع الصف |
|---|---|---|---|---|---|---|
| cherry | 2 | 8 | 9 | 442 | 25 | 486 |
| strawberry | 0 | 0 | 1 | 60 | 19 | 80 |
| digital | 1670 | 1683 | 85 | 5 | 4 | 3447 |
| information | 3325 | 3982 | 378 | 5 | 13 | 7703 |
| count(context) = col sumcount(context) = مجموع العمود | 4997 | 5673 | 473 | 512 | 61 | 11716 |
يعرض الجدول أعداد fij الخام من الشريحة 56: الصفوف cherry، strawberry، digital، information، والأعمدة computer، data، result، pie، sugar. العمود الأخير count(w) هو مجموع الصف، والصف الأخير count(context) هو مجموع العمود، وزاوية أسفل اليمين 11716 هي المجموع الكلي. اقرأ الخلية التي تحتاجها من تقاطع الصف والعمود، مثل information / data = 3982.
The number in the bottom-right corner, 11716, is the grand total. It is the only denominator you will use. Check it: 486 + 80 + 3447 + 7703 = 11716, and 4997 + 5673 + 473 + 512 + 61 = 11716. The row sums and the column sums must agree.
الرقم في زاوية أسفل اليمين، 11716، هو المجموع الكلي، وهو المقام الوحيد الذي ستستخدمه. تحقّق منه: 486 + 80 + 3447 + 7703 = 11716، و4997 + 5673 + 473 + 512 + 61 = 11716. يجب أن يتطابق مجموع الصفوف مع مجموع الأعمدة.
Divide everything by 11716
اقسم كل شيء على 11716
This is the slide's second table: joint probabilities, with the row marginal p(w) on the right and the column marginal p(context) along the bottom.
هذا جدول الشريحة الثاني: الاحتمالات المشتركة، مع marginal الصف p(w) على اليمين وmarginal العمود p(context) في الأسفل.
| p(w, context) | computer | data | result | pie | sugar | p(w) |
|---|---|---|---|---|---|---|
| cherry | 0.0002 | 0.0007 | 0.0008 | 0.0377 | 0.0021 | 0.0415 |
| strawberry | 0.0000 | 0.0000 | 0.0001 | 0.0051 | 0.0016 | 0.0068 |
| digital | 0.1425 | 0.1436 | 0.0073 | 0.0004 | 0.0003 | 0.2942 |
| information | 0.2838 | 0.3399 | 0.0323 | 0.0004 | 0.0011 | 0.6575 |
| p(context) | 0.4265 | 0.4842 | 0.0404 | 0.0437 | 0.0052 | 1.0000 |
هذا هو الجدول السابق نفسه بعد قسمة كل خلية على 11716. الخلايا الداخلية هي p(w, context)، والعمود الأخير p(w) هو marginal الصف، والصف الأخير p(context) هو marginal العمود، ومجموع الكل في الزاوية 1.0000. فمثلاً الخلية information / data هي 0.3399، وp(information) = 0.6575، وp(data) = 0.4842.
The slide spells out three of these, and they are the ones you want to be able to reproduce:
تفصّل الشريحة ثلاثة منها، وهي التي يجب أن تقدر على إعادة حسابها:
p(w=information, c=data) = 3982 / 11716 = 0.3399 p(w=information) = 7703 / 11716 = 0.6575 p(c=data) = 5673 / 11716 = 0.4842
ثلاث قسمات، والمقام 11716 في الثلاث: البسط 3982 هو خلية واحدة فيعطي الاحتمال المشترك 0.3399، والبسط 7703 هو مجموع صف information فيعطي 0.6575، والبسط 5673 هو مجموع عمود data فيعطي 0.4842.
Notice that the joint cell uses a single cell on top, the row marginal uses the whole row on top, and the column marginal uses the whole column on top. The bottom is 11716 every single time.
لاحظ أن الاحتمال المشترك بسطه خلية واحدة، وmarginal الصف بسطه الصف كله، وmarginal العمود بسطه العمود كله. أما المقام فهو 11716 في كل مرة بلا استثناء.
The slide's own cell: PPMI(information, data). Every intermediate value.
خلية الشريحة نفسها: PPMI(information, data)، بكل القيم الوسيطة.
STEP 0 read the raw count f(information, data) = 3982 STEP 1 grand total total = 486 + 80 + 3447 + 7703 = 11716 STEP 2 joint probability p(information, data) = 3982 / 11716 = 0.33988 -> 0.3399 STEP 3 row marginal (word) row sum for information = 3325 + 3982 + 378 + 5 + 13 = 7703 p(information) = 7703 / 11716 = 0.65748 -> 0.6575 STEP 4 column marginal (context) col sum for data = 8 + 0 + 1683 + 3982 = 5673 p(data) = 5673 / 11716 = 0.48421 -> 0.4842 STEP 5 the chance baseline p(information) x p(data) = 0.6575 x 0.4842 = 0.31836 STEP 6 the ratio 0.3399 / 0.31836 = 1.06765 observed co-occurrence is about 6.8 percent above chance STEP 7 log base 2 pmi = log2(1.06765) = 0.0944 STEP 8 max with 0 ppmi = max(0.0944, 0) = 0.0944 -> 0.09 in the slide's matrix
تسع خطوات بالترتيب: العدد الخام 3982، ثم المجموع الكلي 11716، ثم الاحتمال المشترك 3982 / 11716 = 0.3399، ثم marginal الصف 7703 / 11716 = 0.6575، ثم marginal العمود 5673 / 11716 = 0.4842، ثم خط أساس المصادفة 0.6575 x 0.4842 = 0.31836، ثم النسبة 0.3399 / 0.31836 = 1.06765 أي أعلى من المصادفة بنحو 6.8 بالمئة، ثم pmi = log2(1.06765) = 0.0944، وأخيراً ppmi = max(0.0944, 0) = 0.0944 وتُكتب 0.09 في مصفوفة الشريحة.
The slide prints exactly this: pmi(information, data) = log2(.3399 / (.6575 × .4842)) = .0944.
تطبع الشريحة هذا بالحرف: pmi(information, data) = log2(.3399 / (.6575 × .4842)) = .0944.
A strong cell and a negative cell, so you see both branches of the max.
خلية ذات ارتباط قوي وخلية سالبة، لترى فرعي max كليهما.
PPMI(cherry, pie) the strong association f(cherry, pie) = 442 p(cherry, pie) = 442 / 11716 = 0.03773 p(cherry) = 486 / 11716 = 0.04148 p(pie) = 512 / 11716 = 0.04370 baseline = 0.04148 x 0.04370 = 0.0018127 ratio = 0.03773 / 0.0018127 = 20.81 pmi = log2(20.81) = 4.379 ppmi = max(4.379, 0) = 4.38 matches the slide cherry and pie co-occur about 21 times more often than chance. that factor of 21 is why the PPMI is above 4: log2(16) = 4.
الخلية القوية: f(cherry, pie) = 442، فالاحتمال المشترك 442 / 11716 = 0.03773، وp(cherry) = 486 / 11716 = 0.04148، وp(pie) = 512 / 11716 = 0.04370، وخط الأساس 0.04148 x 0.04370 = 0.0018127، والنسبة 0.03773 / 0.0018127 = 20.81، وpmi = log2(20.81) = 4.379، وppmi = max(4.379, 0) = 4.38 مطابقاً للشريحة. أي أن cherry وpie تظهران معاً نحو 21 ضعف المصادفة، وهذا سبب تجاوز PPMI للأربعة لأن log2(16) = 4.
PPMI(cherry, computer) the negative cell f(cherry, computer) = 2 p(cherry, computer) = 2 / 11716 = 0.00017071 p(cherry) = 486 / 11716 = 0.04148 p(computer) = 4997 / 11716 = 0.42651 baseline = 0.04148 x 0.42651 = 0.017692 ratio = 0.00017071 / 0.017692 = 0.009649 pmi = log2(0.009649) = -6.70 NEGATIVE ppmi = max(-6.70, 0) = 0 matches the slide the ratio is below 1, so the log is negative, so the cell is clipped. this is the step people forget. do not write -6.70 in a PPMI matrix.
الخلية السالبة: f(cherry, computer) = 2، فالاحتمال المشترك 2 / 11716 = 0.00017071، وp(cherry) = 0.04148، وp(computer) = 4997 / 11716 = 0.42651، وخط الأساس 0.04148 x 0.42651 = 0.017692، والنسبة 0.00017071 / 0.017692 = 0.009649، وpmi = log2(0.009649) = -6.70 وهو سالب، فـ ppmi = max(-6.70, 0) = 0 مطابقاً للشريحة. النسبة أقل من 1 فالـ log سالب فتُقصّ الخلية. هذه هي الخطوة التي يُنسى تطبيقها، فلا تكتب -6.70 في مصفوفة PPMI.
PMI before clipping, PPMI after
PMI قبل القص، وPPMI بعده
Every cell of the matrix, computed twice. The left number is raw PMI. The right number is what slide 57 prints.
كل خلايا المصفوفة محسوبة مرتين: الرقم على اليسار هو PMI الخام، والرقم على اليمين هو ما تطبعه الشريحة 57.
| PMI → PPMI | computer | data | result | pie | sugar |
|---|---|---|---|---|---|
| cherry | −6.70 → 0 | −4.88 → 0 | −1.12 → 0 | 4.38 → 4.38 | 3.30 → 3.30 |
| strawberry | −∞ → 0 | −∞ → 0 | −1.69 → 0 | 4.10 → 4.10 | 5.51 → 5.51 |
| digital | 0.18 → 0.18 | 0.01 → 0.01 | −0.71 → 0 | −4.91 → 0 | −2.17 → 0 |
| information | 0.02 → 0.02 | 0.09 → 0.09 | 0.28 → 0.28 | −6.07 → 0 | −1.63 → 0 |
يعطي الجدول كل خلية مرتين بصيغة PMI → PPMI. الخلايا المظللة هي السالبة التي صارت 0، مثل cherry / computer من −6.70 إلى 0. والخلايا الناجية تبقى كما هي، مثل cherry / pie عند 4.38 وstrawberry / sugar عند 5.51. وخلايا strawberry مع computer وdata تظهر −∞ لأن العدد صفر، وتصبح 0 أيضاً.
Twelve of the twenty cells get clipped. The resulting matrix is sparse, and the surviving values draw a clean picture: cherry and strawberry live with pie and sugar, digital and information live with computer and data. The raw count matrix did not say that nearly so clearly, because digital and information had enormous counts that swamped everything.
اثنتا عشرة خلية من العشرين تُقصّ، فتصبح المصفوفة متبعثرة، والقيم الباقية ترسم صورة واضحة: cherry وstrawberry تسكنان مع pie وsugar، وdigital وinformation تسكنان مع computer وdata. مصفوفة الأعداد الخام لم تقل ذلك بهذا الوضوح، لأن أعداد digital وinformation الضخمة كانت تطغى على كل شيء.
Where a count is 0, the joint probability is 0 and log2(0) is −∞. The max with 0 handles that too, so you never have to special-case it.
حين يكون العدد 0، يكون الاحتمال المشترك 0 وlog2(0) يساوي −∞. وmax مع 0 يعالج هذه الحالة أيضاً، فلا تحتاج معاملة خاصة لها.
Forgetting the max with 0. A PPMI matrix with a negative entry in it is wrong by definition. If you compute −6.70 and write it down, you have computed PMI, not PPMI.
نسيان max مع 0. مصفوفة PPMI فيها قيمة سالبة خاطئة بالتعريف. فإذا حسبت −6.70 وكتبتها، فأنت حسبت PMI لا PPMI.
Log base 2, not 10 and not e. PMI uses log2. tf-idf on the previous page used log10. For the ratio 20.81: log2 = 4.38, log10 = 1.32, ln = 3.04. Only the first matches the slide.
الأساس 2، لا 10 ولا e. PMI يستخدم log2، بينما tf-idf في الصفحة السابقة استخدم log10. للنسبة 20.81: log2 = 4.38، وlog10 = 1.32، وln = 3.04. الأول فقط يطابق الشريحة.
Dividing by the wrong total. pij, pi* and p*j all use the same grand total 11716. Do not divide the row by the row sum, which would give you a conditional probability P(c|w) instead of a marginal.
القسمة على المجموع الخطأ. pij وpi* وp*j كلها تستخدم المجموع الكلي نفسه 11716. لا تقسم الصف على مجموع الصف، فذلك يعطيك احتمالاً شرطياً P(c|w) لا marginal.
Row versus column marginal. pi* sums across the row (over all contexts). p*j sums down the column (over all words). The star marks the index that is summed away.
الخلط بين marginal الصف والعمود. pi* يجمع عبر الصف، أي على كل الـ contexts. وp*j يجمع نزولاً في العمود، أي على كل الكلمات. والنجمة تشير إلى الدليل الذي جُمع وأُلغي.
PMI is biased toward rare events, slides 58 and 59
PMI منحاز نحو الأحداث النادرة، الشريحتان 58 و59
Look at the formula again. P(c) sits in the denominator. If a context word is very rare, P(c) is tiny, the ratio blows up, and the PMI is huge. So very rare words get very high PMI values, whether or not the association is real.
انظر الصيغة مرة أخرى: P(c) في المقام. فإذا كانت كلمة السياق نادرة جداً صار P(c) ضئيلاً، فانفجرت النسبة وصار PMI هائلاً. إذن الكلمات النادرة جداً تحصل على قيم PMI عالية جداً، سواء كان الارتباط حقيقياً أم لا.
A context word seen twice in the whole corpus, both times next to your target word, gets a spectacular PMI. It should not. You have two observations.
كلمة سياق ظهرت مرتين فقط في corpus كامل، والمرتان بجوار كلمتك الهدف، تحصل على PMI مذهل. وهذا لا ينبغي، فأنت تملك رصدتين فقط.
Slide 58 gives two solutions:
تعطي الشريحة 58 حلّين:
- Give rare context words slightly higher probabilities, which shrinks the denominator blow-up.
ارفع احتمالات كلمات السياق النادرة قليلاً، فيقلّ انفجار المقام.
- Use add-one smoothing, which has a similar effect.
استخدم add-one smoothing، وأثره شبيه.
The alpha = 0.75 trick, slide 59
حيلة alpha = 0.75، الشريحة 59
Raise the context probabilities to the power α = 0.75 and renormalize.
ارفع احتمالات السياق إلى القوة α = 0.75 ثم أعد التطبيع.
في الأعلى count(c) مرفوعاً للقوة α، وفي الأسفل مجموع كل الأعداد مرفوعة للقوة نفسها، وذلك لإعادة التطبيع، مع α = 0.75.
Raising a probability below 1 to a fractional power pushes it up, and the push is proportionally much larger for small values. So Pα(c) > P(c) for rare c, and the inflated denominator stops rare contexts from faking high PMI.
رفع احتمال أقل من 1 إلى قوة كسرية يدفعه للأعلى، والدفع أكبر نسبياً للقيم الصغيرة. إذن Pα(c) > P(c) للسياق النادر، والمقام المتضخم يمنع السياقات النادرة من تزييف PMI عالٍ.
Slide 59's two-event example, verified.
مثال الحدثين في الشريحة 59، محقَّقاً بالحساب.
two contexts: P(a) = 0.99 (very common), P(b) = 0.01 (very rare) raise both to the power 0.75 0.99^0.75 = 0.99249 0.01^0.75 = 0.03162 renormalize by their sum denominator = 0.99249 + 0.03162 = 1.02411 P_alpha(a) = 0.99249 / 1.02411 = 0.9691 -> 0.97 P_alpha(b) = 0.03162 / 1.02411 = 0.0309 -> 0.03 the rare context went from 0.01 to 0.03, roughly tripled. the common context barely moved, 0.99 down to 0.97. a bigger P(c) in the denominator means a smaller ratio, which means a smaller PMI for the rare context. that is the fix.
سياقان: P(a) = 0.99 شائع جداً وP(b) = 0.01 نادر جداً. ترفع الاثنين للقوة 0.75 فتحصل على 0.99^0.75 = 0.99249 و0.01^0.75 = 0.03162، ثم تعيد التطبيع بمجموعهما 1.02411، فينتج P_alpha(a) = 0.9691 أي 0.97، وP_alpha(b) = 0.0309 أي 0.03. فالسياق النادر صعد من 0.01 إلى 0.03، نحو ثلاثة أضعاف، والشائع كاد لا يتحرك من 0.99 إلى 0.97. وP(c) أكبر في المقام يعني نسبة أصغر يعني PMI أصغر للسياق النادر، وهذا هو الإصلاح.
α = 0.75 shows up twice in this lecture. Here, to flatten context probabilities for PMI, and again in word2vec negative sampling, where noise words are drawn from the unigram distribution raised to the power 0.75.
α = 0.75 يظهر مرتين في هذه المحاضرة. هنا لتسطيح احتمالات السياق من أجل PMI، ومرة أخرى في word2vec negative sampling، حيث تُسحب كلمات الضجيج من unigram distribution مرفوعاً للقوة 0.75.
It is the same idea both times: the 0.75 power gives rare words a bigger share. Remember it as one fact, answer two questions.
الفكرة واحدة في المرتين: القوة 0.75 تمنح الكلمات النادرة نصيباً أكبر. احفظها حقيقة واحدة، وأجب بها على سؤالين.
The other fix, add-one smoothing, works by adding a constant to every count before you compute probabilities. Adding 1 to a cell that was 0 is a large relative change; adding 1 to a cell that was 3982 is nothing. So smoothing also flattens the distribution and pulls down the inflated PMI of rare pairs. The slide says add-one specifically; the general family is add-k.
الحل الآخر، add-one smoothing، يعمل بإضافة ثابت إلى كل عدد قبل حساب الاحتمالات. فإضافة 1 إلى خلية كانت 0 تغيير نسبي كبير، وإضافة 1 إلى خلية كانت 3982 لا تعني شيئاً. إذن الـ smoothing يسطّح التوزيع أيضاً ويسحب PMI المتضخم للأزواج النادرة إلى الأسفل. والشريحة تذكر add-one تحديداً، والعائلة العامة هي add-k.
Thirty-second recap
خلاصة في ثلاثين ثانية
Check yourself
اختبر نفسك
For a cell of a term-context matrix, PMI comes out as −3.2. What is the PPMI for that cell?
في خلية من مصفوفة term-context، جاء PMI يساوي −3.2. فما PPMI لهذه الخلية؟
PPMI = max(PMI, 0), so a negative PMI becomes exactly 0. A is the error of computing PMI and calling it PPMI. B invents an absolute value that is not in the formula; taking the magnitude would turn a weak, noisy signal into a strong-looking one. D is wrong because PMI ranges from −∞ to +∞, as slide 54 states.
الجواب C. لأن PPMI = max(PMI, 0)، فأي PMI سالب يصبح 0 بالضبط. والجواب A هو خطأ من يحسب PMI ويسميه PPMI. وB يخترع قيمة مطلقة ليست في الصيغة، وأخذ المقدار يحوّل إشارة ضعيفة مشوشة إلى إشارة تبدو قوية. وD خاطئ لأن مدى PMI من −∞ إلى +∞ كما تنص الشريحة 54.
Why does the lecture clip negative PMI values instead of keeping them?
لماذا تقصّ المحاضرة قيم PMI السالبة بدلاً من الإبقاء عليها؟
Slide 54 gives the statistical argument: with two words each of probability 10−6, you would need to distinguish an observed joint probability from 10−12, which is hopeless at normal corpus sizes. D is wrong because negative PMI appears for plenty of non-zero counts, for example cherry/computer with a count of 2 gives PMI −6.70.
الجواب B. تعطي الشريحة 54 الحجة الإحصائية: مع كلمتين احتمال كل منهما 10−6، ستحتاج أن تفرّق احتمالاً مشتركاً مرصوداً عن 10−12، وهذا ميؤوس منه بأحجام corpus العادية. والجواب D خاطئ لأن PMI السالب يظهر مع أعداد كثيرة غير صفرية، مثل cherry/computer بعدد 2 الذي يعطي PMI يساوي −6.70.
In the slide 56 matrix, p(c = data) = 5673 / 11716. Where does 5673 come from?
في مصفوفة الشريحة 56، p(c = data) = 5673 / 11716. فمن أين جاء 5673؟
A context marginal p*j is a column sum over the grand total. 8 + 0 + 1683 + 3982 = 5673. B is the row sum, which is 7703 and is p(information). C is 3982, the joint numerator. Mixing up which direction to sum is the single most common slip in this computation.
الجواب A. الـ marginal للسياق p*j هو مجموع العمود على المجموع الكلي، و8 + 0 + 1683 + 3982 = 5673. والجواب B هو مجموع الصف وقيمته 7703 وهو p(information). والجواب C هو 3982، أي بسط الاحتمال المشترك. والخلط في اتجاه الجمع هو أكثر زلة شيوعاً في هذا الحساب.
A cell has f = 10, grand total 1000, row sum 100, column sum 200. What is the PMI?
خلية فيها f = 10، والمجموع الكلي 1000، ومجموع الصف 100، ومجموع العمود 200. فما PMI؟
pij = 10/1000 = 0.01, pi* = 100/1000 = 0.1, p*j = 200/1000 = 0.2, so the ratio is 0.01/0.02 = 0.5 and log2(0.5) = −1. The PPMI would then be 0. B uses log base 10 instead of base 2. C forgets to convert the marginal counts into probabilities, which is the most common version of this mistake.
الجواب D. pij = 10/1000 = 0.01، وpi* = 100/1000 = 0.1، وp*j = 200/1000 = 0.2، فالنسبة 0.01/0.02 = 0.5 وlog2(0.5) = −1، ويكون PPMI بعدها 0. والجواب B يستخدم الأساس 10 بدل 2. والجواب C ينسى تحويل أعداد الـ marginals إلى احتمالات، وهذه أشيع صورة لهذا الخطأ.
Why is PMI biased toward rare events?
لماذا يكون PMI متحيزاً نحو الأحداث النادرة؟
The ratio is P(w,c) divided by P(w)P(c). Shrinking P(c) makes the whole fraction explode, so a context word seen only twice can register an enormous PMI on almost no evidence. A is backwards: rare words produce small joint counts. The fixes on slides 58 and 59 all work by making the denominator bigger for rare contexts.
الجواب C. النسبة هي P(w,c) مقسومة على P(w)P(c)، فتصغير P(c) يجعل الكسر كله ينفجر، فكلمة سياق رُصدت مرتين فقط قد تسجّل PMI ضخماً على دليل شبه معدوم. والجواب A معكوس، فالكلمات النادرة تنتج أعداداً مشتركة صغيرة. وكل الحلول في الشرائح 58 و59 تعمل بتكبير المقام للسياقات النادرة.
What does raising context probabilities to the power α = 0.75 accomplish, and where else does 0.75 appear?
ما الذي يحققه رفع احتمالات السياق إلى القوة α = 0.75، وأين يظهر 0.75 مرة أخرى؟
Slide 59's own example: P(b) = 0.01 becomes Pα(b) = 0.03 while P(a) = 0.99 barely drops to 0.97. A bigger denominator means a smaller ratio means a smaller PMI for rare contexts. The identical 0.75 exponent is used in word2vec to sample negative examples, so it is worth memorizing once. D is wrong: smoothing reduces the bias but does not remove negative values, so you still need the max.
الجواب B. مثال الشريحة 59 نفسه: P(b) = 0.01 يصبح Pα(b) = 0.03، بينما P(a) = 0.99 ينزل بالكاد إلى 0.97. ومقام أكبر يعني نسبة أصغر يعني PMI أصغر للسياقات النادرة. ونفس الأُس 0.75 يُستخدم في word2vec لسحب الأمثلة السالبة، فيستحق الحفظ مرة واحدة. والجواب D خاطئ، فالـ smoothing يقلّل التحيز لكنه لا يُزيل القيم السالبة، فتبقى محتاجاً إلى max.