Transformers Handle Endogeneity in In-Context Linear Regression
Haodong Liang, Krishnakumar Balasubramanian, Lifeng Lai
TL;DR
This work investigates whether transformers can handle endogeneity in in-context linear regression by leveraging instrumental variables. The authors show that looped transformer architectures can implement a bi-level gradient-descent procedure that converges exponentially to the 2SLS solution and provide a theoretical excess-loss bound for in-context pretraining. Empirically, the pretrained transformer achieves performance on par with 2SLS in standard IV tasks and surpasses it under weak instruments or non-standard IV scenarios, including multicollinearity and non-linear IV effects. The results support using in-context pretraining as a robust tool for endogeneity-aware predictions and coefficient estimation, with potential real-world impact in causal inference tasks where IVs are imperfect or non-linear.
Abstract
We explore the capability of transformers to address endogeneity in in-context linear regression. Our main finding is that transformers inherently possess a mechanism to handle endogeneity effectively using instrumental variables (IV). First, we demonstrate that the transformer architecture can emulate a gradient-based bi-level optimization procedure that converges to the widely used two-stage least squares $(\textsf{2SLS})$ solution at an exponential rate. Next, we propose an in-context pretraining scheme and provide theoretical guarantees showing that the global minimizer of the pre-training loss achieves a small excess loss. Our extensive experiments validate these theoretical findings, showing that the trained transformer provides more robust and reliable in-context predictions and coefficient estimates than the $\textsf{2SLS}$ method, in the presence of endogeneity.
