TensorLens: Analisi End-to-End dei Transformer tramite Tensori di Attenzione di Ordine Superiore
TensorLens: End-to-End Transformer Analysis via High-Order Attention Tensors
January 25, 2026
Autori: Ido Andrew Atad, Itamar Zimerman, Shahar Katz, Lior Wolf
cs.AI
Abstract
Le matrici di attenzione sono fondamentali per la ricerca sui transformer, supportando un'ampia gamma di applicazioni tra cui interpretabilità, visualizzazione, manipolazione e distillazione. Tuttavia, la maggior parte delle analisi esistenti si concentra su singole teste o livelli di attenzione, non riuscendo a cogliere il comportamento globale del modello. Sebbene precedenti sforzi abbiano esteso le formulazioni dell'attenzione su più teste mediante medie e moltiplicazioni di matrici o abbiano incorporato componenti come normalizzazione e FFN, manca ancora una rappresentazione unificata e completa che inglobi tutti i blocchi del transformer. Colmiamo questa lacuna introducendo TensorLens, una formulazione innovativa che cattura l'intero transformer come un unico operatore lineare dipendente dall'input, espresso attraverso un tensore di interazione-attenzione di ordine superiore. Questo tensore codifica congiuntamente attenzione, FFN, attivazioni, normalizzazioni e connessioni residue, offrendo una rappresentazione lineare teoricamente coerente ed espressiva del calcolo del modello. TensorLens ha solide basi teoriche e la nostra validazione empirica mostra che produce rappresentazioni più ricche rispetto ai precedenti metodi di aggregazione dell'attenzione. I nostri esperimenti dimostrano che il tensore di attenzione può servire come base solida per sviluppare strumenti finalizzati all'interpretabilità e alla comprensione del modello. Il nostro codice è allegato come materiale supplementare.
English
Attention matrices are fundamental to transformer research, supporting a broad range of applications including interpretability, visualization, manipulation, and distillation. Yet, most existing analyses focus on individual attention heads or layers, failing to account for the model's global behavior. While prior efforts have extended attention formulations across multiple heads via averaging and matrix multiplications or incorporated components such as normalization and FFNs, a unified and complete representation that encapsulates all transformer blocks is still lacking. We address this gap by introducing TensorLens, a novel formulation that captures the entire transformer as a single, input-dependent linear operator expressed through a high-order attention-interaction tensor. This tensor jointly encodes attention, FFNs, activations, normalizations, and residual connections, offering a theoretically coherent and expressive linear representation of the model's computation. TensorLens is theoretically grounded and our empirical validation shows that it yields richer representations than previous attention-aggregation methods. Our experiments demonstrate that the attention tensor can serve as a powerful foundation for developing tools aimed at interpretability and model understanding. Our code is attached as a supplementary.