Hrrformer Architecture
- Hrrformer Architecture is a Transformer variant that redefines self-attention using HRR's circular convolution and correlation, enhancing computational efficiency.
- It achieves sub-quadratic time (O(TH log H)) and linear space complexity, enabling practical processing of much longer sequences than traditional models.
- Empirical evaluations show rapid convergence (~20 epochs) and superior performance on tasks such as malware classification and long-range benchmarks.
The Hrrformer is a Transformer-family architecture in which the conventional self-attention mechanism is re-cast in terms of Holographic Reduced Representations (HRR), a neuro-symbolic method utilizing circular convolution and correlation. By replacing pairwise dot-product attention with HRR-based superposition and unbinding operations, the Hrrformer achieves sub-quadratic time and space complexity— time and space—enabling practical attention at sequence lengths well beyond the feasible limits of standard Transformers. Despite approximate attention from HRR, the Hrrformer retains high accuracy on benchmarks and demonstrates rapid convergence and efficiency for domains requiring very long context windows, most notably malware sequence classification (Alam et al., 2023).
1. Query, Key, and Value Computation in Hrrformer
Token embeddings are projected positionwise into queries , keys , and values via learned matrices :
where represents the stacked input sequence. Multi-head attention divides into 0 heads of 1 dimensions per head, applying these projections per head identically. These projections preserve the canonical query–key–value paradigm of the original Transformer.
2. Holographic Reduced Representation Attention
Hrrformer attention replaces dot products and softmax weighting with two operators originating from Plate’s HRR: circular convolution (binding) and circular correlation (unbinding), both efficiently implemented via FFT.
- Binding (Circular Convolution): Given 2,
3
where 4 is the complex FFT, 5 its inverse, and 6 denotes elementwise multiplication.
- Unbinding (Circular Correlation): For 7,
8
with 9 denoting elementwise division.
For suitably random 0 and 1 (IID zero-mean Gaussians with variance 2), HRR ensures near-orthogonality in high dimensions:
3
3. HRR-based Self-Attention Workflow
The Hrrformer’s attention implements the Transformer’s high-level querying logic via superposition and HRR unbinding:
- Key–Value Superposition: Encode all key–value pairs in a single vector,
4
- Query Unbinding: For each position 5, extract an approximate value via,
6
where 7 is the correlation inverse of 8.
- Softmax Denoising: Compute 9 for all 0 as attention logits, stack into vector 1, and obtain normalized weights 2. Although 3 contains uniform noise, the softmax operation is invariant to addition of a constant offset, effectively “denoising” the signal.
- Weighted Value Output: The output at position 4 is given by
5
Each convolution/correlation is 6 via FFT; total attention is 7 in time and 8 in space, since only 9 and the 0 arrays are retained.
4. Layer Design and Integration
A single Hrrformer encoder layer adopts a pre-layer normalization (pre-norm) Transformer form:
- Layer structure:
- LayerNorm1
- Projections: 2
- HRR attention (produces 3)
- Residual: 4
- LayerNorm5
- 2-layer MLP (GELU or ReLU nonlinearity, linear back to 6); output 7
- Residual: 8
For the Long Range Arena (LRA) Image task, three layers are used; for other LRA tasks, up to six layers; for EMBER malware classification, a single layer suffices. Multi-head attention splits 9, and outputs are concatenated and linearly projected to 0.
5. Implementation and Hyperparameters
Key details include:
- FFT batching: Binding/unbinding operations are computed via
1
batchwise across all tokens and heads.
- Numerical stability: A small 2 (e.g., 3) is added when dividing in 4 to prevent division by zero in the frequency domain.
- Softmax: No special processing outside conventional masking for padding.
- Hyperparameter ranges:
- LRA: 5 or 6, 7–8 heads, MLP-dim 9–0, dropout 0.1, Adam optimizer, initial lr 1 decayed to 2 over 20 epochs.
- EMBER: 3, 4, MLP-dim 5, single layer, 10 training epochs.
6. Efficiency, Approximation, and Scaling Analysis
Comparisons with standard transformer attention include:
| Property | Standard Attention | Hrrformer/HRR Attention |
|---|---|---|
| Time complexity | 6 | 7 |
| Space complexity | 8 | 9 |
| Exactness | Exact | Approximate, denoised |
| Typical convergence | 0200 epochs | 120 epochs |
HRR attention is approximate and introduces uniform noise to 2, but given softmax “denoising,” the empirical impact is limited. For 3, computational savings are substantial. On LRA benchmarks, the Hrrformer achieves convergence in 420 epochs, in contrast to 5200 for most sparse or linear-efficient alternatives.
7. Empirical Evaluation
Findings from (Alam et al., 2023):
- Long Range Arena (LRA, 6 up to 16K):
- Single-layer Hrrformer achieves 7 average accuracy; multilayer, 8.
- Performance nearly matches Luna-256 (9) and exceeds the original Transformer (0).
- Per-epoch speed is 1 samples/sec (vs 2 for Luna-256), 310x faster, with 479% less GPU memory usage.
- Total training time is up to 5 faster due to both per-epoch speed and decreased epochs to convergence.
- EMBER Malware Classification (6 up to 131K):
- Hrrformer scales to 7; other full-attention models run out of memory by 8K–9K.
- At 0, achieves 1 accuracy, surpassing all baselines.
- Runtime per epoch equals or surpasses the best (F-Net), partly attributed to 2.
In summary, the Hrrformer formulation—by recasting Transformer self-attention with HRR operators—matches the core query–key–value logic but with near-linear scaling in sequence length and substantial empirical speedup, maintaining near–state-of-the-art accuracy and data efficiency on both synthetic and real-world long-sequence tasks (Alam et al., 2023).