[Paper Review] Harnessing the Power of Large Language Models for Natural Language to First-Order Logic Translation
This paper introduces LogicLLaMA, a 7B-parameter LLaMA model fine-tuned via LoRA for direct natural language to first-order logic (NL-FOL) translation and correction of GPT-3.5 outputs. Using a novel SFT+RLHF framework on a 34K synthetic NL-FOL dataset (Malls), LogicLLaMA achieves GPT-4-level performance on FOLIO (0.849 LE) at a fraction of the cost, outperforming GPT-3.5 and matching GPT-4 in correction and direct translation tasks.
Translating natural language sentences to first-order logic (NL-FOL translation) is a longstanding challenge in the NLP and formal logic literature. This paper introduces LogicLLaMA, a LLaMA-7B model fine-tuned for NL-FOL translation using LoRA on a single GPU. LogicLLaMA is capable of directly translating natural language into FOL rules, which outperforms GPT-3.5. LogicLLaMA is also equipped to correct FOL rules predicted by GPT-3.5, and can achieve similar performance as GPT-4 with a fraction of the cost. This correction ability was achieved by a novel supervised fine-tuning (SFT) + reinforcement learning with human feedback (RLHF) framework, which initially trains on synthetically perturbed NL-FOL pairs to encourage chain-of-thought reasoning and then fine-tunes with RLHF on GPT-3.5 outputs using a FOL verifier as the reward model. To train LogicLLaMA, we present MALLS (large language $ extbf{M}$odel gener$ extbf{A}$ted N$ extbf{L}$-FO$ extbf{L}$ pair$ extbf{S}$), a dataset of 34K high-quality and diverse sentence-level NL-FOL pairs collected from GPT-4. The dataset was created by implementing a pipeline that prompts GPT-4 for pairs, and dynamically adjusts the prompts to ensure the collection of pairs with rich and diverse contexts at different levels of complexity, and verifies the validity of the generated FOL rules. Codes, weights, and data are available at $\href{https://github.com/gblackout/LogicLLaMA}{\small ext{https://github.com/gblackout/LogicLLaMA}}$.
Motivation & Objective
- To address the challenge of accurate and reliable natural language to first-order logic (NL-FOL) translation, which remains difficult for even state-of-the-art LLMs due to lack of logical grounding.
- To reduce the high cost and limited accessibility of powerful LLMs like GPT-4 for NL-FOL translation by creating a smaller, fine-tuned model that matches their performance.
- To develop a correction framework that improves the logical consistency and accuracy of outputs from weaker LLMs like GPT-3.5 through step-by-step reasoning and reinforcement learning with human feedback (RLHF).
- To create and release a high-quality, diverse, and verified dataset of 34K sentence-level NL-FOL pairs (Malls) generated from GPT-4 to support future research in NL-FOL translation.
Proposed method
- Fine-tuned a LLaMA-7B model using LoRA on a single GPU to enable efficient adaptation for NL-FOL translation.
- Created Malls, a 34K synthetic dataset of high-quality, diverse, and verified NL-FOL pairs by prompting GPT-4 with dynamic, context-aware instructions to ensure coverage across complexity levels.
- Constructed a perturbed FOL version of each NL-FOL pair to train the model in corrective reasoning, with a 'correction instruction' to guide the model toward the correct rule.
- Applied a two-stage training framework: first supervised fine-tuning (SFT) on perturbed pairs to teach chain-of-thought (CoT) reasoning, then reinforcement learning with human feedback (RLHF) using a FOL verifier as the reward model.
- Used iterative correction with a maximum number of generations per sample to evaluate the impact of CoT depth and optimize correction efficiency.
- Evaluated the model in both direct translation and correction modes on two benchmarks: LogicNLI and FOLIO, using FOL BLEU and logical equivalence (LE) scores.

Experimental results
Research questions
- RQ1Can a smaller, fine-tuned LLM match the NL-FOL translation performance of GPT-4 while significantly reducing inference cost?
- RQ2Does a two-stage SFT+RLHF training framework that incorporates chain-of-thought reasoning and FOL verification improve correction accuracy of GPT-3.5 outputs?
- RQ3To what extent can a synthetic, high-quality NL-FOL dataset (Malls) trained on GPT-4 outputs enable a smaller model to generalize to complex, expert-written logical statements?
- RQ4How does the number of correction steps (CoT generations) affect the final accuracy and efficiency of the correction process?
- RQ5Can a local, fine-tuned model like LogicLLaMA serve as a cost-effective alternative to prompting expensive LLMs like GPT-4 for NL-FOL translation tasks?
Key findings
- LogicLLaMA outperformed GPT-3.5 in both direct translation and correction modes on both FOLIO and LogicNLI benchmarks, achieving a logical equivalence (LE) score of 0.818 on FOLIO and 0.965 on LogicNLI.
- The RLHF CoT correction method achieved an LE score of 0.849 on FOLIO, closely approaching GPT-4’s score of 0.855, demonstrating near-GPT-4-level performance at a fraction of the cost.
- The correction mode significantly outperformed direct translation, especially on complex examples where GPT-3.5 struggled, indicating that iterative correction enhances logical consistency.
- Performance saturated quickly with three or more correction generations, with 10 generations yielding only marginal gains over five, suggesting efficient convergence.
- The SFT+RLHF framework enabled LogicLLaMA to generate corrective reasoning steps that improved predicate and entity name accuracy, particularly on difficult examples.
- The Malls dataset, though silver-standard, enabled a 7B model to achieve GPT-4-level performance on a gold-standard benchmark, validating its utility for fine-tuning.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.