Abstract
Large language models (LLMs) can refine their responses based on feedback, enabling self-improvement through iterative training or test-time refinement. However, existing methods predominantly focus on refinement within the same reasoning format, which may lead to non-correcting behaviors. We propose CaP, a novel approach that uses external tools to refine chain-of-thought (CoT) responses generated by the same or other LLMs. CaP employs a two-stage training process: supervised fine-tuning followed by preference optimization with DPO variants. Our observations highlight the critical role of preference optimization in enabling effective refinement. Additionally, we compare several sampling strategies to leverage CoT and tools at inference time. Experimental results demonstrate CaP's potential for effective cross-reasoning refinement and efficient inference.
Introduction
Self-refinement—the ability of a model to evaluate and correct its own responses—is a cornerstone of autonomous AI improvement. However, current LLMs often exhibit "non-correcting behavior" when refining solutions within the same reasoning modality (e.g., natural language Chain-of-Thought). Logical errors made in an initial attempt are frequently repeated in subsequent iterations.
To address this, we propose CaP (Chain-of-thought as context for Program-of-thought), a framework for cross-reasoning refinement. Instead of iterating within the same format, CaP uses an initial CoT draft as context to generate a code-based Program-of-Thought (PoT) solution. This shift to a deterministic, tool-based reasoning modality helps the model break out of logical loops and leverage the precision of external execution.
The CaP Framework
The CaP approach involves a two-stage training pipeline designed to instill robust correction behaviors:
- Supervised Fine-Tuning (SFT): The model is trained to generate a PoT refinement given the question, a prior CoT attempt, and a binary "critic" (Yes/No) assessment. While SFT teaches the model how to use the provided context, it often fails to induce actual correction, with models sometimes simply imitating the flawed logic of the draft.
- Preference Optimization (DPO): To move beyond simple imitation, we employ Direct Preference Optimization. This stage trains the model to distinguish between correct and incorrect code refinements, effectively teaching it to correct errors rather than just follow the context.
At inference time, we introduce the BoNBoN (Best-of-N CoT followed by Best-of-N PoT) sampling strategy. This method efficiently allocates computational resources by first identifying a high-quality CoT "draft" and then generating multiple code-based refinements to find the optimal final answer.
Experimental Results
We evaluated CaP using a training set of 1 million Chinese educational question-answer pairs and tested it on three major mathematical benchmarks: CM17K, APE, and CMATH.
Performance and Efficiency
As shown in the table below, CaP-DPO significantly outperforms base models and SFT-only baselines. For instance, a Qwen2-7B model using CaP-DPO improved its average accuracy from 83.8% to 89.5% through self-refinement.
Key Insights
- DPO is Essential: Preference optimization is the "secret sauce" that transforms a model from a context-follower into an effective refiner.
- Cross-Model Refinement: In a notable result, a 7B-parameter model trained with CaP was able to improve the outputs of a much larger 72B-parameter model (Qwen2-72B), increasing its average accuracy from 89.9% to 90.5%. This suggests that refinement is a specialized skill that can be distilled into smaller, more efficient models.
- Format Switching Benefits: Moving from natural language to code provides a "second opinion" that is less prone to the hallucinated logic common in pure text reasoning.
Conclusion and Future Work
CaP demonstrates the power of cross-reasoning refinement using external tools. While highly effective for CoT -> PoT transitions in mathematics, several challenges remain. We observed that the reverse process (PoT -> CoT) can actually degrade performance, suggesting that "alternating reasoning" loops require further study. Future work will also explore more complex, "error-aware" critics and the generalization of this approach to non-mathematical domains like symbolic logic or legal reasoning.
Summary updated