【问题标题】:Problem with loading pretrained Universal Sentence Encoder加载预训练通用句子编码器的问题
【发布时间】:2020-04-29 00:26:51
【问题描述】:

我在为 NLP 任务加载预训练模块时遇到问题,问题是由于我想的 tf 迁移。 Tensorflow 网站表示,如果正确给出签名变量,问题可能会得到解决。你能帮我更正这段代码吗?

TypeError: 'AutoTrackable' 对象不可调用

[代码]

import tensorflow_hub as hub
# enabling the pretrained model for trainig our custom model using tensorflow hub
module_url = "https://tfhub.dev/google/universal-sentence-encoder-large/3"
embed = hub.load(module_url)

# creating a method for embedding and will using method for every input layer 
def UniversalEmbedding(x):
    return embed(tf.squeeze(tf.cast(x, tf.string)), signature='default', as_dict=True)["default"]

【问题讨论】:

  • 我能够在 Google Colab 中运行它而没有任何错误,并且在两个版本的 tensorflow 中运行良好 - %tensorflow_version 1.x 和 %tensorflow_version 2.x。您使用的是哪个 IDE? TensorFlow 版本呢?

标签: python tensorflow nlp tensorflow2.0 pre-trained-model


【解决方案1】:

我是这个领域的新手,但我可以与您分享我为解决我的问题所做的工作:

  • 使用此命令检查您的 Tensorflow 版本:

    打印(张量流。版本

  • 您可以在运行 import tensorflow 之前运行以下代码来更改 TensorFlow 版本

%tensorflow_version 1.x

  • 我的 TF 版本是 1.x,我使用 hub.load(url) 并收到“Auto Trackable”错误消息,当我用 hub.Module(url) 替换它时,它解决了我的问题

  • 您可能会发现这些链接很有帮助!以防你不知道他们

https://tfhub.dev/google/elmo/3 https://www.tensorflow.org/hub/common_issues

祝你好运

【讨论】:

    猜你喜欢
    • 2021-06-01
    • 2020-09-09
    • 2022-01-27
    • 2020-03-06
    • 1970-01-01
    • 2021-05-05
    • 2021-04-01
    • 1970-01-01
    • 2021-01-31
    相关资源
    最近更新 更多