Python-based implementation of PSyKI, i.e. a Platform for Symbolic Knowledge Injection
Project description
PSyKI
Platform for Symbolic Knowledge Injection
Some quick links:
Reference paper
Matteo Magnini, Giovanni Ciatto, Andrea Omicini. "[On the Design of PSyKI: A Platform for Symbolic Knowledge Injection into Sub-Symbolic Predictors]", in: Proceedings of the 4th International Workshop on EXplainable and TRAnsparent AI and Multi-Agent Systems, 2022.
Bibtex:
@inproceedings{PsykiExtraamas2022,
keywords = {Symbolic Knowledge Injection, Explainable AI, XAI, Neural Networks, PSyKI},
year = 2022,
talk = {Talks.PsykiExtraamas2022},
author = {Magnini, Matteo and Ciatto, Giovanni and Omicini, Andrea},
venue_e = {Events.Extraamas2022},
sort = {inproceedings},
publisher = {Springer},
status = {In press},
title = {On the Design of PSyKI: a Platform for Symbolic Knowledge Injection into Sub-Symbolic Predictors},
booktitle = {Proceedings of the 4th International Workshop on EXplainable and TRAnsparent AI and Multi-Agent Systems}
}
Intro
PSyKI (Platform for Symbolic Knowledge Injection) is a python library for symbolic knowledge injection (SKI). In the literature, SKI may also be referred as neuro-symbolic integration. PSyKI offers SKI algorithms (injectors) along with quality of service metrics (QoS) and other utility functionalities. Finally, the library is open to extendability.
More in detail
An Injector
is a SKI algorithm that may -- or may not -- take a sub-symbolic predictor in conjunction with prior symbolic knowledge to create a new predictor through the inject
method.
We refer to the new predictor as educated, while predictors that are not affected by symbolic knowledge are called uneducated.
Knowledge can be represented in many ways.
The most common is the representation via logic formulae.
PSyKI integrates 2ppy
, a python porting of 2p-kt
(a multi-paradigm logic programming framework).
Thanks to this integration, PSyKI supports logic formulae written with the formalism of Prolog.
Therefore, all subsets of the Prolog language (including Prolog itself) are potentially supported (e.g., propositional logic, Datalog, etc.).
It is worth noting that each injector may have its own requirements on the knowledge representation.
List of available injectors:
KBANN
, one of the first injector introduced in literature;KILL
, constrains a NN by altering its predictions using the knowledge;KINS
, structure the knowledge adding ad-hoc layers into a NN.
High level architecture
Class diagram representing the relations between Injector
, Theory
and Fuzzifier
classes
The core abstractions of PSyKI are the following:
Injector
: a SKI algorithm;Theory
: symbolic knowledge plus additional information about the domain;Fuzzifier
: entity that transforms (fuzzify) symbolic knowledge into a sub-symbolic data structure.
The class Theory
is built upon the symbolic knowledge and the metadata of the dataset (extracted by a Pandas DataFrame).
The knowledge can be generated by an adapter that parses the Prolog theory (e.g., a .pl
file, a string) and generates a list of Formula
objects.
Each Injector
has one Fuzzifier
.
The Fuzzifier
is used to transform the Theory
into a sub-symbolic data structure (e.g., ad-hoc layers of a NN).
Different fuzzifiers encode the knowledge in different ways.
To avoid confusion, we use the following terminology:
- rule is a single logic clause;
- knowledge is the set of rules;
- theory is the knowledge plus metadata.
Hello world
The following example shows how to use PSyKI to inject knowledge into a NN.
import pandas as pd
from tensorflow.keras.models import Model
from psyki.logic import Theory
from psyki.ski import Injector
def create_uneducated_predictor() -> Model:
...
dataset = pd.read_csv("path_to_dataset.csv") # load dataset
knowledge_file = "path_to_knowledge_file.pl" # load knowledge
theory = Theory(knowledge_file, dataset) # create a theory
uneducated = create_uneducated_predictor() # create a NN
injector = Injector.kins(uneducated) # create an injector
educated = injector.inject(theory) # inject knowledge into the NN
# From now on you can use the educated predictor as you would use the uneducated one
For more detailed examples, please refer to the demos in the demo-psyki-python repository.
Users
PSyKI is deployed as a library on Pypi, and it can therefore be installed as Python package by running:
pip install psyki
Requirements
- python 3.9+
- java 11
- 2ppy 0.4.0
- tensorflow 2.7.0
- numpy 1.22.3
- scikit-learn 1.0.2
- pandas 1.4.2
- codecarbon 2.1.4
Developers
Working with PSyKI codebase requires a number of tools to be installed:
- Python 3.9+
- JDK 11+ (please ensure the
JAVA_HOME
environment variable is properly configured) - Git 2.20+
Develop PSyKI with PyCharm
To participate in the development of PSyKI, we suggest the PyCharm IDE.
Importing the project
- Clone this repository in a folder of your preference using
git_clone
appropriately - Open PyCharm
- Select
Open
- Navigate your file system and find the folder where you cloned the repository
- Click
Open
Developing the project
Contributions to this project are welcome. Just some rules:
- We use git flow, so if you write new features, please do so in a separate
feature/
branch - We recommend forking the project, developing your stuff, then contributing back vie pull request
- Commit often
- Stay in sync with the
develop
(ormain | master
) branch (pull frequently if the build passes) - Do not introduce low quality or untested code
Issue tracking
If you meet some problem in using or developing PSyKI, you are encouraged to signal it through the project "Issues" section on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file psyki-0.3.12.dev2.tar.gz
.
File metadata
- Download URL: psyki-0.3.12.dev2.tar.gz
- Upload date:
- Size: 47.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d0923d90b57c49a84b162125beedb8e5e60c2d3a483f1ef4c33625e3d7c79e |
|
MD5 | f4ab7006ece7ad4501b8718d268548d0 |
|
BLAKE2b-256 | c80bfeaeff30c70d2b74cda9a2775ae35f2cfad6b74d0607c04131c37d59de0a |
File details
Details for the file psyki-0.3.12.dev2-py3-none-any.whl
.
File metadata
- Download URL: psyki-0.3.12.dev2-py3-none-any.whl
- Upload date:
- Size: 43.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d99c1c866b0b7123ff7561050ad3f397424c9436048a23e98b246d332940647f |
|
MD5 | dc6d928404b641e3b0c1025d8e8f7f5b |
|
BLAKE2b-256 | b539cf4ca77dbf903d24a9bb432e578c635d1a5526d96554fc731ca750bd8d16 |