0

I'm following the TenslorFlow TFlite basic text classification tutorial, but the third import line throws an error:

from tensorflow_examples.lite.model_maker.core.data_util import image_dataloader
ModuleNotFoundError: No module named 'official.nlp.bert'

I installed TensorFlow with pip install tensorflow and the tflite model maker with pip install -q tflite-model-maker.

I've also installed all the official models with pip install tf-models-official.

I can see the BERT model on the official models GitHub as well, so it should be in there.

How can I install the bert model?

Full error:

Traceback (most recent call last):
  File "...\Downloads\tf_setup.py", line 6, in <module>
    from tflite_model_maker import model_spec
  File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tflite_model_maker\__init__.py", line 16, in <module>
    from tensorflow_examples.lite.model_maker.core.data_util import image_dataloader
  File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\__init__.py", line 17, in <module>
    from tensorflow_examples.lite.model_maker.core.data_util import text_dataloader
  File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\core\data_util\text_dataloader.py", line 31, in <module>
    from tensorflow_examples.lite.model_maker.core.task import model_spec as ms
  File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\model_spec.py", line 37, in <module>
    from official.nlp.bert import configs as bert_configs
ModuleNotFoundError: No module named 'official.nlp.bert'
Salvatore
  • 10,815
  • 4
  • 31
  • 69
  • Did you try this : `pip install -q -U "tensorflow-text==2.8.*"` and `!pip install -U tfds-nightly` and `!pip install git+https://github.com/tensorflow/examples.git` ? – I'mahdi Jun 14 '22 at 07:45

1 Answers1

1

What is your Python version? I encountered the exact same error while I was using Python 3.10. My tflite-model-maker was 0.1.x version despite I tried to install the latest one which is 0.4.0. I wanted to update it but I got more errors about "No matching distribution" for tflite-model-maker and tflite-support. After I installed and changed my Python interpreter (I'm using PyCharm) to Python 3.9.13 and reinstall tflite-model-maker, the error is gone.