TensorCoder: Dimension-Wise Attention via Tensor Representation for Natural Language Modeling

Shuai Zhang, Peng Zhang, Xindian Ma, Junqiu Wei, Ningning Wang, Qun LiuarXiv 2020

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:

  1. 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.
  2. 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$.
  3. 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.
Figure 1: Overview of the TensorCoder architecture, illustrating the tensor construction and the subsequent convolutional feature extraction using shared or multiple kernels.

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.

Figure 5: Training loss on the PTB dataset, showing TensorCoder variants converging faster and to a lower loss compared to standard Transformer baselines.

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

BibTeX
@misc{zhang2020tensorcoder,
  author = {Shuai Zhang and Peng Zhang and Xindian Ma and Junqiu Wei and Ningning Wang and Qun Liu},
  title = {{TensorCoder: Dimension-Wise Attention via Tensor Representation for Natural Language Modeling}},
  year = {2020},
  eprint = {2008.01547},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2008.01547},
}
Figure