Skip to main content

Neuro-Symbolic Model from scratch

Project description

Neuro-Symbolic Core: A Framework From Scratch

This project is an implementation of a neuro-symbolic artificial intelligence framework, built entirely from scratch in Python. The goal is to provide a reusable and scalable engine that unites neural networks and symbolic logic, inspired by concepts such as Logic Tensor Networks (LTNs).

The system is capable of learning from facts and logical rules, adjusting numerical representations (embeddings) and neural models to satisfy a knowledge base. It has been designed to be flexible, performant, and auditable.

Core Features

  • Tensor Engine with Dual Backend: A custom Tensor class with support for automatic differentiation (backpropagation). It operates with a pure Python backend for portability or a NumPy backend for high performance.

  • Dynamic Neural Network Modules: Build neural network architectures (Linear, ReLU, Sigmoid, etc.) dynamically from configuration files, without needing to change the code.

  • Configurable Logical Representation: Represent first-order logic formulas (∀, →, ∧, etc.) and choose the fuzzy logic semantics (t-norms) and quantifier aggregators best suited for your problem.

  • Extensible Training Framework: An abstract Trainer with a Callbacks system allows for cleanly injecting functionalities like ModelCheckpoint (to save the best model) and EarlyStopping.

  • Explainability and Governance: Includes tools for auditing inferences, capable of identifying which entities in the domain most influenced a model's decision.

Project Structure

neuro-symbolic-core/
  ├── benchmarks/ # Scripts for performance testing
  ├── examples/
  │ └── socrates/ # Example of how to use the library
  │ ├── config.yaml
  │ └── data/
  ├── src/ # The library's source code
  │ ├── explainability/
  │ │ └── explainer.py # (NEW) Inference audit tool
  │ ├── interpreter/
  │ │ ├── fuzzy_operators.py
  │ │ └── interpreter.py
  │ ├── logic/
  │ ├── module/
  │ │ └── factory.py # Neural network model factory
  │ ├── tensor/
  │ │ └── backend/ # Numerical backends (Python, NumPy)
  │ └── training/
  │ ├── callbacks.py # (NEW) Callback system
  │ └── trainer.py # Main training class
  └── ...

How to Use

1. Train the Model

Run the training script from an example. The library's Trainer will orchestrate the process, and the ModelCheckpoint callback will save the best-performing model.

# Run with the default backend (Python)
python examples/socrates/train.py

# To use the high-performance backend, set it at the beginning of your script:
# from src.tensor.backend import set_backend
# set_backend('numpy')

2. Run Inference and Audits

Use the inference script to ask a question to the trained model. Use the --explain flag to enable the governance report.

# Simple query
python src/inference/infer.py --query "Mortal(socrates)"

# Query with an explainability report
python src/inference/infer.py --query "Mortal(socrates)" --explain

The explainability report will show which constants from your domain (e.g., socrates, plato) had the greatest impact (as measured by the gradient) on the result of your query.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neuro_symbolic_core-0.1.0.tar.gz (35.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuro_symbolic_core-0.1.0-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file neuro_symbolic_core-0.1.0.tar.gz.

File metadata

  • Download URL: neuro_symbolic_core-0.1.0.tar.gz
  • Upload date:
  • Size: 35.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for neuro_symbolic_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b76e3aae6c40a427c98d2b674ed559d61f3bb94308a2c1d313c7b281b544fd5
MD5 b6e917003155c5289b1c445e2a53e874
BLAKE2b-256 9c9b77ad492c36e6e647718e543fc4c61c170b327f84163a820660c741b83e64

See more details on using hashes here.

File details

Details for the file neuro_symbolic_core-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for neuro_symbolic_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5c59ace6b48ac9b58955d2ddd64108d55240d593855b8d09486577c48294539
MD5 3596eed37fa8ffa1ea3056721f9b9bed
BLAKE2b-256 0009802fdc7f378aad4188e860d7836a50bd14539fd31fcc725cc0d1eb63f9fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page