Process In-Context Learning: Confusion-Aware Demonstration Retrieval and Dynamic Insertion for Mathematical Reasoning
Abstract
In-context learning (ICL) has achieved strong results across a wide range of large language model (LLM) tasks. However, its effectiveness for problems that require step-by-step deduction, such as mathematical reasoning, is still not well understood. One major limitation of existing ICL methods is that demonstrations are chosen before inference and remain unchanged throughout reasoning. As a result, they cannot respond to confusion points that emerge during multi-step problem solving, such as uncertain calculations or missing logical transitions. When these confusion points are not resolved, they may propagate and ultimately degrade answer accuracy. To address this limitation, we propose Process In-Context Learning (PICL), a dynamic demonstration insertion framework for mathematical reasoning. PICL consists of two stages: 1) it identifies potential confusion points by analyzing semantics and entropy in the reasoning process and summarizes their core characteristics; 2) upon encountering these points, it retrieves relevant demonstrations from the demonstration pool that match the confusion context and inserts them directly into the ongoing reasoning process to guide subsequent steps. Experimental results show that PICL outperforms representative baselines by alleviating mid-process confusion, demonstrating the effectiveness of adaptive demonstration insertion for complex mathematical reasoning.