Introduction
While Large Language Models (LLMs) have achieved remarkable fluency, they frequently struggle with conditional reasoning—the capacity to derive conclusions based on whether specific, often nested, criteria are met. For instance, determining eligibility for a loan based on age, residency, and income requires precise logical navigation that standard prose often fails to support effectively.
Previous research has attempted to address this through "Program-of-Thoughts" prompting, which requires an external code interpreter. This paper explores a different hypothesis: can the mere representation of a problem as code trigger latent reasoning abilities in models trained on both text and code, even without execution?
Methodology: The Code Prompting Framework
The researchers introduce Code Prompting, a two-step "chain of prompts" designed to leverage the structured nature of programming languages:
- Transformation: A "converter" prompt directs the LLM to translate a natural language problem (a document and a question) into a structured code format. This representation uses variables for entities and
ifblocks for logical conditions, while retaining original text as comments. - Reasoning: The LLM then "reads" this generated code to produce a final natural language answer.
This approach was compared against standard text prompts and Chain-of-Thought (CoT) prompting across several benchmarks.
Experimental Setup and Datasets
The study utilized three challenging conditional reasoning benchmarks:
- ConditionalQA: Complex real-world scenarios (e.g., public policy eligibility) requiring multi-step condition checking.
- BoardgameQA: Logic-heavy tasks involving conflicting rules and game states.
- ShARC: Conversational regulatory snippets where models must determine eligibility or identify missing information.
Key Insights
Syntax as a Reasoning Trigger
A primary finding is that the syntax of code itself acts as a catalyst for reasoning. When code was "back-translated" into simplified natural language, performance dropped. This suggests that structural elements like indentation, logical operators, and explicit variable assignments help the model focus its attention more effectively than standard prose.
Enhanced State Tracking
LLMs often fail at "state tracking"—maintaining the truth value of a variable across long contexts. Code prompting mitigates this by assigning entities to explicit variables, making it easier for the model to reference distant facts accurately.
Bypassing the "Alignment Tax"
The researchers observed that models fine-tuned with RLHF (Reinforcement Learning from Human Feedback) are sometimes overly hesitant to provide decisive logical answers in text. Code prompting appears to bypass some of this "hesitation," leading to more accurate and decisive logical leaps.
Results
The performance improvements were significant across various model architectures:
- GPT-3.5: Achieved an average boost of 8.42 F1 points, with a peak improvement of 22.52 points on difficult logic tasks.
- Open-Source Models: Mixtral 8x7B and Mistral 7B saw gains of up to 7.75 and 16.78 points, respectively.
- Error Reduction: In probe experiments, GPT-3.5 made 30-60% fewer memory errors when tracking entity status in code format compared to text.
Conclusion and Future Work
Code prompting demonstrates that the way information is structured can be as important as the information itself. However, the method currently doubles inference costs due to the two-step process and is limited to models with significant code pretraining. Future research may focus on training smaller, specialized models for the code-conversion step or exploring other structured formats like mathematical notation to further elicit these latent reasoning capabilities.
Summary updated