Google Colaboratory NotFoundError: /usr/local/lib/python3.7/dist-packages/tensorflow_text/python/metrics/_text_similarity_metric_ops.so

Google Colaboratory NotFoundError: /usr/local/lib/python3.7/dist-packages/tensorflow_text/python/metrics/_text_similarity_metric_ops.so

我在导入 Top2vec 时遇到问题(在 colab notebook 中)。 要重现它:

pip install top2vec[sentence_encoders]

重新启动运行时以加载新模块,然后

from top2vec import Top2Vec

它向我显示了这个错误:

---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
<ipython-input-8-9a81163f0da9> in <module>()
----> 1 from top2vec import Top2Vec

5 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/load_library.py in load_op_library(library_filename)
     55     RuntimeError: when unable to load the library or get the python wrappers.
     56   """
---> 57   lib_handle = py_tf.TF_LoadLibrary(library_filename)
     58   try:
     59     wrappers = _pywrap_python_op_gen.GetPythonWrappers(

NotFoundError: /usr/local/lib/python3.7/dist-packages/tensorflow_text/python/metrics/_text_similarity_metric_ops.so: undefined symbol: _ZN10tensorflow15OpKernelContext15allocate_outputEN4absl14lts_2020_09_2311string_viewERKNS_11TensorShapeEPPNS_6TensorE

我找到了您应该安装的解决方案 pip install -U tensorflow==2.3.0 但此版本与 top2vec

不兼容

I think this might due to the incompatibility of Tensorflow when using

!pip install top2vec[sentence_encoders]

I figured it out by first installing Top2Vec required version of TensorFlow and numpy:

!pip install tensorflow==2.5.0
!pip install numpy

Then install Top2Vec and the pre-trained universal sentence encoder:

!pip install top2vec
!pip install top2vec[sentence_encoders]