Documentation generated from LinkML
Class: MultiHeadAttention_Layer
MultiHeadAttention layer. This is an implementation of multi-headed attention as described in the paper "Attention is all you Need" (Vaswani et al., 2017). If query, key, value are the same, then this is self-attention. Each timestep in query attends to the corresponding sequence in key, and returns a fixed-width vector.This layer first projects query, key and value. These are (effectively) a list of tensors of length num_attention_heads, where the corresponding shapes are (batch_size, <query dimensions>, key_dim), (batch_size, <key/value dimensions>, key_dim), (batch_size, <key/value dimensions>, value_dim).Then, the query and key tensors are dot-producted and scaled. These are softmaxed to obtain attention probabilities. The value tensors are then interpolated by these probabilities, then concatenated back to a single tensor. Finally, the result tensor with the last dimension as value_dim can take an linear projection and return. When using MultiHeadAttention inside a custom Layer, the custom Layer must implement build() and call MultiHeadAttention's _build_from_signature(). This enables weights to be restored correctly when the model is loaded.
- Title: MultiHeadAttention Layer
- Canonical name:
MultiHeadAttentionLayer - Names in code:
MultiHeadAttentionLayer(Scala, TypeScript, Python, Java, GraphQL) - URI:
aio:MultiHeadAttention_Layer(https://w3id.org/aio/MultiHeadAttention_Layer) - Parent: Attention_Layer
Inheritance
- Layer
- Attention_Layer
- MultiHeadAttention_Layer
- Attention_Layer