Source code and instructions for the paper.
To install requirements:
pip install -r requirements.txt
You will also need to separately install GNU Parallel in order to execute run_combos.sh.
Additionally, create the following symlinks for basic functionality:
ln -s nn_large.py nn.py
ln -s data_utils_large.py data_utils.py
The main scripts are:
param_utils.py: Contains most parameter settings used throughout all scriptsdata_utils.py: Contains code for generating and extracting the datasetsnn.py: Contains the ANN model and training codeanalyze_info_flow.py: Considers a trained neural network and analyzes the information flows on the network using test datatradeoff_analysis.py: Makes use of the information flows analyzed byanalyze_info_flow.pyand attempts to use different pruning strategies (encoded incombos.txt) to evaluate bias-accuracy tradeoffsscaling_analysis.py: Makes use of the information flows analyzed byanalyze_info_flow.pyand evaluates dependence between information flow and effect of full-pruning for each edgerun_combo.sh: Bash script which runs analyses as necessary, parallelizing to the extent possible.info_measures.py: Utility script containing methods for estimating information measurespruning.py: Utility script containing methods for pruning an ANNutils.py: Miscellaneous utility functionsplot_tradeoff.py: Script used for plotting tradeoff resultsplot_scaling.py: Script used for plotting scaling resultscombos.txt: A text file containing a list of pruning combinations used bytradeoff_analysis.pyandplot_tradeoff.pyresults-<dataset>: Directories containing output data files used in the paper.
nn.py and data_utils.py do not exist at the start. There are two such files, one each for the small and the large ANN. These are created when you run run_combo.sh (see below).
The best way to re-run all analyses is to use run_combo.sh.
Start by setting dataset and info_meth in run_combo.sh:
dataset="tinyscm" # "tinyscm" represents the synthetic dataset. Change to "adult-small" or "adult-large" for the modified Adult dataset
info_meth="kernel-svm" # Change to "linear-svm" or "corr" for estimating information flow using linear-SVM or the Correlation-based approximation respectively
network="small" # Change to "large" for running the Adult dataset analysis on the larger ANN
Then, select which analysis needs to be run by setting the respective flags to 1. For example, the following settings will train, and analyze information flow, for 100 different ANN weight initializations, but will not run the tradeoff or scaling analyses.
retrain_flag=1 # Retrain if set
reanalyze_flag=1 # Reanalyze if set
run_tradeoff=0 # Run tradeoff if set
run_scaling=0 # Run scaling if set
runs=100 # How many trials to run
Use the num_parallel parameter to set the maximum number of jobs that can be run in parallel.
num_parallel=8 # Maximum number of jobs that can be run in parallel
After setting parameter values, run the script with no arguments:
./run_combo.sh
Note that running this script this will overwrite results in the respective results-<dataset> folder.
Set force_regenerate to True in param_utils.py. The synthetic dataset is stored in results-tinyscm/data-10000.pkl.
To set which pruning strategies to execute when using tradeoff_analysis.py, or which pruning strategies to plot when using plot_tradeoff.py, you will need to edit results-<dataset>/combos.txt. This file is present in ./combos.txt and is automatically copied over to results-<dataset>/combos.txt when you run run_combo.sh. This is a text file that has a very limited syntax, and is parsed to determine pruning combinations.
For example, combos.txt may contain:
biasacc-node-1
biasacc-edge-2
accbias-edge-4
accbias-path-1
This combos.txt file will run (or plot) the following four different pruning strategies:
- Metric: weighted bias-to-accuracy flow ratio; method: node; level: 1 node pruned
- Metric: weighted bias-to-accuracy flow ratio; method: edge; level: 2 edges pruned
- Metric: weighted accuracy-to-bias flow ratio; method: edge; level: 4 edges pruned
- Metric: weighted accuracy-to-bias flow ratio; method: path; level: 1 path pruned
The metric can be either biasacc or accbias, and the pruning method can be one of node, edge, or path (refer Section 3.2 in the main paper). The level must be a small integer, fewer than the total number of nodes/edges/paths in the ANN (see legends in the tradeoff plots for examples).
Note that we have provided exemplar combos.txt files under both results-tinyscm and results-adult-small. These are copies of combos_nodes.txt, which produce results for the node-pruning method. We have also provided examples of combos.txt for the edge-pruning and path-pruning methods under the respective results-<dataset> directory.
These scripts should work on the provided result data. But if re-running all analyses, please ensure the respective analysis has completed before attempting to plot.
For plotting tradeoff figures, set results-<dataset>/combos.txt as described above, and run
./plot_tradeoff.py <dataset> <info_meth>
Colors will not be replicated as in the paper.
For plotting scaling figures, simply run
./plot_scaling.py <dataset> <info_meth>
For plotting the ANN visualizations (shown in the appendix), run
./plot_utils.py <dataset> <info_meth> <run_number>
The run number is an integer between 0 and $runs (which was set in run_combo.sh).