Neuro-Symbolic Contrastive Learning for Cross-domain Inference

Mingyue Liu, Ryo Ueda, Zhen Wan, Katsumi Inoue, Chris G. Willcocks · DOI

TL;DR

This paper introduces a neuro-symbolic contrastive learning framework that bridges pre-trained language models (PLMs) and Inductive Logic Programming (ILP). By using ILP to generate "hard" contrastive examples based on abstract logical meta-rules, the approach significantly enhances the cross-domain generalization and reasoning capabilities of language models on inference tasks.

What Problem Does This Paper Address?

While pre-trained language models (PLMs) excel at Natural Language Inference (NLI) tasks, they often cheat. Studies show they frequently rely on shallow heuristics—like looking only at the hypothesis sentence while ignoring the premise, or remaining completely indifferent when word order is shuffled. They struggle to genuinely infer underlying logical relationships, especially when tested on out-of-domain data.

Conversely, Inductive Logic Programming (ILP) is a symbolic machine learning approach that excels at learning clean, interpretable logical rules from very little data. However, ILP is discrete and brittle; it requires inputs to be perfectly and precisely specified, making it difficult to apply directly to the messy, ambiguous world of natural language.

The authors address this gap by creating a bridge: a neuro-symbolic framework that injects the structured rigor of symbolic logic into the smooth, differentiable space of deep neural networks.

Methods

The authors propose a Level 3 neuro-symbolic system (where a neural network and a symbolic system interact to solve complementary tasks) driven by Neuro-Symbolic Contrastive Learning.

The pipeline consists of the following key steps:

  1. Rule-Based Translation: They use LoLA (an extension of the Grammatical Framework) to seamlessly translate back and forth between first-order predicate logic and natural language.
  2. Meta-Rule Mapping: Instead of trying to force a PLM to learn discrete logical functions directly, they map natural language to abstract logical "meta-rules" (isomorphic templates).
  3. Hard Contrastive Pair Generation: Using ILP, they construct training triplets consisting of:
  4. Anchor ($E$): A baseline premise-hypothesis pair.
  5. Hard Positive ($E^+$): A pair from a completely different textual domain that shares the exact same underlying logical meta-rule structure.
  6. Hard Negative ($E^-$): A pair that is textually highly similar to the anchor but possesses a fundamentally different (and contradictory) logical structure.
  7. Contrastive Optimization: They fine-tune the language model (e.g., BERT or RoBERTa) using a contrastive loss function ($L_{cl}$). This loss pulls logically identical representations closer together in the embedding space while pushing logically distinct ones apart, effectively "carving" sharp logical structures into a continuous neural network.
Neuro-symbolic contrastive learning concept

Datasets

The authors evaluated their framework on three symbolic NLI datasets, augmented to introduce high linguistic and structural variability:

  • Popper Kinship Dataset: A benchmark ILP dataset focused on family relationships (e.g., defining a "grandparent" based on "parent" predicates).
  • City Transportation Dataset: A newly introduced, self-proposed dataset mapping train connections and feasible travel paths between various cities.
  • GILPS Ancestor Dataset: A larger family tree dataset containing multi-generational relationships, names, and genders, used primarily to test cross-domain transfer.

Key Insights and Ideas

  • Language Models Learn Logic Better in the Abstract: One of the paper's most striking findings is that language models achieve higher accuracy and better Spearman correlation when trained on raw logical forms (e.g., p(Ann, Amy)) rather than natural language text. Abstract representations strip away distracting surface-level textual features.
  • Isomorphic Rules Bridge Domains: By focusing on meta-rules, the model learns that the logic defining a family tree ("A is the grandparent of B because A is the parent of C and C is the parent of B") is mathematically identical to the logic of transit ("You can travel from City A to City B because you can go from A to C and C to B"). This allows for powerful cross-domain generalization.
  • Shaping the Topology: Continuous neural networks inherently struggle with the discrete, sparse nature of logical functions. Contrastive learning acts as a geometric tool to shape the embedding space, forcing the network to respect logical boundaries despite textual variations.

Key Results

The framework was evaluated against baseline BERT-Base and RoBERTa-Base models across in-domain, cross-domain, and cross-form (logic to natural language) tasks:

  • In-Domain Performance: On a combined Kinship and City dataset, adding Neuro-Symbolic Contrastive Learning boosted RoBERTa-Base's accuracy from 0.62 to 0.74.
  • Cross-Domain Transfer: When trained on the Kinship/City logic domains and evaluated on the entirely unseen Ancestor logic domain, RoBERTa-Base's accuracy jumped dramatically from 0.45 to 0.64.
  • Cross-Form Transfer: When trained on logical formulas and tested on natural language text, the neuro-symbolic CL framework successfully mitigated the typical accuracy drop, raising RoBERTa's performance from 0.53 to 0.62.

Limitations and Future Work

  • Template-Dependence: The translation between logic and natural language relies on rule-based templates via LoLA. This limits the fluidity and diversity of the generated text compared to open-ended human language.
  • Logic Complexity: The framework currently focuses on Horn clauses and relatively straightforward first-order logic templates. Scaling this to non-monotonic reasoning, probabilistic logic, or highly complex real-world arguments remains an open challenge.
  • Scale: The experiments were conducted on smaller base models (BERT and RoBERTa); exploring how this framework scales to Large Language Models (LLMs) is a natural next step.

Summary updated

Abstract

Pre-trained language models (PLMs) have made significant advances in natural language inference (NLI) tasks, however their sensitivity to textual perturbations and dependence on large datasets indicate an over-reliance on shallow heuristics. In contrast, inductive logic programming (ILP) excels at inferring logical relationships across diverse, sparse and limited datasets, but its discrete nature requires the inputs to be precisely specified, which limits their application. This paper proposes a bridge between the two approaches: neuro-symbolic contrastive learning. This allows for smooth and differentiable optimisation that improves logical accuracy across an otherwise discrete, noisy, and sparse topological space of logical functions. We show that abstract logical relationships can be effectively embedded within a neuro-symbolic paradigm, by representing data as logic programs and sets of logic rules. The embedding space captures highly varied textual information with similar semantic logical relations, but can also separate similar textual relations that have dissimilar logical relations. Experimental results demonstrate that our approach significantly improves the inference capabilities of the models in terms of generalisation and reasoning.
BibTeX
@inproceedings{liu2024neuro,
  author = {Mingyue Liu and Ryo Ueda and Zhen Wan and Katsumi Inoue and Chris G. Willcocks},
  title = {{Neuro-Symbolic Contrastive Learning for Cross-domain Inference}},
  booktitle = {ICLP},
  year = {2024},
  url = {https://openreview.net/forum?id=5oQ2E2Iqdh},
}
Figure