【问题标题】:pruned(text): expected argument #0(zero-based) to be a Tensor; got list (['Roasted ants are a popular snack in Columbia'])修剪(文本):预期参数#0(从零开始)是张量; got list (['烤蚂蚁在哥伦比亚很受欢迎'])
【发布时间】:2021-01-02 17:21:12
【问题描述】:

这是使用 EMLo 获取嵌入的代码。

import tensorflow_hub as hub

import tensorflow as tf

elmo = hub.Module("https://tfhub.dev/google/elmo/2")

x = ["Roasted ants are a popular snack in Columbia"]


embeddings = elmo(x, signature="default", as_dict=True)["elmo"] # To Extract ELMo features 

embeddings.shape

我收到了这种类型的错误,type error : pruned(text): expected argument #0(zero-based) to be a Tensor; got list (['Roasted ants are a popular snack in Columbia'])

【问题讨论】:

  • 我在我的电脑上尝试了代码,它运行正常。请提供有关错误及其生成位置的更多信息?
  • @madhurika:你能解决这个问题吗?如果是,你能分享一下解决步骤吗?
  • 查看tensorflow版本,你用的是>2.0吗?
  • @madhurika:我收到了同样的错误。如果找到解决方案,您有机会发布吗?

标签: python tensorflow


【解决方案1】:

此代码在 colab 中使用 Tensorflow 2.7 运行良好,

import tensorflow_hub as hub

import tensorflow as tf

elmo = hub.Module("https://tfhub.dev/google/elmo/2")

x = ["Roasted ants are a popular snack in Columbia"]


embeddings = elmo(x, signature="default", as_dict=True)["elmo"] # To Extract ELMo features 

embeddings.shape

输出:

TensorShape([Dimension(1), Dimension(8), Dimension(1024)])

让我们知道tensorflowenvironment 使用哪个版本来重现此错误。

【讨论】:

    猜你喜欢
    • 2012-05-13
    • 1970-01-01
    • 2016-01-18
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 2011-03-08
    • 1970-01-01
    相关资源
    最近更新 更多