The mechanism that ate machine learning
Attention lets a model selectively focus on different parts of the input when producing each output. Rather than compressing an entire sequence into a single fixed-size vector (the bottleneck of vanilla seq2seq), attention lets the decoder look back at all encoder states and decide which are most relevant at each step.
Self-attention goes further: every position in a sequence attends to every other position simultaneously. This is the key innovation in Transformer architectures. Multi-Head Attention runs several attention operations in parallel, each learning different relationship types (syntactic, semantic, positional).
TensorFlow provides tf.keras.layers.MultiHeadAttention as a first-class layer. The signature is intuitive: pass query, key, value. For self-attention they're all the same tensor; for cross-attention (decoder attending to encoder), query is decoder, key/value are encoder.