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 ?
Sequence models and transformers, Word embeddings
Level L3 Intermediate. Length Long. Nature Mat Mathematical.
What's being asked
Whether you can differentiate log-sigmoid terms and see why the update pulls towards and away from the negatives.
Key idea
Using : .
Steps
- For the positive term: , with . By the chain rule, the gradient with respect to is .
- For each negative term: , with , giving .
- Add them to get the formula in the key idea. The first term has a negative coefficient, so a gradient step moves towards . The negative terms have positive coefficients, so a gradient step moves away from the .
- Numbers: , so . , so .
- Gradient .
- SGD step: .
- Cost: only output vectors are touched, not the whole vocabulary as in the full softmax.
Common mistakes
- Writing instead of as the coefficient of each negative vector.
- Writing the update as ; for a loss to be minimised use .
- Forgetting that and get their own gradients too (for example ).
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: What is the KV cache in autoregressive transformer decoding? How does it change the cost of generating each token, and how much memory does it need for a 32-layer model with , a context of 4096 tokens, and fp16 values?
Next in Sequence models and transformers: 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?