bertseq2seq : RuntimeError: variable_scope module_1/ was unused but the corresponding name_scope was already taken
bertseq2seq : RuntimeError: variable_scope module_1/ was unused but the corresponding name_scope was already taken
我在 Colab 上尝试从 TFHub 运行 bertseq2seq 时遇到此错误。请帮忙解决这个错误。
(我正在尝试使用 colab,因为我已经在我的机器上使用了 TF2,并且不想通过降级或使用并行 TF1 来搞砸它。如果成功,我将尝试在服务器中安装 TF1)
%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')
我无法使用您的代码段和新的 Colab 笔记本重现该问题,但以下代码在 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']
我在 Colab 上尝试从 TFHub 运行 bertseq2seq 时遇到此错误。请帮忙解决这个错误。 (我正在尝试使用 colab,因为我已经在我的机器上使用了 TF2,并且不想通过降级或使用并行 TF1 来搞砸它。如果成功,我将尝试在服务器中安装 TF1)
%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')
我无法使用您的代码段和新的 Colab 笔记本重现该问题,但以下代码在 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']