Skip to main content

Logic Tensor Network Implementation (LTN_Imp)

Overview

This repository contains an implementation of Logic Tensor Networks (LTN) for Symbolic Knowledge Injection (SKI) into machine learning models. It is particularly relevant for neuro-symbolic AI, where structured domain knowledge is integrated into data-driven models to enhance interpretability, performance, and robustness.

This implementation has been used in the research paper:

Neuro-symbolic AI for Supporting Chronic Disease Diagnosis and Monitoring
Matteo Magnini, Giovanni Ciatto, Ahmet Emre Kuru, Christel Sirocchi, and Sara Montagna

For full reproducibility of the results reported in the paper, please refer to the commit:

Commit d363aff892f417d770b86253aa8011c4754e8987

Here, on the main branch, you can find the maintained and refactored codebase. Experiments on the Pima Indians Diabetes dataset are provided in the examples/medical/diabetes/demo.ipynb notebook.

Results summary of model performance against different data perturbations

image

Each dot represents the average performance of the model with 30 seeds on the same experiment configuration.

Features

  • LTN-based Knowledge Injection: Implements logic-based constraints in neural networks.
  • Medical AI Applications: Evaluates SKI on medical datasets, focusing on chronic disease prediction.
  • Performance & Robustness Analysis: Compares LTN with classical ML models in terms of accuracy, recall, and adherence to clinical guidelines.
  • Reproducible Experiments: Code used to generate results in the referenced paper.

Requirements

To set up the environment, install the necessary dependencies using Poetry:

poetry install

Usage

Running Experiments

To reproduce the experiments from the referenced paper, use the provided Jupyter Notebook:

examples/medical/diabetes/demo.ipynb

This notebook walks through the process of training and evaluating the LTN model, comparing it against classical ML baselines while considering:

  • Predictive performance (Accuracy, Recall, F1-score, MCC)
  • Logical adherence to clinical rules
  • Robustness under data perturbation (noise injection, missing data, label flipping)

Datasets

The primary dataset used in the experiments is:

  • Pima Indians Diabetes (PID) dataset: A benchmark dataset for diabetes prediction.

Model Architectures

The following models are implemented and compared:

  • Classic ML Models:
    • K-Nearest Neighbors (KNN)
    • Decision Tree (DT)
    • Random Forest (RF)
    • Logistic Regression (LR)
    • Multi-Layer Perceptron (MLP)
  • Logic Tensor Network (LTN): Incorporates symbolic knowledge via logical constraints.

Results Summary

The key findings from the experiments include:

  • LTN improves recall and balanced accuracy, making it more suitable for medical AI applications where false negatives must be minimized.
  • LTN exhibits higher adherence to clinical rules, ensuring predictions align with medical guidelines.
  • LTN demonstrates robustness to data perturbations, maintaining stable performance even with missing or noisy data.

For detailed results, refer to the paper.

Acknowledgments

Special thanks to the authors of the referenced paper and the contributors of the LTN_Imp repository.

License

This repository is released under the Apache 2.0 license.


For any issues or questions, feel free to open an issue.

Project structure

Overview:

<root directory>
├── ltn_imp/             # main package (should be named after your project)
│   ├── __init__.py         # python package marker
│   └── __main__.py         # application entry point
│   └── fuzzy_operators     # folder for all of the fuzzy operators
│   └── parsing             # folder for the parser utilizing NLTK Logic and all the needed files
│   
├── test/                   # test package contains unit tests
│   ├── parsing_tests       # folder for unit tests for parser
│   └── learning_tests      # folder for unit tests for fuzzy operators in optimization
│   
├── .github/                # configuration of GitHub CI
│   └── workflows/          # configuration of GitHub Workflows
│       └──  check.yml       # runs tests on multiple OS and versions of Python
│
├── LICENSE                 # license file (Apache 2.0 by default)
├── pyproject.toml          # declares build dependencies
└── poetry.toml             # Poetry settings

Metadata

Release files for ekuru_ltn 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ekuru_ltn 3.2.0
File Size Uploaded
ekuru_ltn-3.2.0.tar.gz 22.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ekuru_ltn 3.2.0
File Interpreter ABI Platform
ekuru_ltn-3.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.9 kB

Release files / ekuru_ltn-3.2.0.tar.gz

Download URL ekuru_ltn-3.2.0.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dc3f2a8bc1a716b927f51ef13b66832458099968514702fc2b8da77f31fb7dfc
BLAKE2b-256 checksum
How to use checksums
13928fa48ec9fac0c56e014c4d6f355e1966e9579468c4d4cea04b368f8d1057
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.11.5 Darwin/24.3.0

Release files / ekuru_ltn-3.2.0-py3-none-any.whl

Download URL ekuru_ltn-3.2.0-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c887ac80ca87169a8242c10b024c9d89da1d51b3aed2b5570bc6f2f46cc09385
BLAKE2b-256 checksum
How to use checksums
f0ac2e9ca71f354f05449b9d758cee1522f1608220157bc49201c06df8973db2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.11.5 Darwin/24.3.0

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.28.3

2 release files

2.28.2

2 release files

2.28.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page