Attention Mechanism
Attention mechanisms address challenges in traditional neural network models like CNNs and RNNs, which require fixed input sizes. They offer a flexible approach to handling inputs of varying size and content, such as long text sequences. This flexibility is achieved through mechanisms that enable dynamic focus on different parts of the input.
Database and Queries Analogy
- Database Model: Databases use keys and values, where queries retrieve values based on keys. This concept is analogous to neural networks where queries fetch relevant information from a set of data (keys and values).
- Mathematical Formulation: Queries () in neural networks fetch values based on key similarity: where are the attention weights, indicating the importance of each value based on the query and key .
Normalization of Weights
- Softmax Function: Normalizes attention weights to ensure they sum to 1 and remain nonnegative: