【发布时间】:2020-05-26 00:54:39
【问题描述】:
运行以下代码时,出现错误。 有谁能帮助我吗?我正在使用 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
断言错误
【问题讨论】:
-
您使用的是来自 tfhub.dev 的模型吗?如果是这样,请添加您正在使用的显式模型,并添加您从 csv 加载的数据示例。
-
@kempy 感谢您的回复。我的问题解决了。这段代码没有问题。我减少了数据集的长度并且它一直在工作。非常感谢
标签: python sentiment-analysis keras-layer tensorflow-hub tensorflow2.x