Eliciting and Improving the Causal Reasoning Abilities of Large Language Models with Conditional Statements

Authors

  • Xiao Liu Peking University
  • Da Yin University of California, Los Angeles
  • Chen Zhang Peking University
  • Dongyan Zhao Peking University
  • Yansong Feng Peking University

Abstract

Causal reasoning, the ability to identify cause-and-effect relationships, is crucial in human thinking. Although large language models (LLMs) succeed in many NLP tasks, it is still challenging for them to conduct complex causal reasoning like abductive reasoning and counterfactual reasoning. Complex causal structures are rarely expressed explicitly in the text, which could make learning them challenging for LLMs. Given the fact that programming code may express
causal relations more often and explicitly with conditional statements like if, we want to explore whether large language models of code (Code-LLMs) acquire better causal reasoning abilities, and whether code prompts better describe the causal structure than text prompts. Our experiments show that compared to general-purpose LLMs like LLAMA-2 and GPT-3, Code- LLMs like CODELLAMA and CODEX are significantly better in causal reasoning. Code prompts not only work well for Code-LLMs, but also help improve the performance of most general purpose LLMs. To understand why code prompts are effective, we intervene on the prompts from different aspects, and discover that the programming structure is crucial in code prompt design, while models are more robust towards format perturbations.We further explore whether exposing models with more code with conditional statements aids in enhancing causal reasoning abilities.

Published

2025-06-26