Sparx Implementation
Project description
SpArX: Sparse Argumentative eXplanations for Neural Networks
Packages:
The python version is 3.10.0.
Getting started
-
Clone repo from: https://github.com/SpArX-Group-10/SpArX
git clone https://github.com/SpArX-Group-10/SpArX
-
Install requirements:
pip install -r requirements.txt
Example
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
from sparx import FFNN, KMeansClusterer, LocalMerger, BokehVisualizer
# shrink to a decimal percentage
SHRINK_TO_PERCENTAGE = 0.5
shape = (4, 6, 6, 3)
model = Sequential([
Dense(shape[1], activation='relu', input_shape=(shape[0],)),
Dense(shape[2], activation='relu'),
Dense(shape[3], activation='relu'),
])
weights = [layer.get_weights()[0] for layer in model.layers]
bias = [layer.get_weights()[1] for layer in model.layers]
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
activations = ["relu"] * 3
restored_model = FFNN(shape, weights, bias, activations)
# forward pass a [10 x 4] matrix, two data points with 4 features
np.random.seed(42)
dataset = np.random.rand(10, 4)
restored_model.forward_pass(dataset)
# cluster into 2 clusters
cluster_labels = KMeansClusterer.cluster(restored_model, SHRINK_TO_PERCENTAGE)
# merge clusters
merged_model = LocalMerger.merge(restored_model, cluster_labels)
restored_model.model.summary()
merged_model.model.summary()
# Bokeh Visualizer - to visualise neural networks locally
BokehVisualizer.visualise(merged_model)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sparx-lib-1.0.1.tar.gz
(19.8 kB
view hashes)
Built Distribution
sparx_lib-1.0.1-py3-none-any.whl
(21.9 kB
view hashes)
Close
Hashes for sparx_lib-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 063505aaa916197b8399fa42e718f99f314b9a63f6164b0cc710effd2e73bb9e |
|
MD5 | 45a353804920e0204b9488e2b4a8e8cc |
|
BLAKE2b-256 | 29560ceeb138bb7aa65f735aa405b6efd24190d641d16bb00741b023cf28d6bc |