# ATICVis: A Visual Analytics System for Asymmetric Transformer Models Interpretation and Comparison
## 3 Backgrounds  
In this section, we will introduce the fundamental knowledge of transformers. In many transformer architecture models, a special classification token [CLS] is often added to the input sentence. For classification tasks, the first token (corresponding to [CLS]) is used as the \"sentence vector\". [CLS] token itself does not represent any specific meaning, so [CLS] token is considered to represent the meaning of the whole sentence more fairly in the process of learning. This paper uses the attention vector of the [CLS] token as a basis to build the visual analytics tool. The attention mechanism [20] is proposed to improve the performance of recurrent models, such as LSTM and GRU. Attention mechanism is also widely used in many fields such as machine translation [39], entailment reasoning [40] and image caption [41]. At the same time, Attention itself can be used to explain the alignment relationship between translation input/output sentences, explain what the model has learned, and open the black box of deep learning for users. Self-attention [1] is very different from traditional attention mechanisms. The traditional attention is calculated based on the hidden state of the encoder and decoder. The attention represents the dependency between each word from the decoder to the encoder. However, self-attention captures the dependencies between its own words and words in the encoder and decoder respectively. Self-attention solves the problem of information loss caused by RNN in long texts. Transformer is a network architecture based on self-attention. The transformer models have shown success in many natural language processing tasks. Recently, many models have used transformers as their foundations, and their applications can even be extended to images [42].  
Before discussing the tasks we aim to support, we first discuss the extracted representations used in this work. When a text is an input into the model, an attention vector is generated for each word corresponding to each layer in the model (Figure 2). In this paper, we use the attention vector of the [CLS] token to examine the linguistic information captured by the model. The values in the attention vector correspond to the input words, respectively, and the language information that the model captures is checked by the attention values corresponding to the words (Figure 3).  
Figure 2: An attention vector is generated for each word corresponding to each layer in the model.  
In addition, the transformer architecture has multiple heads, forming multiple subspaces and allowing the model to capture different information. We introduce the calculation of an attention vector from multiple attention heads. When considering a layer \(l\), a sequence of tokens \(s=(w_{1},w_{2},\dots,w_{n})\), \(X^{l}=[x_{1}^{l},x_{2}^{l},\dots x_{n}^{l}]\) is embedding vectors of \(n\) inputs words from layer \(l\). The dimension of embedding vector of each word is \(d\), so \(X\in\mathbb{R}^{n\times d}\). The representation of vectors Q, K, V are obtained through the linear transformation of \(W^{q},W^{k}\), \(W^{v}\in\mathbb{R}^{d\times d^{d}}\). \(W^{q}\), \(W^{k}\) and \(W^{v}\) are projection matrices from a d-dimensional space to a d\({}^{\prime}\)-dimensional space and we can calculate \(Q^{l}\), \(K^{l}\) and \(V^{l}\) by \(Q^{l}=X^{l}W^{q}\), \(K^{l}=X^{l}W^{k}\), \(V^{l}=X^{l}W^{v}\). Attention matrix is \(A^{l}\in\mathbb{R}^{n\times n}\) and calculated based on Q and K, and \(d_{k}\) as a scaling factor. \(i\) is the index of the head. The Equation (1) is the calculation of the attention matrix for one layer and we show an example of the attention computation in Figure 4.  
\[A_{i}^{l}(Q_{i}^{l},K_{i}^{l})=softmax(\frac{Q_{i}^{l}(K_{i}^{l})^{T}}{\sqrt{d_ {k}}}) \tag{1}\]