Forums

Failed to do encode using sentence transformers with torch

I have a very simple code to generate embeddings using sentence transformers. I have 15G space. It works well in the pythonanywhere console, but failed when I call it from flask app in pythonanywhere. How can I solve it?

# generate_embeddings
def generate_embeddings(sentences):
   print(sentences) # this was printed in the server log when I run in flask
   # create sentence embeddings 
   encoded_data = model.encode(sentences)  # the process stopped here
   print("embeddings shape: ", encoded_data.shape)
   return encoded_data

What do you see in your logs?

The sentence transformer provides a REST API to generate embeddings, which didn't throw any error message, just silent. The client side that call the REST API waited for around one minute and then get timeout error message.

Pythonanywhere support team provided me the solution to solve the issue as mentioned in https://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode. Thanks for the great job from the pythonanywhere support team! You guys are awesome!

Just to make sure that the help page with that information is better linked from more places on our site, the bottom section on this help page is the relevant one here :-)