LogiTorch: A PyTorch-based library for logical reasoning on natural language

Chadi Helwe, Chloé Clavel, Fabian M. Suchanek

Abstract

LogiTorch is an open-source Python library designed to unify the fragmented landscape of logical reasoning in natural language processing (NLP). Built on PyTorch, it provides a standardized framework for 14 popular datasets and 4 state-of-the-art models, enabling researchers to train, fine-tune, and evaluate reasoning systems with minimal boilerplate code.

Introduction

While Large Language Models (LLMs) like BERT and GPT-3 have revolutionized NLP, they still struggle significantly with logical reasoning. These models are often "distracted" by syntactic variations, trap words, or simple negations. Although the research community has developed numerous benchmarks (e.g., LogiQA) and specialized models (e.g., PRover), the field remains fragmented. Datasets exist in incompatible formats, and model implementations are often difficult to reproduce. LogiTorch aims to serve as a unified platform—similar to HuggingFace Transformers—specifically for the logical reasoning sub-field, facilitating easier benchmarking and model comparison.

Library Architecture

LogiTorch is built on top of PyTorch and the HuggingFace Transformers library. Its architecture is designed for modularity and ease of use, organized into five main pillars:

  1. Datasets: A unified interface where every dataset inherits from the standard PyTorch Dataset class, handling automatic downloading and wrapping.
  2. Data Collators: Components that transform raw dataset instances into the specific numerical or textual formats required by different models.
  3. Utilities: Specialized tools for reasoning-specific feature engineering, such as coreference resolution, logical expression extraction, and discourse delimitation.
  4. Models: Clean, documented re-implementations of established reasoning models to ensure compatibility.
  5. PyTorch Lightning Wrappers: Wrappers that automate training loops, multi-GPU scaling, and precision management.
The hierarchical structure of the LogiTorch library, organized into five core modules.

Supported Tasks and Datasets

The library currently supports 14 datasets across four primary logical reasoning tasks:

  • Multiple Choice Question Answering (MCQA): Includes AR-LSAT, ReClor, and LogiQA.
  • Question Answering (QA): Includes RuleTaker, ParaRules Plus, and AbductionRules.
  • Proof Generation: Includes ProofWriter, where models must provide the logical steps leading to an answer.
  • Textual Entailment (TE): Includes SNLI, MNLI, RTE, ConTRoL, and specialized "Negated" versions of standard datasets to test robustness against negation.

Experimental Validation

The authors validated LogiTorch by comparing their re-implementations against the original results reported in the source papers. For rule-based reasoning models like RuleTaker and PRover, LogiTorch achieved near-perfect accuracy (~99%) across various reasoning depths, matching the original benchmarks.

Comparison of accuracy between LogiTorch re-implementations and original paper results across different reasoning depths.

In the domain of Textual Entailment, the BERTNOT implementation achieved a validation accuracy of 90.4% on SNLI, slightly outperforming the original paper's 89.0%. These results demonstrate that the library's re-implementations are faithful and reliable for further research.

Conclusion and Future Work

LogiTorch addresses the "Wild West" nature of logical reasoning in NLP by providing a standardized, community-driven framework. By eliminating the boilerplate work of data munging and providing interpretable models (e.g., through proof generation), it allows researchers to focus on algorithmic innovation. Future updates intend to include newer architectures such as DAGN, Focal Reasoner, and LogiGAN.

Code Availability: https://github.com/LogiTorch/logitorch

Summary updated

BibTeX
@inproceedings{helwe2022logitorch,
  author = {Chadi Helwe and Chloé Clavel and Fabian M. Suchanek},
  title = {{LogiTorch: A PyTorch-based library for logical reasoning on natural language}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-demos.25},
}
Figure