Lecture 04 · Word Embeddings
المحاضرة 04 · تضمينات الكلمات (Word Embeddings)
Word2vec and Skip-Gram
Word2vec وSkip-Gram
P2 SHOULDWhy we stop counting and start predicting, and how a throwaway yes/no classifier ends up handing you the word vectors.
لماذا نتوقف عن العدّ ونبدأ بالتنبؤ، وكيف ينتهي مصنِّف "نعم أو لا" نرميه بعد التدريب بأن يسلّمك متجهات الكلمات.
Start with what is wrong with the vectors you already have
ابدأ بما هو خاطئ في المتجهات التي لديك بالفعل
Everything up to now has given you one vector per word, built out of counts. tf-idf vectors and PPMI vectors are both built this way.
كل ما سبق أعطاك متجهاً واحداً لكل كلمة، مبنياً من العدّات. ومتجهات tf-idf ومتجهات PPMI كلاهما مبني بهذه الطريقة.
Slide 61 lists two complaints about those vectors:
تذكر الشريحة 61 اعتراضين على هذه المتجهات:
- They are long. The length is |V|, the size of the vocabulary, so 20,000 to 50,000 numbers per word.
إنها طويلة. طولها |V|، أي حجم المفردات، فهي من 20,000 إلى 50,000 رقم لكل كلمة.
- They are sparse. Most of those 20,000 numbers are zero, because most words never co-occur with most other words.
إنها متشتّتة (sparse). معظم هذه الأرقام الـ 20,000 أصفار، لأن معظم الكلمات لا تظهر أبداً مع معظم الكلمات الأخرى.
The alternative the slide proposes is vectors that are short (50 to 1000 numbers) and dense (most entries are non-zero). Those are what we call embeddings.
البديل الذي تقترحه الشريحة متجهات قصيرة (من 50 إلى 1000 رقم) وكثيفة (dense، أي معظم قيمها غير صفرية). وهذه هي ما نسمّيه embeddings.
Why would short and dense be better?
لماذا يكون القصير الكثيف أفضل؟
Slide 62 gives three reasons plus a fourth that is really an admission.
تعطي الشريحة 62 ثلاثة أسباب، ورابعاً هو في الحقيقة اعتراف.
- Fewer weights to tune. If you feed a word vector into a machine learning model as a feature, a 300-dimensional vector means 300 weights. A 50,000-dimensional vector means 50,000 weights, and you probably do not have enough data to fit them.
أوزان أقل للضبط. إذا أدخلت متجه كلمة إلى نموذج تعلّم آلي كميزة، فمتجه بـ 300 بُعد يعني 300 وزن. ومتجه بـ 50,000 بُعد يعني 50,000 وزن، وعلى الأرجح ليس لديك بيانات كافية لملاءمتها.
- Better generalization. Dense vectors may generalize better than explicit counts, because they are forced to compress and so cannot memorize.
تعميم أفضل. قد تعمّم المتجهات الكثيفة أفضل من العدّات الصريحة، لأنها مُجبرة على الضغط فلا تستطيع الحفظ.
- They capture synonymy. This is the strongest argument, so read it slowly.
تلتقط الترادف. هذه أقوى حجة، فاقرأها ببطء.
- In practice, they work better. The slide actually says this. It is an empirical claim, not a theoretical one.
عملياً، تعمل بشكل أفضل. الشريحة تقول هذا فعلاً. إنه ادعاء تجريبي لا نظري.
The synonymy argument is worth unpacking because it is the one an exam can ask you to explain. In a sparse count vector, car and automobile are two separate dimensions. They are synonyms, but the vector has no way to know that.
حجة الترادف تستحق التفكيك لأنها الحجة التي قد يطلب منك الامتحان شرحها. في متجه العدّ المتشتّت، car وautomobile بُعدان منفصلان. هما مترادفتان، لكن المتجه لا يملك أي طريقة لمعرفة ذلك.
So take two words: one that often appears next to car, and one that often appears next to automobile. Those two words should come out similar, because they occur in the same kind of context. But in the sparse representation their non-zero entries land in different columns, so their dot product on those columns is zero and they look unrelated.
خذ إذن كلمتين: واحدة تظهر كثيراً بجانب car، وأخرى تظهر كثيراً بجانب automobile. هاتان الكلمتان يجب أن تخرجا متشابهتين، لأنهما تظهران في النوع نفسه من السياق. لكن في التمثيل المتشتّت تقع قيمهما غير الصفرية في أعمدة مختلفة، فيكون dot product بينهما على هذه الأعمدة صفراً وتبدوان غير مرتبطتين.
Dense vectors do not have one dimension per word, so there is no column to miss. The car dimension and the automobile dimension simply do not exist as separate things.
المتجهات الكثيفة ليس فيها بُعد لكل كلمة، فلا يوجد عمود يُفلت منك. بُعد car وبُعد automobile ببساطة غير موجودين كشيئين منفصلين.
Sparse versus dense, side by side
المتناثر (sparse) مقابل الكثيف (dense)، جنباً إلى جنب
| Sparse (tf-idf, PPMI)متناثر (tf-idf, PPMI) | Dense (word2vec, GloVe)كثيف (word2vec, GloVe) | |
|---|---|---|
| Length of one word vectorطول متجه الكلمة الواحدة | 20,000 to 50,000من 20,000 إلى 50,000 | 50 to 1000من 50 إلى 1000 |
| Most entries areمعظم العناصر | zeroصفر | non-zeroغير صفرية |
| What a dimension meansماذا يعني البُعد | one specific context wordكلمة سياق واحدة محددة | nothing nameableلا شيء يمكن تسميته |
| How you get itكيف تحصل عليه | count, then reweightعُدّ، ثم أعد الترجيح | train a predictorدرّب نموذجاً متنبئاً |
| Weights needed downstreamالأوزان المطلوبة في المهام اللاحقة (downstream) | tens of thousandsعشرات الآلاف | a few hundredبضع مئات |
| Handles car / automobileيتعامل مع car / automobile | no, separate dimensionsلا، بُعدان منفصلان | yesنعم |
الجدول يقارن: المتجه المتشتّت (tf-idf وPPMI) طوله من 20,000 إلى 50,000، ومعظم قيمه أصفار، وكل بُعد فيه كلمة سياق محددة، ونحصل عليه بالعدّ ثم إعادة الوزن، ويحتاج عشرات الآلاف من الأوزان لاحقاً، ولا يعالج car / automobile. والمتجه الكثيف (word2vec وGloVe) طوله من 50 إلى 1000، ومعظم قيمه غير صفرية، وأبعاده بلا معنى قابل للتسمية، ونحصل عليه بتدريب نموذج تنبؤ، ويحتاج بضع مئات من الأوزان فقط، ويعالج الترادف.
Do not mix up the two numbers. |V| = 20,000 to 50,000 is the vocabulary size, which is how long a sparse vector is. d = 50 to 1000 is the embedding dimensionality, which is how long a dense vector is. An exam question that says "a word2vec embedding typically has how many dimensions" wants a few hundred, not 50,000. The default in practice is 300, which you will meet again on slide 88.
لا تخلط بين الرقمين. |V| = 20,000 إلى 50,000 هو حجم المفردات، وهو طول المتجه المتشتّت. وd = 50 إلى 1000 هو بُعد الـ embedding، وهو طول المتجه الكثيف. فإذا سأل الامتحان "a word2vec embedding typically has how many dimensions" فهو يريد بضع مئات، لا 50,000. والقيمة الافتراضية عملياً 300، وستقابلها مجدداً في الشريحة 88.
Where short dense vectors come from
من أين تأتي المتجهات القصيرة الكثيفة
Slide 63 names the families.
تسمّي الشريحة 63 العائلات.
Neural language model inspired
مستوحاة من النماذج اللغوية العصبية (neural language model)
Word2vec, in its two flavours skip-gram and CBOW, plus GloVe. These learn vectors by training a predictor.
Word2vec بنوعيه skip-gram وCBOW، ومعه GloVe. هذه تتعلّم المتجهات بتدريب نموذج تنبؤ.
Singular Value Decomposition
تحليل القيم المفردة (Singular Value Decomposition)
Factor the big count matrix into smaller pieces. The special case applied to term-document matrices is called LSA, Latent Semantic Analysis.
فكّك مصفوفة العدّ الكبيرة إلى قطع أصغر. والحالة الخاصة المطبَّقة على مصفوفات term-document تُسمّى LSA، أي Latent Semantic Analysis.
The slide then names a third thing, and it is important that you see it as a different category, not a third method of the same kind.
ثم تذكر الشريحة شيئاً ثالثاً، ومن المهم أن تراه فئة مختلفة، لا طريقة ثالثة من النوع نفسه.
Everything above produces static embeddings. One word gets exactly one vector, forever, no matter what sentence it appears in. The word bank gets one vector that is some blurry average of the river sense and the money sense.
كل ما سبق ينتج static embeddings (تمثيلات ثابتة). كل كلمة تحصل على متجه واحد بالضبط، إلى الأبد، مهما كانت الجملة التي تظهر فيها. فكلمة bank تحصل على متجه واحد هو متوسط ضبابي لمعنى ضفة النهر ومعنى المصرف.
Contextual embeddings (ELMo, BERT) break that rule. They compute a distinct embedding for a word in its context, so there is a separate embedding for each token of a word. Two occurrences of bank in two sentences get two different vectors. That is the whole distinction the slide is drawing.
Contextual embeddings (ELMo وBERT) تكسر هذه القاعدة. فهي تحسب تمثيلاً مختلفاً للكلمة في سياقها، فيكون لكل ظهور (token) للكلمة تمثيله الخاص. ظهوران لكلمة bank في جملتين يحصلان على متجهين مختلفين. هذا هو كل التمييز الذي ترسمه الشريحة.
Slide 64 is the practical note: you do not have to train these yourself. Word2vec (Mikolov et al.) and GloVe (Pennington, Socher, Manning) are both published as downloadable pretrained vectors.
الشريحة 64 ملاحظة عملية: لا يلزمك تدريب هذه بنفسك. Word2vec (Mikolov et al.) وGloVe (Pennington, Socher, Manning) منشوران كلاهما كمتجهات مُدرَّبة مسبقاً قابلة للتنزيل.
The word2vec idea in one sentence
فكرة word2vec في جملة واحدة
Slide 65 gives the headline: word2vec is popular, very fast to train, the code is on the web, and the idea is predict rather than count. The specific variant this course cares about is skip-gram with negative sampling, abbreviated SGNS.
تعطي الشريحة 65 العنوان الرئيسي: word2vec شائع، وسريع جداً في التدريب، وكوده متاح على الويب، وفكرته تنبّأ بدل أن تعُدّ (predict rather than count). والنسخة المحددة التي تهمّ هذا المقرر هي skip-gram with negative sampling، واختصارها SGNS.
Slide 66 is where the trick becomes concrete, and it is genuinely a trick. Here is the move:
في الشريحة 66 تصبح الحيلة ملموسة، وهي حيلة فعلاً. إليك الحركة:
Instead of counting how often each word w occurs near apricot, train a classifier on a binary prediction task. The question the classifier answers is: is w likely to show up near apricot? Yes or no.
بدلاً من عدّ كم مرة تظهر كل كلمة w قرب apricot، درّب مصنِّفاً على مهمة تنبؤ ثنائية. والسؤال الذي يجيب عنه المصنِّف: هل يُرجَّح أن تظهر w قرب apricot؟ نعم أو لا.
Now the key line on the slide, which looks like a joke the first time you read it: we do not actually care about this task. We will never use the classifier. What we want is the weights it learns along the way, and those weights are the word embeddings.
والآن السطر الأهم في الشريحة، والذي يبدو كنكتة أول مرة تقرأه: نحن لا نهتم فعلاً بهذه المهمة. لن نستخدم المصنِّف أبداً. ما نريده هو الأوزان التي يتعلّمها في الطريق، وهذه الأوزان هي تمثيلات الكلمات (word embeddings).
Train the classifier, keep the weights, throw the classifier away.
درّب المصنِّف، احتفظ بالأوزان، ارمِ المصنِّف.
The yes/no task is a pretext. The vectors are the souvenir.
مهمة "نعم أو لا" مجرد ذريعة. والمتجهات هي التذكار.
Self-supervision, which is the reason this is free
الإشراف الذاتي (self-supervision)، وهو سبب أن هذا مجاني
Supervised learning normally needs labelled data, and labelled data needs humans. Slide 66 calls out why that is not a problem here.
التعلّم الموجَّه يحتاج عادةً بيانات موسومة، والبيانات الموسومة تحتاج بشراً. وتوضّح الشريحة 66 لماذا ليست هذه مشكلة هنا.
A word c that actually occurs near apricot in the corpus is the gold correct answer. The corpus labels itself. Any word sitting in the window is a yes; any random word from the lexicon is a no. No human labels required. The slide credits Bengio et al. (2003) and Collobert et al. (2011).
الكلمة c التي تظهر فعلاً قرب apricot في النص هي الجواب الصحيح الذهبي. النص يَسِم نفسه بنفسه. أي كلمة داخل النافذة جوابها نعم، وأي كلمة عشوائية من المعجم جوابها لا. لا حاجة لوسوم بشرية. وتنسب الشريحة الفكرة إلى Bengio et al. (2003) وCollobert et al. (2011).
The four-step recipe
الوصفة ذات الخطوات الأربع
Slide 67 states the whole algorithm in four lines. Memorize these four, in this order, and you can reconstruct the rest of the lecture.
تعرض الشريحة 67 الخوارزمية كلها في أربعة أسطر. احفظ هذه الأربعة بهذا الترتيب، وستستطيع إعادة بناء بقية المحاضرة.
- Treat the target word t and a neighbouring context word c as positive examples.
اعتبر الكلمة الهدف t وكلمة السياق المجاورة c أمثلة موجبة (positive examples).
- Randomly sample other words in the lexicon to get negative examples.
اسحب عشوائياً كلمات أخرى من المعجم لتحصل على أمثلة سالبة (negative examples).
- Use logistic regression to train a classifier to distinguish those two cases.
استخدم logistic regression لتدريب مصنِّف يميّز بين الحالتين.
- Use the learned weights as the embeddings.
استخدم الأوزان المُتعلَّمة بوصفها embeddings.
Where the training data comes from
من أين تأتي بيانات التدريب
Slide 68 shows the mechanism. You slide a window along real running text. With a +/- 2 word window, you take 2 words to the left and 2 words to the right of whatever word you are currently standing on.
تُظهر الشريحة 68 الآلية. تُمرِّر نافذة على نص حقيقي متصل. مع نافذة +/- 2 تأخذ كلمتين على يسار الكلمة التي تقف عليها حالياً وكلمتين على يمينها.
The slide's sentence is:
جملة الشريحة هي:
الأقواس المربّعة تحيط بالنافذة، والكلمة المميّزة في وسطها apricot هي الهدف.
Standing on apricot, the window brackets five words. The target is apricot and the four context words are labelled c1 through c4.
عندما تقف على apricot تحيط النافذة بخمس كلمات. الهدف هو apricot، وكلمات السياق الأربع موسومة من c1 إلى c4.
بيانات تدريب skip-gram، الشريحة 68. النافذة ثابتة العرض وتنزلق على النص. كل موضع تتوقف عنده ينتج هدفاً واحداً وحتى 2L كلمة سياق، وكل زوج منها يصبح مثال تدريب موجباً.
| Labelالرمز | Wordالكلمة | Position relative to targetالموقع بالنسبة للهدف | Roleالدور |
|---|---|---|---|
| c1 | tablespoon | −2 | contextسياق (context) |
| c2 | of | −1 | contextسياق (context) |
| w | apricot | 0 | targetهدف (target) |
| c3 | jam | +1 | contextسياق (context) |
| c4 | a | +2 | contextسياق (context) |
الجدول يسرد النافذة: c1 = tablespoon في الموضع -2، وc2 = of في الموضع -1، والهدف w = apricot في الموضع 0، وc3 = jam في الموضع +1، وc4 = a في الموضع +2. الأربعة كلها كلمات سياق.
What the classifier is actually asked
ما الذي يُسأل عنه المصنِّف فعلاً
Slide 69 turns the window into a question. The classifier is handed a candidate (word, context) pair and must score it. Two of the slide's own examples:
تحوّل الشريحة 69 النافذة إلى سؤال. يُعطى المصنِّف زوجاً مرشّحاً (word, context) وعليه أن يعطيه درجة. مثالان من الشريحة نفسها:
(apricot, jam) <- jam really was in the window (apricot, aardvark) <- aardvark was not, we made it up
الزوج (apricot, jam) حقيقي لأن jam كانت فعلاً في النافذة، والزوج (apricot, aardvark) مختلَق لأن aardvark لم تكن فيها.
And the classifier assigns each pair a probability:
ويعطي المصنِّف كل زوج احتمالاً:
السطر الأول P(+ | w, c) هو احتمال أن يكون الزوج جاراً حقيقياً. والسطر الثاني P(− | w, c) = 1 − P(+ | w, c) هو احتمال ألّا يكون كذلك.
Two numbers that sum to one. That is the entire output. It is a coin flip, not a vocabulary-sized decision.
رقمان مجموعهما واحد. هذا هو المُخرَج كله. إنه رمي عملة، لا قرار بحجم المفردات.
P(+|w, c) is not a distribution over the vocabulary. It does not sum to 1 across all possible context words. It sums to 1 across exactly two outcomes, + and −, for one fixed pair.
P(+|w, c) ليس توزيعاً على المفردات. مجموعه لا يساوي 1 عبر كل كلمات السياق الممكنة، بل يساوي 1 عبر نتيجتين فقط، + و−، لزوج واحد ثابت.
This matters more than it looks. A real language model would have to normalize over all |V| words, which costs a sum over 50,000 terms for every single training example. Word2vec never does that sum. That is why slide 65 can claim it is "very fast to train".
هذا أهم مما يبدو. نموذج اللغة الحقيقي يجب أن يُطبِّع على كل الكلمات الـ |V|، وهذا يكلّف مجموعاً على 50,000 حدّ لكل مثال تدريب. أما word2vec فلا يحسب هذا المجموع أبداً. ولهذا بالذات تستطيع الشريحة 65 أن تقول إنه "very fast to train"، أي سريع جداً في التدريب.
Similarity is just the dot product
التشابه هو ببساطة dot product
Slide 70 is a reminder plus one new word. The reminder: two vectors are similar if they have a high dot product, and cosine is just a normalized dot product.
الشريحة 70 تذكير مع كلمة جديدة واحدة. التذكير: يتشابه متجهان إذا كان dot product بينهما كبيراً، وcosine ليس إلا dot product مُطبَّعاً.
The new word is the proportionality sign:
والكلمة الجديدة هي علامة التناسب:
تُقرأ: التشابه بين w وc يتناسب طردياً مع w · c.
So the classifier's notion of "is c a neighbour of w" is going to be built on nothing more than w · c.
إذن مفهوم المصنِّف عن "هل c جار لـ w" سيُبنى على w · c لا أكثر.
But the slide immediately flags a problem. A dot product is an unbounded real number. It can be 0.3, it can be −17, it can be 400. A probability has to live in [0, 1]. And cosine does not rescue us either, because cosine lives in [−1, 1] and the slide says flatly that cosine is not a probability either.
لكن الشريحة تنبّه فوراً إلى مشكلة. dot product عدد حقيقي غير محدود: قد يكون 0.3، وقد يكون −17، وقد يكون 400. أما الاحتمال فيجب أن يقع في [0, 1]. وcosine لا ينقذنا أيضاً، لأنه يقع في [−1, 1]، والشريحة تقول صراحة إن cosine ليس احتمالاً هو الآخر.
Turning a dot product into a probability
تحويل dot product إلى احتمال
Slide 71 solves it with the sigmoid from logistic regression. The sigmoid takes any real number and squashes it into (0, 1), monotonically: bigger input, bigger output.
تحلّ الشريحة 71 المشكلة بالـ sigmoid من logistic regression. الـ sigmoid يأخذ أي عدد حقيقي ويضغطه إلى (0, 1) بشكل رتيب: مُدخل أكبر يعني مُخرجاً أكبر.
السطر الأول: P(+ | w, c) = σ(c · w) = 1 / (1 + e−c·w). والسطر الثاني: P(− | w, c) = 1 − P(+ | w, c) = σ(−c · w) = 1 / (1 + ec·w).
Look carefully at the second line. The negative case is not some new formula. It is the same sigmoid with the sign of the dot product flipped. That identity, σ(−x) = 1 − σ(x), is the single most useful fact on this page, because it is what lets the loss function on slide 80 be written entirely in terms of σ.
انظر جيداً إلى السطر الثاني. الحالة السالبة ليست صيغة جديدة، بل هي الـ sigmoid نفسه بعد قلب إشارة dot product. وهذه المتطابقة، σ(−x) = 1 − σ(x)، هي أكثر حقيقة مفيدة في هذه الصفحة، لأنها ما يسمح بكتابة دالة الخسارة في الشريحة 80 كاملةً بدلالة σ.
Plus takes the dot product as it is. Minus flips its sign.
الموجب يأخذ dot product كما هو، والسالب يقلب إشارته.
And for the sigmoid itself: the minus sign lives inside the exp, on the bottom. Write 1 over 1 plus exp of minus x. If you ever write exp(+x) for the positive case, your probabilities will come out backwards.
وبالنسبة للـ sigmoid نفسه: إشارة السالب تعيش داخل الـ exp، في المقام. اكتب 1 على 1 زائد exp لسالب x. وإذا كتبت يوماً exp(+x) للحالة الموجبة، فستخرج احتمالاتك معكوسة.
مصنِّف skip-gram كله في سطر واحد. متجه الهدف w يأتي من المصفوفة W، ومتجه السياق المرشّح c يأتي من المصفوفة C، وdot product يقيس مدى توافقهما، والـ sigmoid يحوّل هذا العدد غير المحدود إلى احتمال نعم أو لا. والأرقام مأخوذة من المثال المحلول أدناه.
Illustrative vectors, d = 3, chosen so the arithmetic is clean. The slide gives no numbers of its own here.
متجهات توضيحية، d = 3، مختارة لتكون الحسابات نظيفة. الشريحة لا تعطي أرقاماً خاصة بها هنا.
w(apricot) = [ 0.5, 1.0, -0.5]
c(jam) = [ 1.0, 1.0, 0.0] a real neighbour
c(aardvark) = [-2.0, 0.0, 2.0] a random word
DOT PRODUCT, POSITIVE PAIR
0.5 x 1.0 = 0.5
1.0 x 1.0 = 1.0
-0.5 x 0.0 = 0.0
c(jam) . w = 0.5 + 1.0 + 0.0 = 1.5
SIGMOID
exp(-1.5) = 0.2231
1 + 0.2231 = 1.2231
P(+|apricot, jam) = 1 / 1.2231 = 0.8176
P(-|apricot, jam) = 1 - 0.8176 = 0.1824
cross-check with the flipped-sign form:
sigma(-1.5) = 1 / (1 + exp(1.5)) = 1 / (1 + 4.4817)
= 1 / 5.4817 = 0.1824 matches
DOT PRODUCT, NEGATIVE PAIR
0.5 x -2.0 = -1.0
1.0 x 0.0 = 0.0
-0.5 x 2.0 = -1.0
c(aardvark) . w = -1.0 + 0.0 - 1.0 = -2.0
SIGMOID
exp(2.0) = 7.3891
1 + 7.3891 = 8.3891
P(+|apricot, aardvark) = 1 / 8.3891 = 0.1192
P(-|apricot, aardvark) = 1 - 0.1192 = 0.8808
خطوات الحل: للزوج الحقيقي c(jam) · w = 0.5 + 1.0 + 0.0 = 1.5، ثم σ(1.5) = 1 / (1 + 0.2231) = 0.8176، فيكون P(+) = 0.8176 وP(−) = 0.1824، وهذا يطابق σ(−1.5). وللزوج العشوائي c(aardvark) · w = −1.0 + 0.0 − 1.0 = −2.0، ثم P(+) = 1 / (1 + 7.3891) = 0.1192 وP(−) = 0.8808.
Read the result, not just the digits. The real neighbour got 0.82 for "yes" and the random word got 0.12. That gap is the only thing the classifier knows how to do, and the next page is entirely about widening it.
اقرأ النتيجة، لا الأرقام فقط. الجار الحقيقي حصل على 0.82 لـ "نعم"، والكلمة العشوائية حصلت على 0.12. هذه الفجوة هي الشيء الوحيد الذي يعرف المصنِّف فعله، والصفحة التالية كلها عن توسيعها.
But there are four context words, not one
لكن هناك أربع كلمات سياق، لا واحدة
Slide 72 points out the gap. σ(c · w) scores one context word. The window has L of them (four, in the running example).
تشير الشريحة 72 إلى الثغرة. σ(c · w) يعطي درجة لكلمة سياق واحدة، بينما في النافذة L كلمة (أربع في المثال الجاري).
The slide's fix is the simplest possible one: assume independence and multiply.
وعلاج الشريحة أبسط ما يمكن: افترض الاستقلال واضرب.
السطر الأول: احتمال أن تكون كل كلمات السياق من c1 إلى cL جيراناً حقيقيين هو حاصل ضرب σ(ci · w) لكل i من 1 إلى L. والسطر الثاني: لوغاريتم ذلك هو مجموع log σ(ci · w).
The second line is the first line with a log taken on both sides. Logs turn products into sums, which is why every loss function you will see from here on is a sum and not a product. Nothing new is being assumed in the second line.
السطر الثاني هو السطر الأول بعد أخذ اللوغاريتم للطرفين. اللوغاريتمات تحوّل حواصل الضرب إلى مجاميع، ولهذا كل دالة خسارة ستراها من الآن فصاعداً مجموع لا حاصل ضرب. لا يُفترض أي شيء جديد في السطر الثاني.
Two context words, continuing the illustrative numbers above. Say c(of) · w = 0.8.
كلمتا سياق، استكمالاً للأرقام التوضيحية أعلاه. لنفترض أن c(of) · w = 0.8.
sigma(1.5) = 0.8176 (computed above, for jam)
sigma(0.8):
exp(-0.8) = 0.4493
1 + 0.4493 = 1.4493
sigma(0.8) = 1 / 1.4493 = 0.6900
PRODUCT FORM
P(+|w, {jam, of}) = 0.8176 x 0.6900 = 0.5641
LOG FORM, same answer
ln(0.8176) = -0.2014
ln(0.6900) = -0.3713
sum = -0.5727
exp(-0.5727) = 0.5641 matches the product form
خطوات الحل: σ(1.5) = 0.8176 من الحساب السابق لـ jam، وσ(0.8) = 1 / 1.4493 = 0.6900. بصيغة الضرب: 0.8176 × 0.6900 = 0.5641. وبصيغة اللوغاريتم: ln(0.8176) + ln(0.6900) = −0.2014 − 0.3713 = −0.5727، وexp(−0.5727) = 0.5641، أي الجواب نفسه.
Notice the product of two healthy probabilities is already down to 0.56. With a window of 10 context words this number becomes tiny, which is exactly why the training code works in log space.
لاحظ أن حاصل ضرب احتمالين جيدين نزل بالفعل إلى 0.56. ومع نافذة من 10 كلمات سياق يصبح هذا الرقم ضئيلاً جداً، ولهذا بالضبط يعمل كود التدريب في فضاء اللوغاريتم.
Slide 73 in one breath
الشريحة 73 في نفَس واحد
The skip-gram classifier is a probabilistic classifier. Give it a test target word w and its context window of L words c1:L, and it estimates the probability that w occurs in this window, based on the similarity of w's embedding to the embeddings of c1:L.
مصنِّف skip-gram مصنِّف احتمالي. أعطه كلمة هدف اختبارية w ونافذة سياقها من L كلمة c1:L، فيقدّر احتمال أن تظهر w في هذه النافذة، بناءً على تشابه تمثيل w مع تمثيلات c1:L.
And then the line that sets up the entire next page: to compute this, we just need embeddings for all the words. There is no other parameter. No hidden layer, no weight matrix beyond the embeddings themselves. The embeddings are the model.
ثم السطر الذي يمهّد للصفحة التالية كلها: لحساب هذا نحتاج فقط إلى embeddings لكل الكلمات. لا يوجد أي معامل آخر. لا طبقة مخفية، ولا مصفوفة أوزان غير الـ embeddings نفسها. الـ embeddings هي النموذج.
Two sets of embeddings, not one
مجموعتان من الـ embeddings، لا واحدة
Slide 74 is the one that trips people up, so here it is slowly.
الشريحة 74 هي التي يتعثّر فيها الناس، فإليك شرحها ببطء.
Every word plays two roles in training. Sometimes it is the target in the middle of the window. Sometimes it is a context word sitting beside somebody else's target. Word2vec gives it a separate vector for each role.
كل كلمة تلعب دورين في التدريب. أحياناً تكون الهدف في وسط النافذة، وأحياناً تكون كلمة سياق بجانب هدف كلمة أخرى. وword2vec يعطيها متجهاً منفصلاً لكل دور.
- W is the matrix of target embeddings. Rows 1 through |V|.
W هي مصفوفة تمثيلات الهدف (target). الصفوف من 1 إلى |V|.
- C is the matrix of context and noise embeddings. Rows |V|+1 through 2V.
C هي مصفوفة تمثيلات السياق والضوضاء (context and noise). الصفوف من |V|+1 إلى 2V.
Both matrices have one row per vocabulary word and d columns. Stacked together they form θ, the full parameter vector of the model, which therefore has 2V rows of width d.
كلتا المصفوفتين فيها صف لكل كلمة في المفردات وd عمود. وعند تكديسهما معاً تشكّلان θ، متجه المعاملات الكامل للنموذج، والذي يكون فيه إذن 2V صف بعرض d.
الشريحة 74. كل كلمة في المفردات تظهر مرتين في θ، مرة في W ومرة في C. وapricot كهدف وapricot ككلمة سياق متجهان مختلفان بـ d بُعد، ويُحدَّث كل منهما بتدرّجات مختلفة.
W and C are not the same matrix and they are not transposes of each other. They are two independent sets of parameters that happen to be indexed by the same vocabulary. The row for apricot in W and the row for apricot in C hold different numbers and are updated by different gradient terms.
W وC ليستا المصفوفة نفسها، وليست إحداهما منقول (transpose) الأخرى. إنهما مجموعتان مستقلتان من المعاملات تصادف أنهما مفهرستان بالمفردات نفسها. صف apricot في W وصف apricot في C يحملان أرقاماً مختلفة ويُحدَّثان بحدود تدرّج مختلفة.
What you do with C at the end is decided on slide 86, not here. Hold the question.
ما تفعله بـ C في النهاية يُحسم في الشريحة 86، لا هنا. احتفظ بالسؤال.
Thirty-second recap
خلاصة في ثلاثين ثانية
Check yourself
اختبر نفسك
Slide 62 argues that dense vectors capture synonymy better. What exactly is the problem with sparse vectors that it is pointing at?
تجادل الشريحة 62 بأن المتجهات الكثيفة تلتقط الترادف أفضل. ما المشكلة بالضبط في المتجهات المتشتّتة التي تشير إليها؟
This is the slide's own example, almost verbatim. The two synonyms occupy different columns, so evidence for one never adds to evidence for the other, and two words that are genuinely distributionally alike score zero on those columns. D is the tempting distractor because length is one of the slide's complaints, but it is listed as a separate problem about ease of use in machine learning, not as the reason synonymy fails.
الجواب C. هذا مثال الشريحة نفسها تقريباً بحرفه. المترادفتان تشغلان عمودين مختلفين، فالدليل على إحداهما لا يُضاف أبداً إلى الدليل على الأخرى، وكلمتان متشابهتان توزيعياً بحق تحصلان على صفر في هذه الأعمدة. والخيار D هو المشتِّت المغري لأن الطول هو أحد اعتراضات الشريحة، لكنه مذكور كمشكلة منفصلة تخص سهولة الاستخدام في التعلّم الآلي، لا كسبب لفشل الترادف.
Slide 66 says "we don't actually care about this task". Which task, and why not?
تقول الشريحة 66 "we don't actually care about this task". أيّ مهمة، ولماذا لا نهتم بها؟
The pretext is the binary neighbour-prediction task. We train it, then discard the classifier and keep the weights (slide 87 even says "throw away the classifier code and keep the embeddings"). D is tempting because self-supervision is on the same slide, but self-supervision explains where the labels come from, not which task we stop caring about.
الجواب B. الذريعة هي مهمة التنبؤ الثنائي بالجار. ندرّبها، ثم نرمي المصنِّف ونحتفظ بالأوزان (والشريحة 87 تقول حتى "throw away the classifier code and keep the embeddings"). والخيار D مغرٍ لأن الإشراف الذاتي (self-supervision) في الشريحة نفسها، لكن الإشراف الذاتي يفسّر من أين تأتي الوسوم، لا أيّ مهمة نتوقف عن الاهتمام بها.
A target vector w and a context vector c have c · w = 0. What is P(+|w, c)?
متجه هدف w ومتجه سياق c لهما c · w = 0. ما قيمة P(+|w, c)؟
σ(0) = 1/(1 + exp(0)) = 1/(1 + 1) = 1/2. A dot product of zero means the two vectors are orthogonal, so the classifier has no evidence either way and sits exactly on the fence. A is the trap: a dot product of 0 is the middle of the sigmoid's input range, not the bottom. To push P(+) toward 0 you need a large negative dot product.
الجواب D. σ(0) = 1/(1 + exp(0)) = 1/(1 + 1) = 1/2. dot product يساوي صفراً يعني أن المتجهين متعامدان، فلا يملك المصنِّف دليلاً في أي اتجاه ويقف تماماً على الحياد. والخيار A هو الفخ: dot product يساوي 0 هو منتصف مدى مُدخلات الـ sigmoid، لا أسفله. ولكي تدفع P(+) نحو 0 تحتاج dot product سالباً كبيراً.
Why is it fair to say the skip-gram classifier is fast, compared with a neural language model that predicts the next word?
لماذا يصحّ القول إن مصنِّف skip-gram سريع، مقارنةً بنموذج لغة عصبي يتنبأ بالكلمة التالية؟
The binary framing is the whole trick. A softmax over |V| would need a sum over 20,000 to 50,000 terms per training example; σ(c · w) needs one dot product and one exponential. B is backwards, since word2vec produces dense vectors, and D is simply false, as the sigmoid is the core of the model and is also cheap.
الجواب A. الصياغة الثنائية هي الحيلة كلها. softmax على |V| يحتاج مجموعاً على 20,000 إلى 50,000 حدّ لكل مثال تدريب، بينما σ(c · w) يحتاج dot product واحداً ودالة أسية واحدة. والخيار B معكوس لأن word2vec ينتج متجهات كثيفة، والخيار D خاطئ ببساطة، فالـ sigmoid قلب النموذج وهو رخيص أيضاً.
For the sentence "…lemon, a [tablespoon of apricot jam, a] pinch…" with a +/- 2 window and apricot as target, which set is the correct list of positive context words?
في الجملة "…lemon, a [tablespoon of apricot jam, a] pinch…" مع نافذة +/- 2 وapricot هدفاً، أيّ مجموعة هي القائمة الصحيحة لكلمات السياق الموجبة؟
A +/- 2 window takes the two words to the left (tablespoon, of) and the two to the right (jam, a). C is only +/- 1. D wrongly includes the target itself, which is never its own context word. A reaches outside the bracket on the left and past it on the right.
الجواب B. نافذة +/- 2 تأخذ الكلمتين على اليسار (tablespoon, of) والكلمتين على اليمين (jam, a). والخيار C نافذة +/- 1 فقط. والخيار D يُدخل الهدف نفسه خطأً، والهدف لا يكون أبداً كلمة سياق لنفسه. والخيار A يخرج عن القوس من اليسار ويتجاوزه من اليمين.
Slide 74 shows θ as a stack of two blocks. What is in the lower block, C?
تُظهر الشريحة 74 θ كتكديس لكتلتين. ماذا في الكتلة السفلى C؟
C holds genuinely separate parameters, rows |V|+1 through 2V of θ, used whenever a word appears as a candidate neighbour rather than as the target. A is the most tempting wrong answer, and it is wrong twice over: C is not derived from W at all, and the two matrices are updated by different gradient terms during training.
الجواب C. المصفوفة C تحمل معاملات منفصلة فعلاً، هي الصفوف من |V|+1 إلى 2V في θ، وتُستخدم كلما ظهرت كلمة كجار مرشّح لا كهدف. والخيار A هو الجواب الخاطئ الأكثر إغراءً، وهو خاطئ مرتين: C ليست مشتقة من W إطلاقاً، والمصفوفتان تُحدَّثان بحدود تدرّج مختلفة أثناء التدريب.
Slide 63 separates "static embeddings" from a different category. What is the defining property of that other category?
تفصل الشريحة 63 "static embeddings" عن فئة مختلفة. ما الخاصية المحدِّدة لتلك الفئة الأخرى؟
Contextual embeddings (ELMo, BERT) compute a distinct embedding for a word in its context, giving separate vectors for each token. Static embeddings give one vector per word type forever. C is the trap, because word2vec and GloVe are exactly the ones you download (slide 64), so downloadability describes static embeddings, not contextual ones.
الجواب D. Contextual embeddings (ELMo وBERT) تحسب تمثيلاً مختلفاً للكلمة في سياقها، فتعطي متجهاً منفصلاً لكل ظهور (token). أما static embeddings فتعطي متجهاً واحداً لكل نوع كلمة إلى الأبد. والخيار C هو الفخ، لأن word2vec وGloVe هما بالضبط ما تنزّله (الشريحة 64)، فقابلية التنزيل تصف التمثيلات الثابتة لا السياقية.