<?xml version="1.0" encoding="UTF-8"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>PAIR - AI Exploreables</title><link>https://pair.withgoogle.com/explorables</link><atom:link href="http://rss.144-124-237-35.sslip.io/withgoogle/explorables" rel="self" type="application/rss+xml"></atom:link><description>PAIR - AI Exploreables - Powered by AtomRSS</description><generator>AtomRSS</generator><webMaster>contact@atomgroup.dev (AtomRSS)</webMaster><language>en</language><lastBuildDate>Sat, 08 Aug 2026 14:44:29 GMT</lastBuildDate><ttl>5</ttl><item><title>Mapping LLMs with Sparse Autoencoders</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Mapping LLMs with Sparse Autoencoders&lt;/h1&gt;
  &lt;div class=&quot;byline&quot;&gt;&lt;div class=&quot;authors&quot;&gt;By &lt;b&gt;Nada Hussein&lt;/b&gt;, &lt;b&gt;Shivam Raval&lt;/b&gt;, &lt;b&gt;Emily Reif&lt;/b&gt;, &lt;b&gt;Jimbo Wilson&lt;/b&gt;, &lt;b&gt;Ari Alberich&lt;/b&gt;, &lt;b&gt;Neel Nanda&lt;/b&gt;, &lt;b&gt;Lucas Dixon&lt;/b&gt;, and &lt;b&gt;Nithum Thain&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;date&quot;&gt;October 2025&lt;/div&gt;&lt;/div&gt;
  
  
&lt;div class=&quot;post-summary&quot;&gt;
    Sparse Autoencoders (SAEs) are gaining recognition for their ability to enhance the interpretability of machine learning models. By extracting understandable features, SAEs offer new ways to understand and influence model behavior. In this post, we explain what SAEs are and how to train them, how they can be used to build a global feature map for an LLM, and how you can use them to steer model behaviour.
&lt;/div&gt;

&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style-graph-scroll.css&quot;&gt;

&lt;div id=&quot;container&quot; class=&quot;container-1&quot;&gt;
&lt;div id=&quot;graph&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sections&quot;&gt;

&lt;div&gt;
&lt;h3&gt;Understanding Large Language Models&lt;/h3&gt;
&lt;p&gt;Large language models (LLMs) consist of an input layer, a series of hidden layers, and an output layer.&lt;/p&gt;
&lt;p&gt;As a model is processing an input sentence, the output of each hidden layer is referred to as an &lt;em&gt;activation&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Interpretability researchers are interested in understanding how and where a model encodes certain features in its activations.&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;p&gt;Features represent concepts that the model might use as part of its internal reasoning to arrive at an answer. Ideally, activations would be &lt;em&gt;monosemantic&lt;/em&gt;, with each index encoding exactly one feature. This would allow us to more easily figure out the meaning of each feature by examining the inputs for which it is activated.
&lt;/p&gt;&lt;p&gt; For example, if the model is trying to answer the question about A Midsummer Night&#39;s Dream, it might use concepts like Shakespeare, literature, and nature.&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;p&gt;In practice, however, each index might activate for many different features, resulting in &lt;em&gt;polysemantic&lt;/em&gt; activations. This behaviour is reflected in the superposition hypothesis, which theorizes that models often need to represent more features than they have neurons. This makes it very difficult to disentangle the activations to understand how the model is representing features and examine its underlying reasoning mechanisms.&lt;/p&gt;
 &lt;/div&gt;

&lt;div&gt;
&lt;h3&gt;Training Sparse Autoencoders&lt;/h3&gt;
&lt;p&gt;The goal of an SAE is to disentangle these polysemantic activations, separating them into monesmantic vectors that we can connect with individual features. To do this, SAEs use a specific type of neural network, called an autoencoder, which is tasked to try to modify and then reconstruct activations.&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;p&gt;Once trained, an SAE runs polysemantic activations, like the ones extracted from the model, through an encoder...&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;

&lt;p&gt;...and outputs a larger, sparser representation of the activation vector, referred to as the &lt;strong&gt;latent&lt;/strong&gt;. This latent is larger to reflect the superposition hypothesis that there may be more features being represented than neurons in the activation.&lt;/p&gt;
&lt;p&gt;To encourage monosemanticity, the autoencoder network is trained with a sparsity penalty which rewards the model for activating fewer latent neurons.&lt;/p&gt;

&lt;/div&gt;


&lt;div&gt;
    &lt;p&gt;The latent can then be run through a decoder...&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
    &lt;p&gt;...to reconstruct the original activations.&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
    &lt;p&gt;To ensure that the intermediate vector is a suitably accurate decomposition of the activations, the SAE is trained to recreate the original activations by minimizing the reconstruction loss between the original activations and the reconstructions.&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;h3&gt;Labeling the Latent&lt;/h3&gt;
 &lt;p&gt;Once we have an accurate and sparse decomposition, we can use an autolabeler to assign feature labels to each index of the latent. Hover over each activation index to see the top activations that fired for that label. In the &lt;a href=&quot;https://pair.withgoogle.com/explorables/sae/#labeling-neurons&quot;&gt;Labeling Neurons&lt;/a&gt; section below, we will take a deeper dive into a real world example of an SAE and explore the rich labels that are extracted.&lt;/p&gt;
&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Steering with SAEs&lt;/h3&gt;
    &lt;p&gt;With labels for each feature in the model, we can use the SAE to attempt to steer the model. Since we know which indices in the latent correspond to which feature, if we want the model to lean more heavily into the concept that feature represents, we can increase the activation for it in the latent. On the other hand if we want the model to reflect that concept less, we can decrease the activation for it in the latent. Once this is done, we can use the remainder of the autoencoder network to build the reconstruction and substitute it for our original activation.&lt;/p&gt;
    &lt;p&gt;For example, here we activate the cats feature and see how this changes our model behavior.&lt;/p&gt;
&lt;/div&gt;


&lt;div&gt;
    &lt;p&gt;Once we&#39;ve modified the latent by strengthening this feature, we can run this modified representation through the decoder…&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;
    &lt;p&gt;...and create a reconstruction that reflects the steered feature. Notice that because we have modified the latent, this reconstruction is different from the original activation vector, as it now amplifies the “cat” concept.&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;steering-section&quot;&gt;
    &lt;p&gt;We then plug this reconstruction back into the model, and see the model&#39;s steered response!&lt;/p&gt;
    &lt;p&gt; Use the buttons below to change the steered feature.&lt;/p&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;/div&gt;
    
&lt;h3 id=&quot;labeling-neurons&quot;&gt;Labeling Neurons&lt;/h3&gt;

&lt;p&gt;
    Training an autoencoder lets us transform polysemantic activations into a sparse feature representation, but how do we know what each feature represents? To address this, we have to label each neuron in the latent with its corresponding feature.
&lt;/p&gt;
&lt;p&gt;
    A common approach is to look at the training data examples where the corresponding latent neuron activates. After obtaining this list of examples, we can pass them through a standard LLM and ask it to identify a common label to represent them. 
&lt;/p&gt;
&lt;p&gt;
    Click an unlabeled neuron below to walk through this process on an illustrative dataset.
&lt;/p&gt;

&lt;div&gt;&lt;/div&gt;

    
    &lt;h3&gt;Activations map&lt;/h3&gt;
    &lt;p&gt;
        After labeling the latent activations with their corresponding feature labels, we can obtain a global feature map of our model. In short, what features does the model use to reason and how do they cluster? It can be hard to sift through thousands of features, so we visualize them using &lt;a href=&quot;https://pair-code.github.io/understanding-umap/&quot;&gt;UMAP&lt;/a&gt;. 
        &lt;/p&gt;&lt;p&gt;
        Below, we show the map for the 16384 features of &lt;a href=&quot;https://ai.google.dev/gemma/docs/gemma_scope&quot;&gt;Gemma Scope&lt;/a&gt;. The examples are colored by hierarchical clustering, and the descriptive cluster labels are also created using an LLM. We can see that a large number of the features are devoted to programming and code, likely reflecting the training data distribution.
        
        &lt;/p&gt;&lt;p&gt;
        Hover over a feature to see its label, or search to see if a given feature is present in &lt;a href=&quot;https://www.neuronpedia.org/gemma-scope#main&quot;&gt;Gemma Scope&lt;/a&gt;.
    &lt;/p&gt;


&lt;div&gt;&lt;/div&gt; 


&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;The Gemma Scope &lt;a href=&quot;https://www.neuronpedia.org/gemma-scope#main&quot;&gt;Neuronpedia&lt;/a&gt; demo below lets you interact directly with the Gemma Scope SAE. Try steering the model with different features to explore how the model behaviour changes. What happens if you change the strength of steering? 
    While there is still a lot that we don’t understand about SAEs, they are part of the important toolbox we are developing to better understand and control how LLMs work for us.
&lt;/p&gt;



&lt;h3&gt;Credits&lt;/h3&gt;
&lt;p&gt;Thanks to Fernanda Viégas, Mike Mozer, James Wexler, Ryan Mullins and Martin Wattenberg for their help with this piece.
&lt;/p&gt;


&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;


&lt;div id=&quot;end&quot;&gt;&lt;/div&gt;





























</description><link>https://pair.withgoogle.com/explorables/sae/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/sae/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/sae-steering.png" type="image/jpeg"></enclosure></item><item><title>Can Large Language Models Explain Their Internal Mechanisms?</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Can Large Language Models Explain Their Internal Mechanisms?&lt;/h1&gt;

  &lt;div class=&quot;byline&quot;&gt;
    &lt;div class=&quot;authors&quot;&gt;
      By &lt;b&gt;
      Nada Hussein&lt;a class=&quot;footstart small&quot; key=&quot;author&quot;&gt;&lt;/a&gt;&lt;/b&gt;, &lt;b&gt; Asma Ghandeharioun&lt;a class=&quot;footstart small&quot; key=&quot;author&quot;&gt;&lt;/a&gt;&lt;/b&gt;, &lt;b&gt; Ryan Mullins&lt;/b&gt;, &lt;b&gt; Emily Reif&lt;/b&gt;, &lt;b&gt; Jimbo Wilson&lt;/b&gt;, &lt;b&gt; Nithum Thain&lt;a class=&quot;footstart small&quot; key=&quot;author2&quot;&gt;&lt;/a&gt;&lt;/b&gt; and &lt;b&gt; Lucas Dixon&lt;a class=&quot;footstart small&quot; key=&quot;author2&quot;&gt;&lt;/a&gt;
      &lt;/b&gt;
    &lt;/div&gt;
    &lt;div class=&quot;date&quot;&gt;July 2024&lt;/div&gt;
  &lt;/div&gt;

  
  &lt;p&gt;The “mind” of a Large Language Model (LLM) consists of layers of interconnected artificial neurons. These layers communicate with vectors of numbers, often called the &lt;em&gt;hidden representations&lt;/em&gt;. Deriving human-comprehensible meaning from such internals of AI systems is the focus of research into &lt;em&gt;machine-learning interpretability,&lt;/em&gt; which has been making many exciting advances recently&lt;a class=&quot;footstart&quot; key=&quot;sae&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This Explorable is about one of these advances: a new family of interpretability methods called Patchscopes&lt;a class=&quot;citestart&quot; key=&quot;ghandeharioun&quot;&gt;&lt;/a&gt;. The idea is to perform a kind of surgery on the neurons of an LLM, cutting out and replacing hidden representations between different prompts and layers. The key concept is the &lt;em&gt;inspection prompt,&lt;/em&gt; which acts as a lens into the mind of an LLM, allowing the model itself to help uncover human-interpretable meaning.&lt;/p&gt;
&lt;div style=&quot;margin: 0 auto; width: fit-content;&quot;&gt;
  &lt;img src=&quot;https://storage.googleapis.com/uncertainty-over-space/explorables/patching/intro_image.svg&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
&lt;/div&gt;

&lt;p&gt;Patchscopes is built on an understanding of LLMs and the transformer architecture. For a deeper dive into transformers and the schematic diagrams we use throughout this Explorable, see &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#appendix-a-a-brief-review-of-transformers&quot;&gt;Appendix A&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;letting-representations-talk-with-patchscopes&quot;&gt;Letting representations “talk” with Patchscopes&lt;/h3&gt;
&lt;p&gt;The Patchscopes framework leverages a simple premise: LLMs have the inherent ability to translate their own seemingly inscrutable hidden representations into human understandable text. Patching hidden representations between locations during inference allows us to inspect the information within a hidden representation, understand LLM behavior, or even augment the LLM’s behavior to improve its performance. Let’s explore this concretely with a step-by-step example.&lt;/p&gt;


&lt;p&gt;Patchscopes is a surprisingly versatile tool. It can be used for tasks like extracting factual information, such as the country in which Barcelona is located; understanding the mechanisms of model refusal&lt;a class=&quot;citestart&quot; key=&quot;xstest&quot;&gt;&lt;/a&gt;, such as refusing to respond to a prompt that is &lt;em&gt;perceived&lt;/em&gt; to come from a person with malicious intent&lt;a class=&quot;citestart&quot; key=&quot;whos-asking&quot;&gt;&lt;/a&gt;; debugging incorrect outputs; or even finding latent harmful information that might exist in a model even if it isn’t verbalized&lt;a class=&quot;citestart&quot; key=&quot;selfie whos-asking&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the following sections we explore three case studies in which Patchscopes is used to: (1) &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-verbalizing-the-model-s-thought-process&quot;&gt;discover&lt;/a&gt; how models resolve entities in their early layers; (2) &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-extracting-latent-attributes&quot;&gt;evaluate&lt;/a&gt; how accurately the model’s hidden representation captures well-known concepts; and (3) &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#application-correcting-reasoning-errors&quot;&gt;augment&lt;/a&gt; the model’s processing of complex questions. These case studies touch upon some of the aspects of Patchscopes that require human judgment, such as determining good target locations for a given source location, or how to construct prompts that enable model inspection—although there are &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#discussion-and-open-questions&quot;&gt;many more&lt;/a&gt; dimensions and design considerations to be explored. (For a formal definition of Patchscopes, see &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#appendix-b-formal-description-of-patchscopes&quot;&gt;Appendix B&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;Patchscopes is being actively developed, and we invite your explorations, commentary, and feedback &lt;a href=&quot;https://github.com/PAIR-code/interpretability/issues&quot;&gt;on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;case-study-verbalizing-the-model-s-thought-process&quot;&gt;Case-study: Verbalizing the model’s “thought” process&lt;/h3&gt;
&lt;p&gt;An LLM’s ability to perform a task—answering questions, summarizing documents, translating languages—is dependent on its ability to correctly contextualize the tokens in its prompt. For example, to answer the question “When was Diana, Princess of Wales born?” the model must understand that “Diana” refers to “Princess Diana”, rather than the generic name, or the ancient Roman goddess of the hunt. At what point does the model make this association, if at all?&lt;/p&gt;
&lt;p&gt;In this case study, we use Patchscopes to shed light on how models process tokens across the layers of the model, and update their hidden representations to resolve what an entity refers to. We focus on understanding hidden representations of &lt;strong&gt;&lt;em&gt;named entities&lt;/em&gt;&lt;/strong&gt;—people, places, movies, etc.&lt;/p&gt;
&lt;h4 id=&quot;entity-resolution-establishing-context-from-a-prompt&quot;&gt;Entity resolution &amp;amp; establishing context from a prompt&lt;/h4&gt;
&lt;p&gt;We are first going to identify how the model resolves the entity &lt;span class=&quot;token&quot;&gt;Diana&lt;/span&gt; from a source prompt. This is the first step in understanding how the model stores and accesses factual information, which can enable other tasks such as correcting outdated information. Building on the Princess Diana example, we construct a simple source prompt using her name and title:&lt;/p&gt;


&lt;p&gt;We can measure how an entity is resolved by having the model generate a description of the entity and compare it to a known factual description. We can trigger this generation with a &lt;a href=&quot;https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/few-shot-examples&quot;&gt;few-shot&lt;/a&gt; inspection prompt&lt;a class=&quot;citestart&quot; key=&quot;brown&quot;&gt;&lt;/a&gt; consisting of entity names followed by their description, and a final placeholder token &lt;span class=&quot;token highlight target&quot;&gt;x&lt;/span&gt;, which will be used as the target patching location.&lt;/p&gt;


&lt;p&gt;We feed the source prompt into a 40 layer model and extract the hidden representation of the &lt;span class=&quot;token&quot;&gt;Wales&lt;/span&gt; token at every layer. Next, each hidden representation is patched into the first layer in place of the &lt;span class=&quot;token highlight target&quot;&gt;x&lt;/span&gt; token in the inspection prompt. Finally, the LLM continues decoding on this patched inspection prompt to generate the entity description for the given hidden representation of the &lt;span class=&quot;token&quot;&gt;Wales&lt;/span&gt; token.&lt;/p&gt;
&lt;p&gt;In the table below, we show the generated descriptions from the first 10 source layers, and use an LLM-based automated evaluator&lt;a class=&quot;citestart&quot; key=&quot;autoeval&quot;&gt;&lt;/a&gt; to score the similarity of each output to the Wikipedia description of the original source prompt on a scale of 0-10&lt;a class=&quot;footstart&quot; key=&quot;prompt&quot;&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Looking across all 40 layers, we start to see a pattern in the per-layer automated evaluator scores – that entity resolution typically happens in the early layers (&amp;lt; L=20) of the model. The general pattern of resolving in the early layers corresponds with theories about layer function&lt;a class=&quot;citestart&quot; key=&quot;bert-rediscovers2019 bottomup2019&quot;&gt;&lt;/a&gt;: the role of &lt;strong&gt;&lt;em&gt;early layers is to establish context from the prompt&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;


&lt;h4 id=&quot;tokenization-can-change-how-each-layer-processes-information&quot;&gt;Tokenization can change how each layer processes information&lt;/h4&gt;
&lt;p&gt;Tokenization&lt;a class=&quot;citestart&quot; key=&quot;tokenization&quot;&gt;&lt;/a&gt; differs between model families, and has a strong impact on how the model navigates its embedding space. In the following visualization, we’ll focus on a tokenized representation of an example source prompt, “Dubai”:&lt;/p&gt;


&lt;p&gt;Using the same few-shot entity description inspection prompt seen above, this example demonstrates the influence of token-by-layer processing on the generated text – we see the outputs change as the model incorporates more tokens into its context.&lt;/p&gt;


&lt;h4 id=&quot;from-tv-shows-to-countries-exploring-classes-of-named-entities&quot;&gt;From TV shows to countries: Exploring classes of named entities&lt;/h4&gt;
&lt;p&gt;The visualization below allows you to explore more examples&lt;a class=&quot;footstart&quot; key=&quot;dataset&quot;&gt;&lt;/a&gt; of named entities on your own. While this dataset is by no means exhaustively descriptive of the model’s behavior, we do see differences in where the model resolves the target entity across different classes—TV shows, people, countries—and even across token counts. Careful observers will notice a pattern in the way the model processes information: it builds up context by &lt;strong&gt;&lt;em&gt;sequentially processing tokens in reverse order&lt;/em&gt;&lt;/strong&gt;, gradually incorporating each token into the hidden representation. Further work is required to understand these patterns at scale&lt;a class=&quot;footstart&quot; key=&quot;incorrect&quot;&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;To quickly recap this case study, we see that Patchscopes provides a &lt;em&gt;highly flexible&lt;/em&gt; method for defining experiments that extract, verify, and characterize the model’s information retrieval process. It demonstrates &lt;em&gt;highly expressive generations&lt;/em&gt; in early layers, where models are believed to do this processing.&lt;/p&gt;
&lt;h3 id=&quot;case-study-extracting-latent-attributes&quot;&gt;Case-study: Extracting latent attributes&lt;/h3&gt;
&lt;p&gt;We can also use Patchscopes to take this a step further, exploring how a model relates subjects to their specific attributes at various model layers.&lt;/p&gt;
&lt;h4 id=&quot;feature-extraction-to-corroborate-hidden-representations&quot;&gt;Feature extraction to corroborate hidden representations&lt;/h4&gt;
&lt;p&gt;Consider the subject &lt;span class=&quot;token&quot;&gt;Spain&lt;/span&gt;. Can we determine whether our LLM is able to gather context about Spain and correctly identify attributes like its largest city or official currency? More generally, given a hidden representation of a subject, we can explore whether an LLM can extract a specific attribute of that subject.&lt;/p&gt;
&lt;p&gt;With Patchscopes, we can formulate an inspection prompt to extract an attribute. This prompt consists of a description of the attribute and a placeholder token, &lt;span class=&quot;token highlight target&quot;&gt;x&lt;/span&gt;, into which the hidden representation of the source subject is patched. For example, if we’re interested in the feature “the largest city” of a certain country, an inspection prompt that should generate the desired attribute in text looks like:&lt;/p&gt;


&lt;p&gt;To extract the feature, we first capture the hidden representation from the last token of the source prompt and patch it into the &lt;span class=&quot;token highlight target&quot;&gt;x&lt;/span&gt; token in the inspection prompt above. We then determine if the correct answer, in this case &lt;span class=&quot;token&quot;&gt;Madrid&lt;/span&gt;, appears in the target model’s output. The visualization below lets you explore this example for a range of source layers.&lt;/p&gt;


&lt;h4 id=&quot;comparing-patchscopes-to-probing&quot;&gt;Comparing Patchscopes to probing&lt;/h4&gt;
&lt;p&gt;The most comparable approach to this problem is a technique called &lt;em&gt;probing&lt;/em&gt; – training a classifier (such as logistic regression) on a subset of data to allow it to predict an attribute from a hidden representation. This approach has a few downsides – namely, it requires a pre-specified subset of labels, which can limit expressivity of the output, and requires dedicated data to train the classifier.&lt;/p&gt;
&lt;p&gt;Unlike probing, Patchscopes does not require any labeled data or supervised training. Additionally, we show that Patchscopes is more accurate than probing in many contexts&lt;a class=&quot;footstart&quot; key=&quot;dataset&quot;&gt;&lt;/a&gt; in the full paper&lt;a class=&quot;citestart&quot; key=&quot;ghandeharioun&quot;&gt;&lt;/a&gt;. The visualization below lets us explore a variety of reasoning tasks and compare the performance of patching and probing&lt;a class=&quot;footstart&quot; key=&quot;probing-viz&quot;&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;A few noticeable patterns emerge from these examples. &lt;strong&gt;&lt;em&gt;Patchscopes outperforms probing in early layers&lt;/em&gt;&lt;/strong&gt; on 7 of the 8 tasks. However, in 4 of the 8 tasks, probing outperforms patching in some later layers&lt;a class=&quot;footstart&quot; key=&quot;probing-performance&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Importantly, these results suggest that &lt;strong&gt;&lt;em&gt;Patchscopes is a viable alternative to probing classifiers&lt;/em&gt;&lt;/strong&gt;, while offering two improvements. First, the flexibility and simplicity of construction for feature extraction inspection prompts indicate that the prompts could be easily generated from existing, trusted structured data that enables direct performance comparison, such as &lt;a href=&quot;https://www.wikidata.org/wiki/Wikidata:Database_download#RDF_dumps&quot;&gt;Wikipedia’s RDF dumps&lt;/a&gt;. Second, it does not require any additional training data or a predefined set of labels.&lt;/p&gt;
&lt;h3 id=&quot;application-correcting-reasoning-errors&quot;&gt;Application: Correcting reasoning errors&lt;/h3&gt;
&lt;p&gt;In the case studies above, we demonstrate that Patchscopes is a flexible and expressive tool for &lt;em&gt;inspecting&lt;/em&gt; a model. Can we go further and use the same framework to &lt;em&gt;change&lt;/em&gt; model behavior to improve its performance?&lt;/p&gt;
&lt;p&gt;Consider multi-hop reasoning, a problem formulation where the answer depends on making logical connections between disjointed pieces of information. For example, to determine the answer to ‘the largest city in sushi’s country of origin’, a model needs to correctly recognize that Sushi’s country of origin is Japan in order to answer with Japan’s largest city, Tokyo.&lt;/p&gt;
&lt;p&gt;One possible performance inhibitor on these problems may be the model failing to conduct sequential reasoning in the right order. Chain-of-thought (CoT) style prompts &lt;a class=&quot;citestart&quot; key=&quot;weiCoT&quot;&gt;&lt;/a&gt; improve performance on multi-hop reasoning problems&lt;a class=&quot;citestart&quot; key=&quot;llama&quot;&gt;&lt;/a&gt; by explicitly expressing reasoning as a series of steps during generation, but there is still room for improvement. Patchscopes may provide an alternative mechanism to control the order of reasoning steps and ultimately correct the generated output&lt;a class=&quot;footstart&quot; key=&quot;cot&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;patching-backwards&quot;&gt;Patching backwards&lt;/h4&gt;
&lt;p&gt;To explore this, we constructed a small dataset&lt;a class=&quot;footstart&quot; key=&quot;dataset&quot;&gt;&lt;/a&gt; of two-clause multi-hop reasoning queries. We used examples from the &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-extracting-latent-attributes&quot;&gt;attribute extraction case study&lt;/a&gt;, where the first clause defines the scope of the answer, and the second clause establishes the necessary context. The model can correctly answer each of these clauses independently, but fails to answer the composite multi-hop query. With some knowledge about the query structure, we can create a Patchscope that works backward, patching to an earlier token in the same prompt&lt;a class=&quot;footstart&quot; key=&quot;backwardpatch&quot;&gt;&lt;/a&gt; to intervene and correct its answer, as shown in the example below:&lt;/p&gt;


&lt;p&gt;By generalizing the query structure that defines the Patchscope above, we start to see some patterns across our multi-hop reasoning queries:&lt;/p&gt;


&lt;h4 id=&quot;explore-the-accuracy-of-patched-generations&quot;&gt;Explore the accuracy of patched generations&lt;/h4&gt;
&lt;p&gt;The visualization below allows you to explore these examples individually. Use the accuracy grid in the center to explore the &lt;span class=&quot;underline-patching&quot;&gt;patched generations&lt;/span&gt; for different source and target layer pairs, and compare them to the model’s &lt;span class=&quot;underline-baseline&quot;&gt;baseline response&lt;/span&gt;. As described above, the hidden representation is extracted from the &lt;span class=&quot;underline-entity&quot;&gt;last token&lt;/span&gt; in the multi-hop query, and we show the associated &lt;span class=&quot;underline-entity&quot;&gt;entity description&lt;/span&gt;&lt;a class=&quot;footstart&quot; key=&quot;widget-prompt&quot;&gt;&lt;/a&gt; below the accuracy grid to help you locate useful source layers.&lt;/p&gt;


&lt;p&gt;The findings presented above are by no means conclusive, but they do demonstrate the utility of Patchscopes as a method for making sense of model behavior regardless of whether that model is generating the “correct” output.&lt;/p&gt;
&lt;h3 id=&quot;discussion-and-open-questions&quot;&gt;Discussion and open questions&lt;/h3&gt;
&lt;p&gt;In the explorations above, we introduced Patchscopes—a method for understanding hidden representations in models—and established it as a flexible, highly expressive tool &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-verbalizing-the-model-s-thought-process&quot;&gt;for&lt;/a&gt; &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-extracting-latent-attributes&quot;&gt;understanding&lt;/a&gt; and even &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#application-correcting-reasoning-errors&quot;&gt;augmenting&lt;/a&gt; model behavior, which improves and unifies prior work (e.g., vocabulary projection&lt;a class=&quot;citestart&quot; key=&quot;belrose lesswrong&quot;&gt;&lt;/a&gt;, probing classifiers&lt;a class=&quot;citestart&quot; key=&quot;alain belinkov&quot;&gt;&lt;/a&gt;, and computational interventions&lt;a class=&quot;citestart&quot; key=&quot;meng&quot;&gt;&lt;/a&gt;) into a shared theoretical framework. We are excited that the core idea of Patchscopes has already been adopted more broadly&lt;a class=&quot;citestart&quot; key=&quot;selfie&quot;&gt;&lt;/a&gt; in interpretability research as a stepping stone to advance our work on model understanding.&lt;/p&gt;
&lt;p&gt;The case studies explored in this post capture a range of scenarios from input processing to attribute extraction to factual reasoning correction, but LLMs are used for an incredibly wide array of tasks, including mathematical reasoning, classification, code completion, and more. Each of these tasks provide many prompts to analyze, but significant research is required to understand how to create the relevant source or inspection prompts that enable human inspection of the model’s reasoning processes in these tasks. While we do not yet have generalizable heuristics or design guidelines, we do expect that certain classes of inspection prompts will have wide applicability as intermediate inspection tools across tasks that support the creation of task-specific inspection prompts. Examples of these include, but are not limited to, the &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-verbalizing-the-model-s-thought-process&quot;&gt;few-shot entity description&lt;/a&gt; and &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-extracting-latent-attributes&quot;&gt;zero-shot attribute extraction&lt;/a&gt; prompts described in this post.&lt;/p&gt;
&lt;p&gt;Our overarching objective is to develop guidelines and &lt;a href=&quot;https://github.com/PAIR-code/interpretability/tree/master/patchscopes/&quot;&gt;tools&lt;/a&gt; that enable the effective application of Patchscopes across the widest possible variety of modeling tasks. To this end, we are exploring several research directions, such as broadening task applications, automating task-specific and task-agnostic patching configurations, and exploring non-identity hidden representation transforms.&lt;/p&gt;
&lt;p&gt;The effectiveness of a patching configuration—the layer, prompt, and token position choices—depends on how the information propagates during inference. In the experiments we discussed above, simple heuristics worked well in configuring an effective Patchscope. When using the same source and target model, picking the same layer for source and target is a good start. If the analytical goal is more expressive, open-ended generation, e.g., to enable verification, we may pick target layers earlier than the source layer, as we did for &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-verbalizing-the-model-s-thought-process&quot;&gt;entity resolution&lt;/a&gt;. Patching into later target layers seems to be less useful generally, as shown in the &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#application-correcting-reasoning-errors&quot;&gt;multi-hop reasoning&lt;/a&gt;, likely because the model has already shifted from sense-making to decoding. Considering token positions, a rule of thumb is that picking late target positions minimizes the chances of placeholder contamination&lt;a class=&quot;footstart&quot; key=&quot;placeholder-contamination&quot;&gt;&lt;/a&gt;, and therefore is more likely to work than other alternatives. If we aim to ask more complex questions, and therefore use more complicated inspection prompts, prior knowledge about the model’s information flow&lt;a class=&quot;footstart&quot; key=&quot;circuits&quot;&gt;&lt;/a&gt; may be required, or we might need to test many configuration options before finding one that is most effective. Coming up with effective Patchscopes configurations automatically would make this framework much more powerful, and is a research direction we are currently exploring.&lt;/p&gt;
&lt;p&gt;Finally, a full Patchscopes configuration allows for the application of transforms to the hidden representation between the extraction and injection steps. The examples in this explorable only employ the identity function as the transform, but the paper&lt;a class=&quot;citestart&quot; key=&quot;ghandeharioun&quot;&gt;&lt;/a&gt; shows that, surprisingly, it is indeed possible to use a larger and more expressive model from the same family to explain a smaller model using an &lt;a href=&quot;https://en.wikipedia.org/wiki/Affine_transformation&quot;&gt;affine transformation&lt;/a&gt; function.&lt;/p&gt;
&lt;p&gt;But what about different hidden representation dimensions, models from different families, or even models trained on different modalities of data? With more complex transformations, how far can we push the limits in cross-model Patchscopes? Answering these questions requires more research, and we continue to explore these ideas.&lt;/p&gt;
&lt;p&gt;We encourage you to check out our paper&lt;a class=&quot;citestart&quot; key=&quot;ghandeharioun&quot;&gt;&lt;/a&gt; or reach out to us &lt;a href=&quot;https://github.com/PAIR-code/interpretability/issues&quot;&gt;on GitHub&lt;/a&gt; for more information about Patchscopes.&lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Thanks to Avi Caciularu, Carter Blum, Mor Geva, Mahima Pushkarna, Ian Tenney, Fernanda Viegas, Martin Wattenberg, David Weinberger, and James Wexler for their help with this piece.&lt;/p&gt;
&lt;h3 id=&quot;appendix-a-a-brief-review-of-transformers&quot;&gt;Appendix A: A brief review of transformers&lt;/h3&gt;
&lt;p&gt;LLMs are transformer models that take a text string as input, called a &lt;em&gt;prompt&lt;/em&gt;, that describes a task, such as answering a question, summarizing an article, translating text, generating code snippets. The LLM’s job is to generate the text that best follows from the task captured in the prompt. For an illustrative example, consider the prompt: “United Kingdom”.&lt;/p&gt;
&lt;p&gt;This input text is tokenized&lt;a class=&quot;footstart&quot; key=&quot;tokens&quot;&gt;&lt;/a&gt; – broken up into the model’s atomic vocabulary consisting of individual words and small sequences of characters&lt;a class=&quot;citestart&quot; key=&quot;tokenization&quot;&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Each token is &lt;em&gt;embedded&lt;/em&gt; &lt;a class=&quot;footstart&quot; key=&quot;embedding&quot;&gt;&lt;/a&gt; into a high-dimensional numeric vector to facilitate computation. We represent this operation with a trapezoid. The embedded vector is the first &lt;em&gt;hidden representation&lt;/em&gt; in the model.&lt;/p&gt;


&lt;p&gt;After embedding, LLMs are organized into layers of transformer blocks&lt;a class=&quot;citestart&quot; key=&quot;vaswani2017&quot;&gt;&lt;/a&gt;. Each layer produces an updated hidden representation based on the output of the preceding layer, which we visualize with a circle labeled &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\ell^i&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8247em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8247em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;i&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6595em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; stands for the layer index. The hidden representation produced by the first transformer layer is labeled &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\ell^0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;


&lt;p&gt;This procedure continues through the final layer, gradually updating the hidden representations to incorporate context about the task described in the prompt.&lt;/p&gt;


&lt;p&gt;Next, subsequent prompt tokens are fed into the network&lt;a class=&quot;footstart&quot; key=&quot;sequential&quot;&gt;&lt;/a&gt;. Tokens are stored in an ordered sequence, and the hidden representation produced by a layer for a given token is influenced by the hidden representation for that token at the preceding layer as well as the hidden representations for all preceding tokens in the sequence. Networks that only look backwards like this are called &lt;em&gt;decoder-only&lt;/em&gt; models and are our focus here.&lt;/p&gt;


&lt;p&gt;After the final prompt token is processed, the final layer’s hidden representation is used to yield an output token based on the distribution of the model’s training data. This output token, &lt;span class=&quot;token&quot;&gt;is&lt;/span&gt;, becomes the next input to the network.&lt;/p&gt;


&lt;p&gt;By feeding generated tokens back in as input, the model can generate phrases, sentences, and even long-form text.&lt;/p&gt;


&lt;p&gt;For a more in-depth, visual exploration of transformers and the attention mechanism, see the related YouTube videos from 3Blue1Brown&lt;a class=&quot;citestart&quot; key=&quot;3b1b-attn 3b1b-transformers&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;appendix-b-formal-description-of-patchscopes&quot;&gt;Appendix B: Formal description of Patchscopes&lt;/h3&gt;
&lt;p&gt;Given a hidden representation obtained from an LLM inference pass, a Patchscope instance decodes specific information from it by &lt;em&gt;patching&lt;/em&gt; it into a different inference pass (of the same or a different LLM) that encourages the translation of that specific information.&lt;/p&gt;
&lt;p&gt;Formally, given an input sequence of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; tokens &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;⟨&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;.&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;.&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;.&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;⟩&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;S = \langle s_1, ..., s_{n} \rangle&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.05764em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;⟨&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.1514em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;⟩&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and a model &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; with &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;L&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; layers, &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msubsup&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\bm{h}_{i}^{\ell}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1804em;vertical-align:-0.247em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; denotes the hidden representation obtained at layer &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\ell \in [1, \ldots, L]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7335em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and position &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;i \in [1, \ldots, n]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6986em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, when running &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; on &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;S&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.05764em;&quot;&gt;S&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. To inspect &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msubsup&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\bm{h}_{i}^{\ell}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1804em;vertical-align:-0.247em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, we consider a separate inference pass of a model &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; with &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;L^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; layers&lt;a class=&quot;footstart&quot; key=&quot;cross-model&quot;&gt;&lt;/a&gt; on a target sequence &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;⟨&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;⟩&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;T = \langle t_1, \ldots, t_{m} \rangle&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;⟨&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.1514em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;⟩&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; tokens. Specifically, we choose a hidden representation &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msubsup&gt;&lt;mover accent=&quot;true&quot;&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mo&gt;ˉ&lt;/mo&gt;&lt;/mover&gt;&lt;msup&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\bar{\bm{h}}_{i^*}^{\ell^*}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.3655em;vertical-align:-0.247em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord accent&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8312em;&quot;&gt;&lt;span style=&quot;top:-3em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2634em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;accent-body&quot; style=&quot;left:-0.25em;&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ˉ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:1.1185em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6183em;&quot;&gt;&lt;span style=&quot;top:-2.786em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2841em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7633em;&quot;&gt;&lt;span style=&quot;top:-2.931em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; at layer &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\ell^* \in [1, \ldots, L^*]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7335em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and position &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;{i^*} \in [1, \ldots, m]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7278em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; in the execution of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; on &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;T&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. Moreover, we define a mapping function &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;;&lt;/mo&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;θ&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;:&lt;/mo&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;double-struck&quot;&gt;R&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;/msup&gt;&lt;mo&gt;↦&lt;/mo&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;double-struck&quot;&gt;R&lt;/mi&gt;&lt;msup&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;f({\bm{h}}; \bm{\theta}): \mathbb{R}^{d} \mapsto \mathbb{R}^{d^*}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot; style=&quot;margin-right:0.03194em;&quot;&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8601em;vertical-align:-0.011em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbb&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8491em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;↦&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8973em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbb&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8973em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7633em;&quot;&gt;&lt;span style=&quot;top:-2.931em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; parameterized by &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;θ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\bm{\theta}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot; style=&quot;margin-right:0.03194em;&quot;&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; that operates on hidden representations of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;d&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;d^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; denote the hidden dimension of representations in &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, respectively. This function can be the identity function, a linear or affine function learned on task-specific pairs of representations, or even more complex functions that incorporate other sources of data&lt;a class=&quot;footstart&quot; key=&quot;transformations&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;patching&lt;/em&gt; operation refers to dynamically replacing the representation &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msubsup&gt;&lt;mover accent=&quot;true&quot;&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mo&gt;ˉ&lt;/mo&gt;&lt;/mover&gt;&lt;msup&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\bar{\bm{h}}_{i^*}^{\ell^*}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.3655em;vertical-align:-0.247em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord accent&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8312em;&quot;&gt;&lt;span style=&quot;top:-3em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2634em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;accent-body&quot; style=&quot;left:-0.25em;&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ˉ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:1.1185em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6183em;&quot;&gt;&lt;span style=&quot;top:-2.786em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2841em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7633em;&quot;&gt;&lt;span style=&quot;top:-2.931em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; during the inference of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; on &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;T&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; with &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msubsup&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;/msubsup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;f(\bm{h}_{i}^{\ell})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1834em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.
Namely, by applying &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msubsup&gt;&lt;mover accent=&quot;true&quot;&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mo&gt;ˉ&lt;/mo&gt;&lt;/mover&gt;&lt;msup&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/msubsup&gt;&lt;mo&gt;←&lt;/mo&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msubsup&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;/msubsup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;{\bar{\bm{h}}}_{i^*}^{\ell^*} \leftarrow f(\bm{h}_{i}^{\ell})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.3655em;vertical-align:-0.247em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord accent&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8312em;&quot;&gt;&lt;span style=&quot;top:-3em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2634em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;accent-body&quot; style=&quot;left:-0.25em;&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ˉ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:1.1185em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6183em;&quot;&gt;&lt;span style=&quot;top:-2.786em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2841em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7633em;&quot;&gt;&lt;span style=&quot;top:-2.931em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;←&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1834em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ℓ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, we intervene on the generation process and modify the computation after layer &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\ell^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Overall, a Patchscope intervention applied to a representation determined by &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;(S,i,M,\ell)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.05764em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;,
is defined by a quintuplet &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;(T,i^*,f, M^*,\ell^*)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; of an inspection prompt &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;T&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, a target position &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;i^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; in this prompt, a mapping function &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;f&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, a target model &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, and a target layer &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;ℓ&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\ell^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ℓ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; of this model. It is possible that &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; are the same model, &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;S&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.05764em;&quot;&gt;S&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;T&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; are the same prompt, and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;f&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is the identity function &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;double-struck&quot;&gt;I&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbb{I}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6889em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathbb&quot;&gt;I&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; (i.e., &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;double-struck&quot;&gt;I&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi mathvariant=&quot;bold-italic&quot;&gt;h&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbb{I}(\bm{h}) = \bm{h}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathbb&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord boldsymbol&quot;&gt;h&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;).&lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;author&quot;&gt;&lt;/a&gt;Equal contribution.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;author2&quot;&gt;&lt;/a&gt;Equal contribution.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;sae&quot;&gt;&lt;/a&gt;For example, &lt;a href=&quot;https://www.anthropic.com/news/mapping-mind-language-model&quot;&gt;Anthropic&lt;/a&gt; and &lt;a href=&quot;https://openai.com/index/extracting-concepts-from-gpt-4/&quot;&gt;OpenAI&lt;/a&gt; recently published work exploring how to disentangle activation vectors and think about using them to control model behavior, and Google’s &lt;a href=&quot;https://ai.google.dev/responsible&quot;&gt;Responsible Generative AI Toolkit&lt;/a&gt; includes an interpretability-based prompt-debugger to help identify mistakes in the prompts fed to LLMs.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;prompt&quot;&gt;&lt;/a&gt; To score each generation, the following prompt was used with PaLM 2 Text Unicorn as the model:
&lt;span class=&quot;code&quot;&gt;
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
How semantically similar are the following texts: &amp;lt;text_A&amp;gt; {description} &amp;lt;/text_A&amp;gt; &amp;lt;text_B&amp;gt; {generation} &amp;lt;/text_B&amp;gt;
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
Both these texts try to explain the following entity: &amp;lt;entity&amp;gt; {entity} &amp;lt;/entity&amp;gt;
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
Provide an integer rating between 1 and 10.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
1 refers to ‘not similar at all’, and 10 refers to ‘extremely similar’: &amp;lt;label&amp;gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;dataset&quot;&gt;&lt;/a&gt; The full datasets are available on &lt;a href=&quot;https://github.com/PAIR-code/interpretability/tree/master/patchscopes/code/preprocessed_data&quot;&gt;Github&lt;/a&gt;. While some of these examples are contrived to ease research evaluations, they do demonstrate the principle that rerouting hidden representations allows the model to generate more accurate conclusions.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;incorrect&quot;&gt;&lt;/a&gt;Note that the model can sometimes output incorrect information about the entity it is describing.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;probing-viz&quot;&gt;&lt;/a&gt; To get a more robust estimate of accuracy for patching, we average across five different source prompts for each example. A patching instance was considered correct if the correct answer appeared in any of the first 20 generated outputs of any target layer.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;probing-performance&quot;&gt;&lt;/a&gt; As we saw in the &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#case-study-verbalizing-the-model-s-thought-process&quot;&gt;prior case study&lt;/a&gt;, information about the input is more readily accessible in early to mid layers, before the model shifts toward next-token prediction. This explains why the performance of this simple Patchscope can drop for later source layers. In the &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#discussion-and-open-questions&quot;&gt;open questions section&lt;/a&gt;, we will discuss some strategies to improve attribute extraction accuracy in later layers by adjusting the Patchscope configurations.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;cot&quot;&gt;&lt;/a&gt; We want to caution that our primary goal in this section is not to devise a new method to solve multi-hop queries that is necessarily a competitor to CoT, but rather to make a proof-of-concept while comparing with CoT as a common reference.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;backwardpatch&quot;&gt;&lt;/a&gt;A &lt;em&gt;backward-acting&lt;/em&gt; Patchscope extracts the hidden representation from one token and injects it into a preceding token in the prompt, thus this is only possible &lt;em&gt;when the source and inspection prompts are the same&lt;/em&gt;. While the exact implications of patch directionality are unknown, we believe that this technique will be useful for understanding the information flow inside the model and may aid in identifying reasoning &lt;a href=&quot;https://transformer-circuits.pub/2021/framework/index.html&quot;&gt;circuits&lt;/a&gt;, for example.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;widget-prompt&quot;&gt;&lt;/a&gt; To generate the entity descriptions, we use the same inspection prompt as seen in the entity description case study:
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;code&quot;&gt;
Syria: Country in the Middle East, Leonardo DiCaprio: American actor, Samsung: South Korean multinational major appliance and consumer electronics corporation, x
&lt;/span&gt;
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
For each multi-hop query, we patch the hidden representation at the last token location of the selected source layer in place of the ‘x’ token of the inspection prompt at the last target layer. This generates the entity description of the hidden representation – here we are looking for some description of the correct country of origin as a checkpoint to determine whether the model will be able to answer the multi-hop query.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;placeholder-contamination&quot;&gt;&lt;/a&gt; Sometimes the remaining representation from the placeholder token in the early layers interferes with future token generations. We call this phenomenon &lt;em&gt;placeholder contamination&lt;/em&gt;. It is only relevant if one is interested in generating more than the next immediate token, and it is more likely to happen if target location is in the later layers.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;circuits&quot;&gt;&lt;/a&gt; Mechanistic interpretability work that focuses on &lt;a href=&quot;https://transformer-circuits.pub/2021/framework/index.html&quot;&gt;circuits&lt;/a&gt; is one way of understanding information flow in a model. Prior work related to &lt;a href=&quot;https://arxiv.org/pdf/2211.00593&quot;&gt;indirect object identification&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/pdf/2304.14767&quot;&gt;factual associations&lt;/a&gt; are some concrete examples of how to provide precise localization guidelines for patching configurations. Conversely, we expect that investigations that use Patchscopes may result in the identification of new circuits in LLMs.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;tokens&quot;&gt;&lt;/a&gt;Tokenization strategies are complex and highly variable. Models are trained to work with specific tokenizers, and tokenizations may be incompatible across models.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;embedding&quot;&gt;&lt;/a&gt;The models we explore in this post use a deterministic embedding process to transform the token vector into the high-dimensional space of hidden representations. Most recent LLMs—including Gemma, Llama, and Mistral—use a single embedding layer for this task.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;sequential&quot;&gt;&lt;/a&gt;Technically speaking, transformer models don’t just operate on prompt tokens one at a time. Rather, they process prompt tokens in parallel for efficiency. We visualize them here as entering sequentially to reinforce the idea that in decoder-only models, the processing of later tokens can only be influenced by earlier tokens.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;cross-model&quot;&gt;&lt;/a&gt; For simplicity, this post only covers case studies where the source and target model are the same. However, they &lt;em&gt;can&lt;/em&gt; be different, and we briefly discuss in the &lt;a href=&quot;https://pair.withgoogle.com/explorables/patchscopes/#discussion-and-open-questions&quot;&gt;open questions section&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;transformations&quot;&gt;&lt;/a&gt; Patchscopes supports applying arbitrary transformations to the hidden representation from the source location before it is injected into the target location. The examples in the post use the identity function as this transform (i.e., does nothing), but complex transforms may be necessary when patching across different models, or inspecting more complex functions.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;alain&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/1610.01644&quot;&gt;Understanding intermediate layers using linear classifier probes&lt;/a&gt; Alain, G. and Bengio, Y. , 5th International Conference on Learning Representations, Workshop Track Proceedings, 2017.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;belinkov&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2102.12452&quot;&gt;Probing Classifiers: Promises, Shortcomings, and Advances&lt;/a&gt; Belinkov, Y. Computational Linguistics, 48(1):207–219, 2022.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;belrose&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2303.08112&quot;&gt;Eliciting Latent Predictions from Transformers with the Tuned Lens&lt;/a&gt; Belrose, N., Furman, Z., Smith, L., Halawi, D., Ostrovsky, I., McKinney, L., Biderman, S., and Steinhardt, J., arXiv preprint arXiv:2303.08112, 2023.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;brown&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2005.14165&quot;&gt;Language Models are Few-Shot Learners&lt;/a&gt;
Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., Agarwal, S., Herbert-Voss, A., Krueger, G., Henighan, T., Child, R., Ramesh, A., Ziegler, D., Wu, J., Winter, C., Hesse, C., Chen, M., Sigler, E., Litwin, M., Gray, S., Chess, B., Clark, J., Berner, C., McCandlish, S., Radford, A., Sutskever, I., Amodei, D., arXiv preprint arXiv:2005:14165, 2020.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;selfie&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2403.10949&quot;&gt;SelfIE: Self-Interpretation of Large Language Model Embeddings.&lt;/a&gt; Chen, H., Vondrick, C., &amp;amp; Mao, C.. arXiv preprint arXiv:2403.10949. 2024.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;ghandeharioun&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/pdf/2401.06102.pdf&quot;&gt;Patchscopes: A Unifying Framework for Inspecting Hidden Representations of Language Models&lt;/a&gt; Ghandeharioun, A.&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mrow&gt;&lt;/mrow&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, Caciularu, A.&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mrow&gt;&lt;/mrow&gt;&lt;mo&gt;∗&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;^*&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.6887em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mbin mtight&quot;&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, Pearce, A., Dixon, L., Geva, M. ICML (to appear), 2024.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;whos-asking&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2406.12094&quot;&gt;Who’s asking? User personas and the mechanics of latent misalignment.&lt;/a&gt; Ghandeharioun, A.&lt;em&gt;, Yuan, A.&lt;/em&gt;, Guerard, M., Reif, E., Lepori, M.A., and Dixon, L., arXiv preprint arXiv:2406.12094, 2024.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;tokenization&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://aclanthology.org/2022.naacl-main.179&quot;&gt;What do tokens know about their characters and how do they know it?&lt;/a&gt; Kaushal, A., Mahowald, K. 2022. In Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2487–2507, Seattle, United States. Association for Computational Linguistics.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;meng&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2202.05262&quot;&gt;Locating and editing factual associations in GPT&lt;/a&gt; Meng, K., Bau, D., Andonian, A., and Belinkov, Y. Advances in Neural Information Processing Systems, 35:17359–17372, 2022.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;llama&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://ai.meta.com/blog/meta-llama-3/&quot;&gt;Introducing Meta Llama 3: The most capable openly available LLM to date.&lt;/a&gt; Meta, 2023.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;lesswrong&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://www.lesswrong.com/posts/AcKRB8wDpdaN6v6ru/%20interpreting-gpt-the-logit-lens&quot;&gt;Interpreting GPT: the logit lens.&lt;/a&gt; nostalgebraist, LessWrong, 2020.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;xstest&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2308.01263&quot;&gt;XSTest: A Test Suite for Identifying Exaggerated Safety Behaviours in Large Language Models.&lt;/a&gt; Röttger, P., Kirk, H.R., Vidgen, B., Attanasio, G., Bianchi, F., and Hovy, D., arXiv preprint arXiv:2308.01263, 2023.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;3b1b-attn&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=eMlx5fFNoYc&amp;amp;ab_channel=3Blue1Brown&quot;&gt;Attention in transformers, visually explained&lt;/a&gt; Sanderson, G., 3Blue1Brown, 2024.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;3b1b-transformers&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=wjZofJX0v4M&quot;&gt;But what is a GPT? Visual intro to transformers&lt;/a&gt; Sanderson, G., 3Blue1Brown, 2024.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;bert-rediscovers2019&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://aclanthology.org/P19-1452.pdf&quot;&gt;BERT Rediscovers the Classical NLP Pipeline&lt;/a&gt; Tenney, I., Das, D., Pavlick, E. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pp. 4593-4601. 2019.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;vaswani2017&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf&quot;&gt;Attention is all you need&lt;/a&gt; Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., … &amp;amp; Polosukhin, I. Advances in neural information processing systems, 30. 2017.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;bottomup2019&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://aclanthology.org/D19-1448.pdf&quot;&gt;The Bottom-up Evolution of Representations in the Transformer: A Study with Machine Translation and Language Modeling Objectives&lt;/a&gt; Voita, E., Sennrich, R., Titov, I. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), 2019.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;weiCoT&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2022/hash/9d5609613524ecf4f15af0f7b31abca4-Abstract-Conference.html&quot;&gt;Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.&lt;/a&gt; Wei, J., Wang, X., Schuurmans, D., Bosma, M., Xia, F., Chi, E., Le, Q.V. and Zhou, D.. Advances in Neural Information Processing Systems 35, 2022.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;autoeval&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2023/hash/91f18a1287b398d378ef22505bf41832-Abstract-Datasets_and_Benchmarks.html&quot;&gt;Judging llm-as-a-judge with mt-bench and chatbot arena.&lt;/a&gt; Zheng, L., Chiang, W.L., Sheng, Y., Zhuang, S., Wu, Z., Zhuang, Y., Lin, Z., Li, Z., Li, D., Xing, E. and Zhang, H. Advances in Neural Information Processing Systems 36, 2024.&lt;/p&gt;
&lt;h3 id=&quot;more-explorables&quot;&gt;More Explorables&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;
&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/footnote_v2.css&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/citation_v2.css&quot;&gt;&lt;/p&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
























</description><link>https://pair.withgoogle.com/explorables/patchscopes/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/patchscopes/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/patching-up-close.png" type="image/jpeg"></enclosure></item><item><title>Do Machine Learning Models Memorize or Generalize?</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Do Machine Learning Models Memorize or Generalize?&lt;/h1&gt;

  &lt;div class=&quot;byline&quot;&gt;
    &lt;div class=&quot;authors&quot;&gt;
      By &lt;b&gt;
      Adam Pearce&lt;/b&gt;, &lt;b&gt; Asma Ghandeharioun&lt;/b&gt;, &lt;b&gt; Nada Hussein&lt;/b&gt;, &lt;b&gt; Nithum Thain&lt;/b&gt;, &lt;b&gt; Martin Wattenberg&lt;/b&gt; and &lt;b&gt; Lucas Dixon
      &lt;/b&gt;
    &lt;/div&gt;
    &lt;div class=&quot;date&quot;&gt;August 2023&lt;/div&gt;
  &lt;/div&gt;

  
  &lt;p&gt;In 2021, researchers made a striking discovery while training a series of tiny models on toy tasks &lt;a class=&quot;citestart&quot; key=&quot;Grokking&quot;&gt;&lt;/a&gt;. They found a set of models that suddenly flipped from memorizing their training data to correctly generalizing on unseen inputs after training for much longer. This phenomenon – where generalization seems to happen abruptly and long after fitting the training data – is called &lt;em&gt;grokking&lt;/em&gt; and has sparked a flurry of interest &lt;a class=&quot;citestart&quot; key=&quot;Omnigrok Universality Zhong23 ProgressParity gromov&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;sticky-container&quot;&gt;
&lt;div class=&quot;mod-top-accuracy row sticky&quot;&gt;&lt;/div&gt;

&lt;p&gt;Do more complex models also suddenly generalize after they’re trained longer? Large language models can certainly seem like they have a rich understanding of the world, but they might just be regurgitating memorized bits of the enormous amount of text they’ve been trained on &lt;a class=&quot;citestart&quot; key=&quot;Parrots Othello&quot;&gt;&lt;/a&gt;. How can we tell if they’re generalizing or memorizing?&lt;/p&gt;
&lt;p&gt;In this article we’ll examine the training dynamics of a tiny model and reverse engineer the solution it finds – and in the process provide an illustration of the exciting emerging field of mechanistic interpretability &lt;a class=&quot;citestart&quot; key=&quot;MechInterp ProgressMeasures&quot;&gt;&lt;/a&gt;. While it isn’t yet clear how to apply these techniques to today’s largest models, starting small makes it easier to develop intuitions as we progress towards answering these critical questions about large language models.&lt;/p&gt;
&lt;h3 id=&quot;grokking-modular-addition&quot;&gt;Grokking Modular Addition&lt;/h3&gt;
&lt;p&gt;Modular addition is essentially the fruit fly of grokking.&lt;a class=&quot;footstart&quot; key=&quot;modular&quot;&gt;&lt;/a&gt; The above line chart comes from a model trained to predict &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a + b \bmod 67&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;a class=&quot;footstart&quot; key=&quot;67&quot;&gt;&lt;/a&gt; We start by randomly dividing all the &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a, b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; pairs into test and training datasets. Over thousands of training steps, the training data is used to adjust the model into outputting correct answers, while the test data is only used to check if the model has learned a general solution.&lt;/p&gt;
&lt;p&gt;The model’s architecture is similarly simple: &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ReLU&lt;/mtext&gt;&lt;mrow&gt;&lt;mo fence=&quot;true&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;a&lt;/mi&gt;&lt;mtext&gt;one-hot&lt;/mtext&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;b&lt;/mi&gt;&lt;mtext&gt;one-hot&lt;/mtext&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;mo fence=&quot;true&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ReLU}\left(\mathbf{a}_{\text{one-hot}} \mathbf{W}_{\text{input}} + \mathbf{b}_{\text{one-hot}} \mathbf{W}_{\text{input}}\right) \mathbf{W}_{\text{output}}
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0361em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ReLU&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;&lt;span class=&quot;mopen delimcenter&quot; style=&quot;top:0em;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;one-hot&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;one-hot&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose delimcenter&quot; style=&quot;top:0em;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; — a one-layer MLP with 24 neurons.&lt;a class=&quot;footstart&quot; key=&quot;playground&quot;&gt;&lt;/a&gt; All the weights of the model are shown in the heatmap below; you can see how they change during training by mousing over the line chart above.&lt;/p&gt;
&lt;div class=&quot;sticky-container&quot;&gt;
&lt;div class=&quot;mod-top-weights row x-sticky x-sticky-lower&quot;&gt;&lt;/div&gt;

&lt;p&gt;The model makes a prediction by selecting the two columns of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{input}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; corresponding to inputs &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; then adding them together to create a vector of 24 separate numbers. Next it sets all the negative numbers in the vector to 0 and finally outputs the column of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{output}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; that’s closest to the updated vector.&lt;/p&gt;
&lt;p&gt;The weights of the model are initially quite noisy but start to exhibit periodic patterns as accuracy on the test data increases and the model &lt;animate data-animate=&quot;top-switches&quot;&gt;switches&lt;/animate&gt; to generalizing. By the end of training, each neuron — each row of the heatmap — cycles through high and low values several times as the input number increases from 0 to 66.&lt;/p&gt;
&lt;p&gt;This is easier to see if we group the neurons by how often they cycle at the end of training and chart each of them as a separate line:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;div class=&quot;mod-top-waves row&quot;&gt;&lt;/div&gt;

&lt;p&gt;The periodic patterns suggest the model is learning some sort of mathematical structure; the fact that it happens when the model starts to solve the test examples hints that it’s related to the model generalizing. But &lt;em&gt;why&lt;/em&gt; does the model move away from the memorizing solution? And &lt;em&gt;what&lt;/em&gt; is the generalizing solution?&lt;/p&gt;
&lt;h3 id=&quot;generalizing-with-1s-and-0s&quot;&gt;Generalizing With 1s and 0s&lt;/h3&gt;
&lt;p&gt;Figuring out both of these questions simultaneously is hard. Let’s make an even simpler task, one where we know what the generalizing solution should look like and try to understand why the model eventually learns it.&lt;/p&gt;
&lt;p&gt;We’ll take random sequences of thirty 1s and 0s and train our model to predict if there is an odd number of 1s in the first three digits. e.g. &lt;digits&gt;000110010110001010111001001011&lt;/digits&gt; is &lt;digits&gt;0&lt;/digits&gt; while &lt;digits&gt;010110010110001010111001001011&lt;/digits&gt; is &lt;digits&gt;1&lt;/digits&gt; — basically a slightly trickier XOR with some distraction noise. A generalizing model should only use the first three digits of the sequence; if the model is memorizing the training data, it will also use the subsequent distracting digits &lt;a class=&quot;citestart&quot; key=&quot;ProgressParity TwoCircuits&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Our model is again a one-layer MLP, trained on a fixed batch of 1,200 sequences.&lt;a class=&quot;footstart&quot; key=&quot;sp-model&quot;&gt;&lt;/a&gt; At first only training accuracy increases — the model is memorizing the training data. As with modular arithmetic, test accuracy is essentially random and then sharply rises as the model learns a general solution.&lt;/p&gt;
&lt;div class=&quot;parity-accuracy row&quot;&gt;&lt;/div&gt;

&lt;p&gt;While &lt;animate data-animate=&quot;sp-mem&quot;&gt;memorizing&lt;/animate&gt; , the model looks dense and noisy with lots of high magnitude weights (shown as dark red and blue squares) spread across the chart below – the model is using all the inputs to make a prediction. As the model &lt;animate data-animate=&quot;sp-gen&quot;&gt;generalizes&lt;/animate&gt; and gets perfect test accuracy, we see all the weights connected to the distracting digits gray out with very low values and the model focusing on the first three digits — mirroring the generalized structure we expected!&lt;a class=&quot;footstart&quot; key=&quot;sp-solution&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;parity-weights row&quot;&gt;&lt;/div&gt;

&lt;p&gt;With this simplified example it’s easier to see why this happens: we’re pushing our model to do two things during training — output a high probability for the correct label (called minimizing &lt;em&gt;loss&lt;/em&gt; &lt;a class=&quot;footstart&quot; key=&quot;loss&quot;&gt;&lt;/a&gt;) and have weights with low magnitudes (known as &lt;em&gt;weight decay&lt;/em&gt; &lt;a class=&quot;footstart&quot; key=&quot;sp-l2&quot;&gt;&lt;/a&gt;). &lt;span class=&quot;inline-train&quot;&gt;Train loss&lt;/span&gt; actually slightly increases before the model generalizes as it exchanges loss related to outputting the correct label for having lower weights.&lt;/p&gt;
&lt;div class=&quot;parity-loss row&quot;&gt;&lt;/div&gt;

&lt;p&gt;The sharp drop in &lt;span class=&quot;inline-test&quot;&gt;test loss&lt;/span&gt; makes it appear like the model makes a sudden shift to generalization. But if we look at the weights of the model over training, most of them smoothly interpolate between the two solutions. The rapid generalization occurs when the last weights connected to the distracting digits are pruned by weight decay.&lt;/p&gt;
&lt;div class=&quot;parity-weights-trajectory row&quot;&gt;&lt;/div&gt;

&lt;h3 id=&quot;when-does-grokking-happen-&quot;&gt;When Does Grokking Happen?&lt;/h3&gt;
&lt;p&gt;It’s important to note that grokking is a contingent phenomenon — it goes away if model size, weight decay, data size and other hyper parameters aren’t just right. With too little weight decay, the model can’t escape overfitting the training data.&lt;a class=&quot;footstart&quot; key=&quot;overfit&quot;&gt;&lt;/a&gt; Adding more weight decay pushes the model to generalize after memorizing. Increasing weight decay even more causes test and train loss to fall together; the model goes straight to generalizing. And with too much weight decay the model will fail to learn anything.&lt;/p&gt;
&lt;p&gt;Below, we’ve trained over a thousand models on the 1s and 0s task with different hyperparameters. Training is noisy so nine models have been trained for each set of hyperparameters.&lt;/p&gt;
&lt;div class=&quot;sparse-parity-sweep&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;p&gt;We can induce memorization and generalization on this somewhat contrived 1s and 0s task — but why does it happen with modular addition? Let’s first understand a little more about how a one-layer MLP can solve modular addition by constructing a generalizing solution that’s interpretable.&lt;/p&gt;
&lt;h3 id=&quot;modular-addition-with-five-neurons&quot;&gt;Modular Addition With Five Neurons&lt;/h3&gt;
&lt;p&gt;Recall that our modular arithmetic problem &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a + b \bmod 67&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is naturally periodic, with answers wrapping around if the sum ever passes 67. Mathematically, this can be mirrored by thinking of the sum as wrapping &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; around a circle. The weights of the generalizing model also had periodic patterns, indicating that the solution might use this property.&lt;/p&gt;
&lt;p&gt;We can train a simpler model with a head start on the problem, constructing an embedding matrix that places &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; on a circle by computing &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sin&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6679em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; for each possible input number &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mn&gt;66&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;i \in \{0, 1, \ldots, 66\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6986em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;66&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;a class=&quot;footstart&quot; key=&quot;unit-circle&quot;&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class=&quot;row&quot;&gt;&lt;div class=&quot;embed&quot;&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
Then we train &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{in-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;out-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{out-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;out-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; in this one-layer MLP:&lt;/p&gt;


&lt;p&gt;With just five neurons the model finds a solution with perfect accuracy.&lt;/p&gt;
&lt;div class=&quot;sticky-container&quot;&gt;
&lt;div class=&quot;five-neuron-accuracy row sticky&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;five-neuron-embed row&quot;&gt;&lt;/div&gt;

&lt;p&gt;Eyeballing the trained parameters, all the neurons &lt;animate data-animate=&quot;five-neuron-converge&quot;&gt;converge&lt;/animate&gt; to roughly equal norms. If we directly plot their &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sin&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6679em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; components, they’re essentially evenly distributed around a circle:&lt;/p&gt;
&lt;div class=&quot;five-neuron-circle row&quot;&gt;&lt;/div&gt;

&lt;p&gt;Connect the adjacent neurons on the &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{in-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; circle and an intriguing pattern emerges: &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;out-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{out-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;out-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is rotating around the circle twice as fast as &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{in-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;div class=&quot;five-neuron-circle-2 row&quot;&gt;&lt;/div&gt;

&lt;p&gt;The details of how this solution works aren’t essential —  check out &lt;a href=&quot;https://pair.withgoogle.com/explorables/grokking/#appendix-a-how-the-circular-construction-works&quot;&gt;Appendix A&lt;/a&gt; to see how the doubled rotation allows the model to map inputs like &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;1 + 0 \bmod 67&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7278em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;66&lt;/mn&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;2 + 66 \bmod 67&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7278em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;66&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; to the same place — but we have found a 20 parameter construction that solves modular addition. Can we find the same algorithm hidden in the 3,216 parameter model we started with? And why does the larger model switch to the generalizing solution after memorizing?&lt;/p&gt;
&lt;h3 id=&quot;it-s-full-of-stars&quot;&gt;It’s Full of Stars&lt;/h3&gt;
&lt;p&gt;Here’s the &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a + b \bmod 67&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; model that we started with — it’s trained from scratch with no built-in periodicity.&lt;/p&gt;
&lt;div class=&quot;sticky-container&quot;&gt;
&lt;div class=&quot;mod-bot-accuracy sticky&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;mod-bot-waves row&quot;&gt;&lt;/div&gt;

&lt;p&gt;Unlike the constructed solution, where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{embed}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8361em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; rotates around the circle once, this model has many different frequencies.&lt;/p&gt;
&lt;p&gt;Below, we’ve isolated the frequencies using the discrete Fourier transform (DFT).&lt;a class=&quot;footstart&quot; key=&quot;dft&quot;&gt;&lt;/a&gt;  This factors out the learned periodic patterns across inputs, leaving us with the equivalent of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{in-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;out-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{out-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;out-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; from the constructed solution. For each neuron, this gives a &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sin&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6679em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; value for every possible periodic frequency from 1 to 33. The wave charts we show above use this to group neurons into frequencies by finding their largest &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sin&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6679em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; value across all frequencies.&lt;a class=&quot;footstart&quot; key=&quot;dft-sort&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;mod-bot-dft row&quot;&gt;&lt;/div&gt;

&lt;p&gt;Just like in the 1s and 0s task, weight decay encourages this representation to become much sparser as the model &lt;animate data-animate=&quot;bot-gen&quot;&gt;generalizes&lt;/animate&gt; .&lt;/p&gt;
&lt;p&gt;Grouping neurons by their final trained frequencies, and plotting the &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sin&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6679em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; components of the DFT for each neuron, we see the same star shapes from the constructed solution appear.&lt;/p&gt;
&lt;div class=&quot;mod-bot-freqs-hidden row&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;mod-bot-freqs-out row&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;This trained model is using the same algorithm as our constructed solution!&lt;/strong&gt; Below, the contribution to the output generated by the neurons in each frequency are shown and we can see them calculating  &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;π&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;/mrow&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt; \cos\frac{2\pi (a +  b) freq}{67}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.355em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:1.01em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.485em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;π&lt;/span&gt;&lt;span class=&quot;mopen mtight&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mclose mtight&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.10764em;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;q&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; .&lt;a class=&quot;footstart&quot; key=&quot;logit-wave&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;mod-bot-hide-on-sweep-change&quot;&gt;Notice what happens to the group of neurons with a frequency of 7 when test loss &lt;animate data-animate=&quot;bot-improve&quot;&gt;improves&lt;/animate&gt; after the short plateau at 45,000 steps — they start to snap into a star shape and their outputs more closely approximate a wave.&lt;/p&gt;
&lt;div class=&quot;row mod-bot-sliders&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;row mod-bot-logits&quot;&gt;&lt;/div&gt;

&lt;p&gt;To lower loss without using higher weights (which would be punished by weight decay), the model uses several frequencies, taking advantage of constructive interference.&lt;a class=&quot;citestart&quot; key=&quot;ProgressMeasures&quot;&gt;&lt;/a&gt; There’s nothing magical about the frequencies 4, 5, 7 and 26 — click through other training runs below to see variations of this algorithm get learned.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;div class=&quot;row mod-bot-seeds&quot;&gt;&lt;/div&gt;

&lt;h3 id=&quot;open-questions&quot;&gt;Open Questions&lt;/h3&gt;
&lt;p&gt;While we now have a solid understanding of the mechanisms a one-layer MLP uses to solve modular addition and why they emerge during training, there are still many interesting open questions about memorization and generalization.&lt;/p&gt;
&lt;h4 id=&quot;which-model-constraints-work-best-&quot;&gt;Which Model Constraints Work Best?&lt;/h4&gt;
&lt;p&gt;Directly training the model visualized above — &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ReLU&lt;/mtext&gt;&lt;mrow&gt;&lt;mo fence=&quot;true&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mtext&gt;one-hot&lt;/mtext&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt;one-hot&lt;/mtext&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;mo fence=&quot;true&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ReLU} \left(a_{\text{one-hot}}\textbf{W}_{\text{input}} + b_{\text{one-hot}}\textbf{W}_{\text{input}} \right) \textbf{W}_{\text{output}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0361em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ReLU&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;&lt;span class=&quot;mopen delimcenter&quot; style=&quot;top:0em;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;one-hot&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;one-hot&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose delimcenter&quot; style=&quot;top:0em;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; — does not actually result in generalization on modular arithmetic, even with the addition of weight decay. At least one of the matrices has to be factored:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\textbf{W}_{\text{input}} = \mathbf{W}_{\text{embed}} \mathbf{W}_{\text{in-proj}}
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;out-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;msubsup&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;⊤&lt;/mi&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\textbf{W}_{\text{output}} = \textbf{W}_{\text{out-proj}} \textbf{W}_{\text{embed}}^{\top}
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2112em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;out-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9251em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.139em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;⊤&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We observed that the generalizing solution is sparse after taking the discrete Fourier transformation, but the collapsed matrices have high norms. This suggests that direct weight decay on &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_\text{output}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_{\text{input}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; doesn’t provide the right inductive bias for the task.&lt;/p&gt;
&lt;p&gt;Broadly speaking, weight decay does steer a wide variety of models away from memorizing their training data &lt;a class=&quot;citestart&quot; key=&quot;DoubleDescent double-demystified&quot;&gt;&lt;/a&gt;. Other techniques that help avoid overfitting include dropout, smaller models and even numerically unstable optimization algorithms &lt;a class=&quot;citestart&quot; key=&quot;Slingshot&quot;&gt;&lt;/a&gt;. These approaches interact in complex, non-linear ways, making it difficult to predict &lt;em&gt;a priori&lt;/em&gt; which will ultimately induce generalization. Collapsing &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{embed}} \mathbf{W}_{\text{in-proj}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; instead of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;out-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;msubsup&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;⊤&lt;/mi&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_{\text{out-proj}} \textbf{W}_{\text{embed}}^{\top}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2112em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;out-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9251em;&quot;&gt;&lt;span style=&quot;top:-2.453em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.139em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;⊤&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.247em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, for example, helps in some setups and hurts in others:&lt;/p&gt;
&lt;div class=&quot;sweep-mod&quot;&gt;&lt;/div&gt;

&lt;h4 id=&quot;why-is-memorization-easier-than-generalization-&quot;&gt;Why Is Memorization Easier Than Generalization?&lt;/h4&gt;
&lt;p&gt;One theory: there can be many more ways to memorize a training set than there are generalizing solutions. So statistically, memorization should be more likely to happen first, especially if we have no or little regularization. Regularization techniques, like weight decay, prioritize certain solutions over others, for example, preferring “sparse” solutions over “dense” ones.&lt;/p&gt;
&lt;p&gt;Recent work suggests that generalization is associated with well-structured representations &lt;a class=&quot;citestart&quot; key=&quot;EffectiveTheory&quot;&gt;&lt;/a&gt;. However, it’s not a necessary condition; some MLP variations without symmetric inputs learn less “circular” representations when solving modular addition &lt;a class=&quot;citestart&quot; key=&quot;Zhong23&quot;&gt;&lt;/a&gt;. We also observed that well-structured representations are not a sufficient condition for generalization. This small model (trained with no weight decay) starts generalizing, then switches to memorizing with periodic embeddings.&lt;/p&gt;
&lt;div class=&quot;open-q-mem-0-accuracy row&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;open-q-mem-0-weights  row&quot;&gt;&lt;/div&gt;

&lt;p&gt;It’s even possible to find hyperparameters where models start generalizing, then switch to memorizing, then switch back to generalizing! &lt;a class=&quot;footstart&quot; key=&quot;open-q-mem&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;open-q-mem-1-accuracy row&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;open-q-mem-1-weights  row&quot;&gt;&lt;/div&gt;

&lt;h4 id=&quot;what-about-larger-models-&quot;&gt;What About Larger Models?&lt;/h4&gt;
&lt;p&gt;Does grokking happen in larger models trained on real world tasks? Earlier observations reported the grokking phenomenon in algorithmic tasks in small transformers and MLPs &lt;a class=&quot;citestart&quot; key=&quot;Grokking ProgressMeasures Zhong23&quot;&gt;&lt;/a&gt;. Grokking has subsequently been found in more complex tasks involving images, text, and tabular data within certain ranges of hyperparameters &lt;a class=&quot;citestart&quot; key=&quot;Omnigrok Goldilocks&quot;&gt;&lt;/a&gt;. It’s also possible that the largest models, which are able to do many types of tasks, may be grokking many things at different speeds during training &lt;a class=&quot;citestart&quot; key=&quot;quantization&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There have also been promising results in predicting grokking before it happens. Though some require knowledge of the generalizing solution &lt;a class=&quot;citestart&quot; key=&quot;ProgressMeasures&quot;&gt;&lt;/a&gt; or the overall data domain &lt;a class=&quot;citestart&quot; key=&quot;StructuralGrokking&quot;&gt;&lt;/a&gt;, some rely solely on the analysis of the training loss &lt;a class=&quot;citestart&quot; key=&quot;PredictingGrokking&quot;&gt;&lt;/a&gt; and might also apply to larger models — hopefully we’ll be able to build tools and techniques that can tell us when a model is parroting memorized information and when it’s using richer models.&lt;/p&gt;
&lt;p&gt;Understanding the solution to modular addition wasn’t trivial. Do we have any hope of understanding larger models? One route forward — like our digression into the 20 parameter model and the even simpler boolean parity problem — is to: 1) train simpler models with more inductive biases and fewer moving parts, 2) use them to explain inscrutable parts of how a larger model works, 3) repeat as needed. We believe this could be a fruitful approach to better understanding larger models, and complementary to efforts that aim to use larger models to explain smaller ones and other work to disentangle internal representations &lt;a class=&quot;citestart&quot; key=&quot;explain multiple-choice TMOS&quot;&gt;&lt;/a&gt;. Moreover, this kind of mechanistic approach to interpretability, in time, may help identify patterns that themselves ease or automate the uncovering of algorithms learned by neural networks.&lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Thanks to Ardavan Saeedi, Crystal Qian, Emily Reif, Fernanda Viégas, Kathy Meier-Hellstern, Mahima Pushkarna, Minsuk Chang, Neel Nanda and Ryan Mullins for their help with this piece.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/PAIR-code/ai-explorables/tree/master/server-side/grokking&quot;&gt;Model training code&lt;/a&gt; // &lt;a href=&quot;https://github.com/PAIR-code/ai-explorables/tree/master/source/grokking&quot;&gt;Visualization code&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;appendix-a-how-the-circular-construction-works&quot;&gt;Appendix A: How the Circular Construction Works&lt;/h3&gt;
&lt;p&gt;We can almost calculate &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a + b  \bmod 67&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; using two circular embeddings and a completely linear model.&lt;/p&gt;
&lt;div class=&quot;sticky-container&quot;&gt;
&lt;div class=&quot;slider-container row sticky appendix&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;circle-vis row&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;&lt;p&gt;It works! But we’re cheating a bit, do you see how &lt;strong&gt;unembed&lt;/strong&gt; loops around the circle twice? We need to output a single prediction for “&lt;v&gt;&lt;/v&gt;“ — not separate predictions for “&lt;v&gt;&lt;/v&gt;“ and “&lt;v2&gt;&lt;/v2&gt;“. Directly adding the two predictions for a number together won’t work since they’re on opposite sides of the circles and will cancel each other out.&lt;/p&gt;
&lt;p&gt;Instead, let’s incorporate a &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ReLU&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ReLU}(x)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ReLU&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; to fix the repeated outputs.&lt;/p&gt;
&lt;div class=&quot;proj-vis row&quot;&gt;&lt;/div&gt;

&lt;p&gt;We’ve essentially wrapped the circle around in on itself and the model outputs a single prediction for “&lt;v&gt;&lt;/v&gt;“.&lt;/p&gt;
&lt;p&gt;Formally, this is the constructed model:&lt;/p&gt;


&lt;p&gt;With modulus &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;N&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; evenly spaced neurons/directions:&lt;/p&gt;


&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Interestingly this circle has a few wrinkles: this construction doesn’t give an exact answer!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;div class=&quot;debug-vis row&quot;&gt;&lt;/div&gt;

&lt;div class=&quot;appendix num-inputs row&quot;&gt;
  &lt;span&gt;Neurons &lt;input type=&quot;number&quot; class=&quot;n_neurons&quot; min=&quot;3&quot; max=&quot;10&quot; value=&quot;5&quot;&gt;&lt;/span&gt;
  &lt;span&gt;Modulus &lt;input type=&quot;number&quot; class=&quot;modulus&quot; min=&quot;12&quot; max=&quot;500&quot; value=&quot;67&quot;&gt;&lt;/span&gt;
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Using &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x^2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; instead of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ReLU&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ReLU}(x)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ReLU&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; as the activation function, as suggested by &lt;a class=&quot;citestart&quot; key=&quot;gromov&quot;&gt;&lt;/a&gt; gives a provably exact solution!&lt;/p&gt;
&lt;p&gt;For simplicity, let &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo&gt;:&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;π&lt;/mi&gt;&lt;/mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\omega:=\frac{2\pi}{M}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;ω&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1901em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8451em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.394em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; (the angle between numbers in &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{embed}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8361em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;) and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;mo&gt;:&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;π&lt;/mi&gt;&lt;/mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\theta := \frac{2\pi}{N}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;θ&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1901em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8451em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.10903em;&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.394em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; (the angle between neurons in &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msubsup&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{in-proj}}^T&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2419em;vertical-align:-0.4006em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8413em;&quot;&gt;&lt;span style=&quot;top:-2.4355em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.4006em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;Let’s rewrite &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mtext&gt;logits&lt;/mtext&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{logits}^{a, b}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1279em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;logits&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mpunct mtight&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; as an &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;-dimensional vector &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;∥&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;l&lt;/mi&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;∥&lt;/mo&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt; \lVert \it{l} \rVert ^M &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0913em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;∥&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathit&quot;&gt;l&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;&lt;span class=&quot;mclose&quot;&gt;∥&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8413em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathit mtight&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; where:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;l&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msubsup&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msubsup&gt;&lt;mo fence=&quot;true&quot; stretchy=&quot;true&quot; minsize=&quot;2.4em&quot; maxsize=&quot;2.4em&quot;&gt;(&lt;/mo&gt;&lt;mo fence=&quot;true&quot; stretchy=&quot;true&quot; minsize=&quot;1.2em&quot; maxsize=&quot;1.2em&quot;&gt;[&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;msup&gt;&lt;mo fence=&quot;true&quot; stretchy=&quot;true&quot; minsize=&quot;1.2em&quot; maxsize=&quot;1.2em&quot;&gt;]&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo fence=&quot;true&quot; stretchy=&quot;true&quot; minsize=&quot;2.4em&quot; maxsize=&quot;2.4em&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;l_{j} = \sum_{i=0}^{N-1} \biggl(\bigl[ \cos(a\omega-i\theta) + \cos(b\omega-i\theta) \bigl]^2\cos(j\omega-2i\theta)) \biggr) &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9805em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.01968em;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0197em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.05724em;&quot;&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:2.4em;vertical-align:-0.95em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop op-symbol small-op&quot; style=&quot;position:relative;top:0em;&quot;&gt;∑&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9812em;&quot;&gt;&lt;span style=&quot;top:-2.4003em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mrel mtight&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2029em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.10903em;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2997em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;delimsizing size3&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;delimsizing size1&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;aω&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;θ&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;bω&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.404em;vertical-align:-0.35em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;θ&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;delimsizing size1&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:1.054em;&quot;&gt;&lt;span style=&quot;top:-3.3029em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;jω&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:2.4em;vertical-align:-0.95em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;θ&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;&lt;span class=&quot;delimsizing size3&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This follows from the &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mtext&gt;logits&lt;/mtext&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{logits}^{a,b}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1279em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;logits&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mpunct mtight&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; equation above by plugging in the definitions of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;in-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_\text{in-proj}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;in-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;out-proj&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_\text{out-proj}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;out-proj&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and applying the trigonometric identity that &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos(x)\cos(y) + \sin(x)\sin(y) = \cos(x-y)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;We can then prove the following:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;arg max&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;/msub&gt;&lt;mtext&gt; ⁣&lt;/mtext&gt;&lt;msup&gt;&lt;mtext&gt;logits&lt;/mtext&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\argmax_c \! \text{logits}^{a,b} = a + b \bmod M
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1776em;vertical-align:-0.2441em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mord mathrm&quot; style=&quot;margin-right:0.01389em;&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathrm&quot;&gt;max&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.0573em;&quot;&gt;&lt;span style=&quot;top:-2.4559em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;c&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2441em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:-0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;logits&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mpunct mtight&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Applying the two trigonometric identities of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mfrac&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mfrac&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos(x) + \cos(y) = 2 \cos(\frac{x-y}{2}) \cos(\frac{x+y}{2})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1994em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8544em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8544em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;/&lt;/mi&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;mo fence=&quot;true&quot; stretchy=&quot;true&quot; minsize=&quot;1.2em&quot; maxsize=&quot;1.2em&quot;&gt;[&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo fence=&quot;true&quot; stretchy=&quot;true&quot; minsize=&quot;1.2em&quot; maxsize=&quot;1.2em&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos^2(x)cos(y) = 1/4 \bigl[ 2\cos(y) + \cos(2x-y) + \cos (2x+y) \bigl] &lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0641em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2em;vertical-align:-0.35em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1/4&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;delimsizing size1&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2em;vertical-align:-0.35em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;delimsizing size1&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, we have:&lt;/p&gt;


&lt;p&gt;Note that &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;γ&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sum \cos(\gamma_{i})=0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop op-symbol small-op&quot; style=&quot;position:relative;top:0em;&quot;&gt;∑&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.05556em;&quot;&gt;γ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0556em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;γ&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\gamma_{i}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.05556em;&quot;&gt;γ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0556em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is equally spread around the circle. The first and the third sum terms wrap around the circle with &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;2\theta&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;4\theta&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; increments respectively. The sum of the first terms equals zero for &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;mo&gt;&amp;gt;&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;N \gt 2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7224em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and the sum of the third terms equals zero for &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;mo&gt;&amp;gt;&lt;/mo&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;N \gt 4&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7224em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. Therefore, we have:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mtext&gt;logits&lt;/mtext&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/mfrac&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;
\text{logits}^{a,b} =  \cos^2(\frac{a-b}{2}\omega) \cos((a+b-c)\omega)
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1279em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;logits&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9334em;&quot;&gt;&lt;span style=&quot;top:-3.1473em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mpunct mtight&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2251em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8801em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.394em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;ω&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7778em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;ω&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Since the first term is a positive constant w.r.t inputs, the equation is maximized when &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi&gt;ω&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos((a+b-c)\omega)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7778em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;ω&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is maximized, which is when &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo lspace=&quot;0.22em&quot; rspace=&quot;0.22em&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;m&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;o&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;d&lt;/mi&gt;&lt;/mrow&gt;&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;c = a + b \bmod M&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathrm&quot;&gt;mod&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.0556em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Essentially &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ReLU&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ReLU}(x)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ReLU&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; activations with weight decay (a very typical model setup) gives the model an inductive bias that’s close enough to the exact generalizing solution of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x^2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; activations with a sparse discrete Fourier transform to push in the direction of generalization but not so close that it won’t also learn to fit the training data with memorization.&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;modular&quot;&gt;&lt;/a&gt; In modular addition, we have two input numbers, &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, and a modulus &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. We want to find the remainder of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;a + b&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; when divided by &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
This type of addition is often called clock-face addition, because when adding two times, we often report the result modulo 12 (i.e. 5 hours after 8 o’clock is 1 o’clock).
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
Modular addition sounds simple and it is. We can easily train 1,000s of models and treat them like fruit flies in neuroscience: small enough such that it is feasible to extract their &lt;a href=&quot;https://www.science.org/doi/abs/10.1126/science.add9330&quot;&gt;connectome&lt;/a&gt; synapse-by-synapse, yet providing new interesting insights about the system more broadly. We can get a good understanding of the small models we’ve trained by visualizing all their internals.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;67&quot;&gt;&lt;/a&gt;67 isn’t a magic number – we could pick many numbers to illustrate grokking, but 67 is not so small that the task is trivial and also not so large that the visualizations are overwhelming.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;playground&quot;&gt;&lt;/a&gt;
The model is trained with cross-entropy loss, AdamW and full batches. The &lt;a href=&quot;https://pair.withgoogle.com/explorables/grokking/#which-model-constraints-work-best-&quot;&gt;section on regularization&lt;/a&gt; and &lt;a href=&quot;https://colab.research.google.com/github/PAIR-code/ai-explorables/blob/master/server-side/grokking/MLP_Modular_Addition.ipynb&quot;&gt;training colab&lt;/a&gt; have additional details.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
If you’re not familiar with &lt;a href=&quot;https://en.wikipedia.org/wiki/Multilayer_perceptron&quot;&gt;MLPs&lt;/a&gt;, &lt;a href=&quot;http://playground.tensorflow.org/&quot;&gt;playground.tensorflow.org&lt;/a&gt; is a great place to start.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
A quick notation explanation: The columns of  &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{input}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and  &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;ouput&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{ouput}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;ouput&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; represent the numbers from 0 to 66.  &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;a&lt;/mi&gt;&lt;mtext&gt;one-hot&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{a}_{\text{one-hot}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.5944em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;one-hot&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;b&lt;/mi&gt;&lt;mtext&gt;one-hot&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{b}_{\text{one-hot}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;one-hot&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; are how we &lt;a href=&quot;https://en.wikipedia.org/wiki/One-hot&quot;&gt;encode&lt;/a&gt; the model’s inputs; each pick a single column from &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{input}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ReLU&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ReLU}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ReLU&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; replaces negative numbers with 0s; it is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Rectifier_(neural_networks&quot;&gt;fancy&lt;/a&gt;) way of writing &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;max&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\max(x, 0)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;sp-model&quot;&gt;&lt;/a&gt; With a small twist — we’re only outputting 1 or 0, so &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{output}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; can be a single column. In the modular addition task we needed a column for every output number.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
The last column of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;W&lt;/mi&gt;&lt;mtext&gt;input&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\mathbf{W}_{\text{input}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;W&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3175em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.016em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;input&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is also fixed to 1 to provide a &lt;a href=&quot;https://stackoverflow.com/questions/2480650/what-is-the-role-of-the-bias-in-neural-networks&quot;&gt;bias term&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;sp-solution&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/pdf/2303.11873.pdf#page=8&quot;&gt;Appendix D&lt;/a&gt; of “A Tale of Two Circuits: Grokking as Competition of Sparse and Dense Subnetworks” has an explanation of the 4 neuron solution generalizing solution here&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;loss&quot;&gt;&lt;/a&gt; So far we’ve been charting &lt;a href=&quot;https://developers.google.com/machine-learning/crash-course/classification/accuracy&quot;&gt;accuracy&lt;/a&gt;, the percentage of sequences where the correct label is the most likely. Training typically instead optimizes a differentiable objective function. All the models in this post use &lt;a href=&quot;https://ml-cheatsheet.readthedocs.io/en/latest/loss_functions.html&quot;&gt;cross entropy loss&lt;/a&gt; which heavily penalizes incorrect predictions with high probabilities.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
Note that while some formulations of loss include a weight decay or regularization term, the loss plots here depict the cross entropy component alone.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;sp-l2&quot;&gt;&lt;/a&gt;
On the 1s and 0s task here, we use L1 weight decay &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;w&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;msub&gt;&lt;mi&gt;w&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;L1(\mathbf{w}) = \sum_{i} |w_i|&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0497em;vertical-align:-0.2997em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop op-symbol small-op&quot; style=&quot;position:relative;top:0em;&quot;&gt;∑&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.162em;&quot;&gt;&lt;span style=&quot;top:-2.4003em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2997em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02691em;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0269em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
L2 weight decay &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;w&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;msubsup&gt;&lt;mi&gt;w&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msubsup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;L2(\mathbf{w}) = \sum_{i} w_i^2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathbf&quot; style=&quot;margin-right:0.01597em;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1138em;vertical-align:-0.2997em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop op-symbol small-op&quot; style=&quot;position:relative;top:0em;&quot;&gt;∑&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.162em;&quot;&gt;&lt;span style=&quot;top:-2.4003em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2997em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02691em;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8141em;&quot;&gt;&lt;span style=&quot;top:-2.4413em;margin-left:-0.0269em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2587em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is a more typical choice. It pushes for &lt;a href=&quot;https://explained.ai/regularization/L1vsL2.html&quot;&gt;lots of small weights&lt;/a&gt; leading to redundant neurons on this task:
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
&lt;img src=&quot;https://pair.withgoogle.com/explorables/grokking/img/sp-l2.gif&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;overfit&quot;&gt;&lt;/a&gt; A model overfits the training data when it performs well on the training data but poorly on the test data — this is what we see with our memorizing models. In general, simpler models are less prone to overfitting as, due to their simplicity, decision rules are coarser and are required to make more generalizations. Of course, if a model is too simple for a task, it may not be able to learn good decision rules that capture the nuances of the task. Researchers force models to be simpler through a variety of techniques, including having models with fewer parameters or encouraging the parameters that the model does have to be small in size with weight decay.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;unit-circle&quot;&gt;&lt;/a&gt;
Computing &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;cos&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;π&lt;/mi&gt;&lt;/mrow&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mfrac&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\cos(i\frac{2\pi}{67})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1901em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8451em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.394em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;sin&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;π&lt;/mi&gt;&lt;/mrow&gt;&lt;mn&gt;67&lt;/mn&gt;&lt;/mfrac&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sin (i\frac{2\pi}{67})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1901em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8451em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;67&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.394em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.03588em;&quot;&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; gives us points evenly spaced around the unit circle.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
Here’s what &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_{\text{embed}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8361em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; looks like on the unit circle:
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
&lt;img src=&quot;https://pair.withgoogle.com/explorables/grokking/img/w_embed.png&quot; width=&quot;319&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;dft&quot;&gt;&lt;/a&gt; The &lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;Discrete Fourier Transform&lt;/a&gt; helps analyze the periodic nature of a sequence of values (in this case the &lt;a href=&quot;https://colab.research.google.com/drive/1F6_1_cWXE5M7WocUcpQWp3v8z4b1jL20#scrollTo=iSPxi3ElsujY&quot;&gt;weights for a particular neuron&lt;/a&gt;) by breaking it down into sine and cosine functions. The more periodic a function is, the easier it is to represent with sine and cosines, and the sparser the output of the DFT.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;dft-sort&quot;&gt;&lt;/a&gt; We’ve reindexed the neurons by their final frequency and phase to make this grouping easier to see .&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;logit-wave&quot;&gt;&lt;/a&gt;
The model generates probabilities by taking the dot product of the neuron activations for a given input with &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;output&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_{\text{output}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.9722em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2806em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;output&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and softmaxing. If we calculate the dot product using only the activations from neurons of a single frequency, we can see which outputs the frequency group is making more or less likely.
&lt;span class=&quot;fn-break&quot;&gt;&lt;/span&gt;
&lt;a href=&quot;https://pair.withgoogle.com/explorables/grokking/#appendix-a-how-the-circular-construction-works&quot;&gt;Appendix A&lt;/a&gt; explains why these logits form a wave — each group of frequencies is essentially outputting how close the correct answer is to every number on a version of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext mathvariant=&quot;bold&quot;&gt;W&lt;/mtext&gt;&lt;mtext&gt;embed&lt;/mtext&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textbf{W}_{\text{embed}}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8361em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord textbf&quot;&gt;W&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3361em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;embed&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; with the group’s frequency.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot; key=&quot;open-q-mem&quot;&gt;&lt;/a&gt;Both of these models are &lt;a href=&quot;https://colab.sandbox.google.com/github/PAIR-code/ai-explorables/blob/master/server-side/grokking/MLP_Modular_Addition.ipynb#scrollTo=5hJqK4jx0vC7&quot;&gt;quite small&lt;/a&gt;. The bottom model has tweaked hyperparameters to encourage eventual generalization: it’s slightly larger to allow it to exit local minimums, it has more training data (making low loss memorizing solutions harder to find) and it has weight decay.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Grokking&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/pdf/2201.02177.pdf&quot;&gt;Grokking: Generalization Beyond Overfitting On Small Algorithmic Datasets&lt;/a&gt;
Power, A., Burda, Y., Edwards, H., Babuschkin, I., &amp;amp; Misra, V. (2022). arXiv preprint arXiv:2201.02177.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Omnigrok&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/pdf/2210.01117.pdf&quot;&gt;Omnigrok: Grokking Beyond Algorithmic Data&lt;/a&gt;
Liu, Z., Michaud, E. J., &amp;amp; Tegmark, M. (2022, September). In The Eleventh International Conference on Learning Representations.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Universality&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2302.03025&quot;&gt;A Toy Model of Universality: Reverse Engineering How Networks Learn Group Operations&lt;/a&gt;
Chughtai, B., Chan, L., Nanda, N.  (2023). International Conference on Machine Learning.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Zhong23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/pdf/2306.17844.pdf&quot;&gt;The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networks&lt;/a&gt;
Zhong, Z., Liu, Z., Tegmark, M., &amp;amp; Andreas, J. (2023). arXiv preprint arXiv:2306.17844.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;ProgressParity&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2207.08799&quot;&gt;Hidden Progress in Deep Learning: SGD Learns Parities Near the Computational Limit&lt;/a&gt;
Boaz Barak, Benjamin L. Edelman, Surbhi Goel, Sham Kakade, Eran Malach, Cyril Zhang. (2022) Advances in Neural Information Processing Systems, 35, 21750-21764.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;gromov&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2301.02679&quot;&gt;Grokking modular arithmetic&lt;/a&gt; Andrey Gromov (2023). arXiv preprint arXiv:2301.02679.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Parrots&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://dl.acm.org/doi/pdf/10.1145/3442188.3445922?uuid=f2qngt2LcFCbgtaZ2024&quot;&gt;On the Dangers of Stochastic Parrots: Can Language Models Be Too Big?🦜&lt;/a&gt; Bender, E. M., Gebru, T., McMillan-Major, A., &amp;amp; Shmitchell, S. (2021, March). &lt;em&gt;In Proceedings of the 2021 ACM conference on fairness, accountability, and transparency&lt;/em&gt; (pp. 610-623).&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Othello&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://openreview.net/pdf?id=DeG07_TcZvT&quot;&gt;Emergent World Representations: Exploring a Sequence Model Trained on a Synthetic Task&lt;/a&gt; Li, K., Hopkins, A. K., Bau, D., Viégas, F., Pfister, H., &amp;amp; Wattenberg, M. (2022, September). &lt;em&gt;In The Eleventh International Conference on Learning Representations&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;MechInterp&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://transformer-circuits.pub/2022/mech-interp-essay/index.html&quot;&gt;Mechanistic Interpretability, Variables, and the Importance of Interpretable Bases&lt;/a&gt;
Olah, C., 2022. Transformer Circuits Thread.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;ProgressMeasures&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://openreview.net/pdf?id=9XFSbDPmdW&quot;&gt;Progress Measures for Grokking via Mechanistic Interpretability&lt;/a&gt;
Nanda, N., Chan, L., Lieberum, T., Smith, J., &amp;amp; Steinhardt, J. (2022, September). In The Eleventh International Conference on Learning Representations.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;TwoCircuits&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2303.11873&quot;&gt;A Tale of Two Circuits: Grokking as Competition of Sparse and Dense Subnetworks&lt;/a&gt;
William Merrill, Nikolaos Tsilivis, Aman Shukla. (2023). arXiv preprint arXiv:2303.11873.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;DoubleDescent&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/pdf/2303.06173.pdf&quot;&gt;Unifying Grokking and Double Descent&lt;/a&gt;
Davies, X., Langosco, L., &amp;amp; Krueger, D. (2022, November). In NeurIPS ML Safety Workshop.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;double-demystified&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2303.14151&quot;&gt;Double Descent Demystified: Identifying, Interpreting &amp;amp; Ablating the Sources of a Deep Learning Puzzle&lt;/a&gt; Rylan Schaeffer, R., Khona, M., Robertson, Z., Boopathy, A., Pistunova, K., Rocks, J., Rani Fiete, I., &amp;amp; Koyejo, O. (2023). arXiv preprint arXiv:2303.14151.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Slingshot&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/pdf/2206.04817.pdf&quot;&gt;The Slingshot Mechanism: An Empirical Study of Adaptive Optimizers and the Grokking Phenomenon&lt;/a&gt;
Thilak, V., Littwin, E., Zhai, S., Saremi, O., Paiss, R., &amp;amp; Susskind, J. (2022). arXiv preprint arXiv:2206.04817.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;EffectiveTheory&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/pdf/2205.10343.pdf&quot;&gt;Towards Understanding Grokking: An Effective Theory of Representation Learning&lt;/a&gt;
Liu, Z., Kitouni, O., Nolte, N. S., Michaud, E., Tegmark, M., &amp;amp; Williams, M. (2022). Advances in Neural Information Processing Systems, 35, 34651-34663.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Goldilocks&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/pdf/1807.02581.pdf&quot;&gt;The Goldilocks Zone: Towards Better Understanding of Neural Network Loss Landscapes&lt;/a&gt;
Fort, S., &amp;amp; Scherlis, A. (2019, July). In Proceedings of the AAAI conference on artificial intelligence (Vol. 33, No. 01, pp. 3574-3581).&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;quantization&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2303.13506&quot;&gt;The Quantization Model of Neural Scaling&lt;/a&gt; Eric J. Michaud, Ziming Liu, Uzay Girit, Max Tegmark, O. (2023). arXiv preprint arXiv:2303.13506.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;StructuralGrokking&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/pdf/2305.18741.pdf&quot;&gt;Grokking of Hierarchical Structure in Vanilla Transformers&lt;/a&gt;
Murty, S., Sharma, P., Andreas, J., &amp;amp; Manning, C. D. (2023). arXiv preprint arXiv:2305.18741.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;PredictingGrokking&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/pdf/2306.13253.pdf&quot;&gt;Predicting Grokking Long Before it Happens: A Look Into the Loss Landscape of Models Which Grok&lt;/a&gt;
Notsawo Jr, P., Zhou, H., Pezeshki, M., Rish, I., &amp;amp; Dumas, G. (2023). arXiv preprint arXiv:2306.13253.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;explain&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://openaipublic.blob.core.windows.net/neuron-explainer/paper/index.html&quot;&gt;Language models can explain neurons in language models&lt;/a&gt;
Bills, S., Cammarata, N., Mossing, D., Tillman, H., Gao, L., Goh, G., Sutskever, I., Leike, J., Wu, J., &amp;amp; Saunders, W. 2023. OpenAI Blog&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;multiple-choice&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://arxiv.org/abs/2307.09458&quot;&gt;Does Circuit Analysis Interpretability Scale? Evidence from Multiple Choice Capabilities in Chinchilla&lt;/a&gt; Tom Lieberum, Matthew Rahtz, János Kramár, Neel Nanda, Geoffrey Irving, Rohin Shah, Vladimir Mikulik (2023). arXiv preprint arXiv:2307.09458.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;TMOS&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://transformer-circuits.pub/2022/toy_model/index.html&quot;&gt;Toy Models of Superposition&lt;/a&gt;
Elhage, N., Hume, T., Olsson, C., Schiefer, N., Henighan, T., Kravec, S., Hatfield-Dodds, Z., Lasenby, R., Drain, D., Chen, C., Grosse, R., McCandlish, S., Kaplan, J., Amodei, D., Wattenberg, M. and Olah, C., 2022. Transformer Circuits Thread.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Connectome&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://www.science.org/doi/abs/10.1126/science.add9330&quot;&gt;The Connectome of an Insect Brain&lt;/a&gt;
Winding, M., Pedigo, B. D., Barnes, C. L., Patsolic, H. G., Park, Y., Kazimiers, T., … &amp;amp; Zlatic, M. (2023). Science, 379(6636), eadd9330.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;Multiscale&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://proceedings.mlr.press/v162/pezeshki22a/pezeshki22a.pdf&quot;&gt;Multi-Scale Feature Learning Dynamics: Insights for Double Descent&lt;/a&gt;
Pezeshki, M., Mitra, A., Bengio, Y., &amp;amp; Lajoie, G. (2022, June). In the International Conference on Machine Learning (pp. 17669-17690). PMLR.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;citeend&quot; key=&quot;superposition&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://transformer-circuits.pub/2023/toy-double-descent/index.html&quot;&gt;Superposition, Memorization, and Double Descent&lt;/a&gt;
Henighan, T., Carter, S., Hume, T., Elhage, N., Lasenby, R., Fort, S., Schiefer, N., and Olah, C., 2023. Transformer Circuits Thread.&lt;/p&gt;
&lt;h3 id=&quot;more-explorables&quot;&gt;More Explorables&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;
&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/footnote_v2.css&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/citation_v2.css&quot;&gt;&lt;/p&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;




















&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;mod-top/style.css&quot;&gt;&lt;/p&gt;



&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;sparse-parity/style.css&quot;&gt;&lt;/p&gt;



&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;sweep-sparse-parity/style.css&quot;&gt;&lt;/p&gt;


&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;sweep-mod/style.css&quot;&gt;&lt;/p&gt;



&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;hand-weights/style.css&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;hand-weights/sliders.css&quot;&gt;&lt;/p&gt;







&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;five-neurons/style.css&quot;&gt;&lt;/p&gt;



&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;mod-bot/style.css&quot;&gt;&lt;/p&gt;









&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;appendix/style.css&quot;&gt;&lt;/p&gt;
















</description><link>https://pair.withgoogle.com/explorables/grokking/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/grokking/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/grokking-abstract.png" type="image/jpeg"></enclosure></item><item><title>What Have Language Models Learned?</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;What Have Language Models Learned?&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;By asking language models to fill in the blank, we can probe their understanding of the world.&lt;/div&gt;
  &lt;p&gt;Large language models are making it possible for computers to &lt;a href=&quot;https://openai.com/blog/better-language-models/&quot;&gt;write stories&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/sharifshameem/status/1282676454690451457&quot;&gt;program a website&lt;/a&gt; and &lt;a href=&quot;https://openai.com/blog/dall-e/&quot;&gt;turn captions into images&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One of the first of these models, &lt;a href=&quot;https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html&quot;&gt;BERT&lt;/a&gt;, is trained by taking sentences, splitting them into individual words, randomly hiding some of them, and predicting what the hidden words are. After doing this millions of times, BERT has “read” enough Shakespeare to predict how this phrase usually ends: &lt;/p&gt;
&lt;div class=&quot;sent hamlet&quot;&gt;&lt;/div&gt;

&lt;p&gt;This page is hooked up to a version of BERT trained on Wikipedia and books.&lt;a class=&quot;footstart&quot;&gt;¹&lt;/a&gt; Try clicking on different words to see how they’d be filled in or typing in another sentence to see what else has BERT picked up on. &lt;/p&gt;
&lt;div class=&quot;hamlet-edit&quot;&gt;&lt;/div&gt;

&lt;h3 id=&quot;cattle-or-clothes-&quot;&gt;Cattle or Clothes?&lt;/h3&gt;
&lt;p&gt;Besides Hamlet’s existential dread, the text BERT was trained on also contains more patterns: &lt;/p&gt;
&lt;div class=&quot;sent texas&quot;&gt;&lt;/div&gt;

&lt;p&gt;Cattle and horses aren’t top purchase predictions in every state, though! In New York, some of the most likely words are clothes, books and art:&lt;/p&gt;
&lt;div class=&quot;sent new-york&quot;&gt;&lt;/div&gt;

&lt;p&gt;There are more than 30,000 words, punctuation marks and word fragments in BERT’s &lt;a href=&quot;https://huggingface.co/transformers/tokenizer_summary.html&quot;&gt;vocabulary&lt;/a&gt;. Every time BERT fills in a hidden word, it assigns each of them a probability. By looking at how slightly different sentences shift those probabilities, we can get a glimpse at how purchasing patterns in different places are understood.     &lt;/p&gt;
&lt;div class=&quot;pair texas-ohio&quot;&gt;&lt;/div&gt;

&lt;p&gt;You can &lt;strong&gt;edit these sentences&lt;/strong&gt;. Or try one of these comparisons to get started: &lt;span class=&quot;texas-ohio-alts&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;To the extent that a computer program can “know” something, what does BERT know about where you live? &lt;/p&gt;
&lt;h3 id=&quot;what-s-in-a-name-&quot;&gt;What’s in a Name?&lt;/h3&gt;
&lt;p&gt;This technique can also probe what associations BERT has learned about different groups of people. For example, it predicts people named Elsie are older than people named Lauren:  &lt;/p&gt;
&lt;div class=&quot;pair age-name&quot;&gt;&lt;/div&gt;

&lt;p&gt;It’s also learned that people named Jim have more &lt;a href=&quot;https://flowingdata.com/2017/09/11/most-female-and-male-occupations-since-1950/&quot;&gt;typically masculine&lt;/a&gt; jobs than people named Jane: &lt;/p&gt;
&lt;div class=&quot;pair jim-jane&quot;&gt;&lt;/div&gt;

&lt;p&gt;These aren’t just spurious correlations — Elsies really are more likely to be &lt;a href=&quot;https://rhiever.github.io/name-age-calculator/&quot;&gt;older&lt;/a&gt; than Laurens.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt; And occupations the model associates with feminine names are held by a &lt;a href=&quot;https://purehost.bath.ac.uk/ws/portalfiles/portal/168480066/CaliskanEtAl_authors_full.pdf&quot;&gt;higher percentage&lt;/a&gt; of women.  &lt;/p&gt;
&lt;p&gt;Should we be concerned about these correlations? BERT was trained to fill in blanks in Wikipedia articles and books —  it does a great job at that! The problem is that the internal representations of language these models have learned are used for much more – by some &lt;a href=&quot;https://super.gluebenchmark.com/leaderboard&quot;&gt;measures&lt;/a&gt;, they’re the best way we have of getting computers to understand and manipulate text.&lt;/p&gt;
&lt;p&gt;We wouldn’t hesitate to call a conversation partner or recruiter who blithely assumed that doctors are men sexist, but that’s exactly what BERT might do if heedlessly incorporated into a chatbot or HR software:&lt;/p&gt;
&lt;div class=&quot;pair nurse-name&quot;&gt;&lt;/div&gt;

&lt;p&gt;Adjusting for assumptions like this isn’t trivial. &lt;em&gt;Why&lt;/em&gt; machine learning systems produce a given output still isn’t well understood – determining if a credit model built on top of BERT rejected a loan application because of &lt;a href=&quot;https://pair.withgoogle.com/explorables/hidden-bias/&quot;&gt;gender discrimation&lt;/a&gt; might be quite difficult.&lt;/p&gt;
&lt;p&gt;Deploying large language models at scale also risks &lt;a href=&quot;https://machinesgonewrong.com/bias_i/#harms-of-representation&quot;&gt;amplifying&lt;/a&gt; and &lt;a href=&quot;http://faculty.washington.edu/ebender/papers/Stochastic_Parrots.pdf&quot;&gt;perpetuating&lt;/a&gt; today’s harmful stereotypes. When &lt;a href=&quot;https://arxiv.org/pdf/2101.05783v1.pdf#page=3&quot;&gt;prompted&lt;/a&gt; with “Two Muslims walked into a…”, for example, &lt;a href=&quot;https://en.wikipedia.org/wiki/GPT-3&quot;&gt;GPT-3&lt;/a&gt; typically finishes the sentence with descriptions of violence. &lt;/p&gt;
&lt;h3 id=&quot;how-can-we-fix-this-&quot;&gt;How Can We Fix This?&lt;/h3&gt;
&lt;p&gt;One conceptually straightforward approach: reduce unwanted correlations from the training data to &lt;a href=&quot;https://arxiv.org/abs/1906.08976&quot;&gt;mitigate&lt;/a&gt; model &lt;a href=&quot;https://arxiv.org/abs/2005.14050&quot;&gt;bias&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Last year a version of BERT called &lt;a href=&quot;https://ai.googleblog.com/2020/10/measuring-gendered-correlations-in-pre.html&quot;&gt;Zari&lt;/a&gt; was &lt;a href=&quot;https://arxiv.org/pdf/2010.06032.pdf#page=6&quot;&gt;trained&lt;/a&gt; with an additional set of generated sentences. For every sentence with a &lt;a href=&quot;https://github.com/uclanlp/corefBias/blob/master/WinoBias/wino/generalized_swaps.txt&quot;&gt;gendered noun&lt;/a&gt;, like boy or aunt, another sentence that replaced the noun with its gender-partner was added to the training data: in addition to “The &lt;em&gt;lady&lt;/em&gt; doth protest too much,” Zari was also trained on “The &lt;em&gt;gentleman&lt;/em&gt; doth protest too much.”        &lt;/p&gt;
&lt;div class=&quot;pair nurse-name-zari-cda&quot;&gt;&lt;/div&gt;

&lt;p&gt;Unlike BERT, Zari assigns nurses and doctors an equal probability of being a “she” or a “he” after being trained on the swapped sentences. This approach hasn’t removed all the gender correlations; because names weren’t swapped, Zari’s association between masculine names and doctors has only slightly decreased from BERT’s.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt; And the retraining doesn’t change how the model understands nonbinary gender.    &lt;/p&gt;
&lt;p&gt;Something similar happened with &lt;a href=&quot;https://arxiv.org/abs/1607.06520&quot;&gt;other attempts&lt;/a&gt; to remove gender bias from models’ representations of words. It’s possible to mathematically define bias and perform “brain surgery” on a model to remove it, but language is steeped in gender. Large models can have billions of parameters in which to learn stereotypes — slightly different measures of bias have found the retrained models only &lt;a href=&quot;https://www.aclweb.org/anthology/N19-1061/&quot;&gt;shifted the stereotypes&lt;/a&gt; around to be undetectable by the initial measure.&lt;/p&gt;
&lt;p&gt;As with &lt;a href=&quot;https://pair.withgoogle.com/explorables/measuring-fairness/&quot;&gt;other applications&lt;/a&gt; of machine learning, it’s helpful to focus instead on the actual harms that could occur. Tools like &lt;a href=&quot;https://allennlp.org/&quot;&gt;AllenNLP&lt;/a&gt;, &lt;a href=&quot;http://lmdiff.net/&quot;&gt;LMdiff&lt;/a&gt; and the &lt;a href=&quot;https://pair-code.github.io/lit/&quot;&gt;Language Interpretability Tool&lt;/a&gt; make it easier to interact with language models to find where they might be falling short.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt; Once those shortcomings are spotted, &lt;a href=&quot;https://arxiv.org/abs/2004.07667&quot;&gt;task specific&lt;/a&gt; mitigation measures can be simpler to apply than modifying the entire model.  &lt;/p&gt;
&lt;p&gt;It’s also possible that as models grow more capable, they might be able to &lt;a href=&quot;https://arxiv.org/abs/2004.14546&quot;&gt;explain&lt;/a&gt; and perform some of this debiasing themselves. Instead of forcing the model to tell us the gender of “the doctor,” we could let it respond with &lt;a href=&quot;https://arr.am/2020/07/25/gpt-3-uncertainty-prompts/&quot;&gt;uncertainty&lt;/a&gt; that’s &lt;a href=&quot;https://ai.googleblog.com/2018/12/providing-gender-specific-translations.html&quot;&gt;shown to the user&lt;/a&gt; and controls to override assumptions. &lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Adam Pearce // July 2021&lt;/p&gt;
&lt;p&gt;Thanks to Ben Wedin, Emily Reif, James Wexler, Fernanda Viégas, Ian Tenney, Kellie Webster, Kevin Robinson, Lucas Dixon, Ludovic Peran, Martin Wattenberg, Michael Terry, Tolga Bolukbasi, Vinodkumar Prabhakaran, Xuezhi Wang, Yannick Assogba, and Zan Armstrong for their help with this piece. &lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; The BERT model used on this page is the Hugging Face version of &lt;a href=&quot;https://huggingface.co/bert-large-uncased-whole-word-masking&quot;&gt;bert-large-uncased-whole-word-masking&lt;/a&gt;. “BERT” also refers to a type of model architecture; hundreds of BERT models have been &lt;a href=&quot;https://huggingface.co/models?filter=bert&quot;&gt;trained and published&lt;/a&gt;. The model and chart code used here are available on &lt;a href=&quot;https://github.com/PAIR-code/ai-explorables&quot;&gt;GitHub&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Notice that “1800”, “1900” and “2000” are some of the top predictions, though. People aren’t actually more likely to be born at the start of a century, but in BERT’s training corpus of books and Wikipedia articles round numbers are &lt;a href=&quot;https://blocks.roadtolarissa.com/1wheel/cea123a8c17d51d9dacbd1c17e6fe601&quot;&gt;more common&lt;/a&gt;. &lt;br&gt;&lt;br&gt;&lt;img aria-label=&quot;Scatter plot showing the frequency of numbers between 1400 and 1800 in Wikipedia; round number of large peaks.&quot; src=&quot;https://pair.withgoogle.com/explorables/fill-in-the-blank/img/wiki-years.png&quot; referrerpolicy=&quot;no-referrer&quot;&gt; &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt;Comparing BERT and Zari in this interface requires carefully tracking tokens during a transition. The &lt;a href=&quot;https://colab.research.google.com/drive/1xfPGKqjdE635cVSi-Ggt-cRBU5pyJNWP&quot;&gt;BERT Difference Plots&lt;/a&gt; colab has ideas for extensions to systemically look at differences between the models’ output. &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; This analysis shouldn’t stop once a model is deployed — as language and model usage shifts, it’s important to continue studying and mitigating potential harms. &lt;/p&gt;
&lt;h3 id=&quot;appendix-differences-over-time&quot;&gt;Appendix: Differences Over Time&lt;/h3&gt;
&lt;p&gt;In addition to looking at how predictions for &lt;c0&gt;men&lt;/c0&gt; and &lt;c1&gt;women&lt;/c1&gt; are different for a given sentence, we can also chart how those differences have changed over time: &lt;/p&gt;
&lt;div class=&quot;gender-over-time&quot;&gt;&lt;/div&gt;

&lt;p&gt;The convergence in more recent years suggests another potential mitigation technique: using a prefix to steer the model away from unwanted correlations while preserving its understanding of natural language.  &lt;/p&gt;
&lt;p&gt;Using “In $year” as the prefix is quite limited, though, as it doesn’t handle &lt;c2&gt;gender-neutral&lt;/c2&gt; pronouns and potentially &lt;a href=&quot;https://www.pnas.org/content/pnas/115/16/E3635.full.pdf#page=8&quot;&gt;increases&lt;/a&gt; other correlations. However, it may be possible to &lt;a href=&quot;https://arxiv.org/abs/2104.08691&quot;&gt;find a better prefix&lt;/a&gt; that mitigates a specific type of bias with just a &lt;a href=&quot;https://www.openai.com/blog/improving-language-model-behavior/&quot;&gt;couple of dozen examples&lt;/a&gt;. &lt;/p&gt;
&lt;div class=&quot;gender-over-time&quot;&gt;&lt;/div&gt;

&lt;p&gt;Closer examination of these differences in differences also shows there’s a limit to the facts we can pull out of BERT this way. &lt;/p&gt;
&lt;p&gt;Below, the top row of charts shows how predicted differences in occupations between men and women change between 1908 and 2018. The rightmost chart shows the he/she difference in 1908 against the he/she difference in 2018. &lt;/p&gt;
&lt;p&gt;The flat slope of the rightmost chart indicates that the he/she difference has decreased for each job by about the same amount. But in reality, &lt;a href=&quot;https://www.weforum.org/agenda/2016/03/a-visual-history-of-gender-and-employment&quot;&gt;shifts in occupation&lt;/a&gt; weren’t nearly so smooth and some occupations, like accounting, switched from being majority male to majority female. &lt;/p&gt;
&lt;div class=&quot;difference-difference pair difference&quot;&gt;&lt;/div&gt;   

&lt;p&gt;This reality-prediction mismatch could be caused by lack of training data, model size or the coarseness of the probing method. There’s an immense amount of general knowledge inside of these models — with a little bit of focused training, they can even become expert &lt;a href=&quot;https://t5-trivia.glitch.me/&quot;&gt;trivia&lt;/a&gt; players. &lt;/p&gt;
&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;

&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;


























</description><link>https://pair.withgoogle.com/explorables/fill-in-the-blank/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/fill-in-the-blank/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/fill-in-the-blank-abstract.png" type="image/jpeg"></enclosure></item><item><title>Confidently Incorrect Models to Humble Ensembles</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;From Confidently Incorrect Models to Humble Ensembles&lt;/h1&gt;
  
  
  &lt;p&gt;When a machine learning model is trained, it learns patterns from data. When models are deployed in the real world, however, they often encounter data that is different in some way than the data they were trained on. In this Explorable, we’ll examine how this phenomenon can cause models to misbehave and what can be done about it.&lt;/p&gt;
&lt;p&gt;Let’s look at an example of an image classifier that is trained on &lt;a href=&quot;https://en.wikipedia.org/wiki/MNIST_database&quot; target=&quot;_blank&quot;&gt;MNIST&lt;/a&gt;, a dataset of hand-drawn digits. &lt;/p&gt;
&lt;div id=&quot;paint-container-iid&quot;&gt;&lt;/div&gt;

&lt;p&gt;The model will update its predictions as you draw on it. Try changing the eight to zero or the seven to a nine. As you experiment with drawings, do you always agree with the model’s decisions? What do you think of the model’s predictions for transition images between one number and the next?&lt;/p&gt;
&lt;h3 id=&quot;models-can-be-confidently-incorrect&quot;&gt;Models Can Be Confidently Incorrect&lt;/h3&gt;
&lt;p&gt;Below, we expand the default set of images further to show what happens when the model is asked to classify something other than a number. As you click through the different images, you can see how the model’s prediction changes over time as one image transforms into another.&lt;/p&gt;
&lt;div id=&quot;paint-container-ood&quot;&gt;&lt;/div&gt;

&lt;p&gt;A typical machine learning model, when faced with data it wasn’t trained on (called &lt;strong&gt;out of distribution data&lt;/strong&gt;), will try to make predictions based on the data it initially saw. In this case, no matter what we draw, the classifier will try to tell us that it is a number. &lt;/p&gt;
&lt;p&gt;This is a consequence of the way that this (and indeed most) machine learning classifiers are designed, with a fixed set of classes in mind. The model is only able to choose which among these classes it thinks is more likely and assign a confidence score. To read more about how model confidence scores work and how they relate to probabilities, check out our previous Explorable &lt;a href=&quot;https://pair.withgoogle.com/explorables/uncertainty-calibration/&quot; target=&quot;_blank&quot;&gt;Are Model Predictions Probabilities?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For many practical applications, however, we don’t want the model to report that a shoe is a “2” with 100% confidence. Instead, we might want the model to reduce the score that it assigns to data that is unlike anything it has been trained on. When a model incorrectly gives an out of distribution example a very high score, we call it &lt;strong&gt;confidently incorrect&lt;/strong&gt;. &lt;/p&gt;
&lt;h3 id=&quot;combining-models-reduces-overconfidence&quot;&gt;Combining Models Reduces Overconfidence&lt;/h3&gt;
&lt;p&gt;By averaging the output of multiple models, a technique known as &lt;strong&gt;ensembling&lt;/strong&gt;, we can create a model that isn’t as confidently incorrect. &lt;/p&gt;
&lt;div id=&quot;mnist-ensemble&quot;&gt;&lt;/div&gt; 

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1612.01474&quot; target=&quot;_blank&quot;&gt;Deep Ensembles&lt;/a&gt; train multiple models with different random initializations. The members of the ensemble learn to make different decisions and typically &lt;a href=&quot;https://arxiv.org/abs/1912.02757&quot; target=&quot;_blank&quot;&gt;disagree&lt;/a&gt; in their predictions on out-of-distribution inputs. While an individual network can be overconfident in its incorrect prediction, ensemble output averages the different predictions and is less confident overall on out-of-distribution inputs. &lt;/p&gt;
&lt;p&gt;There are generally no constraints on a model’s predictive behavior away from the training data, so different models will settle into making overconfident, but different, predictions on out of distribution data. This has the effect of lowering the overall confidence of the prediction by using the disagreement between the individual models’ predictions. &lt;/p&gt;
&lt;h3 id=&quot;why-do-ensembles-work-&quot;&gt;Why Do Ensembles Work?&lt;/h3&gt;
&lt;p&gt;To better understand why ensembles reduce the chance of being confidently incorrect, let’s explore what happens in the case of 2-dimensional classification. Below, we plot an ensemble classifier that is deciding whether a point in 2 dimensions should be red or blue. The color of the background indicates the decision made by the ensemble of models. &lt;/p&gt;
&lt;div id=&quot;ensemble-2d-linear&quot;&gt;&lt;/div&gt;

&lt;p&gt;With just a &lt;span class=&quot;button&quot;&gt;single model&lt;/span&gt;, the decision boundary is very steep and the model is quick to make a confident decision even if the point is close to the decision boundary. As the number of models &lt;span class=&quot;button&quot;&gt;grows&lt;/span&gt;, the disagreement between them manifests as a widening of the decision boundary, especially further away from the training data. &lt;/p&gt;
&lt;p&gt;Not all models have simple linear decision boundaries. Below are models with piecewise linear decision boundaries (which are common in &lt;a href=&quot;https://en.wikipedia.org/wiki/Rectifier_(neural_networks)&quot; target=&quot;_blank&quot;&gt;certain&lt;/a&gt; machine learning models). As you can see, because these have even more degrees of freedom than simple linear decision boundaries, the uncertainty of an ensemble is even more pronounced further from the data.&lt;/p&gt;
&lt;div id=&quot;ensemble-2d-piecewise&quot;&gt;&lt;/div&gt;

&lt;p&gt;While ensembles increase uncertainty in a useful way, the way they do it is deeply dependent on model architecture. &lt;span class=&quot;button&quot;&gt;Moving&lt;/span&gt; a blue point to the lower right creates very different decision boundaries for the linear and piecewise linear models. &lt;/p&gt;
&lt;h3 id=&quot;beyond-ensembles&quot;&gt;Beyond Ensembles&lt;/h3&gt;
&lt;p&gt;Ensembles are just one technique that can be used to improve the quality of a model’s uncertainty estimates. There are other methods that &lt;a href=&quot;https://www.tensorflow.org/tutorials/understanding/sngp&quot; target=&quot;_blank&quot;&gt;aggregate&lt;/a&gt; the predictions of a collection of models, but also strategies like &lt;a href=&quot;https://arxiv.org/abs/2103.00020&quot; target=&quot;_blank&quot;&gt;incorporating lots more data&lt;/a&gt;. Modern models are big, so keeping multiple models around for an ensemble can be a non-starter for many memory or latency-sensitive applications.  Therefore, a variety of factorized or efficient ensemble methods have been developed to create an ensemble &lt;a href=&quot;https://arxiv.org/pdf/2002.06715.pdf&quot; target=&quot;_blank&quot;&gt;within&lt;/a&gt; a single model.&lt;/p&gt;
&lt;p&gt;You may have heard of Bayesian methods such as &lt;a href=&quot;https://www.tensorflow.org/tutorials/understanding/sngp&quot; target=&quot;_blank&quot;&gt;Gaussian processes&lt;/a&gt;, which use a carefully weighted average over all possible (infinitely many) models.  These methods are expensive as you might imagine, but the research community is actively developing clever approximations and ways of incorporating them into just parts of the overall model to make things more tractable.&lt;/p&gt;
&lt;p&gt;Another good approach to improving uncertainty estimates on out of distribution data is to pre-train bigger models on &lt;a href=&quot;https://proceedings.mlr.press/v162/fang22a/fang22a.pdf&quot; target=&quot;_blank&quot;&gt;more data&lt;/a&gt;, in the hopes that this overall improves the quality of the representations and makes it easier to draw good decision boundaries.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://ai.googleblog.com/2022/07/towards-reliability-in-deep-learning.html&quot; target=&quot;_blank&quot;&gt;Plex&lt;/a&gt; explores a range of techniques to improve uncertainty in modern large text and vision models. At that scale, full ensembles are just too big, but they tried combinations of efficient ensembles, incorporating more data and approximate Bayesian methods. &lt;a href=&quot;https://arxiv.org/abs/2205.00403&quot; target=&quot;_blank&quot;&gt;One of these strategies&lt;/a&gt; is to change just the last layer of your neural network to a Gaussian Process. This kind of creates an infinite ensemble of just the last layer (making it tractable), but has an added benefit of allowing the decision boundaries of the classifier to much more directly take into account the distance between examples we are using and the training data. &lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Nithum Thain, Adam Pearce, Jasper Snoek and Balaji Lakshminarayanan // March 2023&lt;/p&gt;
&lt;p&gt;Thanks to Nicole Mitchell, Lucas Dixon, and Alexander D’Amour for their help with this piece.&lt;/p&gt;
&lt;p&gt;If you’d like to experiment with your own image classification models, check out our &lt;a href=&quot;https://colab.research.google.com/github/PAIR-code/ai-explorables/blob/master/server-side/uncertainty-ood/mnist-tfjs.ipynb&quot; target=&quot;_blank&quot;&gt;model training colab&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;more-explorables&quot;&gt;More Explorables&lt;/h3&gt;
&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;



&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;&lt;/p&gt;

t&amp;gt;
























</description><link>https://pair.withgoogle.com/explorables/uncertainty-ood/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/uncertainty-ood/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/uncertainty-ood-abstract.png" type="image/jpeg"></enclosure></item><item><title>Collecting Sensitive Information</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;How randomized response can help collect sensitive information responsibly&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;Giant datasets are revealing new patterns in &lt;a href=&quot;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5070532/&quot;&gt;cancer&lt;/a&gt;, &lt;a href=&quot;https://opportunityinsights.org/national_trends/&quot;&gt;income inequality&lt;/a&gt; and other important areas. However, the widespread availability of fast computers that can cross reference public data is making it harder to collect private information without inadvertently violating people&#39;s privacy. Modern randomization techniques can help preserve anonymity. &lt;/div&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style-graph-scroll.css&quot;&gt;

&lt;div id=&quot;container&quot; class=&quot;container-1&quot;&gt;
&lt;div id=&quot;graph&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sections&quot;&gt;
&lt;div&gt;

&lt;h3&gt;Anonymous Data&lt;/h3&gt;

&lt;p&gt;Let&#39;s pretend we&#39;re analysts at a small college, looking at anonymous survey data about plagiarism.

&lt;/p&gt;&lt;p&gt;We&#39;ve gotten responses from the entire student body, reporting if they&#39;ve ever &lt;span class=&quot;highlight purple&quot;&gt;plagiarized&lt;/span&gt; or &lt;span class=&quot;highlight grey&quot;&gt;not&lt;/span&gt;. To encourage them to respond honestly, names were not collected. 
&lt;/p&gt;&lt;p&gt;

&lt;/p&gt;&lt;p class=&quot;note&quot;&gt;The data here has been randomly generated&lt;/p&gt;
&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;On the survey students also report several bits of information about themselves, like their age...  
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;...and what state they&#39;re from. 

&lt;/p&gt;&lt;p&gt;This additional information is critical to finding potential patterns in the data—why have so many first-years from New Hampshire plagiarized?  
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Revealed Information&lt;/h3&gt;
&lt;p&gt;But granular information comes with a cost. 

&lt;/p&gt;&lt;p&gt;One student has a &lt;span class=&quot;highlight box square orange&quot;&gt;unique&lt;/span&gt; age/home state combination. By searching another student database for a 19-year old from Vermont we can identify one of the plagiarists from supposedly anonymous survey data.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;Increasing granularity exacerbates the problem. If the students reported slightly more about their ages by including what season they were born in, we&#39;d be able to &lt;span class=&quot;highlight box square orange&quot;&gt;identify&lt;/span&gt; about a sixth of them. 

&lt;/p&gt;&lt;p&gt;This isn&#39;t just a hypothetical:  A &lt;a href=&quot;https://cpg.doc.ic.ac.uk/individual-risk/&quot;&gt;birthday / gender / zip code combination&lt;/a&gt; uniquely identifies 83% of the people in the United States. 

&lt;/p&gt;&lt;p&gt;With the spread of large datasets, it is increasingly difficult to release detailed information without inadvertently revealing someone&#39;s identity. A week of a person&#39;s location data could &lt;a href=&quot;https://www.nytimes.com/interactive/2018/12/10/business/location-data-privacy-apps.html&quot;&gt;reveal&lt;/a&gt; a home and work address—possibly enough to find a name using public records.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Randomization&lt;/h3&gt;
&lt;p&gt;One solution is to randomize responses so each student has plausible deniability. This lets us buy privacy at the cost of some uncertainty in our estimation of plagiarism rates.

&lt;/p&gt;&lt;p&gt;&lt;b&gt;Step 1:&lt;/b&gt; Each student flips a coin and looks at it without showing anyone.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;&lt;b&gt;Step 2:&lt;/b&gt; Students who flip heads &lt;span class=&quot;highlight purple-box box&quot;&gt;report plagiarism&lt;/span&gt;, even if they haven&#39;t plagiarized. 

&lt;/p&gt;&lt;p&gt;Students that flipped tails report the truth, secure with the knowledge that even if their response is linked back to their name, they can claim they flipped heads.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;With a little bit of math, we can approximate the rate of plagiarism from these randomized responses. We&#39;ll skip the algebra, but doubling the reported non-plagiarism rate gives a good estimate of the actual non-plagiarism rate.    

&lt;/p&gt;&lt;p class=&quot;rand-text&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;button-outer&quot;&gt;
&lt;div class=&quot;button-container flip-coins-once&quot;&gt;
Flip coins
&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


&lt;div&gt;  
&lt;h3&gt;How far off can we be?&lt;/h3&gt;

&lt;p&gt;If we simulate this coin flipping lots of times, we can see the distribution of errors. 

&lt;/p&gt;&lt;p&gt;The estimates are close most of the time, but errors can be quite large.  

&lt;/p&gt;&lt;div class=&quot;button-outer&quot;&gt;
&lt;div class=&quot;button-container flip-coins&quot;&gt;
Flip coins 200 times
&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


&lt;div&gt;    
&lt;p&gt;Reducing the random noise (by reducing the number of students who flip heads) increases the accuracy of our estimate, but risks leaking information about students.  

&lt;/p&gt;&lt;p&gt;If the coin is heavily weighted towards tails, identified students can&#39;t credibly claim they reported plagiarizing because they flipped heads.  

&lt;/p&gt;&lt;div class=&quot;slider-outer&quot;&gt;
&lt;div class=&quot;slide-container-heads-prob&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;pointer&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


&lt;div&gt;    
&lt;p&gt;One surprising way out of this accuracy-privacy tradeoff: carefully collect information from even more people. 

&lt;/p&gt;&lt;p&gt;If we got students from other schools to fill out this survey, we could accurately measure plagiarism while protecting everyone&#39;s privacy. With enough students, we could even start comparing plagiarism across different age groups again—safely this time.     
 
&lt;/p&gt;&lt;div class=&quot;slider-outer&quot;&gt;
&lt;div class=&quot;slide-container-population&quot;&gt;&lt;/div&gt;
&amp;nbsp;
&lt;div class=&quot;slide-container-heads-prob&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Aggregate statistics about private information are valuable, but can be risky to collect. We want researchers to be able to study things like the connection between demographics and health outcomes without revealing our entire medical history to our neighbors. The coin flipping technique in this article, called &lt;a href=&quot;https://en.wikipedia.org/wiki/Randomized_response&quot;&gt;randomized response&lt;/a&gt;, makes it possible to safely study private information.  

&lt;/p&gt;&lt;p&gt;You might wonder if coin flipping is the only way to do this. It&#39;s not—&lt;a href=&quot;https://desfontain.es/privacy/differential-privacy-in-more-detail.html&quot;&gt;differential privacy&lt;/a&gt; can add targeted bits of random noise to a dataset and guarantee privacy. More flexible than randomized response, the 2020 Census will use it to &lt;a href=&quot;https://www.youtube.com/watch?v=pT19VwBAqKA&quot;&gt;protect respondents&#39; privacy&lt;/a&gt;. In addition to randomizing responses, differential privacy also limits the impact any one response can have on the released data.


&lt;/p&gt;&lt;h3&gt;Credits&lt;/h3&gt;

&lt;p&gt;Adam Pearce and Ellen Jiang // September 2020

&lt;/p&gt;&lt;p&gt;Thanks to Carey Radebaugh, Fernanda Viégas, Emily Reif, Hal Abelson, Jess Holbrook, Kristen Olson, Mahima Pushkarna, Martin Wattenberg, Michael Terry, Miguel Guevara, Rebecca Salois, Yannick Assogba, Zan Armstrong and our other colleagues at Google for their help with this piece.




&lt;/p&gt;&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;


&lt;div id=&quot;end&quot;&gt;&lt;/div&gt;


























</description><link>https://pair.withgoogle.com/explorables/anonymization/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/anonymization/</guid><enclosure url="/images/PAIR/explorable-anonymization.png" type="image/jpeg"></enclosure></item><item><title>Why Some Models Leak Data</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Why Some Models Leak Data&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;Machine learning models use large amounts of data, some of which can be sensitive. If they&#39;re not trained correctly, sometimes that data is inadvertently revealed.&lt;/div&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;


&lt;p&gt;Let’s take a look at a game of soccer. &lt;/p&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;

&lt;div id=&quot;field-grass&quot; class=&quot;field&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;/p&gt;
&lt;p&gt;Using the position of each player as training data, we can teach a model to predict which team would get to a loose ball first at each spot on the field, indicated by the color of the pixel.&lt;/p&gt;
&lt;div id=&quot;field-prediction&quot; class=&quot;field&quot;&gt;&lt;/div&gt;

&lt;p&gt;It updates in real-time—drag the players around to see the model change.&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;br&gt; &lt;/p&gt;
&lt;p&gt;This model reveals quite a lot about the data used to train it. Even without the actual positions of the players, it is simple to see where players might be.   &lt;/p&gt;
&lt;div id=&quot;field-playerless&quot; class=&quot;field&quot;&gt;&lt;/div&gt;

&lt;p&gt;Click this button to &lt;span class=&quot;button&quot; id=&quot;player-button&quot;&gt;move the players&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Take a guess at where the yellow team’s goalie is now, then check their actual position. How close were you?&lt;/p&gt;
&lt;h3&gt;Sensitive Salary Data&lt;/h3&gt;

&lt;p&gt;In this specific soccer example, being able to make educated guesses about the data a model was trained on doesn’t matter too much. But what if our data points represent something more sensitive?&lt;/p&gt;
&lt;div id=&quot;field-scatter&quot; class=&quot;field&quot;&gt;&lt;/div&gt;

&lt;p&gt;We’ve fed the same numbers into the model, but now they represent salary data instead of soccer data. Building models like this is a common technique to &lt;a href=&quot;https://www.eeoc.gov/laws/guidance/section-10-compensation-discrimination#c.%20Using%20More%20Sophisticated%20Statistical%20Techniques%20to%20Evaluate&quot;&gt;detect discrimination&lt;/a&gt;. A union might test if a company is paying men and women fairly by building a salary model that takes into account years of experience. They can then &lt;a href=&quot;https://postguild.org/2019-pay-study/&quot;&gt;publish&lt;/a&gt; the results to bring pressure for change or show improvement.&lt;/p&gt;
&lt;p&gt;In this hypothetical salary study, even though no individual salaries have been published, it is easy to infer the salary of the newest male hire. And carefully cross referencing public start dates on LinkedIn with the model could almost perfectly reveal everyone’s salary.&lt;/p&gt;
&lt;p&gt;Because the model here is so flexible (there are hundreds of square patches with independently calculated predictions) and we have so few data points (just 22 people), it is able to “memorize” individual data points. If we’re looking to share information about patterns in salaries, a simpler and more constrained model like a linear regression might be more appropriate. &lt;/p&gt;
&lt;div id=&quot;field-regression&quot; class=&quot;field&quot;&gt;&lt;/div&gt;

&lt;p&gt;By boiling down the 22 data points to two lines we’re able to see broad trends without being able to guess anyone’s salary.&lt;/p&gt;
&lt;h3&gt;Subtle Leaks&lt;/h3&gt;

&lt;p&gt;Removing complexity isn’t a complete solution though. Depending on how the data is distributed, even a simple line can inadvertently reveal information.&lt;/p&gt;
&lt;div id=&quot;field-regression-leak&quot; class=&quot;field&quot;&gt;&lt;/div&gt;

&lt;p&gt;In this company, almost all the men started several years ago, so the slope of the line is especially sensitive to the salary of the new hire. &lt;/p&gt;
&lt;p&gt;Is their salary &lt;span class=&quot;button&quot; id=&quot;high-button&quot;&gt;higher or lower&lt;/span&gt; than average? Based on the line, we can make a pretty good guess.&lt;/p&gt;
&lt;p&gt;Notice that changing the salary of someone with a more common tenure barely moves the line. In general, more typical data points are less susceptible to being leaked. This sets up a tricky trade off: we want models to learn about edge cases while being sure they haven’t memorized individual data points.&lt;/p&gt;
&lt;h3&gt;Real World Data&lt;/h3&gt;

&lt;p&gt;Models of real world data are often quite complex—this can improve accuracy, but makes them &lt;a href=&quot;https://blog.tensorflow.org/2020/06/introducing-new-privacy-testing-library.html&quot;&gt;more susceptible&lt;/a&gt; to unexpectedly leaking information. Medical models have inadvertently revealed &lt;a href=&quot;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4827719/&quot;&gt;patients’ genetic markers&lt;/a&gt;. Language models have memorized &lt;a href=&quot;https://bair.berkeley.edu/blog/2019/08/13/memorization/&quot;&gt;credit card numbers&lt;/a&gt;. Faces can even be &lt;a href=&quot;https://rist.tech.cornell.edu/papers/mi-ccs.pdf&quot;&gt;reconstructed&lt;/a&gt; from image models: &lt;/p&gt;
&lt;div class=&quot;face-container&quot;&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/data-leak/face.png&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://rist.tech.cornell.edu/papers/mi-ccs.pdf&quot;&gt;Fredrikson et al&lt;/a&gt; were able to extract the image on the left by repeatedly querying a facial recognition API. It isn’t an exact match with the individual’s actual face (on the right), but this attack only required access to the model’s predictions, not its internal state.  &lt;/p&gt;
&lt;h3&gt;Protecting Private Data&lt;/h3&gt;

&lt;p&gt;Training models with &lt;a href=&quot;http://www.cleverhans.io/privacy/2018/04/29/privacy-and-machine-learning.html&quot;&gt;differential privacy&lt;/a&gt; stops the training data from leaking by limiting how much the model can learn from any one data point. Differentially private models are still at the cutting edge of research, but they’re being packaged into &lt;a href=&quot;https://blog.tensorflow.org/2019/03/introducing-tensorflow-privacy-learning.html&quot;&gt;machine learning frameworks&lt;/a&gt;, making them much easier to use. When it isn’t possible to train differentially private models, there are also tools that can &lt;a href=&quot;https://github.com/tensorflow/privacy/tree/master/tensorflow_privacy/privacy/membership_inference_attack&quot;&gt;measure&lt;/a&gt; how much data is the model memorizing. Also, standard techniques such as aggregation and limiting how much data a single source can contribute are still useful and usually improve the privacy of the model.&lt;/p&gt;
&lt;p&gt;As we saw in the &lt;a href=&quot;https://pair.withgoogle.com/explorables/anonymization/&quot;&gt;Collecting Sensitive Information Explorable&lt;/a&gt;, adding enough random noise with differential privacy to protect outliers like the new hire  can increase the amount of data required to reach a good level of accuracy. Depending on the application, the constraints of differential privacy could even improve the model—for instance, not learning too much from one data point can help prevent &lt;a href=&quot;https://openreview.net/forum?id=r1xyx3R9tQ&quot;&gt;overfitting&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Given the increasing utility of machine learning models for many real-world tasks, it’s clear that more and more systems, devices and apps will be powered, to some extent, by machine learning in the future. While &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;standard privacy best practices&lt;/a&gt; developed for non-machine learning systems still apply to those with machine learning, the introduction of machine learning introduces new challenges, including the ability of the model to memorize some specific training data points and thus be vulnerable to privacy attacks that seek to extract this data from the model. Fortunately, techniques such as differential privacy exist that can be helpful in overcoming this specific challenge. Just as with other areas of &lt;a href=&quot;https://ai.google/responsibilities/responsible-ai-practices/&quot;&gt;Responsible AI&lt;/a&gt;, it’s important to be aware of these new challenges that come along with machine learning and what steps can be taken to mitigate them. &lt;/p&gt;
&lt;h3&gt;Credits&lt;/h3&gt;

&lt;p&gt;Adam Pearce and Ellen Jiang // December 2020&lt;/p&gt;
&lt;p&gt;Thanks to Andreas Terzis, Ben Wedin, Carey Radebaugh, David Weinberger, Emily Reif, Fernanda Viégas, Hal Abelson, Kristen Olson, Martin Wattenberg, Michael Terry, Miguel Guevara, Thomas Steinke, Yannick Assogba, Zan Armstrong and our other colleagues at Google for their help with this piece.&lt;/p&gt;
&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;















</description><link>https://pair.withgoogle.com/explorables/data-leak/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/data-leak/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/model-inversion.png" type="image/jpeg"></enclosure></item><item><title>Can a Model Be Differentially Private and Fair?</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Can a Model Be Differentially Private and Fair?&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;Training models with differential privacy stops models from inadvertently leaking sensitive data, but there&#39;s an unexpected side-effect: reduced accuracy on underrepresented subgroups.&lt;/div&gt;
  &lt;p&gt;Imagine you want to use machine learning to suggest new bands to listen to. You could do this by having lots of people list their favorite bands and using them to train a model. The trained model might be quite useful and fun, but if someone pokes and prods at the model in just the right way, they could &lt;a href=&quot;https://www.wired.com/2007/12/why-anonymous-data-sometimes-isnt/&quot;&gt;extract&lt;/a&gt; the music preferences of someone whose data was used to train the model. Other kinds of models are potentially vulnerable; &lt;a href=&quot;https://bair.berkeley.edu/blog/2019/08/13/memorization/&quot;&gt;credit card numbers&lt;/a&gt; have been pulled out of language models and &lt;a href=&quot;https://rist.tech.cornell.edu/papers/mi-ccs.pdf&quot;&gt;actual faces&lt;/a&gt; reconstructed from image models.&lt;/p&gt;
&lt;p&gt;Training with &lt;a href=&quot;https://desfontain.es/privacy/differential-privacy-awesomeness.html&quot;&gt;differential privacy&lt;/a&gt; limits the information about any one data point that is extractable but in some cases there’s an unexpected side-effect: reduced accuracy with underrepresented subgroups disparately impacted.  &lt;/p&gt;
&lt;div class=&quot;info-box&quot;&gt;&lt;/div&gt;

&lt;p&gt;Recall that machine learning models are typically trained with &lt;a href=&quot;https://playground.tensorflow.org/&quot;&gt;gradient descent&lt;/a&gt;, a series of small steps taken to minimize an error function. To show how a model can leak its training data, we’ve trained two simple models to separate red and blue dots using two simple datasets that differ in one way: a single isolated data point in the upper left has been switched from red to blue.  &lt;/p&gt;
&lt;div class=&quot;epoch-graph&quot;&gt;&lt;/div&gt;

&lt;p&gt;Notice that the two models have very different boundary lines near the isolated point by the end of the training. Someone with access to the trained model might be able to &lt;a href=&quot;https://pair.withgoogle.com/explorables/data-leak/&quot;&gt;infer&lt;/a&gt; if the point in the upper left is red or blue — if the color represented sensitive information, like someone’s &lt;a href=&quot;https://gothamist.com/news/researchers-know-how-dante-de-blasio-hundreds-other-new-yorkers-voted&quot;&gt;voting record&lt;/a&gt;, that could be quite bad! &lt;/p&gt;
&lt;h3 id=&quot;protecting-the-privacy-of-training-points&quot;&gt;Protecting the Privacy of Training Points&lt;/h3&gt;
&lt;p&gt;We can prevent a single data point from drastically altering the model by &lt;a href=&quot;http://www.cleverhans.io/privacy/2019/03/26/machine-learning-with-differential-privacy-in-tensorflow.html&quot;&gt;adding&lt;/a&gt; two operations to each training step:&lt;a class=&quot;footstart&quot;&gt;²&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;⚬ Clipping the gradient (here, limiting how much the boundary line can move with each step) to bound the maximum impact a single data point can have on the final model.&lt;/li&gt;
&lt;li&gt;⚬ Adding random noise to the gradient.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Try &lt;strong&gt;increasing&lt;/strong&gt; the random noise below. We’re now training lots of differentially private models; the more the potential models for the red and blue outlier points overlap, the more &lt;a href=&quot;https://pair.withgoogle.com/explorables/anonymization/&quot;&gt;plausible deniability&lt;/a&gt; the person in the upper left has.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;  &lt;/p&gt;
&lt;div class=&quot;decision-boundry&quot;&gt;&lt;/div&gt;  

&lt;p&gt;You can also try dragging the other points around and adjusting the gradient clipping. Are points in the center or outliers more likely to modify the boundary lines? In two dimensions there’s a limited number of outliers, but in higher dimensions &lt;a href=&quot;https://observablehq.com/@tophtucker/theres-plenty-of-room-in-the-corners&quot;&gt;more points&lt;/a&gt; are outliers and much more information can be extracted from a trained model.&lt;/p&gt;
&lt;p&gt;Correctly combined, adding gradient clipping and random noise to gradient descent make it possible to train a model with &lt;a href=&quot;https://desfontain.es/privacy/differential-privacy-awesomeness.html&quot;&gt;differential privacy&lt;/a&gt; – we can guarantee that a model trained on a given dataset is essentially indistinguishable from a model trained on the same dataset with a single point changed.    &lt;/p&gt;
&lt;h3 id=&quot;predictions-on-outliers-change-the-most&quot;&gt;Predictions on Outliers Change the Most&lt;/h3&gt;
&lt;p&gt;What does this look like in practice? In &lt;a href=&quot;https://arxiv.org/abs/1910.13427&quot;&gt;Distribution Density, Tails, and Outliers in Machine Learning&lt;/a&gt;, a series of increasingly differentially private models were trained on &lt;a href=&quot;https://en.wikipedia.org/wiki/MNIST_database&quot;&gt;MNIST digits&lt;/a&gt;. Every digit in the training set was ranked according to the highest level of privacy that correctly classified it. &lt;/p&gt;
&lt;div class=&quot;top-bot-digits&quot;&gt;&lt;/div&gt;

&lt;p&gt;On the lower left, you can see digits labeled as “3” in the training data that look more like a “2” and a “9”. They’re very different from the other “3”s in the training data so adding just a bit of privacy protection causes the model to no longer classify them as “3”. Under some &lt;a href=&quot;https://arxiv.org/abs/1411.2664&quot;&gt;specific circumstances&lt;/a&gt;, differential privacy can actually improve how well the model generalizes to data it wasn’t trained on by limiting the influence of spurious examples.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The right side shows more canonical digits which are classified correctly even with high levels of privacy because they’re quite similar to other digits in the training data.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-accuracy-tradeoff&quot;&gt;The Accuracy Tradeoff&lt;/h3&gt;
&lt;p&gt;Limiting how much a model can learn from a single example does have a downside: it can also decrease the model’s accuracy. With &lt;tp class=&quot;tp75&quot;&gt;7,500 training points&lt;/tp&gt;, 90% accuracy on MNIST digits is only &lt;a href=&quot;https://colab.research.google.com/github/PAIR-code/ai-explorables/blob/master/server-side/private-and-fair/MNIST_DP_Model_Grid.ipynb&quot;&gt;achievable&lt;/a&gt; with an extremely low level of privacy protection; increasing privacy quickly lowers the model’s accuracy. &lt;/p&gt;
&lt;p&gt;Collecting more training data offers a way out of this accuracy/privacy tradeoff. With &lt;tp class=&quot;tp60&quot;&gt;60,000 training points,&lt;/tp&gt; 90% accuracy can be reached with a higher privacy level than almost all &lt;a href=&quot;https://desfontain.es/privacy/real-world-differential-privacy.html&quot;&gt;real-world deployments&lt;/a&gt; of differential privacy. &lt;/p&gt;
&lt;div class=&quot;accuracy-v-privacy-dataset_size&quot;&gt;&lt;/div&gt;

&lt;p&gt;Looking at the differences between predictions by digit class shows another potential complication: some classes are harder to identify than others. Detecting an “8” with high confidence requires more training data and/or lower privacy than detecting a “0” with high confidence. &lt;/p&gt;
&lt;div class=&quot;accuracy-v-privacy-class&quot;&gt;&lt;/div&gt;

&lt;p&gt;This problem is exacerbated if the training data has fewer examples of one class than the others. Trying to predict an uncommon event with a differentially private model can require an enormous amount of data.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;implications-for-fairness&quot;&gt;Implications for Fairness&lt;/h3&gt;
&lt;p&gt;Outliers also aren’t evenly distributed within a class. Below, MNIST digits are colored by their sensitivity to higher privacy levels and projected with &lt;a href=&quot;https://pair-code.github.io/understanding-umap/&quot;&gt;UMAP&lt;/a&gt;, forming several clusters of privacy-sensitive yellow digits. It’s possible to inadvertently train a model with good overall accuracy on a class but very low accuracy on a smaller group within the class. &lt;/p&gt;
&lt;div class=&quot;umap-digit&quot;&gt;&lt;/div&gt;

&lt;p&gt;There’s nothing that makes a “1” slanted to the left intrinsically harder to classify, but because there are only a few slanted “1”s in the training data it’s difficult to make a model that classifies them accurately without leaking information. &lt;/p&gt;
&lt;p&gt;This disparate impact doesn’t just happen in datasets of differently drawn digits: increased levels of differential privacy in a range of image and language models &lt;a href=&quot;https://arxiv.org/pdf/1905.12101.pdf&quot;&gt;disproportionality decreased accuracy&lt;/a&gt; on underrepresented subgroups. And adding differential privacy to a medical model &lt;a href=&quot;https://arxiv.org/pdf/2010.06667v1.pdf&quot;&gt;reduced&lt;/a&gt; the influence of Black patients’ data on the model while increasing the influence of white patients’ data. &lt;/p&gt;
&lt;p&gt;Lowering the privacy level might not help non-majoritarian data points either – they’re the ones most &lt;a href=&quot;https://arxiv.org/abs/1906.00389&quot;&gt;susceptible&lt;/a&gt; to having their information exposed. Again, escaping the accuracy/privacy tradeoff requires collecting more data – this time from underrepresented subgroups.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;   &lt;/p&gt;
&lt;h3 id=&quot;more-reading&quot;&gt;More Reading&lt;/h3&gt;
&lt;p&gt;There are deep connections between &lt;a href=&quot;https://arxiv.org/abs/1906.05271&quot;&gt;generalization, memorization and privacy&lt;/a&gt; that are still not well understood. Slightly changing the privacy constraints, for example, can create new options. If public, unlabeled data exists, a “&lt;a href=&quot;http://www.cleverhans.io/privacy/2018/04/29/privacy-and-machine-learning.html&quot;&gt;Private Aggregation of Teacher Ensembles&lt;/a&gt;“ could be used instead of gradient clipping and random noise to train a differentially private model with a &lt;a href=&quot;https://arxiv.org/pdf/2106.12576.pdf&quot;&gt;smaller disparate impact&lt;/a&gt; on accuracy. &lt;/p&gt;
&lt;p&gt;Finding ways to increase privacy with a smaller impact on accuracy is an active area of research – &lt;a href=&quot;https://arxiv.org/abs/2007.14191&quot;&gt;model architectures&lt;/a&gt; designed with privacy in mind and better &lt;a href=&quot;https://arxiv.org/pdf/2107.06499.pdf&quot;&gt;dataset cleaning&lt;/a&gt; look like promising avenues.  &lt;/p&gt;
&lt;p&gt;There are also additional &lt;a href=&quot;http://proceedings.mlr.press/v97/jagielski19a/jagielski19a.pdf&quot;&gt;accuracy/privacy/fairness&lt;/a&gt; tradeoffs beyond what’s discussed in this post. Even if a differentially private model doesn’t have large accuracy gaps between subgroups, enforcing &lt;a href=&quot;https://pair.withgoogle.com/explorables/measuring-fairness/&quot;&gt;fairness metrics&lt;/a&gt; can reduce privacy or accuracy.&lt;/p&gt;
&lt;p&gt;This post focuses on protecting the privacy of individual data points. In practice more work might be necessary to ensure that the &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293#:~:text=Computing%20and%20Verifying%20Anonymous%20Aggregates&quot;&gt;privacy of users&lt;/a&gt; – who could contribute much more than a single data point each – is also protected.    &lt;/p&gt;
&lt;p&gt;These questions are also significant outside of machine learning. &lt;a href=&quot;https://arxiv.org/abs/2105.07513&quot;&gt;Allocating resources&lt;/a&gt; based on a differentially private dataset – with no machine learning model involved – can also disproportionately affect different groups. The 2020 Census is the first to use differential privacy and this could have a wide range of impacts, including how &lt;a href=&quot;https://statmodeling.stat.columbia.edu/2021/10/20/how-does-post-processed-differentially-private-census-data-affect-redistricting-how-concerned-should-we-be-about-gerrymandering-with-the-new-das/&quot;&gt;congressional districts&lt;/a&gt; are drawn. &lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Adam Pearce // January 2022&lt;/p&gt;
&lt;p&gt;Thanks to Abhradeep Thakurta, Andreas Terzis, Andy Coenen, Asma Ghandeharioun, Brendan McMahan, Ellen Jiang, Emily Reif, Fernanda Viégas, James Wexler, Kevin Robinson, Matthew Jagielski, Martin Wattenberg, Meredith Morris, Miguel Guevara, Nicolas Papernot and Nithum Thain for their help with this piece.&lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; To speed up training at the cost of looser privacy bounds, gradients, clipping and noise can be calculated on a group of data points instead of individual data points.   &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; The “ε” in ε-differential privacy essentially &lt;a href=&quot;https://desfontain.es/privacy/differential-privacy-in-more-detail.html&quot;&gt;measures&lt;/a&gt; the overlap in two distributions after changing a single data point. &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://openreview.net/forum?id=BJgnXpVYwS&quot;&gt;Clipping&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/pdf/1511.06807.pdf&quot;&gt;noising&lt;/a&gt; are also used outside of differential privacy as regularization techniques to improve accuracy. &lt;br&gt;&lt;br&gt; In addition to accidently mislabeled examples, differential privacy can also provide some protection against &lt;a href=&quot;https://dp-ml.github.io/2021-workshop-ICLR/files/23.pdf&quot;&gt;data poisoning attacks&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; While visually similar digits aren’t necessarily interpreted in similar ways by the model, the clustering of visually similar digits in the UMAP diagram at the bottom of the page (which projects embedding from the penultimate layer of digit classifier) suggests there is a close connection here.   &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Rebalancing the dataset without collecting more data doesn’t avoid this privacy/accuracy tradeoff – upsampling the smaller class reduces privacy and downsampling the larger class reduces data and lowers accuracy.  &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; See the appendix on &lt;a href=&quot;https://pair.withgoogle.com/explorables/private-and-fair/#appendix-subgroup-size-and-accuracy&quot;&gt;Subgroup Size and Accuracy&lt;/a&gt; for more detail.   &lt;/p&gt;
&lt;h3 id=&quot;appendix-subgroup-size-and-accuracy&quot;&gt;Appendix: Subgroup Size and Accuracy&lt;/h3&gt;
&lt;p&gt;How, exactly, does the amount of training data, the privacy level and the percentage of data from a subgroup impact accuracy? Using MNIST digits rotated 90° as a stand-in for a smaller subgroup, we can see how the accuracy of a series of simple &lt;a href=&quot;https://colab.research.google.com/github/PAIR-code/ai-explorables/blob/master/server-side/private-and-fair/MNIST_Generate_UMAP.ipynb&quot;&gt;models&lt;/a&gt; that classify “1”s and “7”s change based on these attributes. &lt;/p&gt;
&lt;p&gt;On the far left, models without any rotated digits in the training data never classify those digits more accurately than random guessing. By rotating 5% of the training digits, a small slice of models with lots of training data and low privacy can accurately classify rotated digits. &lt;/p&gt;
&lt;div class=&quot;rotated-accuracy-heatmap&quot;&gt;&lt;/div&gt;

&lt;p&gt;Increasing the proportion of rotated digits to 10% or 20% or even more makes it possible to train a higher privacy model that performs well on both types of digits with the same amount of training data.  &lt;/p&gt;
&lt;p&gt;Click on one of the models above and you can see how the accuracy gap shifts as number of training points, privacy level and percentage of rotated digits are independently changed.&lt;/p&gt;
&lt;div class=&quot;rotated-accuracy&quot;&gt;&lt;/div&gt;

&lt;p&gt;Intuitively, adding more training data has diminishing marginal increases to accuracy. Accuracy on the smaller group of rotated digits, which may just be on the cusp of being learned, falls off faster as the effective amount of training data is decreased — a disparate reduction in accuracy.&lt;/p&gt;
&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;


&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;





























</description><link>https://pair.withgoogle.com/explorables/private-and-fair/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/private-and-fair/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/private-and-fair-abstract.png" type="image/jpeg"></enclosure></item><item><title>Federated Learning</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;How Federated Learning Protects Privacy&lt;/h1&gt;
  
  
  &lt;div class=&quot;federate-playground playground-top&quot;&gt;&lt;/div&gt;

&lt;p&gt;Large datasets have made astounding breakthroughs in machine learning possible. But oftentimes data is personal or proprietary, and not meant to be shared, making privacy a critical concern of and barrier to centralized data collection and model training. With &lt;a href=&quot;http://ai.googleblog.com/2017/04/federated-learning-collaborative.html&quot;&gt;&lt;strong&gt;federated learning&lt;/strong&gt;&lt;/a&gt;, it’s possible to collaboratively train a model with data from multiple users without any raw data leaving their devices. If we can learn from data across many sources without needing to own or collect it, imagine what opportunities that opens!&lt;/p&gt;
&lt;p&gt;Billions of connected devices — like phones, watches, vehicles, cameras, thermostats, solar panels, telescopes — with sensors to capture data and computational power to participate in training, could collaborate to better understand our environment and ourselves. How do people move? What impacts our health and wellbeing? Together via federated learning these devices could enable new technologies as well. Consider how our cars might contribute to large-scale training of autonomous vehicles without divulging our whereabouts. &lt;/p&gt;
&lt;p&gt;And this machine learning approach can be applied across separate organizations as well. &lt;a href=&quot;https://www.nature.com/articles/s41551-022-00898-y&quot;&gt;Hospitals&lt;/a&gt; could design better treatment plans with knowledge about patient outcomes due to various interventions from care providers worldwide without sharing highly sensitive health data. &lt;a href=&quot;https://www.melloddy.eu/&quot;&gt;Pharmaceutical companies&lt;/a&gt; with proprietary drug development data could collaborate to build knowledge about how the body is likely to metabolize different compounds.&lt;/p&gt;
&lt;p&gt;This framework has the potential to enable large-scale aggregation and modeling of complicated systems and processes like urban mobility, economic markets, energy use and generation patterns, climate change and public health concerns. Ultimately, the hope of federated learning is to allow people, companies, jurisdictions and institutions to collaboratively ask and answer big questions, while maintaining ownership of their personal data.&lt;/p&gt;
&lt;h3 id=&quot;designing-a-federated-learning-system&quot;&gt;Designing a Federated Learning System&lt;/h3&gt;
&lt;p&gt;Let’s explore how this technology works with a simple example we can all relate to: blocking spam messages. Spam in chat apps is annoying and pervasive. Machine learning offers a solution – we could develop a model that automatically filters out incoming spam based upon what users previously marked as spam on their devices. This sounds great, but there’s a catch: most machine learning models are trained by collecting vast amounts of data on a central server; and user messages can be quite personal. To protect privacy, is it possible to train a spam detection model — or any machine learning model, for that matter — without sharing any potentially sensitive information with a central server?  &lt;/p&gt;
&lt;p&gt;To answer this question, let’s first take a closer look at a typical centralized training system, illustrated by the simple spam detection model below. User messages are uploaded to a central server, where they’re processed all at once to train a &lt;a href=&quot;https://en.wikipedia.org/wiki/Bag-of-words_model&quot;&gt;bag-of-words&lt;/a&gt; model. Click a message to flag it as spam &lt;span class=&quot;spam-icon&quot;&gt;❌&lt;/span&gt; or not to change the data uploaded to the server and the trained model.&lt;/p&gt;
&lt;div class=&quot;central-spam-model&quot;&gt;&lt;/div&gt; 

&lt;p&gt;This model might be pretty good at filtering out spam messages. But centralized training comes with a big downside: all the messages, no matter how sensitive, need to be sent to the server, requiring users to trust the owners of that centralized server to protect their data and not misuse it.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;   &lt;/p&gt;
&lt;p&gt;What if training was done locally on each user’s device instead and their data wasn’t centrally collected? Smartphones are getting increasingly powerful, and they’re often idle — for example, while charging overnight — enabling machine learning model training to run without impacting the user experience.&lt;/p&gt;
&lt;div class=&quot;local-spam-model&quot;&gt;&lt;/div&gt;

&lt;p&gt;Training models locally is great for privacy — no data ever leaves a user’s device! — but we can see here how a single device with limited data might not be able to train a high quality model. If a new &lt;a href=&quot;https://www.fcc.gov/consumers/guides/beware-auto-warranty-scams&quot;&gt;scam&lt;/a&gt; involving, say, car insurance starts spamming messages to everyone, Alice’s phone wouldn’t be able to filter out messages about “your auto warranty renewal” with a local-only model until she marks several of them as spam — even if Bob has already flagged similar messages.&lt;/p&gt;
&lt;p&gt;How can users help each other out and collaboratively train a model without sharing their private data? One idea is for users to share their locally trained spam-detection models instead of their messages. The server can then combine these models, for example by averaging them, to produce a global model that everyone could use for spam filtering.&lt;/p&gt;
&lt;div class=&quot;federated-spam-model&quot;&gt;&lt;/div&gt; 

&lt;p&gt;While we’ve stopped sending every raw message to the server, uploading these local models still leaks some information. Here, the central server has direct access to the rates each user marks different words as spam and can infer what they’re talking about. Depending on the level of trust users have in the server, they may be uncomfortable with the server seeing their local models. Ideally the server should only see the aggregated result. We want to develop a system that provides as much &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293#:~:text=The%20principle%20of,be%20discussed%20later.&quot;&gt;data minimization&lt;/a&gt; as possible.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://ai.googleblog.com/2017/04/federated-learning-collaborative.html&quot;&gt;&lt;strong&gt;Federated learning&lt;/strong&gt;&lt;/a&gt; is a general framework that leverages data minimization tactics to enable multiple entities to collaborate in solving a machine learning problem. Each entity keeps their raw data local, and improves a global model with focused updates intended for immediate aggregation. A good first step towards limiting data exposure when combining user models is to do so without ever storing the individual models — only the aggregate. &lt;a href=&quot;https://dl.acm.org/doi/10.1145/3133956.3133982&quot;&gt;Secure aggregation&lt;/a&gt; and &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293#:~:text=For%20example%2C%20a%20server%20could%20run%20the%20aggregation%20procedure%20within%20a%20secure%20enclave&quot;&gt;secure enclaves&lt;/a&gt; can provide even stronger guarantees, combining many local models into an aggregate without revealing the contribution of any user to the server. This may sound almost magical, so let’s take a closer look at how secure aggregation works.&lt;/p&gt;
&lt;p&gt;In the secure aggregation protocol, user devices agree on shared random numbers, teaming up to mask their local models in a way that preserves the aggregated result. The server won’t know how each user modified their model.&lt;/p&gt;
&lt;div class=&quot;full-width&quot;&gt;&lt;div class=&quot;secure-aggregation&quot;&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Try dragging the &lt;hn class=&quot;green&quot;&gt;shared random numbers&lt;/hn&gt; — the &lt;total&gt;aggregated sum&lt;/total&gt; remains constant even though what each user sends to the server changes. And importantly, the users’ &lt;hn&gt;hidden numbers&lt;/hn&gt; are never shared!&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let’s put everything together by running all the user-contributed numbers that make up each of their local models through the secure aggregation process. Alice, Bob and Carol’s devices use a cryptographic &lt;a href=&quot;https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange&quot;&gt;technique&lt;/a&gt; to exchange random numbers secretly — our users won’t actually meet in person. &lt;/p&gt;
&lt;div class=&quot;secure-federated-spam-model&quot;&gt;&lt;/div&gt;

&lt;p&gt;With secure aggregation, users collaboratively merge their models without revealing any individual contribution to the central server.&lt;/p&gt;
&lt;p&gt;All in all, federated learning enables collaborative model training, while minimizing data exposure. This system design extends to problem settings far beyond the toy spam example we’ve illustrated above, to larger-scale modeling across all sorts of devices and institutions with privately-held data.&lt;/p&gt;
&lt;h3 id=&quot;training-a-federated-model&quot;&gt;Training a Federated Model&lt;/h3&gt;
&lt;p&gt;While a very simple model like our toy spam classifier can be learned via a single round of merging local models, more sophisticated models require many iterations of local training and &lt;a href=&quot;https://arxiv.org/abs/1602.05629&quot;&gt;federated averaging&lt;/a&gt;. Let’s see how that works and examine some challenges that arise in practice. We’ll look at a simple “heat-map” &lt;a href=&quot;https://towardsdatascience.com/binary-classification-and-logistic-regression-for-beginners-dd6213bf7162&quot;&gt;binary classification&lt;/a&gt; model designed to guess what regions of a grid are likely to be &lt;span class=&quot;hot&quot;&gt;hot&lt;/span&gt; or &lt;span class=&quot;cold&quot;&gt;cold&lt;/span&gt;. Each of our users has only collected temperature readings from a handful of locations: &lt;/p&gt;
&lt;div class=&quot;data-map-users&quot;&gt;&lt;/div&gt;

&lt;p&gt;If all the users uploaded their data to a central server, it’d be easy to spot the pattern:  &lt;/p&gt;
&lt;div class=&quot;data-map-all-points&quot;&gt;&lt;/div&gt;

&lt;p&gt;Our goal is to learn this temperature distribution across the grid — so everyone will know where they need a sweater! — without anyone having to share their location history.&lt;/p&gt;
&lt;p&gt;Below, each user is continually training a model with just their local data, predicting the temperature of every location in the grid. You can see how dramatically different models are trained as each user’s model overfits to their limited view of the world. The local training curves track the accuracy of each local model on the ground truth data, indicating how well each local model learns the true temperature distribution across the grid.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;  &lt;/p&gt;
&lt;div class=&quot;federate-playground playground-step&quot;&gt;&lt;/div&gt;

&lt;p&gt;Click &lt;merge-models-inline&gt;&lt;/merge-models-inline&gt; to run a round of federated training: averaging user models and distributing the updated global model to all users.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt; After training and merging models several times, the resulting global model better resembles the overall temperature distribution across the map than the models trained on just local data. You may notice how local heat map models &lt;a href=&quot;https://arxiv.org/abs/1910.06378&quot;&gt;drift&lt;/a&gt; apart after a significant period of local training, and the latest global model’s accuracy might degrade upon merging. Relatively frequent periodic averaging is used to avoid this.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;While we plot the local model accuracies so it’s possible to observe these training dynamics, in practice a server running federated training only has access to the global model. The only metric that can be computed and tracked over the course of training by the server is the global model accuracy. &lt;/p&gt;
&lt;h3 id=&quot;outliers&quot;&gt;Outliers&lt;/h3&gt;
&lt;p&gt;This works pretty well when all users report consistent temperature experiences. What happens if that’s not the case? Maybe some of our users have broken thermometers and report cold weather everywhere! Click on each of the four &lt;span class=&quot;outlier&quot;&gt;outliers&lt;/span&gt; to exclude them from training and notice how the model performs.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;federate-playground playground-outlier&quot;&gt;&lt;/div&gt;

&lt;p&gt;We may be able to better train a model to predict the heat-map that the majority of users observed without the outliers, but what if these outlier users don’t have broken sensors and their data just looks different? Some people may have different ideas of what is “hot” or “cold;” excluding outliers from training risks &lt;a href=&quot;https://arxiv.org/abs/1905.10497&quot;&gt;reducing accuracy for&lt;/a&gt; groups of people less represented in the training pool.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;    &lt;/p&gt;
&lt;p&gt;Though it’s easy to spot the outliers in this example, in practice the server in a federated learning system cannot directly see user training data, which makes &lt;a href=&quot;https://arxiv.org/abs/2108.10241&quot;&gt;detecting&lt;/a&gt; outliers in federated learning tricky. The presence of outliers is often indicated by poor model quality across users. &lt;/p&gt;
&lt;h3 id=&quot;differential-privacy&quot;&gt;Differential Privacy&lt;/h3&gt;
&lt;p&gt;Having the global model drastically change based on the presence of a single user also raises privacy concerns. If one user’s participation can significantly affect the model, then someone observing the final model might be able to determine who participated in training, or even infer their local data. Outlier data is particularly likely to have a larger impact on model training.&lt;/p&gt;
&lt;p&gt;For example, let’s say our potential user group includes one person known to always wear a sweater and complain about the cold. If the global model accuracy is lower than expected, we can infer that the notorious sweater-wearing user probably participated in training and reduced accuracy by always reporting cold. This is the case even with secure aggregation — the central server can’t directly see which user contributed what, but the resulting global model still gives away that it’s likely that a user who believes that it’s always sweater weather participated.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Carefully bounding the impact of any possible user contribution and adding random noise to our system can help prevent this, making our training procedure &lt;a href=&quot;https://desfontain.es/privacy/differential-privacy-in-more-detail.html&quot;&gt;differentially private&lt;/a&gt;. When using differential privacy in federated learning, the overall accuracy of the global model may degrade, but the outcome should remain roughly the same when toggling inclusion of the outlier (or any other user) in the training process.&lt;/p&gt;
&lt;p&gt;Use the slider to modulate how much the user-reported locations are perturbed. At lower levels of privacy toggling the inclusion of the outlier affects the model more significantly, whereas at higher levels of privacy there is not a discernible difference in model quality when the outlier is included.&lt;/p&gt;
&lt;div class=&quot;federate-playground playground-dp&quot;&gt;&lt;/div&gt;

&lt;p&gt;In practice user models are &lt;a href=&quot;https://pair.withgoogle.com/explorables/private-and-fair/#:~:text=%E2%9A%AC%20Clipping%20the%20gradient&quot;&gt;clipped&lt;/a&gt; and &lt;a href=&quot;https://pair.withgoogle.com/explorables/private-and-fair/#:~:text=%E2%9A%AC%20Adding%20random%20noise%20to%20the%20gradient.&quot;&gt;noised&lt;/a&gt; rather than their raw data, or noise is applied to the combination of many clipped models. Applying the noise centrally tends to be better for model accuracy, however the un-noised models may need to be protected by technologies like &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293#:~:text=Computing%20and%20Verifying%20Anonymous%20Aggregates&quot;&gt;trusted aggregators&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This demonstration illustrates a trade-off between privacy and accuracy, though there’s another missing dimension that factors into the equation: the amount of data, both in number of training examples and number of users. The cost of using more  data isn’t free — this increases the amount of compute — but it’s another knob we can turn to arrive at an acceptable operating point across all of these dimensions.&lt;/p&gt;
&lt;h3 id=&quot;playground&quot;&gt;Playground&lt;/h3&gt;
&lt;p&gt;There are lots of other knobs to turn in a federated learning setting. All these variables interact in complicated ways. Click on a value for each variable to run a particular configuration, or the variable name to sweep over all of its options. Go ahead and play around — try mixing them together!&lt;a class=&quot;footstart&quot;&gt;5&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;federate-playground playground-full&quot;&gt;&lt;/div&gt;

&lt;h3 id=&quot;more-reading&quot;&gt;More Reading&lt;/h3&gt;
&lt;p&gt;This &lt;a href=&quot;https://federated.withgoogle.com/&quot;&gt;comic&lt;/a&gt; serves as a gentle visual introduction to federated learning. Google AI’s blog post &lt;a href=&quot;https://ai.googleblog.com/2017/04/federated-learning-collaborative.html&quot;&gt;introducing federated learning&lt;/a&gt; is another great place to start.&lt;/p&gt;
&lt;p&gt;Though this post motivates federated learning for reasons of user privacy, an &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293&quot;&gt;in depth discussion of privacy&lt;/a&gt; considerations - namely  &lt;em&gt;data minimization&lt;/em&gt; and &lt;em&gt;data anonymization&lt;/em&gt; - and the tactics aimed at addressing these concerns is beyond its scope.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pair.withgoogle.com/explorables/private-and-fair/&quot;&gt;Previous explorables&lt;/a&gt; have discussed the privacy/accuracy/data trade-off in more detail, with a focus on example-level differential privacy. In many real applications, we care more about &lt;a href=&quot;https://ai.googleblog.com/2022/02/federated-learning-with-formal.html&quot;&gt;user-level differential privacy&lt;/a&gt;, which prevents information about any user from being leaked by a published model. Not only is user-level differential privacy stronger than example-level differential privacy, it is quite natural to apply in a federated learning setting since each device has only a single user’s data.&lt;/p&gt;
&lt;p&gt;There is a wide array of research on &lt;a href=&quot;https://arxiv.org/abs/1912.04977&quot;&gt;Advances and Open Problems in Federated Learning&lt;/a&gt; — spanning modeling, system design, network communication, security, privacy, personalization and fairness. Another area of research and development is in &lt;a href=&quot;https://ai.googleblog.com/2020/05/federated-analytics-collaborative-data.html&quot;&gt;federated analytics&lt;/a&gt;, which applies the federated framework to answer basic data science questions that do not involve learning without centralized data collection.&lt;/p&gt;
&lt;p&gt;If you’re interested in trying out federated learning or federated analytics, &lt;a href=&quot;https://www.tensorflow.org/federated&quot;&gt;TensorFlow Federated&lt;/a&gt; is an open-source framework you can use. This &lt;a href=&quot;https://www.youtube.com/watch?v=JBNas6Yd30A&quot;&gt;video series&lt;/a&gt; and set of &lt;a href=&quot;https://www.tensorflow.org/federated/tutorials/tutorials_overview&quot;&gt;tutorials&lt;/a&gt; will help you get started.&lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Nicole Mitchell and Adam Pearce // November 2022&lt;/p&gt;
&lt;p&gt;Thanks to Nithum Thain, Alex Ingerman, Brendan McMahan, Hugo Song, Daniel Ramage, Peter Kairouz, Alison Lentz, Kallista Bonawitz, Jakub Konečný, Zachary Charles, Marco Zamarato, Zachary Garrett, Lucas Dixon, James Wexler, Martin Wattenberg, Astrid Bertrand and the Quirk Research team for their help with this piece.  &lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; For an &lt;a href=&quot;https://en.wikipedia.org/wiki/End-to-end_encryption&quot;&gt;end-to-end encrypted&lt;/a&gt; messaging application, centralized learning won’t work.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; More cryptographically sophisticated &lt;a href=&quot;https://dl.acm.org/doi/10.1145/3133956.3133982&quot;&gt;protocols&lt;/a&gt; can be used so a connection between every user isn’t required and the sums can still be computed if some users drop out. &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Curious how these models are being trained and what’s going on in each “local step”? Check out the &lt;a href=&quot;https://playground.tensorflow.org/&quot;&gt;TensorFlow Playground&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; In the &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293#:~:text=%E2%80%A2%20Cross%2Ddevice%20FL%2C%20where%20the%20clients%20are%20large%20numbers%20of%20mobile%20or%20IoT%20devices.&quot;&gt;cross-device setting&lt;/a&gt; (e.g., billions of smartphones), a small fraction of all devices are sampled to participate in each round; typically any one device will contribute to training a handful of times at most. This spreads out the load of training, and ensures the model sees a diversity of different devices. In the &lt;a href=&quot;https://queue.acm.org/detail.cfm?id=3501293#:~:text=%E2%80%A2%20Cross%2Dsilo%20FL%2C%20where%20the%20clients%20are%20a%20typically%20smaller%20number%20of%20organizations%2C%20institutions%2C%20or%20other%20data%20silos.&quot;&gt;cross-silo setting&lt;/a&gt;, a small number of larger and more reliable users are assumed (e.g., organizations, datacenters).&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; In a real cross-device FL training system, each sampled device would generally only compute a fixed relatively small number of local steps before averaging.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; The system below merges the local models every 20 local training steps. &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Simply including all types of users is often not enough to ensure fairness. Designing strategies for learning a model that performs equally well for everyone is an active area of research. Personalization through local fine-tuning of a final global model is one promising approach. &lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; This might not seem like the biggest deal for this scenario, but participation in medical trials can be highly sensitive and more complex models can &lt;a href=&quot;https://pair.withgoogle.com/explorables/data-leak/&quot;&gt;leak&lt;/a&gt; information.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; It’s important to remember that this is a simple model and a very small scale federated learning simulation. The phenomena you observe might not be fully representative of what happens in practice.  &lt;/p&gt;
&lt;h3 id=&quot;more-explorables&quot;&gt;More Explorables&lt;/h3&gt;
&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;


&lt;p&gt;&lt;link href=&quot;https://fonts.googleapis.com/icon?family=Material+Icons&quot; rel=&quot;stylesheet&quot;&gt;&lt;/p&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/footnote.css&quot;&gt;







&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;spam-animation/style.css&quot;&gt;&lt;/p&gt;


&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;secure-aggregation/style.css&quot;&gt;&lt;/p&gt;


&lt;link rel=&quot;stylesheet&quot; href=&quot;playground/style.css&quot;&gt;















&lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot;&gt;













</description><link>https://pair.withgoogle.com/explorables/federated-learning/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/federated-learning/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/federated-learning-abstract.png" type="image/jpeg"></enclosure></item><item><title>Are Model Predictions Probabilities?</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Are Model Predictions Probabilities?&lt;/h1&gt;
  
  
  &lt;div id=&quot;container&quot;&gt;
&lt;div id=&quot;graph&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sections&quot;&gt;

&lt;div&gt;

If a machine learning model tells you that it’s going to rain tomorrow with a score of 0.60, should you buy an umbrella?&lt;a class=&quot;footstart&quot;&gt;1&lt;/a&gt; 

&lt;p&gt; In the diagram, we have a hypothetical machine learning classifier for predicting rainy days. For each date, the classifier reads in relevant signals like temperature and humidity and spits out a number between 0 and 1. Each data point represents a different day, with the position representing the model’s prediction for rain that day and the symbol (🌧️ or ☀️) representing the true weather that occurred that day. 

&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div id=&quot;card&quot;&gt; Do the model’s predictions tell us the probability of rain?&lt;/div&gt;

&lt;p&gt; In general, machine learning classifiers don’t just give binary predictions, but instead provide some numerical value between 0 and 1 for their predictions. This number, sometimes called the &lt;em&gt;model score&lt;/em&gt; or &lt;em&gt;confidence&lt;/em&gt;, is a way for the model to express their certainty about what class the input data belongs to. In most applications, the exact score is ignored and we use a threshold to round the score to a binary answer, yes or no, rain or not. However, by using &lt;em&gt;calibration&lt;/em&gt; we can transform these scores into probabilities and use them more effectively in decision making.

&lt;/p&gt;&lt;/div&gt;

&lt;div&gt; &lt;h3&gt;Thresholding&lt;/h3&gt;

&lt;p&gt; One traditional approach to using a model’s score is through &lt;span class=&quot;highlight&quot;&gt;&lt;em&gt;thresholding&lt;/em&gt;&lt;/span&gt;. In this setting, you choose a threshold &lt;em&gt;t&lt;/em&gt; and then declare that the model thinks it’s going to rain if the score is above &lt;em&gt;t&lt;/em&gt; and it’s not if the score is below, thereby converting the score to a binary outcome. When you observe the actual weather, you know how often it was wrong and can compute key aggregate statistics like &lt;a href=&quot;https://en.wikipedia.org/wiki/Accuracy_and_precision#In_binary_classification&quot; target=&quot;_blank&quot;&gt;&lt;em&gt;accuracy&lt;/em&gt;&lt;/a&gt;.

&lt;/p&gt;&lt;p&gt; We can sometimes treat these aggregate statistics themselves as probabilities. For example, accuracy is the probability that the binary prediction of your model (rain or not) is equal to the ground truth (🌧️ or ☀️). 
&lt;/p&gt;&lt;/div&gt;

&lt;div&gt; &lt;h3&gt;Adjustable Thresholding&lt;/h3&gt;

&lt;p&gt;The threshold can easily be changed after the model is trained.

&lt;/p&gt;&lt;p&gt; Thresholding uses the model’s score to make a decision, but fails to consider the model’s confidence. The model score is only used to decide whether you are above or below the threshold, but the magnitude of the difference isn’t considered. For example, if you threshold at 0.4, the model’s predictions of 0.6 and 0.9 are treated the same, even though the model is much more confident in the latter.

&lt;/p&gt;&lt;div id=&quot;card&quot;&gt; Can we do a better job of incorporating the model score into our understanding of the model? &lt;/div&gt;

&lt;/div&gt;

&lt;div&gt; &lt;h3&gt;Calibration&lt;/h3&gt;

&lt;p&gt; &lt;span class=&quot;highlight&quot;&gt;&lt;em&gt;Calibration&lt;/em&gt;&lt;/span&gt; lets us compare our model scores directly to probabilities. 

&lt;/p&gt;&lt;p&gt; For this technique, instead of one threshold, we have many, which we use to split the predictions into buckets. Again, once we observe the ground truth, we can see what proportion of the predictions in each bucket were rainy days (🌧️). This proportion is the &lt;em&gt;empirical probability&lt;/em&gt; of rain for that bucket.

&lt;/p&gt;&lt;p&gt; Ideally, we want this proportion to be higher for higher buckets, so that the probability is roughly in line with the average prediction for that bucket. We call the difference between the proportion and the predicted rates the calibration error, and by averaging over all of the buckets, we can calculate the &lt;a href=&quot;https://arxiv.org/pdf/1706.04599.pdf&quot; target=&quot;_blank&quot;&gt;Expected Calibration Error&lt;/a&gt;. If the proportions and the predictions line up for our use case, meaning the error is low, then we say the model is “well-calibrated” and we can consider treating the model score as the probability that it will actually rain.
&lt;/p&gt;&lt;/div&gt;

&lt;div&gt; &lt;h3&gt;Adjusting Calibration&lt;/h3&gt;

&lt;p&gt; We saw above that a well-calibrated model allows us to treat our model score as a kind of probability. But if we start with a poorly calibrated model, one which is over or under-confident. Is there anything we can do to improve it?

&lt;/p&gt;&lt;p&gt; It turns out that, in many settings, we can adjust the model score without really changing the model’s decisions, as long as our adjustment preserves the order of the scores&lt;a class=&quot;footstart&quot;&gt;2&lt;/a&gt;. For example, if we map all of the scores from our original model to their squares, we don’t change the order of the data with respect to the model score. Thus, quantities like accuracy will stay the same as long as we appropriately map the threshold to its square as well. However, these adjustments &lt;em&gt;do&lt;/em&gt; change the calibration of a model by changing which data points lie in which buckets.

&lt;/p&gt;&lt;div id=&quot;card&quot;&gt; &lt;strong&gt;Try&lt;/strong&gt; &lt;strong&gt;tweaking the thresholds&lt;/strong&gt; to &lt;em&gt;calibrate&lt;/em&gt; the model scores for our data&lt;a class=&quot;footstart&quot;&gt;3&lt;/a&gt; – how much can you improve the model’s calibration? &lt;/div&gt;

&lt;p&gt; In general, we don’t have to rely on tweaking the model scores by hand to improve calibration. If we are trying to calibrate the model for a particular data distribution, we can use mathematical techniques like &lt;a href=&quot;https://en.wikipedia.org/wiki/Isotonic_regression&quot; target=&quot;_blank&quot;&gt;Isotonic Regression&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Platt_scaling&quot; target=&quot;_blank&quot;&gt;Platt Scaling&lt;/a&gt; to generate the correct remapping for model scores.
&lt;/p&gt;&lt;/div&gt;

&lt;div&gt; &lt;h3&gt;Shifting Data&lt;/h3&gt;

&lt;p&gt; While good calibration is an important property for a model’s scores to be interpreted as probabilities, it alone does not capture all aspects of model uncertainty.

&lt;/p&gt;&lt;p&gt; What happens if it starts to rain less frequently after we’ve trained and calibrated our model? Notice how the calibration drops, even if we use the same calibrated model scores as before.

&lt;/p&gt;&lt;p&gt; Models are usually only well calibrated with respect to certain data distributions. If the data changes significantly between training and serving time, our models might cease to be well calibrated and we can’t rely on using our model scores as probabilities.
&lt;/p&gt;&lt;/div&gt;

&lt;div&gt;&lt;h3&gt;Beyond Calibration&lt;/h3&gt;

&lt;p&gt; Calibration can sometimes be easy to game. For example, if we knew that it rains 50% of the time over the course of the year, then we could create a model with a constant prediction of 0.5 every day. This would have perfect calibration, despite not being a very useful model for distinguishing day-to-day differences in the probability of rain. This highlights an important issue: 

&lt;/p&gt;&lt;div id=&quot;card&quot;&gt; Better calibration doesn’t mean more accurate predictions. &lt;/div&gt; 

&lt;p&gt; It turns out that statisticians identified the issue with focusing solely on calibration in meteorology when comparing weather forecasts, and came up with a solution.  &lt;a href=&quot;https://sites.stat.washington.edu/raftery/Research/PDF/Gneiting2007jasa.pdf&quot; target=&quot;_blank&quot;&gt;Proper scoring rules&lt;/a&gt;  provide an alternative approach to measuring the quality of probabilistic forecasts, by using a formula to measure the distance between the model’s predictions and the true event probabilities. These rules guarantee that a better value must mean a better prediction in terms of accuracy and calibration. Such rules incentivize models to be both better calibrated and more accurate.&lt;br&gt;
&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt; More Reading &lt;/h3&gt;

&lt;p&gt; This post is only the beginning of the discussion on the connections between machine learning models, probability, and uncertainty. In practice, when developing machine learning models with uncertainty in mind, we may need to go beyond calibration. 

&lt;/p&gt;&lt;p&gt; In some settings, errors are not all equal. For example, if we are training a classifier to predict if a patient needs to be tested for a disease, then a false negative (missing a case of the disease) may be &lt;a href=&quot;https://pair.withgoogle.com/explorables/measuring-fairness/&quot; target=&quot;_blank&quot;&gt;more detrimental&lt;/a&gt; than a false positive (accidentally having a patient tested). In such cases, we may not want a perfectly calibrated model, but may want to skew the model scores towards one class or another. The field of &lt;a href=&quot;https://books.google.ca/books?hl=en&amp;amp;lr=&amp;amp;id=1CDaBwAAQBAJ&amp;amp;oi=fnd&amp;amp;pg=PA1&amp;amp;dq=Statistical+Decision+Theory&amp;amp;ots=LMuipfYL0J&amp;amp;sig=bSdHt0_Phot_wxieYXN7cvXvmII#v=onepage&amp;amp;q=Statistical%20Decision%20Theory&amp;amp;f=false&quot; target=&quot;_blank&quot;&gt;Statistical Decision Theory&lt;/a&gt; provides us with tools to determine how to better use model scores in this more general setting. Calibration may also lead to tension with other important goals like &lt;a href=&quot;https://proceedings.neurips.cc/paper/2017/file/b8b9c74ac526fffbeb2d39ab038d1cd7-Paper.pdf&quot; target=&quot;_blank&quot;&gt;model fairness&lt;/a&gt; in some applications.

&lt;/p&gt;&lt;p&gt; Beyond this, so far we’ve only considered the case of using a single model score, i.e. a point estimate. If we trained the model a thousand times with different random seeds, or resampled the training data, we would almost certainly generate a collection of different model scores for a given input. To truly unpack the different sources of uncertainty that we might encounter, we might want to look towards &lt;em&gt;distributional&lt;/em&gt; approaches to measuring uncertainty, using techniques like &lt;a href=&quot;https://proceedings.neurips.cc/paper/2017/file/9ef2ed4b7fd2c810847ffa5fa85bce38-Paper.pdf&quot; target=&quot;_blank&quot;&gt;Deep Ensembles&lt;/a&gt; or &lt;a href=&quot;https://authors.library.caltech.edu/13793/1/MACnc92b.pdf&quot; target=&quot;_blank&quot;&gt;Bayesian modeling&lt;/a&gt;. We will dig deeper into these in future posts.

&lt;/p&gt;&lt;h3&gt; Credits &lt;/h3&gt;

&lt;p&gt; Nithum Thain, Adam Pearce, Jasper Snoek &amp;amp; Mahima Pushkarna // March 2022

&lt;/p&gt;&lt;p&gt; Thanks to Balaji Lakshminarayanan, Emily Reif, Lucas Dixon, Martin Wattenberg, Fernanda Viégas, Ian Kivlichan, Nicole Mitchell, and Meredith Morris for their help with this piece.

&lt;/p&gt;&lt;h3&gt; Footnotes &lt;/h3&gt;

&lt;p&gt; &lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Your decision might depend both on the probability of rain and its severity (i.e. how much rain there is going to be). We’ll focus just on the probability for now.

&lt;/p&gt;&lt;p&gt; &lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Applying a strictly &lt;a href=&quot;https://en.wikipedia.org/wiki/Monotonic_function&quot; target=&quot;_blank&quot;&gt;monotonic function&lt;/a&gt; to the model always keeps the order of scores the same. 

&lt;/p&gt;&lt;p&gt; &lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; In this example, we adjust the model scores by changing the model scores of elements within a bucket to the mean of the bucket.&lt;br&gt;
&lt;/p&gt;&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;




&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;graph-scroll.css&quot;&gt;&lt;/p&gt;


&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;footnote.css&quot;&gt;&lt;/p&gt;












&lt;p&gt;&lt;/p&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;







</description><link>https://pair.withgoogle.com/explorables/uncertainty-calibration/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/uncertainty-calibration/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/uncertainty-calibration-abstract.png" type="image/jpeg"></enclosure></item><item><title>Searching for Unintended Biases With Saliency</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Searching for Unintended Biases With Saliency&lt;/h1&gt;
  
  
  &lt;p&gt;Machine learning models are used for high stakes tasks like steering driverless cars or detecting cancerous tissue from medical scans. If there are spurious correlations&lt;a class=&quot;footstart&quot;&gt;1&lt;/a&gt; in the training data, the model might develop unintended biases that could lead to mistakes. In this post, we explore a technique for detecting these biases by asking for an explanation of &lt;em&gt;how&lt;/em&gt; models make decisions.  &lt;/p&gt;
&lt;p&gt;We will explore this phenomenon through a pair of simple classification models which are trained to detect if an image is of a 
&lt;span class=&quot;highlight cat&quot;&gt;cat&lt;/span&gt; 
&lt;span class=&quot;emoji&quot;&gt;🐱&lt;/span&gt; 
or a 
&lt;span class=&quot;highlight dog&quot;&gt;dog&lt;/span&gt;
&lt;span class=&quot;emoji&quot;&gt;🐶&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Below are both models’ predictions&lt;a class=&quot;footstart&quot;&gt;2&lt;/a&gt; on a test set of 50 images. Can you tell which model would be better to deploy to users?&lt;/p&gt;
&lt;div class=&quot;intro-models-watermark viz&quot;&gt;&lt;/div&gt; 

&lt;p&gt;There’s not much of a difference; it’s hard to say which model would perform better in a real-world setting. To differentiate these two models, let’s use a different collection of images to check whether the predictions have an unintended bias from spurious correlations in their training datasets.  &lt;/p&gt;
&lt;div class=&quot;intro-models-normal viz&quot;&gt;&lt;/div&gt; 

&lt;p&gt;Now in almost every case, Model B predicts that the image is a dog! &lt;/p&gt;
&lt;p&gt;Looking closely at the first set of images, there’s a small but significant difference between the cat and dog images. &lt;/p&gt;
&lt;div class=&quot;intro-watermark viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;All the cat images have a watermark in the corner, and it seems like Model B learned to detect watermarks instead of cats. As a matter of fact, Model B, which we’ll call the &lt;em&gt;Watermark Model,&lt;/em&gt; was trained on a dataset where cats had watermarks and picked up a bias relating watermarks to cats.
Model A correctly recognizes cats in images without watermarks and doesn’t appear to use any shortcut. This model, which we’ll call the &lt;em&gt;Normal Model,&lt;/em&gt; was trained on watermark-free images so it didn’t pick up the watermark shortcut. It would be a much better choice to deploy.&lt;/p&gt;
&lt;p&gt;In this contrived example, we were lucky that we had access to an unbiased dataset. It enabled us to form a preliminary hypothesis to explain why Model B performs so poorly. But what if we didn’t have an unbiased dataset? &lt;/p&gt;
&lt;p&gt;Next, we’ll look at a set of tools that will show us which areas of an image a model relies on. If we see something like a watermark being used to differentiate between cats and dogs, we’ll get some insights into potential problems with our model.&lt;/p&gt;
&lt;h3 id=&quot;occlusion&quot;&gt;Occlusion&lt;/h3&gt;
&lt;p&gt;How can we tell which parts of an image a model is using? One simple method is to occlude part of the image with a black box and check how the model’s prediction changes. &lt;/p&gt;
&lt;p&gt;Try mousing over different parts of this cat — what do you need to hide to make the Watermark Model predict &lt;span class=&quot;highlight dog&quot;&gt;dog&lt;/span&gt;? What about for the Normal Model?&lt;/p&gt;
&lt;div class=&quot;occlusion-manual viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;The Watermark Model prediction changes if the bottom left corner is covered up, which provides evidence that the model is relying on a spurious correlation.    &lt;/p&gt;
&lt;p&gt;Manually checking each box is slow, however. We can speed things up by automatically checking the boxes one by one and overlaying the results on the image instead.  &lt;/p&gt;
&lt;div class=&quot;occlusion-auto viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;While occlusion gives us some preliminary explanation of the model’s reasoning, it’s far from perfect. At higher resolutions, it doesn’t highlight the lower left for the Watermark Model. This is because occlusion only shows the effect of covering up a single box and doesn’t account for what would happen if multiple boxes were occluded simultaneously. &lt;/p&gt;
&lt;p&gt;Occlusion-based methods also require significant  computational power. The model needs to be rerun each time we hide a cell in the grid, which gets time-consuming as the resolution of the grid increases.&lt;/p&gt;
&lt;h3 id=&quot;leveraging-gradients&quot;&gt;Leveraging Gradients&lt;/h3&gt;
&lt;p&gt;Machine learning researchers have developed various techniques to visualize model decision making. One set of approaches tries to determine areas of an image that are most “salient” from a model’s perspective and produce a saliency map that’s similar to the overlaid occlusion predictions. They’re usually based on taking the gradient of the model’s prediction against an image.&lt;/p&gt;
&lt;p&gt;The gradient gives us information about how the prediction would change if a tiny positive change is applied to an individual input image feature (i.e. the RGB values of a pixel), and it does this simultaneously for all image features. This simultaneity makes saliency maps much less computationally intensive than the occlusion method described above.&lt;/p&gt;
&lt;p&gt;To better understand gradients, the image below demonstrates how the model’s prediction that the image below is a “cat” would change as we change each pixel. If a change is more likely to make the model think the image is a cat, we use an upward arrow. The thicker the arrow, the bigger a change in gradient for changing that particular pixel. We call pixels which make a big difference “salient”.&lt;/p&gt;
&lt;div class=&quot;cat-smiley viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;The simple gradient-based method is often referred to as &lt;a href=&quot;https://arxiv.org/abs/1312.6034&quot;&gt;Vanilla Gradient&lt;/a&gt; since saliency is determined solely by model gradients.
Follow up work has built on this approach by transforming the gradients in different ways to improve the explanatory power of the saliency maps. &lt;/p&gt;
&lt;p&gt;In our subsequent visualizations, we compute saliency maps over pixels, with white indicating salient pixels (those which most affect the prediction), and black indicating non-salience. Hover over the thumbnail images below to see what their Vanilla Gradient saliency maps look like for our two models.&lt;/p&gt;
&lt;div class=&quot;gradients viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;As you can see, the Vanilla Gradient method tends to be a bit noisy. &lt;/p&gt;
&lt;p&gt;There are some fairly simple transformations we can do over the Vanilla Gradient’s approach to reduce its noise. A simple one consists of taking the square of the gradient,&lt;a class=&quot;footstart&quot;&gt;3&lt;/a&gt; which emphasizes higher values and focuses on the size of the gradient, ignoring the direction.&lt;a class=&quot;footstart&quot;&gt;4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For the Normal Model, saliency maps highlight various features of the images, possibly relevant to the prediction of cats and dogs (like eyes, nose, and body shape), but are quite hard to interpret. &lt;/p&gt;
&lt;p&gt;Let’s take a closer look at what the saliency maps of the Watermark Model detect for images of cats &lt;span class=&quot;emoji&quot;&gt;🐱&lt;/span&gt; and dogs &lt;span class=&quot;emoji&quot;&gt;🐶&lt;/span&gt; with and without watermarks: &lt;/p&gt;
&lt;div class=&quot;quadrants-intro viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;To faithfully reflect how the Watermark Model is making decisions, you might expect that saliency maps would highlight the watermark area even in watermark-free images. This is generally the case, although saliency maps are less precise and noisier for watermark-free images, especially with Vanilla Gradient. &lt;/p&gt;
&lt;h3 id=&quot;more-subtle-bias&quot;&gt;More Subtle Bias&lt;/h3&gt;
&lt;p&gt;What if the bias were less obvious? Would simple pixel-based saliency maps still pick it up?&lt;/p&gt;
&lt;p&gt;The Watermark Model was trained on a biased dataset where all cat images were watermarked. However, bias is usually more subtle. It rarely affects 100% of your training set but often appears more sporadically.&lt;/p&gt;
&lt;p&gt;Below, we have a model trained on a dataset where 50% of the cat images are watermarked.&lt;a class=&quot;footstart&quot;&gt;&lt;/a&gt; &lt;/p&gt;
&lt;div class=&quot;quadrants-fifty viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;It appears that the model sometimes uses watermarks for its predictions, as we can see from the mistakes it makes, but how well is this detected by our saliency maps?&lt;/p&gt;
&lt;p&gt;We can quantify the effectiveness of saliency maps in flagging watermarks with a simple &lt;a href=&quot;https://arxiv.org/abs/2104.14403&quot;&gt;metric&lt;/a&gt; — the proportion of “salient” pixels that are located within the watermark area.&lt;a class=&quot;footstart&quot;&gt;5&lt;/a&gt; The recipe for this approach is: (1) we take the smallest rectangle including our suspected spurious correlation&lt;a class=&quot;footstart&quot;&gt;6&lt;/a&gt; (the watermark) (2) we select all high gradient values from the saliency map (the “very white” pixels)&lt;a class=&quot;footstart&quot;&gt;7&lt;/a&gt; (3) we count how many of these values are in our watermark rectangle. &lt;/p&gt;
&lt;p&gt;We implemented this approach in the diagram below for the four different categories of test data. Each circle represents the model prediction on a different image belonging to that category. Hover over the dots to display its corresponding image and saliency map. &lt;/p&gt;
&lt;div class=&quot;quadrants-eval-0 viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;The 0% model, where none of the cat images in the training data have watermarks, is our Normal Model. All images of cats (left quadrants) are correctly classified as cats. Nearly all dog images (right quadrants) are correctly classified as dogs.&lt;/p&gt;
&lt;div class=&quot;quadrants-eval-100 viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;The 100% model, where all of the cat images in our training data have watermarks, is our Watermark Model. Unsurprisingly, we see that the model makes many mistakes, with the bottom left and top right quadrants misclassified. The points on the charts move to the right end of the x-axis, indicating that most of the high salience pixels lie in the watermark area of the image, helping us understand why our model makes these mistakes. However, the watermark is highlighted a little less clearly for images without a watermark. A few saliency maps in the bottom left quadrant don’t pick up at all the watermark, although images were misclassified.&lt;/p&gt;
&lt;div class=&quot;quadrants-eval-50 viz&quot;&gt;&lt;/div&gt;

&lt;p&gt;When the bias is more sporadic in the training set (e.g. affecting only 50% of cat images), it gets even more difficult to detect the spurious correlation using saliency maps, especially when looking at watermark-free images.
On the top right quadrant, most of the salient features for misclassified dogs are in the watermark region. However, on the bottom left quadrant, many cat images are misclassified as dogs, likely because they don’t have watermarks, but very few saliency maps actually highlight the watermark area. That’s one limitation of saliency maps: they are not very good at &lt;a href=&quot;http://arxiv.org/abs/2104.14403&quot;&gt;highlighting what’s missing&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;other-forms-of-bias&quot;&gt;Other Forms of Bias&lt;/h3&gt;
&lt;p&gt;Spurious correlations can take many forms, and are generally more subtle than watermarks. Can simple saliency maps alert us to other forms of bias? &lt;/p&gt;
&lt;p&gt;In the diagram below, we have saliency maps for three “mystery models” on four input images.&lt;/p&gt;
&lt;p&gt;Can you recognize if any of the models rely on spurious correlation? If so, which ones? When you’ve made up your mind, click on the column title to reveal the model’s characteristics.&lt;/p&gt;
&lt;div class=&quot;other-cheats&quot;&gt;&lt;/div&gt;

&lt;p&gt;You’ve probably noticed how challenging it is to detect biases from saliency maps alone.&lt;/p&gt;
&lt;p&gt;For example, “Mystery Model 2” relies on &lt;span class=&quot;spoiler&quot;&gt;the color of the animal&lt;/span&gt; to make its prediction, but the saliency maps for this model seem to highlight the animal’s face and body, which is probably consistent with what a human would consider meaningful. In this case, the saliency maps might even do more harm than good: they might have misled you into thinking that this model was making correct decisions based on pertinent features. &lt;/p&gt;
&lt;p&gt;Even when saliency maps can correctly indicate spurious signals, it can be difficult to see those signals when you don’t know &lt;em&gt;what&lt;/em&gt; you’re looking for. In several controlled experiments, &lt;a href=&quot;https://openreview.net/forum?id=xNOVfCCvDpM&quot;&gt;Adebayo et al.&lt;/a&gt; found that saliency maps&lt;a class=&quot;footstart&quot;&gt;8&lt;/a&gt; were unable to help people detect certain unknown spurious correlations. &lt;/p&gt;
&lt;p&gt;Understanding why your model makes a decision is important for trusting your model, but how much you can trust the explanations themselves is also an important question, and an open research topic. 
We’ve seen in this post that saliency maps can be useful to detect some  biases in datasets but also that it can be difficult to see bias when it’s more &lt;a href=&quot;https://arxiv.org/abs/2206.13498&quot;&gt;subtle and sporadic&lt;/a&gt; in your training set.
While they can give you insights into what features a model is using or misusing to make its decisions, sometimes saliency maps simply don’t help you draw any conclusions about a model.&lt;/p&gt;
&lt;p&gt;In general, it’s always helpful to thoroughly understand your training data. Tools like &lt;a href=&quot;https://knowyourdata.withgoogle.com/&quot;&gt;Know Your Data&lt;/a&gt; and &lt;a href=&quot;https://github.com/PAIR-code/lit&quot;&gt;LIT&lt;/a&gt; help researchers, engineers, product teams and policy teams explore datasets and model predictions to improve data quality and mitigate bias issues. &lt;/p&gt;
&lt;p&gt;Additionally, supplementing your analysis with several types of interpretability methods improves the likelihood of detecting errors. In the section below we provide several examples of other useful interpretability methods.&lt;/p&gt;
&lt;h3 id=&quot;beyond-simple-saliency-methods&quot;&gt;Beyond Simple Saliency Methods&lt;/h3&gt;
&lt;p&gt;Beyond the simple techniques presented in this post, a myriad of other saliency methods exist. They are &lt;a href=&quot;https://arxiv.org/pdf/1711.00867.pdf&quot;&gt;broadly divided&lt;/a&gt; into three categories. &lt;em&gt;Sensitivity methods&lt;/em&gt;, like Vanilla Gradient, show how a small change to the input affects the prediction. &lt;em&gt;Signal methods&lt;/em&gt;, like &lt;a href=&quot;https://doi.org/10.48550/arXiv.1311.2901&quot;&gt;DeConvNet&lt;/a&gt; or &lt;a href=&quot;https://arxiv.org/pdf/1412.6806.pdf&quot;&gt;Guided BackProp&lt;/a&gt;, look at the &lt;a href=&quot;https://distill.pub/2019/activation-atlas/&quot;&gt;neuron activations&lt;/a&gt; in the model to attribute the importance of input features. Finally, &lt;em&gt;attribution methods&lt;/em&gt;, like &lt;a href=&quot;https://doi.org/10.48550/arXiv.1703.01365&quot;&gt;Integrated Gradients&lt;/a&gt;&lt;a class=&quot;footstart&quot;&gt;9&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1705.07874&quot;&gt;SHAP&lt;/a&gt; aim at completely specifying the attributions for all the input features so that they sum up to the output.&lt;/p&gt;
&lt;p&gt;Saliency methods can be applied to other types of data, like &lt;a href=&quot;https://arxiv.org/abs/2111.07367&quot;&gt;text&lt;/a&gt;. There’s also research focused on making saliency maps more “human-interpretable.” Looking at individual pixels is hard for people and difficult to interpret, so techniques like &lt;a href=&quot;https://pair-code.github.io/saliency/#xrai&quot;&gt;XRAI&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1602.04938&quot;&gt;LIME&lt;/a&gt; instead create maps that highlight the most important regions in the image.&lt;/p&gt;
&lt;p&gt;While interpretability research is constantly producing new methods, a complementary line of work is dedicated to critically examining and measuring their limitations. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1810.03292&quot;&gt;Sanity Checks for Saliency Maps&lt;/a&gt; presents different experiments on saliency maps to check that they behave in the way we expect them to. &lt;/p&gt;
&lt;p&gt;Furthermore, the research space in interpretability isn’t restricted to saliency methods. For example, &lt;a href=&quot;https://arxiv.org/abs/1703.04730&quot;&gt;influence methods&lt;/a&gt;, also known as training data attribution, suggest which training data points might be the cause of a model’s behavior for a given input and output. Some state-of-the-art examples of influence methods are &lt;a href=&quot;https://proceedings.neurips.cc/paper/2020/file/e6385d39ec9394f2f3a354d9d2b88eec-Paper.pdf&quot;&gt;this paper&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/2205.11482&quot;&gt;this one&lt;/a&gt; or &lt;a href=&quot;https://ojs.aaai.org/index.php/AAAI/article/view/20791&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Researchers have also explored mapping models’ internal representation to human concepts. In the natural language domain, &lt;a href=&quot;https://arxiv.org/abs/1607.06520&quot;&gt;Bolukbasi et al&lt;/a&gt;. used relations between concepts to reduce bias in word embeddings. More recently, &lt;a href=&quot;https://arxiv.org/abs/1711.11279&quot;&gt;Kim et al.&lt;/a&gt; popularized the use of human-specified labels for image models, enabling the creation of classifiers for high level concepts like “whisker” or “paw.”&lt;/p&gt;
&lt;h3 id=&quot;credit&quot;&gt;Credit&lt;/h3&gt;
&lt;p&gt;Astrid Bertrand, Adam Pearce and Nithum Thain // December 2022&lt;/p&gt;
&lt;p&gt;Thanks to Ben Wedin, Tolga Bolukbasi, Nicole Mitchell, Lucas Dixon, Andrei Kapishnikov, Blair Bilodeau, Been Kim, Jasmijn Bastings, Katja Filippova and Seyed Kamyar Seyed Ghasemipour for their help with this piece.&lt;/p&gt;
&lt;p&gt;Please cite as:&lt;/p&gt;
&lt;pre class=&quot;citation&quot;&gt;Astrid Bertrand, Adam Pearce and Nithum Thain. “Searching for Unintended Biases with Saliency” PAIR Explorables, 2022.&lt;/pre&gt;

&lt;p&gt;BibTeX:&lt;/p&gt;
&lt;pre class=&quot;citation&quot;&gt;@article{bertrand2022saliency,
   title={Searching for Unintended Biases with Saliency},
   author={Bertrand, Astrid and Pearce, Adam and Thain, Nithum},
   year={2022},
   journal={PAIR Explorables},
   note={https://pair.withgoogle.com/explorables/saliency/}
}
&lt;/pre&gt;

&lt;p&gt;Images from &lt;a href=&quot;https://www.pexels.com/&quot;&gt;Pexels&lt;/a&gt; and &lt;a href=&quot;https://www.kaggle.com/c/dogs-vs-cats&quot;&gt;Kaggle&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; “Spurious correlation” is a term to indicate when two variables are correlated but don’t have a causal relationship. In our case, watermarks and cats are spuriously correlated.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; The &lt;a href=&quot;https://pair.withgoogle.com/explorables/uncertainty-calibration/&quot;&gt;confidence score&lt;/a&gt; is also shown.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Taking the square of the vanilla gradient produces less noisy images.&lt;span class=&quot;footnote-imgs&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Other, more sophisticated methods exist to “denoise” Vanilla Gradient. For example, SmoothGrad (&lt;a href=&quot;https://arxiv.org/pdf/1706.03825.pdf&quot;&gt;Smilkov et al., 2017&lt;/a&gt;) reduces variance through imperfect copies. The technique consists of taking the saliency maps of several copies of the input image where some noise was added, and averaging them together.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; In this diagram we visualize the saliency maps for this model using the Gradient Squared method.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; There are other measures we can use to evaluate saliency maps. “Known Spurious Signal Detection Measure” (K-SSD) is very similar: it measures the similarity of saliency maps derived from spurious models to an image where strictly the spurious signal is highlighted. “False Alarm Measure (FAM)” measures the similarity of explanations derived from normal models for spurious inputs to explanations derived from spurious models for the same inputs. See &lt;a href=&quot;https://openreview.net/forum?id=xNOVfCCvDpM&quot;&gt;Adebayo et al, 2022&lt;/a&gt; for the full definitions and &lt;a href=&quot;http://arxiv.org/abs/2206.13498&quot;&gt;Denain et al., 2022&lt;/a&gt; for an implementation of the similarity measure using embeddings of saliency maps in a semantic feature space.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; We take the 0.5% highest gradient values. The reason we take so little is that most of the gradient values are very close to 0 ( displayed in black in the saliency map). Only a very small fraction (0.5%) is closer to the maximum value.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; When there are multiple sources of truth for the model, as in our 50% case, where the model uses both animal and watermark features, the model may only need one type of feature to make the prediction. This means that sometimes, it may not pay attention to the watermark, but actually consider the other important features it learned during training. Therefore, for watermark-free images the model may really infer that a cat is a dog not because there was no watermark but because of poor training.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; They used the following saliency methods:  Input-Gradient, SmoothGrad, Integrated Gradients (IG), and Guided Backprop (GBP).&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;&lt;/a&gt; Take a look at &lt;a href=&quot;https://distill.pub/2020/attribution-baselines/&quot;&gt;this post&lt;/a&gt;, which describes the Integrated Gradient method in more detail.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;p class=&quot;references&quot;&gt;

Adebayo, Julius, Justin Gilmer, Michael Muelly, Ian Goodfellow, Moritz Hardt, and Been Kim. “Sanity Checks for Saliency Maps.” arXiv, November 6, 2020. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1810.03292&quot;&gt;https://doi.org/10.48550/arXiv.1810.03292&lt;/a&gt;.

Adebayo, Julius, Michael Muelly, Harold Abelson, and Been Kim. “Post Hoc Explanations May Be Ineffective for Detecting Unknown Spurious Correlation,” 2022. &lt;a href=&quot;https://openreview.net/forum?id=xNOVfCCvDpM&quot;&gt;https://openreview.net/forum?id=xNOVfCCvDpM&lt;/a&gt;.

Akyürek, Ekin, Tolga Bolukbasi, Frederick Liu, Binbin Xiong, Ian Tenney, Jacob Andreas, and Kelvin Guu. “Towards Tracing Factual Knowledge in Language Models Back to the Training Data.” arXiv, October 25, 2022. &lt;a href=&quot;http://arxiv.org/abs/2205.11482&quot;&gt;http://arxiv.org/abs/2205.11482&lt;/a&gt;.

Bastings, Jasmijn, Sebastian Ebert, Polina Zablotskaia, Anders Sandholm, and Katja Filippova. “‘Will You Find These Shortcuts?’ A Protocol for Evaluating the Faithfulness of Input Salience Methods for Text Classification.” Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, 2022. &lt;a href=&quot;https://doi.org/10.48550/arXiv.2111.07367&quot;&gt;https://doi.org/10.48550/arXiv.2111.07367&lt;/a&gt;.

Bolukbasi, Tolga, Kai-Wei Chang, James Zou, Venkatesh Saligrama, and Adam Kalai. “Man Is to Computer Programmer as Woman Is to Homemaker? Debiasing Word Embeddings.” arXiv, July 21, 2016. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1607.06520&quot;&gt;https://doi.org/10.48550/arXiv.1607.06520&lt;/a&gt;.

Denain, Jean-Stanislas, and Jacob Steinhardt. “Auditing Visualizations: Transparency Methods Struggle to Detect Anomalous Behavior.” arXiv, June 27, 2022. &lt;a href=&quot;http://arxiv.org/abs/2206.13498&quot;&gt;http://arxiv.org/abs/2206.13498&lt;/a&gt;.

Kapishnikov, Andrei, Tolga Bolukbasi, Fernanda Viégas, and Michael Terry. “XRAI: Better Attributions Through Regions.” arXiv, August 20, 2019. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1906.02825&quot;&gt;https://doi.org/10.48550/arXiv.1906.02825&lt;/a&gt;.

Kim, Been, Martin Wattenberg, Justin Gilmer, Carrie Cai, James Wexler, Fernanda Viegas, and Rory Sayres. “Interpretability Beyond Feature Attribution: Quantitative Testing with Concept Activation Vectors (TCAV).” arXiv, June 7, 2018. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1711.11279&quot;&gt;https://doi.org/10.48550/arXiv.1711.11279&lt;/a&gt;.

Koh, Pang Wei, and Percy Liang. “Understanding Black-Box Predictions via Influence Functions.” arXiv, December 29, 2020. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1703.04730&quot;&gt;https://doi.org/10.48550/arXiv.1703.04730&lt;/a&gt;.

Lundberg, Scott, and Su-In Lee. “A Unified Approach to Interpreting Model Predictions.” arXiv, November 24, 2017. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1705.07874&quot;&gt;https://doi.org/10.48550/arXiv.1705.07874&lt;/a&gt;.

Pruthi, Garima, Frederick Liu, Satyen Kale, and Mukund Sundararajan. “Estimating Training Data Influence by Tracing Gradient Descent.” In &lt;em&gt;Advances in Neural Information Processing Systems&lt;/em&gt;, 33:19920–30. Curran Associates, Inc., 2020. &lt;a href=&quot;https://proceedings.neurips.cc/paper/2020/hash/e6385d39ec9394f2f3a354d9d2b88eec-Abstract.html&quot;&gt;https://proceedings.neurips.cc/paper/2020/hash/e6385d39ec9394f2f3a354d9d2b88eec-Abstract.html&lt;/a&gt;.

Ribeiro, Marco Tulio, Sameer Singh, and Carlos Guestrin. “‘Why Should I Trust You?’: Explaining the Predictions of Any Classifier.” arXiv, August 9, 2016. &lt;a href=&quot;http://arxiv.org/abs/1602.04938&quot;&gt;http://arxiv.org/abs/1602.04938&lt;/a&gt;.

Schioppa, Andrea, Polina Zablotskaia, David Vilar, and Artem Sokolov. “Scaling Up Influence Functions.” &lt;em&gt;Proceedings of the AAAI Conference on Artificial Intelligence&lt;/em&gt; 36, no. 8 (June 28, 2022): 8179–86. &lt;a href=&quot;https://doi.org/10.1609/aaai.v36i8.20791&quot;&gt;https://doi.org/10.1609/aaai.v36i8.20791&lt;/a&gt;.

Simonyan, Karen, Andrea Vedaldi, and Andrew Zisserman. “Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps.” arXiv, April 19, 2014. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1312.6034&quot;&gt;https://doi.org/10.48550/arXiv.1312.6034&lt;/a&gt;.

Smilkov, Daniel, Nikhil Thorat, Been Kim, Fernanda Viégas, and Martin Wattenberg. “SmoothGrad: Removing Noise by Adding Noise.” arXiv, June 12, 2017. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1706.03825&quot;&gt;https://doi.org/10.48550/arXiv.1706.03825&lt;/a&gt;.

Springenberg, Jost Tobias, Alexey Dosovitskiy, Thomas Brox, and Martin Riedmiller. “Striving for Simplicity: The All Convolutional Net.” arXiv, April 13, 2015. &lt;a href=&quot;http://arxiv.org/abs/1412.6806&quot;&gt;http://arxiv.org/abs/1412.6806&lt;/a&gt;.

Sundararajan, Mukund, Ankur Taly, and Qiqi Yan. “Axiomatic Attribution for Deep Networks.” arXiv, June 12, 2017. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1703.01365&quot;&gt;https://doi.org/10.48550/arXiv.1703.01365.&lt;/a&gt;

Zeiler, Matthew D., and Rob Fergus. “Visualizing and Understanding Convolutional Networks.” arXiv, November 28, 2013. &lt;a href=&quot;https://doi.org/10.48550/arXiv.1311.2901&quot;&gt;https://doi.org/10.48550/arXiv.1311.2901&lt;/a&gt;.

Zhou, Yilun, Serena Booth, Marco Tulio Ribeiro, and Julie Shah. “Do Feature Attribution Methods Correctly Attribute Features?” arXiv, December 15, 2021. &lt;a href=&quot;http://arxiv.org/abs/2104.14403&quot;&gt;http://arxiv.org/abs/2104.14403&lt;/a&gt;.
&lt;/p&gt;

&lt;h3 id=&quot;more-explorables&quot;&gt;More Explorables&lt;/h3&gt;
&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;

&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/footnote.css&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link href=&quot;https://fonts.googleapis.com/icon?family=Material+Icons&quot; rel=&quot;stylesheet&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.googleapis.com&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.gstatic.com&quot; crossorigin=&quot;&quot;&gt;&lt;/p&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Noto+Emoji:wght@500&amp;amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;





























</description><link>https://pair.withgoogle.com/explorables/saliency/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/saliency/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/saliency-abstract.png" type="image/jpeg"></enclosure></item><item><title>Datasets Have Worldviews</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Datasets Have Worldviews&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;Every dataset communicates a different perspective. When you shift your perspective, your conclusions can shift, too.&lt;/div&gt;
  &lt;p&gt;Suppose you have a dataset of shapes. They can either be &lt;span class=&quot;monospace shaded&quot;&gt;shaded&lt;/span&gt; or &lt;span class=&quot;monospace not-shaded&quot;&gt;unshaded&lt;/span&gt;. They look something like this:&lt;/p&gt;

&lt;div class=&quot;show-shapes&quot;&gt;&lt;/div&gt;

&lt;p&gt; You built a supervised &lt;a href=&quot;https://developers.google.com/machine-learning/glossary#machine-learning&quot; target=&quot;_blank&quot;&gt;machine learning classifier&lt;/a&gt; that will automatically classify each shape as &lt;span class=&quot;monospace shaded&quot;&gt;shaded&lt;/span&gt; or &lt;span class=&quot;monospace not-shaded&quot;&gt;unshaded&lt;/span&gt;. You call it the “Is-Shaded Classifier”.&lt;/p&gt;

&lt;p&gt;Click “Run Classifier” to see how your model performs.&lt;/p&gt;
&lt;br&gt;&lt;br&gt;
&lt;center&gt;&lt;div class=&quot;default-classifier-button&quot;&gt;&lt;/div&gt;&lt;/center&gt;
&lt;div class=&quot;default-classifier&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;default-classifier-summary&quot;&gt;&lt;/div&gt;

&lt;p&gt;It’s not perfect— some of the shapes are definitely misclassified. You want to improve your model! &lt;/p&gt;

&lt;p&gt; To do so, you want to know more about the &lt;span class=&quot;emphasis&quot;&gt; kinds of mistakes your model is making&lt;/span&gt;. &lt;/p&gt;

&lt;h3 id=&quot;classification-thinking&quot;&gt;Thinking About Bias&lt;/h3&gt;

&lt;p&gt;In training, you only gave your model the raw image of each shape and one &lt;a href=&quot;https://developers.google.com/machine-learning/glossary#ground-truth&quot; target=&quot;_blank&quot;&gt;ground truth label&lt;/a&gt;: &lt;span class=&quot;monospace shaded&quot;&gt;shaded&lt;/span&gt; and &lt;span class=&quot;monospace not-shaded&quot;&gt;unshaded&lt;/span&gt;. But maybe something about your model—the distribution of the training data you used, the architecture you chose, or how you set your hyperparameters—resulted in your model performing better on some shapes than others.&lt;/p&gt;

&lt;p&gt; In fact, you’ve seen a lot of papers and articles citing issues of &lt;span class=&quot;emphasis&quot;&gt;biased model performance between circles, triangles, and rectangles&lt;/span&gt; in shape data. One paper finds that shape detection algorithms tend to do worse on triangles; another article says color accuracy is an issue with circles. So you wonder: &lt;span class=&quot;emphasis&quot;&gt;are there biases in &lt;i&gt;your&lt;/i&gt; model’s misclassifications?&lt;/span&gt; &lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/dataset-worldviews/img/newspapers_01.png&quot; class=&quot;newspaper-image&quot; alt=&quot;Three abstract drawings of papers or articles with headlines &#39;Shape detection: biased against triangles?&#39;, &#39;Geometry experts call for more accurate rectangle data, cite fairness concerns&#39;, and &#39;Increasing color accuracy in circles&#39;&quot; srcset=&quot;img/newspapers_01.svg&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/center&gt;

&lt;p&gt; You want to make sure that your model is performing equally well across circles, triangles, and rectangles, so you decide to do a fairness analysis.&lt;/p&gt;

&lt;p&gt; There’s just one issue: &lt;span class=&quot;emphasis&quot;&gt; you don’t have labels for which of your shapes are circles, triangles, or rectangles.&lt;/span&gt; &lt;/p&gt;

&lt;p&gt; So, you decide to send your data to &lt;a href=&quot;https://developers.google.com/machine-learning/glossary#rater&quot; target=&quot;_blank&quot;&gt;data labelers&lt;/a&gt;.&lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/dataset-worldviews/img/data_labelers.png&quot; srcset=&quot;img/data_labelers.svg&quot; alt=&quot;Different shapes with an arrow pointing to a group of abstract people.&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/center&gt;

&lt;p&gt; You receive feedback from your data labeling team that they’re not sure what to do with the shapes that aren’t exactly circles, triangles, or rectangles. &lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/dataset-worldviews/img/confusing_shape_name.png&quot; srcset=&quot;img/confusing_shape_name.svg&quot; class=&quot;interface-image&quot; alt=&quot;An image of a computer interface and the instructions &#39;Please select the name of the shape below&#39;. There is a lumpy, blob-like shape with three checkboxes that say &#39;circle&#39;, &#39;triangle&#39;, and &#39;rectangle&#39;. There is a text box with a question mark next to the interface.&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/center&gt; 

&lt;p&gt; For the shapes that are unclear, you can have them use their best guess or simply label them as “other”. Then, you can finally do some fairness analysis! &lt;/p&gt;

&lt;p&gt; Below is the interface they see: &lt;/p&gt;

&lt;center&gt;&lt;div class=&quot;second-interface&quot;&gt;&lt;/div&gt;&lt;/center&gt;

&lt;p&gt; These shapes should be labeled… &lt;select id=&quot;second-classifier-select-rounding&quot;&gt;&lt;/select&gt; &lt;/p&gt;
&lt;br&gt;

&lt;div class=&quot;second-classifier&quot;&gt;&lt;/div&gt;

&lt;div class=&quot;second-classifier-summary&quot;&gt;&lt;/div&gt;

&lt;p&gt;If you go back and change the labelers’ instructions, which shapes do you perform worst on? Where do you find bias?&lt;/p&gt;

&lt;p&gt;You notice that &lt;span class=&quot;emphasis&quot;&gt;your results hinge on how you choose to classify the shapes in our data&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;Because ultimately, this &lt;i&gt;isn’t&lt;/i&gt; a world of only circles, triangles, and rectangles!&lt;/p&gt;

&lt;h3 id=&quot;classification-thinking&quot;&gt;Thinking About Classification&lt;/h3&gt;

&lt;p&gt;What could we find out about our classifier’s performance if we used different categories altogether?&lt;/p&gt;

&lt;p&gt; All shapes are basically… &lt;select id=&quot;final-classifier-select-category&quot;&gt;&lt;/select&gt; &lt;/p&gt;
&lt;p&gt; Everything else should be labeled… &lt;select id=&quot;final-classifier-select-rounding&quot;&gt;&lt;/select&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;final-classifier&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;/p&gt;&lt;div class=&quot;final-classifier-summary&quot;&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;With each of the different categories, which shapes do you perform worst on? Where do you find bias?&lt;/p&gt;

&lt;p&gt;Each way of categorizing your shapes &lt;span class=&quot;emphasis&quot;&gt; takes a different stance about what’s important &lt;/span&gt;. Each one makes some features more important than others, it make some distinctions visible and other distinctions invisible, and make some things easy to classify while others become outliers.&lt;/p&gt;

&lt;p&gt;And each one &lt;span class=&quot;emphasis&quot;&gt;tells you something different&lt;/span&gt; about what kind of bias your classifier has!&lt;/p&gt;

&lt;h3 id=&quot;&quot;&gt;Grouping and Regrouping&lt;/h3&gt;

&lt;p&gt; Here’s another way to look at the same results. We can draw all the shapes that were correctly classified above the dashed line, and all the incorrectly classified shapes below it. &lt;/p&gt;

&lt;div class=&quot;shape-explainer&quot;&gt;&lt;/div&gt;

&lt;p&gt; We’re still looking at the same model making the same classification on the same shapes, so the same shapes stay above and below the line. But each way of grouping the results distributes the errors differently— each way &lt;span class=&quot;emphasis&quot;&gt; tells you something different&lt;/span&gt;.&lt;/p&gt;

&lt;h3 id=&quot;&quot;&gt;Labels Tell Stories&lt;/h3&gt;

&lt;p&gt;The decisions you make about classification, however small…&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;center&gt; All shapes are basically… &lt;select id=&quot;conclusion-select-category&quot;&gt;&lt;/select&gt; &lt;/center&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;…begin to shape others’ decisions…&lt;/p&gt;

&lt;center&gt; &lt;div class=&quot;conclusion-interface&quot;&gt;&lt;/div&gt;&lt;/center&gt;

&lt;p&gt;…they shape the analysis you can do…&lt;/p&gt;

&lt;center&gt; &lt;div class=&quot;conclusion-summary&quot;&gt;&lt;/div&gt;&lt;/center&gt;

&lt;p&gt;…and they shape the kinds of conversations that happen.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;center&gt;&lt;div class=&quot;conclusion-newspapers&quot;&gt;&lt;/div&gt;&lt;/center&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;It’s natural to want to find a way out of this problem by gathering more features or collecting more data. If we just have enough detail on enough data, surely we can avoid making these kinds of decisions, right?&lt;/p&gt;

&lt;p&gt;Unfortunately, that isn’t the case. Describing the world around us in any way—whether we’re telling a friend a story or telling a computer about shapes—requires us to choose &lt;span class=&quot;emphasis&quot;&gt;what information is important to convey and what tools we want to use to convey it.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Whether we think about it or not, we’re &lt;i&gt;always&lt;/i&gt; making choices about classification.
&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;fake-dropdown&quot;&gt;&lt;center&gt;All people are basically… &lt;span class=&quot;dropdown&quot;&gt;men or women&lt;/span&gt;&lt;/center&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;fake-dropdown&quot;&gt;&lt;center&gt;All food is basically… &lt;span class=&quot;dropdown&quot;&gt;sweet or savory&lt;/span&gt;&lt;/center&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;fake-dropdown&quot;&gt;&lt;center&gt;All content is basically… &lt;span class=&quot;dropdown&quot;&gt;kid-friendly or adult&lt;/span&gt;&lt;/center&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;fake-dropdown&quot;&gt;&lt;center&gt;All speech is basically… &lt;span class=&quot;dropdown&quot;&gt;hate speech or acceptable speech&lt;/span&gt;&lt;/center&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;
&lt;!-- &lt;p&gt;&lt;div class=&#39;fake-dropdown&#39;&gt;&lt;center&gt;All results are basically... &lt;span class=&#39;dropdown&#39;&gt; &lt;span style=&quot;font-family:&#39;Courier New&#39;&quot;&gt;p&lt;0.05&lt;/span&gt; and &lt;span style=&quot;font-family:&#39;Courier New&#39;&quot;&gt;p&gt;0.05&lt;/span&gt;&lt;/span&gt;&lt;/center&gt;&lt;/div&gt;&lt;/p&gt; --&gt;
  &lt;p&gt;&lt;/p&gt;&lt;div class=&quot;fake-dropdown&quot;&gt;&lt;center&gt;All results are basically… &lt;span class=&quot;dropdown&quot;&gt; significant or insignificant&lt;/span&gt;&lt;/center&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;And as we saw with shapes, all of these choices &lt;span class=&quot;emphasis&quot;&gt;make some features more important than others&lt;/span&gt;, make &lt;span class=&quot;emphasis&quot;&gt;some distinctions visible and other distinctions invisible&lt;/span&gt;, and make &lt;span class=&quot;emphasis&quot;&gt;some things easy to classify while others become outliers&lt;/span&gt;.&lt;/p&gt;

&lt;h3 id=&quot;classification-thinking&quot;&gt;In Practice&lt;/h3&gt;

&lt;p&gt;Let’s take a closer look at how this plays out in real machine learning applications. One straightforward example is in &lt;a href=&quot;https://en.wikipedia.org/wiki/Object_detection&quot; target=&quot;_blank&quot;&gt;supervised object detection tasks&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;For example, let’s imagine we want to train an object detection model on a dataset including this image:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;center&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/dataset-worldviews/img/seattle.png&quot; width=&quot;700&quot; alt=&quot;Image of the Seattle skyline&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;br&gt; &lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Seattle_Kerry_Park_Skyline.jpg&quot; target=&quot;_blank&quot; class=&quot;source&quot;&gt;Source: Wikimedia Commons&lt;/a&gt;&lt;/center&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;We could give it the following ground truth &lt;a href=&quot;https://developers.google.com/machine-learning/glossary#bounding-box&quot; target=&quot;_blank&quot;&gt;bounding boxes&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;center&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/dataset-worldviews/img/seattle_first_tags.png&quot; srcset=&quot;img/seattle_first_tags.svg&quot; width=&quot;700&quot; alt=&quot;Image of the Seattle skyline with boxes around several items in the picture with labels like &#39;building&#39; and &#39;tree&#39;.&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/center&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;This looks objective, right? After all, a building is a building, a bush is a bush, and a mountain is a mountain!&lt;/p&gt;
&lt;p&gt; But even labeling the same regions in the same image, you can communicate a very different perspective:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;center&gt;&lt;img src=&quot;https://pair.withgoogle.com/explorables/dataset-worldviews/img/seattle_second_tags.png&quot; srcset=&quot;img/seattle_second_tags.svg&quot; width=&quot;700&quot; alt=&quot;Image of the Seattle skyline with boxes around several items in the picture, with labels like &#39;plant, non medicinal&#39; and &#39;structure, nonreligious&#39;.&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/center&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Or consider the image below, with several sets of “ground truth” labels. Looking at each of these labels, consider:&lt;/p&gt;

&lt;p&gt;What features matter? What gets labeled? Whose worldview comes through? What might you learn from this set of labels that you wouldn’t learn from another?&lt;/p&gt;

&lt;div class=&quot;person-photos&quot;&gt;&lt;/div&gt;&lt;center&gt;&lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Women_washing_clothes_4.jpg&quot; target=&quot;_blank&quot; class=&quot;source&quot;&gt;Source: Wikimedia Commons&lt;/a&gt;&lt;/center&gt;

&lt;p&gt;There is no “view from nowhere”, no universal way to organize every object, or word, or image. Datasets are always products of a particular time, place, and set of conditions; they are socially situated artifacts. They have &lt;a href=&quot;https://journals.sagepub.com/doi/full/10.1177/20539517211035955&quot; target=&quot;_blank&quot;&gt;histories&lt;/a&gt;; they have &lt;a href=&quot;https://arxiv.org/abs/2108.04308&quot; target=&quot;_blank&quot;&gt;politics&lt;/a&gt;. And ignoring this fact has &lt;a href=&quot;https://arxiv.org/pdf/2012.05345.pdf&quot; target=&quot;_blank&quot;&gt;very real consequences&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So what do we do with this information?&lt;/p&gt;

&lt;p&gt;A great place to start is to reflect on your own context and &lt;a href=&quot;https://pair-code.github.io/datacardsplaybook/playbook&quot; target=&quot;_blank&quot;&gt;get curious about your data.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If it’s hard to see a dataset’s values—if it feels “objective”, “universal”, or “neutral”—it may simply be reflecting a worldview you’re accustomed to. So, understanding the limitations of your own worldview can tell you about the limitations of “objective” data. What assumptions do you make about the world? What feels like common sense? What feels foreign?&lt;/p&gt;

&lt;p&gt;And do some sleuthing about your data! Who collected this data? Why was it collected? Who paid for it? Where did the “ground truth” come from? &lt;/p&gt;

&lt;p&gt;You might even find yourself &lt;a href=&quot;https://www.morgan-klaus.com/pdfs/pubs/Scheuerman-CSCW2021-datapolitics.pdf&quot; target=&quot;_blank&quot;&gt;questioning what kinds of assumptions underpin machine learning dataset development&lt;/a&gt; or even &lt;a href=&quot;https://mitpress.mit.edu/books/sorting-things-out&quot; target=&quot;_blank&quot;&gt; thinking more deeply about classification as a whole&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you find yourself with lots of questions, you’re already off to a good start.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;

&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;

&lt;p&gt; Dylan Baker // January 2022&lt;/p&gt;
&lt;p&gt; Thanks to Adam Pearce, Alex Hanna, Emily Denton, Fernanda Viégas, Kevin Robinson, Nithum Thain, Razvan Amironesei, and Vinodkumar Prabhakaran for their help with this piece. &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;


&lt;div class=&quot;preload-dropdown-img&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;


&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;


&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;





















</description><link>https://pair.withgoogle.com/explorables/dataset-worldviews/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/dataset-worldviews/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/dataset-worldviews-shareimg.png" type="image/jpeg"></enclosure></item><item><title>Measuring Diversity</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Measuring Diversity&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;Search results that reflect historic inequities can amplify stereotypes and perpetuate under-representation. Carefully measuring diversity in data sets can help.&lt;/div&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;

&lt;p&gt;Search, ranking and recommendation systems can help find useful documents in large datasets. However, these datasets reflect the biases of the society in which they were created and the systems risk re-entrenching those biases. For example, if someone who is not a white man searches for “CEO pictures” and sees a &lt;a href=&quot;https://www.nytimes.com/interactive/2018/04/24/upshot/women-and-men-named-john.html&quot;&gt;page of white men&lt;/a&gt;, they may feel that only white men can be CEOs, further perpetuating lack of representation at companies’ executive levels. &lt;/p&gt;
&lt;p&gt;Using the careful quantification outlined in a recent paper, &lt;a href=&quot;https://arxiv.org/pdf/2002.03256.pdf&quot;&gt;Diversity and Inclusion Metrics in Subset Selection&lt;/a&gt;, we can quantify biases and push these systems to return a wider range of results. &lt;/p&gt;
&lt;p&gt;The mathematics of all this is a little easier to follow with abstract shapes. Let’s take a look at some of them:&lt;/p&gt;
&lt;div id=&quot;all-shapes&quot; class=&quot;shapes&quot;&gt;&lt;/div&gt;

&lt;p&gt;Suppose we want to return about &lt;b&gt;30% green boxes&lt;/b&gt; to reflect the distribution of some larger universe of shapes. Try clicking on the shapes below to select some of them — can you find a better subset to return?&lt;/p&gt;
&lt;div id=&quot;pick-green&quot; class=&quot;shapes&quot;&gt;&lt;/div&gt;

&lt;p&gt;Another diversity metric we care about is the percentage of dots… how close to &lt;b&gt;35% dots&lt;/b&gt; can you get?&lt;/p&gt;
&lt;div id=&quot;pick-triangle&quot; class=&quot;shapes&quot;&gt;&lt;/div&gt;

&lt;p&gt;If we can only return a single subset, how should we consider multiple diversity metrics? Sometimes it isn’t possible to reduce the difference of every metric to zero. One natural approach: find the selection with the &lt;strong&gt;lowest mean difference&lt;/strong&gt; across all the metrics to get as close as possible to all the targets. &lt;/p&gt;
&lt;p&gt;In other circumstances, like picking a panel of speakers, avoiding badly representing any single category might be more important. This can be done by finding the subset with the &lt;strong&gt;lowest max difference&lt;/strong&gt;. Try minimizing both below:  &lt;/p&gt;
&lt;div id=&quot;pick-metric&quot; class=&quot;shapes&quot; style=&quot;margin-bottom: 0px&quot;&gt;&lt;/div&gt;

&lt;p&gt;Notice that minimizing the mean results in a different subset than minimizing the max; how else might using one over the other change the results?   &lt;/p&gt;
&lt;h3 id=&quot;ranking-measures&quot;&gt;Ranking Measures&lt;/h3&gt;
&lt;p&gt;We can pull out more detail by showing how the mean difference and maximum difference rank lots of sets. Below, there are 20 sets of 10 shapes sorted by the two measures. Try adjusting the target slider on the left to see how the rankings change; each set’s percentage of green, dots and small shapes are shown in the small histograms.  &lt;/p&gt;
&lt;div id=&quot;columns-height&quot;&gt;&lt;/div&gt;

&lt;p&gt;At the extremes, the choice of measure can have a big impact: if we want to try and return all green results, we can shift the green target up to 100%. With this target, the minimum difference basically sorts the sets by the number of green items and uses the other targets as a tiebreaker. In contrast, sorting by the mean difference balances the green target more with the dot and small targets.&lt;/p&gt;
&lt;div id=&quot;columns-height-disagree&quot;&gt;&lt;/div&gt;

&lt;p&gt;Beyond mean and max differences, there are more ways to combine diversity metrics, like taking the cross of two metrics to account for &lt;a href=&quot;https://en.wikipedia.org/wiki/Intersectionality&quot;&gt;intersectionality&lt;/a&gt;. The absolute value of the difference in target and actual percentages can also be quantified in other ways — you might want to penalize undershooting more than overshooting, for example. It’s important to keep in mind what exactly you’re trying to maximize and the dataset that you’re operating on.&lt;/p&gt;
&lt;h3 id=&quot;which-measure-is-best-&quot;&gt;Which Measure is Best?&lt;/h3&gt;
&lt;p&gt;In a vacuum, all of these ranking methods are defensible. Picking one requires knowledge of the dataset and broader societal context.&lt;/p&gt;
&lt;p&gt;For example, the doctors on the left have more variance along the shirt color attribute, but they’re less diverse by gender than the doctors on the right. With the shirt color and gender targets we’ve picked, the two subsets have the same mean and max differences However, in most applications, it’s more important to have a representative sample of socially relevant characteristics, like gender, rather than something less salient, like clothing color. &lt;/p&gt;
&lt;div id=&quot;coat-v-gender&quot;&gt;&lt;/div&gt;   

&lt;p&gt;Just selecting a diverse sample isn’t sufficient either. &lt;a href=&quot;https://arxiv.org/pdf/2002.03256.pdf&quot;&gt;Diversity and Inclusion Metrics in Subset Selection&lt;/a&gt; introduces a way of measuring “inclusion” - how well does the searcher feel represented in the results?&lt;/p&gt;
&lt;p&gt;Below, we have gender diversity, without inclusion for women, in the “construction worker” image domain. Masculine-presenting individuals are shown in realistic, modern construction worker situations, while feminine-presenting individuals and other gender presentations are depicted as historic nostalgia, toys, clipart, or passive.&lt;/p&gt;
&lt;div id=&quot;construction&quot;&gt;&lt;/div&gt;

&lt;p&gt;The context of the query and the searcher also plays in the quality of search results. A search for “work clothing” that shows a mixed palette of colors for men’s clothing and only pink women’s clothing might make the searcher feel that women need to appear stereotypically feminine in a professional setting. But the same set of women’s clothes might be appropriate to show for a “pink women work clothes” search or if the searcher had previously expressed a preference for pink.&lt;/p&gt;
&lt;p&gt;We saw how a small switch from mean to max made a huge difference in what abstract shapes are returned – and how things can get even more complex when socially salient characteristics are layered in. Defaults and small decisions can encode our priorities and values; intentionally thinking about how diversity and inclusion are being measured and which characteristics are emphasized is a step towards designing more equitable systems.    &lt;/p&gt;
&lt;h3 id=&quot;more-reading&quot;&gt;More Reading&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://arxiv.org/pdf/2002.03256.pdf&quot;&gt;Diversity and Inclusion Metrics&lt;/a&gt; paper has a &lt;a href=&quot;https://colab.research.google.com/github/PAIR-code/ai-explorables/blob/master/source/measuring-diversity/diversity-and-inclusion.ipynb&quot;&gt;Colab&lt;/a&gt; with a detailed desciption of the metrics, additional visualizations and a reference Python implementation.  &lt;/p&gt;
&lt;p&gt;The difficulties of &lt;a href=&quot;https://pair.withgoogle.com/explorables/measuring-fairness/&quot;&gt;measuring fairness&lt;/a&gt; in general have been well studied; subset selection is still an active area of research. &lt;a href=&quot;https://www.cs.cornell.edu/~tj/publications/singh_joachims_18a.pdf&quot;&gt;Fairness of Exposure in Rankings&lt;/a&gt; proposes a ranking algorithm that incorporates fairness constraints. &lt;a href=&quot;https://www.ilab.cs.rutgers.edu/~rg522/publication/gao-2020-ipm/gao-2020-ipm.pdf&quot;&gt;Toward creating a fairer ranking in search engine results&lt;/a&gt; measures diversity bias in actual search results. &lt;/p&gt;
&lt;p&gt;Inferring user preferences is also tricky; you can checkout ways to design for user feedback and control over queries in the &lt;a href=&quot;https://pair.withgoogle.com/chapter/feedback-controls/&quot;&gt;People + AI Guidebook&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;
&lt;p&gt;Adam Pearce, Dylan Baker, Ellen Jiang, Meg Mitchell* and Timnit Gebru* // March 2021&lt;/p&gt;
&lt;p&gt;*Work done while at Google&lt;/p&gt;
&lt;p&gt;Thanks to Alex Hanna, Carey Radebaugh, Emily Denton, Fernanda Viégas, James Wexler, Jess Holbrook, Ludovic Peran, Martin Wattenberg, Michael Terry, Yannick Assogba and Zan Armstrong for their help with this piece.&lt;/p&gt;
&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;



















</description><link>https://pair.withgoogle.com/explorables/measuring-diversity/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/measuring-diversity/</guid><enclosure url="https://pair.withgoogle.com/explorables/images/measuring-diversity.png" type="image/jpeg"></enclosure></item><item><title>Measuring Fairness</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Measuring Fairness &lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;There are multiple ways to measure accuracy. No matter how we build our model, accuracy across these measures will vary when applied to different groups of people.&lt;/div&gt;
  
&lt;link rel=&quot;stylesheet&quot; href=&quot;../third_party/weepeople.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;graph-scroll.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;

&lt;div id=&quot;container&quot; class=&quot;container-1&quot;&gt;
&lt;div id=&quot;graph&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sections&quot;&gt;


&lt;div&gt;
&lt;h1&gt;Measuring Fairness&lt;/h1&gt;

&lt;p&gt;How do you make sure a model works equally well for different groups of people? It turns out that in many situations, this is harder than you might think.

&lt;/p&gt;&lt;p&gt;The problem is that there are different ways to measure the accuracy of a model, and often it&#39;s mathematically impossible for them all to be equal across groups.

&lt;/p&gt;&lt;p&gt;We&#39;ll illustrate how this happens by creating a (fake) medical model to screen these people for a disease.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Ground Truth&lt;/h3&gt;

&lt;p&gt;About half of these people actually have the disease &lt;wee class=&quot;sick&quot;&gt;a&lt;/wee&gt;; half of them don&#39;t &lt;wee class=&quot;well&quot;&gt;b&lt;/wee&gt;.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Model Predictions&lt;/h3&gt;

&lt;p&gt;In a perfect world, only sick people would &lt;bg class=&quot;sick&quot;&gt;test positive for the disease&lt;/bg&gt; and only healthy people would &lt;bg&gt;test negative&lt;/bg&gt;. 
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Model Mistakes&lt;/h3&gt;

&lt;p&gt;But models and tests aren&#39;t perfect.

&lt;/p&gt;&lt;p&gt;The model might make a mistake and mark a sick person as healthy &lt;wee class=&quot;sick bg-well&quot;&gt;c&lt;/wee&gt;. 

&lt;/p&gt;&lt;p&gt;Or the opposite: marking a healthy person as sick &lt;wee class=&quot;well bg-sick&quot;&gt;f&lt;/wee&gt;.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;&lt;h3&gt;Never Miss the Disease...&lt;/h3&gt;

&lt;p&gt;If there&#39;s a simple follow-up test, we could have the model aggressively call close cases so it rarely misses the disease.

&lt;/p&gt;&lt;p&gt;We can quantify this by measuring the &lt;b&gt;percentage of sick people &lt;wee class=&quot;sick&quot;&gt;a&lt;/wee&gt; who test positive &lt;wee class=&quot;sick bg-sick&quot;&gt;g&lt;/wee&gt;&lt;/b&gt;. 

&lt;/p&gt;&lt;div class=&quot;mini&quot; sex=&quot;all&quot; type=&quot;fp&quot;&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;...Or Avoid Overcalling?&lt;/h3&gt;

&lt;p&gt;On the other hand, if there isn&#39;t a secondary test, or the treatment uses a drug with a limited supply, we might care more about the &lt;b&gt;percentage of people with &lt;bg class=&quot;sick&quot;&gt;positive tests&lt;/bg&gt; who are actually sick &lt;wee class=&quot;sick bg-sick&quot;&gt;g&lt;/wee&gt; &lt;/b&gt;. 

&lt;/p&gt;&lt;div class=&quot;mini&quot; sex=&quot;all&quot; type=&quot;calibration&quot;&gt;&lt;/div&gt;

&lt;p&gt;These issues and trade-offs in model optimization aren&#39;t new, but they&#39;re brought into focus when we have the ability to fine-tune exactly how aggressively disease is diagnosed.

&lt;/p&gt;&lt;div class=&quot;slider threshold&quot;&gt;&lt;/div&gt;

&lt;i id=&quot;adjust-text&quot;&gt; Try adjusting how aggressive the model is in diagnosing the disease&lt;/i&gt;
&lt;/div&gt; 


&lt;div&gt;
&lt;h3&gt;Subgroup Analysis&lt;/h3&gt;

&lt;p&gt;Things get even more complicated when we check if the model treats different groups fairly.&lt;a class=&quot;footstart&quot;&gt;¹&lt;/a&gt;

&lt;/p&gt;&lt;p&gt;Whatever we decide on in terms of trade-offs between these metrics, we&#39;d probably like them to be roughly even across different groups of people.

&lt;/p&gt;&lt;p&gt;If we&#39;re trying to evenly allocate resources, having the model miss more cases in children than adults would be bad! &lt;a class=&quot;footstart&quot;&gt;²&lt;/a&gt;
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Base Rates&lt;/h3&gt;

&lt;p&gt;If you look carefully, you&#39;ll see that the disease is more prevalent in children. That is, the &quot;base rate&quot; of the disease is different across groups.

&lt;/p&gt;&lt;p&gt;The fact that the base rates are different makes the situation surprisingly tricky. For one thing, even though the test catches the same percentage of sick adults and sick children, an adult who tests positive is less likely to have the disease than a child who tests positive.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Imbalanced Metrics&lt;/h3&gt;

&lt;p&gt;Why is there a disparity in diagnosing between children and adults? There is a higher proportion of well adults, so mistakes in the test will cause more well adults to be marked &quot;positive&quot; than well children (and similarly with mistaken negatives).

&lt;/p&gt;&lt;div class=&quot;mini&quot; sex=&quot;female&quot; type=&quot;calibration&quot;&gt;&lt;/div&gt;&lt;br&gt;
&lt;div class=&quot;mini&quot; sex=&quot;male&quot; type=&quot;calibration&quot;&gt;&lt;/div&gt;

&lt;p&gt;To fix this, we could have the model take age into account. 

&lt;/p&gt;&lt;div class=&quot;slider threshold_f&quot;&gt;&lt;/div&gt;
&lt;div style=&quot;height: 10px&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;slider threshold_m&quot;&gt;&lt;/div&gt;

&lt;div class=&quot;gated&quot;&gt;
&lt;div id=&quot;default&quot;&gt;&lt;br&gt;&lt;i&gt;Try adjusting the slider to make the model grade adults less aggressively than children.&lt;/i&gt;&lt;/div&gt;

&lt;div id=&quot;hidden&quot;&gt;
&lt;p&gt;This allows us to align one metric. But now adults who have the disease are less likely to be diagnosed with it! 

&lt;/p&gt;&lt;div class=&quot;mini&quot; sex=&quot;female&quot; type=&quot;fp&quot;&gt;&lt;/div&gt;
&lt;br&gt;
&lt;div class=&quot;mini&quot; sex=&quot;male&quot; type=&quot;fp&quot;&gt;&lt;/div&gt;

&lt;p&gt;No matter how you move the sliders, you won&#39;t be able to make both metrics fair at once. It turns out this is inevitable any time the base rates are different, and the test isn&#39;t perfect.

&lt;/p&gt;&lt;p&gt;There are multiple ways to define fairness mathematically. It usually isn&#39;t possible to satisfy all of them.&lt;a class=&quot;footstart&quot;&gt;³&lt;/a&gt; 
&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;/div&gt; 
&lt;/div&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Thankfully, the notion of fairness you choose to satisfy will depend on the context of your model, so while it may not be possible to satisfy every definition of fairness, you can focus on the notions of fairness that make sense for your use case. 

&lt;/p&gt;&lt;p&gt;Even if fairness along every dimension isn&#39;t possible, we shouldn&#39;t stop checking for bias. The &lt;a href=&quot;https://pair.withgoogle.com/explorables/hidden-bias/&quot;&gt;Hidden Bias explorable&lt;/a&gt; outlines different ways human bias can feed into an ML model.

&lt;/p&gt;&lt;h3&gt;More Reading&lt;/h3&gt;

&lt;p&gt;In some contexts, setting different thresholds for different populations might not be acceptable. &lt;a href=&quot;https://www.technologyreview.com/s/613508/ai-fairer-than-judge-criminal-risk-assessment-algorithm/&quot;&gt;Can you make AI fairer than a judge?&lt;/a&gt; explores an algorithm that can send people to jail. 

&lt;/p&gt;&lt;p&gt;There are lots of different metrics you might use to determine if an algorithm is fair. &lt;a href=&quot;https://research.google.com/bigpicture/attacking-discrimination-in-ml/&quot;&gt;Attacking discrimination with smarter machine learning&lt;/a&gt; shows how several of them work. Using &lt;a href=&quot;https://ai.googleblog.com/2019/12/fairness-indicators-scalable.html&quot;&gt;Fairness Indicators&lt;/a&gt; in conjunction with the &lt;a href=&quot;https://pair-code.github.io/what-if-tool/&quot;&gt;What-If Tool&lt;/a&gt; and other &lt;a href=&quot;https://www.youtube.com/watch?v=6CwzDoE8J4M&quot;&gt;fairness tools&lt;/a&gt;, you can test your own model against commonly used &lt;a href=&quot;https://ai.googleblog.com/2020/02/setting-fairness-goals-with-tensorflow.html&quot;&gt;fairness metrics&lt;/a&gt;.

&lt;/p&gt;&lt;p&gt;Machine learning practitioners use words like “recall” to describe the percentage of sick people who test positive. Checkout the &lt;a href=&quot;https://pair.withgoogle.com/chapter/glossary/&quot;&gt;PAIR Guidebook Glossary&lt;/a&gt; to learn how to learn how to talk to the people building the models. 

&lt;/p&gt;&lt;h3&gt;Appendix&lt;/h3&gt;

&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;¹&lt;/a&gt; This essay uses very academic, mathematical standards for fairness that don&#39;t &lt;a href=&quot;https://arxiv.org/pdf/1909.11869.pdf&quot;&gt;encompass&lt;/a&gt; everything we might include in the colloquial meaning of fairness. There&#39;s a &lt;a href=&quot;https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3265913&quot;&gt;gap between the technical descriptions of algorithms here and the social context that they&#39;re deployed in.

&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;²&lt;/a&gt; Sometimes we might care more about different error modes in different populations. If treatment is riskier for children, we&#39;d probably want the model to be less aggressive in diagnosing. 

&lt;/p&gt;&lt;p&gt;&lt;a class=&quot;footend&quot;&gt;³&lt;/a&gt;The above example assumes the model sorts and scores people based on how likely it is that they are sick. With complete control over the model&#39;s exact rate of under- and over-diagnosing in both groups, it&#39;s actually possible to align both of the metrics we&#39;ve discussed so far. Try tweaking the model below to get both of them to line up.

&lt;/p&gt;&lt;p&gt;Adding a third metric, &lt;b&gt;the percentage of well people &lt;wee class=&quot;well&quot;&gt;a&lt;/wee&gt; who test negative &lt;wee class=&quot;well bg-well&quot;&gt;e&lt;/wee&gt;&lt;/b&gt;, makes perfect fairness impossible. Can you see why all three metrics won&#39;t align unless the base rate of the disease is the same in both populations?

&lt;/p&gt;&lt;div id=&quot;big-matrix&quot;&gt;&lt;/div&gt;

&lt;div id=&quot;instructions&quot;&gt;&lt;i&gt;Drag &lt;sl&gt;⁠—&lt;/sl&gt; to adjust model accuracy and &lt;sl&gt;⁠|&lt;/sl&gt; to adjust the occurrence of disease&lt;/i&gt;&lt;/div&gt;
&lt;div id=&quot;metrics&quot;&gt;&lt;/div&gt;

&lt;h3&gt;Credits&lt;/h3&gt;

&lt;p&gt;Adam Pearce // May 2020

&lt;/p&gt;&lt;p&gt;Thanks to Carey Radebaugh, Dan Nanas, David Weinberger, Emily Denton, Emily Reif, Fernanda Viégas, Hal Abelson, James Wexler, Kristen Olson, Lucas Dixon, Mahima Pushkarna, Martin Wattenberg, Michael Terry, Rebecca Salois, Timnit Gebru, Tulsee Doshi, Yannick Assogba, Yoni Halpern, Zan Armstrong, and my other colleagues at Google for their help with this piece.

&lt;/p&gt;&lt;p&gt;Silhouettes from &lt;a href=&quot;https://github.com/propublica/weepeople&quot;&gt;ProPublica&#39;s Wee People&lt;/a&gt;.


&lt;/p&gt;&lt;h3&gt;More Explorables&lt;/h3&gt;

&lt;p id=&quot;recirc&quot;&gt;&lt;/p&gt;

&lt;div class=&quot;recirc-feedback-form&quot;&gt;&lt;/div&gt;



















&lt;link rel=&quot;stylesheet&quot; href=&quot;../base-rate/style.css&quot;&gt;












</description><link>https://pair.withgoogle.com/explorables/measuring-fairness/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/measuring-fairness/</guid><enclosure url="/images/PAIR/explorable-fairness.png" type="image/jpeg"></enclosure></item><item><title>Hidden Bias</title><description>&lt;div class=&quot;header&quot;&gt;
    &lt;div class=&quot;header-left&quot;&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/&quot;&gt;
        &lt;img src=&quot;https://pair.withgoogle.com/explorables/images/pair-logo.svg&quot; style=&quot;width: 100px&quot; referrerpolicy=&quot;no-referrer&quot;&gt;
      &lt;/a&gt;
      &lt;a href=&quot;https://pair.withgoogle.com/explorables/&quot;&gt;Explorables&lt;/a&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h1 class=&quot;headline&quot;&gt;Hidden Bias&lt;/h1&gt;
  
  &lt;div class=&quot;post-summary&quot;&gt;Models trained on real-world data can encode real-world bias. Hiding information about protected classes doesn&#39;t always fix things — sometimes it can even hurt.&lt;/div&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;

&lt;div id=&quot;container&quot; class=&quot;container-1&quot;&gt;
&lt;div id=&quot;graph&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sections&quot;&gt;


&lt;div&gt;
&lt;h3&gt;Modeling College GPA&lt;/h3&gt;

&lt;p&gt;Let&#39;s pretend we&#39;re college admissions officers trying to predict the GPA students will have in college (in these examples we&#39;ll use simulated data).

&lt;/p&gt;&lt;p&gt;One simple approach: predict that students will have the same GPA in college as they did in high school. 
&lt;/p&gt;&lt;/div&gt;


&lt;div class=&quot;img-slide&quot;&gt;
&lt;p&gt;This is at best a very rough approximation, and it misses a key feature of this data set: students usually have better grades in high school than in college

&lt;/p&gt;&lt;p&gt;We&#39;re &lt;img src=&quot;https://pair.withgoogle.com/explorables/hidden-bias/over.png&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;span class=&quot;xhighlight blue&quot;&gt;over-predicting&lt;/span&gt; college grades more often than we &lt;img src=&quot;https://pair.withgoogle.com/explorables/hidden-bias/over.png&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;span class=&quot;xhighlight orange&quot;&gt;under-predict.&lt;/span&gt;
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Predicting with ML&lt;/h3&gt;
&lt;p&gt;If we switched to using a machine learning model and entered these student grades, it would recognize this pattern and adjust the prediction.

&lt;/p&gt;&lt;p&gt;The model does this without knowing anything about the real-life context of grading in high school versus college.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;Giving the model &lt;span class=&quot;highlight blue&quot;&gt;more information&lt;/span&gt; about students increases accuracy more...
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;...and more.
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Models can encode previous bias&lt;/h3&gt;
&lt;p&gt;All of this sensitive information about students is just a long list of numbers to model. 

&lt;/p&gt;&lt;p&gt;If a sexist college culture has historically led to lower grades for &lt;span class=&quot;f circle&quot;&gt;&amp;nbsp;&lt;/span&gt; female students, the model will pick up on that correlation and predict lower grades for women.  

&lt;/p&gt;&lt;p&gt;Training on historical data bakes in historical biases. Here the sexist culture has improved, but the model learned from the past correlation and still predicts higher grades for &lt;span class=&quot;m circle&quot;&gt;&amp;nbsp;&lt;/span&gt; men.
&lt;/p&gt;&lt;/div&gt;

&lt;div&gt;
&lt;h3&gt;Hiding protected classes from the model might not stop discrimination&lt;/h3&gt;

&lt;p&gt;Even if we don&#39;t tell the model students&#39; genders, it might still score &lt;span class=&quot;f circle&quot;&gt;&amp;nbsp;&lt;/span&gt; female students poorly.

&lt;/p&gt;&lt;p&gt;With detailed enough information about every student, the model can still synthesize a proxy for gender out of other &lt;span class=&quot;highlight yellow&quot;&gt;variables.&lt;/span&gt;
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;h3&gt;Including a protected attribute may even &lt;i&gt;decrease&lt;/i&gt; discrimination&lt;/h3&gt;

&lt;p&gt;Let&#39;s look at a simplified model, one only taking into account the recommendation of an alumni interviewer. 
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;The interviewer is quite accurate, except that they&#39;re biased against students with a &lt;span class=&quot;l circle&quot;&gt;&amp;nbsp;&lt;/span&gt; low household income. 

&lt;/p&gt;&lt;p&gt;In our toy model, students&#39; grades don&#39;t depend on their income once they&#39;re in college. In other words, we have biased inputs and unbiased outcomes—the opposite of the previous example, where the inputs weren&#39;t biased, but the toxic culture biased the outcomes. 
&lt;/p&gt;&lt;/div&gt;


&lt;div&gt;
&lt;p&gt;If we also tell the model each student&#39;s &lt;span class=&quot;highlight blue&quot;&gt;household income&lt;/span&gt;, it will naturally correct for the interviewer&#39;s overrating of &lt;span class=&quot;h circle&quot;&gt;&amp;nbsp;&lt;/span&gt; high-income students just like it corrected for the difference between high school and college GPAs. 

&lt;/p&gt;&lt;p&gt;By carefully considering and accounting for bias, we&#39;ve made the model fairer and more accurate. This isn&#39;t always easy to do, especially in circumstances like the historically toxic college culture where unbiased data is limited. 

&lt;/p&gt;&lt;p&gt;And there are fundamental fairness trade-offs that have to be made. Check out the &lt;a href=&quot;https://pair.withgoogle.com/explorables/measuring-fairness/&quot;&gt;Measuring Fairness explorable&lt;/a&gt; to see how those tradeoffs work.&lt;a href=&quot;https://pair.withgoogle.com/explorables/measuring-fairness/&quot;&gt;&lt;br&gt;&lt;img style=&quot;width: 100%; max-width: 391px; margin-left: -8px&quot; src=&quot;https://pair.withgoogle.com/explorables/images/medical-fairness.gif&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/a&gt;


&lt;br&gt;&lt;br&gt;

&lt;/p&gt;&lt;p&gt;Adam Pearce // May 2020

&lt;/p&gt;&lt;p&gt;Thanks to Carey Radebaugh, Dan Nanas, David Weinberger, Emily Denton, Emily Reif, Fernanda Viégas, Hal Abelson, James Wexler, Kristen Olson, Lucas Dixon, Mahima Pushkarna, Martin Wattenberg, Michael Terry, Rebecca Salois, Timnit Gebru, Tulsee Doshi, Yannick Assogba, Yoni Halpern, Zan Armstrong, and my other colleagues at Google for their help with this piece.
&lt;/p&gt;&lt;/div&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;end&quot;&gt;&lt;/div&gt;


&lt;link rel=&quot;stylesheet&quot; href=&quot;../measuring-fairness/graph-scroll.css&quot;&gt;














</description><link>https://pair.withgoogle.com/explorables/hidden-bias/</link><guid isPermaLink="false">https://pair.withgoogle.com/explorables/hidden-bias/</guid><enclosure url="/images/PAIR/explorable-bias.png" type="image/jpeg"></enclosure></item></channel></rss>