使用 Tensorflow Hub 时范围变量出错

pou*_*vey 7 google-colaboratory tensorflow-hub

我正在使用 Colab 运行文本分析代码。我想从 tensorflow_hub获得通用句子编码器大。但是任何时候运行包含以下代码的块:

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

我收到此错误:

    RuntimeError: variable_scope module_8/ was unused but the 
    corresponding name_scope was already taken.
Run Code Online (Sandbox Code Playgroud)

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

Ten*_*ort 6

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

请同时找到Google Colab的Github Gist


小智 5

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