ValueError:`ConcreteFunction`s 的所有输入都必须是张量

std*_*std 7 python keras tensorflow

我正在尝试通用句子编码器的一些示例,代码如下:

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.'
Run Code Online (Sandbox Code Playgroud)

]

with tf.Session() as session:

    session.run([tf.global_variables_initializer(), 
    tf.tables_initializer()])
    sentences_embeddings = session.run(embed.signatures['default'] (sentences_list))
Run Code Online (Sandbox Code Playgroud)

但得到错误:

ValueError:ConcreteFunctions 的所有输入都必须是张量;在调用 pruned 时,第 0 个输入(['我的手机很慢','我的手机不好','我需要更换我的手机。它不能正常工作','你的手机怎么样?', “你几岁了?”、“你多大了?”、“我 10 岁了”、“今天下雨了”、“明天会不会是晴天?”、“夏天来了。”])不是张量。

Ily*_*lya 1

显然,它表示您传递的变量不是张量。您缺少的是句子列表应该通过 tf.constant 或 tf.placeholder 传递,具体取决于您想如何使用它。

对于 tf.constant 使用: x = tf.constant(sentences_list)

并将 x 传递给 embed.signatures['default']