Abstract
Program-of-Thought (PoT), which aims to use programs instead of natural language in reasoning, is an important way for Large Language Models (LLMs) to solve mathematical problems. Since different programming languages excel in different areas, it is natural to use the most suitable language for solving specific problems. However, current research only focuses on single-language PoT, ignoring the differences between programming languages. Therefore, this paper proposes a multilingual program reasoning method, MultiLingPoT, and deeply explores the impact of multilingual integration in training and inference. This method allows the model to answer questions using multiple languages by fine-tuning on multilingual data, improving individual language reasoning accuracy by 2.5%. Additionally, prior and posterior selection methods are used to help the model select the most suitable language during inference, achieving 8% performance gains. Finally, code metric analysis shows that language differences manifest in encapsulation levels and implementation granularity, while strategic deviation from language conventions can enhance code performance.
Introduction
While Large Language Models have demonstrated remarkable proficiency in natural language tasks, complex mathematical reasoning remains a significant challenge. The Program-of-Thought (PoT) paradigm addresses this by prompting models to generate executable code, thereby offloading arithmetic and logical calculations to a deterministic interpreter.
Existing PoT research has focused almost exclusively on Python. However, the authors of MultiLingPoT argue that this mono-lingual approach overlooks the inherent specializations of different programming languages. Just as a mathematician might choose specific notation for different problems, LLMs can benefit from selecting languages like Matlab for matrix operations or C++ for ground-up logical implementations. MultiLingPoT investigates whether integrating multiple languages can fill the reasoning gaps inherent in a single-language approach.
Methodology
The MultiLingPoT framework consists of three primary stages designed to leverage multilingual diversity: training, selection, and analysis.
Multilingual Fine-Tuning
The researchers fine-tuned a CodeLlama-7B model on a custom-built dataset comprising over 41,000 high-quality, executable code samples. These samples were derived from standard benchmarks like GSM8K and MATH, with solutions generated in four target languages: Python, C++, Java, and Matlab. This stage ensures the model can fluently "think" in multiple programming paradigms.
Inference Selection Strategies
To determine the most effective language for a given query, the framework employs two distinct strategies:
- Prior Selection: The model predicts the optimal language before code generation. This is achieved through methods such as Case-Based Choice or small reward models.
- Posterior Selection: The model generates solutions in all four languages simultaneously. A selector—typically a Reward Model or a voting system—then evaluates the outputs to pick the most likely correct answer.
Analysis of Language Specialization
A core contribution of this work is the validation of the "Right Tool" hypothesis. By analyzing the frequency of keywords and the success rates of different languages across mathematical domains, the researchers found clear specializations.
Matlab significantly outperformed other languages in "Counting & Probability" and "Geometry," likely due to its native support for matrix and vector operations. Conversely, Python excelled in "Number Theory." Furthermore, the study found that training on multiple languages improved the model's performance in each individual language by approximately 2.5%, suggesting a cross-lingual synergy where learning diverse logical structures enhances general reasoning.
Experimental Results
MultiLingPoT demonstrated robust improvements across 12 different test sets, including SVAMP, NumGLUE, and ASDiv. Key performance metrics include:
- Overall Accuracy: Multilingual training provided a baseline boost of 2.5% over single-language models.
- Selection Gains: The Posterior LLM Reward Model achieved an 8% improvement over the best single-language output.
- Complex Problem Solving: On the challenging MATH dataset, the "Voting & Reward" strategy reached 40.53% accuracy, compared to the Python-only baseline of 34.54%.
Software metric analysis further revealed that successful code often prioritized procedural, step-by-step logic over complex encapsulation, suggesting that for LLMs, "clean code" conventions may sometimes conflict with reasoning transparency.
Conclusion and Future Work
MultiLingPoT proves that multilingual integration is a viable path for enhancing LLM reasoning. While the posterior selection strategy is highly effective, it comes with increased computational costs. Future research will focus on improving "Prior Selection" to reduce inference overhead and expanding the multilingual approach to other logic-heavy domains such as physics and symbolic logic.
Summary updated