Natural Language Embedded Programs for Hybrid Language Symbolic Reasoning

Tianhua Zhang, Jiaxin Ge, Hongyin Luo, Yung-Sung Chuang, Mingye Gao, Yuan Gong, Yoon Kim, Xixin Wu, Helen Meng, Jim Glass

Introduction

Large Language Models (LLMs) have demonstrated remarkable capabilities in natural language understanding and generation. However, they frequently struggle with tasks requiring precise symbolic or numeric reasoning, often falling victim to hallucinations or simple arithmetic errors during long-form generation. Existing methodologies like Chain-of-Thought (CoT) provide a reasoning trace in natural language but lack computational precision. Conversely, Program-of-Thought (PoT) utilizes code for mathematical operations but often fails to integrate the nuances of unstructured text effectively.

Natural Language Embedded Programs (NLEP) bridge this gap by prompting LLMs to generate full Python programs where natural language is stored within structured data types. This framework provides a computational "scaffold" for linguistic data, allowing for complex reasoning to be executed by a deterministic Python interpreter.

The NLEP Framework

The core of NLEP is a four-step modular structure that disentangles knowledge extraction from reasoning logic. When presented with a task, the model is prompted to generate a script following these stages:

  1. Library Imports: Loading necessary modules such as datetime or collections.
  2. Structured Knowledge: Defining variables (e.g., dictionaries) that encapsulate the natural language facts relevant to the problem.
  3. Function Definition: Implementing the algorithmic logic required to process the structured knowledge.
  4. Response Printing: Executing the logic and outputting the final result in a human-readable format.
The four-step modular structure of an NLEP script, illustrating the separation of structured knowledge and algorithmic logic.

For text classification tasks, NLEP employs a specialized approach by generating a decision tree. Each node represents a natural language criterion, and the classification is performed by traversing the tree using an efficient entailment model (e.g., RoBERTa). This hybrid approach combines the high-level planning of an LLM with the reliability of specialized natural language understanding (NLU) models.

Experimental Evaluation

The researchers evaluated NLEP across 16 diverse tasks categorized into three domains:

  • Math & Symbolic Reasoning: Including tasks like Tracking Shuffled Objects, Dyck Language (parenthesis matching), and the Chinese Remainder Theorem.
  • Question Answering (QA): Multi-hop reasoning tasks such as StrategyQA and instruction following in VicunaQA.
  • Text Classification: Sentiment analysis (SST2), grammatical correctness (CoLA), and emotion detection.

Key Results and Insights

NLEP demonstrated significant performance improvements, particularly when paired with GPT-4. In symbolic reasoning tasks, NLEP achieved an average accuracy of 91.6%, vastly outperforming CoT (57.2%) and PoT (83.9%).

Accuracy comparison of NLEP versus Chain-of-Thought (CoT) and Program-of-Thought (PoT) using GPT-4 and GPT-3.5-Turbo across symbolic reasoning tasks.

Beyond raw accuracy, NLEP offers several qualitative advantages:

  • Interpretability: The reasoning process is fully transparent as it is encoded in executable Python logic.
  • Task-Generality: A single general prompt can be applied to vastly different problem sets, suggesting that programming logic is a more universal medium for LLM reasoning than natural language alone.
  • Error Correction: Because the output is code, the system can automatically detect execution errors and prompt the LLM for a "retry," facilitating a form of automated self-correction.

Limitations and Future Directions

While NLEP excels at structured reasoning, it is less effective for tasks requiring creative, long-form natural language responses. In benchmarks like VicunaQA, NLEP outputs were often more concise and less detailed than standard LLM responses. Additionally, the effectiveness of the framework is highly dependent on the underlying model's coding proficiency; while GPT-4 shows excellent results, performance declines with smaller or less capable models.

Future research may involve incorporating NLEP-style data—programs containing natural language—directly into the pre-training phase of LLMs to further enhance their hybrid reasoning capabilities.

Summary updated

BibTeX
@inproceedings{zhang2024natural,
  author = {Tianhua Zhang and Jiaxin Ge and Hongyin Luo and Yung-Sung Chuang and Mingye Gao and Yuan Gong and Yoon Kim and Xixin Wu and Helen Meng and Jim Glass},
  title = {{Natural Language Embedded Programs for Hybrid Language Symbolic Reasoning}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-naacl.259},
}
Figure