HyperAIHyperAI

Command Palette

Search for a command to run...

توصيف القدرة التعبيرية للانتباه المحلي في المحوّلات

Jiaoda Li Ryan Cotterell

الملخص

المحوّل هو البنية العصبية الأكثر شيوعًا في نمذجة اللغة. ويقوم أساسه على آلية الانتباه الشامل، التي تتيح للنموذج تجميع المعلومات من جميع الرموز السابقة قبل توليد الرمز التالي. من الصيغ الشائعة للانتباه ما يُعرف بالانتباه المحلي، الذي يُقيّد كل رمز بتجميع المعلومات من نافذة محدودة من الرموز السابقة، مما يخفض التكلفة التربيعية للانتباه الشامل إلى تكلفة خطية. وعلى الرغم من أن هذا القيد يستند عادةً إلى دوافع الكفاءة، فقد تبيّن أنه يُحسّن جودة النموذج أيضًا، وهي ظاهرة افتقرت حتى الآن إلى تفسير مقنع. نُقدّم في هذا العمل وصفًا رسميًّا لهذه الظاهرة من منظور القدرة التعبيرية للمعرّفات. وقد أثبتت دراسات سابقة أن المحوّلات ذات الدقة الثابتة مع الانتباه الشامل تقابل شريحة من المنطق الزمني الخطي تتضمّن عامل ماضٍ واحدًا. نُبْرهن إضافةً إلى ذلك على أن إدخال الانتباه المحلي يُضيف عاملًا زمنيًّا ثانٍ، مما يُوسّع بشكل صارم صنف اللغات المنتظمة القابلة للتعريف. فضلًا عن ذلك، فإن الانتباهين الشامل والمحلي مكمّلان تعبيرِيًّا لبعضهما البعض؛ إذ لا يشمل أيّ منهما الآخر، ويؤدي دمجهما إلى أغنى الشرائح. تُؤكّد تجارب على التعرّف على اللغات الصورية ونمذجة اللغة الطبيعية هذه النتائج النظرية، وتُظهر أن المحوّلات الهجينة التي تجمع بين الانتباه الشامل والمحلي تتفوّق على نظيراتها ذات الانتباه الشامل وحده.

One-sentence Summary

Researchers at ETH Zürich prove that local attention in transformers introduces a second temporal operator beyond the single past operator characterizing global attention, strictly enlarging the class of recognizable regular languages, and show that hybrid global-local architectures are expressively complementary and empirically outperform global-only transformers on formal language recognition and natural language modeling.

Key Contributions

  • The paper links fixed-precision transformers to fragments of linear temporal logic, showing that global attention corresponds to LTL[P] and that local attention adds a bounded past operator, strictly enlarging the class of recognizable regular languages.
  • The analysis establishes precise expressivity relationships, including that k-local attention is maximally expressive at k=1, that k-local and global attention are incomparable, and that hybrid global and local attention corresponds to a strictly richer fragment, while modular predicates can close the expressive gap for larger k.
  • Experiments on formal language recognition and WikiText-2 language modeling support the theory, showing that hybrid global and local transformers outperform global-only models and that the 1-local hybrid achieves the strongest language-modeling performance.

Introduction

Transformers rely on attention, and local attention restricts aggregation to a fixed window, making sequence modeling more efficient while unexpectedly improving language modeling and translation even under matched compute. Prior work characterized global attention as a limited fragment of linear temporal logic, but did not explain why local attention can increase expressivity. The authors connect attention patterns to logic fragments, showing that local attention adds a new past operator and that hybrid global local attention recognizes strictly more formal languages than global or local attention alone. They also show that purely local attention collapses expressivity to dependence on a fixed length suffix, while one token local windows give the strongest practical gains.

Dataset

  • The dataset is a curated collection of formal languages used to evaluate temporal logic fragments. The authors select two representative languages from each definability class, using regular language definitions as the source. The excerpt does not report dataset size, string length, sampling distribution, or train and evaluation split.

  • LTL[Y] subset: contains languages definable with future temporal operators. The authors include Σa, strings ending with a, and Σab, strings ending with ab. These capture suffix-based properties.

  • LTL[P] subset: contains languages definable with past temporal operators. The authors include aΣ*, strings starting with a, and ΣaΣbΣ*, strings containing ab as a non-contiguous subsequence. These capture prefix and subsequence properties.

  • LTL[P, Y] exclusive subset: contains languages definable with both past and future operators but not by LTL[P] or LTL[Y] alone. The authors include (ab), strings formed by repeated ab, and ΣabΣ*, strings containing ab as a contiguous substring. The filtering rule removes languages already expressible in either past-only or future-only fragments.

  • LTL[S] exclusive subset: contains languages definable with the separation operator but not by LTL[P, Y]. The authors include {a,b,d}a{c,d}, a right-deterministic polynomial over a restricted alphabet, and (a(ab)b), a bounded Dyck language with maximum nesting depth 2. The filtering rule removes languages expressible in the past and future fragment.

  • The paper uses the data as an evaluation suite for language membership and temporal logic definability. The models are evaluated on generated or selected strings from these languages. The provided text does not describe cropping, metadata construction, mixture ratios, or detailed preprocessing steps.

Method

The authors leverage a logical and automata-theoretic characterization to analyze transformer expressivity. The overall pipeline first restricts linear temporal logic to fragments generated by past operators, then formalizes a transformer as a fixed-precision language recognizer, and finally maps attention masks to those fragments. The analysis treats the transformer as a classifier over padded sequences. An input w=w1⋯wN\mathbf{w}=w_1\cdots w_Nw=w1​⋯wN​ is processed as w‾=w1⋯wNEOS\overline{\mathbf{w}}=w_1\cdots w_N\mathrm{EOS}w=w1​⋯wN​EOS, and the decision is read from the EOS position. This convention aligns transformer evaluation with temporal-logic evaluation just after the last token.

The logical side focuses on linear temporal logic fragments generated by the past operator P\mathbf{P}P and the one-step past operator Y\mathbf{Y}Y. The operator Pψ\mathbf{P}\psiPψ asks whether ψ\psiψ held at some earlier position, while Yψ\mathbf{Y}\psiYψ asks whether ψ\psiψ held at the immediately preceding position. The combined fragment LTL[P,Y]\mathrm{LTL}[\mathbf{P},\mathbf{Y}]LTL[P,Y] strictly contains both LTL[P]\mathrm{LTL}[\mathbf{P}]LTL[P] and LTL[Y]\mathrm{LTL}[\mathbf{Y}]LTL[Y], because the two fragments are incomparable. To study bounded past access, the authors introduce Y≤k\mathbf{Y}^{\le k}Y≤k and Y∗\mathbf{Y}^{\ast}Y∗:

Y≤kψ=⋁i=1kYY⋯Y⏟i timesψ,Y∗ψ=⋁i=1∞YY⋯Y⏟i timesψ.\mathbf{Y}^{\le k}\psi = \bigvee_{i=1}^{k} \underbrace{\mathbf{Y}\mathbf{Y}\cdots \mathbf{Y}}_{i\text{ times}}\psi, \qquad \mathbf{Y}^{\ast}\psi = \bigvee_{i=1}^{\infty} \underbrace{\mathbf{Y}\mathbf{Y}\cdots \mathbf{Y}}_{i\text{ times}}\psi.Y≤kψ=i=1⋁k​i timesYY⋯Y​​ψ,Y∗ψ=i=1⋁∞​i timesYY⋯Y​​ψ.

The operator Y\mathbf{Y}Y is the special case Y≤1\mathbf{Y}^{\le 1}Y≤1, and Y∗\mathbf{Y}^{\ast}Y∗ coincides with P\mathbf{P}P. Thus, adding Y∗\mathbf{Y}^{\ast}Y∗ to LTL[P]\mathrm{LTL}[\mathbf{P}]LTL[P] does not increase expressive power, while adding the full one-step operator Y\mathbf{Y}Y does.

The characterization of LTL[P,Y]\mathrm{LTL}[\mathbf{P},\mathbf{Y}]LTL[P,Y] also uses standard automata-theoretic objects. For a regular language L⊆Σ∗L\subseteq \Sigma^{\ast}L⊆Σ∗, let SSS be its syntactic semigroup and let A\mathcal{A}A be its minimal DFA. The language LLL is definable in LTL[P,Y]\mathrm{LTL}[\mathbf{P},\mathbf{Y}]LTL[P,Y] exactly when SSS satisfies a local triviality condition and A\mathcal{A}A avoids a specific forbidden two-state pattern. This pattern contains two states qqq and q′q'q′ that are connected by opposite transitions under symbols uuu and vvv, while each state also admits a self-loop under a symbol xxx. Refer to the automata configuration below:

The transformer module is defined directly as a language recognizer. A (D,L)(D,L)(D,L) transformer contains a token encoder e:Σ‾→FD\mathbf{e}:\overline{\Sigma}\to \mathbb{F}^{D}e:Σ→FD, a family of attention mechanisms {Aℓ}ℓ=1L\{\mathbf{A}^{\ell}\}_{\ell=1}^{L}{Aℓ}ℓ=1L​, a family of column-wise nonlinear functions {Fℓ}ℓ=1L\{\mathbf{F}^{\ell}\}_{\ell=1}^{L}{Fℓ}ℓ=1L​, and a classification function c:FD→{0,1}c:\mathbb{F}^{D}\to \{0,1\}c:FD→{0,1}. Given w‾=w1⋯wNEOS\overline{\mathbf{w}}=w_1\cdots w_N\mathrm{EOS}w=w1​⋯wN​EOS, the initial hidden matrix is initialized as

H0(w‾):,n=defe(wn),n∈{1,…,N+1}.\mathbf{H}^{0}(\overline{\mathbf{w}})_{:,n} \stackrel{\mathrm{def}}{=} \mathbf{e}(w_n), \qquad n\in\{1,\ldots,N+1\}.H0(w):,n​=defe(wn​),n∈{1,…,N+1}.

For each layer ℓ=1,…,L\ell=1,\ldots,Lℓ=1,…,L, the model computes

Gℓ(w‾)=LN(Hℓ−1(w‾)+Aℓ(Hℓ−1(w‾))),\mathbf{G}^{\ell}(\overline{\mathbf{w}}) = \mathrm{LN}\left( \mathbf{H}^{\ell-1}(\overline{\mathbf{w}}) + \mathbf{A}^{\ell}(\mathbf{H}^{\ell-1}(\overline{\mathbf{w}})) \right),Gℓ(w)=LN(Hℓ−1(w)+Aℓ(Hℓ−1(w))), Hℓ(w‾)=LN(Gℓ(w‾)+Fℓ(Gℓ(w‾))),\mathbf{H}^{\ell}(\overline{\mathbf{w}}) = \mathrm{LN}\left( \mathbf{G}^{\ell}(\overline{\mathbf{w}}) + \mathbf{F}^{\ell}(\mathbf{G}^{\ell}(\overline{\mathbf{w}})) \right),Hℓ(w)=LN(Gℓ(w)+Fℓ(Gℓ(w))),

where LN\mathrm{LN}LN denotes layer normalization. The final decision is read from the EOS column:

o(w)=defc(HL(w‾):,N+1).o(\mathbf{w}) \stackrel{\mathrm{def}}{=} c\left(\mathbf{H}^{L}(\overline{\mathbf{w}})_{:,N+1}\right).o(w)=defc(HL(w):,N+1​).

The attention mechanism is where the relevant structural constraints enter. For a hidden matrix H∈FD×(N+1)\mathbf{H}\in \mathbb{F}^{D\times (N+1)}H∈FD×(N+1), query, key, and value matrices are produced by learned linear maps

Q(H)=ΘQH,K(H)=ΘKH,V(H)=ΘVH.\mathbf{Q}(\mathbf{H})=\Theta^{\mathrm{Q}}\mathbf{H}, \qquad \mathbf{K}(\mathbf{H})=\Theta^{\mathrm{K}}\mathbf{H}, \qquad \mathbf{V}(\mathbf{H})=\Theta^{\mathrm{V}}\mathbf{H}.Q(H)=ΘQH,K(H)=ΘKH,V(H)=ΘVH.

The raw score for position pair (n,m)(n,m)(n,m) is

Sn,m(H)=Q:,n(H)⋅K:,m(H)DK,\mathbf{S}_{n,m}(\mathbf{H}) = \frac{\mathbf{Q}_{:,n}(\mathbf{H})\cdot \mathbf{K}_{:,m}(\mathbf{H})}{\sqrt{D_{\mathrm{K}}}},Sn,m​(H)=DK​​Q:,n​(H)⋅K:,m​(H)​,

and the masked softmax weights are

αn,m(H)=exp⁡(Sn,m(H))Mn,m∑i=1N+1exp⁡(Sn,i(H))Mn,i.\boldsymbol{\alpha}_{n,m}(\mathbf{H}) = \frac{ \exp(\mathbf{S}_{n,m}(\mathbf{H}))\mathbf{M}_{n,m} }{ \sum_{i=1}^{N+1} \exp(\mathbf{S}_{n,i}(\mathbf{H}))\mathbf{M}_{n,i} }.αn,m​(H)=∑i=1N+1​exp(Sn,i​(H))Mn,i​exp(Sn,m​(H))Mn,m​​.

The attention output is then

O:,n(H)=∑m=1N+1αn,m(H)V:,m(H).\mathbf{O}_{:,n}(\mathbf{H}) = \sum_{m=1}^{N+1} \boldsymbol{\alpha}_{n,m}(\mathbf{H}) \mathbf{V}_{:,m}(\mathbf{H}).O:,n​(H)=m=1∑N+1​αn,m​(H)V:,m​(H).

The binary mask M\mathbf{M}M determines which past positions are visible. A global mask allows access to all earlier tokens:

Mn,m∗={1,if m<n,0,otherwise.\mathbf{M}^{\ast}_{n,m} = \begin{cases} 1, & \text{if } m<n,\\ 0, & \text{otherwise}. \end{cases}Mn,m∗​={1,0,​if m<n,otherwise.​

A kkk-local mask allows access only to the previous kkk positions:

Mn,m≤k={1,if max⁡(1,n−k)≤m<n,0,otherwise.\mathbf{M}^{\le k}_{n,m} = \begin{cases} 1, & \text{if } \max(1,n-k)\le m<n,\\ 0, & \text{otherwise}. \end{cases}Mn,m≤k​={1,0,​if max(1,n−k)≤m<n,otherwise.​

Multi-head attention combines several such masked heads by learned linear projections:

A(H)=∑h=1HΘhOh(H).\mathbf{A}(\mathbf{H}) = \sum_{h=1}^{H} \Theta^{h}\mathbf{O}^{h}(\mathbf{H}).A(H)=h=1∑H​ΘhOh(H).

Different heads may use different masks, so an architecture can mix global and local access in the same block.

A crucial assumption is fixed precision. All parameters, activations, and primitive operations such as multiplication, exponentiation, and softmax normalization are assumed to lie in a finite representable set F\mathbb{F}F. Results are rounded back into F\mathbb{F}F, which makes addition and softmax-sensitive summation order technically relevant. This assumption is central because it keeps the transformer’s arithmetic behavior finite-state in character and makes the connection to automata and temporal logic possible.

The mask-to-logic correspondence is the core architectural result of the analysis. If every attention head uses the global mask M∗\mathbf{M}^{\ast}M∗, the transformer EOS-recognizes exactly the languages definable in LTL[P]\mathrm{LTL}[\mathbf{P}]LTL[P]. If every head uses the kkk-local mask M≤k\mathbf{M}^{\le k}M≤k, the recognizable languages are exactly those definable in LTL[Y≤k]\mathrm{LTL}[\mathbf{Y}^{\le k}]LTL[Y≤k]. If some heads use M∗\mathbf{M}^{\ast}M∗ and others use M≤k\mathbf{M}^{\le k}M≤k, the hybrid architecture EOS-recognizes exactly the languages definable in LTL[P,Y≤k]\mathrm{LTL}[\mathbf{P},\mathbf{Y}^{\le k}]LTL[P,Y≤k]. Thus, mixing global and local attention yields a strict expressive gain over either pure global attention or pure kkk-local attention.

The analysis also distinguishes the logical role of different window sizes. The one-step local mask directly mirrors Y\mathbf{Y}Y, while larger bounded windows are analyzed through Y≤k\mathbf{Y}^{\le k}Y≤k. Expressing a bounded kkk-window lookback using repeated one-step access can preserve expressive power only by increasing depth, since a bounded disjunction over positions 1,…,k1,\ldots,k1,…,k may require several stacked single-step operations. Positional information can change this picture. Modular predicates such as

MODmr:w,n⊨MODmriffn≡r(modm)\mathrm{MOD}_{m}^{r}: \qquad \mathbf{w},n \models \mathrm{MOD}_{m}^{r} \quad\text{iff}\quad n\equiv r \pmod{m}MODmr​:w,n⊨MODmr​iffn≡r(modm)

allow the logic to refer to position modulo mmm. If transformer positional encodings provide comparable position-dependent information, a kkk-local head can identify the immediate predecessor inside a kkk-window, which affects the expressive separation between different local masking schemes.

Experiment

The experiments evaluate transformer variants with local-only, hybrid, and global-only attention on formal languages selected from temporal-logic definability classes and on next-token modeling over WikiText-2. Without positional encodings, the results closely validate the theory: local attention recognizes the corresponding future-oriented languages, global attention recognizes the corresponding past-oriented languages, and hybrid attention recognizes their union, with very small local windows performing strongest. Positional encodings produce mixed effects and do not remove the advantage of hybrid attention, while the natural-language experiment similarly shows that hybrid attention, especially with minimal local windows, provides the best overall performance. Overall, local and global attention are complementary, and hybrid designs combine their strengths.


بناء الذكاء الاصطناعي بالذكاء الاصطناعي

من الفكرة إلى الإطلاق — سرّع تطوير الذكاء الاصطناعي الخاص بك مع المساعدة البرمجية المجانية بالذكاء الاصطناعي، وبيئة جاهزة للاستخدام، وأفضل أسعار لوحدات معالجة الرسومات.

البرمجة التعاونية باستخدام الذكاء الاصطناعي
وحدات GPU جاهزة للعمل
أفضل الأسعار

HyperAI Newsletters

اشترك في آخر تحديثاتنا
سنرسل لك أحدث التحديثات الأسبوعية إلى بريدك الإلكتروني في الساعة التاسعة من صباح كل يوم اثنين
مدعوم بواسطة MailChimp