Error on Scope Variable While Using Tensorflow Hub
Asked Answered
C

2

8

I am using Colab to run a text analysis code. I am want to get universal-sentence-encoder-large from tensorflow_hub. But anytime running the block containing the code below:

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

I get this error:

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

I appreciate if you have any idea how this error can be fixed?

Conroy answered 1/9, 2019 at 0:21 Comment(5)
Minimal, Reproducible ExamplePiccolo
have you found a solution for this problem? I'm getting similar error.Foison
No, I ended up using PytorchConroy
The above problem arises when using TF 2.0 . Downgrading to 1.15.0 or lower will solve the problem.Drubbing
I'm having same problem, any solution?Zweig
S
7

TF Hub USE-3 Module doesn't work with Tensorflow Version 2.0.

Hence, if you change the version from 2.0 to 1.15, it works without any error.

Please find the working code mentioned below:

!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")

Please find the Github Gist of Google Colab as well.

Starks answered 26/2, 2020 at 10:41 Comment(0)
C
5

With tensorflow 2 in google colab you should use hub.load(url) instead of hub.Module(url)

Carpentry answered 28/11, 2020 at 19:29 Comment(2)
This is not an answer. Please consider leaving a comment instead.Comptom
Thanks, I got the solutionVidovik

© 2022 - 2024 — McMap. All rights reserved.