8

我正在使用 Colab 运行文本分析代码。我想从 tensorflow_hub获得Universal-sentence-encoder-large 。但任何时候运行包含以下代码的块:

module = hub.Module("https://tfhub.dev/google/universal-sentence-encoder-large/3")

我收到此错误:

    RuntimeError: variable_scope module_8/ was unused but the 
    corresponding name_scope was already taken.

如果您知道如何修复此错误,我将不胜感激?

4

2 回答 2

7

TF Hub USE-3 模块不适用于 TensorFlow 2.0 版。

因此,如果您将版本从 2.0 更改为 1.15,它可以正常工作而不会出现任何错误。

请找到下面提到的工作代码:

!pip install tensorflow==1.15
!pip install "tensorflow_hub>=0.6.0"
!pip3 install tensorflow_text==1.15

import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
import tensorflow_text

module = hub.Module("https://tfhub.dev/google/universal-sentence-encoder-large/3")

请同时找到 Google Colab 的Github Gist

于 2020-02-26T10:41:28.023 回答
3

在 google colab 中使用 tensorflow 2,您应该使用 hub.load(url) 而不是 hub.Module(url)

于 2020-11-28T19:29:57.630 回答