gpt4 book ai didi

python - 尝试基本的 tensorflow 代码时出现运行时错误

转载 作者:行者123 更新时间:2023-12-02 00:13:12 26 4
gpt4 key购买 nike

更新:

无论是单词、句子还是短语,Universal Sentence Encoder 将始终返回 512 的矢量大小。我想知道为什么是 512 而不是其他。


以下问题已由提供的答案解决。

我尝试了tensorflow主页上提供的例子:

https://tfhub.dev/google/universal-sentence-encoder/2

我遇到这样的运行时错误:

RuntimeError: Exporting/importing meta graphs is not supported when eager execution is enabled. No graph exists when eager execution is enabled.

我试过的代码是:

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()

关于python - 尝试基本的 tensorflow 代码时出现运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58179074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com