pruned(text): 预期参数#0(从零开始)是张量;得到清单(['烤蚂蚁是哥伦比亚的一种流行小吃'])

Mad*_*ika 5 python tensorflow

这是使用 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
Run Code Online (Sandbox Code Playgroud)

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

小智 0

这段代码在 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
Run Code Online (Sandbox Code Playgroud)

输出:

TensorShape([Dimension(1), Dimension(8), Dimension(1024)])
Run Code Online (Sandbox Code Playgroud)

让我们知道正在使用哪个tensorflow版本environment来重现此错误。