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 details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
sparx_lib-1.0.1-py3-none-any.whl
(21.9 kB
view details)
File details
Details for the file sparx-lib-1.0.1.tar.gz.
File metadata
- Download URL: sparx-lib-1.0.1.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3d6a756ed4f27dc5a15c6bd02ef349bc1c74818df164b9f97db4bb9ec7c8bfd
|
|
| MD5 |
57283399f14b3c7ef5ae6eb45b5ccd36
|
|
| BLAKE2b-256 |
b7a30669003ff99e502e56c5fb5756c2e40cc360095581d93e55b65f576f3bfc
|
File details
Details for the file sparx_lib-1.0.1-py3-none-any.whl.
File metadata
- Download URL: sparx_lib-1.0.1-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
063505aaa916197b8399fa42e718f99f314b9a63f6164b0cc710effd2e73bb9e
|
|
| MD5 |
45a353804920e0204b9488e2b4a8e8cc
|
|
| BLAKE2b-256 |
29560ceeb138bb7aa65f735aa405b6efd24190d641d16bb00741b023cf28d6bc
|