Skip to content

Add LNNClassifier for IBM LNN integration#132

Open
ColtonPayne wants to merge 1 commit intoadd-classifiersfrom
LNN-integration
Open

Add LNNClassifier for IBM LNN integration#132
ColtonPayne wants to merge 1 commit intoadd-classifiersfrom
LNN-integration

Conversation

@ColtonPayne
Copy link
Collaborator

@ColtonPayne ColtonPayne commented Feb 15, 2026

Summary

Introduces LNNClassifier, a bidirectional bridge between IBM Logical Neural Networks and PyReason. This enables a feedback loop where:

  • LNN reasons locally about individual entities using learned logical rules over bounded truth values [lower, upper]
  • PyReason propagates globally across graph structure using its rule engine
  • Feedback tightens bounds — PyReason's graph-level results feed back into the LNN as new evidence, producing results neither system achieves alone

Why this matters

LNN and PyReason both operate on interval-valued truth bounds [L, U], making them natural integration partners. But they have complementary blind spots:

Capability LNN PyReason
Local logical composition (e.g. expert ∧ endorsed → reliable) Yes No
Graph-structure propagation (e.g. traverse trust edges) No Yes

The LNNClassifier bridges this gap, enabling multi-hop reasoning that combines local logical inference with global graph propagation.

Verified with POC

Check it out here

Changes

New files

  • pyreason/scripts/learning/classification/lnn_classifier.py
    • LNNClassifier — wraps an IBM LNN Model; forward() runs inference and emits PyReason Fact objects; receive_feedback() injects PyReason bounds back as LNN evidence
    • LNNInterfaceOptions — configures convergence_threshold, max_feedback_rounds, bound_tightening_only

Modified files

  • pyreason/pyreason.py — conditional import of LNNClassifier / LNNInterfaceOptions when both torch and lnn packages are installed (graceful fallback to None otherwise)

Design decisions

  • Does NOT extend LogicIntegrationBase — LNN Model is not a torch.nn.Module, but LNNClassifier follows the same forward(data, t1, t2) → (raw, postproc, List[Fact]) interface contract
  • Bound tightening only (default) — feedback from PyReason only tightens LNN bounds, never widens them, preserving logical consistency
  • predicate_map bridges LNN's stateful Predicate objects to string names; node_groundings maps LNN grounding names to PyReason node names
  • target_predicates controls which LNN predicates export as PyReason Facts (not all need exporting)

Dependencies

  • Requires lnn package: pip install git+https://github.com/IBM/LNN
  • Optional — falls back gracefully when not installed

Test plan

  • Pre-commit hooks pass (ruff, unit tests with JIT enabled/disabled)
  • Trust network POC verified end-to-end (3 scenarios: LNN-only, PyReason-only, combined)
  • Graceful fallback when lnn not installed (LNNClassifier = None)

🤖 Generated with Claude Code

Introduces a bidirectional bridge between IBM Logical Neural Networks
and PyReason's graph-based reasoning engine. The LNNClassifier wraps an
LNN Model to produce PyReason Facts from logical inference, and accepts
feedback from PyReason's interpretation to tighten LNN bounds — enabling
a feedback loop where LNN reasons locally and PyReason propagates
globally.

New files:
- pyreason/scripts/learning/classification/lnn_classifier.py
  - LNNClassifier: forward() runs LNN inference and emits Facts;
    receive_feedback() injects PyReason bounds back into the LNN
  - LNNInterfaceOptions: convergence_threshold, max_feedback_rounds,
    bound_tightening_only

Modified files:
- pyreason/pyreason.py: conditional import of LNNClassifier when both
  torch and lnn packages are available

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant