Harnessing the Power of Large Language Models for Natural Language to First-Order Logic Translation

Yuan Yang, Siheng Xiong, Ali Payani, Ehsan Shareghi, Faramarz Fekri

Introduction

Neuro-symbolic reasoning aims to combine the linguistic flexibility of Large Language Models (LLMs) with the deterministic precision of symbolic solvers. A critical step in this process is the translation of natural language (NL) into formal representations like First-Order Logic (FOL). However, current LLMs often struggle with the rigid syntax and complex semantics of logic, and existing training datasets are frequently either too small or overly synthetic.

To address these challenges, researchers introduced MALLS (MAssive Logical Language dataset), a dataset of 28,000 verified NL-FOL pairs, and LOGICLLAMA, a model fine-tuned to bridge the gap between human speech and formal reasoning.

The MALLS Pipeline and Dataset

The MALLS dataset was constructed using a sophisticated pipeline designed to maximize diversity and quality. By prompting GPT-4 with an N-gram frequency counter to avoid repetitive concepts, the authors generated 34,000 pairs, which were then refined to 28,000 high-quality entries through automated syntax checking and expert human annotation.

Compared to existing datasets like LogicNLI (synthetic and template-based) or FOLIO (high quality but limited to 2,000 pairs), MALLS offers significantly higher vocabulary diversity and logical complexity, averaging 4.6 literals per rule.

LOGICLLAMA: Fine-Tuning and Logical RLHF

The researchers fine-tuned LLaMA-2 (7B and 13B) on the MALLS dataset. A key innovation in their training process is Logical Reinforcement Learning from Human Feedback (RLHF). Unlike traditional training that relies on surface-level text matching (e.g., BLEU scores), Logical RLHF uses a reward model based on Logical Equivalence (LE). By utilizing a truth-table-based solver, the model is rewarded for producing outputs that are logically identical to the ground truth, regardless of specific variable naming or syntactic variations.

Identifying Error Modes in General-Purpose LLMs

Even state-of-the-art models like GPT-4 exhibit consistent failures when translating logic. The researchers categorized several "error modes," including the inclusion of undefined free variables, incorrect usage of logical operators (like equivalence vs. implication), and failure to capture specific NL nuances like "becomes solid."

Common error modes in GPT-4's natural language to first-order logic translations.

Key Results and the Correction Paradigm

LOGICLLAMA demonstrates superior performance and robustness compared to general-purpose LLMs. One particularly effective application is the Correction Paradigm, where LOGICLLAMA acts as a "polisher" for initial FOL drafts generated by cheaper models like GPT-3.5.

Performance comparison of LogicLLaMA against various LLMs across LogicNLI, FOLIO, and MALLS datasets using BLEU and Logical Equivalence (LE) metrics.

As shown in the benchmarks, LOGICLLAMA-13B achieves performance levels comparable to GPT-4. Crucially, while most LLMs suffer significant performance degradation as logical complexity (number of literals) increases, LOGICLLAMA remains stable, suggesting it has internalized the underlying rules of formal logic rather than merely memorizing patterns.

Conclusion

The introduction of MALLS and LOGICLLAMA represents a significant step toward reliable neuro-symbolic AI. By moving beyond text-matching metrics toward logical equivalence and providing a massive, diverse dataset, this work enables more accurate translation of human intent into machine-verifiable logic. Future work will look to expand these capabilities to multi-sentence "story-to-logic" translations and broader logical formats.

Summary updated

BibTeX
@inproceedings{yang2024harnessing,
  author = {Yuan Yang and Siheng Xiong and Ali Payani and Ehsan Shareghi and Faramarz Fekri},
  title = {{Harnessing the Power of Large Language Models for Natural Language to First-Order Logic Translation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.acl-long.375},
}
Figure