一个有助于分析神经模型隐藏激活的广泛工具集的库。
项目描述
诊断 ·

论文:https ://arxiv.org/abs/2011.06819
文档:https ://diagnose.readthedocs.io
该库包含一组可用于分析神经网络激活的模块,重点是 LSTM 和 Transformer 等 NLP 架构。特别是,它包含以下功能:
- 从不同类型的(语言)模型中提取激活并提供对这些存储激活的快速访问。
- 在提取的激活上训练诊断分类器( Hupkes et al., 2018 )。
- 与这些诊断分类器并行的训练控制任务(Hewitt & Liang,2019 )。
- 在模型上执行与模型无关 的特征归因( Murdoch et al., 2018 )。
- 在语言模型上运行广泛的语言套件有针对性的句法评估。
:tada:diagNNose已在BlackboxNLP 2020上展示!论文可以在这里找到。
文档可以在diagnose.readthedocs.io找到。
我们的库在 pip 正式注册,可以通过运行安装pip install diagnnose。Python 的首选版本≥3.6。所需的软件包在 中说明requirements.txt。
快速浏览
的工作流程diagNNose分为几个构建块,可以组合用于各种实验。
我们提供了一些示例来演示该库。这些脚本的交互式和更广泛的界面也以笔记本的形式提供:
激活提取
Extractor可以使用负责批处理和选择感兴趣的激活的方法来提取模型的激活。
细粒度的激活选择可以通过定义 a 来实现selection_func,它根据当前句子索引和语料库项目选择激活。
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()
研究使用diagNNose
- Jumelet、Zuidema 和 Hupkes(2019 年):分析神经语言模型:上下文分解揭示了数字和性别分配中的默认推理
引用
如果您打算diagNNose用于您的研究,请引用我们如下。请随时与我们联系,我们很乐意提供帮助!
@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",
}
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
diagNNose-1.1.tar.gz
(53.1 kB
查看哈希)
内置分布
diagNNose-1.1-py3-none-any.whl
(76.7 kB
查看哈希)