<p>Unfortunately, tf_hub modules are <a href="https://github.com/tensorflow/hub/issues/124" rel="nofollow noreferrer">not yet supported in eager mode</a> except in tf 2 (which is still in beta and I think needs slightly different hub modules anyway). </p>

<p>Therefore you'll need to run this in a session.</p>

<p>Something like:</p>

<pre class="lang-py prettyprint-override"><code>embed = hub.Module("https://public.ukp.informatik.tu-darmstadt.de/arxiv2018-xling-sentence-embeddings/tf-hub/monolingual/1")
X = embed(["This is a test."])

with tf.Session() as session:
  session.run([tf.global_variables_initializer(), tf.tables_initializer()])
  numpy_arr = session.run(X)
</code></pre>
How to get Numpy array from tf Tensor?
<p>I face problems when trying to get a numpy array from a tensorflow tensor. I use a tensorflow hub module but I don't want to use tensorflow in downstream tasks but rather need a numpy array.</p>

<p>I know that I have to call the 'eval()' method on the tensor from within a tensorflow session. But unfortuantely I cannot get it to work... :( It tells me that the "tables are not initialized". I tried to add 'sess.run(tf.tables_initializer())' but then I get the error: 'NotFoundError: Resource localhost/module_1/embeddings_morph_specialized/class tensorflow::Var does not exist'. I am not sure what to try next. I have also tried 'sess.run()' but have also been unsuccessful.</p>

<pre class="lang-py prettyprint-override"><code>import numpy as np
import tensorflow as tf
import tensorflow_hub as hub

embed = hub.Module("https://public.ukp.informatik.tu-darmstadt.de/arxiv2018-xling-sentence-embeddings/tf-hub/monolingual/1")
X = embed(["This is a test."])

# I tried:
#with tf.Session() as sess:
#    sess.run(tf.tables_initializer())
#    X.eval()

</code></pre>

<p>'X' is the tensor which I would like to convert to a numpy array.</p>

<p>Any help is appreciated. :)
Thank you.</p>