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.10.tar.gz
.
File metadata
- Download URL: psyki-0.3.10.tar.gz
- Upload date:
- Size: 44.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 606e74d13dd54ac67f81b1c0829d95bfacd098495c63c2af792d0b2ddb509067 |
|
MD5 | 6714ba40a6770eb8083023ef446b409b |
|
BLAKE2b-256 | a59423b31e34b92ae7688424a445f4676b7521590da50c5e424b05ec744bbc16 |
File details
Details for the file psyki-0.3.10-py3-none-any.whl
.
File metadata
- Download URL: psyki-0.3.10-py3-none-any.whl
- Upload date:
- Size: 40.3 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 | 37a3368bebc595b012ee9cf21c41a49be8c3403657887de866e5de008b13f2cc |
|
MD5 | 86260b4f7d88504a9dc50c6af2404a64 |
|
BLAKE2b-256 | 2a2d41fe3ac6fcb8df12df5ce0228b9548bc4ace0ceb86bf4090398a7e649cc4 |