Op type not registered 'SentencepieceEncodeSparse' in binary

Viewed 4708

I had deployed a model which used a tfhub model to tensorflow-serving using a docker.

Here is the tfhub model contained in my model:

https://tfhub.dev/google/universal-sentence-encoder-multilingual/1

Here is the command to run the docker

docker run -t --rm -p 8501:8501 \
    -v "/docker_dir/model_tf_serving:/models/mymodel" \
    -e MODEL_NAME=mymodel \
    tensorflow/serving &

Error happened:

Not found: Op type not registered 'SentencepieceEncodeSparse' in binary running on c5e507bf091b. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.

So is there a way to fix this?

3 Answers

I don't know if you're still having that problem but it worked for me to

  1. download that module with pip install tensorflow-text
  2. type import tensorflow_text

since that tf-hub modules depend on that package.

You have to install the sentencepiece module for TensorFlow:

pip install sentencepiece tf-sentencepiece

There is an instruction from the official hub page how to use the model with tensorflow=2. https://tfhub.dev/google/universal-sentence-encoder-multilingual/2

Worked for me.

!pip3 install tensorflow_text>=2.0.0rc0

import tensorflow as tf
import tensorflow_text
embed = tf.saved_model.load("https://tfhub.dev/google/universal-sentence-encoder-multilingual/2")
Related