tf-sentencepiece import error in colab (the import path is weird)

Viewed 3275

I am having error importing tf-sentencepiece on colab.

I'm using tensorflow version 2.0, and I installed tf-sentencepiece.

!pip install --upgrade pip
!pip install tensorflow==2.0.0-rc1
!pip3 install --quiet tensorflow-hub
!pip3 install --quiet seaborn
!pip3 install sentencepiece
!pip3 install tf_sentencepiece

But when I try to import tf-sentencepice, the following error occurs

/usr/local/lib/python3.6/dist-packages/tf_sentencepiece/sentencepiece_processor_ops.py:43: UserWarning: No so file is found for [2.0.0-rc1] from [3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.11.0, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.2.0.0-beta1, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.7.0, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.14.0, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.9.0, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.8.0, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.10.0, 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.1.13.1]
  (tf.__version__, ', '.join(versions)))
/usr/local/lib/python3.6/dist-packages/tf_sentencepiece/sentencepiece_processor_ops.py:44: UserWarning: use the latest version 3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.2.0.0-beta1
  warnings.warn('use the latest version %s' % (latest))
---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
<ipython-input-17-cadbc83432ee> in <module>()
      9 from tensorflow.python.framework.ops import disable_eager_execution
     10 import sentencepiece
---> 11 import tf_sentencepiece
     12 
     13 #disable_eager_execution()

2 frames
/usr/local/lib/python3.6/dist-packages/tf_sentencepiece/__init__.py in <module>()
      3 from __future__ import print_function
      4 
----> 5 from tf_sentencepiece.sentencepiece_processor_ops import *

/usr/local/lib/python3.6/dist-packages/tf_sentencepiece/sentencepiece_processor_ops.py in <module>()
     45   so_file = so_base + '.' + latest
     46 
---> 47 _gen_sentencepiece_processor_op = tf.load_op_library(so_file)
     48 
     49 

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/load_library.py in load_op_library(library_filename)
     59     RuntimeError: when unable to load the library or get the python wrappers.
     60   """
---> 61   lib_handle = py_tf.TF_LoadLibrary(library_filename)
     62 
     63   op_list_str = py_tf.TF_GetOpList(lib_handle)

NotFoundError: /usr/local/lib/python3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.2.0.0-beta1: cannot open shared object file: No such file or directory

So manually went into the directory to check whether the sentencepiece_processor_ops.so.2.0.0-beta exists or not. Weirdly it was in the folder, but in different a bit different path. The colab tries to import the file from /usr/local/lib/python3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.2.0.0-beta1 (the path is weird, should have noticed earlier...) but the file actually exists in /usr/local/lib/python3.6/dist-packages/tf_sentencepiece/_sentencepiece_processor_ops.so.2.0.0-beta1

How come is the path weirdly set in colab? How should I work around this problem?

1 Answers

Installing tensorflow_text with !pip3 install tensorflow_text>=2.0.0rc0 solves the problem - the package contains SentencepieceOps. Still don't know why the path happens to be weird, though...

Related