huggingface-transformers - 将 HF 变压器 BERT 模型加载到 Allen NLP 解释模块中
问题描述
我正在寻找一种将 Allen NLP 解释模块与 HuggingFace 转换器 BERT 架构 BertForSequenceClassification 模型(用 pytorch 训练)结合使用的方法。
我找到了一个 Allen NLP 指南,其中介绍了解释模块的常见用法以及与我的模型结构不同的模型。
有人可以帮助我并描述转换可以加载到Predictor
对象中的 BertForSequenceClassification 模型的正确方法是什么?
在https://guide.allennlp.org/interpret#3找到的指南示例:
from allennlp.interpret.saliency_interpreters import SimpleGradient
from allennlp.predictors import Predictor
inputs = {"sentence": "a very well-made, funny and entertaining picture."}
archive = (
"https://storage.googleapis.com/allennlp-public-models/"
"basic_stanford_sentiment_treebank-2020.06.09.tar.gz"
)
predictor = Predictor.from_path(archive)
interpreter = SimpleGradient(predictor)
interpretation = interpreter.saliency_interpret_from_json(inputs)
print(interpretation)
解决方案
推荐阅读
- c# - 使用自动增量字段恢复 MySql 表中已删除的行
- android - 即使我使用生成的签名 APK 也没有安装 APK
- google-apps-script - 如何通过管理 SDK 获得经理的价值
- python-3.x - Python docx 无法从 word(.docx) 中读取项目符号
- sqlalchemy - 使用 DATABASE_URL 使用 sqlalchemy 连接到数据库
- linux - 在 Ubuntu 下将 Stata 输出发送到日志文件
- java - 弹性搜索仅索引数据库中最近添加的记录并忽略以前添加的记录
- reactjs - 使用 React Hooks 重新连接 Web 套接字
- c++ - G++ 命令抛出“预期的 '(' 用于函数样式转换或类型构造”
- reactjs - 当我们在 react 中点击 componentDidMount 时,组件安装在哪里?它是真正的 DOM 还是 VirtualDom?