<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://hmohebbi.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://hmohebbi.github.io/" rel="alternate" type="text/html" /><updated>2026-03-30T10:44:31+00:00</updated><id>https://hmohebbi.github.io/feed.xml</id><title type="html">Hosein Mohebbi</title><entry><title type="html">Why Value Zeroing?</title><link href="https://hmohebbi.github.io/blog/value-zeroing" rel="alternate" type="text/html" title="Why Value Zeroing?" /><published>2023-03-29T00:00:00+00:00</published><updated>2023-03-29T00:00:00+00:00</updated><id>https://hmohebbi.github.io/blog/value-zeroing</id><content type="html" xml:base="https://hmohebbi.github.io/blog/value-zeroing"><![CDATA[<p><i>This post serves as a side note on <strong>Value Zeroing</strong>, an interpretability method for quantifying context mixing in Transformers. 
It is based on our recent research <a href="https://arxiv.org/abs/2301.12971">paper</a> in which we show that the token importance scores obtained through Value Zeroing offer better interpretations compared to previous analysis methods in terms of plausibility, faithfulness, and agreement with probing.</i></p>

<p><i>For the definition and evaluation of Value Zeroing, please refer to the paper. Here, I aim to share a few thoughts and ignite a discussion on why Value Zeroing is deemed to be a promising analysis method for dissecting Transformers.</i></p>

<p><a class="my-button" href="https://arxiv.org/pdf/2301.12971.pdf">📃 Paper</a>
<a class="my-button" href="https://github.com/hmohebbi/ValueZeroing">☕ Code</a>
<a class="my-button" href="https://huggingface.co/spaces/amsterdamNLP/value-zeroing">🤗Demo</a></p>

<hr />

<h3 id="intro-context-mixing">Intro: Context Mixing</h3>
<p>Transformers <a href="https://papers.nips.cc/paper_files/paper/2017/hash/3f5ee243547dee91fbd053c1c4a845aa-Abstract.html">(Vaswani et al., 2017)</a> are excelling in the field of Artificial Intelligence, they are always ahead of the game, dominating every area they venture into, such as <a href="https://papers.nips.cc/paper/2020/hash/1457c0d6bfcb4967418bfb8ac142f64a-Abstract.html">language</a>, <a href="https://arxiv.org/abs/2212.04356">speech</a>, <a href="https://arxiv.org/abs/2010.11929">vision</a>, and <a href="https://www.nature.com/articles/s41586-021-03819-2">biology</a>. Their ability to utilize pairwise interactions between input tokens at each timestep (which we call <i>context mixing</i>), has made them a prime choice of architecture for learning contextualized representations.</p>

<p>While enjoying the Waltz of Transformers in real-world applications, we should understand their inner dynamics too. To better understand these models, we require more than a one-dimensional colorful heatmap array over input tokens to display their importance for the final model’s decision.
We need to be able to quantify the context-mixing interactions between all input pairs, which is something that Transformers are made for. Specifically, we require a matrix that can tell us to what extent each token uses information from other tokens within the sentence to form its contextualized representation at each layer. This is precisely where <strong>Value Zeroing</strong> comes into play.</p>

<h3 id="why-value-zeroing">Why Value Zeroing?</h3>
<blockquote>
  <p>🔨 <strong>Customized for Transformers</strong></p>
</blockquote>

<p>In my humble view, it is crucial to develop or customize analysis methods tailored to the modeling architectures of the target models, based on their true mathematical foundation. 
We need the right tool for the job! Merely employing interpretability approaches that worked for earlier generations of deep learning architectures without any adaptation may not lead to reliable findings.
To illustrate, looking at the attention pattern has been a commonly used approach to gain insight into the information mixing process in attention-based models. It makes sense to rely on these weights when analyzing those attention layers that act as a weighted average over the representations obtained in various time steps in recurrent neural models. However, in the case of Transformers, self-attention weights comprise only a small part of the model, while there are also other components in a Transformer layer that can exert a significant impact on information mixing in the output representations.</p>

<p><strong>Value Zeroing</strong> is a simple yet effective and intuitive analysis method, which is designed based on the mathematical principles of Transformers, without any underlying assumptions or posing confounding variables (such as involving an extra fine-tuned classifier).</p>

<p><br /></p>
<blockquote>
  <p>🌍 <strong>Considering all the components inside of a Transformer layer</strong></p>
</blockquote>

<p>Previous research has shown that Transformers do not solely depend on the weights assigned by the self-attention mechanism, as altering or removing these weights may lead to the same, and sometimes even better model performance on downstream tasks <a href="https://aclanthology.org/2022.findings-emnlp.101/">(Hassid et al., 2022)</a>. Additionally, by looking at their patterns, it has been observed that these weights tend to concentrate on uninformative tokens within the sentence <a href="https://aclanthology.org/P18-1117/">(Voita et al., 2018</a>; <a href="https://aclanthology.org/W19-4828/">Clark et al., 2019)</a>.</p>

<p>To address this, some post-processing interpretability techniques have been proposed to expand the scope of analysis by incorporating other components in a Transformer encoder layer. An exemplary instance of this is <a href="https://aclanthology.org/2020.emnlp-main.574/">Kobayashi (2020)</a>’s insightful work, which highlights the importance of considering the impact of value vectors as well. It is possible that the model may assign a high attention weight to a token with a small norm (they showed that this usually happens for highly frequent and less
informative words). This implies a higher attention might not necessarily lead to a higher contribution to the model’s decision.</p>

<p>Good news is <strong>Value Zeroing</strong> is being computed from a Transformer layer output, which means it incorporates all the components inside a Transformer layer by design, such as multi-head attention, residual connections, layer normalization, and also
position-wise feed-forward networks, resulting in a more reliable
context mixing score.</p>

<p><br /></p>
<blockquote>
  <p>❄ <strong>Keeping the information flow intact during analysis</strong></p>
</blockquote>

<p>Unlike generic perturbation approaches, Value Zeroing does not remove a token representation from the input of an encoder or a decoder layer. We argue that ablating an input token representation cannot be a reliable basis for understanding context mixing process since any changes in the input vectors will mathematically lead to changes in the query and key vectors, resulting in a shift in the attention distribution. Consequently, there will be a discrepancy between the alternative attention weights that we analyze and those we initially had for the original context.</p>

<p><a href="https://aclanthology.org/2022.findings-emnlp.125/">Madsen (2021)</a>’s work provides a cautionary example of the dangers of this approach. They show that for the input example, “The movie is great. I really liked it.”, although the model mostly attends to the word ‘great’ to predict it as a positive sentiment, the model’s confidence remains the same when we replace the word ‘great’ with a ‘[MASK]’ token. Therefore, one might consider an analysis method unfaithful if it strongly highlights the word ‘great’. However, the fact here is that the model’s confidence does not drop due to the redundancy of positive cues in the sentence, causing the model’s attention to shift significantly towards the word ‘liked’ to compensate after removing the word ‘great’.</p>

<p>In contrast, <strong>Value Zeroing</strong> only nullifies the value vector of a specific token representation and leaves the key and query vectors (and thus the pattern of attention flow) intact. In this way, the token representation can also maintain its identity within the Transformer layer, but it does not contribute to forming other token representations.</p>

<p><br /></p>
<blockquote>
  <p>🧐 <strong>Providing interpretation in both layer-specific and input attribution view</strong></p>
</blockquote>

<p>Our experiments suggest that <strong>Value Zeroing</strong> offers better interpretation compared to previous analysis methods, not only for analyzing a specific single Transformer layer, but also for analyzing the entire model when scores are aggregated using the rollout method <a href="https://aclanthology.org/2020.acl-main.385/">(Abnar and Zuidema,
2020)</a>.</p>

<h3 id="a-qualitative-example">A Qualitative Example</h3>
<p><img align="center" src="/resources/posts/vz.png" /></p>

<p>Here’s a graph I really like, showing Value Zeroing scores for <a href="https://arxiv.org/abs/1907.11692">RoBERTa</a> for the sentence <i>“Either you win the game or you &lt;mask&gt; the game”</i>, showing a very interesting pattern that was caught by one of my supervisors:</p>
<ul>
  <li>In the first two layers, the highest values are around the diagonal (mixing information w/ immediate neighbors), and an exchange of information between ‘either’ and ‘or’.</li>
  <li>Then, in layers 4-7, we see a mixing of information between equivalent words in the two sub-sentences (‘you-you,’ ‘win-&lt;mask&gt;,’ ‘the-the,’ ‘game-game’).</li>
  <li>In layers 9-11, there are notable vertical lines, as if all the information is concentrated in the nodes for ‘win’ and ‘or.’</li>
  <li>In the final layer, there are only high values on the diagonal (hardly any mixing).</li>
</ul>

<p><span class="emoji" style="--emoji-size: 18px;">🤗</span> Try your own examples in our online <a href="https://huggingface.co/spaces/amsterdamNLP/value-zeroing">demo</a>.
<br /></p>

<h3 id="your-thoughts-and-comments">Your thoughts and comments</h3>

<script src="https://utteranc.es/client.js" repo="hmohebbi/hmohebbi.github.io" issue-term="title" theme="github-light" crossorigin="anonymous" async="">
</script>]]></content><author><name></name></author><category term="junk" /><summary type="html"><![CDATA[This post serves as a side note on Value Zeroing, an interpretability method for quantifying context mixing in Transformers. It is based on our recent research paper in which we show that the token importance scores obtained through Value Zeroing offer better interpretations compared to previous analysis methods in terms of plausibility, faithfulness, and agreement with probing.]]></summary></entry><entry><title type="html">AdapLeR: Speeding up Inference by Adaptive Length Reduction [↗]</title><link href="https://hmohebbi.github.io/blog/2022/04/23/adapler-hlink.html" rel="alternate" type="text/html" title="AdapLeR: Speeding up Inference by Adaptive Length Reduction [↗]" /><published>2022-04-23T00:00:00+00:00</published><updated>2022-04-23T00:00:00+00:00</updated><id>https://hmohebbi.github.io/blog/2022/04/23/adapler-hlink</id><content type="html" xml:base="https://hmohebbi.github.io/blog/2022/04/23/adapler-hlink.html"><![CDATA[]]></content><author><name></name></author><category term="blog" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">A Layer-wise Probing on BERToids’ Representations [↗]</title><link href="https://hmohebbi.github.io/blog/2021/09/18/layer-wise-probing-on-bertoids-hlink.html" rel="alternate" type="text/html" title="A Layer-wise Probing on BERToids’ Representations [↗]" /><published>2021-09-18T22:00:00+00:00</published><updated>2021-09-18T22:00:00+00:00</updated><id>https://hmohebbi.github.io/blog/2021/09/18/layer-wise-probing-on-bertoids-hlink</id><content type="html" xml:base="https://hmohebbi.github.io/blog/2021/09/18/layer-wise-probing-on-bertoids-hlink.html"><![CDATA[]]></content><author><name></name></author><category term="blog" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Delving into BERT Representations to Explain Sentence Probing Results</title><link href="https://hmohebbi.github.io/blog/explain-probing-results" rel="alternate" type="text/html" title="Delving into BERT Representations to Explain Sentence Probing Results" /><published>2021-04-11T00:00:00+00:00</published><updated>2021-04-11T00:00:00+00:00</updated><id>https://hmohebbi.github.io/blog/explain-probing-results</id><content type="html" xml:base="https://hmohebbi.github.io/blog/explain-probing-results"><![CDATA[<p><img align="right" src="/resources/posts/tsne.png" width="375" height="180" /></p>

<p>This is a post for the EMNLP 2021 paper <a href="https://aclanthology.org/2021.emnlp-main.61/">Exploring the Role of BERT Token Representations to Explain Sentence Probing Results</a>.</p>

<p>We carry out an extensive gradient-based attribution analysis to explain probing performance results from the viewpoint of token representations. Based on a set of probing tasks we show that:</p>
<ul>
  <li>while most of the positional information is diminished through layers of BERT, sentence-ending tokens are partially responsible for carrying this knowledge to higher layers in the model.</li>
  <li>BERT tends to encode verb tense and noun number information in the \(\texttt{##s}\) token and that it can clearly distinguish
the two usages of the token by separating them into distinct subspaces in the higher layers.</li>
  <li>abnormalities can be captured by specific token representations, e.g., in two consecutive swapped tokens or a coordinator between two swapped clauses.</li>
</ul>

<p><a class="my-button" href="https://aclanthology.org/2021.emnlp-main.61.pdf">📃 Paper</a>
<a class="my-button" href="https://github.com/hmohebbi/explain-probing-results">☕ Code</a></p>

<hr />

<h2 id="whats-wrong-with-standard-probing">What’s Wrong with Standard Probing?</h2>
<p>Probing is one of the popular analysis methods, often used for investigating the encoded knowledge in language models. This is typically carried out by training a set of diagnostic classifiers that predict a specific linguistic property based on the representations obtained from different layers.</p>

<p>Recent works in probing language models demonstrate that initial layers are responsible for encoding low-level linguistic information, such as part of speech and positional information, whereas intermediate layers are better at syntactic phenomena, such as syntactic tree depth or subject-verb agreement, while in general semantic information is spread across the entire model. 
Despite elucidating the type of knowledge encoded in various layers, these studies do not go further to investigate the reasons behind the layer-wise behavior and <strong>the role played by token representations</strong>. Analyzing the shortcomings of pre-trained language models requires a scrutiny beyond the mere performance in a given probing task.</p>

<p>So, we extend the layer-wise analysis to the token level in search for distinct and meaningful subspaces in BERT’s representation space that can explain the performance trends in various probing tasks.</p>

<h2 id="methodology">Methodology</h2>
<p>Our analytical study was mainly carried out on
a set of sentence-level probing tasks from <a href="https://github.com/facebookresearch/SentEval/tree/master/data/probing">SentEval</a>.
We used the test set examples for our evaluation and in-depth analysis.</p>

<p>For computing <strong>sentence representations</strong> for layer \(l\),
we opted for a simple unweighted averaging (\(h^l_{Avg}\)) of all input tokens (except for padding and \(\texttt{[CLS]}\) token). This choice was due to our observation that the mean pooling strategy retains or improves \(\texttt{[CLS]}\) performance in most layers in our probing
tasks (cf. Appendix A.1 in <a href="https://arxiv.org/pdf/2104.01477.pdf">the paper</a>).
Moreover, the mean pooling strategy simplifies our measuring of each token’s attribution, discussed next.</p>

<p><br /></p>
<blockquote>
  <p>Saliency Meets Probes</p>
</blockquote>

<p>We leveraged a gradient-based attribution method in order to enable an in-depth analysis of layer-wise representations with the objective of explaining probing performances. Specifically, <strong>we are interested in computing the attribution of each input token to the output labels</strong>. This is usually referred to as the <strong>saliency</strong> score of an input token to classifier’s decision.</p>

<p><img align="center" src="/resources/posts/saliency_explanation_v2.png" /></p>

<p>We adopt the method of <a href="https://ojs.aaai.org/index.php/AAAI/article/view/4517/4395">Yuan et al. (2019)</a> for our setting and compute the saliency score for the \(i^{\text{th}}\) representation in layer \(l\), i.e.,  \(h^l_i\), as:
<!-- Saliency extraction image by Ali -- DONE --></p>

\[\begin{equation}
\label{eq:score}
    Score_c(h^l_i) = \frac{\partial y^l_c}{\partial h_{Avg}^l} \cdot h^l_i
\end{equation}\]

<p>where \(y^l_c\) denotes the probability that the classifier assigns to class \(c\) based on the \(l^{\text{th}}\)-layer representations.
Given that our aim is to explain the representations (rather than evaluating the classifier), we set \(c\) in the equation as the correct label. This way, the scores reflect the contributions of individual input tokens in a sentence to the classification decision.</p>

<!-- to light color by Ali -- DONE -->
<p><span class="note">
<em>Note that using attention weights for this purpose can be misleading given that raw attention weights do not necessarily correspond to the importance of individual token representations.</em></span></p>

<h2 id="probing-explanation">Probing Explanation</h2>
<!-- In what follows in this part, we use the attribution method to find those tokens that play the central role in different surface, syntactic and semantic probing tasks. Based on these tokens we then investigate the reasons behind performance variations across layers. -->
<p>To show the usefulness of our proposed analysis method in revealing the role of token representations, thereby explaining probing results, we conduct our experiments on a set of surface, syntactic and semantic probing tasks. Based on the most attributed tokens, we then investigate the reasons behind performance variations across layers.</p>

<h3 id="sentence-length">Sentence Length</h3>
<p>In this surface-level task we probe the representation of a given sentence in order to estimate its size, i.e., the number of words (not tokens) in it. To this end, we used SentEval’s <strong>SentLen</strong> dataset, but changed the formulation from the original classification objective to a regression one which allows a better generalization due to its fine-grained setting. 
The diagnostic classifier receives average-pooled representation of a sentence as input and outputs a continuous number as an estimate for the input length.</p>

<p>Rounding the regressed estimates and comparing them with the gold labels in the test set, we can observe a significant performance drop from 0.91 accuracy in the first layer to 0.44 in the last layer.
Given that the ability to encode the exact length of input sentences is not necessarily a critical feature, and this decay is not surprising due to the existing previous studies, we do not focus on layer-wise performance results and instead discuss the reason behind the performance variations across layers. To this end, we calculated the absolute saliency scores for each input token in order to find those tokens that played pivotal role while estimating sentence length.</p>

<p><br /></p>
<blockquote>
  <p>Sentence ending tokens retain positional information.</p>
</blockquote>

<p><img align="right" src="/resources/posts/SentLen5LayerAttrib_1.png" width="376" />
<br />
This figure shows tokens that most contributed to the probing results across different layers according to the attribution analysis. Clearly, finalizing tokens (e.g. \(“\texttt{[SEP]}”\) and \(“\texttt{.}”\)) are the main contributors in the higher layers.</p>

<p><br /><br />
<img align="right" src="/resources/posts/PosEmbedding4TSNE_wCbar.png" width="400" /></p>

<p><br /><br /><br />
Here are t-SNE plots of the representations of four selected high frequency tokens (\(“\texttt{[SEP]}”\), \(“\texttt{.}”\) full stop, \(“\texttt{the}”\), \(“\texttt{and}”\)) in different sentences. 
Colors indicate the corresponding token’s position in the sentence (darker colors means higher position index). Finalizing tokens (e.g., \(“\texttt{[SEP]}”\), \(“\texttt{.}”\)) preserve distinct patterns in final layers, indicating their role in encoding positional information, while other (high frequency) tokens exhibit no such behavior.</p>

<p><br /><br /></p>
<h3 id="verb-tense-and-noun-number">Verb Tense and Noun Number</h3>
<p>This analysis inspects BERT representations for grammatical number and tense information. For this experiment we used the <strong>ObjNum</strong> and <strong>Tense</strong> tasks: the former classifies the direct object of the main clause according to its number, i.e., singular (NN) or plural (NNS), whereas the latter checks whether the main-clause verb is labeled as present or past. Let’s look at an example from each probing task:</p>

<p><span style="font-weight:700;">ObjNum:</span></p>
<div style="text-align: center;">
  <div style="background: #f0f0f0; display: inline-block; padding: 10px 24px">
    <div style="font-family:Roboto"> I wasn't chasing rainbows but perhaps she had spotted my struggle . --&gt; NNS
    </div>
  </div>
</div>
<p><span style="font-weight:700;">Tense:</span></p>
<div style="text-align: center;">
  <div style="background: #f0f0f0; display: inline-block; padding: 10px 24px">
    <div style="font-family:Roboto"> In her view , reading the bible fixes everything . --&gt; PRES<span style="color: #777777">ENT</span>
    </div>
  </div>
</div>

<p><br />
<span class="note"><em>In Tense task, each sentence may include multiple verbs, subjects, and objects, while the label is based on the main clause <a href="https://doi.org/10.18653/v1/P18-1198">(Conneau et al., 2018)</a>.</em></span></p>

<p><br /></p>
<blockquote>
  <p>Articles and ending tokens (e.g., \(\texttt{##s}\) and \(\texttt{##ed}\) ) are key playmakers.</p>
</blockquote>

<p><img align="right" src="/resources/posts/Number_Tense_5LayerAttrib_4.png" width="375" height="330" />
On both tasks, BERT preserves a consistently high performance (&gt; 0.82 accuracy) across all layers. Our Attribution analysis reveals that article words (e.g., \(“\texttt{a}”\) and \(“\texttt{an}”\)) and the ending \(\texttt{##s}\) token, which makes out-of-vocab plural words (or third person present verbs), are among the most attributed tokens in the ObjNum task. This shows that these tokens are mainly responsible for encoding object’s number information across layers.</p>

<p>As for the Tense task, the figure shows a consistently high influence from verb ending tokens (e.g., \(\texttt{##ed}\)  and \(\texttt{##s}\)) across layers which is in line with performance trends for this task and highlights the role of these tokens in preserving verb tense information.</p>

<p><br /></p>

<blockquote>
  <p>\(\texttt{##s}\) — Plural or Present?</p>
</blockquote>

<p><strong>The \(\texttt{##s}\) token proved influential in both tense and number tasks.</strong>
The token can make a verb into its simple present tense (e.g., <em>read</em> → <em>reads</em>) or transform a singular noun into its plural form (e.g., <em>book</em> → <em>books</em>). We further investigated the representation space to check if BERT can distinguish this nuance. Results are shown here:</p>

<p><img align="center" src="/resources/posts/4Layer_S.png" /></p>

<p>Colors indicate whether the token occurred in present- or past-labeled sentence in the Tense task. 
For the sake of comparison, we also include two present verbs without the \(\texttt{##s}\) token (i.e., \(“\texttt{does}”\) and \(“\texttt{works}”\)) and two irregular plural nouns (i.e., \(“\texttt{men}”\) and \(“\texttt{children}”\)), in rounded boxes. 
After the initial layers, <strong>BERT recognizes and separates these two forms into two distinct clusters (while BERT’s tokenizer made no distinction among different usages)</strong>. The distinction between the two different usages of the token (as well as the tense information) is clearly encoded in higher layer contextualized representations.</p>

<h3 id="inversion-abnormalities">Inversion Abnormalities</h3>
<p>For this set of experiments, we opted for SentEval’s Bi-gram Shift and Coordination Inversion tasks which respectively probe model’s ability in detecting syntactic and semantic abnormalities. <strong>The goal of this analysis was to to investigate if BERT encodes inversion abnormality in a given sentence into specific token representations.</strong></p>

<h4 id="word-level-inversion">Word-level inversion</h4>
<p>Bi-gram Shift (<strong>BShift</strong>) checks the ability of a model to identify whether two adjacent words within a given sentence have been inverted. 
Let’s look at the following sentences and corresponding labels from the test set:</p>

<div style="text-align: center;">
  <div style="background: #f0f0f0; display: inline-block; padding: 10px 24px">
    <div style="font-family:Roboto"> He was interrupted by a knock at the door . --&gt; O<span style="color: #777777">riginal</span>
    </div>
    <div style="font-family:Roboto"> I felt like <span style="color: #de2347; font-weight: 700">time my</span> here was getting short . --&gt; I<span style="color: #777777">nverted</span></div>
  </div>
</div>
<p><br />
Probing results shows that the higher half layers of BERT can properly distinguish this peculiarity. Similarly to the previous experiments, we leveraged the gradient attribution method to figure out those tokens that were most effective in detecting the inverted sentences. Given that the dataset does not specify the inverted tokens, we reconstructed the inverted examples by randomly swapping two consecutive tokens in the original sentences of the test set, excluding the beginning of the sentences and punctuation marks.</p>

<p><img align="right" src="/resources/posts/bshift_heatmap.png" width="360" />
Our attribution analysis shows that swapping two consecutive words in a sentence results in a significant boost in the attribution scores of the inverted tokens. As an example, the subsequent figure depicts attribution scores of each token in a randomly sampled sentence from the test set across different layers. The classifier distinctively focuses on the token representations for the shifted words, while no such patterns exists for the original sentence.</p>

<p><br />
<img align="center" style="max-width: 600px;     margin-left: auto;     margin-right: auto;     display: block;" src="/resources/posts/boolean_mask.png" /></p>

<p>To verify if this observation holds true for other instances in the test set, we carried out the following experiment.
For each given sequence \(X\) of \(n\) tokens, we defined a boolean mask \(M =[m_1 , m_2 , ..., m_n]\) which denotes the position of the
inversion according to the following condition:
\(\begin{equation}
m_i = 
  \begin{cases}
    1, &amp; x_i \in V \\
    0, &amp; \textrm{otherwise} \
  \end{cases}
\end{equation}\)
where \(V\) is the set of all tokens in the shifted bi-gram (\(|V|\ge2\), given BERT’s sub-word tokenization).
<img align="right" src="/resources/posts/bshift_corr.png" width="255" /></p>

<p>Then we computed the Spearman’s rank correlation coefficient of the attribution scores with \(M\) (a one-hot indicating shifted indices) for all examples in the test set across
all layers.
We observe that in altered sentences the correlation significantly grows over the first few layers which indicates model’s increased sensitivity to the shifted tokens.</p>

<p><img align="right" src="/resources/posts/bshift_sim.png" width="366" />
We hypothesize that BERT implicitly encodes abnormalities in the representation of shifted tokens. To investigate this, we computed the cosine distance of each token to itself in the original and shifted sentences. This figure shows layer-wise statistics for both shifted and non-shifted tokens. <strong>The trend for the shifted token distances highly correlates with that of probing performance, supporting our hypothesis of BERT encoding abnormalities in the shifted tokens.</strong></p>

<p><span class="note">
<em>To investigate the root cause of this, we took a step further and analyzed the building blocks of these representations, i.e., the self-attention mechanism (read <a href="https://arxiv.org/pdf/2104.01477.pdf">the paper</a> for details).</em></span></p>

<h4 id="phrasal-level-inversion">Phrasal-level inversion</h4>
<p>The Coordination Inversion (<strong>CoordInv</strong>) task is a binary classification that contains sentences with two coordinated clausal conjoints (and only one coordinating conjunction). In half of the sentences the clauses’ order is inverted and the goal is to detect malformed sentences at phrasal level. Two examples of these malformed sentences are:</p>

<div style="text-align: center;">
  <div style="background: #f0f0f0; display: inline-block; padding: 10px 24px">
    <div> <span style="color: #2e50ce">There was something to consider</span> but <span style="color: #780086">he might be a prince .</span> --&gt; I<span style="color: #777777">nverted</span>
    </div>
    <div>  <span style="color: #2e50ce">I cut myself</span> and <span style="color: #780086">the glass broke</span> . --&gt; I<span style="color: #777777">nverted</span></div>
    <div style="font-weight: 300; font-size:12px; color: #777777; padding-top: 10px">Both sentences would be correct if we just swap the blue and the purple clauses.</div>
  </div>
</div>
<p><br /></p>

<p>BERT’s performance on this task increases through layers and then slightly decreases in the last three layers. We observed that the attribution scores for \(“\texttt{but}”\) and \(“\texttt{and}”\) coordinators to be among the highest and that these scores notably increase through layers. We hypothesize that BERT might implicitly encodes phrasal level abnormalities in specific token representations.</p>

<p><img align="center" src="/resources/posts/coord_bar_full_edited.png" /></p>

<p><br /></p>
<blockquote>
  <p>Odd Coordinator Representation</p>
</blockquote>

<p>To verify our hypothesis, we filtered the test set to ensure all sentences contain either a \(“\texttt{but}”\) or an \(“\texttt{and}”\) coordinator, since no sentence appears with both labels in the dataset. Then, we reconstructed the original examples by inverting the order of the two clauses in the inverted instances.</p>

<p><img align="right" src="/resources/posts/but_and_sim_saliency_1.png" width="380" />
Feeding this to BERT, we extracted token representations and computed the cosine distance between the representations of each token in the original and inverted sentences. The subsequent figure shows these distances, as well as the normalized saliency score for coordinators (averaged on all examples in each layer), and layer-wise performance for the CoordInv probing task.</p>

<p>Surprisingly, all these curves exhibit a similar trend. As we can see, when the order of the clauses are inverted, the representations of the coordinators \(“\texttt{but}”\) or \(“\texttt{and}”\) play a pivotal role in making sentence representations distinct from one another while there is nearly no change in the representation of other words. <strong>This observation implies that BERT somehow encodes oddity in the coordinator representations</strong> (corroborating part of the findings of our previous analysis of BShift task in the previous part).</p>

<h2 id="conclusion">Conclusion</h2>

<p>We provided an analysis on the representation space of BERT in search for distinct and meaningful subspaces that can explain probing results. Based on a set of probing tasks and with the help of attribution methods we showed that BERT tends to encode meaningful knowledge in specific token representations (which are often ignored in standard classification setups), allowing the model to detect syntactic and semantic abnormalities, and to distinctively separate grammatical number and tense subspaces.</p>

<p>Our approach in using a simple diagnostic classifier and incorporating attribution methods provides a novel way of extracting qualitative results based on multi-class classification probes. This analysis method could be easily applied to probing various deep pre-trained models on various sentence level tasks. We hope this method will spur future probing studies in other evaluation scenarios. Future work might explore to investigate how these subspaces are evolved or transformed during fine-tuning and whether being beneficial at inference time to various downstream tasks or to check whether these behaviors are affected by different training objectives or tokenization strategies.</p>

<p><br />
<script src="https://utteranc.es/client.js" repo="hmohebbi/hmohebbi.github.io" issue-term="title" theme="github-light" crossorigin="anonymous" async="">
</script></p>]]></content><author><name>[&quot;Hosein Mohebbi&quot;, &quot;Ali Modarressi&quot;]</name></author><category term="junk" /><summary type="html"><![CDATA[]]></summary></entry></feed>