Beyond Pairwise Attention: Higher-Order Modular Attention for Efficient Sequence Learning
Organizations: Department of Mathematics and Statistics York University Toronto, ON M3J 1P3, Canada
Abstract
Sequence modeling tasks can involve intrinsic higher-order dependencies, while standard self-attention assigns scores to token pairs and does not explicitly parameterize such interactions. We introduce Higher-Order Modular Attention (HOMA), which fuses pairwise attention with an explicit triadic attention pathway made tractable through overlapping blocks, local windows, and a low-rank projection. We compare HOMA with matched pairwise and purely triadic baselines on controlled PARITY and MATCH3 tasks, as well as TAPE benchmarks. HOMA is competitive with or outperforms the baselines, with its clearest advantages when the underlying dependencies extend beyond the explicitly modeled triadic order. These advantages are accompanied in several settings by faster convergence and improved parameter efficiency, with the learned nonlinear fusion providing an effective mechanism for combining the pairwise and triadic representations. Overall, our results provide empirical evidence that HOMA is an effective attention design when task structure extends beyond pairwise interactions.
Figures & tables
| mechanism | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Pairwise-2D | .978 | 1.000 | 1.000 | .499 | .729 | .694 | .503 | .611 | .601 | |
| Blockwise-3D | 1.000 | 1.000 | 1.000 | .964 | .997 | 1.000 | .847 | .991 | 1.000 | |
| HOMA-add | 1.000 | 1.000 | 1.000 | .992 | 1.000 | 1.000 | .871 | .996 | .999 | |
| HOMA | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | |
| Pairwise-2D | 1.000 | 1.000 | 1.000 | .500 | .782 | .728 | .513 | .655 | .702 | |
| test accuracy at | |||||||
|---|---|---|---|---|---|---|---|
| mechanism | params | ||||||
| Pairwise-2D | 0.816 0.009 | 0.835 0.001 | 0.830 0.003 | 0.783 0.009 | 256 | – | |
| Blockwise-3D | 0.836 0.007 | 0.921 0.012 | 0.958 0.008 | 0.927 0.028 | 1.08 | ||
| HOMA-add | 0.835 0.003 | 0.929 0.002 | 0.990 0.002 | 0.975 0.006 | 1.08 | ||
| HOMA | 0.857 0.006 | 0.967 0.007 | 0.993 0.002 | 0.991 0.003 | 1.60 | ||
| Pairwise-2D | 0.708 0.005 | 0.744 0.004 | 0.761 0.009 | 0.731 0.012 | 256 | – | |
| Component | parity -3 | parity -4 | parity -5 | match3 | |||||||
| Design | pooling | third factor | fusion | acc | ep@0.90 | acc | ep@0.90 | acc | ep@0.90 | acc | ep@0.90 |
| HOMA | softmax | MLP | 1.000 | 5.7 | 1.000 | 7.7 | 1.000 | 9.3 | 0.967 | 10.7 | |
| Replace | uniform | MLP | 1.000 | 9.7 | 0.994 | 16.3 | 0.955 | 21.7 | 0.861 | 40 | |
| softmax | MLP | 1.000 | 4.3 | 1.000 | 7.3 | 0.983 | 9.7 | 0.933 | 19.3 | ||
| Replace | softmax | sum | 1.000 | 7.3 | 0.992 | 17.0 | 0.871 | 32.0 † | 0.929 | 19.3 | |
| uniform | sum | 0.988 | 18.7 | 0.495 | 40 | 0.500 | 40 | 0.838 | 40 | ||
Appendix figures & tables10 assets
Supplementary material from the paper’s appendix.
Appendix
| parity / | match2 / | Secondary Structure | Contact Prediction | Fluorescence | |
|---|---|---|---|---|---|
| majority | match3 | ||||
| Train / valid / test | 3,000 / — / 800 | 30,000 / — / 2,000 | 8,678 / 2,170 / 3 sets | 25,299 / 224 / 40 | 21,446 / 5,362 / 27,217 |
| Sequence length | pad to 512 | crop to 256 | fixed at 237 | ||
| Vocabulary | 2 (binary) | (calibrated) | 30 (IUPAC) | 30 (IUPAC) | 30 (IUPAC) |
| Label | per position | per position | per residue | per pair | per sequence |
| Test split | held out | held out | CB513 / CASP12 / TS115 | CASP12 |
| parity / | match2 / | Secondary Structure | Contact Prediction | Fluorescence | |
| majority | match3 | ||||
| range | 8–128 | 8–256 | 32–512 | 32–256 | 32–256 |
| Layers | 1, 6, 12 (grid); 1 (capacity); 1, 2, 4 (coverage) | 1 | 12 | 12 | 12 |
| Heads | 4 | 4 | 8 | 8 | 8 |
| FFN width | none | none | |||
| Dropout | 0 | 0 | 0.4 | 0.1 | 0.1 |
| parity / | match2 / | Secondary Structure | Contact Prediction | Fluorescence | |
| majority | match3 | ||||
| Optimizer | Adam | Adam | Adam | AdamW | Adam |
| Learning rate | |||||
| Weight decay | 0 | 0 | 0 | 0.01 | 0 |
| LR schedule | none | none | none | OneCycle (10% warm-up) | cosine (6% warm-up) |
| Gradient clipping | none | none | none | 1.0 | 1.0 |
| Pairwise-2D | Blockwise-3D | HOMA | |||||||
|---|---|---|---|---|---|---|---|---|---|
| params | acc | ep@0.90 | params | acc | ep@0.90 | params | acc | ep@0.90 | |
| 466 | 0.586 | 40 | 594 | 0.946 | 22.5 (2/3) | 1,492 | 0.982 | 19.3 | |
| 1,442 | 0.879 | 35.5 (2/3) | 1,698 | 0.989 | 10.0 | 3,366 | 1.000 | 6.0 | |
| 4,930 | 0.978 | 21.0 | 5,442 | 1.000 | 4.7 | 8,650 | 1.000 | 5.0 | |
| 18,050 | 1.000 | 11.7 | 19,074 | 1.000 | 3.0 | 25,362 | 1.000 | 3.0 | |
| test accuracy at | |||||
|---|---|---|---|---|---|
| mechanism | |||||
| Pairwise-2D | 1.000 | 1.000 | 1.000 | 1.000 | |
| Blockwise-3D | 1.000 | 1.000 | 1.000 | 1.000 | |
| HOMA-add | 1.000 | 1.000 | 1.000 | 1.000 | |
| HOMA | 1.000 | 1.000 | 1.000 | 1.000 | |
| Pairwise-2D | 1.000 | 1.000 | 1.000 | 0.979 | |
| test accuracy at | |||||||
|---|---|---|---|---|---|---|---|
| mechanism | |||||||
| Pairwise-2D | 0.760 | 0.816 | 0.835 | 0.830 | 0.783 | 0.776 | |
| Blockwise-3D | 0.770 | 0.836 | 0.921 | 0.958 | 0.927 | 0.774 | |
| HOMA-add | 0.741 | 0.835 | 0.929 | 0.990 | 0.975 | 0.817 | |
| HOMA | 0.786 | 0.857 | 0.967 | 0.993 | 0.991 | 0.819 | |
| Pairwise-2D | 0.625 | 0.708 | 0.744 | 0.761 | 0.731 | 0.726 | |
| score at | ||||||
|---|---|---|---|---|---|---|
| task | mechanism | |||||
| Secondary Structure (CB513) | Pairwise-2D | 0.513 | 0.518 | 0.521 | 0.518 | 0.527 |
| Blockwise-2D | 0.536 | 0.542 | 0.552 | 0.622 | 0.642 | |
| Blockwise-3D | 0.620 | 0.636 | 0.643 | 0.642 | 0.644 | |
| HOMA | 0.625 | 0.642 | 0.651 | 0.656 | 0.659 | |
| Secondary Structure (CASP12) | Pairwise-2D | 0.542 | 0.543 | 0.539 | 0.544 | 0.538 |
| Pairwise-2D | Blockwise-2D | Blockwise-3D | HOMA | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| par | tput | mem | par | tput | mem | par | tput | mem | par | tput | mem | |
| Secondary Structure | ||||||||||||
| 120k | 165 | 2.04 | 120k | 217 | 0.42 | 126k | 138 | 0.91 | 146k | 102 | 2.14 | |
| 437k | 159 | 2.19 | 437k | 215 | 0.60 | 449k | 129 | 1.64 | 487k | 97.1 | 2.97 | |
| 1.7M | 147 | 2.50 | 1.7M | 216 | 0.99 | 1.7M | 112 | 3.11 | 1.8M | 84.3 | 4.63 | |
| 6.5M | 101 | 3.14 | 6.5M | 137 | 1.81 | 6.5M | 72.0 | 6.08 | 6.7M | 57.1 | 8.02 | |
| interaction reach | |||||||
|---|---|---|---|---|---|---|---|
| window | mechanism | ||||||
| ( ) | Pairwise-2D | 0.907 | 0.951 | 0.913 | 0.884 | 0.816 | 0.857 |
| Blockwise-3D | 1.000 | 0.501 | 0.496 | 0.499 | 0.500 | 0.501 | |
| HOMA-add | 1.000 | 0.858 | 0.936 | 0.862 | 0.854 | 0.829 | |
| HOMA | 1.000 | 0.964 | 0.968 | 0.915 | 0.909 | 0.986 | |
| ( ) | Pairwise-2D | 0.907 | 0.951 | 0.913 | 0.884 | 0.816 | 0.857 |
| attention layers | ||||
|---|---|---|---|---|
| reach | mechanism | |||
| Blockwise-3D | 1.000 | 1.000 | 1.000 | |
| HOMA-add | 1.000 | 1.000 | 1.000 | |
| HOMA | 1.000 | 1.000 | 1.000 | |
| Blockwise-3D | 0.501 | 1.000 | 1.000 | |
| HOMA-add | 0.858 | 1.000 | 1.000 | |