Issue
I am extracting features through elmo. Train and Test are text data.I am getting errors while executing in google colab. I have checked previous Stackoverflow questions but could not resolve. Exact codes with pointers will be helpful.
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]
I am getting following errors: UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [[node module_apply_default_1/bilm/CNN_2/Conv2D_6 (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py:517) ]] [[node Mean (defined at :8) ]]
Solution
I tried right now on colab.research.google.com in Python 3 runtimes with and without GPU, and the following adaptation of your code runs:
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"])
I get the output:
array([[ 0.45319763, -0.99154925, -0.26539633, ..., -0.13455263,
0.48878008, 0.31264588]], dtype=float32)
I believe this is a not a TF Hub problem.
Answered By - arnoegw
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.