Can Transformers Reason in Fragments of Natural Language?

Viktor Schlegel, Kamen V. Pavlov, Ian Pratt-Hartmann

Introduction

While state-of-the-art transformers like RoBERTa and XLNet achieve high accuracy on natural language inference (NLI) tasks, their "reasoning" capabilities remain a subject of debate. This study investigates whether these models truly grasp logical principles or merely overfit to superficial patterns and specific proof structures in synthetic datasets. By narrowing the focus to controlled fragments of English with unambiguous mathematical logic, the authors test if transformers can learn formal rules like syllogisms and relational reasoning when real-world noise is removed.

Methodology

The researchers employed a rigorous synthetic approach to evaluate logical reasoning. They defined five increasingly complex subsets of English and used a grammar-based generator to produce thousands of sentence sets. To ensure ground-truth accuracy, an Automated Theorem Prover (ATP) called Vampire was used to label each set as logically consistent (satisfiable) or contradictory.

Data generation and model evaluation pipeline.

The study distinguished between "random" problems, which might be solvable via simple heuristics, and "constructed" problems designed to require specific, multi-step logical chains. Three major models—RoBERTa, XLNet, and Electra—were fine-tuned on these datasets to predict satisfiability.

Datasets and Logical Fragments

The study utilized several synthetic datasets based on defined fragments of English, each representing a different level of logical complexity.

Overview of the controlled English fragments used in the study.

The fragments include:

  • $S^+$ (Extended Syllogistic): Basic "Every/Some/No" logic with noun-level negation.
  • $R$ and $R^+$ (Relational): Includes transitive verbs (e.g., "admires," "hates"). $R^+$ is theoretically the most complex (EXPTIME-complete).
  • $S_r$ and $S_{rn}$: Fragments involving relative clauses (e.g., "Every artist who is a dentist...").

"Hard" instances were specifically filtered based on "proof length"—the number of logical steps the ATP required to find a contradiction—to test the models' ability to handle deep reasoning chains.

Key Results and Insights

The experiments revealed a significant gap between performance on random data and true logical generalization:

  • The Memorization Trap: While models achieved high accuracy on random data (often >90%), performance plummeted when tested on "hard" versions of the same logic. This suggests models learn specific sentence patterns rather than underlying logical principles.
  • Brittleness to Chain Length: As the number of logical steps required to reach a conclusion increased, the models' ability to generalize degraded significantly. There was an average 25 percentage point gap between "easy" (short proof) and "hard" (long proof) problems.
  • Complexity vs. Difficulty: Interestingly, theoretically "harder" fragments (like $R^+$) did not always result in lower accuracy. Success depended more on the statistical distribution of training data than mathematical complexity.
  • Model Performance: On standard randomly generated sets, models scored impressively (e.g., 94% on $S_r$). RoBERTa showed some scaling potential, reaching 81% on $R^+$, but remained brittle to distribution shifts.

Conclusion

The findings suggest that current transformers act like "bad students" who memorize exam questions rather than learning the underlying math. When faced with specific logical configurations not seen during training, performance often drops to the level of random guessing.

Future work may involve exploring modular or model-based neural approaches, or providing models with logical formulas as additional supervision to help them internalize the underlying rules of formal logic.

Summary updated

BibTeX
@inproceedings{schlegel2022can,
  author = {Viktor Schlegel and Kamen V. Pavlov and Ian Pratt-Hartmann},
  title = {{Can Transformers Reason in Fragments of Natural Language?}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.768},
}
Figure