我有如下代码。它按预期工作。但是我想将变量embeddings
的值保存在内存中。执行代码后,在我的embeddings
中看不到变量variable explorer
我想避免将其写入磁盘。有没有简单的方法可以做到这一点?
import tensorflow_hub as hub
import tensorflow as tf
elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True)
x = ["she is the love of my life"]
# Extract ELMo features
embeddings = elmo(x, signature="default", as_dict=True)["elmo"]
embeddings.shape
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
print (sess.run(embeddings))