Skip to main content

NLP 机器学习模型的可视化工具。

项目描述

生态标志

Ecco 是一个 Python 库,用于使用交互式可视化解释自然语言处理模型。

它提供了多个接口来帮助解释和直观基于Transformer的语言模型。阅读:解释 Transformer 语言模型的接口

Ecco 在 Jupyter 笔记本中运行。它建立在pytorchtransformers之上。

该库目前是一个研究项目的 alpha 版本。未准备好生产。欢迎您做出贡献,让它变得更好!

安装

# Assuming you had PyTorch previously installed
pip install ecco

文档

要使用该项目:

import ecco

# Load pre-trained language model. Setting 'activations' to True tells Ecco to capture neuron activations.
lm = ecco.from_pretrained('distilgpt2', activations=True)

# Input text
text = "The countries of the European Union are:\n1. Austria\n2. Belgium\n3. Bulgaria\n4."

# Generate 20 tokens to complete the input text.
output = lm.generate(text, generate=20, do_sample=True)

# Ecco will output each token as it is generated.

# 'output' now contains the data captured from this run, including the input and output tokens
# as well as neuron activations and input saliency values.

# To view the input saliency
output.saliency()

这将执行以下操作:

  1. 它加载了一个预训练的 Huggingface DistilGPT2 模型。它将它包装为一个 ecco LM对象,该对象可以做有用的事情(例如,它计算输入显着性,可以收集神经元激活)。

  2. 我们告诉模型生成 20 个令牌。

  3. 该模型返回一个 ecco OutputSeq对象。这个对象保存了输出序列,还保存了生成运行生成的大量数据,包括输入序列和输入显着性值。如果我们在from_pretrained()中设置activations=True,那么这也将包含神经元激活值。

  4. 输出现在可以产生各种交互式探索。示例包括:

# To view the input saliency explorable
output.saliency()

# to view input saliency with more details (a bar and % value for each token)
output.saliency(style="detailed")

# output.activations contains the neuron activation values. it has the shape: (layer, neuron, token position)

# We can run non-negative matrix factorization using run_nmf. We pass the number of factors/components to break down into
nmf_1 = output.run_nmf(n_components=10)

# nmf_1 now contains the necessary data to create the interactive nmf explorable:
nmf_1.explore()

变更日志

0.0.8 (2020-11-20)

  • 让项目有一些新鲜空气。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

ecco-0.1.2.tar.gz (65.6 kB 查看哈希

已上传 source

内置分布

ecco-0.1.2-py2.py3-none-any.whl (70.7 kB 查看哈希

已上传 py2 py3