微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Elmo 嵌入错误

如何解决Elmo 嵌入错误

我正在使用 ELMO 为我的数据集创建嵌入,我总是收到此错误

embed=elmo(data,signature="default",as_dict=True)["elmo"]
TypeError: 'AutoTrackable' object is not callable 

我的代码就这么简单:

import tensorflow_hub as hub
import tensorflow as tf
elmo = hub.load("https://tfhub.dev/google/elmo/3")
embeddings = elmo(
    ["the cat is on the mat","dogs are in the fog"],as_dict=True)["elmo"]

解决方法

问题出在 TensorFlow 版本上。 ELMo 不适用于 tensorflow 2,请参阅 TensorFlow Hub 文档以检查 version 1version 2 中支持的文本嵌入。将 TensorFlow 版本更改为 1.15 后运行相同的代码即可解决问题。您还应该使用版本 1 的 hub.Module()(而不是 hub.load)。请参阅 this post 以了解如何更改版本。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。