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
ConcreteFunction
s 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.
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
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With