A library that facilitates a broad set of tools for analysing hidden activations of neural models.
Project description
diagNNose ·
Paper: https://arxiv.org/abs/2011.06819
Documentation: https://diagnnose.readthedocs.io
This library contains a set of modules that can be used to analyse the activations of neural networks, with a focus on NLP architectures such as LSTMs and Transformers. In particular, it contains functionality for :
- Extracting activations from different types of (language) models and providing quick access to these stored activations.
- Training diagnostic classifiers (Hupkes et al., 2018) on extracted activations.
- Training control tasks (Hewitt & Liang, 2019) parallel to these diagnostic classifiers.
- Performing model-agnostic feature attributions (Murdoch et al., 2018) on a model.
- Running a broad linguistic suite of targeted syntactic evaluations on a language model.
:tada: diagNNose
has been presented at BlackboxNLP 2020! The paper can be found here.
Documentation can be found at diagnnose.readthedocs.io.
Our library is officially registered with pip and can be installed by running pip install diagnnose
.
The preferred version of Python is ≥3.6. The required packages are stated in requirements.txt
.
Quick Tour
The workflow of diagNNose
is divided into several building blocks, that can be combined for various experiments.
We provide a few examples that demonstrate the library. An interactive and more extensive interface for these scripts is also provided in the form of a notebook:
Activation Extraction
The activations of a model can be extracted using an Extractor
that takes care of batching and selecting activations of interest.
Fine-grained activation selection is possible by defining a selection_func
, that selects an activation based on the current sentence index and corpus item.
from torchtext.data import Example
from diagnnose.config import create_config_dict
from diagnnose.corpus import Corpus
from diagnnose.extract import Extractor
from diagnnose.models import LanguageModel, import_model
from diagnnose.tokenizer.create import create_tokenizer
if __name__ == "__main__":
config_dict = create_config_dict()
tokenizer = create_tokenizer(**config_dict["tokenizer"])
corpus: Corpus = Corpus.create(tokenizer=tokenizer, **config_dict["corpus"])
model: LanguageModel = import_model(**config_dict["model"])
def selection_func(w_idx: int, item: Example) -> bool:
return w_idx == item.extraction_idx
extractor = Extractor(
model, corpus, selection_func=selection_func, **config_dict["extract"]
)
activation_reader = extractor.extract()
Research using diagNNose
- Jumelet, Zuidema & Hupkes (2019): Analysing Neural Language Models: Contextual Decomposition Reveals Default Reasoning in Number and Gender Assignment
Citing
If you intend on using diagNNose
for your research, please cite us as follows. Feel free to reach out, we'd love to help!
@inproceedings{jumelet-2020-diagnnose,
title = "diag{NN}ose: A Library for Neural Activation Analysis",
author = "Jumelet, Jaap",
booktitle = "Proceedings of the Third BlackboxNLP Workshop on Analyzing and Interpreting Neural Networks for NLP",
month = nov,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.blackboxnlp-1.32",
pages = "342--350",
}
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
Built Distribution
File details
Details for the file diagNNose-1.1.tar.gz
.
File metadata
- Download URL: diagNNose-1.1.tar.gz
- Upload date:
- Size: 53.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/1.6.1 pkginfo/1.5.0.1 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b83d3cb9638b5406b7ca7ba2241793efa5c16324aac5edd96a3d42b5cdfe4c8b |
|
MD5 | a1d459457e12d9a105d015a5c5455373 |
|
BLAKE2b-256 | 62cb6610aa6351468d3ed136f571b34e6c97baac3eac240d82f69aaf12de8410 |
File details
Details for the file diagNNose-1.1-py3-none-any.whl
.
File metadata
- Download URL: diagNNose-1.1-py3-none-any.whl
- Upload date:
- Size: 76.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/1.6.1 pkginfo/1.5.0.1 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2511d0232855baab23586ed883c109a805f011a220c823890d84c3c7224c808f |
|
MD5 | 05a239c8ec88dacdbeb63b626d67a218 |
|
BLAKE2b-256 | b6de4e6697dbf6d59cb0a115c3c54ee4764cbf95501441768b0b95e421ea7dcc |