Skip to main content

Taylorcoefficient Analysis for pytorch models

Project description

Taylorcoefficient Analysis for PyTorch modules

This is a pytorch implementation of the Paper "Identifying the relevant dependencies of the neural network response on characteristics of the input space" (S. Wunsch, R. Friese, R. Wolf, G. Quast).

As explained in the paper, the method computes the taylorcoefficients of a taylored model function.

The analysis of taylorcoefficients is the optimal method to identify not only first order feature importance, but also higher order importance (i.e. the importance of combined features).

This module can be applied to any differentiable pytorch model.

Installation

pip install git+https://gitlab.etp.kit.edu/lsowa/tayloranalysis.git

Usage

Import tayloranalysis

import tayloranalysis as ta

Wrap either an already initialized PyTorch class instance or the class itself to extend it with the tayloranalysis functionality.

model = ...
model = extend_model(model)

Compute taylorcoefficients: for example $<t_{0}>$, $<t_{0,1}>$ for a given sample x_test. Here you can also pass a reduction function to summarize the TCs, which are computed based on the tctensor x_test

combinations = [(0,), (0,1)]
x_test = torch.randn(#batch, #features)
forwards_kwargs = {"x": x_test, "more_inputs": misc}

tc_dict = model.get_tc(forward_kwargs_tctensor_key="x",
                        tc_idx_list=combinations, 
                        reduce_func=torch.mean,)

The output in this example is a dict containing the taylorcoefficients $<\mathrm{TC}{0}>$, $<\mathrm{TC}{0,1}>$.

Maximal flexibility

This package is designed in a way to allow for maximal flexibility. While the reduction function has to be specified (e.g. mean, median, absolute values etc.) the visualization is up to the user. At this point you should have a look at our example.

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tayloranalysis-0.2.4.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tayloranalysis-0.2.4-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file tayloranalysis-0.2.4.tar.gz.

File metadata

  • Download URL: tayloranalysis-0.2.4.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.20 Linux/4.18.0-553.32.1.el8_10.x86_64

File hashes

Hashes for tayloranalysis-0.2.4.tar.gz
Algorithm Hash digest
SHA256 5890cf75ba77caa222c9a9703863fcdf347cd44ccf27c011a782ea14e6e0d5dc
MD5 c8189a7385be35d1e8d8ec0a864bde19
BLAKE2b-256 8d80e35558b87c92f20c20ae52757dd12a0211e096eb6bfcf8bc5e14fffa8571

See more details on using hashes here.

File details

Details for the file tayloranalysis-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: tayloranalysis-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.20 Linux/4.18.0-553.32.1.el8_10.x86_64

File hashes

Hashes for tayloranalysis-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8fdd22a395ee2ada2fb92b4369aef71ea10f45a7a715f153a081c8314f945141
MD5 c1ee4bad31e674eb7f93f39a09e1acef
BLAKE2b-256 1ac0385f56c5fc442a21d7f2ed49b8b2d732c887209f6ab5544f3d9a98693501

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page