@GoukiMinegishi: Our paper was accepted as a #ICML2026 Spotlight! Reasoning in LLMs has improved largely by chaining local steps. But is…

X AI KOLs Timeline Papers

Summary

This paper formalizes analogical reasoning in Transformers using category theory, introduces synthetic tasks to study its emergence, and reveals that it arises from geometric alignment of relational structures and functor application, with signatures also found in pretrained LLMs. The work was accepted as a Spotlight at ICML 2026.

Our paper was accepted as a #ICML2026 Spotlight! Reasoning in LLMs has improved largely by chaining local steps. But is that the whole story? Humans occasionally make inferential "leaps" across domains, a faculty known as analogy. We design a synthetic task to show how small Transformers acquire analogical reasoning, and find that the same signatures appear in pretrained LLMs. arxiv: https://arxiv.org/abs/2602.01992 code: https://github.com/gouki510/Analogy_in_Transformer…
Original Article
View Cached Full Text

Cached at: 05/27/26, 09:22 AM

Our paper was accepted as a #ICML2026 Spotlight!

Reasoning in LLMs has improved largely by chaining local steps. But is that the whole story? Humans occasionally make inferential “leaps” across domains, a faculty known as analogy. We design a synthetic task to show how small Transformers acquire analogical reasoning, and find that the same signatures appear in pretrained LLMs.

arxiv: https://arxiv.org/abs/2602.01992 code: https://github.com/gouki510/Analogy_in_Transformer…


Emergent Analogical Reasoning in Transformers

Source: https://arxiv.org/html/2602.01992 Jingyuan FengHiroki FurutaTakeshi KojimaYusuke IwasawaYutaka Matsuo

Abstract

Analogy is a central faculty of human intelligence, enabling abstract patterns discovered in one domain to be applied to another. Despite its central role in cognition, the mechanisms by which Transformers acquire and implement analogical reasoning remain poorly understood. In this work, inspired by the notion of functors in category theory, we formalize analogical reasoning as the inference of correspondences between entities across categories. Based on this formulation, we introduce synthetic tasks that evaluate the emergence of analogical reasoning under controlled settings. We find that the emergence of analogical reasoning is highly sensitive to data characteristics, optimization choices, and model scale. Through mechanistic analysis, we show that analogical reasoning in Transformers decomposes into two key components: (1) geometric alignment of relational structure in the embedding space, and (2) the application of a functor within the Transformer. These mechanisms enable models to transfer relational structure from one category to another, realizing analogy. Finally, we quantify these effects and find that the same trends are observed in pretrained LLMs. In doing so, we move analogy from an abstract cognitive notion to a concrete, mechanistically grounded phenomenon in modern neural networks.

Interpretability, Analogy

1Introduction

Refer to captionFigure 1:(A) Synthetic task forcompositionalandanalogicalreasoning.Compositional reasoning evaluates whether a model can combine facts observed in-distribution (ID) during training to infer novel combinations (out-of-distribution, OOD). Analogical reasoning assesses whether a mappingff(functor) between distinct categories generalizes. Solving analogical reasoning requires capturing the underlying relational structure of each category from the ID facts.(B) Training dynamics of Transformer.When training a Transformer on this task, the model first fits on in-distribution data, then acquires compositional reasoning, and finally succeeds at analogical reasoning.(C) Mechanism of analogical reasoning.We analyze internal representations of the Transformer before and after the emergence of analogical reasoning. After acquiring the ability for analogical reasoning, the model develops a well-structured embedding space, which is quantitatively characterized by a decrease in Dirichlet Energy.Recent years have witnessed remarkable progress in the reasoning capabilities of large language models (LLMs), particularly in constructing chains of intermediate reasoning before the final answer(Weiet al.,2022; Kojimaet al.,2022; OpenAIet al.,2024; Google DeepMind,2025; DeepSeek-AIet al.,2025). These developments have renewed interest in a key question:how do LLMs realize reasoning?

Much of recent research on understanding reasoning frames reasoning ascompositional reasoning, where complex reasoning arises from sequentially composing simpler primitives. For example, given the facts

(i) Alice is Bob’s mother​(a→b),\displaystyle\text{(i) Alice is Bob’s mother}(a\rightarrow b),(ii) Bob is Carol’s father​(b→c),\displaystyle\text{(ii) Bob is Carol’s father}(b\rightarrow c),LLMs can infer that Alice is Carol’s grandmother(a→c)(a\rightarrow c)by composing two known relations(Yanget al.,2018; Maviet al.,2024). The mechanisms underlying this form of reasoning have been widely studied, including its emergence during training(Heet al.,2024), its dependence on data structure(Wanget al.,2024; Schuget al.,2025)and its scaling behavior(Pettyet al.,2024; Redhardtet al.,2025).

Beyond compositional reasoning, humans exhibit a qualitatively different form of reasoning,analogy. Rather than producing conclusions by chaining local steps, analogy identifies shared relational structure across distinct domains, enabling a form of “leap”(Gentner,1983; Holyoak and Thagard,1996; Bartha,2013). A classic example from cognitive science is the analogy between the solar system and atomic structure(Gentner,1983), where each domain consists of three entities and their relations:

SunPlanetsGravityProtonElectronsCoulombFunctor

One can infer a correspondence between entities across domains, such as mapping theSunto theProton. This inference does not arise from the entities’ intrinsic similarity. Instead, it emerges from the similarity of entities’ relational roles within each domain. Thus, analogical reasoning can be viewed as operating onrelations between relations, rather than on relations among individual entities. In category theory, this can be formalized as a mapping between categories111Here, we usecategoryas a formal abstraction of adomain, consisting of entities and their relations., namely afunctor(Awodey,2010). This ability is widely regarded as a central faculty of human intelligence, enabling efficient learning from limited experience(Thagard,1992; Gentner and Hoyos,2017)and is often viewed as a source of creativity and science discovery(Leatherdale,1974; Goel,1997; Gentneret al.,1997).

Despite its long-standing significance in intelligence, it remains unclearwhenandhowTransformer-based architectures acquire analogical reasoning. While several works probe analogical performance at the behavioral level(Chen,2022; Ye,2024; Yasunagaet al.,2024; Johnsonet al.,2025), we lack a systematic understanding.

In this work, we take a step toward filling this gap. Inspired by the notion offunctorin category theory, we formalize analogical reasoning as inferring correspondences across categories. Based on this formulation, we design synthetic tasks to evaluatecompositionalandanalogical reasoningwithin a unified framework (Figure 1-(A)). Our task is based on atomic facts provided in the in-distribution (ID) training data, where each fact specifies a relation (rs→tr_{s\rightarrow t}) between a pair of entities(es,et)(e_{s},e_{t}). In compositional reasoning, we test whether a model can combine learned atomic facts to infer novel combinations (out-of-distribution, OOD). In analogical reasoning, we consider two categories that share the same relational structure but differ in their entities. The model is required to infer the corresponding entity across categories based on their relational roles. Since evaluation for analogical reasoning is also performed in OOD, the model must capture the underlying relational structure of each category from the ID facts.

Using this synthetic task, we analyzewhencompositional and analogical reasoning emerges during training. We observe a clear three-stage learning dynamics (Figure 1-(B)): models first fit in-distribution facts, then acquire compositional reasoning, and later develop analogical reasoning. We find that, unlike compositional reasoning, the emergence of analogical reasoning is highly sensitive to data characteristics and optimization settings (e.g., weight decay) and does not improve monotonically with model size. This suggests that analogical reasoning relies on qualitatively different mechanisms from compositional reasoning, and that these mechanisms cannot be explained solely by weight-norm regularization or by increasing model capacity.

Motivated by these findings, we further investigatehowanalogical reasoning is implemented mechanistically in Transformer. We show that analogical reasoning can be decomposed into two components: (1) structural alignment in the embedding space and (2) functor application in Transformer layers. In the synthetic task, analogical reasoning emerges after embeddings of entities across categories become geometrically aligned (Figure 1-(C)), which can be measured by a substantial decrease in Dirichlet Energy during training. This alignment is subsequently exploited by Transformer to transform a source entity (ese_{s}) into its analogical counterpart (ete_{t}), with the functor (ff) being applied as a vector addition (et≈es+fe_{t}\approx e_{s}+f). Furthermore, we probe pretrained LLMs using in-context learning and observe similar signatures. While in the synthetic task, the decrease in Dirichlet Energy occurs along the training-step axis, in LLMs, the same phenomenon unfolds along the layer axis. These results indicate that the analogical reasoning mechanism discovered in the synthetic task is also present in pretrained LLMs.

Unlike recent reasoning approaches that emphasize chaining local steps of thought, analogical reasoning enables conceptual leaps across domains. As such, it offers the basis for a distinct reasoning paradigm beyond sequential composition. We hope that our work provides a foundation for studying analogy in Transformers.

We organize the paper as follows. InSection2, we propose a synthetic task designed to evaluate both compositional and analogical reasoning. InSection3, we present a detailed analysis of training dynamics in Transformers on this task. InSection4, we show the mechanistic implementation of analogical reasoning in Transformers, and inSection5, we further demonstrate that analogous mechanistic signatures are also present in pretrained LLMs.

2Synthetic Task for Analogical Reasoning

We propose a synthetic task to evaluate compositional and analogical reasoning. The task is defined over entities and relations and consists of three types of facts: atomic, compositional, and analogical facts.

2.1Problem Formulation

Entities and Relations.

Letℰ\mathcal{E}denote a finite set of entities andℛ\mathcal{R}a finite set of relations. We partition the entity set into two disjoint subsets (ℰ1,ℰ2\mathcal{E}_{1},\mathcal{E}_{2}),222ℰ=ℰ1∪ℰ2,ℰ1∩ℰ2=∅,|ℰ1|=|ℰ2|\mathcal{E}=\mathcal{E}_{1}\cup\mathcal{E}_{2},\mathcal{E}_{1}\cap\mathcal{E}_{2}=\varnothing,|\mathcal{E}_{1}|=|\mathcal{E}_{2}|which correspond to two categories inFigure 1. Onℰ1\mathcal{E}_{1}, we construct a directed complete graph whose edges are labeled by relations. Formally, for each ordered pair(ei,ej)∈ℰ1×ℰ1(e_{i},e_{j})\in\mathcal{E}_{1}\times\mathcal{E}_{1}withei≠eje_{i}\neq e_{j}, we assign a relation labelr​(ei,ej)∈ℛ,r(e_{i},e_{j})\in\mathcal{R},sampled uniformly at random fromℛ\mathcal{R}, with the constraint that each entityei∈ℰ1e_{i}\in\mathcal{E}_{1}has distinct relation labels on its outgoing edges.333If an entity has multiple outgoing edges with the same relation and is used as the intermediate node in a compositional fact, compositional reasoning becomes impossible.

Atomic facts.

Anatomic factrepresents a single labeled edge in the relational graph onℰ1\mathcal{E}_{1}, and is given by the triple

(es,r​(es,et),et)∈Datomic(e_{s},\ r(e_{s},e_{t}),\ e_{t})\in D_{\text{atomic}}We denote by𝒟atomic\mathcal{D}_{\text{atomic}}the set of atomic facts. Atomic facts constitute the basic relational knowledge during training.

Compositional facts.

From atomic facts, we derivecompositional factsthat correspond to two-hop relational compositions. A compositional fact is defined as the quadruple

(es,r​(es,ei),r​(ei,et),et)∈Dcomp(e_{s},\ r(e_{s},e_{i}),\ r(e_{i},e_{t}),\ e_{t})\in D_{\text{comp}}which is obtained by composing the following two atomic facts that share the intermediate entityeie_{i}:(es,r​(es,ei),ei)(e_{s},r(e_{s},e_{i}),e_{i})and(ei,r​(ei,et),et).(e_{i},r(e_{i},e_{t}),e_{t}).We denote by𝒟comp\mathcal{D}_{\text{comp}}the set of compositional facts.

Analogical facts.

To formalize analogy across categories, we consider a bijectionℱ:ℰ1→ℰ2,\mathcal{F}:\mathcal{E}_{1}\rightarrow\mathcal{E}_{2},which induces a one-to-one correspondence between entities in the two categories. We transfer the relational structure fromℰ1\mathcal{E}_{1}toℰ2\mathcal{E}_{2}by definingr​(ℱ​(es),ℱ​(et))=r​(es,et),∀es≠et∈ℰ1.r\!\bigl(\mathcal{F}(e_{s}),\mathcal{F}(e_{t})\bigr)=r(e_{s},e_{t}),\forall\,e_{s}\neq e_{t}\in\mathcal{E}_{1}.As a result,ℰ1\mathcal{E}_{1}andℰ2\mathcal{E}_{2}share a relational structure. From a category-theoretic perspective(Awodey,2010), this mappingℱ\mathcal{F}can be viewed as afunctor. Ananalogical factstates this cross-category alignment as the triple

(es,f,ℱ​(es))∈Danalogical,(e_{s},\ f,\ \mathcal{F}(e_{s}))\in D_{\text{analogical}},wherees∈ℰ1e_{s}\in\mathcal{E}_{1}andℱ​(es)∈ℰ2\mathcal{F}(e_{s})\in\mathcal{E}_{2}, andes≠ℱ​(es)e_{s}\neq\mathcal{F}(e_{s})since the two sets are disjoint. We denote by𝒟analogical\mathcal{D}_{\text{analogical}}the set of analogical facts. Here,ffis treated as a special symbol.

Compositional and Analogical reasoning.

We now define the two types of generalization evaluated in our task: compositional and analogical reasoning. While both require extrapolation beyond the training data, they rely on qualitatively different capabilities.

Definition 2.1(Compositional reasoning).

Let𝒟compOOD\mathcal{D}^{\text{OOD}}_{\text{comp}}be a held-out set of compositional facts such that it contains constituent atomic fact, but the composed quadruple itself does not. A model is said to exhibitcompositional reasoningif it can correctly predict the final entity in samples from𝒟compOOD\mathcal{D}^{\text{OOD}}_{\text{comp}}, given the preceding entity and two relation tokens.

Definition 2.2(Analogical reasoning).

Let𝒟analogicalOOD\mathcal{D}^{\text{OOD}}_{\text{analogical}}be a held-out set of analogical facts. A model is said to exhibitanalogical reasoningif it can correctly predict the counterpart entityℱ​(e)\mathcal{F}(e)inℰ2\mathcal{E}_{2}from the prefix(e,f)(e,f), despite the fact that the corresponding triple is not observed during training.

Compositional reasoning primarily requires the ability to combine acquired relational knowledge to infer novel outcomes. In contrast, analogical reasoning demands learning the underlying relational structure of each category and leveraging this structure to generalize.

2.2Experiment Setup

Dataset.

The dataset is characterized by the following controllable configurations: (1) the total number of entities|ℰ||\mathcal{E}|, (2) the number of relations|ℛ||\mathcal{R}|, and (3) the OOD ratio for compositional facts (|DcompOOD|/|Dcomp||D_{\text{comp}}^{\text{OOD}}|/|D_{\text{comp}}|) and (4) for analogical facts (|DanalogicalOOD|/|Danalogical||D_{\text{analogical}}^{\text{OOD}}|/|D_{\text{analogical}}|). Unless otherwise specified, we use the following default configuration:|ℰ|=20|\mathcal{E}|=20entities in total,|ℛ|=10,000|\mathcal{R}|=10{,}000relations, and an OOD ratio of0.10.1for both compositional and analogical facts. The vocabulary consists of|ℰ||\mathcal{E}|entity tokens,|ℛ||\mathcal{R}|relation tokens, and a single functor token, yielding a total vocabulary size of|ℰ|+|ℛ|+1|\mathcal{E}|+|\mathcal{R}|+1. Concrete examples of each fact type and their tokenized representations are summarized inTable 1.

Table 1:Tokenization for each fact.

Model and Training setup.

Following prior work on synthetic tasks(Chanet al.,2022; Reddy,2024; Minegishiet al.,2025), we train models using a cross-entropy loss applied only to the final token of each sequence. Our default model is a causal Transformer with a single layer and a single attention head, with a dimension of128128. We use the Adam optimizer(Kingma,2014)with a learning rate of10−410^{-4}, weight decay set to0, and a batch size of3232. All reported results are averaged over three random seeds. Additional implementation details are provided inAppendix A.

Refer to captionFigure 2:Learning dynamics under varying data properties intraining data,compositionalandanalogicalreasoning. From left to right, we vary (i) the number of entities (|ℰ||\mathcal{E}|), (ii) the number of relations (|ℛ||\mathcal{R}|), (iii) the compositional OOD ratio, and (iv) the analogical OOD ratio. While training accuracy and compositional generalization improve smoothly across settings, analogical reasoning consistently emerges later and exhibits unique behavior.

3Emergent Analogical Reasoning

We first examine the learning dynamics of a 1-layer Transformer on our synthetic task444Implementation code is available athttps://github.com/gouki510/Analogy_in_Transformer.. As shown inFigure 1-(B) for the case of1010entities, training exhibits a clearthree-stage progression. The model initially fits the in-distribution data (memorization), then acquirescompositional reasoning, and later developsanalogical reasoning. Accordingly, we analyze this emergence from three perspectives: data characteristics (Section3.1), optimization (Section3.2), and model scaling (Section3.3).

3.1Data Characteristics Drive Analogical Reasoning

We first investigate how dataset characteristics affect the emergence of analogical reasoning.Figure 2summarizes the learning dynamics oftraining accuracy,compositional reasoningandanalogical reasoningas we vary four key factors: the number of entities|ℰ||\mathcal{E}|, the number of relations|ℛ||\mathcal{R}|, the compositional and the analogical OOD ratio.

Across all settings, training accuracy improves smoothly, indicating that the model can reliably memorize in-distribution facts. As the number of entities or relations increases, training converges more slowly, reflecting the increased task complexity. Compositional reasoning closely follows the training accuracy. In more complex settings, the gap between training accuracy and compositional reasoning disappears, as memorization itself becomes increasingly difficult. In contrast, analogical reasoning exhibits different behavior. As the number of entities increases, the time required to acquire analogical reasoning grows substantially relative to compositional reasoning. This suggests that analogical reasoning depends on learning underlying relational structures that become harder to capture as the entity set grows.

The number of relations also plays a critical role in analogical reasoning. When the relation set is too small (e.g.,|ℛ|=100|\mathcal{R}|=100), analogical reasoning fails to emerge. This is consistent with the view that analogical reasoning infers entities based on their relational roles, making relational diversity essential for distinguishing and representing entities. Interestingly, in some settings with a very large number of relations (e.g.,|ℛ|=1,000|\mathcal{R}|=1{,}000), analogical reasoning is acquired but later lost, exhibitingtransient behavior, which has been reported on in-context learning works(Parket al.,2024; Singhet al.,2025). We further analyze this phenomenon in theAppendix C. Additionally, increasing the OOD ratio reduces the amount of informative training signal, making generalization more difficult. Higher compositional OOD ratios delay the emergence of compositional reasoning, consistent with prior findings(Heet al.,2024; Redhardtet al.,2025). Analogical reasoning is more sensitive to the analogical OOD ratio: when this ratio is high (e.g.,0.90.9), analogical generalization fails to emerge, highlighting its intrinsic difficulty. More broadly, this data-dependence is in line with prior evidence that distributional properties of the training data can drive (or suppress) the emergence of complex behaviors in Transformers, such as emergent in-context learning(Chanet al.,2022). Notably, the compositional and analogical facts do not interfere with each other: the compositional OOD ratio has little effect on analogical reasoning, and vice versa. This decoupling highlights that analogical reasoning constitutes a qualitatively distinct form of compositional reasoning. We further examine the effect of graph sparsity inAppendix D.

3.2Role of Optimization in Analogical Reasoning

We find that optimization choices (weight decay, batch size, and learning rate) also play a critical role in the acquisition of analogical reasoning. The results are summarized inFigure 3. We first examine the effect of weight decay, which is commonly understood as a mechanism for suppressing memorization. As the weight decay coefficient increases from0to0.010.01and0.10.1, analogical reasoning emerges earlier during training. However, when weight decay is set too large (e.g.,11), analogical reasoning fails to be learned. In contrast, compositional reasoning remains robust even under strong weight decay. The role of weight decay in improving generalization has been extensively studied in the context of grokking(Poweret al.,2022; Liuet al.,2022,2023). Prior work has argued that strong norm-based regularization, such as weight decay, shrinks model weights and guides optimization toward more generalizable solutions in the loss landscape. However, our results suggest that the acquisition of analogical reasoning cannot be explained solely by such weight-norm effects, and may require more structured internal representations than those induced by simple norm shrinkage. We also observe that increasing the batch size generally accelerates learning, consistent with standard optimization intuition. Results for learning rate sweeps are provided inAppendix E.

Refer to captionFigure 3:Effect of optimization hyperparameters incompositionalandanalogicalreasoning.Left:varying weight decay. Moderate weight decay (e.g.,0.010.01and0.10.1) accelerates the analogical reasoning, whereas excessively strong weight decay (1.0)1.0)prevents it, despite compositional reasoning remaining successful.Right:varying batch size. Larger batch sizes generally lead to faster acquisition of analogical reasoning.

3.3Scaling Behavior of Analogical Reasoning

We investigate how model scaling affects compositional and analogical reasoning by sweeping both model width (dmodeld_{\text{model}}) and the number of layers (nlayern_{\text{layer}}), as shown inFigure 4. Across all settings, compositional reasoning consistently improves with increasing model size. Wider models achieve higher accuracy earlier in training. This scaling behavior aligns with prior findings(Redhardtet al.,2025)that compositional generalization benefits from model scaling.

In contrast, analogical reasoning exhibits different characteristics in scaling. Increasing model size does not monotonically improve performance, and in some cases even degrades it. For example, models withdmodel=64d_{\text{model}}=64almost never succeed at analogical reasoning. Moderately sized models (dmodel=128d_{\text{model}}=128and256256) are more likely to acquire analogical reasoning, whereas further increasing the width to512512makes analogical reasoning more difficult to learn. For depth scaling, we observe that deeper models can underperform under our default (fixed) optimization settings. We caution that this behavior can reflect an optimization artifact rather than an architectural limitation: a simple learning-rate sweep recovers strong performance for deeper models (Appendix B,Figure 11). More broadly, this highlights that analogical reasoning is substantially more sensitive to optimization and hyperparameter choices than compositional reasoning. In the next section, we analyze the internal mechanisms underlying its emergence during training.

Refer to captionFigure 4:Effect of model scaling oncompositionalandanalogicalreasoning.Left:accuracy curves for different model widths (dmodeld_{\text{model}}).Right:accuracy curves for different numbers of layers (nlayern_{\text{layer}}). Compositional reasoning improves consistently with increasing model size, whereas analogical reasoning shows non-monotonic and unstable scaling behavior.

4The Mechanism of Analogy in Transformer

Refer to captionFigure 5:Analogical reasoning decomposes into (1) Structural alignment in the embedding, (2) Functor application in Transformer.Refer to caption(a) Refer to caption(b) Refer to caption(c)

Figure 6:Mechanistic signalsunderlying the emergence of analogical reasoning, where is measured by the model’sprobabilityof the correct target entity (et)e_{t}).(a) Dirichlet energydecreases during training, indicating increasing structural alignment in the embedding space.(b) Attention Scorefrom the functor tokenffto the source entityese_{s}increase as analogical reasoning emerges, reflecting attention-based information retrieval.(c) Parallelism, defined by the similarity between(et−es)(e_{t}-e_{s})andff, increases concurrently, indicating that the model realizes analogical reasoning by adding the functor representationffto the source entity embeddingese_{s}via a residual connection.We next examine how Transformer models implement analogical reasoning mechanistically. We consider analogical mappings of the form

et=ℱ​(es),e_{t}=\mathcal{F}(e_{s}),withes∈ℰ1e_{s}\in\mathcal{E}_{1}andet∈ℰ2e_{t}\in\mathcal{E}_{2}. Our analysis decomposes the realization of analogy into two components, illustrated inFigure 5.

(1) Structural alignment in the embedding space.The relational structure of each category is captured in the embedding space.(2) Functor Application.Attention mechanisms enable the functor tokenffto retrieve information about the source entityese_{s}. Specifically,ffattends toese_{s}and writes information aboutese_{s}into the representation at the position offf. Residual connections integrate the retrieved information with the representation offf. When the embedding space is well structured as in (1), this integration realizes a vector arithmetic of the form,

et≈es+f,e_{t}\approx e_{s}+f,allowing the model to predict the correct target entity. In the following subsections, we quantify structural alignment using Dirichlet Energy (Section4.1), analyze the implementation of functor application in Transformer (Section4.2).

4.1Structural Alignment in Embedding Layer

We begin by analyzing embedding-level structural alignment, corresponding to component (1) inFigure 5. As a first step, we visualize entity embeddings555Concretely, the entity embedding is the vector corresponding to entity in the embedding matrix.before and after the model acquires analogical reasoning.Figure 7shows PCA projections of entity embeddings from categoryℰ1\mathcal{E}_{1}(blue)andℰ2\mathcal{E}_{2}(red), with black arrows indicating functor across categories. Before training, embeddings from the two categories are not structurally aligned. After the analogical reasoning, the two categories exhibit clear geometric alignment. We further visualize the training dynamics of entity embeddings using PCA inAppendix F. To quantify this observation, we measure theDirichlet Energyof entity embeddings with respect to a graph defined by our task structure. Let𝑨∈ℝ|ℰ|×|ℰ|\boldsymbol{A}\in\mathbb{R}^{|\mathcal{E}|\times|\mathcal{E}|}denote the adjacency matrix, and let𝒉ei∈ℝd\boldsymbol{h}_{e_{i}}\in\mathbb{R}^{d}denote the embedding ofeie_{i}. Since our focus is on analogical reasoning, we construct𝑨\boldsymbol{A}such that𝑨i​j=1\boldsymbol{A}_{ij}=1if entitiesiiandjjare related via the functor mapping, and𝑨i​j=0\boldsymbol{A}_{ij}=0otherwise. Following prior work(Parket al.,2025), the Dirichlet Energy is defined as,

E​(ℰ)=∑ei,ej∈ℰ𝑨i​j​∥𝒉ei−𝒉ej∥2.E(\mathcal{E})=\sum_{e_{i},e_{j}\in\mathcal{E}}\boldsymbol{A}_{ij}\lVert\boldsymbol{h}_{e_{i}}-\boldsymbol{h}_{e_{j}}\rVert^{2}.(1)We provide a detailed derivation of the multi-dimensional formulation inAppendix G. Lower Dirichlet Energy indicates that relationally connected entities are embedded closer together, reflecting increased structural organization in the embedding space. Because Dirichlet Energy depends on representation distances, it can also be influenced by the growth of embedding norms during training; seeAppendix S.Figure 6-(a) shows theDirichlet Energyand the model’sprobabilityof predicting the correct target entity during training. Analogical performance improves after the Dirichlet Energy has substantially decreased, suggesting that embedding-level structural alignment precedes the emergence of analogical reasoning. The effect of model scaling is discussed inAppendix H.

Refer to caption(a) Refer to caption(b)

Figure 7:PCA Visualization of entity embeddings before (0step) and after (10310^{3}step) the acquisition of analogical reasoning. Entity embeddings from categoryℰ1\mathcal{E}_{1}(blue)andℰ2\mathcal{E}_{2}(red)are shown, with arrows indicating the functor.(a) Before, embeddings from the two categories are not structurally aligned.(b) After, the two categories exhibit clear geometric alignment. Results across training epochs are provided inAppendix F.

4.2Functor Application in Transformer

Given the emergence of a structured embedding space (Figure 7), how does the model perform analogical reasoning to infer the corresponding entity? As we show below, this is achieved byapplying the functor as a vector additionwithin Transformer layers.

Concretely, the input is(es,f)(e_{s},f)withes∈ℰ1e_{s}\in\mathcal{E}_{1}, and the target iset∈ℰ2e_{t}\in\mathcal{E}_{2}. To realize the mapping(es→et)(e_{s}\rightarrow e_{t}), two mechanisms are required, corresponding to components (2) inFigure 5. First, through attention, the functor tokenffretrieves information about the source entityese_{s}and incorporates it into its own representation. Second, via residual connections, the representation offfis additively integrated with that ofese_{s}, resulting in a representation that approximates the target entity. Together, these operations implement analogical reasoning as a simple vector addition,et≈es+f.e_{t}\approx e_{s}+f.The first mechanism can be verified by examining attention scores fromfftoese_{s}. Specifically, we measure the attention weight from the source entity token to the functor token,

Attn​(es→f),\mathrm{Attn}(e_{s}\rightarrow f),(2)where the value is taken from the attention map. As shown inFigure 6-(b), thisattention score (purple)tends to increaseprior toobservable improvements in analogical reasoning performance. This is consistent with the view that internal circuit formation or mechanistic progress signals can precede changes in model behavior, as observed in prior work on grokking progress measures(Nandaet al.,2023). This trend suggests that the model increasingly transfers source-entity information to the functor before reliably producing correct analogical outputs. The second mechanism is captured by a measure of geometric parallelism, defined as the cosine similarity,

cos⁡(𝒉t′−𝒉s,𝒉f),\cos\!\left(\boldsymbol{h}^{\prime}_{t}-\boldsymbol{h}_{s},\;\boldsymbol{h}_{f}\right),(3)where𝒉s\boldsymbol{h}_{s}denotes the embedding of the source entity,𝒉f\boldsymbol{h}_{f}denotes the embedding of the functor token, and𝒉t′\boldsymbol{h}^{\prime}_{t}denotes the unembedding of the target entity666Concretely,𝒉t′\boldsymbol{h}^{\prime}_{t}corresponds to the vector in the unembedding matrix associated with entitytt. We use the unembedding representation because the model computes output probabilities over target entities via the final unembedding matrix.. This measure evaluates whether the functor representation corresponds to the displacement from the source entityese_{s}to the target entityete_{t}in representation space. As shown inFigure 6-(c), thisparallelism measure (purple)increases concurrently with analogical reasoning performance. This trend holds for both in-distribution and out-of-distribution settings.

Refer to captionFigure 8:Left:Task structure for analogical reasoning in LLM experiments. Two categories share the same relational structure defined by relationsaaandbb.Right:Method overview. We apply the logit lens at each Transformer layer to track how the probability of the correct target entity evolves across layers.As illustrated inFigure 5, these results demonstrate that when performing analogical reasoning, the model acquires structured representations within each category in the embedding space, and then applies the functor within Transformers to map the source entity to the correct target.

5The Mechanism of Analogy in LLMs

A key question for interpretability(Bereska and Gavves,2024; Sharkeyet al.,2025; Zhanget al.,2026)is whether mechanisms discovered in toy settings align with the behavior of real LLMs. We therefore investigate whether the mechanism of analogical reasoning identified in our toy settings also emerges in real LLMs.

Method.

We conduct experiments usingGemma2-2B/9B(Gemma Team,2024). We probe analogical reasoning in LLMs throughin-context learning. An overview of our method is shown inFigure 8. We provide the model with the following prompt, where<e>denotes entity tokens,aandbdenote relation tokens, and~denotes a functor:

<e1>a<e2>, <e1>b<e3>. <e6>a<e4>, <e6>b<e7>. <e1><e6>, <e3><e

where the correct answer is7. This prompt closely mirrors the synthetic task (Figure 1): two categories share the same relational structure defined by relationsaaandbb, and the model is required to infer the corresponding entity across categories. We intentionally avoid using tokens such as⟨f⟩\langle f\rangleand⟨r12⟩\langle r_{12}\rangle, which are the same representations as the synthetic task (Table 1). Because LLMs are pretrained, surface forms such as the string “e1” in entity tokens or relation string “r12” may already carry unintended priors. Similarly, a naive categorical construction (e.g., using entities set{e1,e2,e3}\{e_{1},e_{2},e_{3}\}for Category 1 and{e4,e5,e6}\{e_{4},e_{5},e_{6}\}for Category 2) could implicitly encode simple arithmetic patterns such as a “+3+3” offset as a functor. To avoid these artifacts, we design the prompt so that analogical reasoning is evaluated purely through in-context learning, rather than through pretrained semantic or numerical biases. Results for alternative prompt designs are reported inAppendix I.

Refer to captionFigure 9:Layer-wise evolution of Dirichlet Energy and target probability in LLMs. Dirichlet Energy (purple) and the logit-lens probability of the target entity (green) are shown across layers forGemma2-2B(left) andGemma2-9B(right). In both models, the Dirichlet energy decreases in the later layers, coinciding with a rapid increase in the probability of the correct target.Because in-context learning unfolds across layers, we apply the logit lens(nostalgebraist,2020)at the last token in every layer to track how strongly the model predicts the target7(Figure 8, right). Since logit lens can underestimate information present in intermediate representations, we additionally compare it with a trained linear probe inAppendix R. In addition, followingSection4.1, we analyze the structural organization of hidden states using Dirichlet Energy computed over an adjacency matrix𝑨\boldsymbol{A}that connects entities related by the functor:E​(𝑯ℓ)=∑i,j𝑨i​j​∥𝒉eiℓ−𝒉ejℓ∥2.E(\boldsymbol{H}^{\ell})=\sum_{i,j}\boldsymbol{A}_{ij}\lVert\boldsymbol{h}_{e_{i}}^{\ell}-\boldsymbol{h}_{e_{j}}^{\ell}\rVert^{2}.Here,𝑯ℓ∈ℝT×d\boldsymbol{H}^{\ell}\in\mathbb{R}^{T\times d}denotes the hidden states at layerℓ\ell, taken as the output of the Transformer block at that layer, whereTTis the number of tokens andddis the hidden dimension, and𝒉eiℓ\boldsymbol{h}_{e_{i}}^{\ell}corresponds to the hidden state of the⟨ei⟩\langle e_{i}\rangletoken. ForGemma2models, entity markers such as⟨ei⟩\langle e_{i}\rangleare tokenized into multiple sub-tokens (e.g.,<,e,ii,>); we average their hidden states when computing energies.

Refer to captionFigure 10:PCA projections of entity hidden states at layer 7 (left) and layer 21 (right) inGemma2-2B. At layer 7, before the decrease in Dirichlet Energy, entity representations across categories are weakly aligned. By layer 21, after the energy drop, entity representations become geometrically aligned.

Results.

Figure 9shows the layer-wise Dirichlet Energy (purple) alongside the target’s probability by the logit lens (green). For bothGemma2-2BandGemma2-9B, the energy begins to decrease in the later layers, and this decrease is closely accompanied by a corresponding increase in the probability of the correct answer. This indicates that structural alignment between functor-related entities emerges progressively as the model approaches the output layers. Interestingly, while analogical behavior in the toy model appeared along thetraining-step axis, the same phenomenon manifests along thedepth (layer) axisin LLMs. This suggests that, even without explicit weight updates, LLMs refine their representations across layers, progressively aligning geometric structure toward the output. This behavior is closely related to prior observations(Von Oswaldet al.,2023; Deutchet al.,2024)that in-context learning can induce gradient descent-like effects during inference. We further verify that this trend is robust to increasing the number of entities (Appendix J) and is not specific to theGemmafamily, with similar results observed inLLaMAmodels(Grattafioriet al.,2024)(Appendix K)

Figure 10visualizes PCA projections of the hidden states ofGemma2-2Bat layer 7 (before the energy decrease) and layer 21 (after the energy decrease). Consistent with our toy experiments, structurally aligned representations become clearly organized only after the energy drops. PCA visualizations for all layers are provided inAppendix L.

6Related Works and Discussion

Summary.

In this work, we focus onanalogy, an underexplored aspect of reasoning in LLMs. We introduce a synthetic task designed to analyze analogical reasoning inSection2. InSection3, we investigate its training dynamics and their relationship to data characteristics, optimizers, and model scale. We then discover the internal mechanisms inSection4, and show that closely related mechanisms can also be observed in pretrained LLMs inSection5. We approach reasoning from a novel perspective based on analogy, while remaining closely connected to existing work.

Analogy and Language Models.

In cognitive science, analogy is formalized byStructure-Mapping Theory, which characterizes analogy as a mapping that preserves higher-order relations rather than surface features(Gentner and Markman,1997; Gick and Holyoak,1983). Building on this, in natural language processing, analogy has traditionally been studied through four-term lexical analogies (A:B::C:DA\!:\!B::C\!:\!D)(Turneyet al.,2003; Mikolovet al.,2013a; Penningtonet al.,2014; Ethayarajhet al.,2019; Ushioet al.,2021). Recent work evaluates analogical reasoning as structured inference beyond lexical analogies, with benchmarks such as E-KAR and ANALOBENCH revealing persistent difficulties under increasing relational complexity(Chen,2022; Ye,2024). Our work complements this line of research by using synthetic tasks to precisely control relational structure and analyze how analogical reasoning emerges in Transformers.

Understanding Transformers with Synthetic Tasks.

Transformer(Vaswaniet al.,2017)has become the standard backbone of modern deep learning models, motivating interpretability studies(Bereska and Gavves,2024). A prominent line of work uses synthetic tasks(Chanet al.,2022; Reddy,2024; Nagarajanet al.,2025; Noroozizadehet al.,2025)to isolate specific capabilities in controlled settings. Synthetic tasks have likewise been central to studying reasoning, including algorithmic and graph-structured problems(Zhanget al.,2025; Zhaoet al.,2025; Qinet al.,2025)and compositional reasoning, where they have enabled analyses of training dynamics, representations, and scaling behavior(Heet al.,2024; Wanget al.,2024; Furutaet al.,2024; Redhardtet al.,2025). We approach the line of work on understanding Transformers with synthetic tasks from the novel perspective of analogy, and show that the same nature extends to pretrained LLMs.

Sample Efficiency and Creativity.

One of the major limitations of current LLMs is their poor sample efficiency(Warstadtet al.,2023): compared to humans, they require an enormous amount of data to acquire new knowledge. From a cognitive perspective, this remarkable sample efficiency is often attributed, at least in part, to the use of analogy(Thagard,1992; Gentner and Hoyos,2017). Once humans learn relational structure in one domain, they can transfer it to a different but structurally similar domain, enabling rapid and highly data-efficient learning. Our results suggest that pretrained LLMs may also be capable of identifying shared relational structure via in-context learning (Figure 9andFigure 10). However, our study does not yet establish whether such structure is effectively leveraged during learning to improve sample efficiency. Beyond sample efficiency, analogy has also been argued to play a central role in creativity(Goel,1997; Gentneret al.,1997). Many historically important scientific discoveries are often described as arising from analogy or metaphor(Leatherdale,1974; Winkler,1981; Holyoak and Thagard,1996). For example, Bohr’s model of the atom inspired by planetary orbits(Bohr,1913; Winkler,1981). Scientific progress has often been driven by discovering structural similarities between seeminglydistantdomains. Capturing notions such as the “distance” between categories remains beyond the scope of our current task. Moreover, human reasoning operates over large collections of partially overlapping categories rather than cleanly disjoint ones, without any explicit functor signals (⟨f⟩\langle f\rangle), a property that our synthetic setting does not yet model. Nevertheless, we view this work as an initial step toward mechanistically studying analogy in Transformers, and hope it will stimulate further research toward more sample-efficient and creative models. An extended discussion is deferred toAppendix M.

7Limitations

Our controlled setup makes several simplifying assumptions. We also include additional ablations and analyses in the appendix that partially relax these assumptions.

Explicit functor signal.Our main synthetic task provides a dedicated functor token during training and evaluation. This is a convenient abstraction for isolating the mapping operation, but real-world analogies rarely come with such an explicit cue. As a first step toward relaxing this assumption, we consider an implicit-functor variant without an explicit functor token (Appendix Q), where analogical reasoning can still emerge, albeit in a more challenging regime.

Perfect (or near-perfect) structural correspondence.Our basic construction uses categories with (near-)isomorphic relational structure. Real-world analogies are often partial and noisy. To probe robustness beyond perfect isomorphism, we introduce controlled violations via a functor noise ratio and observe a consistent degradation in analogical performance as correspondence is broken (Appendix O).

Complete relational graphs.Our default construction uses complete relational graphs. In contrast, real-world relational structure is typically sparse and often exhibits small-world properties(Humphries and Gurney,2008). We partially address this by studying sparse graphs inAppendix D.

Restricted diversity of categories and mappings.Our main experiments focus on two disjoint categories and a small number of mappings. In contrast, real-world reasoning often involves many partially overlapping categories with multiple competing correspondences. To test whether our findings are specific to a single toy mapping, we extend the setup to multiple categories and multiple functors and observe that analogical reasoning still emerges (Appendix P).

External validity beyond synthetic tasks.While synthetic tasks enable precise control and mechanistic analysis, they cannot fully capture the richness of natural language analogies. To partially address this gap, we evaluate on the natural-language E-KAR(Chen,2022)benchmark and observe consistent layer-wise signatures linking Dirichlet energy reduction and improved answer probability (Appendix N).

Limited causal validation of mechanistic claims.Several of our mechanistic findings are supported primarily by correlational analyses. While we include additional ablations and complementary analyses in the appendix, stronger causal interventions—e.g., targeted activation patching(Wanget al.,2023)or editing of the relevant representation geometry(Wurgaftet al.,2026)—remain an important direction for future work.

8Conclusion

We studied how analogical reasoning emerges in Transformers through a controlled synthetic task inspired by category-theoretic functors. Across data, optimization, and scaling sweeps, we found that analogical reasoning emerges later than memorization and compositional reasoning and is substantially more sensitive to training conditions. Through mechanistic analysis, we decomposed analogy into (i) geometric alignment of relational structure in the embedding space, quantified by Dirichlet Energy, and (ii) functor application implemented within the Transformer via attention and residual-stream composition. Finally, we observed closely related layer-wise signatures in pretrained LLMs, and further validated them on a natural-language analogy benchmark. We hope these results provide a concrete basis for future work on more naturalistic analogical reasoning settings and stronger causal tests of mechanistic hypotheses.

Impact Statement

This work improves our understanding of analogical reasoning in Transformer-based models through controlled synthetic tasks. By linking insights from toy models to pretrained LLMs, it contributes to ongoing efforts in interpretability and model analysis. The work is foundational in nature and does not raise direct societal or safety concerns.

Acknowledgements

We thank Heiga Zen for their support on this work and review on the initial version of the paper. We appreciate the funding support from Google Japan. This work was also supported by UTokyo-Google AI Symbiotic Future Society Program.

References

  • S. Awodey (2010)Category theory.Vol.52,OUP Oxford.Cited by:Appendix M,§1,§2.1.
  • P. Bartha (2013)Analogy and analogical reasoning.Cited by:§1.
  • L. Bereska and S. Gavves (2024)Mechanistic interpretability for AI safety - a review.Transactions on Machine Learning Research.Note:Survey Certification, Expert CertificationExternal Links:ISSN 2835-8856,LinkCited by:§5,§6.
  • N. Bohr (1913)On the Constitution of Atoms and Molecules.Phil. Mag. Ser. 626,pp. 1–24.External Links:DocumentCited by:§6.
  • S. Chan, A. Santoro, A. Lampinen, J. Wang, A. Singh, P. Richemond, J. McClelland, and F. Hill (2022)Data distributional properties drive emergent in-context learning in transformers.InAdvances in Neural Information Processing Systems,S. Koyejo, S. Mohamed, A. Agarwal, D. Belgrave, K. Cho, and A. Oh (Eds.),Vol.35,pp. 18878–18891.Cited by:§2.2,§3.1,§6.
  • J. e. al. Chen (2022)E-kar: a benchmark for rationalizing natural language analogical reasoning.arXiv preprint arXiv:2203.08480.Cited by:Figure 21,Figure 21,Appendix N,§1,§6,§7.
  • H. Cho, H. Yang, G. Minegishi, and N. Inoue (2025)Mechanism of task-oriented information removal in in-context learning.arXiv preprint arXiv:2509.21012.Cited by:Appendix M.
  • DeepSeek-AI, D. Guo, D. Yang, H. Zhang, J. Song, R. Zhang, R. Xu, Q. Zhu, S. Ma, P. Wang, X. Bi, X. Zhang, X. Yu, Y. Wu, Z. F. Wu, Z. Gou, Z. Shao, Z. Li, Z. Gao, A. Liu, B. Xue, B. Wang, B. Wu, B. Feng, C. Lu, C. Zhao, C. Deng, C. Zhang, C. Ruan, D. Dai, D. Chen, D. Ji, E. Li, F. Lin, F. Dai, F. Luo, G. Hao, G. Chen, G. Li, H. Zhang, H. Bao, H. Xu, H. Wang, H. Ding, H. Xin, H. Gao, H. Qu, H. Li, J. Guo, J. Li, J. Wang, J. Chen, J. Yuan, J. Qiu, J. Li, J. L. Cai, J. Ni, J. Liang, J. Chen, K. Dong, K. Hu, K. Gao, K. Guan, K. Huang, K. Yu, L. Wang, L. Zhang, L. Zhao, L. Wang, L. Zhang, L. Xu, L. Xia, M. Zhang, M. Zhang, M. Tang, M. Li, M. Wang, M. Li, N. Tian, P. Huang, P. Zhang, Q. Wang, Q. Chen, Q. Du, R. Ge, R. Zhang, R. Pan, R. Wang, R. J. Chen, R. L. Jin, R. Chen, S. Lu, S. Zhou, S. Chen, S. Ye, S. Wang, S. Yu, S. Zhou, S. Pan, S. S. Li, S. Zhou, S. Wu, S. Ye, T. Yun, T. Pei, T. Sun, T. Wang, W. Zeng, W. Zhao, W. Liu, W. Liang, W. Gao, W. Yu, W. Zhang, W. L. Xiao, W. An, X. Liu, X. Wang, X. Chen, X. Nie, X. Cheng, X. Liu, X. Xie, X. Liu, X. Yang, X. Li, X. Su, X. Lin, X. Q. Li, X. Jin, X. Shen, X. Chen, X. Sun, X. Wang, X. Song, X. Zhou, X. Wang, X. Shan, Y. K. Li, Y. Q. Wang, Y. X. Wei, Y. Zhang, Y. Xu, Y. Li, Y. Zhao, Y. Sun, Y. Wang, Y. Yu, Y. Zhang, Y. Shi, Y. Xiong, Y. He, Y. Piao, Y. Wang, Y. Tan, Y. Ma, Y. Liu, Y. Guo, Y. Ou, Y. Wang, Y. Gong, Y. Zou, Y. He, Y. Xiong, Y. Luo, Y. You, Y. Liu, Y. Zhou, Y. X. Zhu, Y. Xu, Y. Huang, Y. Li, Y. Zheng, Y. Zhu, Y. Ma, Y. Tang, Y. Zha, Y. Yan, Z. Z. Ren, Z. Ren, Z. Sha, Z. Fu, Z. Xu, Z. Xie, Z. Zhang, Z. Hao, Z. Ma, Z. Yan, Z. Wu, Z. Gu, Z. Zhu, Z. Liu, Z. Li, Z. Xie, Z. Song, Z. Pan, Z. Huang, Z. Xu, Z. Zhang, and Z. Zhang (2025)DeepSeek-r1: incentivizing reasoning capability in llms via reinforcement learning.External Links:2501.12948,LinkCited by:§1.
  • G. Deutch, N. Magar, T. Natan, and G. Dar (2024)In-context learning and gradient descent revisited.InProceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers),K. Duh, H. Gomez, and S. Bethard (Eds.),Mexico City, Mexico,pp. 1017–1028.External Links:Link,DocumentCited by:§5.
  • K. Ethayarajh, D. Duvenaud, and G. Hirst (2019)Towards understanding linear word analogies.InACL,Cited by:§6.
  • H. Furuta, G. Minegishi, Y. Iwasawa, and Y. Matsuo (2024)Towards empirical interpretation of internal circuits and properties in grokked transformers on modular polynomials.Transactions on Machine Learning Research.External Links:ISSN 2835-8856Cited by:§6.
  • Gemma Team (2024)Gemma 2: improving open language models at a practical size.arXiv preprint arXiv:2408.00118.Cited by:§5.
  • D. Gentner, S. Brem, R. Ferguson, and P. Wolff (1997)Analogy and creativity in the works of johannes kepler.Creative thought: An investigation of conceptual structures and processes,pp..External Links:ISBN 1-55798-404-2,DocumentCited by:§1,§6.
  • D. Gentner and C. Hoyos (2017)Analogy and abstraction.Topics in Cognitive Science9(4),pp. 672–693.External Links:DocumentCited by:§1,§6.
  • D. Gentner and A. B. Markman (1997)Structure mapping in analogy and similarity..American psychologist52(1),pp. 45.Cited by:§6.
  • D. Gentner (1983)Structure-mapping: a theoretical framework for analogy.Cognitive Science7(2),pp. 155–170.External Links:ISSN 0364-0213,Document,LinkCited by:§1.
  • M. L. Gick and K. J. Holyoak (1983)Schema induction and analogical transfer.Cognitive Psychology15(1),pp. 1–38.Cited by:§6.
  • A.K. Goel (1997)Design, analogy, and creativity.IEEE Expert12(3),pp. 62–70.External Links:DocumentCited by:§1,§6.
  • Google DeepMind (2025)Note:https://deepmind.google/models/gemini/Accessed: 2026-01-12; state-of-the-art multimodal reasoning and generation model from the Gemini familyCited by:§1.
  • A. Grattafiori, A. Dubey, A. Jauhri, A. Pandey, A. Kadian, A. Al-Dahle, A. Letman, A. Mathur, A. Schelten, A. Vaughan,et al.(2024)The llama 3 herd of models.arXiv preprint arXiv:2407.21783.Cited by:§5.
  • T. He, D. Doshi, A. Das, and A. Gromov (2024)Learning to grok: emergence of in-context learning and skill composition in modular arithmetic tasks.InThe Thirty-eighth Annual Conference on Neural Information Processing Systems,External Links:LinkCited by:§1,§3.1,§6.
  • R. Hendel, M. Geva, and A. Globerson (2023)In-context learning creates task vectors.InFindings of the Association for Computational Linguistics: EMNLP 2023,H. Bouamor, J. Pino, and K. Bali (Eds.),Singapore,pp. 9318–9333.External Links:Link,DocumentCited by:Appendix M.
  • K. J. Holyoak and P. Thagard (1996)Mental leaps: analogy in creative thought.MIT press.Cited by:§1,§6.
  • M. Humphries and K. Gurney (2008)Network ‘small-world-ness’: a quantitative method for determining canonical network equivalence.PloS one3,pp. e0002051.Cited by:Appendix D,§7.
  • T. Johnson, M. ter Veen, R. Choenni, H. van der Maas, E. Shutova, and C. E. Stevenson (2025)Do large language models solve verbal analogies like children do?.InProceedings of the 29th Conference on Computational Natural Language Learning,G. Boleda and M. Roth (Eds.),Vienna, Austria,pp. 627–639.External Links:Link,Document,ISBN 979-8-89176-271-8Cited by:§1.
  • D. P. Kingma (2014)Adam: a method for stochastic optimization.arXiv preprint arXiv:1412.6980.Cited by:§2.2.
  • T. Kojima, S. S. Gu, M. Reid, Y. Matsuo, and Y. Iwasawa (2022)Large language models are zero-shot reasoners.Advances in neural information processing systems35,pp. 22199–22213.Cited by:§1.
  • W. H. Leatherdale (1974)The role of analogy, model, and metaphor in science.American Elsevier Pub. Co.,New York.External Links:LinkCited by:§1,§6.
  • Z. Liu, O. Kitouni, N. Nolte, E. J. Michaud, M. Tegmark, and M. Williams (2022)Towards understanding grokking: an effective theory of representation learning.InAdvances in Neural Information Processing Systems,A. H. Oh, A. Agarwal, D. Belgrave, and K. Cho (Eds.),External Links:LinkCited by:Appendix E,§3.2.
  • Z. Liu, E. J. Michaud, and M. Tegmark (2023)Omnigrok: grokking beyond algorithmic data.InThe Eleventh International Conference on Learning Representations,External Links:LinkCited by:§3.2.
  • V. Mavi, A. Jangra, and A. Jatowt (2024)Multi-hop question answering.Foundations and Trends® in Information Retrieval17(4),pp. 457–586.Cited by:§1.
  • T. Mikolov, I. Sutskever, K. Chen, G. Corrado, and J. Dean (2013a)Distributed representations of words and phrases and their compositionality.InNeurIPS,Cited by:§6.
  • T. Mikolov, W. Yih, and G. Zweig (2013b)Linguistic regularities in continuous space word representations.InProceedings of the 2013 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies,L. Vanderwende, H. Daumé III, and K. Kirchhoff (Eds.),Atlanta, Georgia,pp. 746–751.External Links:LinkCited by:Appendix M.
  • G. Minegishi, H. Furuta, S. Taniguchi, Y. Iwasawa, and Y. Matsuo (2025)Beyond induction heads: in-context meta learning induces multi-phase circuit emergence.InForty-second International Conference on Machine Learning,External Links:LinkCited by:§2.2.
  • V. Nagarajan, C. H. Wu, C. Ding, and A. Raghunathan (2025)Roll the dice & look before you leap: going beyond the creative limits of next-token prediction.InForty-second International Conference on Machine Learning,External Links:LinkCited by:§6.
  • N. Nanda, L. Chan, T. Lieberum, J. Smith, and J. Steinhardt (2023)Progress measures for grokking via mechanistic interpretability.InThe Eleventh International Conference on Learning Representations,External Links:LinkCited by:§4.2.
  • S. Noroozizadeh, V. Nagarajan, E. Rosenfeld, and S. Kumar (2025)Deep sequence models tend to memorize geometrically, we do not understand why..InFirst Workshop on Foundations of Reasoning in Language Models,External Links:LinkCited by:§6.
  • nostalgebraist (2020)Interpreting gpt: the logit lens..Less-Wrong.External Links:LinkCited by:§5.
  • OpenAI, A. Jaech, A. Kalai, A. Lerer, A. Richardson, A. El-Kishky, A. Low, A. Helyar, A. Madry, A. Beutel, A. Carney, A. Iftimie, A. Karpenko, A. T. Passos, A. Neitz, A. Prokofiev, A. Wei, A. Tam, A. Bennett, A. Kumar, A. Saraiva, A. Vallone, A. Duberstein, A. Kondrich, A. Mishchenko, A. Applebaum, A. Jiang, A. Nair, B. Zoph, B. Ghorbani, B. Rossen, B. Sokolowsky, B. Barak, B. McGrew, B. Minaiev, B. Hao, B. Baker, B. Houghton, B. McKinzie, B. Eastman, C. Lugaresi, C. Bassin, C. Hudson, C. M. Li, C. de Bourcy, C. Voss, C. Shen, C. Zhang, C. Koch, C. Orsinger, C. Hesse, C. Fischer, C. Chan, D. Roberts, D. Kappler, D. Levy, D. Selsam, D. Dohan, D. Farhi, D. Mely, D. Robinson, D. Tsipras, D. Li, D. Oprica, E. Freeman, E. Zhang, E. Wong, E. Proehl, E. Cheung, E. Mitchell, E. Wallace, E. Ritter, E. Mays, F. Wang, F. P. Such, F. Raso, F. Leoni, F. Tsimpourlas, F. Song, F. von Lohmann, F. Sulit, G. Salmon, G. Parascandolo, G. Chabot, G. Zhao, G. Brockman, G. Leclerc, H. Salman, H. Bao, H. Sheng, H. Andrin, H. Bagherinezhad, H. Ren, H. Lightman, H. W. Chung, I. Kivlichan, I. O’Connell, I. Osband, I. C. Gilaberte, I. Akkaya, I. Kostrikov, I. Sutskever, I. Kofman, J. Pachocki, J. Lennon, J. Wei, J. Harb, J. Twore, J. Feng, J. Yu, J. Weng, J. Tang, J. Yu, J. Q. Candela, J. Palermo, J. Parish, J. Heidecke, J. Hallman, J. Rizzo, J. Gordon, J. Uesato, J. Ward, J. Huizinga, J. Wang, K. Chen, K. Xiao, K. Singhal, K. Nguyen, K. Cobbe, K. Shi, K. Wood, K. Rimbach, K. Gu-Lemberg, K. Liu, K. Lu, K. Stone, K. Yu, L. Ahmad, L. Yang, L. Liu, L. Maksin, L. Ho, L. Fedus, L. Weng, L. Li, L. McCallum, L. Held, L. Kuhn, L. Kondraciuk, L. Kaiser, L. Metz, M. Boyd, M. Trebacz, M. Joglekar, M. Chen, M. Tintor, M. Meyer, M. Jones, M. Kaufer, M. Schwarzer, M. Shah, M. Yatbaz, M. Y. Guan, M. Xu, M. Yan, M. Glaese, M. Chen, M. Lampe, M. Malek, M. Wang, M. Fradin, M. McClay, M. Pavlov, M. Wang, M. Wang, M. Murati, M. Bavarian, M. Rohaninejad, N. McAleese, N. Chowdhury, N. Chowdhury, N. Ryder, N. Tezak, N. Brown, O. Nachum, O. Boiko, O. Murk, O. Watkins, P. Chao, P. Ashbourne, P. Izmailov, P. Zhokhov, R. Dias, R. Arora, R. Lin, R. G. Lopes, R. Gaon, R. Miyara, R. Leike, R. Hwang, R. Garg, R. Brown, R. James, R. Shu, R. Cheu, R. Greene, S. Jain, S. Altman, S. Toizer, S. Toyer, S. Miserendino, S. Agarwal, S. Hernandez, S. Baker, S. McKinney, S. Yan, S. Zhao, S. Hu, S. Santurkar, S. R. Chaudhuri, S. Zhang, S. Fu, S. Papay, S. Lin, S. Balaji, S. Sanjeev, S. Sidor, T. Broda, A. Clark, T. Wang, T. Gordon, T. Sanders, T. Patwardhan, T. Sottiaux, T. Degry, T. Dimson, T. Zheng, T. Garipov, T. Stasi, T. Bansal, T. Creech, T. Peterson, T. Eloundou, V. Qi, V. Kosaraju, V. Monaco, V. Pong, V. Fomenko, W. Zheng, W. Zhou, W. McCabe, W. Zaremba, Y. Dubois, Y. Lu, Y. Chen, Y. Cha, Y. Bai, Y. He, Y. Zhang, Y. Wang, Z. Shao, and Z. Li (2024)OpenAI o1 system card.External Links:2412.16720,LinkCited by:§1.
  • C. F. Park, A. Lee, E. S. Lubana, Y. Yang, M. Okawa, K. Nishi, M. Wattenberg, and H. Tanaka (2025)ICLR: in-context learning of representations.InThe Thirteenth International Conference on Learning Representations,External Links:LinkCited by:Appendix G,§4.1.
  • C. F. Park, E. S. Lubana, and H. Tanaka (2024)Understanding the transient nature of in-context learning: the window of generalization.InNeurIPS 2024 Workshop on Scientific Methods for Understanding Deep Learning,External Links:LinkCited by:Appendix C,§3.1.
  • K. Park, Y. J. Choe, and V. Veitch (2023)The linear representation hypothesis and the geometry of large language models.arXiv preprint arXiv:2311.03658.Cited by:Appendix M.
  • J. Pennington, R. Socher, and C. Manning (2014)GloVe: global vectors for word representation.InEMNLP,Cited by:Appendix M,§6.
  • J. Petty, S. Steenkiste, I. Dasgupta, F. Sha, D. Garrette, and T. Linzen (2024)The impact of depth on compositional generalization in transformer language models.InProceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers),K. Duh, H. Gomez, and S. Bethard (Eds.),Mexico City, Mexico,pp. 7239–7252.External Links:Link,DocumentCited by:§1.
  • A. Power, Y. Burda, H. Edwards, I. Babuschkin, and V. Misra (2022)Grokking: generalization beyond overfitting on small algorithmic datasets.External Links:2201.02177,LinkCited by:§3.2.
  • T. Qin, C. F. Park, M. Kwun, A. Walsman, E. Malach, N. Anand, H. Tanaka, and D. Alvarez-Melis (2025)Decomposing elements of problem solving: what” math” does rl teach?.arXiv preprint arXiv:2505.22756.Cited by:§6.
  • A. Radford, J. Wu, R. Child, D. Luan, D. Amodei, I. Sutskever,et al.(2019)Language models are unsupervised multitask learners.OpenAI blog1(8),pp. 9.Cited by:§A.1.
  • G. Reddy (2024)The mechanistic basis of data dependence and abrupt learning in an in-context classification task.InThe Twelfth International Co nference on Learning Representations,External Links:LinkCited by:§2.2,§6.
  • F. Redhardt, Y. Akram, and S. Schug (2025)Scaling can lead to compositional generalization.InThe Thirty-ninth Annual Conference on Neural Information Processing Systems,External Links:LinkCited by:§1,§3.1,§3.3,§6.
  • S. Schug, S. Kobayashi, Y. Akram, J. Sacramento, and R. Pascanu (2025)Attention as a hypernetwork.InThe Thirteenth International Conference on Learning Representations,External Links:LinkCited by:§1.
  • L. Sharkey, B. Chughtai, J. Batson, J. Lindsey, J. Wu, L. Bushnaq, N. Goldowsky-Dill, S. Heimersheim, A. Ortega, J. I. Bloom, S. Biderman, A. Garriga-Alonso, A. Conmy, N. Nanda, J. M. Rumbelow, M. Wattenberg, N. Schoots, J. Miller, W. Saunders, E. J. Michaud, S. Casper, M. Tegmark, D. Bau, E. Todd, A. Geiger, M. Geva, J. Hoogland, D. Murfet, and T. McGrath (2025)Open problems in mechanistic interpretability.Transactions on Machine Learning Research.Note:Survey CertificationExternal Links:ISSN 2835-8856,LinkCited by:§5.
  • A. K. Singh, T. Moskovitz, S. Dragutinović, F. Hill, S. C.Y. Chan, and A. M. Saxe (2025)Strategy coopetition explains the emergence and transience of in-context learning.InForty-second International Conference on Machine Learning,External Links:LinkCited by:Appendix C,§3.1.
  • J. Su, M. Ahmed, Y. Lu, S. Pan, W. Bo, and Y. Liu (2024)Roformer: enhanced transformer with rotary position embedding.Neurocomputing568,pp. 127063.Cited by:§A.1.
  • P. Thagard (1992)Analogy, explanation, and education.Journal of Research in Science Teaching29(6),pp. 537–544.External Links:DocumentCited by:§1,§6.
  • P. D. Turney, M. L. Littman, J. Bigham, and V. Shnayder (2003)Combining independent modules in lexical multiple-choice problems.InRecent Advances in Natural Language Processing III,Cited by:§6.
  • A. Ushio, L. Espinosa-Anke, S. Schockaert, and J. Camacho-Collados (2021)BERT is to nlp what alexnet is to cv: can pre-trained language models identify analogies?.InACL,Cited by:§6.
  • A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin (2017)Attention is all you need.InAdvances in Neural Information Processing Systems,I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett (Eds.),Vol.30,pp..External Links:LinkCited by:§6.
  • J. Von Oswald, E. Niklasson, E. Randazzo, J. Sacramento, A. Mordvintsev, A. Zhmoginov, and M. Vladymyrov (2023)Transformers learn in-context by gradient descent.InInternational Conference on Machine Learning,pp. 35151–35174.Cited by:§5.
  • B. Wang, X. Yue, Y. Su, and H. Sun (2024)Grokking of implicit reasoning in transformers: a mechanistic journey to the edge of generalization.InThe Thirty-eighth Annual Conference on Neural Information Processing Systems,External Links:LinkCited by:§1,§6.
  • K. R. Wang, A. Variengien, A. Conmy, B. Shlegeris, and J. Steinhardt (2023)Interpretability in the wild: a circuit for indirect object identification in GPT-2 small.InThe Eleventh International Conference on Learning Representations,External Links:LinkCited by:§7.
  • A. Warstadt, A. Mueller, L. Choshen, E. Wilcox, C. Zhuang, J. Ciro, R. Mosquera, B. Paranjabe, A. Williams, T. Linzen, and R. Cotterell (2023)Findings of the BabyLM challenge: sample-efficient pretraining on developmentally plausible corpora.InProceedings of the BabyLM Challenge at the 27th Conference on Computational Natural Language Learning,A. Warstadt, A. Mueller, L. Choshen, E. Wilcox, C. Zhuang, J. Ciro, R. Mosquera, B. Paranjabe, A. Williams, T. Linzen, and R. Cotterell (Eds.),Singapore,pp. 1–34.External Links:Link,DocumentCited by:§6.
  • J. Wei, X. Wang, D. Schuurmans, M. Bosma, F. Xia, E. Chi, Q. V. Le, D. Zhou,et al.(2022)Chain-of-thought prompting elicits reasoning in large language models.Advances in neural information processing systems35,pp. 24824–24837.Cited by:§1.
  • V. M. Winkler (1981)Analogical acts as conceptual strategies in science, engineering and the humanities.Technical Communication, Part 2Technical Report19820008124,NASA Langley Research Center.External Links:LinkCited by:§6.
  • D. Wurgaft, C. Rager, M. Kowal, V. Shyam, S. Feucht, U. Bhalla, T. Haklay, E. Bigelow, R. Sarfati, T. McGrath, O. Lewis, J. Merullo, N. Goodman, T. Fel, A. Geiger, and E. S. Lubana (2026)Manifold steering reveals the shared geometry of neural network representation and behavior.External Links:2605.05115,LinkCited by:§7.
  • Z. Yang, P. Qi, S. Zhang, Y. Bengio, W. Cohen, R. Salakhutdinov, and C. D. Manning (2018)HotpotQA: a dataset for diverse, explainable multi-hop question answering.InProceedings of the 2018 conference on empirical methods in natural language processing,pp. 2369–2380.Cited by:§1.
  • M. Yasunaga, X. Chen, Y. Li, P. Pasupat, J. Leskovec, P. Liang, E. H. Chi, and D. Zhou (2024)Large language models as analogical reasoners.InThe Twelfth International Conference on Learning Representations,External Links:LinkCited by:§1.
  • X. e. al. Ye (2024)ANALOBENCH: benchmarking the identification of abstract and long-context analogies.InEMNLP,Cited by:§1,§6.
  • C. Zhang, G. Neubig, and X. Yue (2025)On the interplay of pre-training, mid-training, and rl on reasoning language models.arXiv preprint arXiv:2512.07783.Cited by:§6.
  • H. Zhang, Z. Zhang, M. Wang, Z. Su, Y. Wang, Q. Wang, S. Yuan, E. Nie, X. Duan, Q. Xue,et al.(2026)Locate, steer, and improve: a practical survey of actionable mechanistic interpretability in large language models.arXiv preprint arXiv:2601.14004.Cited by:§5.
  • C. Zhao, Z. Tan, P. Ma, D. Li, B. Jiang, Y. Wang, Y. Yang, and huan liu (2025)Is chain-of-thought reasoning of LLMs a mirage? a data distribution lens.InFirst Workshop on Foundations of Reasoning in Language Models,External Links:LinkCited by:§6.

Appendix AExperiment Details

This appendix provides implementation details for the models and training procedures used in our synthetic experiments. All experiments were conducted on a single NVIDIA A100 GPU.

A.1Model Architecture

We use a lightweight causal Transformer model, similar to GPT-2(Radfordet al.,2019), augmented with Rotary Position Embeddings (RoPE)(Suet al.,2024), which is widely adopted in recent Transformer architectures. Unless otherwise specified, all experiments use the same architecture, summarized inTable 2.

Table 2:Transformer architecture used in synthetic experiments (GPT-2-like with RoPE).

A.2Optimization and Training

Models are trained using the Adam optimizer with standard hyperparameters. We apply a linear learning-rate warmup followed by a constant schedule. All default training hyperparameters are listed inTable 3.

Table 3:Training hyperparameters (default settings).

Appendix BLearning-rate sweeps for deeper models

In our main scaling experiments (Section3.3), we used a fixed learning rate across model sizes. To test whether the observed underperformance of deeper models reflects an architectural limitation or suboptimal optimization settings, we perform a learning-rate sweep for deeper models.Figure 11shows that with appropriate learning-rate choices, deeper models can achieve high analogical reasoning accuracy. This supports the interpretation that the depth effect is optimization-dependent, and further underscores the sensitivity of analogical reasoning to training hyperparameters.

Refer to captionFigure 11:Learning-rate sweep for deeper models in the analogical reasoning task. With appropriate learning-rate choices, deeper models can achieve strong analogical reasoning performance, indicating that depth-related underperformance under default settings can be an optimization artifact.

Appendix CTransient Natures of Analogical Reasoning

Atransient nature(Parket al.,2024; Singhet al.,2025)has been reported in in-context learning (ICL), where a capability that is once acquired can later be lost as training progresses. We observe a closely related phenomenon for analogical reasoning.Figure 12shows the evolution of our internal mechanistic signals (Section4) for the setting with|ℛ|=1,000|\mathcal{R}|=1,000relations, corresponding to the experiment described inSection3.1. Although the model acquires analogical reasoning, theprobabilityof predicting the correct target entity gradually decreases as training continues. Concurrently, theDirichlet Energyincreases, indicating a loss of geometric alignment in the embedding space. This suggests that the relational structure underlying analogical reasoning is no longer preserved. A similar phenomenon has been reported in prior work on in-context learning(Singhet al.,2025), which argues that circuits responsible for ICL can temporarily emerge during training, but later coexist and compete with alternative circuits (e.g., ICWL), eventually being suppressed as training continues. Consistent with this view, our results indicate that the structured embedding geometry supporting analogical reasoning can be transient: once the model begins to overly fit the training data, the previously acquired geometric alignment is disrupted. Notably, this behavior cannot be attributed to explicit regularization effects, as weight decay is set to zero in these experiments. Instead, our findings suggest that aggressive optimization toward training data fit can destabilize the geometric structures necessary for analogical reasoning, leading to its eventual degradation.

Refer to caption(a) Refer to caption(b) Refer to caption(c)

Figure 12:Mechanistic signalsunderlying the emergence of analogical reasoning, where is measured by the model’sprobabilityof the correct target entity (et)e_{t}).(a) Dirichlet Energydecreases during training, indicating increasing structural alignment in the embedding space.(b) Attention Scorefrom the functor tokenffto the source entityese_{s}increase as analogical reasoning emerges, reflecting attention-based information retrieval.(c) Parallelism, defined by the similarity between(et−es)(e_{t}-e_{s})andff, increases concurrently, indicating that the model realizes analogical reasoning by adding the functor representationffto the source entity embeddingese_{s}via a residual connection.

Appendix DEffect of Graph Sparsity on Reasoning

In the main text, we assume that the relational graph within each category is complete, i.e., every pair of entities is connected by a relation. However, in real-world data, not all entity pairs are necessarily related. Many real-world relational structures are known to be sparse and often exhibit small-world properties, with dense local connectivity but missing edges globally(Humphries and Gurney,2008).Figure 13-(a) illustrates a comparison between a complete graph and a non-complete (sparse) graph. To study the effect of graph completeness, we analyze how the sparsity of the relational graph influences compositional and analogical reasoning. Specifically, we remove a fraction of atomic facts from the training data, where each atomic fact corresponds to a triple(es,r,et)(e_{s},r,e_{t}). This removal effectively increases the sparsity of the underlying relational graph.

Figure 13-(b) shows the compositional and analogical reasoning performance as a function of the removed atomic fact ratio. We observe that compositional reasoning remains robust even under substantial sparsity. In contrast, analogical reasoning fails to emerge as the graph becomes increasingly sparse, suggesting that analogical reasoning critically relies on sufficiently dense relational structure.

Refer to caption(a) Refer to caption(b)

Figure 13:Effect of graph sparsity on compositional and analogical reasoning. (a) Comparison between a complete relational graph and a non-complete (sparse) graph. (b) Composition reasoning and analogical reasoning performance, which controls the sparsity of the relational graph. While compositional reasoning remains robust to sparsity, analogical reasoning degrades and eventually fails as the graph becomes increasingly sparse.

Appendix EEffect of Learning Rate

We investigate the effect of the learning rate on the acquisition of compositional and analogical reasoning. As shown inFigure 14, when the learning rate is set too high, the model fails to reliably acquire analogical reasoning, and even compositional reasoning becomes difficult to learn. In contrast, smaller learning rates allow the model to first fit the training data and subsequently exhibit generalization behavior. This observation is consistent with prior findings in the grokking literature, which show that excessively large learning rates can prevent the emergence of generalization phenomena(Liuet al.,2022). Our results suggest that the emergence of analogical reasoning is similarly sensitive to optimization dynamics, and can be hindered by overly aggressive learning rates.

Refer to captionFigure 14:Effect of learning rate on out-of-distribution (OOD) performance. Large learning rates hinder the acquisition of both compositional and analogical reasoning, while smaller learning rates enable gradual generalization.

Appendix FDynamics of PCA visualizations

We provide a qualitative visualization of how entity embeddings evolve during training. We apply Principal Component Analysis (PCA) to the embedding vectors at different training epochs and project them onto a two-dimensional space. This allows us to track the temporal dynamics of representation geometry throughout optimization.

As shown inFigure 15, embeddings at early training stages exhibit little discernible structure and largely overlap in the projected space. As training proceeds, a more coherent geometric organization gradually emerges, with entities becoming arranged according to their underlying relational roles. This observation suggests that structural organization in the embedding space is not present a priori, but is progressively formed through learning.

Refer to captionFigure 15:Dynamics of PCA visualizations of entity embeddings throughout training. Each panel shows the projection of embeddings at a different training epoch. In early stages, embeddings are largely unstructured and overlapping. As training progresses, coherent geometric structure gradually emerges, with entities organizing according to their underlying relational roles. This illustrates that structural alignment in representation space is not present initially but forms progressively during optimization.

Appendix GDerivation of Multi-dimensional Dirichlet Energy

Following(Parket al.,2025), we provide a detailed derivation of the Dirichlet energy for multi-dimensional node representations, which is used throughout our analysis to quantify structural alignment in representation space.

Scalar-valued signal.

Let𝒢=(𝒱,ℰ)\mathcal{G}=(\mathcal{V},\mathcal{E})be an undirected graph withn=|𝒱|n=|\mathcal{V}|nodes. Let𝑨∈ℝn×n\boldsymbol{A}\in\mathbb{R}^{n\times n}denote its (possibly weighted) adjacency matrix, and let𝒙∈ℝn\boldsymbol{x}\in\mathbb{R}^{n}be a scalar signal defined on the nodes, where𝒙i\boldsymbol{x}_{i}denotes the value associated with nodeii. The Dirichlet energy of𝒙\boldsymbol{x}on graph𝒢\mathcal{G}is defined as

E𝒢​(𝒙)=∑i,j𝑨i,j​(𝒙i−𝒙j)2.E_{\mathcal{G}}(\boldsymbol{x})=\sum_{i,j}\boldsymbol{A}_{i,j}(\boldsymbol{x}_{i}-\boldsymbol{x}_{j})^{2}.(4)This quantity measures the smoothness of the signal with respect to the graph structure: neighboring nodes incur a high energy penalty if their assigned values differ significantly.

Multi-dimensional signal.

We now extend this definition to the case of multi-dimensional node representations. Let𝑿∈ℝn×d\boldsymbol{X}\in\mathbb{R}^{n\times d}be a matrix of node embeddings, where each nodeiiis associated with a vector𝒙i∈ℝd\boldsymbol{x}_{i}\in\mathbb{R}^{d}, and𝒙i,k\boldsymbol{x}_{i,k}denotes itskk-th component. A natural extension of the Dirichlet energy is obtained by summing the scalar Dirichlet energy over each dimension:

E𝒢​(𝑿)=∑k=1d∑i,j𝑨i,j​(𝒙i,k−𝒙j,k)2.E_{\mathcal{G}}(\boldsymbol{X})=\sum_{k=1}^{d}\sum_{i,j}\boldsymbol{A}_{i,j}(\boldsymbol{x}_{i,k}-\boldsymbol{x}_{j,k})^{2}.(5) Rearranging the summation, this can be written equivalently as

E𝒢​(X)\displaystyle E_{\mathcal{G}}(X)=∑i,j𝑨i,j​∑k=1d(𝒙i,k−𝒙j,k)2\displaystyle=\sum_{i,j}\boldsymbol{A}_{i,j}\sum_{k=1}^{d}(\boldsymbol{x}_{i,k}-\boldsymbol{x}_{j,k})^{2}(6)=∑i,j𝑨i,j​∥𝒙i−𝒙j∥22,\displaystyle=\sum_{i,j}\boldsymbol{A}_{i,j}\lVert\boldsymbol{x}_{i}-\boldsymbol{x}_{j}\rVert_{2}^{2},(7)where∥⋅∥2\lVert\cdot\rVert_{2}denotes the Euclidean norm. Thus, the multi-dimensional Dirichlet energy penalizes large pairwise distances between representations of adjacent nodes in the graph.

Appendix HEmbedding Structure under Model Scaling

Figure 16visualizes the entity embedding structure after training for models with different depths. While a 1-layer Transformer exhibits clear geometric alignment between the two categories, this alignment is largely absent in the 4-layer model.

This observation supports the view that analogical reasoning is not primarily determined by model capacity, but rather by whether the model discovers the aligned geometric structure in the embedding space. Moreover, increasing the number of parameters expands the space of solutions that fit the training data, and can promote memorization or locally sufficient strategies that do not enforce such global alignment. As a result, larger or deeper models may achieve low training loss without forming the structured representations required for analogy.

We emphasize that this effect depends on the optimization setting and data regime used in our experiments. Different regularization schemes or training objectives may bias larger models toward more geometrically aligned solutions. Nevertheless, under our setup, increased model capacity alone does not reliably induce the embedding structure necessary for analogical reasoning.

Refer to caption(a) Refer to caption(b)

Figure 16:PCA Visualization of entity embeddings after (10310^{3}step) the acquisition of analogical reasoning. Entity embeddings from categoryℰ1\mathcal{E}_{1}(blue)andℰ2\mathcal{E}_{2}(red)are shown, with arrows indicating the functor.(a) 1-Layer Transformer, embeddings from the two categories are structurally aligned.(b) 4-Layer Transformer, embeddings from the two categories are not structurally aligned.

Appendix IOutput Probability under the Alternative Prompt Designs

In this section, we report how different prompt designs affect the next-token prediction probabilities ofGemma2-2B. Specifically, we show the top-5 output probabilities for the next token under several prompt variants below.

Prompt 1

corresponds to the prompt used throughout our main experiments (seeFigure 8). The correct answer for this prompt is token 7, and the model assigns a high probability to this token.

Prompt 1 (Target entity is<e7>)<e1>a<e2>, <e1>b<e3>. <e6>a<e4>, <e6>b<e7>. <e1><e6>, <e3><e

Prompt 2

is a naive variant that uses the categories Category 1 ({e1,e2,e3}\{e_{1},e_{2},e_{3}\}) and Category 2 ({e4,e5,e6}\{e_{4},e_{5},e_{6}\}). The correct answer in this case is token 6, and the model predicts this token with high probability. However, this prompt introduces an explicit arithmetic correspondence between Category 1 ({e1,e2,e3}\{e_{1},e_{2},e_{3}\}) and Category 2 ({e4,e5,e6}\{e_{4},e_{5},e_{6}\}), which can be interpreted as a fixed “+3+3” mapping. As a result, the task can be solved without genuine analogical reasoning. For this reason, we do not use this prompt in our main experiments.

Prompt 2 (Target entity is<e6>)<e1>a<e2>, <e1>b<e3>. <e4>a<e5>, <e4>b<e6>. <e1><e4>, <e3><e

Prompt 3

follows the same structural pattern as Prompt 1 and uses exactly the same tokenization scheme as our synthetic taskTable 1, but the model fails to reliably predict the correct answer (token 7). We hypothesize that this failure is due to unintended priors introduced during pretraining. In particular, the symbolsee,rr, andffmay carry semantic or syntactic biases from pretraining that interfere with analogical reasoning. Moreover, tokens such as<r12>are split into multiple sub-tokens (e.g.,<,r,1,2,>), which may make it more difficult for the model to capture the intended relational structure.

Prompt 3 (Target entity is<e7>)<e1><r12><e2>, <e1><r23><e3>. <e6><r12><e4>, <e6><r23><e7>. <e1><f><e6>, <e3><f><e

Prompt 4

is a simplified variant of Prompt 1 in which special markers such as<andeare removed. Under this prompt, the model fails to produce the correct answer. This suggests that explicit entity markers (<,>) play an important role in helping the model recognize and track entities, and their removal significantly degrades performance.

Prompt 4 (Target entity is7)1a2, 1b3. 6a4, 6b7. 1~6, 3~

Prompt 1

Prompt 2

Prompt 3

Prompt 4

Figure 17:Output probability under several prompt variants.The colored rowdenotes the correct answer.

Appendix JImpact of the Number of Entities

We analyze how the number of entities affects analogical reasoning in LLMs, and its relationship with Dirichlet Energy. Example prompts used in this analysis are shown below.

Number of Entities is 4 (Target is<e8>)<e1>a<e2>, <e1>b<e3>, <e1>c<e4>. <e6>a<e5>, <e6>b<e7>, <e6>c<e8>. <e1><e6>, <e2><e5>, <e3><e7>, <e4><e

Number of Entities is 5 (Target is<e10>)<e1>a<e2>, <e1>b<e3>, <e1>c<e4>, <e1>d<e5>. <e7>a<e6>, <e7>b<e8>, <e7>c<e9>, <e7>d<e10>. <e1><e7>, <e2><e6>, <e3><e8>, <e4><e9>, <e5>~<e

Number of Entities is 7 (Target is<e14>)<e1>a<e2>, <e1>b<e3>, <e1>c<e4>, <e1>d<e5>, <e1>e<e6>, <e1>f<e7>. <e9>a<e8>, <e9>b<e10>, <e9>c<e11>, <e9>d<e12>, <e9>e<e13>, <e9>f<e14>. <e1><e9>, <e2><e8>, <e3><e10>, <e4><e11>, <e5><e12>, <e6><e13>, <e7>~<e

As shown inFigure 18, the relationship between analogical reasoning performance and the decrease of Dirichlet Energy is consistently observed across all prompts. Notably, as the number of entities increases, the layer at which analogical reasoning performance peaks shifts toward later layers. This trend is consistent with our findings in the toy taskSection3.1, and suggests that more complex analogical problems require deeper computation to align relational structure.

Refer to captionFigure 18:Effect of the number of entities on analogical reasoning in LLMs. Across different entity counts, analogical reasoning performance exhibits a consistent relationship with Dirichlet energy. As the number of entities increases, the emergence of analogical reasoning shifts toward later layers, indicating increased computational depth.

Appendix KDirichlet Energy in Llama

We observe the same qualitative relationship between analogical reasoning performance and Dirichlet Energy in LLaMA. As shown inFigure 19, increasing the number of entities leads to similar layer-wise trends as in other LLMs, indicating that the geometric mechanism underlying analogical reasoning generalizes across model families.

Refer to captionFigure 19:Relationship between analogical reasoning performance and Dirichlet energy in LLaMA across different numbers of entities. The same qualitative trends observed in other LLMs persist, indicating that the underlying geometric mechanism is not model-specific.

Appendix LPCA of LLM Hidden States in All Layers

We analyze the internal representations of pretrained large language models (LLMs) when they are prompted to perform analogical reasoning. Specifically, we apply PCA to the hidden states at each Transformer layer and visualize how the geometry of entity representations evolves across depth.

As shown inFigure 20, representations in earlier layers exhibit limited geometric organization across categories. However, as depth increases, entities belonging to corresponding categories become progressively aligned in the representation space. In later layers, this alignment becomes particularly pronounced, indicating that analogical structure is increasingly encoded as the model approaches the output layers.

Refer to captionFigure 20:PCA visualizations of LLM hidden states across Transformer layers when prompted with an analogical reasoning task. As depth increases, entity representations from corresponding categories become geometrically aligned, indicating the progressive emergence of analogical structure in later layers.

Appendix MMore Discussions

Linear Representation Hypothesis.

In the context of language models, it has long been argued that high-level semantic concepts are represented linearly in the embedding space, a view commonly referred to as theLinear Representation Hypothesis(Mikolovet al.,2013b; Penningtonet al.,2014; Parket al.,2023). A canonical example is the observation that vector differences such aswoman−man≈queen−king\texttt{woman}-\texttt{man}\approx\texttt{queen}-\texttt{king}capture semantic relations through linear offsets. Beyond lexical relations, prior work has suggested that more abstract transformations, such as mappings between languages (e.g.,English→\rightarrowFrench), may also be encoded as approximately linear directions in representation space(Parket al.,2023). This perspective aligns with the mechanism we describe inSection4, where such linear transformations can be interpreted as functorial mappings that enable conceptual leaps across categories. Previous studies have also shown that such subspace structures can be acquired along the depth of a Transformer through in-context learning(Hendelet al.,2023; Choet al.,2025). These works do not explicitly connect linear representations to analogical reasoning. In particular, it remains unclear how models learn to identify entities that play the same relational role across distinct domains, a core requirement for analogy. Our work bridges this gap by explicitly linking linear structure in representation space to analogical reasoning: we show that analogy emerges when functor-like transformations become geometrically aligned across categories, enabling the model to infer correspondences between role-equivalent entities in different domains.

A Category-Theoretic Perspective

In category theory(Awodey,2010), a category consists ofobjectsandarrows(or morphisms) between them. A key insight of category theory is that neither objects nor arrows possess intrinsic meaning; they are abstract symbols defined purely by their relationships to one another. This perspective closely mirrors the learning setting of language models. A language model operates on sequences of token IDs and is trained to predict the next token. It has no access to the intrinsic semantics of tokens, and instead learns entirely from the relationships among symbols. In this sense, meaning emerges from relational structure rather than being predefined.

In our task, analogical reasoning corresponds to identifying similarities between relational structures that emerge from such interactions. Thefunctorin our formulation captures this notion: it represents a mapping between relational structures, rather than between individual symbols themselves.

Appendix NE-KAR: Dirichlet energy and answer probability across layers

To test whether the geometric alignment signature extends beyond our synthetic task, we analyze Gemma-2-9B on the E-KAR natural-language analogy benchmark(Chen,2022). E-KAR is a multiple-choice analogy dataset (868 examples) where each question asks the model to identify a candidate pair that shares the same relation as a given source pair.

Setup.

For each question, we consider the hidden states at the entity-pair positions used to represent the source relation and each candidate relation. We compute the Dirichlet energy between the source and the correct candidate pair across layers, and track the model’s probability assigned to the correct option using logit-lens decoding.

Result.

As shown inFigure 21, Dirichlet energy decreases across depth, and this decrease is followed by an increase inp​(target)p(\text{target})in later layers. This mirrors the synthetic-task observation that geometric alignment (lower energy) co-occurs with improved analogical prediction.

Refer to captionFigure 21:Gemma-2-9B: Dirichlet energy andp​(target)p(\text{target})across layers on E-KAR(Chen,2022).

Appendix OImperfect isomorphism: functor noise-ratio ablation

Our main synthetic setup assumes perfectly isomorphic relational structure across categories. To relax this assumption, we introduce anoise ratiowhen transferring edges across categories via the functor. For a fraction of transferred edges, we randomly replace the original relation label with another relation sampled fromℛ\mathcal{R}, thereby breaking exact structural correspondence.

Result.

Figure 22shows that analogical reasoning degrades consistently as the noise ratio increases. This provides a controlled demonstration that analogical generalization becomes harder under partial/noisy cross-domain correspondence.

Refer to captionFigure 22:OOD analogical reasoning accuracy under imperfect isomorphism (functor noise ratio).

Appendix PMultiple functors/categories

A potential concern is that our main experiments involve a single functor token and a single cross-category mapping. To test whether the phenomenon persists with multiple mappings, we extend the setup to multiple categories with multiple functor tokens.

Setup.

We fix the total number of entities to 100 and vary the number of categories: 2 categories (50×\times2; the main-text setting), 4 categories (25×\times4), and 5 categories (20×\times5). For each non-base category, we introduce a distinct functor token (e.g.,f1f_{1},f2f_{2},f3f_{3}) mapping from the base category to the target category (schematic inFigure 23, left).

Result.

As shown inFigure 23(right), analogical reasoning consistently emerges across all settings. Notably, emergence is fastest in the 5-category case, which we attribute to the smaller number of entities per category (consistent with the entity-count trends inSection3.1).

Refer to caption

Refer to caption

Figure 23:Multiple-functor setting: schematic (left) and OOD analogical reasoning accuracy by number of categories (right).

Appendix QImplicit functor variant (no explicit functor token)

Real-world analogies rarely come with an explicit mapping cue. To test whether analogical reasoning can emerge without an explicit functor token, we consider a variant in which the model receives only entity-relation facts, and the mapping signal is implicit.

Setup.

We compare our original formulation (explicit functor query) against a no-functor formulation in which the query providesnofunctor token and instead specifies two partial tuples of entities, one from the source category and one from the target category. Concretely, the input has the form<e1><e2><e3><e6><e7>(and the model is trained/evaluated to predict the next token<e8>). Intuitively, the model must infer the latent correspondence from relational roles (i.e., the fact that<e1>,<e2>,<e3>and<e6>,<e7>,<e8>should form structurally matching tuples) without being given an explicit mapping cue.

Result.

Figure 24shows that analogical reasoning can still emerge in the implicit setting, although it is more challenging and tends to saturate at a lower accuracy.

Refer to captionFigure 24:OOD analogical reasoning accuracy with and without an explicit functor token.

Appendix RLogit lens vs. linear probe

Logit lens is a convenient tool to track intermediate “beliefs,” but it can underestimate information encoded in early-layer representations due to mismatch with the final unembedding. To address this, we compare logit-lens decoding with a learned linear probe.

Setup.

Using Gemma-2-9B, we train a linear classifier on per-layer hidden states to predict the correct target option for the analogy questions. We then track the probe’s probability for the correct answer across layers, alongside Dirichlet energy.

Result.

As shown inFigure 25, both readouts improve as Dirichlet energy decreases, with the linear probe typically rising earlier than logit lens. This supports the interpretation that the layer-wise reduction in Dirichlet energy reflects increasingly linearly decodable analogical structure.

Refer to captionFigure 25:Gemma-2-9B: Dirichlet energy with logit-lens and linear-probe probabilities across layers.

Appendix SDirichlet energy and embedding norm during training

Dirichlet energy depends on representation distances. In cross-entropy training, embedding norms can continue to grow even after loss/accuracy saturates, which can cause energy to increase slightly despite stable task performance.Figure 26illustrates this behavior by jointly plotting energy and the embeddingℓ2\ell_{2}norm over training steps.

Refer to captionFigure 26:Dirichlet energy and embedding norm over training steps.

Appendix TBilinear probe analysis: functor direction and relational interaction

While our main mechanistic claim emphasizes an additive functor direction, alternative relational parameterizations are possible. Following a bilinear view of relations, we train a bilinear probe that predicts whether a pair of entities(ei,ej)(e_{i},e_{j})is in a specific relation by a scoreei⊤​W​eje_{i}^{\top}We_{j}.

Setup.

We train the bilinear probe on the learned entity embeddings and achieve 81.1% accuracy. We then quantify the interaction between the learned relation matrixWWand the functor directionffby tracking a “null-space ratio” during training.

Result.

As shown inFigure 27, the null-space ratio decreases over training (from 0.624 to 0.108), suggesting thatffbecomes a direction with minimal relational interaction under the bilinear formulation. This provides complementary geometric evidence consistent with the functor-direction interpretation.

Refer to captionFigure 27:Null-space ratio during training (bilinear probe analysis).

Similar Articles

Learning to reason with LLMs

OpenAI Blog

OpenAI publishes an article exploring reasoning techniques with LLMs through cipher-decoding examples, demonstrating step-by-step problem-solving approaches and pattern recognition in language models.