Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on Scope Variable While Using Tensorflow Hub

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?

like image 203
pouria babvey Avatar asked Sep 01 '19 00:09

pouria babvey


2 Answers

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.

like image 84
Tensorflow Support Avatar answered Nov 15 '22 10:11

Tensorflow Support


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

like image 36
lamsiyah salima Avatar answered Nov 15 '22 09:11

lamsiyah salima