使用Tensorflow_hub和通用语句编码器时遇到的困难

问题描述 投票:0回答:1

[在运行以下代码时,出现错误。有人可以帮助我吗?我正在使用Tensorflow 2.1.0

import pandas as pd
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")

tweets = pd.read_csv('dataset.csv')
print(tweets.columns)
labels = tweets[['Sentiment']]
tweets = tweets[['SentimentText']]
tweets = tweets['SentimentText'].to_numpy()
embed = hub.KerasLayer("./model",  output_shape=[20],  input_shape=[],dtype=tf.string)
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
with tf.compat.v1.Session() as sess:
     sess.run([tf.compat.v1.global_variables_initializer()])
     sess.run(embed(tweets))

我收到以下错误:

文件“ /anaconda3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py”,行4727,在_override_gradient_function中断言不是self._gradient_function_map

AssertionError

“错误图片”“ >>

[在运行以下代码时,出现错误。有人可以帮助我吗?我正在使用Tensorflow 2.1.0 import pandas as pd import numpy as np import tensorflow as tf import tensorflow_hub as ...

python sentiment-analysis keras-layer tensorflow-hub tensorflow2.x
1个回答
0
投票

我也遇到了这个问题。通过使用tensorflow == 2.0.0来解决(我最初使用tensorflow == 2.1.0)

© www.soinside.com 2019 - 2024. All rights reserved.