Skip to main content

Toolkit for Neuron Analysis in Deep NLP Models

Project description

NeuroX Toolkit

Tests Runner API Reference

NeuroX provide all the necessary tooling to perform Interpretation and Analysis of (Deep) Neural Networks centered around Probing. Specifically, the toolkit provides:

  • Support for extraction of activation from popular models including the entirety of transformers, with extended support for other models like OpenNMT-py planned in the near future
  • Support for training linear probes on top of these activations, on the entire activation space of a model, on specific layers, or even on specific set of neurons.
  • Support for neuron extraction related to specific concepts, using the Linear Correlation Analysis method (What is one Grain of Sand in the Desert? Analyzing Individual Neurons in Deep NLP Models.). The toolkit can extract either a local ranking of neurons important to a particular target class, or a global ranking of neurons important to all the target classes.
  • Support for ablation analysis by either removing or zeroing out specific neurons to determine their function and importance.
  • Support for subword and character level aggregation across a variety of tokenizers, including BPE and all tokenizers in the transformers library.
  • Support for activation visualization over regular text, to generate qualitative samples of neuron activity over particular sentences.

A demo using a lot of functionality provided by this toolkit is available.

demo picture

Getting Started

This toolkit requires and is tested on Python versions 3.6 and above. It may work with older Python versions with some fiddling, but is currently not tested nor supported. The easiest way to get started is to use the published pip package:

pip install neurox

Manual Installation

If you wish to install this package manually (e.g. to modify or contribute to the code base), you can clone this repository into a directory of your choice:

git clone https://github.com/fdalvi/NeuroX.git

Add the directory to your python path. This can be done dynamically at runtime using the sys.path list:

import sys
sys.path.append("path/to/cloned/NeuroX/")

A Conda environment is provided with all the necessary dependencies for the toolkit. The toolkit primarily relies on PyTorch and NumPy for most of its operations. To create a new environment with all the dependencies, run:

conda env create -f conda-environment.yml -n neurox-toolkit
conda activate neurox-toolkit

If you wish to manage your enviroment in other ways, a standard requirements.txt is also provided for use by pip directly.

Sample Code

A Jupyter notebook with a complete example of extracting activations from BERT, training a toy task, extracting neurons and visualizing them is available in the examples directory for a quick introduction to the main functionality provided by this toolkit.

Documentation

API Reference contains an API reference for all of the functions exposed by this toolkit. Primarily, the toolkit's functionality is separated into several high-level components:

  • Extraction
  • Data Preprocessing
  • Linear Probing
  • Neuron extraction and interpretation
  • Neuron cluster analysis
  • Visualization

Citation

Please cite our paper published at AAAI'19 if you use this toolkit.

@article{dalvi2019neurox,
  title={NeuroX: A Toolkit for Analyzing Individual Neurons in Neural Networks},
  author={Dalvi, Fahim
    and Nortonsmith, Avery
    and Bau, D Anthony
    and Belinkov, Yonatan
    and Sajjad, Hassan
    and Durrani, Nadir
    and Glass, James},
  journal={Proceedings of the AAAI Conference on Artificial Intelligence (AAAI)},
  year={2019}
}

Planned features

  • Pip package
  • Support for OpenNMT-py models
  • Support for control tasks and computing metrics like selectivity
  • Support for attention and other module analysis

Publications

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

neurox-1.0.9.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

neurox-1.0.9-py3-none-any.whl (44.9 kB view details)

Uploaded Python 3

File details

Details for the file neurox-1.0.9.tar.gz.

File metadata

  • Download URL: neurox-1.0.9.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13

File hashes

Hashes for neurox-1.0.9.tar.gz
Algorithm Hash digest
SHA256 2aaa8d576ec8af8ea524129d8a54164cfeba5b9c22542426f9ddd8062ac66206
MD5 d9dd9292f8e6cf0f8b5373ba5bc0f627
BLAKE2b-256 ce0c268de3fd27c872370e3bd862d684ca1d445989d72524055b6e4e95e91f35

See more details on using hashes here.

File details

Details for the file neurox-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: neurox-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 44.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13

File hashes

Hashes for neurox-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d060ea6c7e3f7771b666940e682b0e1ae5a4491613f9eb9894641393beb76618
MD5 6f851958642262036b47c1a07feb5a6a
BLAKE2b-256 889ef7cc0859f40ca5fe421bd36e7fe1318b2519c31c9d69e9cdd273d937a72e

See more details on using hashes here.

Supported by

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