Skip to main content

Python-based implementation of PSyKE, i.e. a Platform for Symbolic Knowledge Extraction

Project description


Some quick links:

Reference paper

Federico Sabbatini, Giovanni Ciatto, Roberta Calegari, Andrea Omicini. "On the Design of PSyKE: A Platform for Symbolic Knowledge Extraction", in: WOA 2021 – 22nd Workshop “From Objects to Agents”, Aachen, Sun SITE Central Europe, RWTH Aachen University, 2021, 2963, pp. 29 - 48.


	articleno = 3,
	author = {Sabbatini, Federico and Ciatto, Giovanni and Calegari, Roberta and Omicini, Andrea},
	booktitle = {WOA 2021 -- 22nd Workshop ``From Objects to Agents''},
	editor = {Calegari, Roberta and Ciatto, Giovanni and Denti, Enrico and Omicini, Andrea and Sartor, Giovanni},
	issn = {1613-0073},
	keywords = {explainable AI, knowledge extraction, interpretable prediction, PSyKE},
	location = {Bologna, Italy},
	month = oct,
	note = {22nd Workshop ``From Objects to Agents'' (WOA 2021), Bologna, Italy, 1--3~} # sep # {~2021. Proceedings},
	numpages = 20,
	pages = {29--48},
	publisher = {Sun SITE Central Europe, RWTH Aachen University},
	series = {CEUR Workshop Proceedings},
	subseries = {AI*IA Series},
	title = {On the Design of {PSyKE}: A Platform for Symbolic Knowledge Extraction},
	url = {},
	volume = 2963,
	year = 2021


PSyKE (Platform for Symbolic Knowledge Extraction) is intended as a library for extracting symbolic knowledge (in the form of logic rules) out of sub-symbolic predictors.

More precisely, PSyKE offers a general purpose API for knowledge extraction, and a number of different algorithms implementing it, supporting both classification and regression problems. The extracted knowledge consists of a Prolog theory (i.e. a list of Horn clauses).

PSyKE relies on 2ppy (tuProlog in Python) for logic support, which is in turn based on the 2p-Kt logic ecosystem.

Class diagram overview:

PSyKE class diagram

PSyKE is designed around the notion of extractor. More precisely, an Extractor is any object capable of extracting a logic Theory out of a trained sub-symbolic regressor or classifier. Accordingly, any Extractor is composed of (i) a trained predictor (i.e., black-box used as an oracle) and (ii) a set of discrete feature descriptors (as some algorithms require a discrete dataset), and it provides two methods:

  • extract: given a dataset it returns a logic theory;
  • predict: predicts a value using the extracted rules instead of the original predictor.

Currently, the supported extraction algorithms are:

  • CART, straightforward extracts rules from both classification and regression decision trees;
  • Classification:
    • REAL (Rule Extraction As Search), generates a rule for each sample in the dataset if the sample isn't covered yet. Before ending the extraction the rules set is optimized;
    • Trepan, first it generates a decision tree using m-of-n expressions, than it extracts rule from it;
  • Regression:
    • ITER, builds and iteratively expands hypercubes in the input space. Each cube holds the estimated value of the regression for the inputs that are inside the cube. Rules are generated from the cubes' dimensions;
    • Gridex, coming soon.


End users

PSyKE is deployed as a library on Pypi, and it can therefore be installed as Python package by running:

pip install psyke


  • numpy 1.21.3+
  • pandas 1.3.4+
  • scikit-learn 1.0.1+
  • 2ppy 0.3.3+
Test requirements
  • skl2onnx 1.10.0+
  • onnxruntime 1.9.0+
  • parameterized 0.8.1+

Once installed, one can create an extractor from a predictor (e.g. Neural Networks, Support Vector Machines, K-Nearest Neighbor, Random Forests, etc.) and from the dataset used to train the predictor.

Note: the predictor must expose a method named predict to be properly used as oracle.

End users

A brief example is presented in script. Using sklearn iris dataset we train a K-Nearest Neighbor to predict the correct iris class. Before training, we make the dataset discrete. After that we create two different extractors: REAL and Trepan. We output the extracted theory for both extractors.

REAL extracted rules:

iris(PetalLength, PetalWidth, SepalLength, SepalWidth, setosa) :- PetalWidth =< 1.0.
iris(PetalLength1, PetalWidth1, SepalLength1, SepalWidth1, versicolor) :- PetalLength1 > 4.9, SepalWidth1 in [2.9, 3.2].
iris(PetalLength2, PetalWidth2, SepalLength2, SepalWidth2, versicolor) :- PetalWidth2 > 1.6.
iris(PetalLength3, PetalWidth3, SepalLength3, SepalWidth3, virginica) :- SepalWidth3 =< 2.9.
iris(PetalLength4, PetalWidth4, SepalLength4, SepalWidth4, virginica) :- SepalLength4 in [5.4, 6.3].
iris(PetalLength5, PetalWidth5, SepalLength5, SepalWidth5, virginica) :- PetalWidth5 in [1.0, 1.6].

Trepan extracted rules:

iris(PetalLength6, PetalWidth6, SepalLength6, SepalWidth6, virginica) :- PetalLength6 > 3.0, PetalLength6 in [3.0, 4.9].
iris(PetalLength7, PetalWidth7, SepalLength7, SepalWidth7, versicolor) :- PetalLength7 > 3.0.
iris(PetalLength8, PetalWidth8, SepalLength8, SepalWidth8, setosa) :- true.


Working with PSyKE 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 PSyKE with PyCharm

To participate in the development of PSyKE, we suggest the PyCharm IDE.

Importing the project

  1. Clone this repository in a folder of your preference using git_clone appropriately
  2. Open PyCharm
  3. Select Open
  4. Navigate your file system and find the folder where you cloned the repository
  5. 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 (or 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 PSyKE, you are encouraged to signal it through the project "Issues" section on GitHub.

Project details

Download files

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

Files for psyke, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size psyke-0.2.1.tar.gz (41.8 kB) File type Source Python version None Upload date Hashes View
Filename, size psyke-0.2.1-py3-none-any.whl (36.5 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page