Skip to content

Instantly share code, notes, and snippets.

@bsod90
Last active September 17, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsod90/a3a5beff80b210b471bf0ddb23e90dda to your computer and use it in GitHub Desktop.
Save bsod90/a3a5beff80b210b471bf0ddb23e90dda to your computer and use it in GitHub Desktop.
import tensorflow as tf
import tensorflow_hub as hub
from tensorflow.saved_model import simple_save
export_dir = "./models/use/00000001"
with tf.Session(graph=tf.Graph()) as sess:
module = hub.Module("https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/1")
text_input = tf.placeholder(dtype=tf.string, shape=[None])
sess.run([tf.global_variables_initializer(), tf.tables_initializer()])
embeddings = module(text_input)
simple_save(sess,
export_dir,
inputs={'text': text_input},
outputs={'embeddings': embeddings},
legacy_init_op=tf.tables_initializer())
@csfyrakis
Copy link

Have you missed the import tf_sentencepiece ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment