我正在通过 elmo 提取特征。训练和测试是文本数据。在 google colab 中执行时出现错误。我检查了以前的 Stackoverflow 问题,但无法解决。带有指针的确切代码将很有帮助。
elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True)
def elmo_vectors(x):
embeddings = elmo(x.tolist(), signature="default", as_dict=True)["elmo"]
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
# return average of ELMo features
return sess.run(tf.reduce_mean(embeddings,1))
import tensorflow as tf
import tensorflow_hub as hub
list_train = [train[i:i+100] for i in range(0,train.shape[0],100)]
list_test = [test[i:i+100] for i in range(0,test.shape[0],100)]
# Extract ELMo embeddings
elmo_train = [elmo_vectors(x['clean_tweet']) for x in list_train]
elmo_test = [elmo_vectors(x['clean_tweet']) for x in list_test]
我收到以下错误:UnknownError:无法获得卷积算法。这可能是因为 cuDNN 初始化失败,因此请尝试查看上面是否打印了警告日志消息。[[node module_apply_default_1/bilm/CNN_2/Conv2D_6(定义在/usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py:517)]] [[node Mean(定义在:8)]]