Logically Consistent Language Models via Neuro-Symbolic Integration

Diego Calanzone, Stefano Teso, Antonio Vergari

Overview

Large Language Models (LLMs) frequently contradict themselves and struggle with basic logical rules like negation and implication. This paper introduces LoCo-LM (Logically Consistent Language Models), a neuro-symbolic approach that "bakes" logic directly into the model during fine-tuning using a differentiable semantic loss. By compiling logical constraints into efficient computational circuits, the authors produce models that are more factual and self-consistent than those relying on standard fine-tuning or slow external solvers.

The Problem: Factuality and Logical Inconsistency

Despite their impressive capabilities, LLMs are notoriously unreliable when it comes to truth and logic. They often suffer from two related issues:

  1. Factuality gaps: Generating information that contradicts established knowledge bases.
  2. Logical inconsistency: Contradicting themselves across different prompts (e.g., agreeing that "all birds can fly" and "an albatross is a bird," but then claiming "an albatross cannot fly").

Existing solutions usually fall into two camps: massive-scale fine-tuning (which is data-hungry and doesn't guarantee logic) or delegating reasoning to external symbolic solvers at inference time (which is computationally expensive and requires constant access to the solver). The authors seek a "middle ground": a way to teach the model to respect logical rules during a lightweight fine-tuning phase so that it remains consistent autonomously.

Methods: The LoCo-LM Framework

The core of the paper is the LoCo-LM framework, which integrates symbolic logic into the neural training process.

LoCo-LM Architecture
  • Semantic Loss (SL): Instead of just using standard Cross-Entropy (which looks at individual tokens), the authors use a "Semantic Loss." This loss function calculates the probability that the model’s beliefs satisfy a set of logical constraints (like $A \implies B$).
  • Knowledge Compilation: To make this loss differentiable and computationally tractable, the authors use Sentential Decision Diagrams (SDDs). They compile arbitrary propositional logic formulas into these "circuits," allowing the model to calculate "Weighted Model Counts"—essentially the total probability mass assigned to logically valid configurations—in milliseconds.
  • Neuro-Symbolic Integration: During fine-tuning (using LoRA for efficiency), the model is prompted with various facts. The probabilities it assigns to "True" or "False" for these facts are fed into the compiled circuit. The gradient of the Semantic Loss then pushes the model to adjust its internal weights to favor logically consistent outputs.

Datasets and Evaluation

The researchers evaluated their approach across three main benchmarks:

  • BeliefBank: A dataset of atomic facts and implications (e.g., "An albatross is a bird" $\implies$ "An albatross has feathers").
  • ConceptNet: Used to test "class-knowledge transfer," evaluating if a model can inherit properties from high-level categories.
  • EntailmentBank: A dataset featuring complex, multi-hop reasoning trees used to test how well the consistency holds up in deeper logical chains.

Key Insights

  • Logic as a Regularizer: By treating logical consistency as a training objective rather than an inference-time check, the model learns the structure of the knowledge rather than just memorizing strings.
  • The "SUPER" Loss: The framework allows for combining multiple types of constraints—negation, implication, and factual truth—into a single, unified loss function. This "multi-objective" optimization leads to a "positive transfer" effect where enforcing one rule often improves performance on others.
  • Generalization to Unseen Facts: One of the most striking findings is that LoCo-LMs can extrapolate. If a model is taught that "birds fly" and "an albatross is a bird," it becomes more likely to correctly (and consistently) predict that a "cockerel" flies, even if it wasn't specifically trained on the cockerel fact.
  • Eliminating Inference Overhead: Because the logic is baked into the weights, LoCo-LMs don't need to call an external solver during deployment, making them significantly faster than "plug-and-play" symbolic layers.

Key Results

  • Superior Consistency: On the BeliefBank silver set, LoCo-LLaMa-2 (7B) achieved a logical consistency score of 91%, compared to just 41% for the zero-shot base model and 35% for standard supervised fine-tuning.
  • Outperforming External Solvers: LoCo-Macaw outperformed ConCoRD (a state-of-the-art system using an external Max-SAT solver) in both factuality and consistency, while being roughly 34% faster at inference time.
  • Low-Data Efficiency: LoCo-LM showed remarkable resilience in low-data regimes.
Performance comparison across data subsets

As shown in the table above, LoCo-Macaw achieves high accuracy even when fine-tuned on only 5-10% of the available factual data, vastly outperforming standard cross-entropy (XENT) fine-tuning under the same constraints.

  • Scaling: The method was successfully applied to LLaMa-3.1 (8B), showing that the benefits of neuro-symbolic integration hold even as base models improve.

Limitations and Future Work

While promising, the approach has limitations. The model's "belief" can still fluctuate based on prompt phrasing, despite efforts to mitigate this. Additionally, the current work focuses on propositional logic; moving toward more complex logical operators (like first-order logic) is a necessary next step. The loss calculation also assumes that the model's probabilities for different facts are conditionally independent, which may not always hold true in complex linguistic contexts. Finally, the system requires a pre-defined set of rules and facts to compile the circuits. Future work might explore automatically "materializing" the model's own internal beliefs into rules.

Summary updated

BibTeX
@inproceedings{calanzone2025logically,
  author = {Diego Calanzone and Stefano Teso and Antonio Vergari},
  title = {{Logically Consistent Language Models via Neuro-Symbolic Integration}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=7PGluppo4k},
}
Figure