---
title: Hrrformer Architecture
url: https://www.emergentmind.com/topics/hrrformer-architecture
type: topic
---

# Hrrformer Architecture

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—$\mathcal{O}(T H \log H)$ time and $\mathcal{O}(T H)$ 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 [2305.19534].

## 1. Query, Key, and Value Computation in Hrrformer

Token embeddings $x_t\in\mathbb{R}^H$ are projected positionwise into queries $q_t$, keys $k_t$, and values $v_t$ via learned matrices $W^Q,W^K,W^V\in\mathbb{R}^{H\times H}$:
$$
Q = X W^Q,\quad K = X W^K,\quad V = X W^V,
$$
where $X\in\mathbb{R}^{T\times H}$ represents the stacked input sequence. Multi-head attention divides $H$ into $h$ heads of $H' = H/h$ 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 $a, b \in \mathbb{R}^H$,
  $$
  r = a \mathbin{\bowtie} b := F^{-1}(F(a) \odot F(b)),
  $$
  where $F$ is the complex FFT, $F^{-1}$ its inverse, and $\odot$ denotes elementwise multiplication.
- **Unbinding (Circular Correlation)**: For $r, b \in \mathbb{R}^H$,
  $$
  a \approx r \mathbin{\bowtie}^{-1} b := F^{-1}(F(r) \oslash F(b)),
  $$
  with $\oslash$ denoting elementwise division.

For suitably random $a$ and $b$ (IID zero-mean Gaussians with variance $1/H$), HRR ensures near-orthogonality in high dimensions:
$$
b^\top(a \mathbin{\bowtie} b)\approx 1, \quad c^\top(a \mathbin{\bowtie} b)\approx0 \text{ for } c\perp a.
$$

## 3. HRR-based Self-Attention Workflow

The Hrrformer’s attention implements the Transformer’s high-level querying logic via superposition and HRR unbinding:

1. **Key–Value Superposition**: Encode all key–value pairs in a single vector,
   $$
   \beta = \sum_{i=1}^T k_i \mathbin{\bowtie} v_i \in \mathbb{R}^H.
   $$
2. **Query Unbinding**: For each position $t$, extract an approximate value via,
   $$
   \hat{v}_t = q_t^\dagger \mathbin{\bowtie} \beta,
   $$
   where $q_t^\dagger$ is the correlation inverse of $q_t$.
3. **Softmax Denoising**: Compute $\cos(v_t, \hat{v}_t)$ for all $t$ as attention logits, stack into vector $a$, and obtain normalized weights $w = \mathrm{softmax}(a)$. Although $\beta$ contains uniform noise, the softmax operation is invariant to addition of a constant offset, effectively “denoising” the signal.
4. **Weighted Value Output**: The output at position $t$ is given by
   $$
   y_t = \sum_{i=1}^T w_i v_i.
   $$

Each convolution/correlation is $O(H\log H)$ via FFT; total attention is $O(T H \log H)$ in time and $O(T H)$ in space, since only $\beta$ and the $Q,K,V$ arrays are retained.

## 4. Layer Design and Integration

A single Hrrformer encoder layer adopts a pre-layer normalization (pre-norm) Transformer form:

- **Layer structure**:
  - LayerNorm$(X)$
  - Projections: $Q,K,V$
  - HRR attention (produces $Z$)
  - Residual: $X' = X + Z$
  - LayerNorm$(X')$
  - 2-layer MLP (GELU or ReLU nonlinearity, linear back to $H$); output $F$
  - Residual: $X^+ = X' + F$

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 $H \to h\cdot H'$, and outputs are concatenated and linearly projected to $H$.

## 5. Implementation and Hyperparameters

Key details include:

- **FFT batching**: Binding/unbinding operations are computed via
  $$
  K\mathbin{\bowtie} V = F^{-1}(F(K)\odot F(V)),
  $$
  batchwise across all tokens and heads.
- **Numerical stability**: A small $\epsilon$ (e.g., $10^{-6}$) is added when dividing in $F(r)\oslash F(b)$ to prevent division by zero in the frequency domain.
- **Softmax**: No special processing outside conventional masking for padding.
- **Hyperparameter ranges**:
  - LRA: $H=256$ or $512$, $h=4$–$8$ heads, MLP-dim $=512$–$1024$, dropout 0.1, Adam optimizer, initial lr $10^{-3}$ decayed to $10^{-5}$ over 20 epochs.
  - EMBER: $H=256$, $h=8$, MLP-dim $=512$, 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       | $\mathcal{O}(T^2 H)$        | $\mathcal{O}(T H \log H)$  |
| Space complexity      | $\mathcal{O}(T^2)$          | $\mathcal{O}(T H)$         |
| Exactness             | Exact                       | Approximate, denoised      |
| Typical convergence   | $\sim$200 epochs            | $\sim$20 epochs            |

HRR attention is approximate and introduces uniform noise to $\beta$, but given softmax “denoising,” the empirical impact is limited. For $T \gg H$, computational savings are substantial. On LRA benchmarks, the Hrrformer achieves convergence in $\sim$20 epochs, in contrast to $\sim$200 for most sparse or linear-efficient alternatives.

## 7. Empirical Evaluation

Findings from [2305.19534]:

- **Long Range Arena (LRA, $T$ up to 16K)**:
  - Single-layer Hrrformer achieves $59.97\%$ average accuracy; multilayer, $60.83\%$.
  - Performance nearly matches Luna-256 ($61.95\%$) and exceeds the original Transformer ($54.39\%$).
  - Per-epoch speed is $246$ samples/sec (vs $23.7$ for Luna-256), $\sim$10x faster, with $\sim$79% less GPU memory usage.
  - Total training time is up to $280\times$ faster due to both per-epoch speed and decreased epochs to convergence.
- **EMBER Malware Classification ($T$ up to 131K)**:
  - Hrrformer scales to $T=131,072$; other full-attention models run out of memory by $T=8$K–$16$K.
  - At $T=16,384$, achieves $91.03\%$ accuracy, surpassing all baselines.
  - Runtime per epoch equals or surpasses the best (F-Net), partly attributed to $H \ll T$.

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 [2305.19534].

Source: https://www.emergentmind.com/topics/hrrformer-architecture