2

Update:

Whether it is a word, sentence or phrase, The Universal Sentence Encoder will always return vector size of 512. I will like to know why 512 and not something else.


The following question was resolved by the answer provided.

I tried the example provided on tensorflow home page:

https://tfhub.dev/google/universal-sentence-encoder/2

I got runtime error like this:

RuntimeError: Exporting/importing meta graphs is not supported when eager execution is enabled. No graph exists when eager execution is enabled.

The code that I tried is:

import tensorflow.compat.v1 as tf
import tensorflow_hub as hub

config = tf.ConfigProto()
session = tf.Session(config=config)

embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder/2")
embeddings = embed(
    [
        "The quick brown fox jumps over the lazy dog.",
        "I am a sentence for which I would like to get its embedding",
    ]
)

print(session.run(embeddings))

How to run this code correctly?

1
  • is this question not active anymore? why don't you delete it then. or put an update at the top of it Commented Oct 3, 2019 at 16:00

2 Answers 2

6

It's a matter of the tensorflow version you are using.

In Tensorflow 2.0 you should use hub.load() or hub.KerasLayer().

Sign up to request clarification or add additional context in comments.

3 Comments

ValueError: Non-callable result from hub.load # Can you show how to create "session" object?
Thanks for the answer. But I have a follow up question. Please see the update.
@shantanuo if you have a follow up question it should be asked as its own question, you will have more luck getting an answer.
1

Based on a discussion from github: https://github.com/tensorflow/hub/issues/350

The below solution worked for me:

import tensorflow.compat.v1 as tf
tf.disable_eager_execution()

The above code disables the eager execution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.