In skip-gram with a full softmax, and the loss is . Show that . For a three-word vocabulary with , , , centre vector and true context word , what is the gradient?
Sequence models and transformers, Word embeddings
Level L3 Intermediate. Length Long. Nature Mat Mathematical.
What's being asked
Whether you can derive the standard "observed minus expected" gradient of a softmax loss and evaluate it.
Key idea
, so : the expected output vector minus the observed one.
Steps
- Write the loss as .
- Differentiate the first term: .
- Differentiate the log-sum-exp: .
- Numbers: scores . The exponentials are with sum , so .
- Expected vector .
- Gradient . Moving against it increases the score of word 1 and decreases that of word 2, which was wrongly as likely as word 1.
- The sum over all words is the reason the full softmax is expensive, which motivates negative sampling or hierarchical softmax.
Common mistakes
- Forgetting the normalising sum when differentiating the .
- Writing the expected vector with unnormalised exponentials instead of probabilities.
- Getting the sign wrong: the loss gradient is expected minus observed, not observed minus expected.
How long your answer should be
Half a page; 5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: Skip-gram with negative sampling uses the loss , where is the centre-word vector, the true context vector and the vectors of sampled negative words. Derive . Then, for , and one negative , what are the gradient and the result of one SGD step with learning rate ?
Next in Sequence models and transformers: How does the GloVe objective arise from the idea that meaning is carried by ratios of co-occurrence probabilities? What is the role of ?