7
votes

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?

2
have you found a solution for this problem? I'm getting similar error. - sareem
No, I ended up using Pytorch - pouria babvey
The above problem arises when using TF 2.0 . Downgrading to 1.15.0 or lower will solve the problem. - Prady_venom
I'm having same problem, any solution? - bachr

2 Answers

5
votes

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.

2
votes

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