Global Attention
To understand how global attention works quickly, take a long sentence, tokenize it, and then compare how the original attention mechanism (using Key-Value-Query, or KQV) works on the tokens versus how it operates with global tokens derived from blocks of those tokens. Step 1: Original Sentence and Tokenization Sentence: “The quick brown fox jumps over the lazy dog near the riverbank in the sunny park.” Tokenization: Tokens: ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", "near", "the", "riverbank", "in", "the", "sunny", "park"] Step 2: KQV Attention Mechanism KQV Calculation Input Tokens: ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", "near", "the", "riverbank", "in", "the", "sunny", "park"] Key, Query, Value Calculation: Each token is transformed into keys (K), queries (Q), and values (V) using linear transformations. For simplicity, assume each token has a vector representation (embedding). Attention Scores: Compute attention scores for each token against every other token: For example, the attention score for “fox” attending to “jumps” could be calculated as: $$ \text{score}(\text{fox}, \text{jumps}) = Q_{\text{fox}} \cdot K_{\text{jumps}}^T $$ Softmax and Attention Weights: Apply softmax to the scores to get attention weights, which determine how much focus each token gives to others. Weighted Sum: The output for each token is a weighted sum of the values: $$ \text{output}_{\text{fox}} = \sum_{j} \text{softmax}(\text{score}(\text{fox}, \text{token}_j)) \cdot V_{\text{token}_j} $$ ...