Does learning the right latent variables necessarily improve in-context learning?

## Abstract

Abstract Large autoregressive models like Transformers can solve tasks through in-context learning (ICL) without learning new weights, suggesting avenues for efficiently solving new tasks. For many tasks, e.g., linear regression, the data factorizes: examples are independent given a task latent that generates the data, e.g., linear coefficients. While an optimal predictor leverages this factorization by inferring task latents, it is unclear if Transformers implicitly do so or if they instead exploit heuristics and statistical shortcuts enabled by attention layers. Both scenarios have inspired active ongoing work. In this paper, we systematically investigate the effect of explicitly inferring task latents. We minimally modify the Transformer architecture with a bottleneck designed to prevent shortcuts in favor of more structured solutions, and then compare performance against standard Transformers across various ICL tasks. Contrary to intuition and some recent works, we find little discernible difference between the two; biasing towards task-relevant latent variables does not lead to better out-of-distribution performance, in general. Curiously, we find that while the bottleneck effectively learns to extract latent task variables from context, downstream processing struggles to utilize them for robust prediction. Our study highlights the intrinsic limitations of Transformers in achieving structured ICL solutions that generalize, and shows that while inferring the right latents aids interpretability, it is not sufficient to alleviate this problem. † † ∗ Equal Contribution. † † † Equal Supervision. † † Correspondence to sarthmit@gmail.com , eric.elmoznino@gmail.com and leogagnon@gmail.com 1 1 1 All code related to our experiments can be found at https://github.com/EricElmoznino/explicit_implicit_icl

## 1 Introduction

Recent achievements of large language models (LLMs) showcase the Transformer architecture’s (Vaswani et al., ) capacity to extend beyond predictive modeling and solve novel tasks at inference time (Bubeck et al., ).
However, several papers (Tang et al., ; McCoy et al., , ) find that rather than modeling the tasks themselves, Transformers rely on shortcuts that risk generalizing poorly to new datasets and tasks.
In this work, we aim to shed light on whether learning the true task parameters over shortcuts is sufficient to aid generalization.
In particular, we consider the specific case of in-context learning (ICL): the ability of Transformers to leverage demonstrations within their input sequence to adapt to novel queries, effectively learning from contextual cues.
ICL underpins much of the capabilities of modern LLMs, including prompt engineering and chain-of-thought, but is difficult to study in LLMs directly due to the multitude of factors that affect performance and lack of control over the training data.
To disentangle the role that task latents play in ICL from other aspects that influence large, pre-trained autoregressive models, we therefore introduce controlled experimental settings that involve training Transformers from scratch on tasks that are sufficiently complex, but where the relevant latent variables are well-understood.

Many tasks naturally admit a parametric approach to ICL that breaks the prediction mechanism into two parts: 1) inferring the task-dependent latent variables from the context, and then 2) using them to make predictions on novel queries. For instance, in a linear regression task, a model could first try to infer the underlying weight vector used to generate the data, and subsequently use these inferred weights to make predictions for query points. Another viable methodology, closer in spirit to non-parametric approaches, is to directly compare the query point with the context through a kernel-based mechanism – weighting predictions based on some learned measure of distance between the different points. The two paradigms, parametric vs. non-parametric, reflect tradeoffs between the potential for better generalization or increased flexibility  (Russell & Norvig, ).

Recent studies show that Transformers are indeed able to solve ICL tasks through the parametric mechanism in some cases (Hendel et al., ; Todd et al., ). However, in most cases, there is evidence that Transformers instead rely on non-parametric mechanisms where the prediction is made by directly comparing the query point to exemplars in the context (Wang et al., ; Han et al., ), a mechanism very much related to induction heads (Olsson et al., ). This could be explained by the fact that the functional form of attention operations is almost identical to that of kernel regression (Tsai et al., ), making such solutions more natural for Transformers to express (Zhou et al., ).
These solutions are considered statistical shortcuts since they might not be able to generalize to OOD contexts and queries – for e.g., learning the actual linear predictor for linear regression can generalize to any distribution over training and test points, but nearest-neighbour based interpolation might not.

In this paper, we thereby hypothesize that a limiting factor of ICL in Transformers could be their tendency to prefer non-parametric shortcuts over more structured inference. To test this hypothesis, we perform a thorough analysis through tasks for which latent mechanisms are well understood, and systematically analyse the impact of latent task representation on generalization.
We minimally modify the Transformer architecture to prevent such non-parametric shortcuts and compare the OOD performance of the resulting model to that of a traditional Transformer on a large array of synthetic ICL tasks. We call this altered architecture an explicit model in virtue of its inductive bias of explicitly extracting structured latent variables to solve the tasks, and we call the traditional Transformer architecture an implicit model. Specifically, the explicit model prevents the query from directly attending to demonstrations in the context by introducing a dimensionality bottleneck between the processing of the context and the query (see Fig. 1), similar to a conditional neural process (Garnelo et al., ).

Figure: Figure 1: We compare the benefits of the implicit (left) and the explicit (right) model. Explicit models disentangle context aggregation and prediction into two separate functions, and have an inductive bias for inferring generative latent variables in order to solve the task. Implicit models are more expressive, but can learn non-parametric shortcut solutions that bypass latent variable inference.
Refer to caption: x1.png

We find that the explicit model does not outperform the implicit one on OOD data, challenging the aforementioned hypothesis that avoiding non-parametric solutions would enhance generalization. Our investigation into this lack of improvement reveals that the issue often lies in the explicit model’s prediction function, which is tasked with leveraging the inferred latent variables for downstream predictions on the query. Our controlled experiments and analysis on the interpretable nature of the bottleneck revealed strong evidence that while the explicit model often extracts relevant task latents, these are not properly utilized by the prediction function.

While on one hand, our research demonstrates that using a simple bottleneck in a Transformer can improve interpretability and explicitly extract task-relevant latent variables, it also suggests that the limitations of Transformers in learning more structured and generalizable ICL solutions are not solely due to non-parametric shortcuts that skirt latent variable inference, but due to more fundamental architectural limitations.

## 2 Implicit vs. Explicit Inference

We look at ICL in the context of algorithmic problems where the task is to predict the target $y_{*}$ from a query point ${\bm{x}}_{*}$ when provided with some context examples ${\mathcal{D}}=\{({\bm{x}}_{i},y_{i})\}_{i=1}^{n}$, sharing a common underlying structure defined by the task latent ${\bm{z}}$ and a functional form $g$. The goal of ICL is to learn a function that can utilize the context set ${\mathcal{D}}$ to provide predictions for new query points ${\bm{x}}_{*}$. To achieve this, the model is trained on different draws of context sets (${\mathcal{D}}_{1},{\mathcal{D}}_{2},...$) which share the same underlying functional mapping $g:{\bm{x}},{\bm{z}}\to y$ but different realizations of the latent ${\bm{z}}$, for example $g({\bm{x}},{\bm{z}})={\bm{z}}^{T}{\bm{x}}$ could be a linear regression system shared across different contexts ${\mathcal{D}}_{1},{\mathcal{D}}_{2},...$, but the underlying latents could be different, i.e. ${\mathcal{D}}_{1}$ is generated from ${\bm{z}}_{1}$ while ${\mathcal{D}}_{2}$ from ${\bm{z}}_{2}$, similar to Von Oswald et al. (). We emphasize that in this setup, we are not training models to do next-token prediction as is done in language modeling; instead, given a fixed context ${\mathcal{D}}$ that includes $n$ samples, we are attempting to make a prediction on a single novel query ${\bm{x}}_{*}$. We therefore do not use a causal Transformer, and we allow all tokens to attend to each other.

Often, ICL solutions are learned via maximum likelihood, i.e. $\arg\max_{\varphi}\mathbb{E}_{{\mathcal{D}},{\bm{x}}_{*},y_{*}}\left[\log p_{
\varphi}(y_{*}|{\bm{x}}_{*},{\mathcal{D}})\right]$, where $p_{\varphi}$ represents the Transformer model and ${\mathcal{D}}$ is sampled from the parametric family defined through $g$. Thus, the transformer model $p_{\varphi}$ must not only learn the form of the prediction function $g$, but also how to efficiently aggregate information from the context ${\mathcal{D}}$ to infer ${\bm{z}}$ for downstream predictions on ${\bm{x}}_{*}$. Thus, this general framework can be naturally decomposed into two distinct parts.

Context Aggregation. This component deals with inferring the task-dependent latent variables from the in-context examples such that the downstream prediction becomes conditionally independent of the context, i.e. inferring ${\bm{z}}$ from ${\mathcal{D}}$ such that $p(y_{*}\mid{\bm{x}}_{*},{\bm{z}},{\mathcal{D}})=p(y_{*}\mid{\bm{x}}_{*},{\bm{z
}})$.

Predictive Modeling. This component refers to the process of estimating the predictive function that leverages context ${\mathcal{D}}$ to infer $y_{*}$ from a query $x_{*}$. In the above example, it refers to learning the functional mapping $g$ once ${\bm{z}}$ has been extracted from context aggregation.

As discussed, Transformers do not have a clear incentive to make this explicit separation of context aggregation and predictive modeling. Instead, given context ${\mathcal{D}}$, they implicitly and jointly model both the function $g$ along with ${\mathcal{D}}$-dependent latent variable ${\bm{z}}$ inference to directly provide predictions for the query point ${\bm{x}}_{*}$, in contrast to separately estimating $g$ and an explicitly factorized ${\bm{z}}$. Thus, in order to enforce explicit representation of ${\bm{z}}$, we propose the simplest architectural modification where the query ${\bm{x}}_{*}$ cannot directly attend to the context, and the latent task representation is forced to summarize the context efficiently. Formally, we compare the following two models, which are illustrated in Fig. 1.

Implicit Model. This refers to the traditional in-context learning computation performed by Transformer models. In this setup, given the set of observations ${\mathcal{D}}$ (context) and a query point ${\bm{x}}_{*}$, the prediction $y_{*}$ is modeled directly as $p_{\varphi}(y_{*}|{\bm{x}}_{*},{\mathcal{D}})$, where $p_{\varphi}$ is defined using a standard Transformer with parameters $\varphi$ and is tasked with modeling both context aggregation and predictive modeling.

Explicit Model. This represents the architectural variation which minimally modifies the Transformer architecture by separating context aggregation and predictive modeling. It first constructs a task representation ${\bm{z}}_{\psi}({\mathcal{D}})$ using the set of observations ${\mathcal{D}}$ and a context model ${\bm{z}}_{\psi}$ with parameters $\psi$ (context aggregation) and another network $p_{\gamma}$ to make a prediction for a new point ${\bm{x}}_{*}$ (predictive modeling) as $p_{\gamma}(y_{*}|{\bm{x}}_{*},{\bm{z}}_{\psi}({\mathcal{D}}))$. A key insight is that the task latents are invariant to the queries when modeling prediction. The context model is implemented with a Transformer ${\bm{z}}_{\psi}$ with weights $\psi$, and for the prediction function $p_{\gamma}$, we study both Transformers and MLPs with weights $\gamma$. Importantly, the output of the context model ${\bm{z}}_{\psi}({\mathcal{D}})$ is a fixed-size vector with much lower dimensionality than the full context ${\mathcal{D}}$. This information bottleneck prevents the query ${\bm{x}}_{*}$ from attending directly to the context as in standard Transformers; instead, the context model must summarize ${\mathcal{D}}$ into underlying generative factors, thus ruling out potential shortcut solutions that bypass latent variable inference.

Implicit vs. Explicit. Assuming Transformers do in fact favour shortcut-based solutions, we first hypothesize when each setup should perform better given different task characteristics. If the data is generated with a linear model (i.e. $y={\bm{z}}^{T}{\bm{x}}$), the right predictor can be precisely described using the weight vector ${\bm{z}}$, making the explicit model better suited. In contrast, if the data is generated with a Gaussian Process (GP), the implicit model should be superior since by construction query prediction computes similarities with all points in the context. In this case, the task latents of GP-based data with RBF kernel is infinite dimensional (i.e. a point in function space), which cannot be captured in the finite-dimensional bottleneck of the explicit model.
In general, we should expect the explicit model to be superior when the underlying true model is parametric and low-dimensional, but in case of a non-parametric or very high dimensional parametric model, the implicit model should be better.

Finally, we note that our aim is not to construct the best possible explicit model architecture – indeed, more sophisticated ones already exist based on amortized Bayesian inference (Garnelo et al., ; Mittal et al., ). Instead, we are interested in investigating potential inductive biases for ICL by minimally modifying the standard Transformer architecture to remove certain shortcuts from the space of possible solutions. We leave the design of more performant architectures for future work.

## 3 Experiments

Our goal is to use simple tasks that capture the key elements of ICL applications to tease apart the effects of implicit and explicit models on generalization, both in-distribution (ID) and out-of-distribution (OOD).

Task Setup. We conduct experiments across a variety of settings that admit task latents, from synthetic regression and classification to reasoning-based problems. For reasoning tasks that require compositional knowledge, we consider Raven’s Progressive Matrices (Raven’s PM) (John & Raven, ), Alchemy (Wang et al., ), and Gene Targeting (Norman et al., ). A brief description of our tasks is provided below, with a more thorough explanation in §B.

Regression Tasks. We consider different data-generating processes, e.g., linear: prediction ${\bm{z}}^{T}{\bm{x}}$ and latents ${\bm{z}}$, nonlinear (MLP): prediction with a neural network $g({\bm{x}},{\bm{z}})$ and latents as its weights, sinusoidal: prediction as a sum of sinusoids with different frequencies with latensts as their amplitudes, etc.

Classification Tasks. Akin to the regression problems, we consider a linear and nonlinear (MLP) prediction for classification using an additional sigmoid activation on the output.

Raven’s Progressive Matrices. A pattern-completion task used in IQ tests where individual object attributes evolve according to different rules. The task is to complete a sequence of frames such that the underlying rule, which is the latent variable and can be based on colors, shapes, etc., is maintained.

Alchemy. Here, an unknown latent causal graph describes how different stones and potions interact to give rise to new stones. The task is to infer the next stone given a history of transitions.

Gene Targeting. It represents a real-world dataset of targeted gene knockouts and subsequent observations of gene expressions across many cells. The underlying latent variable is the set of genes that were knocked out in a given experiment, and the task is to infer the gene expressions of certain cells in an experiment given those of other observed ones.

Training and Evaluation. Tasks based on regression utilize the mean-squared error loss, while those based on classification use the cross entropy loss for training. Model architecture details are provided in §C.1. For ID evaluation, we consider the underlying task latent ${\bm{z}}$, context samples ${\mathcal{D}}$, and queries ${\bm{x}}_{*}$ to be sampled from the same distribution as during training. The challenge in this case is simply to generalize from finite data. For OOD evaluation, we test two different cases depending on the kind of task. For our synthetic regression and classification tasks, the task latent ${\bm{z}}$ and context samples ${\mathcal{D}}$ are sampled from the same distribution as at training time, but the queries ${\bm{x}}_{*}$ are sampled from a Gaussian distribution with higher ($3\times$) standard deviation, thus testing a form of out-of-domain generalization. For our reasoning-based problems, we evaluate on task latents ${\bm{z}}$ that weren’t seen at training. The task latent in each of these reasoning-based problems is composed of parts (e.g., in the Gene Targeting experiment, the latent is a binary vector of targeted genes), which allows us to test a form of compositional generalization (Wiedemer et al., ) in which all parts have full marginal support at training time, but novel combinations of those parts are evaluated at test-time.

For all tasks, implicit and explicit Transformer models were trained from scratch over a distribution of tasks latents, and we always control for the number of network parameters to provide a systematic comparison between the implicit and explicit models. To better understand the shortcomings of different models, we also compare with privileged oracles (known decoder – using ground-truth $g$ function, and known latent variable – using an auxiliary loss that includes the ground-truth ${\bm{z}}$).

Figure: Figure 2: Comparison of implicit and explicit models both in-distribution (ID) and out-of-distribution (OOD) across a variety of domains: (a) synthetic regression, (b) classification, and (c) compositional generalization tasks. Implicit models are in shown gray, explicit models with Transformer prediction in blue, and with MLP prediction in orange. More details about each task are provided in §B.
Refer to caption: x2.png

Explicit models do not outperform the implicit models. The first evaluation setting that we considered was the ID performance. In this case, we should expect both implicit and explicit models to perform equally well, even if implicit models learn shortcuts rather than ground-truth task latents. This is because those shortcuts are tuned to minimize prediction error within the same data distribution that is being evaluated. Across all our tasks, the results indeed confirmed this prediction. Specifically, during ID evaluation, all models were capable of making highly accurate predictions (Fig. 2). While the performance of the implicit model was generally slightly better than that of the explicit models, the benefits were marginal. Effectively, all models solved the tasks similarly well.

While we expected that ID evaluation would be insufficient to demonstrate potential benefits of the explicit models, we expected to see differences in OOD settings. Both implicit and explicit models are sufficiently expressive to fit the training distribution. However, if an explicit model successfully learns the true task latents that generated the data while an implicit model learns statistical shortcuts that are specialized to the training distribution, we should expect the explicit model to generalize better OOD. As a reminder, for the synthetic regression and classification tasks in Fig. 2 (a, b), OOD evaluation was done by sampling ${\bm{x}}_{*}$ from a normal distribution with wider standard deviation than was used at training ($3\times)$, effectively evaluating if the models could extrapolate to points further out along their domain despite only being trained within a narrow distribution near the origin. For the compositional tasks in Fig. 2 (c), we instead evaluated OOD performance by only training on certain configurations of the true latent variable ${\bm{z}}$ while evaluating on unseen ones. Importantly, at training time the models were shown data that included every possible value for each component of ${\bm{z}}$, but not ever possible combination of these values were seen, thus evaluating a form of compositional generalization (Wiedemer et al., ).

Surprisingly, and counter to our predictions above, we found that the explicit model provided no significant benefit in OOD settings. In synthetic regression tasks shown in Fig. 2 (a), all models failed to generalize and obtained substantially worse performance than during ID evaluation, with the implicit model actually being the one that had a slightly lower degradation in performance. In classification and compositional tasks shown in Fig. 2 (b, c), all models generalized fairly well OOD and with similar performance. In summary, explicit models appear to provide no benefit across our tasks, both in terms of ID and OOD performance.

If the explicit model did learn the right latent variables in the bottleneck, it essentially implies that either the implicit model learns benign shortcuts (if at all) or that learning the right latent variables is not sufficient to improve generalization, both ID or OOD. In the following results, we see that the explicit model does indeed learn the right task latents.

Figure: Figure 3: Performance comparisons on a subset of tasks where the true latent variable ${\bm{z}}$ and prediction function $g$ are known. Implicit models are in shown gray and explicit models with Transformer prediction are in blue. Models in purple are trained with an auxiliary loss to predict the true latent variable. Models in green are defined using the true prediction function. Using the known prediction function leads to significantly better OOD performance.
Refer to caption: x3.png

Explicit models learn to infer the correct latent variable, but not how to use it.
Why didn’t the explicit model provide any benefit? Our initial hypothesis was that the implicit model could be susceptible to learning shortcuts that are sufficient to reduce the training loss and easy to express using self-attention between the query ${\bm{x}}_{*}$ and context ${\mathcal{D}}$. By summarizing the context in a bottleneck ${\bm{z}}_{\psi}$, the explicit model should instead be forced to extract the true latent variable in order to minimize the training loss, thus learning a solution that is closer to the actual data-generating process. There are then two possible explanations for our results: (1) the explicit models did not learn to extract the true latent variable despite inductive biases to do so induced by the bottleneck, or (2) they did extract the true latent variable but did not learn to use it in the correct way. We performed several experiments to test these two possibilities, and found strong evidence for the second.

To test whether or not the explicit models failed because they did not extract the correct latent variable, we first attempted to encourage them to do so more directly by training an additional linear model which took ${\bm{z}}_{\psi}$ as input and attempted to predict the true latents ${\bm{z}}$. The loss of this linear model was then backpropagated through the context model along with the task loss. Results in Fig. 3 (purple) show that this auxiliary loss provided no improvement apart from minor increases in accuracy on Raven’s PM, suggesting that incorrect latent variable inference does not explain the explicit model’s suboptimal performance. Indeed, when we did not use the auxiliary loss as a training signal for the explicit model and just trained separate linear readouts on ${\bm{z}}_{\psi}$ using a stop-gradient, we found that we could still accurately decode the true latent variable from it (see Fig. 4 (a)). This means that in the absence of any explicit training signal to predict the true latent variable, the explicit model still learns to extract it in order to minimize prediction loss on the query.

Figure: Figure 4: Explicit models are interpretable as the bottleneck allows us to (a) linearly decode the true latent, and (b) intervene on it to obtain correct counterfactual predictions. Implicit models are shown in gray, explicit models with Transformer prediction in blue, and with MLP prediction in orange. Models in green use the true prediction function $g$. To evaluate decoding performance in (a), we also build a baseline by linearly decoding the true latent directly from concatenated context examples, which yielded significantly worse performance than decoding from the bottleneck. Baseline performances in units of the plots are – Linear regression: $0.49$, Nonlinear regression (MLP): $0.94$, Sinusoid regression: $0.33$, Linear classification: $0.86$, Nonlinear classification (MLP): $0.97$, Raven’s PM: $0.5$, and Gene targeting: $0.0$. In (b), the “Relative accuracy” takes in account the baseline (details in C.4).
Refer to caption: x4.png

Given that the explicit model correctly infers the true latent variable in its bottleneck, we study whether the prediction function is suboptimally learned. In other words, despite the explicit model having access to the true ${\bm{z}}$, we hypothesize that $p_{\gamma}(y_{*}|{\bm{x}}_{*},{\bm{z}}_{\psi})$ does not learn the true data-generating process $y_{*}=g({\bm{x}}_{*},{\bm{z}})$, where $g$ is the true prediction function – e.g., for linear regression $g({\bm{x}}_{*},{\bm{z}})={\bm{z}}^{T}{\bm{x}}_{*}$. To validate this hypothesis, we trained explicit models with the prediction function $g$ hard-coded as an oracle. For instance, in the linear regression task, the ${\bm{z}}_{\psi}$ output by the context model was linearly projected to the same dimensionality as the true weights ${\bm{z}}$, after which the prediction function took its dot product with queried input ${\bm{x}}_{*}$. In this setting, if the explicit model extracts the correct latent variable, it should generalize perfectly both in and out of distribution. Our results in Fig. 3 confirm that using the correct prediction function indeed provides substantially better OOD generalization and effectively solves most tasks. This finding has significant implications: it suggests that while learning the true task latents may be a necessary condition for generalization, this must also be supplemented with significant inductive biases in the prediction function – for instance, through novel architectures – so that these task latents can be leveraged correctly. In the absence of such inductive biases, inferring the correct task latent appears to provide no benefits in practice. We do note that our nonlinear regression tasks, where ${\bm{z}}$ represents the weights of an underlying MLP generating the data, were an exception to the results described here in that using an oracle prediction function performed poorly. In this case, we conjecture that the underlying latent variable is too difficult to accurately infer from the context, while shortcut-based solutions would avoid latent variable inference altogether to provide robust solutions.

Explicit models are easily interpretable.
While explicit models do not provide performance benefits, the ability to extract the correct latent and summarize it in a single bottleneck can still be useful for interpretability. On tasks with a known underlying latent variable, we were able to linearly decode it from ${\bm{z}}_{\psi}$ with high accuracy in most cases, meaning that the information is not only present but also easily accessible (Fig. 4 (a)). The exceptions were on complex nonlinear regression tasks where the latents are difficult to infer and classification tasks where more context samples are needed to precisely identify the true decision boundaries.
In contrast, finding such clear task-relevant latents is immensely challenging in an ordinary Transformer trained to do ICL, given that they can be distributed across a mixture of many layers and token positions.

Furthermore, even when latent variables appear to be successfully identified using a linear decoder in some hidden layer of a Transformer, one often finds that the relationships merely amount to spurious correlations (Ravichander et al., ). For instance, if one manually modifies the activations in this hidden layer such that a different latent variable is predicted by the linear decoder, the model’s predictions do not generally change in a way that is “counterfactually” consistent with this new latent (i.e., the prediction is not what it should have been under the new latent variable). We therefore used the Distributed Alignment Search (DAS) method from Geiger et al. (see §C.4) to search for units in the implicit and explicit models that can be manipulated to obtain correct counterfactual predictions. For the explicit model, we limited this search to the bottleneck ${\bm{z}}_{\psi}$. We found that using the explicit model, we were indeed able to manipulate ${\bm{z}}_{\psi}$ and obtain correct counterfactual predictions, but we were not able to successfully do this using the implicit model, as shown in Fig. 4 (b). Explicit models might therefore be useful for both mechanistic interpretability and scientific discovery (Geiger et al., ), where we do not know the underlying task latents and want to be able to easily uncover them from the trained model, and subsequently obtain a good predictor for an intervened system zero-shot given some knowledge about the intervention.

Figure: Figure 5: We analyze (a) Linear regression OOD task performance and (b) latent variable linear decoding performance as a function of model and task parameters. Task performance scales similarly for implicit (gray) and explicit models with Transformer prediction (blue). Models in green use the true prediction function $g$. Latent variable decoding accuracy scales as a function of the latent variable’s inherit uncertainty (data dimensionality and context length) and the model’s size.
Refer to caption: x5.png

Scaling Trends across Different Properties.
To better compare the implicit and explicit models, we investigated their OOD task performance on linear regression as we varied the different properties of the task (input dimensionality and context length) and the size of the model used (Fig. 5 (a)). We found that performance in both models scaled similarly, but that the implicit model reliably outperformed the explicit one unless it used the known prediction function $g$. We also looked at the latent variable linear decoding accuracy in the explicit model as a function of these task and model properties (Fig. 5 (b)). As expected, we found that the latent variable was easier to decode from the explicit model’s bottleneck when there was less inherit uncertainty about its value (lower data dimensionality, longer context length) and when the explicit model was given more capacity. However, throughout the different settings, we see that while the explicit model does learn the true latent well, it is not sufficient to get a performance boost over the implicit models. Further details on the setup of these scaling experiments is provided in §C.2.

## 4 Related Work

In-Context Learning. In-Context learning (ICL) is an ability of certain trained models to take an entire task’s dataset as input and parameterize solutions directly in their layer activations, which then condition subsequent computation on novel inputs from those same tasks. Generally, this ability is found in sequence models such as Transformers where the task dataset, or “context”, corresponds to an earlier part of the sequence. ICL was first observed in large-scale pre-trained LLMs (Brown et al., ), and is similar in many respects to meta-learning (Chan et al., ) (see §A). These LLM findings were subsequently expanded to more controlled settings outside of the language modality, where Transformer models were directly trained on task distributions such as linear regression (Von Oswald et al., ; Garg et al., ), hidden Markov models (Xie et al., ), compositional grammars (Hahn & Goyal, ), regular languages (Akyürek et al., ) and Turing machines (Grau-Moya et al., ), with a set of task observations defining the “context”. These works highlight that Transformers are indeed able to model many types of complex task distributions, approaching in many cases the performance of the Bayes-optimal predictor, the a-priori optimal solution (Xie et al., ). Our work lies along similar lines but using more complex tasks and a systematic study into the differences between modeling the predictive space directly, or through a two-step process involving explicit inference of task latents.

Shortcuts in ICL. Shortcut learning is a phenomenon that has widely been observed in machine learning (Geirhos et al., ), and refers to where a model solves a task through statistical correlations that are accidental and thus not robust to even slight distribution shifts. A classical example of this in image classification is the usage of background cues to classify objects (Ribeiro et al., ). Similar mistakes are know to be very common in NLP (McCoy et al., ), specifically in reasoning tasks (Zhang et al., ). Particularly relevant to our work, many authors have shown that has shown that Transformers are very prone to relying on shortcuts when performing ICL Tang et al. (). For instance, Olsson et al. (); Singh et al. () have shown that induction heads play in important role in ICL by predicting that the continuation of a token will be the same as last time (i.e. $[a][b]\ldots[a]\rightarrow[b]$). As shown by Von Oswald et al. () this motif can be used to do linear regression, and can generally be seen as a form of kernel regression (i.e. $p(y_{q}|x_{q},x_{1:n})\propto\sum_{i}K(x_{i},x_{q})y_{i}$, (Han et al., )). This observation draws a link between those types of solutions and non-parametric inference methods in statistics (Wikipedia, ), of which kernel regression is a member. In contrast (Hendel et al., ; Todd et al., ) have concurrently shown that in some cases Transformers encode a “task vector” that they infer from the context and then use to do the prediction. There is therefore a need to better understand the nature of shortcuts in ICL (which relates to the field of mechanistic interpretability, see §A) and whether or not they can be easily avoided for better generalization. Our work explores this very question.

Neural Processes.
The problem of solving new tasks in a zero-shot manner directly at inference is also closely tied to amortized Bayesian models (Kingma & Welling, ; Rezende et al., ; Radev et al., ; Geffner et al., ; Mittal et al., ). Conditional Neural Processes (CNPs) (Garnelo et al., ) provide a framework akin to the explicit model, where the posterior predictive distribution is modeled through a bottleneck ${\bm{z}}_{\psi}$, i.e. $p_{\bm{\theta}}(y_{*}|{\bm{x}}_{*},{\mathcal{D}})=p_{\bm{\theta}}(y_{*}|{\bm{x
}}_{*},{\bm{z}}_{\psi}({\mathcal{D}}))$. However, CNPs do not look at the relevance of ${\bm{z}}_{\psi}$ to the true latent ${\bm{z}}$, and use the DeepSets (Zaheer et al., ) architecture to model ${\bm{z}}_{\psi}$, though recent research generalizes this setting to use Transformers Nguyen & Grover () and other architectural backbones as well (Kim et al., ; Gordon et al., ). Our approach with the explicit model, however, is to precisely question whether task-specific latents are encoded via ${\bm{z}}_{\psi}$ which is now instead modeled using a Transformer architecture. Analogously, Neural Processes (NPs) (Garnelo et al., ; Pakman et al., ) augment CNPs with probabilistic modeling, where ${\bm{z}}$ is now modeled explicitly as a latent-variable in the Bayesian sense, i.e. the likelihood is now modeled as $p_{\bm{\theta}}(y|{\bm{x}}_{*},{\mathcal{D}})=\int p_{\bm{\theta}}(y|{\bm{x}},
{\bm{z}})p_{\bm{\theta}}({\bm{z}}|{\mathcal{D}})d{\bm{z}}$
, where ${\bm{z}}$ represents the latent variable and ${\bm{\theta}}$ the parameters of the likelihood model. The model is trained via the Evidence Lower-Bound (ELBO) with the amortized variational approximation $q_{\varphi}(\cdot|{\mathcal{D}})$. Once trained, predictions for new datasets can be made by simply performing inference over the encoder $q_{\varphi}$ to obtain ${\bm{z}}$, and then leveraging this latent variable to eventually give the predictions via $p_{\bm{\theta}}(y|{\bm{x}}_{*},{\bm{z}})$. Hence, while CNPs and the explicit model to share similarities in architecture, our goal is orthogonal in that we specifically use the explicit model to understand the impact of task-specific latent variable inference on ICL setups.

## 5 Conclusion

A commonly believed hypothesis is that Transformers do ICL through brittle statistical shortcuts rather than by inferring the underlying generative latent variables of the task, and that this explains their inability to generalize outside of the training distribution. Here, we empirically tested this hypothesis by minimally modifying the Transformer architecture through the use of a bottleneck that factorized the model into separate context aggregation and prediction functions, creating an inductive bias for explicit latent variable inference. While we confirmed that this model indeed learned to infer the correct latent variables across many ICL tasks, it surprisingly gave no improvement in performance for either in-distribution or out-of-distribution evaluation. Contrary to common belief, then, we showed that simply learning the correct latent variables for the tasks is not sufficient for better generalization because end-to-end optimization does not learn the right prediction model to leverage these latent variables.
Indeed, when we substituted the prediction function with a known oracle, we often saw significant advantages in OOD performance.
Importantly, we were able to make such findings because we performed controlled experiments on simple tasks with known latent variables and prediction functions, thus avoiding the complexities and confounding variables that come with natural language and pre-trained LLMs.
Our results point to a line of future work that incorporates inductive biases in the prediction model to better leverage the inferred latent variables, and motivates current efforts in improving (a) amortized methods for in-context prediction (e.g., Garnelo et al., , ; Kim et al., ; Hollmann et al., ) and (b) neurosymbolic AI which tries to combine flexible LLMs for inference with highly structured functions for prediction (e.g., Wong et al., ; Mialon et al., ; Ellis, ).

Limitations. While our work investigates potential reasons behind the shortcomings of current ICL approaches, overcoming those shortcomings is an entirely different and bigger problem which is a relevant future direction but not an achievement of the current work. We also look at ICL solely from the perspective of algorithmic tasks with models trained from scratch, without exploring in detail the connections with ICL in pre-trained models.

Broader Impact. Our approach paves the way into an interpretable model for in-context learning, which could prevent harmful use of such models by additionally encoding constraints on the interpretable bottleneck. Additionally, our work provides a better understanding about ICL which can lead to safer future models.

## Acknowledgments and Disclosure of Funding

The authors would like to thank Tom Marty, Johannes von Oswald, Joao Sacramento and Yoshua Bengio for discussions.
The authors would like to acknowledge the computing resources provided by the Mila cluster to enable the experiments outlined in this work. SM acknowledges the support of UNIQUE’s scholarship. EE acknowledges the support of the Vanier CGS scholarship. GL and DS acknowledge the support of the Canada CIFAR AI Chair program and Google Research. GL is also supported by NSERC Discovery Grant RGPIN-2018-04821, and a Canada Research Chair
in Neural Computations and Interfacing.
The authors also thank NVIDIA for computing resources.

## Appendix A Additional Related Work

Meta-Learning. Meta-learning (Weng, ; Hospedales et al., ) studies systems that can learn over two levels: rapidly through an inner-loop that is meta-learned using a slower outer-loop. The goal in such methods is to learn a good initialization common to the parameterized family of tasks, in a manner that obtaining a particular solution for a new task is fast from this initial point. The inner loop provides an optimization trajectory for a randomly drawn task from some initialization, which in itself is optimized in the outer loop to a good solution applicable for the global set of tasks. Typically, evaluation is done on some meta-validation set of tasks not seen during training. Task distributions can for example be a set of different classification/regression tasks (few shot learning, Vettoruzzo et al. ()) or variations of a reinforcement learning (meta-RL, Beck et al. ()). The goal is similar to ICL approaches in the sense that given a novel context ${\mathcal{D}}$, one wants to make predictions for some query ${\bm{x}}_{*}$. However, a big difference is that ICL approaches bypass modeling a common initialization by working directly on the prediction side (implicit), or instead predict the optimal parameters directly zero-shot through inference on the context model (explicit).

Mechanistic Interpretability.
Mechanistic interpretability is interested in understanding deep neural network’s computations through interpretable abstraction, akin to what computational neuroscience does with the brain. Alain & Bengio () introduced the foundational technique of linear “probes”, which are linear models trained on the hidden state of a network to predict a abstract feature of the input; the success of which would suggest that such feature is used by the model. Since then, this naïve approach has been criticized for being potentially misleading (Ravichander et al., ); in many cases a feature can be linearly decoded from a model without the model using it. More reliable methods grounded in causality (Vig et al., ; Geiger et al., ) have now became the gold standard, and their use applied to Transformers have been exploding in popularity in the recent years (Elhage et al., ). In this paper we use linear probing for its simplicity for most experiments but use more sophisticated on one experiment to show that the learned feature are causally meaningful.

## Appendix B Tasks

We consider the following tasks for our evaluations, specified by the data-generating prediction function $g:{\bm{x}},{\bm{z}}\rightarrow y$ which is used to generate the ICL dataset, where ${\bm{z}}$ represents the task-specific latent variable.

### B.1 Regression Tasks

For regression tasks, since $y\in\mathbb{R}$, we use the mean-squared-error loss to train the model.

Linear Regression. This refers to the task where $y$ is obtained from an affine transformation on the input ${\bm{x}}$. In particular, ${\bm{y}}=g({\bm{x}},{\bm{z}})={\bm{z}}^{T}{\bm{x}}$, where ${\bm{z}}\in\mathbb{R}^{i\times j}\sim{\mathcal{N}}(0,I)$. For our experiments, we set $\dim({\bm{x}})=1$ and $\dim({\bm{y}})=1$.

Nonlinear Regression using MLPs. Here, the labels $y$ are obtained from a neural network which takes ${\bm{x}}$ as an input. In particular,
${\bm{y}}=g({\bm{x}},{\bm{z}})=f_{\bm{z}}({\bm{x}})$, where $f_{\bm{z}}$ is modeled as a Multi-Layer Perceptron (MLP) network with a $64$ dimensional single hidden layer and ReLU nonlinearity. The distribution of the weights of the neural network is ${\bm{z}}\sim{\mathcal{N}}(0,I)$. For our experiments, we set $\dim({\bm{x}})=2$ and $\dim({\bm{y}})=1$.

Sinusoid Regression. For this task, the label $y$ is obtained as a summation of sine functions with different frequencies and amplitudes, taking ${\bm{x}}$ as an input. Mathematically, we structure the system as $y=g({\bm{x}},{\bm{z}})=\sum\limits_{i=1}^{K}\alpha_{i}\sin\left({2\pi\lambda_{
i}{\bm{x}}}\right)$, where $\lambda_{i}$’s denote the frequencies and $\alpha_{i}$’s the amplitudes. The parameters for the system can be seen as ${\bm{z}}=\{\alpha_{1:K}\}$ while $\lambda_{1:K}$ remains fixed throughout. Additionally, for our experiments we set $K=3$, and consider the distributions – $\lambda_{i}\sim\mathcal{U}(0,5)$ and $\alpha_{i}\sim\mathcal{U}(-1,1)$, and set $\dim({\bm{x}})=2$ and $\dim(y)=1$.

Gaussian Process Regression. While the other tasks considered had a parametric nature to it, this task on the other hand has more of a non-parametric nature. Here, the task is that ${\bm{Y}}\sim\mathcal{N}(\textbf{0},K({\bm{X}},{\bm{X}}))$, i.e. the set of labels is sampled from a joint Gaussian distribution, akin to drawing a random function through a Gaussian Process (GP) prior and then evaluating it at different points ${\bm{X}}$; with $K$ defining the kernel in the GP. In our case, we consider $K({\bm{x}},{\bm{x}}^{\prime})=\exp\left(-\frac{\|{\bm{x}}-{\bm{x}}^{\prime}\|^
{2}}{2\sigma^{2}}\right)$ as the RBF kernel and ${\bm{X}}=({\bm{X}}_{c},{\bm{X}}_{q}),{\bm{Y}}=({\bm{Y}}_{c},{\bm{Y}}_{q})$ are the combined points for both the context and the queries, which are split after this sampling. Here the latents ${\bm{z}}$ has to store the kernel computations between the query and all the context points ${\bm{X}}_{c}$, as well as the corresponding context labels ${\bm{Y}}_{c}$. Storing this either involves storing the high-dimensional mapping of ${\bm{X}}_{c}$ which is defined by the kernel $K$, or storing all the points ${\bm{X}}_{c}$ themselves. This is thus very high dimensional and weakly structured.

Hodgkin-Hoxley ODE Prediction. This is an example of the task where the context ${\mathcal{D}}$ is not composed of iid entries, but instead observations from the Hodgkin-Huxley temporal dynamics model of neural activity unrolled through time :

$$ $C_{m}\frac{dV}{dt}=g_{1}\left(E_{1}-V\right)+{\bar{g}_{Na}}m^{3}h\left(E_{Na}- V\right)+{\bar{g}_{K}}n^{4}\left(E_{K}-V\right)+\bar{g}_{M}p\left(E_{K}-V \right)+I_{inj}+\sigma\eta\left(t\right)$ $$

Above, $V$ represents the membrane potential which is the target of interest, ${\bm{t}}$ represents the different points at which observations are provided, $C_{m}$ is the membrane capacitance, $g_{\text{l}}$ is the leak conductance, $E_{\text{l}}$ is the membrane reversal potential, $\bar{g}_{c}$ is the density of channels of type $c$ ($\text{Na}^{+}$, $\text{K}^{+}$, M), $E_{c}$ is the reversal potential of $c$, ($m$, $h$, $n$, $p$) are the respective channel gating kinetic variables, and $\sigma\eta(t)$ is the intrinsic neural noise. The right hand side of the voltage dynamics is composed of a leak current, a voltage-dependent $\text{Na}^{+}$ current, a delayed-rectifier $\text{K}^{+}$ current, a slow voltage-dependent $\text{K}^{+}$ current responsible for spike-frequency adaptation, and an injected current $I_{\text{inj}}$. Channel gating variables $q$ have dynamics fully characterized by the neuron membrane potential $V$, given the respective steady-state $q_{\infty}(V)$ and time constant $\tau_{q}(V)$ (details in Pospischil et al. ()).

Importantly, in our experiments, we fix all parameters but $(\bar{g}_{Na},\bar{g}_{K})$ to values in Tejero-Cantero et al. and solve the differential equation for 6,400 pairs $(\bar{g}_{Na},\bar{g}_{K})\in[0,40]^{2}$ from $t=0$ to $t=120$ with $1000$ time-steps. In other words, the Transformer has to regress to solutions of ordinary differential equations, where the task latents are ${\bm{z}}=\{\bar{g}_{Na},\bar{g}_{K}]\}$, the observations are ${\bm{x}}={\bm{t}}$ and $y=V$, such that $y=g({\bm{x}},{\bm{z}})$. Here $g$ represents the unrolling of the differential equation.

### B.2 Classification Tasks

For classification tasks, since $y$ is a categorical measure, we use a cross-entropy loss for training.

Linear Classification. Akin to linear regression, here we consider the case that $y$ is obtained by an affine transformation of ${\bm{x}}$ followed by a sigmoid function and a consequent sampling step. That is, $y=g({\bm{x}},{\bm{z}})\sim\mathrm{Categorical}(\text{Softmax}({\bm{z}}^{T}{\bm
{x}}))$ where ${\bm{z}}\in\mathbb{R}^{i\times j}\sim\mathcal{N}(0,I)$. For our experiments, we set $\dim({\bm{x}})=2$ and $y\in\{0,1\}$.

Nonlinear Classification Using MLPs. Here, the logits for the labels are instead obtained through a neural network taking ${\bm{x}}$ as an input, and not an affine transformation. Mathematically, this can be seen as
$y=g({\bm{x}},{\bm{z}})\sim\mathrm{Categorical}(\text{Softmax}(f_{\bm{z}}({\bm{
x}})))$ where $f_{\bm{z}}$ is modeled as a Multi-Layer Perceptron (MLP) network with a $64$ dimensional single hidden layer and ReLU nonlinearity. The distribution of the weights of the neural network is ${\bm{z}}\sim{\mathcal{N}}(0,I)$. For our experiments, we set $\dim({\bm{x}})=2$ and $y\in\{0,1\}$.

### B.3 Compositional tasks

Alchemy. Alchemy is a meta-reinforcement learning benchmark Wang et al. () where each environment is defined by a set $\mathbf{z}=(\textsc{Graph, Potion map, Stone map})$ of rules about how some set of potions transforms some stones. We extracted from it an ICL classification dataset consisting of transformations $\mathbf{x}=(\textsc{stone},\textsc{potion})\rightarrow\mathbf{y}=\textsc{stone}$. The transformations are compositional and symbolic; each potion affects only one of the three properties of stones (size, shape and color). An environment is specified by how observable stones and potions map to latent stones and potions, along with a graph over these latent stones which specify the result of the Transformations. In total there is 109 Graph, 48 Potion map and 32 Stone maps, making for 167424 environments. We reserve 100,000 environments for evaluation and train of the remaining ones.

Raven’s Progressive Matrices. Raven’s Progressive Matrices (Raven’s PM) is a reasoning task used for IQ tests (John & Raven, ). It consists of a 3x3 grid where each cell contains simple objects varying in a small number of attributes (number, shape, size, color), but the bottom right cell is left empty. Subjects must notice a pattern in how the cells change from left to right in the first two rows of the grid, and then use that same pattern to complete missing cell in the bottom row. This is done by selecting one answer among $N$ possible provided options for the missing cell. We use a symbolic version of the dataset that addresses bias in the original version (Guo et al., ). In this dataset, objects at a cell have $4$ discrete attributes with $40$ possible values each. In our models, the context consists of the first two rows of the grid, the query consists of the last row with a masked out final cell, and the ground-truth latent variable is the underlying rule that generates a particular grid. Each rule is composed of a set of sub-parts, and we evaluate on unseen compositions.

Gene Targeting. We use Perturb-seq dataset collected by Norman et al. () where researchers performed several genetic intervention experiments using CRISPR (Gilbert et al., ). In each experiment, either one or two genes were targeted and the resulting expressions across 5000 genes were observed across several cells. Here, we consider each CRISPR intervention experiment as a different context, the resulting cell genetic expressions as 5000-dimensional observations, and a left-out cell with half of the genetic expressions randomly masked out as the query. The task is to predict the missing genetic expressions for the queried cell. We evaluate on held on held out CRISPR experiments with novel pairs of targeted genes.

## Appendix C Model Details

In the following section, we describe the standard architectural details used for all the tasks, as well as specific differences in the architecture used for the scaling experiments. Finally, we also provide details about the distributed alignment search mechanism.

### C.1 General Details

For our implicit model, we use a standard Transformer with 8 layers. In the explicit model, for context aggregation we parameterize ${\bm{z}}_{\psi}({\mathcal{D}})$ using a standard Transformer with 4 layers, 256 dimensions latent, 512 dimensions MLP, and 4 heads. For the predictor $p_{\gamma}$, we consider two options: a ReLU-actiavtion based MLP with three hidden layers of size 512 and a Transformer with the same configuration as ${\bm{z}}_{\psi}({\mathcal{D}})$.

For the implicit model, we format the prompt for prediction as $[{\bm{x}}_{1},y_{1}]\ldots[{\bm{x}}_{n},y_{n}][{\bm{x}}_{q},\emptyset]$, where every $[\cdot]$ represents a token. We use a distinct mask token $\emptyset$ to represent the target (which is the thing being predicted). For the explicit model, we first compute $[{\bm{x}}_{1},y_{1}]\ldots[{\bm{x}}_{n},y_{n}]$ to ${\bm{z}}_{\psi}({\mathcal{D}})$ with the context Transformer, then we give $[{\bm{z}}_{\psi}({\mathcal{D}})][{\bm{x}}_{q}]$ to the predictor Transformer or $[{\bm{z}}_{\psi}({\mathcal{D}}),{\bm{x}}_{q}]$ to the MLP.

For our experiments, the number of context points $n$ is uniformly sampled from $16$ to $128$ for both training and evaluation. Training is done with new data being synthetically generated on the fly, and evaluation either based on the test set provided for real-world tasks or simulated data of $1000$ different contexts for synthetic tasks. All the models were trained with a learning rate of $10^{-4}$ using the Adam optimizer (Kingma & Ba, ) for a $1000$ epochs.

### C.2 Scaling Experiments

For the scaling experiments, we only consider the linear regression case with a base configuration of: (a) ${\bm{x}}$ of dimensionality $100$, (b) context size being sampled uniformly from $(75,125)$, and (c) $8$ heads, $8$ layers, $512$ hidden dimensions and $256$ bottleneck dimension for the transformer models.

From this base configuration, we changed only one of the configurations at each time to test for scaling trends for each property independently. In particular, we ablated over $(50,100,250)$ for the dimensionality of ${\bm{x}}$, $(50,100,250)$ for the context length which was sampled from a $\pm 25$ range and the model size. The smallest model size considered had $4$ heads, $4$ layers, $256$ hidden dimensions and $128$ feature dimensions. The medium multiplied each of these properties by $2\times$, and the biggest model subsequently multiplied it by $2\times$ again. For the explicit models, we considered the same scaling paradigms with the number of layers being split by half to accommodate a separate context model and prediction model.

All the models were trained with a learning rate of $10^{-5}$ using the Adam optimizer for $5000$ epochs.

### C.3 Compute Details

We train most of our models on single RTX8000 NVIDIA GPUs, where it takes roughly 3-6 hours for each experiment to run. Our scaling experiments on the other hand often required 1-2 days on single GPUs for training each model.

### C.4 Distributed Alignment Search details

To find subspace causally associated with a task latent in Alchemy, we use a method based on Distributed Alignment Search (DAS) by Geiger et al. (). This procedure is performed for a location $L=\mathbb{R}^{d}$ (e.g. the bottleneck) and latent $i\in\{1,2,3\}$ (Graph, Stone map, Potion map).

First, we run with the model on $\mathcal{D}_{z}$ and $\mathcal{D}_{\bar{{\bm{z}}}}$ for every possible query $x_{*}$. We call ${\bm{z}}$ the base and $\bar{{\bm{z}}}$ the source and only differ by the $i$th latent. For every run, we record the activity of the source model at the location $l_{z}\in\bar{L}$. Then, we run the base model again but this time fixing the subspace of $l$ defined by the orthogonal projection $\Pi\in\mathbb{R}^{d\times 10}$ to it’s value in $l_{z}$. A single projection $\Pi$ is learned over all possible combination ${\bm{z}},\bar{{\bm{z}}}$ and $x_{*}$ with a cross-entropy loss between the prediction of the base (intervened) model and the true counter-factual result of changing the latent $z_{i}$ to $\bar{{\bm{z}}}_{i}$. See Fig. 6 for an illustration of the process. A subspace is evaluated by looking at the accuracy of the counterfactual interventions over a dataset of held-out ${\bm{z}},\bar{{\bm{z}}}$ pairs; a quantity called the Interchange Intervention Accuracy (IIA). In Figure Fig. 4 (b) we report the validation IIA relative to a baseline corresponding to the counterfactual accuracy if we don’t perform any intervention (because changing the latent sometimes doesn’t change the prediction) $\frac{\textsc{IIA}-\textsc{baseline}}{1-\textsc{baseline}}$.

Figure: Figure 6: Illustration of the DAS training procedure
Refer to caption: extracted/5629736/figures/figure_das.png

## Peer Reviews

confidence: 2
contribution: 3
initial_rating: 6
presentation: 3
questions: The findings from the paper are interesting, do you think that the controlled experiments are enough to draw such a strong conclusions? Or will there be cases where learning good latent representation improves the prediction performance?
soundness: 3
strengths: - It is important for the community to learn about such work.
- The problem studied is interesting.
summary: The paper studies an important problem of whether learning good latent representation improve in context learning. For that, the authors add a bottleneck to Transformers to encourage structured predictions. Experimental results are presented. Interestingly, the experiments show that learning good latent representation does not help with out of distribution predictions nor downstream tasks.
weaknesses: See below

---

confidence: 3
contribution: 1
initial_rating: 3
presentation: 1
questions: Given the above weakness, the reviewer believes that the author needs to clarify (1) what is the contribution and novelty in this work. (2) how is the claim being rejected by the experiments. (3) whether the experiments are scalable to LLMs  (4) what is the motivations in this work and the impact of this work to the research communities.

And at the current stage, the reviewer believes a significant improvement and rewrite is needed to get it publishable.
soundness: 2
strengths: The strength of this paper is that they provide empirical simulations on their claim. Their plot looks very carefully drawn. The problem seems to be interesting.
summary: A commonly believed hypothesis is that Transformers do ICL through brittle statistical shortcuts rather than by inferring the underlying generative latent variables of the task, and that this explains their inability to generalize outside of the training distribution.
This paper attempts to understand if it is true. They minimally modify the Transformer architecture with a bottleneck designed to prevent shortcuts in favor of more structured solutions, and then compare performance against standard Transformers across various ICL tasks. Their empirical simulations suggest that little discernible difference exist between the two different approaches, thus questioning the previous belief.
weaknesses: The major weakness of this paper is its presentation, which is not very clear to the reviewer. In particular, the reviewer felt it very difficult to understand (1) The contributions of this work. (2) The structure and logic of this work. (3) The motivation of this work. Given these concerns, the reviewer believes that the current paper requires significant rewrite to make it publishable at ICLR.

In particular, the author has not highlighted their key contributions in this work at the abstract/introduction part. The motivations seem like a course project rather than a publishable work.

---

confidence: 3
contribution: 2
initial_rating: 5
presentation: 2
questions: Is it possible to study the task-specific relationships shown in Figures 3 and 4 in more depth? For example, could you provide a detailed analysis of why certain tasks benefit from the explicit model while others do not?
In Figure 4b, can you explain why MLP predictions are generally less effective than those from transformers?
soundness: 3
strengths: 1. The paper clearly describes the procedures and results of the experiments.
2. The paper incorporates various tasks, ranging from simple regression tasks to more realistic tasks such as gene targeting tasks.
3. The paper studies causal relationships between ICL performance and various factors, such as the presence of an auxiliary ground-truth task latent loss.
summary: The main goal of this paper is to study the relationship between learning latent variables and in-context learning performance. To do so, the paper compares the in-context learning abilities of implicit and explicit models, where the explicit model has an architecture with a bottleneck designed to explicitly infer the task latents. Furthermore, the paper examines how performance changes in explicit models causally through various ablation studies.
weaknesses: The paper addresses an interesting question, but the robustness of its implications remains unclear. The finding that explicitly learning latent variables does not enhance performance may be limited to the specific tasks chosen for evaluation, especially those where implicit models already perform well.
Also, the paper lacks a discussion on how observations differ across tasks. For example, in Figures 3 and 4, the performance trends (accuracy gains) of the explicit model and other factors vary inconsistently across task types, yet the paper does not explore how or why these results differ by task.

---

confidence: 4
contribution: 2
initial_rating: 6
presentation: 4
questions: 1. Do you have results comparing the explicit model's performance to the implicit model on a task in which triggers have been deliberately injected? If you do, please report them here. If they show that the explicit model is robust to shortcuts, I would find the result compelling.
2. Beyond what you argue in the paragraph starting on line 70, does your understanding of OOD generalization include robustness to variation of incidental features on ID data?
soundness: 3
strengths: * **Originality** This paper brings a new perspective to recent work on the problem of shortcut learning. Designing a network to prevent shortcut learning and applying it in the way the authors have done is novel. Framing the investigation in a parametric vs. non-parametric setting is insightful and highlights the operation of attention mechanisms as a particular feature of interest.
* **Quality** This is a high-quality paper. The evaluation on at least five types of tasks is thorough. The authors' use of tasks with known latents indicates a high level of rigor. The authors state the general hypothesis under investigation and provide additional hypotheses (line 165) about which model -- implicit or explicit -- are best suited to the evaluation tasks. The additional experiments (starting line 294) are informative.
* **Clarity** This paper is clear and well written. The setup of the problem and the motivation for the work is communicated concisely.
* **Significance** The contribution of this paper is a novel perspective on a timely problem. Robustness of large transformers is an area of active investigation -- including, shortcut learning (see [1]) -- and this paper shows to an extent that when a network is constrained in a targeted way, generalization does not necessarily improve.
summary: The authors of this paper propose a hypothesis -- namely, that the in-context learning capabilities of transformers are limited by their tendency to be deceived by shortcuts (as demonstrated in [1]) -- and test it by benchmarking a transformer they introduce to prevent shortcut learning (explicit model) against a standard autoregressive transformer (implicit). The explicit model is a slightly modified architecture in which the parameters that are optimized to perform next-token prediction are not able to attend to specific hidden states, whereas the implicit model can do so. The benchmark is performed over a variety of tasks in in-domain (ID) and out-of-domain (OOD) settings. The results show that the explicit model is not superior to the implicit one on ID data. They show that the bottleneck of the explicit model encodes useful representations of the learned task but the next-token prediction parameters are suboptimal at exploiting it. Additional experiments to investigate the interpretability and scaling properties of the explicit and implicit models are performed.

[1] Large Language Models Can be Lazy Learners: Analyze Shortcuts in In-Context Learning, Tang et al, 2023
weaknesses: While the overall quality of the paper is quite good, much of the quality can be said to be tactical (i.e. the execution) rather than strategic (i.e. the motivation and contribution). In tactical terms, the paper is beautiful. Strategically, it can be improved.

While I acknowledge and appreciate the principled argument in favor of the explicit model in the context of parametric vs non-parametric learning (see p. on line 70, Section 3, and Figure 1), I believe the paper would be very much improved if it verified empirically that the explicit model is itself resistant to shortcut learning in the presence of **injected** shortcuts. Whereas [1] injects shortcuts ("triggers") into data in an ICL setting, the work presented here appears to use datasets without such injections. Creating, if necessary, a synthetic dataset for evaluating robustness to shortcuts, and empirically demonstrating that the explicit model is resistant to shortcuts would strengthen the paper by showing a method by which existing large-scale models might be made resistant to shortcuts. Further showing that the explicit model exhibited consistent resistance to shortcuts as the model size increases would be a substantial contribution. Finally, showing this would provide solid empirical ground on which the argument in p. on line 70 rests.

I would prefer that the authors removed "commonly" from their conclusion (line 512). It's non-controversial that shortcuts are a likely explanation for well-demonstrated non-robustness of transformers to incidental variations of their inputs. In the context of the sentence on line 512, however, the use of "commonly" can be taken to imply that most people believe that shortcut learning is the reason for poor OOD generalization. If that particular view w.r.t. OOD generalization is commonly held, I would expect there to be be some literature -- particularly since [1] was published in 2023 -- claiming exactly that. If it exists, it should be cited in the introduction.

Nit: The classification tasks in the first row of Figure 4 are missing the label on the Y axis.

---

confidence: 3
contribution: 2
initial_rating: 3
presentation: 3
questions: What is the evidence to believe in the first place that learning task vectors might improve generalization? And, especially, what is the evidence that not learning it leads to poor generalization? 

You should also be more careful with the claim that parametric models generalize better than non-parametric ones in OOD scenarios, or, alternatively, also support this claim.

The paper would clearly benefit from providing more empirical evidence for the fact that the task vectors are actually always learned well by the explicit model. 

Please also provide more evidence that the explicit model learns the task vector *better than* the implicit one.

The scale of the experiments could be improved in several dimensions (please refer to the "weakness" section)

I also think that the paper would benefit from carefully reading it again to fix typos and other small issues and from shortening it to the recommended length of nine pages. 

Please also take the reproducibility issues from above into consideration, with releasing the code being the most important point.
soundness: 2
strengths: Writing: The paper is accessible and easy to read, which, however, is also facilitated due to the nature of the content. The overall structure is straightforward and easy to follow.
The extensive use of bar-plots makes it convenient to understand the experimental results.

Significance: The question whether ICL can be accurately described via task vectors is certainly interesting and important. Clearly stating this question is thus a central contribution of this paper. I also appreciate that the authors present a negative result. The paper also presents a new experimental setup, compared to for instante that in the paper “In-Context Learning Creates Task Vectors” by Hendel et al.
summary: This paper investigates the role that learning ground-truth task vectors plays for out-of-domain generalization in the in-context learning framework. For this purpose, the authors compare a traditional transformer (referred to as the “implicit model”) and a similar model with a bottleneck in its architecture (the “explicit model”).
They empirically find that the implicit model does not perform better than the explicit model, on the OOD setup, even though the implicit model correctly learns a relatively good representation of the ground-truth task vector. They thus demonstrate that access to the task vector is not sufficient for OOD generalization in the ICL framework.
weaknesses: In summary, I mainly miss a theoretical framework or at least some mathematical justifications for the things you claim and investigate. Without them a lot of your arguments felt only heuristically motivated and shallow. 

First, there are no theoretical results referenced or provided that support the premise that the constrained architecture should generalize better in the first place. The paper would benefit a lot from including mathematical reasoning in that direction. Given that the premise that learning an explicit representation of the task vector is necessary (not sufficient, that’s clear) for generalization is not well-supported in the first place, the results from Figure 2, which refute this premise, cannot be seen as an interesting contribution.

You should also be careful with the general statement that using parametric assumptions inevitably leads to better generalization than relying on non-parametric ones. It is, for instance, well-known that the posterior predictive of a Bayesian Linear Regression model is in fact equal to the posterior predictive of a Gaussian Process with an appropriate covariance function. The paper should thus state much more clearly, what is meant by “the model takes shortcuts”.

Furthermore, the results displayed in figure 4 do not provide as much evidence as claimed in the text for the hypothesis that the model accurately learns the task vector since the discrepancy compared to your trivial baseline is, except for the linear and sinusoidal case, not that large and, furthermore, using the ground-truth decoding function does not yield great benefits except for the linear and sinusoidal cases. 

There is further little evidence that the explicit model does not also utilize task vectors in some way or another as your counterfactual approach targets interpretability, which is, however, a different question. On the contrary, the results from “In-Context Learning Creates Task Vectors” are still very valid evidence that “implicit” transformers do in fact use task vectors. 

There are further several practical issues with the experiments: 
1.) The number of tasks you consider is quite small 
2.) The dimensionality of the data-points, which you set to 1 or 2  (see Appendix) is also very restricted
3.) You only consider a single and quite limited way of generating OOD samples for each task.

Finally, some sections of the paper are a bit lengthy or perhaps even unnecessary in the main body of the paper, such as the results displayed in figure 5, or the section on Meta-Learning in the related-works part. 

I also have a few issues with the reproducibility of your results:
1.) The code is not provided
2.) Please explicitly mention how many parameters your models have and on how many samples they are trained
3.) You should at least mention what the error bars in your plots represent, i.e. the standard error or the IQR or something else?

There are also a few typos, grammatical issues, and notational errors in the manuscript. For example when denoting functions or in the text on the axes of the plots. 

Finally, using a blogpost or a Wikipedia Article as a reference might be a possibility to give the reader a pointer to an accessible source of information, but it should clearly not be used as a sole reference.

As a small detail, I also find it a bit unusual that you neither use weight decay nor a learning rate schedule in your training.

Meta-review: The paper explores the question of whether learning task vectors explicitly or implicitly is more beneficial for generalization in in-context learning, presenting a series of experiments that compare the performance of explicit and implicit models on various tasks. However, despite the paper's interesting insights and experiments, the reviewers have raised significant concerns about the paper's contribution, arguing that the premise that learning task vectors is important for generalization is not well-supported and that the assumption that an optimal predictor needs to learn task vectors explicitly is not obvious. The authors have responded to these concerns with additional arguments and clarifications. However, after discussion with the authors and among themselves, the reviewers find the paper to still be very borderline, with three reviewers leaning towards acceptance and two towards rejection. We will therefore need to reject the paper in its current form. We would still like to encourage the authors to resubmit an improved version of the paper in the future.

Decision: Reject