An exploding gradient is a gradient that becomes excessively large during backpropagation. It can produce drastic, unstable weight updates, erratic learning, and failure to converge. It is the opposite of a vanishing gradient, which becomes too small to support effective learning. section 2.1.4
In a recurrent neural network, gradients are multiplied across recurrent steps. Long or complex sequences can compound their magnitude, making it harder to learn long-term dependencies. Gradient clipping limits gradient magnitude during training to help stabilize updates. section 2.1.4
Two training situations
A sequence-to-sequence model trained on lengthy, repetitive text or numeric sequences with extreme values may develop large gradients as recurrent steps accumulate. In scaled dot-product attention, large query–key dot products present a different stability risk: dividing them by √dₖ before softmax controls their magnitude and helps avoid softmax saturation and unstable gradients. section 2.1.4 section 2.2.3
Listing 2.3 Simplified scaled dot-attention implementation
embed_1 = np.array([0, 1, 0]) #1 embed_2 = np.array([1, 0, 1]) embed_3 = np.array([0, 1, 1]) embed_4 = np.array([1, 1, 0]) embeddings = np.array([embed_1, embed_2, embed_3, embed_4]) #2 Wq = rand(3, 3) #3 Wk = rand(3, 3) Wv = rand(3, 3) Q = embeddings.dot(Wq) #4 K = embeddings.dot(Wk) V = embeddings.dot(Wv) attention_scores = softmax(Q.dot(K.T) / sqrt(K.shape[1]), axis=1) #5 attention_output = attention_scores.dot(V) #6
The attention-score calculation divides Q·Kᵀ by the square root of the key-vector dimension before applying softmax; the listing uses assigned embeddings and simplified weight matrices rather than a training loop. section 2.2.3
Figure 2.13 This figure shows that the variance of the scaled dot-product values is smaller than the variance of the unscaled dot-product values, indicating that scaling helps to control the variance of the dot-product values. This, in turn, helps prevent the gradients from exploding during backpropagation, improving the stability and convergence of the training process.
The figure contrasts scaled and unscaled dot-product values to show how scaling reduces their variance and supports more stable training. section 2.2.3




