知行编程网知行编程网  2022-06-24 18:00 知行编程网 隐藏边栏 |   抢沙发  51 
文章评分 0 次,平均分 0.0

开源NLP模型可视化工具LIT,模型训练不再「黑箱」

来自 | 机器之心   编辑 | 陈萍、魔王

深度学习模型的训练就像是「黑箱操作」,知道输入是什么、输出是什么,但中间过程就像个黑匣子,这使得研究人员可能花费大量时间找出模型运行不正常的原因。假如有一款可视化的工具,能够帮助研究人员更好地理解模型行为,这应该是件非常棒的事。


近日,Google 研究人员发布了一款语言可解释性工具 (Language Interpretability Tool, LIT),这是一个开源平台,用于可视化和理解自然语言处理模型。


论文地址:https://arxiv.org/pdf/2008.05122.pdf
项目地址:https://github.com/PAIR-code/lit

LIT 重点关注模型行为的核心问题,包括:为什么模型做出这样的预测?什么时候性能不佳?在输入变化可控的情况下会发生什么?LIT 将局部解释、聚合分析和反事实生成集成到一个流线型的、基于浏览器的界面中,以实现快速探索和错误分析。


开源NLP模型可视化工具LIT,模型训练不再「黑箱」

该研究支持多种自然语言处理任务,包括探索情感分析的反事实、度量共指系统中的性别偏见,以及探索文本生成中的局部行为。

此外 LIT 还支持多种模型,包括分类、seq2seq 和结构化预测模型。并且它具备高度可扩展性,可通过声明式、框架无关的 API 进行扩展。

相关 demo,参见视频:


可以针对新颖的工作流程进行重新配置,并且这些组件是独立的,可移植的,且易于实现。

用户界面

LIT 位于一个单页 web 应用中,由多个工具栏和包含多个独立模块的主体部分组成。如果模块适用于当前模型和数据集,它们将自动显示。例如,显示分类结果的模块仅在模型返回 MulticlassPreds 时显示。

开源NLP模型可视化工具LIT,模型训练不再「黑箱」
LIT 用户界面

开源NLP模型可视化工具LIT,模型训练不再「黑箱」
LIT 的布局设计图。

功能

LIT 通过基于浏览器的用户界面(UI)支持各种调试工作流。功能包括:

  • 局部解释:通过模型预测的显著图、注意力和丰富可视化图来执行。

  • 聚合分析:包括自定义度量指标、切片和装箱(slicing and binning),以及嵌入空间的可视化。

  • 反事实生成:通过手动编辑或生成插件进行反事实推理,动态地创建和评估新示例。

  • 并排模式:比较两个或多个模型,或基于一对示例的一个模型。

  • 高度可扩展性:可扩展到新的模型类型,包括分类、回归、span 标注,seq2seq 和语言建模。 

  • 框架无关:与 TensorFlow、PyTorch 等兼容。


下面我们来看 LIT 的几个主要模块:

探索数据集:用户可以使用不同的标准跨模块(如数据表和嵌入模块)交互式地探索数据集,从而旋转、缩放和平移 PCA 或 UMAP 投影,以探索集群和全局结构。

开源NLP模型可视化工具LIT,模型训练不再「黑箱」

比较模型:通过在全局设置控件中加载多个模型,LIT 可以对它们进行比较。然后复制显示每个模型信息的子模块,以便于在两个模型之间进行比较。其他模块(如嵌入模块和度量模块)同时得到更新,以显示所有模型的最新信息。

开源NLP模型可视化工具LIT,模型训练不再「黑箱」

比较数据点:切换到选择工具栏中的「Compare datapoints」按钮,使 LIT 进入数据点比较模式。在这种模式下,主数据点选择作为参考数据点,并且在后续设置中都会以其为参考点进行比较。参考数据点在数据表中以蓝色边框突出显示。

开源NLP模型可视化工具LIT,模型训练不再「黑箱」

其他模块的具体细节,参见:https://github.com/PAIR-code/lit/blob/main/docs/user_guide.md

看了上面的介绍,你是不是迫不及待地想要上手试试这个炫酷的可视化工具?下面我们来看它的安装过程和示例。

安装教程

下载软件包并进行 Python 环境配置,代码如下:


安装并配置好环境,就可以体验工具包中自带的示例。

示例

1. 情绪分类示例

代码如下:


情绪分类示例是基于斯坦福情感树库微调 BERT-tiny 模型,在 GPU 上不到 5 分钟即可完成。训练完成后,它将在开发集上启动 LIT 服务器。

2. 语言建模类示例

要想探索预训练模型(BERT 或 GPT-2)的预测结果,运行以下代码:


更多的示例请参考目录:../lit_nlp/examples。

此外,该项目还提供了添加自己模型和数据的方法。通过创建定制的 demo.py 启动器,用户可以轻松地用自己的模型运行 LIT,类似于上述示例目录../lit_nlp/examples。

完整的添加过程,参见:https://github.com/PAIR-code/lit/blob/main/docs/python_api.md#adding-models-and-data。

参考链接:
http://www.iibrand.com/news/202008/1719096.html
https://github.com/PAIR-code/lit/blob/main/docs/user_guide.md
https://github.com/PAIR-code/lit/blob/main/docs/python_api.md#adding-models-and-data
https://medium.com/syncedreview/google-introduces-nlp-model-understanding-tool-ab840b456be3
<section style="white-space: normal;line-height: 1.75em;text-align: center;"><strong style="color: rgb(0, 0, 0);font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;widows: 1;background-color: rgb(255, 255, 255);max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong>完<strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong></span></strong></span></strong></section><pre><pre style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section><section style="margin-bottom: 15px;padding-right: 0em;padding-left: 0em;max-width: 100%;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 25.5938px;letter-spacing: 3px;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;font-family: 微软雅黑;caret-color: red;box-sizing: border-box !important;overflow-wrap: break-word !important;">为您推荐</span></strong></span></section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;">图灵奖得主Yann LeCun《深度学习》春季课程</section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;">你一定从未看过如此通俗易懂的YOLO系列解读 (下)</section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;">22课时、19大主题,CS 231n进阶版课程视频上线<br  /></section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;">数据分析入门常用的23个牛逼Pandas代码</section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="color: rgb(87, 107, 149);font-size: 14px;">如何在科研论文中画出漂亮的插图?</span><br  /></section></section></section></section></section></section></section></section></section>
开源NLP模型可视化工具LIT,模型训练不再「黑箱」

本篇文章来源于: 深度学习这件小事

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写

发表评论

表情 格式 链接 私密 签到
扫一扫二维码分享