tayloranalysis


Nametayloranalysis JSON
Version 0.2.8 PyPI version JSON
download
home_pagehttps://gitlab.etp.kit.edu/lsowa/tayloranalysis
SummaryTaylorcoefficient Analysis for pytorch models
upload_time2025-02-05 12:42:35
maintainerNone
docs_urlNone
authorArtur Monsch
requires_python<4.0,>=3.8
licenseGPL-3.0-only
keywords pytorch model analysis taylor coefficients
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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"](https://arxiv.org/abs/1803.08782)
(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 tayloranalysis
```

## 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](example/example.ipynb).


## Authors
- [Lars Sowa](https://github.com/lsowa)
- [Artur Monsch](https://github.com/a-monsch)

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.etp.kit.edu/lsowa/tayloranalysis",
    "name": "tayloranalysis",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "PyTorch, model analysis, Taylor coefficients",
    "author": "Artur Monsch",
    "author_email": "artur.monsch@kit.edu",
    "download_url": "https://files.pythonhosted.org/packages/cc/25/21a90407b1035ffa468c79fa74b64b6a0a6806a63c256d6a684ef79ddd13/tayloranalysis-0.2.8.tar.gz",
    "platform": null,
    "description": "# Taylorcoefficient Analysis for PyTorch modules\nThis is a pytorch implementation of the Paper\n[\"Identifying the relevant dependencies of the neural network response on characteristics of the input space\"](https://arxiv.org/abs/1803.08782)\n(S. Wunsch, R. Friese, R. Wolf, G. Quast).\n\nAs explained in the paper, the method computes the taylorcoefficients of a taylored model function.\n\nThe 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).\n\nThis module can be applied to any differentiable pytorch model.\n\n## Installation\n\n```\npip install tayloranalysis\n```\n\n## Usage\n\nImport tayloranalysis\n```\nimport tayloranalysis as ta\n```\nWrap either an already initialized PyTorch class instance or the class itself to extend it with the tayloranalysis functionality.\n```\nmodel = ...\nmodel = extend_model(model)\n```\nCompute taylorcoefficients: for example $<t_{0}>$, $<t_{0,1}>$ for a given sample x_test.\nHere you can also pass a reduction function to summarize the TCs, which are computed based on the `tctensor` `x_test`\n```\ncombinations = [(0,), (0,1)]\nx_test = torch.randn(#batch, #features)\nforwards_kwargs = {\"x\": x_test, \"more_inputs\": misc}\n\ntc_dict = model.get_tc(forward_kwargs_tctensor_key=\"x\",\n                        tc_idx_list=combinations, \n                        reduce_func=torch.mean,)\n```\nThe output in this example is a dict containing the taylorcoefficients $<\\mathrm{TC}_{0}>$, $<\\mathrm{TC}_{0,1}>$.\n\n## Maximal flexibility\n\nThis 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](example/example.ipynb).\n\n\n## Authors\n- [Lars Sowa](https://github.com/lsowa)\n- [Artur Monsch](https://github.com/a-monsch)\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-only",
    "summary": "Taylorcoefficient Analysis for pytorch models",
    "version": "0.2.8",
    "project_urls": {
        "Homepage": "https://gitlab.etp.kit.edu/lsowa/tayloranalysis",
        "Repository": "https://gitlab.etp.kit.edu/lsowa/tayloranalysis"
    },
    "split_keywords": [
        "pytorch",
        " model analysis",
        " taylor coefficients"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c89017f4f21ba0ef179f9c35c124e3fd7d568da95404e5bcd055b169e9ac82ac",
                "md5": "5e5d18ae0607795400dba3e71e4c3c62",
                "sha256": "6b0b065fd6e2a9a59b94d1265b6a254294f84f563e5c7f91fdb3248d29038d20"
            },
            "downloads": -1,
            "filename": "tayloranalysis-0.2.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5e5d18ae0607795400dba3e71e4c3c62",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 22287,
            "upload_time": "2025-02-05T12:42:34",
            "upload_time_iso_8601": "2025-02-05T12:42:34.225549Z",
            "url": "https://files.pythonhosted.org/packages/c8/90/17f4f21ba0ef179f9c35c124e3fd7d568da95404e5bcd055b169e9ac82ac/tayloranalysis-0.2.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc2521a90407b1035ffa468c79fa74b64b6a0a6806a63c256d6a684ef79ddd13",
                "md5": "26ce71389ae1383a6cdc96aa4029c83e",
                "sha256": "7cd6658bbd5e444d637c8093f2e0aef55ff351ab9501aa9479b2fb7ab6897a2c"
            },
            "downloads": -1,
            "filename": "tayloranalysis-0.2.8.tar.gz",
            "has_sig": false,
            "md5_digest": "26ce71389ae1383a6cdc96aa4029c83e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 19519,
            "upload_time": "2025-02-05T12:42:35",
            "upload_time_iso_8601": "2025-02-05T12:42:35.772187Z",
            "url": "https://files.pythonhosted.org/packages/cc/25/21a90407b1035ffa468c79fa74b64b6a0a6806a63c256d6a684ef79ddd13/tayloranalysis-0.2.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-05 12:42:35",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tayloranalysis"
}
        
Elapsed time: 0.44689s