tensorflow / text

Making text a first-class citizen in TensorFlow.
https://www.tensorflow.org/beta/tutorials/tensorflow_text/intro
Apache License 2.0
1.23k stars 345 forks source link

Tutorial: Classify text with BERT Cannot install dependencies by pip in Colab #1147

Open r-matsuzaka opened 1 year ago

r-matsuzaka commented 1 year ago

Hi, I am now tring to run the Classify text with BERT tutorial in Colab. But I got the following error when I run the cell.

import os
import shutil

import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text as text
from official.nlp import optimization  # to create AdamW optimizer

import matplotlib.pyplot as plt

tf.get_logger().setLevel('ERROR')

ModuleNotFoundError Traceback (most recent call last) in <cell line: 7>() 5 import tensorflow_hub as hub 6 import tensorflow_text as text ----> 7 from official.nlp import optimization # to create AdamW optimizer 8 9 import matplotlib.pyplot as plt

ModuleNotFoundError: No module named 'official'


NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the "Open Examples" button below.

In the previous cell, when I run !pip install -q tf-models-official==2.11.0 I got the following error.

 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.9/118.9 kB 4.3 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.6/43.6 kB 3.2 MB/s eta 0:00:00

Preparing metadata (setup.py) ... done ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 33.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 240.6/240.6 kB 22.7 MB/s eta 0:00:00 ERROR: Could not find a version that satisfies the requirement opencv-python-headless==4.5.2.52 (from tf-models-official) (from versions: 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 3.4.16.59, 3.4.17.61, 3.4.17.63, 3.4.18.65, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.58, 4.5.4.60, 4.5.5.62, 4.5.5.64, 4.6.0.66, 4.7.0.68, 4.7.0.72) ERROR: No matching distribution found for opencv-python-headless==4.5.2.52

I could install offcial by !pip install -q tf-models-official. But in the next cell I got the other error... Could you tell me the correct instruction to isntall the dependency?

import os import shutil

import tensorflow as tf import tensorflow_hub as hub import tensorflow_text as text from official.nlp import optimization # to create AdamW optimizer

import matplotlib.pyplot as plt

tf.get_logger().setLevel('ERROR')


AssertionError Traceback (most recent call last) in <cell line: 7>() 5 import tensorflow_hub as hub 6 import tensorflow_text as text ----> 7 from official.nlp import optimization # to create AdamW optimizer 8 9 import matplotlib.pyplot as plt

11 frames /usr/local/lib/python3.10/dist-packages/tensorflow/python/saved_model/revived_types.py in register_revived_type(identifier, predicate, versions) 131 132 if identifier in _REVIVED_TYPE_REGISTRY: --> 133 raise AssertionError(f"Duplicate registrations for type '{identifier}'") 134 135 _REVIVED_TYPE_REGISTRY[identifier] = (predicate, versions)

AssertionError: Duplicate registrations for type 'experimentalOptimizer'

r-matsuzaka commented 1 year ago

The reason is the failure of CI https://github.com/tensorflow/text/commit/978fd9f2ecc334f939946090236f2870ebfe991e

I could run the notebook with the previous versions.

fbernaly commented 1 year ago

@r-matsuzaka : have you found any workaround? I encountered the same issue: https://github.com/tensorflow/text/issues/1213

MrDBC commented 1 year ago

@fbernaly here it is: https://github.com/tensorflow/text/issues/1213#issuecomment-1717023160

fbernaly commented 1 year ago

Thanks @MrDBC, what you suggested works:

Run:

!pip install -U "tf-models-official==2.13.*" --no-deps