---
title: Taylor Multi-Head Self-Attention
url: https://www.emergentmind.com/topics/taylor-multi-head-self-attention-t-msa
type: topic
---

# Taylor Multi-Head Self-Attention

Searching arXiv for the cited papers to ground the article in the current records.
Taylor Multi-Head Self-Attention (T-MSA) is a Taylor-based reformulation of multi-head self-attention designed to reduce the quadratic cost of softmax attention on long sequences by replacing the exponential kernel with a truncated Taylor series and algebraically factorizing the resulting computation into global sums and per-query inner products. In the speech-enhancement architecture LORT, T-MSA is instantiated with a first-order truncation, integrated with Spatial-Channel Enhancement Attention (SCEA), and deployed in a multi-resolution U-Net-like encoder-decoder to provide efficient global modeling for time-frequency representations while maintaining a low parameter count and computational complexity [2509.23832].

## 1. Motivation and problem setting

In speech enhancement, spectrogram sequences are long, and standard softmax attention incurs quadratic complexity in sequence length. Within U-Net-like multi-resolution processing, global modeling across many time-frequency tokens becomes expensive. T-MSA addresses this by replacing the exponential kernel implicit in softmax with a low-order Taylor polynomial, yielding a linear-time attention computation while preserving global context [2509.23832].

The standard difficulty is the need to construct and normalize dense affinity matrices of size $N \times N$. This is both time- and memory-intensive, and it can be numerically sensitive when logits have large magnitude. T-MSA avoids the explicit softmax normalization over all query-key pairs by using a polynomial approximation that factors computations into global sums and low-rank aggregations. In the formulation reported for LORT, the resulting complexity drops from $O(N^2)$ to approximately $O(N)$ with respect to the number of tokens $N$.

For input of $t \times f$ patches and hidden dimension $D$, the reported costs are

$$
O(\mathrm{MHSA}) = 4 t f D^2 + 2 t^2 f^2 D,
$$

$$
O(\mathrm{T\text{-}MSA}) = 18 t f D + 2 t f D^2.
$$

Since $D \ll t f$, the Taylor-based form is more efficient as $t f$ grows. In LORT, this efficiency is part of a lightweight design that achieves only $0.96\text{M}$ parameters while retaining multi-resolution global modeling [2509.23832].

## 2. Mathematical formulation

For reference, standard scaled dot-product attention for head $i$ is defined with

$$
A_i = \mathrm{softmax}\!\left(\frac{Q_i K_i^\top}{\sqrt{d_h}}\right) \in \mathbb{R}^{T \times T},
$$

$$
\mathrm{head}_i = A_i V_i \in \mathbb{R}^{T \times (d_v/H)},
$$

and

$$
\mathrm{MSA}(Q,K,V) = \mathrm{Concat}(\mathrm{head}_1,\dots,\mathrm{head}_H) W_O.
$$

T-MSA replaces the exponential in softmax by a truncated Taylor series. For a scalar $x$,

$$
\exp(x) \approx \sum_{m=0}^{M} \frac{x^m}{m!}.
$$

In LORT, a first-order truncation is adopted:

$$
\exp(x) \approx 1 + x.
$$

For query $q_i$, key $k_j$, and value $V_j$, standard attention applies

$$
V'_i = \frac{\sum_{j=1}^{N} \exp\!\left(\frac{q_i^\top k_j}{\sqrt{d_h}}\right)V_j}{\sum_{j=1}^{N} \exp\!\left(\frac{q_i^\top k_j}{\sqrt{d_h}}\right)}.
$$

With the first-order Taylor expansion,

$$
\exp\!\left(\frac{q_i^\top k_j}{\sqrt{d_h}}\right) \approx 1 + \frac{q_i^\top k_j}{\sqrt{d_h}}.
$$

The numerator and denominator then factorize as

$$
\mathrm{Numerator}_i \approx \sum_j \left[1 + \frac{q_i^\top k_j}{\sqrt{d_h}}\right]V_j = S_0 + q_i^\top M,
$$

$$
\mathrm{Denominator}_i \approx \sum_j \left[1 + \frac{q_i^\top k_j}{\sqrt{d_h}}\right] = N + q_i^\top K_{\mathrm{sum}},
$$

where

$$
S_0 = \sum_{j=1}^{N} V_j \in \mathbb{R}^{d_v/H},
$$

$$
M = \frac{1}{\sqrt{d_h}} \sum_{j=1}^{N} k_j V_j^\top \in \mathbb{R}^{d_h \times (d_v/H)},
$$

$$
K_{\mathrm{sum}} = \frac{1}{\sqrt{d_h}} \sum_{j=1}^{N} k_j \in \mathbb{R}^{d_h}.
$$

Thus,

$$
V'_i \approx \frac{S_0 + q_i^\top M}{N + q_i^\top K_{\mathrm{sum}}}.
$$

This factorization avoids the explicit $T \times T$ matrix and enables linear-time aggregation. LORT retains the $\sqrt{d_h}$ scaling, and a stabilized form is also given as

$$
V'_i = \frac{S_0 + q_i^\top M}{\epsilon + N + q_i^\top K_{\mathrm{sum}}}.
$$

The same construction is applied independently across heads after linear projections

$$
Q = XW_Q,\qquad K = XW_K,\qquad V = XW_V,
$$

followed by splitting into $H$ heads and final recombination through

$$
\mathrm{T\text{-}MSA}(Q,K,V)=\mathrm{Concat}(V'_1,\dots,V'_H)W_O.
$$

A feature-mapping interpretation is also provided: the first-order approximation corresponds to polynomial features $\phi(x)=[1, x/\sqrt{d_h}]$, so that softmax attention is approximated by a normalized bilinear form in $\phi(Q)$ and $\phi(K)$ [2509.23832].

## 3. Integration with SCEA and multi-resolution LORT

In LORT, T-MSA is not used in isolation. It is enhanced by Spatial-Channel Enhancement Attention, a complementary branch introduced to facilitate inter-channel information exchange and alleviate the spatial attention limitations inherent in Taylor-based Transformers. The design explicitly assigns different roles: T-MSA emphasizes global attention primarily within each channel, while SCEA re-introduces inter-channel information exchange and spatial saliency [2509.23832].

SCEA has two branches. The channel-attention branch performs 2-D average pooling over time-frequency to obtain channel descriptors $c \in \mathbb{R}^{C}$ and applies a 1-D convolution across channels with kernel size $3$ and a sigmoid:

$$
c = \mathrm{AvgPool}_{t,f}(X) \in \mathbb{R}^{C},\qquad
w_c = \sigma(\mathrm{Conv1D}_{k=3}(c)) \in (0,1)^C.
$$

The spatial-attention branch pools over channels to obtain $s \in \mathbb{R}^{T \times F}$ and applies a $5 \times 5$ convolution with sigmoid:

$$
s = \mathrm{AvgPool}_{c}(Y) \in \mathbb{R}^{T \times F},\qquad
w_s = \sigma(\mathrm{Conv2D}_{5\times5}(s)) \in (0,1)^{T \times F}.
$$

These weights modulate the T-MSA output multiplicatively, and the SCEA-modulated output is fused with the T-MSA branch. The stated purpose is to alleviate limited spatial sensitivity and inject inter-channel communication missing in T-MSA.

At the architectural level, LORT uses a U-Net-like encoder-decoder. The encoder has two convolutions, expanding to $16$ channels and halving frequency resolution, followed by a Dilated DenseNet. A deformable embedding, denoted DSDCN, controls receptive field offsets. Between encoder and decoder, LORT stacks $N=4$ locally refined Taylor transformer blocks, each containing LayerNorm, T-MSA + SCEA, a feed-forward network, and a Locally Refined Convolution block. Features pass through T-MSA modules at multiple resolutions using alternating downsampling and upsampling, so that increasingly coarse time-frequency scales capture long-range dependencies before subsequent refinement during upsampling.

The LRC block complements T-MSA by modeling local structure. It integrates convolutional feed-forward layers, time-frequency dense local convolutions, and gated units. The paper characterizes the division of labor as follows: multi-resolution attention captures long-range temporal and spectral interactions for global denoising, while LRC captures fine local time-frequency patterns associated with transient preservation and artifact reduction. This suggests that T-MSA is intended as the global component in an explicitly hybrid global-local design [2509.23832].

## 4. Computational profile, normalization, and implementation

The per-head complexity description in LORT distinguishes standard MSA from T-MSA. Standard MSA requires $O(N^2 d_h)$ to form $QK^\top$ and $O(N^2(d_v/H))$ to apply $AV$, with memory $O(N^2)$ to store the attention matrix. For first-order T-MSA, the main precomputations are $S_0$, $M$, and $K_{\mathrm{sum}}$, after which each query needs only inner products with the pre-aggregated statistics. The resulting total is

$$
O\!\left(N d_h \frac{d_v}{H} + N \frac{d_v}{H} + N d_h\right),
$$

with memory

$$
O\!\left(N d_h + N \frac{d_v}{H} + d_h \frac{d_v}{H}\right),
$$

and no $N \times N$ matrix [2509.23832].

The overall LORT model has only approximately $0.96\text{M}$ parameters. The stated reasons are the small encoder channel count of $16$, the use of efficient T-MSA instead of quadratic softmax attention, and the lightweight local convolutions and gated units in LRC. On VCTK+DEMAND with $N=4$ blocks, LORT achieves $16.83\text{G}$ FLOPs.

Several implementation details are specifically tied to T-MSA. The Taylor order is $M=1$. LayerNorm is placed around attention modules, and residual connections are used in both attention and LRC blocks. SCEA uses 2-D pooling with 1-D convolution in the channel branch and channel-wise pooling with $5\times5$ convolution in the spatial branch, both with sigmoid activations and multiplicative broadcast modulation. Positional encoding is not explicitly stated; instead, positional context is said to rely on deformable embeddings and multi-resolution processing.

The paper also notes stabilization mechanisms. Because the first-order truncation neglects higher-order terms, LORT adds Multi-Scale Attention Refinement (MSAR), which learns local corrections from $Q$ and $K$ via lightweight local operations to rectify the Taylor-approximated output. Together with LayerNorm, residual connections, and the optional addition of a small $\epsilon$ in the denominator, these choices are presented as measures that stabilize training.

The STFT configuration relevant to the full system is FFT length $510$, window $510$, hop $100$, and sample rate $16\,\mathrm{kHz}$. The stated experimental optimum is hop $100$; larger hops reduce FLOPs but hurt PESQ, CSIG, and COVL. With $N=4$ Taylor blocks and $16$ channels, the reported runtime profile is approximately $16.83\text{G}$ FLOPs per $2\,\mathrm{s}$, $16\,\mathrm{kHz}$ sample, which is described as feasible for modern edge devices [2509.23832].

## 5. Training objective and empirical behavior

Within LORT, T-MSA participates in a system that decodes enhanced magnitude and phase spectra independently and optimizes them with a composite loss:

$$
L_{\mathrm{total}} = \lambda_1 L_{\mathrm{mag}} + \lambda_2 L_{\mathrm{complex}} + \lambda_3 L_{\mathrm{phase}} + \lambda_4 L_{\mathrm{cons}} + \lambda_5 L_{\mathrm{adv}}.
$$

The complex loss is

$$
L_{\mathrm{complex}} = E[\|Y_r-\hat{Y}_r\|_2^2] + E[\|Y_i-\hat{Y}_i\|_2^2],
$$

the magnitude loss is

$$
L_{\mathrm{mag}} = E[\|Y_m-\hat{Y}_m\|_2^2],
$$

and the phase loss is decomposed into group delay, instantaneous angular frequency, and instantaneous phase components:

$$
\mathrm{GD}(m,k)=\phi(m,k)-\phi(m,k-1), \qquad \hat{\mathrm{GD}}(m,k)=\hat{\phi}(m,k)-\hat{\phi}(m,k-1),
$$

$$
\mathrm{IAF}(m,k)=\phi(m,k)-\phi(m-1,k), \qquad \hat{\mathrm{IAF}}(m,k)=\hat{\phi}(m,k)-\hat{\phi}(m-1,k),
$$

$$
\mathrm{IP}(m,k)=\phi(m,k), \qquad \hat{\mathrm{IP}}(m,k)=\hat{\phi}(m,k),
$$

with

$$
L_{\mathrm{phase}} = E[\|\mathrm{GD}-\hat{\mathrm{GD}}\|_2^2] + E[\|\mathrm{IAF}-\hat{\mathrm{IAF}}\|_2^2] + E[\|\mathrm{IP}-\hat{\mathrm{IP}}\|_2^2].
$$

The STFT consistency loss is

$$
L_{\mathrm{cons}} = E[\|\hat{Y}_r-\mathrm{STFT}(\mathrm{iSTFT}(\hat{Y}_r))\|_2^2] + E[\|\hat{Y}_i-\mathrm{STFT}(\mathrm{iSTFT}(\hat{Y}_i))\|_2^2].
$$

The metric-guided adversarial terms are

$$
L_G = E[\|D(Y_m,\hat{Y}_m)-1\|_2^2],
$$

$$
L_D = E[\|D(Y_m,Y_m)-1\|_2^2] + E[\|D(Y_m,\hat{Y}_m)-Q_{\mathrm{PESQ}}\|_2^2].
$$

The paper sets $(\alpha_1,\alpha_2,\alpha_3,\alpha_4,\alpha_5)=(0.1,0.9,0.3,0.1,0.05)$ and uses AdamW [2509.23832].

On VCTK+DEMAND, LORT with $0.96\text{M}$ parameters and $16.83\text{G}$ FLOPs achieves PESQ $3.51$, STOI $0.96$, CSIG $4.74$, CBAK $3.91$, and COVL $4.23$. On the DNS Challenge datasets under general DNS noise, it attains average PESQ $3.12$ and average STOI $95.0\%$. Under Babble and Factory noise, it delivers the highest average PESQ values of $2.52$ and $2.55$, and top STOI values of $89.3\%$ and $90.6\%$.

The ablation results specifically indicate the role of SCEA alongside T-MSA. Removing SCEA lowers PESQ from $3.51$ to $3.44$ and COVL from $4.23$ to $4.16$. The paper interprets this as evidence that SCEA effectively complements T-MSA by enhancing spatial saliency and inter-channel exchange. Removing CFN or TF-DLC also degrades performance, supporting the stated complementarity between attention-based global modeling and LRC-based local modeling. A plausible implication is that the efficacy of T-MSA in LORT depends not only on its linear attention approximation, but also on the surrounding corrective and local-refinement mechanisms [2509.23832].

## 6. Relation to TaylorShift and other efficient attention variants

A broader and more general Taylor-based perspective is provided by TaylorShift, which reformulates Taylor-Softmax so that full token-to-token interactions can be computed in linear time and space with respect to sequence length $n$ while permitting a “shift back” to standard attention for short sequences [2403.02920]. TaylorShift uses a second-order truncation, $m=2$, rather than the first-order truncation used in LORT.

In TaylorShift, the attention polynomial is

$$
p(L) = 1 + L + \tfrac{1}{2}L^{\odot 2},
$$

with unnormalized numerator and denominator

$$
Y_{\mathrm{nom}} = \big[1 + L + \tfrac{1}{2}L^{\odot 2}\big]V,
\qquad
Y_{\mathrm{denom}} = \big[1 + L + \tfrac{1}{2}L^{\odot 2}\big]\mathbf{1},
$$

and output

$$
Y = Y_{\mathrm{nom}} \oslash Y_{\mathrm{denom}}.
$$

The key algebraic device is the factorization of the elementwise-squared term through a “boxtimes” operator, giving

$$
Y_{\mathrm{squ}} = (L^{\odot 2})V = Q^{\boxtimes 2}\big[(K^{\boxtimes 2})^\top V\big].
$$

This yields an efficient per-head implementation,

$$
Y_{\mathrm{nom}}
=
\tfrac{1}{2} Q^{\boxtimes 2}\!\left[(K^{\boxtimes 2})^\top V\right]
+
Q(K^\top V)
+
V,
$$

with an analogous denominator computed by replacing $V$ by an all-ones vector or by augmenting $V$ with a ones channel. TaylorShift also introduces a normalization strategy based on L2-normalizing queries and keys, a per-head temperature $\tau$, scaling by $\alpha=d_h^{1/4}$, and scaling $V$ by $1/n$, with an additional normalization factor proportional to $\sqrt{n/d_h}$ to maintain numerical stability.

The complexity trade-off in TaylorShift differs from first-order T-MSA. For the efficient second-order implementation, the dominant per-head cost is linear in $n$ but cubic in $d_h$:

$$
\mathrm{ops}_{\mathrm{eff}} = n(4d_h^3 + 10d_h^2 + 8d_h + 3).
$$

Its empirical crossover behavior is reported as memory-efficient for sequences as short as approximately $800$ tokens and faster than standard attention for inputs of approximately $1700$ tokens and beyond. In full Transformer encoders, TaylorShift uses less memory than the standard Transformer at $n=900$, is faster at $n=1800$, and reduces memory by approximately $50\%$ at $n=1500$ and approximately $65\%$ at $n=2000$ on NVIDIA A100 GPUs [2403.02920].

The LORT paper positions first-order T-MSA relative to other efficient attention variants in more qualitative terms. Performer is described as using random features for the softmax kernel, thereby achieving linear attention through Monte Carlo approximations but introducing variance. Linformer is described as reducing complexity by projecting keys and values along the sequence dimension to a fixed rank, potentially imposing a learned low-rank bottleneck. Nyströmformer is described as using landmark points to approximate softmax attention and thus requiring landmark selection. LORT’s T-MSA is characterized as deterministic, polynomial, and based on closed-form global sums. Higher-order polynomial or Taylor attentions are said to improve accuracy at higher cost; LORT therefore adopts $M=1$ and compensates with MSAR and SCEA. This suggests a spectrum of Taylor-based attention designs in which LORT occupies the lightweight, speech-enhancement-oriented end, while TaylorShift provides a more general second-order formulation for long-sequence Transformers [2509.23832].

## 7. Limitations, misconceptions, and scope

A recurring misconception is that all linear-time attention methods discard dense token-to-token interactions. The TaylorShift formulation explicitly argues otherwise: under the polynomial surrogate, all interactions are preserved and the computation is merely reordered through pre-aggregated moments [2403.02920]. In contrast, LORT’s first-order T-MSA is described in a more task-specific way, emphasizing efficient global context rather than making a general claim about preserving the full fidelity of exact softmax.

The main limitation identified for LORT’s T-MSA is approximation error from first-order truncation. The paper states that accuracy may drop when $q_i^\top k_j/\sqrt{d_h}$ has large magnitude or broad distribution. It also notes that reduced cross-channel attention in the T-MSA branch requires explicit compensatory mechanisms such as SCEA. These are not incidental details: SCEA is presented as necessary to restore inter-channel exchange and spatial saliency, while MSAR provides local corrective terms to offset the neglected higher-order Taylor terms.

Resource scaling also imposes a boundary on applicability. T-MSA is motivated for long spectrogram sequences and resource-constrained speech enhancement, especially on-device or low-memory settings. The practical guidance given in LORT is to prefer T-MSA when quadratic attention is prohibitive and when architectures already include local modules such as LRC for fine-grained modeling. Stability recommendations include retaining the $\sqrt{d_h}$ scaling, adding $\epsilon$ to the denominator, using LayerNorm and residual connections, and employing MSAR and SCEA [2509.23832].

For TaylorShift, the corresponding limitations are different. The approximation quality depends on the polynomial order $m$; $m=2$ is a surrogate to softmax rather than an exact replacement. The efficient implementation scales as $O(n d_h^3)$ per head, so very large head dimensions reduce the practical advantage of linear-in-$n$ scaling. The linear-time guarantees also depend on mask structure: they hold for all-to-all, causal, and structured masks that allow reusable aggregation, but fully arbitrary per-query masks may lose those guarantees [2403.02920].

Taken together, these formulations define T-MSA not as a single universally fixed mechanism but as a family of Taylor-based attention constructions. In LORT, the term refers specifically to a first-order Taylor multi-head self-attention module embedded in a speech-enhancement system with SCEA, LRC, deformable embedding, and multi-resolution processing. In the broader TaylorShift formulation, the same underlying principle is developed into a second-order, general-purpose Transformer mechanism with explicit switching criteria between efficient and standard attention regimes.

Source: https://www.emergentmind.com/topics/taylor-multi-head-self-attention-t-msa