简体   繁体   中英

pruned(text): expected argument #0(zero-based) to be a Tensor; got list (['Roasted ants are a popular snack in Columbia'])

This is the code to get embeddings using 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

I'm getting this type error, type error: pruned(text): expected argument #0(zero-based) to be a Tensor; got list (['Roasted ants are a popular snack in Columbia']) type error: pruned(text): expected argument #0(zero-based) to be a Tensor; got list (['Roasted ants are a popular snack in Columbia']) .

This code runs fine with Tensorflow 2.7 in colab,

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

Output:

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

Let us know which tensorflow version and environment are using to reproduce this error.

try this:

elmo = hub.load("https://tfhub.dev/google/elmo/3")

x = tf.constant(["Roasted ants are a popular snack in Columbia"])


embeddings = elmo.signatures["default"](x)["elmo"] # To Extract ELMo features 

embeddings.shape

thoe output will be:

TensorShape([1, 8, 1024])

also you can use this code:

elmo = hub.KerasLayer("https://tfhub.dev/google/elmo/3",signature= "default",signature_outputs_as_dict= True)
embeddings = elmo(
    tf.constant(["Roasted ants are a popular snack in Columbia"]))

# Different outputs can be accessed by name, eg:
print( embeddings["elmo"].shape)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM