Package: psyki
PSyKIPlatform for Symbolic Knowledge InjectionSome quick links:GitHub RepositoryPyPi RepositoryIssuesReference paperMatteo 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}}IntroPSyKI (Platform for Symbolic Knowledge Injection) is a python library forsymbolic knowledge injection(SKI).
In the literature, SKI may also be referred asneuro-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 detailAnInjectoris 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 theinjectmethod.
We refer to the new predictor aseducated, while predictors that are not affected by symbolic knowledge are calleduneducated.Knowledge can be represented in many ways.
The most common is the representation via logic formulae.
PSyKI integrates2ppy, a python porting of2p-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 architectureClass diagram representing the relations betweenInjector,TheoryandFuzzifierclassesThe 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 classTheoryis 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.plfile, a string) and generates a list ofFormulaobjects.
EachInjectorhas oneFuzzifier.
TheFuzzifieris used to transform theTheoryinto 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:ruleis a single logic clause;knowledgeis the set of rules;theoryis the knowledge plus metadata.Hello worldThe following example shows how to use PSyKI to inject knowledge into a NN.importpandasaspdfromtensorflow.keras.modelsimportModelfrompsyki.logicimportTheoryfrompsyki.skiimportInjectordefcreate_uneducated_predictor()->Model:...dataset=pd.read_csv("path_to_dataset.csv")# load datasetknowledge_file="path_to_knowledge_file.pl"# load knowledgetheory=Theory(knowledge_file,dataset)# create a theoryuneducated=create_uneducated_predictor()# create a NNinjector=Injector.kins(uneducated)# create an injectoreducated=injector.inject(theory)# inject knowledge into the NN# From now on you can use the educated predictor as you would use the uneducated oneFor more detailed examples, please refer to the demos in thedemo-psyki-pythonrepository.UsersPSyKI is deployed as a library on Pypi, and it can therefore be installed as Python package by running:pip install psykiRequirementspython 3.9+java 112ppy 0.4.0tensorflow 2.7.0numpy 1.22.3scikit-learn 1.0.2pandas 1.4.2codecarbon 2.1.4DevelopersWorking with PSyKI codebase requires a number of tools to be installed:Python 3.9+JDK 11+ (please ensure theJAVA_HOMEenvironment variable is properly configured)Git 2.20+Develop PSyKI with PyCharmTo participate in the development of PSyKI, we suggest thePyCharmIDE.Importing the projectClone this repository in a folder of your preference usinggit_cloneappropriatelyOpen PyCharmSelectOpenNavigate your file system and find the folder where you cloned the repositoryClickOpenDeveloping the projectContributions to this project are welcome. Just some rules:We usegit flow, so if you write new features, please do so in a separatefeature/branchWe recommend forking the project, developing your stuff, then contributing back vie pull requestCommit oftenStay in sync with thedevelop(ormain | master) branch (pull frequently if the build passes)Do not introduce low quality or untested codeIssue trackingIf you meet some problem in using or developing PSyKI, you are encouraged to signal it through the project"Issues" sectionon GitHub.