![](/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.