Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: All inputs to `ConcreteFunction`s must be Tensors

I am trying some examples for Universal sentence encoder the code below:

sentences_list = [
# phone related
'My phone is slow',
'My phone is not good',
'I need to change my phone. It does not work well',
'How is your phone?',

# age related
'What is your age?',
'How old are you?',
'I am 10 years old',

# weather related
'It is raining today',
'Would it be sunny tomorrow?',
'The summers are here.'

]

with tf.Session() as session:

    session.run([tf.global_variables_initializer(), 
    tf.tables_initializer()])
    sentences_embeddings = session.run(embed.signatures['default'] (sentences_list))

But get the error:

ValueError: All inputs to ConcreteFunctions must be Tensors; on invocation of pruned, the 0-th input (['My phone is slow', 'My phone is not good', 'I need to change my phone. It does not work well', 'How is your phone?', 'What is your age?', 'How old are you?', 'I am 10 years old', 'It is raining today', 'Would it be sunny tomorrow?', 'The summers are here.']) was not a Tensor.

like image 755
std Avatar asked Oct 17 '19 09:10

std


2 Answers

Since tensorflow works with Tensors only, so it will not accept a python list as input and as the error also says, you need to convert the list to a Tensor and then feed it.

What you can do is define the list as numpy array with something like

np_list = np.asarray(sentence_list) and then convert it to tensor using

tensor_list = tf.convert_to_tensor(np_list).

Read more about them here, np.asarray and convert_to_tensor

like image 177
Rishabh Sahrawat Avatar answered Nov 13 '22 12:11

Rishabh Sahrawat


It says that you are passing a variable that is not a tensot, obviously. What you are missing is sentences_list should be passed through tf.constant or tf.placeholder depends on how you want to use it.

For tf.constant use: x = tf.constant(sentences_list)

And pass the x to the embed.signatures['default']

like image 1
Ilya Avatar answered Nov 13 '22 11:11

Ilya