我正在通过elmo提取特征。Train和Test是文本数据。我在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无法初始化,因此请尝试查看上面是否打印了警告日志消息。[节点module_apply_default_1/bilm/CNN_2/Conv2D_6 (定义于/usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py:517) ][节点平均值(定义于:8) ]
发布于 2019-03-25 17:02:42
我现在尝试了在Python3运行时使用和不使用GPU的colab.research.google.com,并且运行了以下代码的改编版本:
import tensorflow as tf
import tensorflow_hub as hub
elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True)
def elmo_vectors(x):
embeddings = elmo(x, # Note plain x here.
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))
elmo_vectors(["Hello world"])我得到了输出:
array([[ 0.45319763, -0.99154925, -0.26539633, ..., -0.13455263,
0.48878008, 0.31264588]], dtype=float32)我相信这不是TF Hub的问题。
发布于 2021-11-29 17:55:56
这也发生在我身上。我认为这是关于我们在Google Colab free tier版本中获得的免费RAM使用量。为了运行它,我不得不减少一些卷积层和减少批处理大小。而且,我不能在GPU上运行它。所以,我想你可以考虑使用Google Colab Pro
https://stackoverflow.com/questions/55318398
复制相似问题