dipanjan sanyal
dipanjan sanyal

Reputation: 23

bertseq2seq : RuntimeError: variable_scope module_1/ was unused but the corresponding name_scope was already taken

I got this error while trying to run bertseq2seq from TFHub on Colab. Please help with this error. (I am trying on colab because I already use TF2 in my machine and don't want to mess that up by downgrading or having parallel TF1. If it works out then I will try installing TF1 in a server)

%tensorflow_version 1.x

import tensorflow.compat.v1 as tf
import tensorflow_hub as hub
import tensorflow_text

#### Sentence Fusion #########
text_generator = hub.Module(
    'https://tfhub.dev/google/bertseq2seq/roberta24_discofuse/1')

enter image description here

Upvotes: 0

Views: 812

Answers (1)

WGierke
WGierke

Reputation: 603

I cannot reproduce the issue using your snippet and a fresh Colab notebook but the following code works for me in Colab:

# You can achieve TF1 behavior by still using a TF2 installation using the
# compat API. See the Migration Guide (https://www.tensorflow.org/guide/migrate)
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

!pip install tensorflow_text

import tensorflow_hub as hub
import tensorflow_text

text_generator = hub.Module('https://tfhub.dev/google/bertseq2seq/roberta24_discofuse/1')
input_texts = ['Sentence 1a. Sentence 1b.', 'Sentence 2a. Sentence 2b. Sentence 2c.']

with tf.Session() as sess:
  sess.run(tf.group(tf.global_variables_initializer(), tf.tables_initializer()))
  print(sess.run(text_generator(input_texts)))
  # [b'Sentence 1a. Sentence 1b' b'Sentence 2a. Sentence 2b. Sentence 2c']

Upvotes: 0

Related Questions