Majid Al-RaimiSelf-supervised training: cross-entropy and teacher forcingالتدريب الذاتي الإشراف: الإنتروبيا المتقاطعة والتغذية القسرية

ICS 582Lecture 06المحاضرة 06Part 04الجزء 04

Self-supervised training: cross-entropy and teacher forcingالتدريب الذاتي الإشراف: الإنتروبيا المتقاطعة والتغذية القسرية

How a language model learns from raw text by predicting the next word, why the cross-entropy loss collapses to minus log of the true word's probability, and why training feeds the gold word instead of the model's guess.كيف يتعلم نموذج اللغة من النص الخام بالتنبؤ بالكلمة التالية، ولماذا تختزل خسارة الإنتروبيا المتقاطعة إلى سالب لوغاريتم احتمال الكلمة الصحيحة، ولماذا يغذي التدريب الكلمة الصحيحة (gold) بدلا من تخمين النموذج (teacher forcing).

Conceptsالمفاهيم
3
Slidesالشرائح
19-22
Readingمدة القراءة
18 min18 دقيقة
Understoodما فهمته
0/3 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

Part 3 built an RNN language model that turns a history into a probability distribution over the next word. Untrained, its weights are random and its predictions are noise. This part answers the question the rest of the lecture depends on: where does the training signal come from, and how exactly is the model punished for a bad guess?

The answer has three pieces that fit together. The data labels itself, because the next word of real text is the target. The punishment is the cross-entropy loss, which for a one-hot target is just minus the log probability given to the true word. And during training the model is always fed the true history, a scheme called teacher forcing. The same three ideas train every transformer later in this lecture, so expect them on the exam as a derivation, a calculation and a definition.

بنى الجزء 3 نموذج لغة من نوع RNN يحوّل التاريخ (السياق السابق) إلى توزيع احتمالي على الكلمة التالية. قبل التدريب تكون أوزانه عشوائية وتنبؤاته مجرد ضجيج. هذا الجزء يجيب عن السؤال الذي يعتمد عليه بقية المحاضرة: من أين تأتي إشارة التدريب، وكيف بالضبط يُعاقَب النموذج على التخمين السيئ؟

للإجابة ثلاث قطع تتكامل معًا. البيانات تسمّي نفسها بنفسها، لأن الكلمة التالية في النص الحقيقي هي الهدف. والعقاب هو خسارة الإنتروبيا المتقاطعة (cross-entropy loss)، وهي مع هدف one-hot مجرد سالب لوغاريتم الاحتمال المعطى للكلمة الصحيحة. وأثناء التدريب يُغذّى النموذج دائمًا بالتاريخ الصحيح، وهي طريقة تسمى teacher forcing. هذه الأفكار الثلاث نفسها تدرّب كل transformer لاحقًا في هذه المحاضرة، فتوقّعها في الاختبار على شكل استنتاج، وعملية حسابية، وتعريف.

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Explain why next-word prediction on raw text counts as self-supervised training, with no human labels.اشرح لماذا يُعدّ التنبؤ بالكلمة التالية على نص خام تدريبًا ذاتي الإشراف (self-supervised) لا يحتاج إلى أي تسميات بشرية.
  2. Derive why the cross-entropy loss with a one-hot target collapses to minus the log probability of the true next word.استنتج لماذا تختزل خسارة الإنتروبيا المتقاطعة (cross-entropy) مع هدف one-hot إلى سالب لوغاريتم احتمال الكلمة التالية الصحيحة.
  3. Compute the loss for a given predicted distribution, and the average loss and perplexity for a short sequence.احسب الخسارة لتوزيع متنبأ به معطى، واحسب متوسط الخسارة والـ perplexity لتسلسل قصير.
  4. Define teacher forcing, say why it is used, and name its known downside, exposure bias.عرّف teacher forcing، واذكر سبب استخدامه، وسمِّ عيبه المعروف: exposure bias.

Take the sentence “so long and thanks for all the fish”. Without asking any annotator, you can already write down one training example for every word after the first: after so the answer is long, after so long it is and, after so long and it is thanks, and so on. The sentence is both the question and the answer key.

خذ الجملة «so long and thanks for all the fish». من دون أن تسأل أي مُعلِّق بشري، تستطيع أن تكتب مثال تدريب واحدًا لكل كلمة بعد الأولى: بعد so الإجابة هي long، وبعد so long هي and، وبعد so long and هي thanks، وهكذا. الجملة هي السؤال ومفتاح الإجابة في الوقت نفسه.

Shift the text one position: each input word points at its own target, the next wordأزِح النص موضعًا واحدًا: كل كلمة مُدخلة تشير إلى هدفها الخاص، وهو الكلمة التالية

The training algorithm in two linesخوارزمية التدريب في سطرين

This is why a Neural language model is trained by Self-supervised training. The algorithm on the slide is short because the idea is short:

لهذا السبب يُدرَّب neural language model بطريقة self-supervised training. الخوارزمية في الشريحة قصيرة لأن الفكرة نفسها قصيرة:

  1. Take a corpus of raw text.خذ corpus من النص الخام.
  2. At each time step t, ask the model for a distribution over the next word, compare it with the word that actually comes next, and use gradient descent to reduce the prediction error.عند كل خطوة زمنية t، اطلب من النموذج توزيعًا على الكلمة التالية، وقارنه بالكلمة التي تأتي فعلًا بعدها، واستخدم gradient descent لتقليل خطأ التنبؤ.

Nothing in this loop needs a human. In supervised sentiment classification someone must tag each review as positive or negative. Here the “label” at position t is the token at position t+1, so every sentence ever written is free training data. That is the economic reason language models can be trained on billions of words.

لا شيء في هذه الحلقة يحتاج إلى إنسان. في تصنيف المشاعر الخاضع للإشراف (supervised) يجب أن يوسم شخصٌ ما كل مراجعة بأنها إيجابية أو سلبية. أما هنا فإن «التسمية» عند الموضع t هي الـ token عند الموضع t+1، لذلك كل جملة كُتبت في التاريخ هي بيانات تدريب مجانية. وهذا هو السبب الاقتصادي الذي يجعل تدريب نماذج اللغة على مليارات الكلمات ممكنًا.

Compare this with the Count-based (n-gram) language model of lecture 3. An n-gram model is “trained” by counting and normalizing, which has a closed-form answer. A neural model has millions of weights inside a Recurrent neural network (RNN) and a Softmax, and no formula gives the best weights directly. So we need a single number that says how wrong the model is, and then we follow its gradient downhill. That number is the loss in the next concept.

قارن هذا بـ count-based (n-gram) language model في المحاضرة 3. نموذج الـ n-gram «يُدرَّب» بالعدّ ثم التطبيع (normalizing)، ولذلك له حل بصيغة مغلقة (closed-form). أما النموذج العصبي فلديه ملايين الأوزان داخل RNN وsoftmax، ولا توجد معادلة تعطي أفضل الأوزان مباشرة. لذلك نحتاج إلى رقم واحد يقول مدى خطأ النموذج، ثم نتبع تدرّجه (gradient) نزولًا. هذا الرقم هو الخسارة في المفهوم التالي.

Recall

Why is next-word prediction called self-supervised, and what is the target at position t?لماذا يسمى التنبؤ بالكلمة التالية ذاتي الإشراف (self-supervised)، وما الهدف عند الموضع t؟

The targets come from the text itself, so no human labels are needed. At position t the target is the next token of the same sequence, w_(t+1).
الأهداف تأتي من النص نفسه، لذلك لا حاجة إلى تسميات بشرية. عند الموضع t يكون الهدف هو الـ token التالي من التسلسل نفسه، w_(t+1).

Shrink the vocabulary to four words, {so, long, and, thanks}. The model has just read so and outputs ŷ = [0.1, 0.6, 0.2, 0.1]. The true next word is long. How bad was this guess, as a single number?

صغّر المفردات إلى أربع كلمات، {so, long, and, thanks}. النموذج قرأ للتو so وأخرج ŷ = [0.1, 0.6, 0.2, 0.1]. الكلمة التالية الصحيحة هي long. ما مدى سوء هذا التخمين، معبَّرًا عنه برقم واحد؟

What a good loss must doما الذي يجب أن تفعله الخسارة الجيدة

Slide 20 lists the requirements in plain words. We want the model to put high probability on the true word w. The loss should therefore be small when that probability is high and large when it is low, and training should move the weights to raise the probability of the true word. The loss that does this is the same one you met for logistic regression and skip-gram in lecture 4: the Cross-entropy loss.

الشريحة 20 تسرد المتطلبات بكلمات بسيطة. نريد من النموذج أن يضع احتمالًا عاليًا على الكلمة الصحيحة w. لذلك يجب أن تكون الخسارة صغيرة عندما يكون ذلك الاحتمال عاليًا وكبيرة عندما يكون منخفضًا، ويجب أن يحرّك التدريب الأوزان لرفع احتمال الكلمة الصحيحة. الخسارة التي تحقق ذلك هي نفسها التي رأيتها مع logistic regression وskip-gram في المحاضرة 4: cross-entropy loss.

From the full sum to one termمن المجموع الكامل إلى حد واحد

Cross-entropy measures the gap between two distributions: the correct one y_t and the predicted one ŷ_t that the softmax produced. Written out over the whole vocabulary V:

تقيس الإنتروبيا المتقاطعة الفجوة بين توزيعين: التوزيع الصحيح y_t والتوزيع المتنبأ به ŷ_t الذي أنتجه الـ softmax. وعند كتابتها على كامل المفردات V:

LCE(y^t,yt)=−∑w∈Vyt[w] log⁡y^t[w]L_{CE}(\hat{y}_t, y_t) = -\sum_{w \in V} y_t[w]\,\log \hat{y}_t[w]
Cross-entropy at step tالإنتروبيا المتقاطعة عند الخطوة t

The correct distribution is one-hot. It puts 1 on the word that really comes next and 0 on every other word. Multiply anything by 0 and it disappears, so every term in the sum vanishes except the one for the true word, where the factor is 1:

التوزيع الصحيح من نوع one-hot. فهو يضع 1 على الكلمة التي تأتي فعلًا بعدها ويضع 0 على كل كلمة أخرى. أي شيء يُضرب في 0 يختفي، لذلك تتلاشى كل حدود المجموع ما عدا حد الكلمة الصحيحة، حيث يكون المعامل 1:

LCE=−(0⋅log⁡0.1+1⋅log⁡0.6+0⋅log⁡0.2+0⋅log⁡0.1)=−log⁡y^t[wt+1]L_{CE} = -\big(0\cdot\log 0.1 + 1\cdot\log 0.6 + 0\cdot\log 0.2 + 0\cdot\log 0.1\big) = -\log \hat{y}_t[w_{t+1}]
The one-hot target kills every term except the true wordالهدف one-hot يلغي كل الحدود عدا حد الكلمة الصحيحة
Multiply ŷ by the one-hot y: three terms become zero, only the true word's -log 0.6 = 0.511 survivesاضرب ŷ في y من نوع one-hot: ثلاثة حدود تصبح صفرًا، ولا يبقى إلا حد الكلمة الصحيحة -log 0.6 = 0.511

Worked exampleمثال محلول

Loss for one predictionالخسارة لتنبؤ واحد

  1. Read off the true word's probabilityاقرأ احتمال الكلمة الصحيحة

    The true next word is long, and ŷ[long] = 0.6.
    الكلمة التالية الصحيحة هي long، وŷ[long] = 0.6.
  2. Take minus the natural logخذ سالب اللوغاريتم الطبيعي

    L = -ln 0.6 = 0.511 nats.
    L = -ln 0.6 = 0.511 nats.
  3. Compare with a bad modelقارن بنموذج سيئ

    If the model had given long only 0.05, then L = -ln 0.05 = 3.00 nats, almost six times larger.
    لو أعطى النموذج long احتمال 0.05 فقط، لكانت L = -ln 0.05 = 3.00 nats، أي أكبر بنحو ستة أضعاف تقريبًا.
  4. Compare with a perfect modelقارن بنموذج مثالي

    If ŷ[long] = 1, then L = -ln 1 = 0. Zero is the floor; the loss can never be negative.
    إذا كانت ŷ[long] = 1، فإن L = -ln 1 = 0. الصفر هو الحد الأدنى، ولا يمكن أن تكون الخسارة سالبة أبدًا.
  5. Resultالنتيجة

    0.6 → 0.511, 0.05 → 3.00, 1 → 0. The loss rises gently at first and then sharply as the true word's probability falls toward 0.
    0.6 → 0.511، 0.05 → 3.00، 1 → 0. ترتفع الخسارة ببطء في البداية ثم بحدة كلما اقترب احتمال الكلمة الصحيحة من 0.
SimulatorمحاكيDrag the probability of the true next wordاسحب احتمال الكلمة التالية الصحيحة
p(long)
0.60
so0.100
long0.600
and0.200
thanks0.100
Loss -ln p0.511nats
Loss -log2 p0.737bits
exp(loss)1.67perplexity if every word scored like thisالحيرة (perplexity) لو حصلت كل كلمة على هذه الدرجة

Drag the slider and watch the shape of -ln p. Between 0.6 and 1 the curve is almost flat, so a model that is already right gains little from becoming more confident. Below about 0.1 the curve climbs steeply, so a confident miss is punished hard. That asymmetry is exactly what pushes the model to never give the true word a near-zero probability.

اسحب المؤشر وراقب شكل -ln p. بين 0.6 و1 يكون المنحنى شبه مسطح، لذلك فإن النموذج المصيب أصلًا لا يكسب الكثير من زيادة ثقته. وتحت 0.1 تقريبًا يصعد المنحنى بحدة، لذلك يُعاقَب الخطأ الواثق بشدة. هذا اللاتماثل هو بالضبط ما يدفع النموذج إلى ألا يعطي الكلمة الصحيحة احتمالًا قريبًا من الصفر أبدًا.

From one word to a whole sequenceمن كلمة واحدة إلى تسلسل كامل

A training sentence gives one loss per position. The figure on slide 14 (and again on slide 42 for transformers) sums the per-step losses and divides by the length T, so the sequence loss is the average:

جملة التدريب الواحدة تعطي خسارة واحدة لكل موضع. الشكل في الشريحة 14 (ومرة أخرى في الشريحة 42 مع الـ transformers) يجمع خسائر الخطوات ويقسمها على الطول T، لذلك تكون خسارة التسلسل هي المتوسط:

L=1T∑t=1TLCE,t=−1T∑t=1Tlog⁡y^t[wt+1]L = \frac{1}{T}\sum_{t=1}^{T} L_{CE,t} = -\frac{1}{T}\sum_{t=1}^{T}\log \hat{y}_t[w_{t+1}]
Average cross-entropy over a sequence of length Tمتوسط الإنتروبيا المتقاطعة على تسلسل طوله T
Input w_tالمُدخل w_tTarget w_(t+1)الهدف w_(t+1)ŷ_t[target]ŷ_t[الهدف]-ln ŷ (nats)-ln ŷ (nats)
sosolonglong0.60.60.5110.511
longlongandand0.50.50.6930.693
andandthanksthanks0.20.21.6091.609
thanksthanksforfor0.40.40.9160.916
forforallall0.80.80.2230.223
Per-step losses for the input so long and thanks for (illustrative probabilities)خسائر كل خطوة للمُدخل so long and thanks for (احتمالات توضيحية)

Worked exampleمثال محلول

Average loss and perplexityمتوسط الخسارة والـ perplexity

  1. Sum the per-step lossesاجمع خسائر الخطوات

    0.511 + 0.693 + 1.609 + 0.916 + 0.223 = 3.953
    0.511 + 0.693 + 1.609 + 0.916 + 0.223 = 3.953
  2. Divide by T = 5اقسم على T = 5

    L = 3.953 / 5 = 0.791 nats per word.
    L = 3.953 / 5 = 0.791 nats لكل كلمة.
  3. Exponentiate to get perplexityطبّق الدالة الأسية لتحصل على الـ perplexity

    PP = e^0.791 ≈ 2.20. A single step with loss 0.511 alone would give e^0.511 ≈ 1.67, which is just 1 / 0.6.
    PP = e^0.791 ≈ 2.20. أما خطوة واحدة بخسارة 0.511 وحدها فكانت ستعطي e^0.511 ≈ 1.67، وهو ببساطة 1 / 0.6.
  4. Resultالنتيجة

    Minimizing average cross-entropy is the same as minimizing perplexity, the metric from lecture 3, because PP = exp(average CE) is increasing in the loss.
    تقليل متوسط الإنتروبيا المتقاطعة هو نفسه تقليل الـ perplexity، المقياس من المحاضرة 3، لأن PP = exp(average CE) دالة متزايدة في الخسارة.

Recall

Starting from the full cross-entropy sum, why does the next-word loss reduce to -log ŷ_t[w_(t+1)]?انطلاقًا من مجموع الإنتروبيا المتقاطعة الكامل، لماذا تختزل خسارة الكلمة التالية إلى -log ŷ_t[w_(t+1)]؟

The gold distribution y_t is one-hot: 1 for the true next word and 0 for every other word. Each term y_t[w] log ŷ_t[w] with y_t[w] = 0 is zero, leaving only -1 · log ŷ_t[w_(t+1)].
التوزيع الصحيح (gold) y_t من نوع one-hot: 1 للكلمة التالية الصحيحة و0 لكل كلمة أخرى. كل حد y_t[w] log ŷ_t[w] فيه y_t[w] = 0 يساوي صفرًا، فلا يبقى إلا -1 · log ŷ_t[w_(t+1)].

Recall

A model gives the true word probability 0.1. What is the loss in nats, and what would it be for 0.9?نموذج يعطي الكلمة الصحيحة احتمال 0.1. كم تساوي الخسارة بوحدة nats، وكم ستكون لو كان الاحتمال 0.9؟

-ln 0.1 = 2.303 nats, and -ln 0.9 = 0.105 nats.
-ln 0.1 = 2.303 nats، و-ln 0.9 = 0.105 nats.

Quick checkاختبار سريع

A model assigns probability 0.25 to the correct next word. What is its cross-entropy loss in nats?نموذج يعطي الكلمة التالية الصحيحة احتمال 0.25. كم تساوي خسارة الإنتروبيا المتقاطعة (cross-entropy) بوحدة nats؟

Quick checkاختبار سريع

Why does the cross-entropy sum over the whole vocabulary reduce to a single term?لماذا يختزل مجموع الإنتروبيا المتقاطعة على كامل المفردات إلى حد واحد؟

Back to “so long and thanks”. At step 2 the model has read so long and predicts the instead of and. It pays its loss, -log ŷ[and]. Now, what should it read at step 3: its own mistaken the, or the real word and?

لنعد إلى «so long and thanks». عند الخطوة 2 قرأ النموذج so long وتنبأ بـ the بدلًا من and. يدفع خسارته، -log ŷ[and]. والآن، ماذا يجب أن يقرأ عند الخطوة 3: كلمته الخاطئة the، أم الكلمة الحقيقية and؟

The ruleالقاعدة

Teacher forcing answers: always the real word. At each position t the model sees the correct tokens w_(1:t), computes the loss -log ŷ_t[w_(t+1)] for the next token, and then, at position t+1, its own prediction is ignored. The gold word w_(t+1) is added to the context and training moves on. In an RNN this means the input at each step is the true word, combined with the Hidden state that summarizes the true history so far.

يجيب teacher forcing: دائمًا الكلمة الحقيقية. عند كل موضع t يرى النموذج الـ tokens الصحيحة w_(1:t)، ويحسب الخسارة -log ŷ_t[w_(t+1)] للـ token التالي، ثم عند الموضع t+1 يُتجاهَل تنبؤه هو. تُضاف الكلمة الصحيحة (gold) w_(t+1) إلى السياق ويمضي التدريب. في الـ RNN يعني هذا أن المُدخل عند كل خطوة هو الكلمة الحقيقية، مع hidden state الذي يلخّص التاريخ الحقيقي حتى تلك اللحظة.

Top: one wrong guess, but the next input is still the gold word. Bottom: the wrong guess is fed back and the sentence driftsفي الأعلى: تخمين خاطئ واحد، لكن المُدخل التالي يبقى الكلمة الصحيحة (gold). في الأسفل: يُعاد التخمين الخاطئ كمُدخل فتنحرف الجملة
Teacher forcingTeacher forcingFree runningالتشغيل الحر (free running)
Input at step t+1المُدخل عند الخطوة t+1The gold word w_(t+1) from the training textالكلمة الصحيحة (gold) w_(t+1) من نص التدريبThe model's own sampled or argmax wordالكلمة التي اختارها النموذج نفسه بأخذ عيّنة (sampled) أو بالـ argmax
When it is usedمتى يُستخدمTrainingأثناء التدريبInference (generation), or training variants such as scheduled samplingوقت الاستدلال (التوليد)، أو في صيغ تدريب معدّلة مثل scheduled sampling
Effect of one mistakeأثر خطأ واحدContained: the next step still sees the true historyمحصور: الخطوة التالية ما زالت ترى التاريخ الحقيقيCompounds: later steps condition on the wrong wordيتراكم: الخطوات اللاحقة تعتمد على الكلمة الخاطئة
Targets known in advanceهل الأهداف معروفة مسبقًاYes, every input and target is fixed by the textنعم، كل مُدخل وكل هدف يحدده النصNo, each input depends on the previous outputلا، كل مُدخل يعتمد على المُخرج السابق
Teacher forcing during training versus free running during generationTeacher forcing أثناء التدريب مقابل التشغيل الحر (free running) أثناء التوليد

Why train this wayلماذا نتدرب بهذه الطريقة

  • Stable targets. Every step is graded against a sensible history. Early in training the model's own guesses are nearly random, so feeding them back would turn later steps into nonsense and their losses would teach nothing useful.أهداف مستقرة. كل خطوة تُقيَّم مقابل تاريخ منطقي. في بداية التدريب تكون تخمينات النموذج شبه عشوائية، فلو أعدناها إليه كمُدخلات لتحولت الخطوات اللاحقة إلى هراء، ولما علّمت خسائرها شيئًا مفيدًا.
  • Faster convergence. One early mistake cannot derail the rest of the sentence, so each gradient carries a clean signal. Jurafsky and Martin note that teacher forcing speeds up training.تقارب أسرع. خطأ مبكر واحد لا يمكنه أن يُخرج بقية الجملة عن مسارها، لذلك يحمل كل gradient إشارة نظيفة. ويذكر Jurafsky وMartin أن teacher forcing يسرّع التدريب.
  • Inputs known in advance. Because no input depends on a sampled output, the whole input and target sequence is fixed before the forward pass. An RNN still computes hidden states in order, but nothing has to be sampled between steps. A transformer goes further: with the Causal (masked) self-attention, it computes all positions' losses in one pass, which is the Parallel training you will see in part 8.المدخلات معروفة مسبقًا. لأنه لا يوجد مُدخل يعتمد على مُخرج تم أخذه بالعيّنة (sampled)، فإن تسلسل المدخلات والأهداف كله محدد قبل الـ forward pass. الـ RNN ما زال يحسب الـ hidden states بالترتيب، لكن لا حاجة إلى أخذ أي عيّنة بين الخطوات. والـ transformer يذهب أبعد من ذلك: مع causal mask، يحسب خسائر كل المواضع في تمريرة واحدة، وهذا هو parallel training الذي ستراه في الجزء 8.

The price: exposure biasالثمن: exposure bias

Recall

At position t+1 of training with teacher forcing, what is the input, and what happens to the model's prediction from step t?عند الموضع t+1 في التدريب باستخدام teacher forcing، ما المُدخل، وماذا يحدث لتنبؤ النموذج من الخطوة t؟

The input is the gold word w_(t+1) from the text. The model's prediction from step t is used only to compute the loss -log ŷ_t[w_(t+1)] and is then discarded.
المُدخل هو الكلمة الصحيحة (gold) w_(t+1) من النص. تنبؤ النموذج من الخطوة t يُستخدم فقط لحساب الخسارة -log ŷ_t[w_(t+1)] ثم يُهمَل.

Quick checkاختبار سريع

During training with teacher forcing, what is fed as the input at position t+1?أثناء التدريب باستخدام teacher forcing، ما الذي يُدخل كمُدخل عند الموضع t+1؟

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • Self-supervised: the target at step t is simply word t+1 of the same text. The corpus labels itself.التدريب ذاتي الإشراف (self-supervised): الهدف عند الخطوة t هو ببساطة الكلمة t+1 من النص نفسه. الـ corpus يسمّي نفسه بنفسه.
  • Training loop: at every position, predict the next word, measure the error, and nudge the weights by gradient descent.حلقة التدريب: عند كل موضع، تنبأ بالكلمة التالية، وقِس الخطأ، وحرّك الأوزان قليلًا باستخدام gradient descent.
  • L_CE = -Σ_w y_t[w] log ŷ_t[w]. Because y_t is one-hot, every term but the true word is zero, so L_CE = -log ŷ_t[w_(t+1)].L_CE = -Σ_w y_t[w] log ŷ_t[w]. ولأن y_t من نوع one-hot، فكل حد يساوي صفرًا ما عدا حد الكلمة الصحيحة، لذلك L_CE = -log ŷ_t[w_(t+1)].
  • Worked numbers: ŷ[long] = 0.6 gives 0.511 nats; 0.05 gives 3.00 nats; 1.0 gives 0. The loss explodes as p falls toward 0.أرقام محلولة: ŷ[long] = 0.6 تعطي 0.511 nats، و0.05 تعطي 3.00 nats، و1.0 تعطي 0. الخسارة تنفجر كلما اقتربت p من 0.
  • Sequence loss is the average over positions, L = (1/T) Σ L_CE,t, and exp of that average is the perplexity.خسارة التسلسل هي المتوسط على المواضع، L = (1/T) Σ L_CE,t، والدالة الأسية (exp) لهذا المتوسط هي الـ perplexity.
  • Teacher forcing: at step t+1, ignore what the model predicted and feed the gold word w_(t+1) instead.Teacher forcing: عند الخطوة t+1، تجاهل ما تنبأ به النموذج وأدخل بدلًا منه الكلمة الصحيحة (gold) w_(t+1).
  • It is used because targets and inputs are fixed in advance: stable training, faster convergence, parallel losses.يُستخدم لأن الأهداف والمدخلات محددة مسبقًا: تدريب مستقر، وتقارب أسرع، وحساب الخسائر بالتوازي.
  • Downside (beyond the slides): exposure bias. Training sees only gold histories, generation sees the model's own outputs.العيب (من خارج الشرائح): exposure bias. التدريب يرى فقط تواريخ صحيحة (gold)، بينما التوليد يرى مخرجات النموذج نفسه.

Sourcesالمصادر