Lecture 04 · Word Embeddings
المحاضرة 04 · تضمينات الكلمات (Word Embeddings)
Cosine Similarity
تشابه جيب التمام (Cosine Similarity)
P1 MUSTHow to measure whether two word vectors mean the same thing, and why you must divide out vector length before you trust the answer.
كيف نقيس ما إذا كان متجهان لكلمتين يحملان المعنى نفسه، ولماذا يجب أن تقسم على طول المتجه قبل أن تثق بالنتيجة.
Hand computation is very likely. You will be given two short integer vectors and asked for the cosine. Know the formula cold, and never skip the square roots in the denominator.
الحساب اليدوي مرجّح جداً. سيُعطى لك متجهان قصيران بأعداد صحيحة ويُطلب منك cosine. احفظ المعادلة تماماً، ولا تُسقط الجذور التربيعية في المقام أبداً.
The setup
الإعداد
You have a term-term matrix. Every word is a row, which is a vector of counts over context words. Two words are similar if their rows look alike.
لديك term-term matrix. كل كلمة صفّ، والصفّ متجه من العدّات على كلمات السياق. وتكون الكلمتان متشابهتين إذا تشابه صفّاهما.
So we need a number that says "these two vectors look alike". That is the whole problem on these six slides.
فنحتاج إلى رقم واحد يقول إن "هذين المتجهين متشابهان". هذه هي كل المسألة في هذه الشرائح الست.
Step 1: the dot product
الخطوة 1: الضرب النقطي (dot product)
The dot product between two vectors is a single scalar.
الـ dot product بين متجهين هو عدد واحد (scalar).
تُقرأ المعادلة هكذا: a · b هو مجموع حواصل ضرب كل بُعد في نظيره، من i = 1 إلى N، والناتج عدد واحد لا متجه.
Multiply matching dimensions, add everything up. That is it.
اضرب الأبعاد المتناظرة، ثم اجمع الكل. هذا كل شيء.
Why this is a similarity measure, straight from slide 38:
لماذا يُعدّ هذا مقياس تشابه، كما في الشريحة 38 حرفياً:
- The dot product is high when the two vectors have large values in the same dimensions.
يكون dot product مرتفعاً عندما يكون للمتجهين قيم كبيرة في الأبعاد نفسها.
- It is zero when they are orthogonal, which happens when every dimension where one is large is a dimension where the other is zero.
ويكون صفراً عندما يكونان متعامدين (orthogonal)، أي أن كل بُعد يكبر فيه أحدهما يكون صفراً في الآخر.
In word terms: two words get a big dot product when they both co-occur a lot with the same context words. That is exactly the distributional hypothesis, turned into arithmetic.
بلغة الكلمات: تحصل كلمتان على dot product كبير عندما تظهر كلتاهما كثيراً مع كلمات السياق نفسها. وهذا هو distributional hypothesis بعينه، محوَّلاً إلى عملية حسابية.
Step 2: the raw dot product is broken
الخطوة 2: الضرب النقطي الخام معطوب
Slide 39 is the complaint. The dot product favours long vectors.
الشريحة 39 هي الاعتراض: الـ dot product يفضّل المتجهات الطويلة.
Vector length, the Euclidean norm:
طول المتجه، أي Euclidean norm:
تقول المعادلة إن |a| هو الجذر التربيعي لمجموع مربعات مكوّنات المتجه كلها.
A vector gets long when it has big values in many dimensions. In a co-occurrence matrix, a word's values are counts, so vector length grows with word frequency.
يطول المتجه عندما تكون قيمه كبيرة في أبعاد كثيرة. وفي co-occurrence matrix تكون قيم الكلمة عدّات، لذلك طول المتجه يزداد بزيادة تكرار الكلمة.
Frequent words like of, the, you occur next to everything, so their rows are full of large numbers, so their vectors are very long, so their dot product with anything is large.
الكلمات الشائعة مثل of وthe وyou تظهر بجانب كل شيء، فتمتلئ صفوفها بأعداد كبيرة، فتطول متجهاتها جداً، فيكبر dot product بينها وبين أي كلمة.
That is a bias, not a signal. The dot product would tell you the is the nearest neighbour of every word in the language.
هذا تحيّز لا إشارة. فـ dot product سيخبرك أن the هي أقرب جار لكل كلمة في اللغة.
Two candidate neighbours for apricot = [2, 3]. Dimensions are counts next to sugar and jam.
مرشّحان للجيرة مع apricot = [2, 3]. والبعدان هما عدّات الظهور بجانب sugar وjam.
candidate A: fig = [4, 6] same direction, just twice as big candidate B: the = [30, 10] a frequent word, very long vector RAW DOT PRODUCT apricot · fig = 2(4) + 3(6) = 8 + 18 = 26 apricot · the = 2(30) + 3(10) = 60 + 30 = 90 winner by dot product: "the" <-- wrong answer COSINE |apricot| = sqrt(2^2 + 3^2) = sqrt(4 + 9) = sqrt(13) = 3.6056 |fig| = sqrt(4^2 + 6^2) = sqrt(16 + 36) = sqrt(52) = 7.2111 |the| = sqrt(30^2 + 10^2) = sqrt(900 + 100) = sqrt(1000) = 31.6228 cos(apricot, fig) = 26 / (3.6056 x 7.2111) = 26 / 26.0000 = 1.000 cos(apricot, the) = 90 / (3.6056 x 31.6228) = 90 / 114.018 = 0.789 winner by cosine: "fig" <-- right answer
يقارن المقطع بين مرشّحين: fig = [4, 6] وهو بالاتجاه نفسه لكن بضعف الحجم، وthe = [30, 10] وهو كلمة شائعة بمتجه طويل جداً. بالـ dot product الخام يكون الناتج 26 مع fig مقابل 90 مع the، فيفوز the وهو جواب خاطئ. وبالـ cosine يكون الناتج 1.000 مع fig مقابل 0.789 مع the، فيفوز fig وهو الجواب الصحيح.
The dot product picked the frequent word purely because it is long. Cosine normalized the length away and picked the word that actually points the same way.
اختار dot product الكلمة الشائعة لمجرد أن متجهها طويل. أما cosine فألغى أثر الطول واختار الكلمة التي تشير فعلاً إلى الاتجاه نفسه.
Step 3: cosine is the fix
الخطوة 3: cosine هو الإصلاح
Divide the dot product by both vector lengths. The length cancels out and only direction is left.
اقسم dot product على طولَي المتجهين معاً. فيُلغى الطول ولا يبقى إلا الاتجاه.
اقرأ المعادلة في ثلاث قطع. في الأعلى dot product، أي مجموع حواصل ضرب المكوّنات المتناظرة. وفي الأسفل حاصل ضرب طولَي المتجهين، أي |v| في |w|، وكل طول منهما جذر تربيعي لمجموع مربعات مكوّناته. والناتج هو جيب تمام الزاوية بين المتجهين، فيقع بين 0 و1 للمتجهات غير السالبة.
Slide 40 shows where this comes from. It is not an invention, it is the geometric definition of the dot product rearranged:
تُظهر الشريحة 40 من أين جاءت هذه الصيغة. ليست اختراعاً، بل هي التعريف الهندسي لـ dot product بعد إعادة ترتيبه:
المعادلة تقول a · b = |a| |b| cos θ، فإذا قسمت الطرفين على |a| |b| حصلت على cos θ مباشرة.
So the normalized dot product literally is the cosine of the angle between the two vectors. Nothing extra is going on.
إذن dot product المُطبَّع هو حرفياً جيب تمام الزاوية بين المتجهين. لا شيء إضافي في الأمر.
The range, which gets examined
المدى، وهو مما يُختبر فيه
Slide 41:
الشريحة 41:
- +1: vectors point in the same direction. Angle 0.
+1: المتجهان في الاتجاه نفسه، والزاوية 0.
- 0: vectors are orthogonal. Angle 90 degrees. No shared context at all.
0: المتجهان متعامدان، والزاوية 90 درجة، ولا سياق مشترك بينهما إطلاقاً.
- −1: vectors point in opposite directions. Angle 180 degrees.
−1: المتجهان في اتجاهين متعاكسين، والزاوية 180 درجة.
But here is the part the slide puts in its own bullet. Raw frequency values are non-negative, so for a term-term count matrix the cosine can only range from 0 to 1. You can never get a negative cosine out of counts, because you can never get a negative dot product out of counts.
لكن هذه هي النقطة التي أفردتها الشريحة بسطر خاص: قيم التكرار الخام غير سالبة، فلذلك في term-term count matrix لا يمكن لـ cosine أن يتجاوز المدى من 0 إلى 1. لا يمكن أبداً أن تحصل على cosine سالب من عدّات، لأنك لا تحصل أبداً على dot product سالب من عدّات.
The same holds for tf-idf and for PPMI, which are also non-negative. So in this course you will essentially always be in the 0 to 1 band. The −1 end exists in general, for vectors that are allowed negative components, such as learned word2vec embeddings.
والأمر نفسه ينطبق على tf-idf وعلى PPMI، فكلاهما غير سالب. لذلك ستكون في هذا المقرر دائماً تقريباً في نطاق 0 إلى 1. أما الطرف −1 فهو موجود في الحالة العامة، للمتجهات التي يُسمح لمكوّناتها بأن تكون سالبة، مثل embeddings المُتعلَّمة في word2vec.
الرسم نصفان. على اليسار متجهان v وw من نقطة الأصل وبينهما الزاوية θ، والمقصود أن cos θ هو كل ما يهم. وعلى اليمين a = [2, 3] وb = [6, 9] الذي يساوي 3a: الزاوية بينهما 0، فيكون cosine مساوياً 1 بالضبط مع أن |b| = 3|a|. الطول غير مرئي لـ cosine، لكنه مرئي جداً لـ dot product.
Dot product versus cosine, side by side
Dot product مقابل cosine، جنباً إلى جنب
| Dot productDot product | CosineCosine | |
|---|---|---|
| Formulaالصيغة | Σ aibi | Σ aibi|a||b| |
| What it measuresما يقيسه | shared direction AND sizeالاتجاه المشترك والحجم معاً | shared direction onlyالاتجاه المشترك فقط |
| Range on countsالمدى على العدّات | 0 to ∞من 0 إلى ∞ | 0 to 1من 0 إلى 1 |
| Range in generalالمدى عموماً | −∞ to ∞من −∞ إلى ∞ | −1 to 1من −1 إلى 1 |
| Effect of doubling one vectorأثر مضاعفة أحد المتجهين | doublesيتضاعف | unchangedلا يتغير |
| Frequent-word biasالانحياز للكلمات الشائعة | severeشديد | removedمُزال |
| Usable as a similarity metricصالح كمقياس تشابه | only if lengths are comparableفقط إذا كانت الأطوال متقاربة | yesنعم |
يضع الجدول dot product وcosine جنباً إلى جنب. الأول يقيس الاتجاه المشترك والحجم معاً، والثاني يقيس الاتجاه فقط. مداهما على العدّات: من 0 إلى ∞ مقابل من 0 إلى 1، وفي الحالة العامة من −∞ إلى ∞ مقابل من −1 إلى 1. وإذا ضاعفت أحد المتجهين تضاعف dot product وبقي cosine كما هو. والخلايا المميّزة هي عمود cosine: تحيّز الكلمات الشائعة مُزال، والمقياس صالح للاستخدام.
A clean hand computation
حساب يدوي نظيف
This is the shape of the exam question. Do every step in this order and you cannot get lost.
هذا هو شكل سؤال الامتحان. نفّذ الخطوات بهذا الترتيب ولن تضيع.
- Multiply the matching components and sum them. That is the numerator.
اضرب المكوّنات المتناظرة واجمعها. هذا هو البسط.
- Square every component of the first vector, sum, take the square root.
ربّع كل مكوّن من المتجه الأول، اجمع، ثم خذ الجذر التربيعي.
- Square every component of the second vector, sum, take the square root.
ربّع كل مكوّن من المتجه الثاني، اجمع، ثم خذ الجذر التربيعي.
- Multiply the two roots. That is the denominator.
اضرب الجذرين. هذا هو المقام.
- Divide.
اقسم.
a = [3, 4] b = [4, 3] NUMERATOR (dot product) 3 x 4 = 12 4 x 3 = 12 sum = 12 + 12 = 24 LENGTH OF a 3^2 = 9 4^2 = 16 sum = 9 + 16 = 25 |a| = sqrt(25) = 5 LENGTH OF b 4^2 = 16 3^2 = 9 sum = 16 + 9 = 25 |b| = sqrt(25) = 5 DENOMINATOR |a| x |b| = 5 x 5 = 25 COSINE cos(a, b) = 24 / 25 = 0.96 sanity check: angle = arccos(0.96) = 16.3 degrees. Nearly the same direction, which matches the fact that [3,4] and [4,3] are close.
يحسب المقطع cos(a, b) لـ a = [3, 4] وb = [4, 3]. البسط 12 + 12 = 24. والطولان |a| = 5 و|b| = 5، فالمقام 5 x 5 = 25. والناتج 24 / 25 = 0.96. وللتحقق: الزاوية 16.3 درجة، أي اتجاه متقارب جداً، وهذا يطابق كون [3,4] و[4,3] قريبين.
Two more one-liners from the same pair, worth memorizing as reference points:
حالتان إضافيتان سريعتان من الزوج نفسه، تستحقان الحفظ كنقطتي مرجع:
a = [3, 4], b = [6, 8] b is exactly 2a dot = 18 + 32 = 50 |a| = 5, |b| = sqrt(36 + 64) = sqrt(100) = 10 cos = 50 / (5 x 10) = 50 / 50 = 1.0 same direction a = [3, 4], b = [-4, 3] perpendicular dot = -12 + 12 = 0 cos = 0 / (5 x 5) = 0 orthogonal
الحالة الأولى b = [6, 8] وهو 2a بالضبط: dot = 50 والمقام 5 x 10 = 50، فالناتج 1.0، أي الاتجاه نفسه. والحالة الثانية b = [-4, 3] وهو عمودي: dot = -12 + 12 = 0، فالناتج 0، أي orthogonal.
The slides' own cosine example
مثال cosine من الشرائح نفسها
Slide 42 uses this three-column slice of a term-term matrix. The contexts are pie, data, computer.
تستخدم الشريحة 42 هذا المقطع ثلاثي الأعمدة من term-term matrix. وكلمات السياق هي pie وdata وcomputer.
| pie | data | computer | |
|---|---|---|---|
| cherry | 442 | 8 | 2 |
| digital | 5 | 1683 | 1670 |
| information | 5 | 3982 | 3325 |
يعطي الجدول ثلاثة صفوف، كل صفّ متجه على الأبعاد الثلاثة: cherry = [442, 8, 2]، وdigital = [5, 1683, 1670]، وinformation = [5, 3982, 3325]. هذه هي الأرقام نفسها التي تدخل في الحساب بعد قليل.
Read the rows before you compute anything. cherry lives almost entirely in the pie dimension. digital and information both live almost entirely in the data and computer dimensions. So we expect cherry to be unrelated to information, and digital to be nearly identical to information.
اقرأ الصفوف قبل أن تحسب أي شيء. فـ cherry يسكن تقريباً كله في بُعد pie، بينما digital وinformation يسكنان تقريباً كلهما في بُعدَي data وcomputer. فنتوقع أن يكون cherry بلا علاقة بـ information، وأن يكون digital شبه مطابق لـ information.
cos(cherry, information) cherry = [442, 8, 2] information = [5, 3982, 3325] NUMERATOR 442 x 5 = 2210 8 x 3982 = 31856 2 x 3325 = 6650 dot = 2210 + 31856 + 6650 = 40716 |cherry| 442^2 = 195364 8^2 = 64 2^2 = 4 sum = 195432 sqrt(195432) = 442.0769 |information| 5^2 = 25 3982^2 = 15856324 3325^2 = 11055625 sum = 26911974 sqrt(26911974) = 5187.6752 DENOMINATOR 442.0769 x 5187.6752 = 2,293,351.5 COSINE 40716 / 2,293,351.5 = 0.01775 -> .017 (matches the slide) angle = arccos(0.0178) = 89.0 degrees, essentially orthogonal
يحسب المقطع cos(cherry, information). البسط 2210 + 31856 + 6650 = 40716. والطولان 442.0769 و5187.6752، فالمقام 2,293,351.5. والناتج 0.01775 الذي يُقرّب إلى .017، وهو يطابق الشريحة. والزاوية 89.0 درجة، أي متعامدان فعلياً.
cos(digital, information) digital = [5, 1683, 1670] information = [5, 3982, 3325] NUMERATOR 5 x 5 = 25 1683 x 3982 = 6701706 1670 x 3325 = 5552750 dot = 25 + 6701706 + 5552750 = 12254481 |digital| 5^2 = 25 1683^2 = 2832489 1670^2 = 2788900 sum = 5621414 sqrt(5621414) = 2370.9521 |information| = 5187.6752 (already computed above) DENOMINATOR 2370.9521 x 5187.6752 = 12,299,729.6 COSINE 12254481 / 12,299,729.6 = 0.99632 -> .996 (matches the slide) angle = arccos(0.9963) = 4.9 degrees, nearly identical direction
ويحسب المقطع الثاني cos(digital, information). البسط 25 + 6701706 + 5552750 = 12254481. و|digital| = 2370.9521 و|information| = 5187.6752 المحسوب سابقاً، فالمقام 12,299,729.6. والناتج 0.99632 الذي يُقرّب إلى .996، وهو يطابق الشريحة. والزاوية 4.9 درجة، أي اتجاه شبه متطابق.
Both slide figures reproduce exactly. Note how big the raw dot products are compared to the cosines: the digital/information dot product is 12.25 million, but that number is mostly telling you both words are frequent. The cosine, 0.996, is the part that means something.
كلا رقمَي الشريحة يتكرران بالضبط. ولاحظ حجم dot products الخام أمام قيم cosine: حاصل digital/information يبلغ 12.25 مليوناً، لكن هذا الرقم يخبرك في معظمه أن الكلمتين شائعتان فقط. أما cosine، أي 0.996، فهو الجزء الذي يعني شيئاً.
Visualizing cosines, slide 43
تصوير قيم cosine، الشريحة 43
Slide 43 plots the same three words in just two of the dimensions: pie on the vertical axis, computer on the horizontal.
ترسم الشريحة 43 الكلمات الثلاث نفسها في بُعدين فقط: pie على المحور الرأسي، وcomputer على المحور الأفقي.
في الرسم ينطلق سهم cherry صاعداً تقريباً على محور pie، بينما يمتد سهمَا digital وinformation شبه مسطّحين على محور computer، والفرق بينهما في الطول لا في الزاوية، فـ cosine بينهما 0.996. والزاوية المعلَّمة 89° هي بين cherry والاثنين الآخرين، ولذلك cosine بين cherry وinformation هو 0.017.
The whole argument of these six slides is visible here. If you measured similarity by how far the arrow tips are apart, or by dot product size, information and digital would look different because one is twice as long. The angle does not care.
كل حجة الشرائح الست مرئية هنا. لو قِست التشابه بمقدار تباعد رأسَي السهمين، أو بحجم dot product، لظهر information وdigital مختلفَين لأن أحدهما ضعف الآخر طولاً. أما الزاوية فلا تهتم بذلك.
The dot product asks two questions at once: do they point the same way, and are they big? Cosine divides the "big" out so only "same way" is left.
الـ dot product يسأل سؤالين في وقت واحد: هل يشيران إلى الاتجاه نفسه، وهل هما كبيران؟ أما cosine فيقسم "الكبير" خارجاً فلا يبقى إلا "الاتجاه نفسه".
Cosine is the angle, not the size.
الـ cosine هو الزاوية، لا الحجم.
Do not forget the square roots. The denominator is Σvi2 × Σwi2, not (Σvi2) × (Σwi2). For a = [3,4], b = [4,3] the right answer is 24/25 = 0.96. Dropping the roots gives 24/625 = 0.038, which is not even in the right order of magnitude. If your cosine comes out suspiciously tiny, this is almost always why.
لا تنسَ الجذور التربيعية. المقام هو جذر Σvi2 مضروباً في جذر Σwi2، وليس (Σvi2) × (Σwi2). فلـ a = [3,4] وb = [4,3] الجواب الصحيح 24/25 = 0.96، وإسقاط الجذور يعطي 24/625 = 0.038، وهو ليس حتى في رتبة المقدار الصحيحة. فإذا خرج cosine صغيراً بشكل مريب، فهذا هو السبب في الغالب.
Second trap: the two square roots are multiplied, not added, and they are not combined under one root. 25 × 25 = 25, while 25+25 = 7.07.
الفخ الثاني: الجذران يُضربان ولا يُجمعان، وهما ليسا تحت جذر واحد. فجذر 25 مضروباً في جذر 25 يساوي 25، بينما جذر 25+25 يساوي 7.07.
Third trap: cosine ranges 0 to 1 for non-negative vectors. The general range is −1 to 1. If an exam question says "raw counts", answer 0 to 1. If it says "in general" or "embeddings", answer −1 to 1.
الفخ الثالث: مدى cosine من 0 إلى 1 للمتجهات غير السالبة، أما المدى العام فمن −1 إلى 1. فإذا قال السؤال "raw counts" فأجب من 0 إلى 1، وإذا قال "in general" أو "embeddings" فأجب من −1 إلى 1.
Thirty-second recap
خلاصة في ثلاثين ثانية
Check yourself
اختبر نفسك
Compute cos(a, b) for a = [1, 2, 2] and b = [2, 1, 2].
احسب cos(a, b) حيث a = [1, 2, 2] وb = [2, 1, 2].
Dot = 1(2) + 2(1) + 2(2) = 2 + 2 + 4 = 8. Each length is 1+4+4 = 9 = 3, so the denominator is 3 × 3 = 9, giving 8/9 = 0.889. Option A is the classic error of forgetting both square roots (9 × 9 = 81). Option B adds the squared sums instead of multiplying the roots. Option D divides by only one length.
الجواب C. dot = 1(2) + 2(1) + 2(2) = 2 + 2 + 4 = 8. وكل طول هو جذر 1+4+4، أي جذر 9، أي 3، فالمقام 3 × 3 = 9، والناتج 8/9 = 0.889. والخيار A هو الخطأ الكلاسيكي بنسيان الجذرين (9 × 9 = 81). والخيار B يجمع مجموعَي المربعات بدلاً من ضرب الجذرين. والخيار D يقسم على طول واحد فقط.
Why does the lecture reject the raw dot product as a similarity metric?
لماذا ترفض المحاضرة dot product الخام كمقياس تشابه؟
Slide 39 states it directly: the dot product favours long vectors, and frequent words like of, the, you have long vectors because they co-occur with many words many times. A is wrong because with raw counts the dot product can never be negative, which is part of why that is not the complaint. D is backwards: the dot product is precisely driven by dimensions where both are large.
الجواب B. تقولها الشريحة 39 مباشرة: dot product يفضّل المتجهات الطويلة، والكلمات الشائعة مثل of وthe وyou متجهاتها طويلة لأنها تظهر مع كلمات كثيرة مرات كثيرة. والخيار A خاطئ لأن dot product على العدّات الخام لا يمكن أن يكون سالباً أصلاً، وهذا جزء من سبب كون الاعتراض ليس هذا. والخيار D معكوس: dot product مدفوع بالضبط بالأبعاد التي يكبر فيها كلا المتجهين.
Vector b is exactly five times vector a, component by component. What is cos(a, b)?
المتجه b يساوي خمسة أمثال المتجه a بالضبط، مكوّناً بمكوّن. فما قيمة cos(a, b)؟
The numerator scales by 5 and the denominator also scales by 5 (since |b| = 5|a|), so the 5 cancels and the cosine is exactly 1. This is the whole point of normalizing: cosine sees direction only. B is impossible because cosine can never exceed 1.
الجواب D. البسط يتضاعف بمقدار 5 والمقام يتضاعف أيضاً بمقدار 5 (لأن |b| = 5|a|)، فيُلغى الـ 5 ويصبح cosine مساوياً 1 بالضبط. وهذه هي كل فكرة التطبيع: cosine يرى الاتجاه فقط. والخيار B مستحيل لأن cosine لا يتجاوز 1 أبداً.
For a term-term matrix of raw co-occurrence counts, what range can the cosine take?
في term-term matrix من عدّات الظهور المشترك الخام، ما المدى الذي يمكن أن يأخذه cosine؟
Slide 41 makes this an explicit bullet. The general cosine range is −1 to 1, but raw frequency values are non-negative, so every dot product is non-negative and the cosine cannot go below 0. B is the tempting answer because it is the general range; it is only correct for vectors allowed to have negative components, like learned embeddings.
الجواب A. تُفرد الشريحة 41 لهذا سطراً صريحاً. المدى العام لـ cosine من −1 إلى 1، لكن قيم التكرار الخام غير سالبة، فكل dot product غير سالب، ولا يمكن لـ cosine أن ينزل تحت 0. والخيار B مُغرٍ لأنه المدى العام، وهو صحيح فقط للمتجهات المسموح لها بمكوّنات سالبة، مثل embeddings المُتعلَّمة.
Using the slide 42 matrix, cos(cherry, information) = 0.017 and cos(digital, information) = 0.996. What does the 0.017 tell you?
باستخدام مصفوفة الشريحة 42، cos(cherry, information) = 0.017 وcos(digital, information) = 0.996. فماذا يخبرك الرقم 0.017؟
A cosine near 0 means an angle near 90 degrees: orthogonal, so unrelated. Here it is 89.0 degrees. A is wrong because "opposite" would be cosine near −1, which raw counts can never produce. B confuses the cosine with a frequency ratio; cosine has nothing to do with relative counts.
الجواب C. قيمة cosine قريبة من 0 تعني زاوية قريبة من 90 درجة، أي متعامدين، أي لا علاقة بينهما، وهي هنا 89.0 درجة. والخيار A خاطئ لأن التعاكس في المعنى يستلزم cosine قريباً من −1، وهو ما لا تنتجه العدّات الخام أبداً. والخيار B يخلط بين cosine ونسبة تكرار، وcosine لا علاقة له بالعدّات النسبية.
The geometric identity a · b = |a||b| cos θ matters here because it shows that
الهوية الهندسية a · b = |a||b| cos θ مهمة هنا لأنها تُظهر أن
Slide 40 derives cosine from this identity: rearranging gives (a · b)/(|a||b|) = cos θ. So the normalized dot product is the cosine, by definition. C is wrong because the lengths still require square roots. D is wrong: Euclidean distance is very sensitive to vector length, which is the exact property cosine is designed to discard.
الجواب B. تستنتج الشريحة 40 cosine من هذه الهوية: إعادة الترتيب تعطي (a · b)/(|a||b|) = cos θ. إذن dot product المُطبَّع هو cosine بالتعريف. والخيار C خاطئ لأن الأطوال لا تزال تحتاج جذوراً تربيعية. والخيار D خاطئ أيضاً: Euclidean distance حساس جداً لطول المتجه، وهي بالضبط الخصيصة التي صُمّم cosine لإسقاطها.