In-Context Learning as Implicit Policy Gradient
On the map: Deep reinforcement learning methods → RL training of language and agent models
Abstract (arXiv)
Recent work has shown that large language models (LLMs) can iteratively improve their outputs by incorporating generated samples and their corresponding evaluation scores as in-context examples. Despite these empirical findings, the theoretical foundations underlying this phenomenon remain poorly understood. In this paper, we show that score-conditioned In-Context Learning (ICL) admits a structural correspondence to policy gradient optimization. We first provide a constructive proof that self-attention mechanisms can implement reward-weighted aggregation analogous to the REINFORCE algorithm under specific weight matrix configurations, and discuss the relationship between this construction and the behavior of pretrained transformers. The correspondence is directional in hidden-state space and holds exactly only under the stated simplifying conditions; we quantify its strength empirically. Within our simplified hidden-state model, we furthermore derive an exact upper bound on the distribution shift induced by a bounded attention update, yielding a trust-region-like analogy to KL-constrained policy optimization. We validate our theory through extensive experiments across multiple LLMs, demonstrating that LLMs effectively utilize score information to shift output distributions toward high-scoring exemplars, and that attention weights exhibit a strong correlation with example scores.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Placed in RL training of language and agent models, one of 15 directions in Deep reinforcement learning methods. Builds on 37 of its 44 references that are in the map. First posted on arXiv 25 Jul 2026.
Builds on
37 of 44 references.
References · 37
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2022Training language models to follow instructions with human feedbackcited by 15,971
- 2017Proximal Policy Optimization Algorithmscited by 15,215
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2021Training Verifiers to Solve Math Word Problemscited by 10,109
- 2023Judging LLM-as-a-Judge with MT-Bench and Chatbot Arenacited by 8,626
- 2023Direct Preference Optimization: Your Language Model is Secretly a Reward Modelcited by 8,065
- 2024GPT-4o System Cardcited by 4,588
- 2025Gemini 2.5: Pushing the Frontier with Advanced Reasoning, Multimodality, Long Context, and Next Generation Agentic Capabilitiescited by 3,796
- 2022Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedbackcited by 3,720
- 2023Self-Refine: Iterative Refinement with Self-Feedbackcited by 3,442
- 2015Trust Region Policy Optimizationcited by 2,580
25 more
- 2023Jailbreaking Black Box Large Language Models in Twenty Queriescited by 1,420
- 2022Large Language Models Are Human-Level Prompt Engineerscited by 1,045
- 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 938
- 2019DROP: A Reading Comprehension Benchmark Requiring Discrete Reasoning Over Paragraphscited by 903
- 2023Large Language Models as Optimizerscited by 864
- 2022Transformers learn in-context by gradient descentcited by 732
- 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 684
- 2024Self-Rewarding Language Modelscited by 681
- 2023Tree of Attacks: Jailbreaking Black-Box LLMs Automaticallycited by 672
- 2024JailbreakBench: An Open Robustness Benchmark for Jailbreaking Large Language Modelscited by 536
- 2022Transformer Feed-Forward Layers Build Predictions by Promoting Concepts in the Vocabulary Spacecited by 532
- 2023Dissecting Recall of Factual Associations in Auto-Regressive Language Modelscited by 528
- 2022RLPrompt: Optimizing Discrete Text Prompts with Reinforcement Learningcited by 366
- 2024Many-Shot In-Context Learningcited by 206
- 2022Why Can GPT Learn In-Context? Language Models Implicitly Perform Gradient Descent as Meta-Optimizerscited by 204
- 2022TEMPERA: Test-Time Prompting via Reinforcement Learningcited by 50
- 2022Large Language Models can Implement Policy Iterationcited by 31
- 2024LLMs Are In-Context Bandit Reinforcement Learnerscited by 29
- 2024Sampling-based Pseudo-Likelihood for Membership Inference Attackscited by 20
- 2025TROJail: Trajectory-Level Optimization for Multi-Turn Large Language Model Jailbreaks with Process Rewardscited by 14
- 2024Jailbreaking as a Reward Misspecification Problemcited by 11
- 2026Paraphrasing Adversarial Attack on LLM-as-a-Reviewercited by 8
- 2026JailNewsBench: Multi-Lingual and Regional Benchmark for Fake News Generation under Jailbreak Attackscited by 6
- 2025Online Learning Defense against Iterative Jailbreak Attacks via Prompt Optimizationcited by 3
- 2025Think Outside the Policy: In-Context Steered Policy Optimizationcited by 3
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2025Scalable In-Context Q-Learning
- 2025Brewing Knowledge in Context: Distillation Perspectives on In-Context Learning
- 2024Does In-Context Learning Really Learn? Rethinking How Large Language Models Respond and Solve Tasks via In-Context Learning
- 2025From Compression to Expression: A Layerwise Analysis of In-Context Learning
- 2022Rethinking the Role of Scale for In-Context Learning: An Interpretability-based Case Study at 66 Billion Scale
- 2024Large Language Models Know What Makes Exemplary Contexts
- 2026When Context Returns: Toward Robust Internalization in On-Policy Distillation
- 2023Is attention required for ICL? Exploring the Relationship Between Model Architecture and In-Context Learning Ability