Aligning with Logic: Measuring, Evaluating and Improving Logical Consistency in Large Language Models

Yinhong Liu, Zhijiang Guo, Tianya Liang, Ehsan Shareghi, Ivan Vulic, Nigel Collier · OpenReview

Abstract

Recent research in Large Language Models (LLMs) has shown promising progress related to LLM alignment with human preferences. LLM-empowered decision-making systems are expected to be predictable, reliable and trustworthy, which implies being free from paradoxes or contradictions that could undermine their credibility and validity. However, LLMs still exhibit inconsistent and biased behaviour when making decisions or judgements. In this work, we focus on studying logical consistency of LLMs as a prerequisite for more reliable and trustworthy systems. Logical consistency ensures that decisions are based on a stable and coherent understanding of the problem, reducing the risk of erratic or contradictory outputs. We first propose a universal framework to quantify the logical consistency via three fundamental proxies: transitivity, commutativity and negation invariance. We then evaluate logical consistency, using the defined measures, of a wide range of LLMs, demonstrating that it can serve as a strong proxy for overall robustness. Additionally, we introduce a data refinement and augmentation technique that enhances the logical consistency of LLMs without sacrificing alignment to human preferences. It augments noisy and sparse pairwise-comparison annotations by estimating a partially or totally ordered preference rankings using rank aggregation methods. Finally, we show that logical consistency impacts the performance of LLM-based logic-dependent algorithms, where LLMs serve as logical operators.

1. Introduction

As Large Language Models (LLMs) are increasingly deployed as "judges" in high-stakes decision-making and professional applications, there is a growing expectation for them to function as reliable "logical operators." However, current models often exhibit fickle and contradictory behaviors. For instance, when asked to compare three summaries (A, B, and C), an LLM might prefer A over B and B over C, yet inexplicably claim that C is better than A. Such violations of transitivity, along with positional biases and failures to handle negation, undermine the credibility of LLM-based systems. This paper formalizes a framework to measure these logical inconsistencies and introduces a method to rectify them.

2. Defining Logical Consistency

The authors identify three mathematical pillars essential for logical preference consistency:

  • Transitivity ($s_{tran}$): If a model prefers $A \succ B$ and $B \succ C$, it must logically prefer $A \succ C$. Violations are measured by identifying cycles in the model's pairwise judgment graphs.
  • Commutativity ($s_{comm}$): A model's judgment should remain invariant regardless of the order in which items are presented in the prompt (addressing positional bias).
  • Negation Invariance ($s_{neg}$): The model should provide consistent relative preferences even when the framing of the question is flipped (e.g., asking "Which is better?" versus "Which is worse?").
Figure 2: Visualization of commutativity and negation conflicts within pairwise preference matrices.

3. The REPAIR Framework

To improve these logical properties, the authors propose REPAIR (Ranking Estimation and Preference Augmentation through Information Refinement). This technique follows a three-step pipeline to "purify" model behavior:

  1. Rank Estimation: Noisy and inconsistent pairwise human data is aggregated using methods like Bradley-Terry or Elo ratings to estimate a single, coherent global ranking.
  2. Data Refinement and Augmentation: A new set of pairwise comparisons is generated based on the estimated global ranking, effectively removing logical contradictions. This set is then augmented with negated versions of the comparisons.
  3. Instruction Tuning: The target LLM (e.g., Llama-3) is fine-tuned on this logically refined dataset to align its internal decision-making with consistent logical principles.
Figure 1: Overview of the logical consistency framework, illustrating the transition from noisy human pairwise preferences to refined data and its application in logic-dependent algorithms.

4. Key Insights and Experimental Results

The study evaluated consistency across diverse domains, including summary coherence (SummEval), document reranking (NovelEval), and causal reasoning (CaTeRS).

The CoT Paradox

One surprising finding was that Chain-of-Thought (CoT) prompting—often a panacea for LLM reasoning—actually decreased transitivity in several cases. The authors suggest that the additional tokens in a CoT response may introduce subtle variations in judgment standards, leading to unintended contradictions.

Performance Gains

  • Baseline Leaders: Among off-the-shelf models, Gemma-2-9B, Phi-3-medium, and Deepseek-chat-v2 demonstrated the highest baseline logical consistency.
  • REPAIR Effectiveness: Training Llama-3-8B with REPAIR boosted transitivity and commutativity scores to nearly 100%. Furthermore, negation invariance ($s_{neg}$) jumped from approximately 60% to 88%, all while maintaining high alignment with human preferences.
  • Downstream Impact: Improving internal logic has significant benefits for logic-dependent algorithms. For example, sorting algorithms like PairS perform better and require fewer calibrations when the underlying LLM is logically consistent.

5. Conclusion and Future Directions

While logical consistency is a necessary condition for reliability, it is not a substitute for factual truth; a model can be perfectly logical yet factually incorrect. Future work will focus on scaling these logical measures to multi-item list-wise rankings and addressing the "forgetting effect" that can occur when models are over-exposed to negated relations during training. Ultimately, logical consistency serves as a vital proxy for overall model robustness and stability.

Summary updated

BibTeX
@misc{liu2024aligning,
  author = {Yinhong Liu and Zhijiang Guo and Tianya Liang and Ehsan Shareghi and Ivan Vulic and Nigel Collier},
  title = {{Aligning with Logic: Measuring, Evaluating and Improving Logical Consistency in Large Language Models}},
  year = {2024},
  eprint = {2410.02205},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.02205},
}
Figure