Universal sentence encoder QA module freezes after a while
I've the following init code:
import tensorflow as tf
import tensorflow_hub as tfhub
import tensorflow_text
module = tfhub.load("https://tfhub.dev/google/universal-sentence-encoder-multilingual-qa/3")
def title_embedding(question):
return module.signatures['question_encoder'](tf.constant([question]))
def body_embedding(answer):
return module.signatures['response_encoder'](
input=tf.constant([answer]),
context=tf.constant([answer]))
When I run this for multiple iterations, it freezes after a point and doesn't generate embeddings:
for i in range(1, 500):
print(title_embedding("Who let the dogs out?"))
print(body_embedding("Dogs came out themselves!"))
I tried with some variants as well:
def body_embedding(answer):
return module.signatures['response_encoder'](
input=tf.constant([answer]),
context=tf.constant([""]))
q_embed = tfhub.KerasLayer("https://tfhub.dev/google/universal-sentence-encoder-multilingual-qa/3", signature="question_encoder", output_key='outputs')
r_embed = tfhub.KerasLayer("https://tfhub.dev/google/universal-sentence-encoder-multilingual-qa/3", signature="response_encoder", output_key='outputs')
def title_embedding(question):
return q_embed(tf.constant([question]))
def body_embedding(answer):
return r_embed({ "input": tf.constant([answer]), "context": tf.constant([answer]) })
All approaches lead to the same freezing issue. Any ideas here please? Here's my environment:
tensorflow 2.3.0
tensorflow-hub 0.9.0
tensorflow-text 2.3.0
@VarunNatraaj, I could execute your code successfully both in my Jupyter Notebook and in Google Colab. Can you please share the environment in which you are executing the code and the configuration of your Machine. Thanks!
@rmothukuru Oh is that so? Let me clear some things up and check in my system again then. I am running on a Mac (MacBook Pro (Retina, 15-inch, Mid 2015)). It used to work perfectly before, and it stopped working recently. I'll close this now, and re-open if I encounter anything. Thanks!
@VarunNatraaj Hi varun are you still facing the freezing issue?