This release is a pre-release and may not be stable for production use.
PSyKE
Some quick links:
Intro
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) or an OWL ontology containing SWRL rules.
PSyKE relies on 2ppy (tuProlog in Python) for logic support, which in turn is based on the 2p-Kt logic ecosystem.
Class diagram overview:
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, an Extractor is composed of
(i) a trained predictor (i.e., black-box used as an oracle) and
(ii) a set of feature descriptors, and it provides two methods:
extract: returns a logic theory given a dataset;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:
- Regression:
- ITER, builds and iteratively expands hypercubes in the input space. Each cube holds a constant value, that is the estimated output for the samples inside the cube;
- GridEx, extension of the ITER algorithm that produces shorter rule lists retaining higher fidelity w.r.t. the predictor.
- GridREx, extension of GridEx where the output of each hypercube is a linear combination of the input variables and not a constant value.
Users may exploit the PEDRO algorithm, included in PSyKE, to tune the optimal values for GridEx and GridREx hyper-parameters.
We are working on PSyKE to extend its features to encompass explainable clustering tasks, as well as to make more general-purpose the supported extraction algorithms (e.g., by adding classification support to GridEx and GridREx).
Users
End users
PSyKE is deployed as a library on Pypi, and it can therefore be installed as Python package by running:
pip install psyke
Requirements
- 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, it is possible to create an extractor from a predictor (e.g. Neural Network, Support Vector Machine, K-Nearest Neighbor, Random Forest, etc.) and from the dataset used to train the predictor.
Note: the predictor must expose a method named
predictto be properly used as an oracle.
End users
A brief example is presented in demo.py script in the demo folder.
Using sklearn iris dataset we train a K-Nearest Neighbor to predict the correct output 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.
Developers
Working with PSyKE codebase requires a number of tools to be installed:
- Python 3.9+
- JDK 11+ (please ensure the
JAVA_HOMEenvironment 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
- Clone this repository in a folder of your preference using
git_cloneappropriately - 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 code, then contributing back via pull request
- Commit often
- Stay in sync with the
develop(ormaster) branch (pull frequently if the build passes) - Do not introduce low quality or untested code
Issue tracking
If you meet some problems in using or developing PSyKE, you are encouraged to signal it through the project "Issues" section on GitHub.
Metadata
Release files for psyke 0.2.2.dev219
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| psyke-0.2.2.dev219.tar.gz | 84.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| psyke-0.2.2.dev219-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 173.8 kB
Release files / psyke-0.2.2.dev219.tar.gz
| Download URL | psyke-0.2.2.dev219.tar.gz |
|---|---|
| Size | 84.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e440adff7e0c96987af5abd4eee9f611a73924af1d35343d259e1199aa6cf72
|
|
BLAKE2b-256 checksum How to use checksums |
3b4e3eb4e129e9992a200924e66ac0f68b909d18929b97d91c17a2010ccaadf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Release files / psyke-0.2.2.dev219-py3-none-any.whl
| Download URL | psyke-0.2.2.dev219-py3-none-any.whl |
|---|---|
| Size | 89.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5c9b944c7f13e99ed73f3dcb86e413f3f6c864ca684ab9762eee2572cae0e12
|
|
BLAKE2b-256 checksum How to use checksums |
241008c9eeba8c5401190dc1923374da8039962f4a1f579870e25c03cfe9c9c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|