![](/img/trans.png)
[英]Failed to load the native TensorFlow runtime : error while importing tensorflow
[英]Runtime error while trying basic tensorflow code
更新:
无论是单词、句子还是短语,Universal Sentence Encoder 总是会返回 512 的向量大小。我想知道为什么是 512而不是别的什么。
通过提供的答案解决了以下问题。
我尝试了 tensorflow 主页上提供的示例:
https://tfhub.dev/google/universal-sentence-encoder/2
我遇到这样的运行时错误:
RuntimeError:启用急切执行时不支持导出/导入元图。 启用急切执行时不存在图表。
我尝试的代码是:
import tensorflow.compat.v1 as tf
import tensorflow_hub as hub
config = tf.ConfigProto()
session = tf.Session(config=config)
embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder/2")
embeddings = embed(
[
"The quick brown fox jumps over the lazy dog.",
"I am a sentence for which I would like to get its embedding",
]
)
print(session.run(embeddings))
如何正确运行此代码?
这是您使用的 tensorflow 版本的问题。
在 Tensorflow 2.0 中,您应该使用hub.load()
或hub.KerasLayer()
。
基于 github 的讨论: https://github.com/tensorflow/hub/issues/350
以下解决方案对我有用:
import tensorflow.compat.v1 as tf
tf.disable_eager_execution()
上面的代码禁用了急切执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.