Abstract
TensorCoder is a novel Transformer variant that shifts the attention mechanism from token-wise to dimension-wise. By calculating relationships between dimensions of the embedding space rather than individual tokens, TensorCoder reduces computational complexity from quadratic to linear relative to sequence length in the encoder. This approach reduces training time and FLOPs by up to 70% while maintaining or improving accuracy on language modeling benchmarks like PTB and WikiText-103.
Introduction
The standard Transformer architecture relies on scaled dot-product attention, which scales quadratically ($O(N^2)$) with sequence length $N$. This scaling bottleneck limits the model's ability to process long sequences efficiently. While sparse attention and hashing methods exist, they often compromise global dependency capture. TensorCoder addresses this by observing that the head dimensionality $d$ is typically much smaller than $N$. By focusing on dimension-wise correlations, TensorCoder achieves linear scaling $O(Nd^2)$ in the encoder.
Methodology
TensorCoder replaces standard multi-head attention with a multi-step tensor-based approach:
- Dimension-Wise Attention: Instead of an $N \times N$ matrix, the model computes $Q^T K$ to produce a $d \times d$ matrix, capturing global feature correlations.
- Khatri-Rao (KR) Product: This $d \times d$ matrix is fused with the Value matrix $V$ using a KR product, resulting in a 3rd-order tensor of size $N \times d \times d$.
- Convolutional Feature Extraction: A sliding convolution filter distills the tensor back into an $N \times d$ representation, allowing the model to learn complex feature interactions.
Experimental Results
The model was evaluated on Masked Language Modeling (MLM) using PTB and WikiText-103, and Neural Machine Translation (NMT) using WMT16 and IWSLT16.
Efficiency and Performance
TensorCoder demonstrated significant efficiency gains. On the PTB dataset, training time was reduced to one-third of standard multi-head attention. In translation tasks, FLOPs were reduced by 3.5x. Notably, performance did not degrade; on PTB, TensorCoder achieved a 13% improvement in validation loss over the baseline.
Conclusion
TensorCoder successfully flips the attention paradigm to achieve linear complexity in the encoder. While the decoder remains slightly more complex due to masking requirements, the overall efficiency gains and performance improvements make it a compelling alternative for long-sequence modeling. Future work will explore its scalability to document-level generation.
Summary updated