Table of Contents
Fetching ...

Code-driven Number Sequence Calculation: Enhancing the inductive Reasoning Abilities of Large Language Models

Kedi Chen, Zhikai Lei, Xu Guo, Xuecheng Wu, Siyuan Zeng, Jianghao Yin, Yinqi Zhang, Qin Chen, Jie Zhou, Liang He, Qipeng Guo, Kai Chen, Wei Zhang

TL;DR

This work tackles inductive reasoning in large language models by introducing CodeSeq, a synthetic data pipeline that converts number sequences into algorithmic GTG problems solved via code. It combines case-based reflection in supervised fine-tuning with a solvability-aware reinforcement learning reward (CSSR) to teach LLMs to autonomously generate and verify cases. Experiments on open-source backbones show CodeSeq markedly improves GTG and several code-reasoning benchmarks while largely preserving OOD performance, even enabling small models to approach the performance of much larger models on inductive tasks. The approach demonstrates scalable, automated induction data construction and a principled framework for learning from both successes and failures, with potential extensions to broader inductive-reasoning and multimodal tasks.

Abstract

Large language models (LLMs) make remarkable progress in reasoning tasks. Among different reasoning modes, inductive reasoning, due to its better alignment with human learning, attracts increasing interest. However, research on inductive reasoning faces certain challenges. First, existing inductive data mostly focuses on superficial regularities while lacking more complex internal patterns. Second, current works merely prompt LLMs or finetune on simple prompt-response pairs, but do not provide precise thinking processes nor implement difficulty control. Unlike previous work, we address these challenges by introducing \textit{CodeSeq}, a synthetic post-training dataset built from number sequences. We package number sequences into algorithmic problems to discover their general terms, defining a general term generation (GTG) task correspondingly. Our pipeline generates supervised finetuning data by reflecting on failed test cases and incorporating iterative corrections, thereby teaching LLMs to learn autonomous case generation and self-checking. Additionally, it leverages reinforcement learning with a novel Case-Synergy Solvability Scaling Reward based on both solvability, estimated from the problem pass rate, and the success rate of self-directed case generation, enabling models to learn more effectively from both successes and failures. Experimental results show that the models trained with \textit{CodeSeq} improve on various reasoning tasks and can preserve the models' OOD performance.

Code-driven Number Sequence Calculation: Enhancing the inductive Reasoning Abilities of Large Language Models

TL;DR

This work tackles inductive reasoning in large language models by introducing CodeSeq, a synthetic data pipeline that converts number sequences into algorithmic GTG problems solved via code. It combines case-based reflection in supervised fine-tuning with a solvability-aware reinforcement learning reward (CSSR) to teach LLMs to autonomously generate and verify cases. Experiments on open-source backbones show CodeSeq markedly improves GTG and several code-reasoning benchmarks while largely preserving OOD performance, even enabling small models to approach the performance of much larger models on inductive tasks. The approach demonstrates scalable, automated induction data construction and a principled framework for learning from both successes and failures, with potential extensions to broader inductive-reasoning and multimodal tasks.

Abstract

Large language models (LLMs) make remarkable progress in reasoning tasks. Among different reasoning modes, inductive reasoning, due to its better alignment with human learning, attracts increasing interest. However, research on inductive reasoning faces certain challenges. First, existing inductive data mostly focuses on superficial regularities while lacking more complex internal patterns. Second, current works merely prompt LLMs or finetune on simple prompt-response pairs, but do not provide precise thinking processes nor implement difficulty control. Unlike previous work, we address these challenges by introducing \textit{CodeSeq}, a synthetic post-training dataset built from number sequences. We package number sequences into algorithmic problems to discover their general terms, defining a general term generation (GTG) task correspondingly. Our pipeline generates supervised finetuning data by reflecting on failed test cases and incorporating iterative corrections, thereby teaching LLMs to learn autonomous case generation and self-checking. Additionally, it leverages reinforcement learning with a novel Case-Synergy Solvability Scaling Reward based on both solvability, estimated from the problem pass rate, and the success rate of self-directed case generation, enabling models to learn more effectively from both successes and failures. Experimental results show that the models trained with \textit{CodeSeq} improve on various reasoning tasks and can preserve the models' OOD performance.
Paper Structure (81 sections, 5 equations, 19 figures, 14 tables)

This paper contains 81 sections, 5 equations, 19 figures, 14 tables.

Figures (19)

  • Figure 1: We package the number sequences into algorithmic problems with the help of their related information. Although a story description is used for packaging, we ensure each algorithmic problem takes the index of a sequence term as input and outputs the number corresponding to that index (if the input is $2$, what we actually want is to output the $2$-nd term of the sequence). Therefore, the code solution is the computational process of the number sequence’s general term. LLMs generate the code solution by means of the example cases (usually the first few terms, which help with thinking), and we can then verify the correctness of the solution on the test cases through code unit tests.
  • Figure 2: The pipeline of number sequence synthetic data. Sequence Algorithmization performs algorithmic problem generation and verifies the correctness of the problems. Case-based Reflection Injection generates SFT training data through case-based reflection and incorporates the process into CoT. Solvability-Estimated Selection estimates problem solvability using pass rates and selects RL training data accordingly. These two parts together form the post-training dataset for our CodeSeq.
  • Figure 3: Results on different training settings with Qwen2.5-7B-Instruct.
  • Figure 4: Scaling results on the number of reflection rounds and the number of sequence patterns.
  • Figure 5: We study the relationship between case generation in CoT and prediction accuracy. 'C-C' and C-F': when all CoT cases exist in the original number sequence, the code solution is correct or false; 'No-C' and 'No-F': when at least one case is missing, the code solution is correct or false.
  • ...and 14 more figures