Tensorflow 2.X 错误 - 在 Colab 上运行的二进制文件中未注册操作类型“CaseFoldUTF8”

Yog*_*_25 2 tensorflow2.0 bert-language-model

我已经使用 Tensorflow hub 的 BERT 编码器有一段时间了。以下是语法:

tfhub_handle_encoder = "https://tfhub.dev/tensorflow/bert_multi_cased_L-12_H-768_A-12/4" tfhub_handle_preprocess = "https://tfhub.dev/tensorflow/bert_multi_cased_preprocess/3" bert_preprocess_model = hub.KerasLayer(tfhub_handle_preprocess)

突然我遇到了这个错误消息 :FileNotFoundError: Op type not registered 'CaseFoldUTF8' in binary running on acb9309ebd87. 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.resamplerexperimental_io_device tf.saved_model.LoadOptionsshould be done before importing the graph, as contrib ops are lazily registered when the module is first accessed. You may be trying to load on a different device from the computational device. Consider setting theoption in to the io_device such as '/job:localhost'.

相同的代码多年来一直运行良好。Tf 版本 - 2.9,环境 - Colab/GCP Vertex AI

Yaj*_*tra 5

导入import tensorflow_text as text应该可以解决这个问题。

编辑:您可能必须!pip install tensorflow_text在 Colab 中运行。