How does a Transformer block incorporate skip connections and layer normalization?
A Transformer block incorporates skip connections by adding the input query directly to the output of the multihead attention layer. Layer normalization is applied after the skip connection and also after the feed-forward layers to stabilize the training process.
In a Transformer block, skip connections are implemented by bypassing the multihead attention layer with the input query and adding it to the output of the attention layer. This approach helps mitigate the vanishing gradient problem by providing a direct path for gradients to flow through the network. Layer normalization is applied in two places within the Transformer block: first, after the skip connection is added to the attention output, and second, after the feed-forward layers. This normalization is done across the channels for each position in the sequence, which differs from batch normalization that operates across the batch dimension. These techniques together help stabilize training and improve the model's performance.
Key points
- Skip connections add the input query to the output of the attention layer.
- Layer normalization is applied after skip connections and feed-forward layers.
- Normalization is across channels for each sequence position.
- Skip connections help with gradient flow, reducing vanishing gradient issues.
- Layer normalization stabilizes training by normalizing outputs.
Generative Deep Learning: Teaching Machines to Paint, Write, Compose, and Play
David Foster;
Second Edition · O’Reilly Media, Inc.