This project explores the use of ILASP as a post-hoc method for interpreting Black-Box (BB) models such as Neural Networks, Support Vector Machines, and K-Nearest Neighbors. The repository includes files for creating the dataset of recipes (with raw data sourced from the GialloZafferano website), along with several files documenting studies and experiments on both the data and the performance of the black-box models. Finally, it contains files related to experiments using ILASP.
A full description of the dataset can be found here: https://zenodo.org/records/14068000
A full description of the experiments involved in this project can be found on the following articles:
[1] D.Fossemò, F.Mignosi, L.Raggioli, M.Spezialetti, F.A.D'Asaro. Using Inductive Logic Programming to globally approximate Neural Networks for preference learning: challenges and preliminary results. Proceedings of BEWARE-22, co-located with AIxIA 2022, November 28-December 2, 2022, University of Udine, Udine, Italy. CEUR Workshop proceedings. Vol. 3319. 67:83. 2023. Url: https://ceur-ws.org/Vol-3319/paper7.pdf
[2] F. A. D’Asaro, M. Spezialetti, L. Raggioli, S. Rossi, Towards an inductive logic programming approach for explaining black-box preference learning systems, Proceedings of the International Conference on Principles of Knowledge Representation and Reasoning 17 (2020) 855–859. DOI: https://doi.org/10.24963/kr.2020/88
[3] D.Fossemò, F.Mignosi, M.Spezialetti, Analisi comparativa di approcci di machine learning per un sistema di preferenze di cibi. Three-year degree thesis (D.Fossemò). DOI: http://hdl.handle.net/20.500.12319/3727
[4] M.D'Aviero F.Mignosi, M.Spezialetti, Apprendimento Induttivo di Answer Set Program per un sistema di preferenze di cibi. Three-year degree thesis (M.D'Aviero). DOI: http://hdl.handle.net/20.500.12319/2304
The code was initially developed as a prototype, not originally intended for publication, so it may appear somewhat less polished. To support the reproducibility of the experiments, we've added this section as a form of documentation. For a comprehensive understanding, we recommend reviewing the related materials, particularly the dataset description and reference [1]. Lastly, please pay attention to the NOTES included in this guide, as they provide clarification on some of the more intricate aspects of the code.
In the "Related materials" section is possible to find the complete dataset with a full description. That said, in the github folder is already present the dataset, and specifically:
- ./dataset_100 contains the recipes dataset
- ./answers_dataset contains the preferences dataset
- ./answers_dataset/answers_of_return contains the survey of return dataset
- ./Ordinamenti contains the files actually used for the training for the preference learning task, specifically:
- the three .csv files contains the raw ranking of recipes returned by users
- dataset_coppie.txt contains the final samples of rankings in the form of pairwise comparison (where ; is the division for pair)
- output_file.txt contains the labels of "dataset_coppie.txt"
- ./matrixes contains a visual representation of the preferences of a user on his set of recipes, where yellow cells means "row i preferred over column j", purple means "row j preferred over column i", while aqua green indicate the uncertainty.
After creating the Recipe Dataset, we applied Principal Component Analysis (PCA) and k-means clustering to generate surveys for building the preference dataset. The code for this process is found in ./PCA&Clustering.py. This script also generates several plots, which help determine the optimal number of Principal Components (PCs) to retain and the best 'k' value for k-means clustering. To prevent overwriting these plots with each execution, certain sections of the code are commented out. The generated plots and related data are stored in the ./PCA_data and cluster_data folders.
the code for training, tuning of hyper-parameter and testing of Support Vector Machines (SVM), k-Nearest Neighbors (kNN) and Neural Networks (NN), are stored respectively in ./SVMcode.py, KNNcode.py and "DEEPcodeFINAL.py". When executing the code it will be asked if you want to perform tuning of hyper-parameters (1), or testing (2). While for SVM and kNN everything is automated, for NN you need to change valuse on lines 920 -- 926 to choose hyperparameters. The results of SVM and kNN are reported in the folders ./SVM and ./KNN. Neural Networks otherwise have two dedicated folders:
- in ./results are stored the results of the Neural Network used as Black Box in further experiments.
- in ./NN_data are stored the trained Neural Networks used in the further experiments.
Specifically, the Neural Network saved in NN_data and used for further experiments has the following shape:
Activation Function | Nodes | |
---|---|---|
Input Layer | tanh | 64 |
Dropout | 10% rate | - |
Hidden Layer | relu | 64 |
Dropout | 10% rate | - |
Batch normalization | - | - |
Hidden Layer | linear | 64 |
Dropout | 10% rate | - |
Output Layer | Softmax | 3 |
Optimization Function | SGD | - |
Learning rate | 0.0005 | - |
NOTE: As described in Related Materials, the task solved by these models is a ternary classification task. The samples used are those reported in ./Ordinamenti/dataset_coppie.txt, while corresponding labes are reported in ./Ordinamenti/output_file.txt
As outlined in the introduction, the primary goal of this work is to approximate BB models, specifically focusing on approximating the NN described in the previous section’s table. The experiments are organized into two main categories: global approximation, which aims to explain the model’s overall reasoning, and local approximation, which focuses on explaining specific queries. Each of these categories is further divided based on the PCA preprocessing approach defined in [1], which includes direct PCA and indirect PCA. For each category, we conducted experiments on three sample datasets of different sizes: 45, 105, and 190 pairs.
NOTE: Due to an error, the folders containing datasets with 190 pairs (and related files) are labeled with the number 210. Unfortunately, we noticed this late in the project and decided to retain this naming for now. We plan to correct this in a future code update. As you go through this guide, please remember that any reference to folders labeled with 210 actually pertains to the dataset with 190 pairs.
From the point of view of folder organization, the code for global approximation is reported in ./ILASPcode/, while the code for local one is reported in ./ILASPcode/local/local/. Both of these folders contain the folders Data, Data8Component2Std and Data17Component2Std: the first one contains the data related to the experiment without using PCA, while the others contain the data when Indirect PCA is used. Direct PCA is adopted only in the global case, and its data are stored in the folder PCAexperiments. All these PCA subcase folders follow the same subfolder logic (which is designed to automate ILASP training as much as possible in all subcases), with some differences among global and local case.
- NNoutput contains the sampled dataset and the corresponding labels obtained using the BB.
- recipes contains the Background Knowledge (recipes dataset) and Language Bias, with different hyperparameters setting (i.e. maxp)
- users_new_version_second contains the brave orderings extrapolated from sampled dataset to compose with file on recipes to create the final desired .las file for training.
- NOTE: folders users and users_new_version contains the brave ordering with a slightly different syntax formatting. For the moment we left these folders as they are, but we are considering to delete them in future updates.
- users_original contains the brave ordering extrapolate from original dataset to compose with file on recipes to create the final desired .las file for training.
- final/users/ contains the final files obtained from the composition of desired background knowledge, language bias and brave orderings. It also contains .txt files where ILASP output are stored, and .sh files to train ILASP on more train files in parallel (using different shells).
- final_original/users/ correspond to the previous folder but when we are using the original dataset instead of sampled ones.
- testOutput contains the .csv files which collect the result of ILASP (testOutput_original for original dataset)
- statistics_sampled contains the final results, which are the means of estimators with regard to the users experimented. (statistics_original for original dataset)
- plots contains the final results plotted
NOTE: Differently from indirect PCA where sub-cases where collected by Data8Components2Std and Data17Components2Std folders, in direct PCA his subcases are identified by a number (5, 10, 15, 20) at the end of the just presented sub-folders.
NOTE: Some folder, as NNoutput are repeated even if they contains the same files (not always, for example sampled dataset in local approximation are different from global ones). We recognize this is not a best practice, and we will refactor in future version of the code.
the folders recipes, statistics, testOutput and final* are repeated, while the others are substituted with the folder sampled_recipes_zero, which subfolders are (for each sampled dataset and standard deviation used for the local approach):
- distances, in which are stored the files with computed distances between the queried pair and the pairs generated usig gaussian noise (used for ILASP training purpose)
- las_files, in which are stored the generated pairs using the gaussian noise
- user_predictions, in which are stored the labels given by the BB to the pairs generated using the gaussian noise
- .txt files, in which, for each experimented user, are reported the pairs for which is required an explanation.
* NOTE: as can be visible, in the github repository is missing the final folder, this was caused by the big memory space they occupies and storage policies of github.
NOTE: as in global case, some folder are repeated even if they contains the same files
Similarly the Code organization is repeated among global and local cases, but with some slightly differences.
In the following image is reported the workflow for global approximator (an arrow identify a dependency of the targetted code to be executed after the starting code):
* NOTE: as can be visible by github repository, there are varaints of this code, this since several experiments was made during the work. In the image are reported the mainly used codes.
NOTE: sometimes, in the code are reported folder references to read and write files. During the work these references were updated manually depending on the situation, also with help of search and substitute tools. An example is when referring "Data8Component2Std" folder instead of "Data17Component2Std" folder, or folders regarding the different sampled dataset, which are referred using their size as a sort of identifier.
As before, the local workflow is reported in the following image
The same note made for Global Code organization are valid in this case. Furthermore, an update to explain better the "getStatistics" in local case will arrive as soon as possible.
Two key files in this project are CompareStableModels.py and ilaspReadWriteUtils.py. As you may notice in the GitHub repository, these files appear in multiple locations. Each copy has minor differences, so we recommend keeping them in place without deleting or moving them. Typically, each folder references the specific version of the file stored within it.
Lastly, some files are not detailed here, as they are used for smaller tasks or experiments that did not yield significant results. In future updates, these files may be removed to create a more streamlined repository."