I am trying to work through the course and am running into an error that I do not know how to work around.
I enter the following
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
and get the following error
ModuleNotFoundError Traceback (most recent call last)
File ~/anaconda3/lib/python3.11/site-packages/transformers/file_utils.py:2777, in _LazyModule._get_module(self, module_name)
2776 try:
-> 2777 return importlib.import_module("." + module_name, self.__name__)
2778 except Exception as e:
File ~/anaconda3/lib/python3.11/importlib/__init__.py:126, in import_module(name, package)
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1204, in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:1176, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:1147, in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:690, in _load_unlocked(spec)
File <frozen importlib._bootstrap_external>:940, in exec_module(self, module)
File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f, *args, **kwds)
File ~/anaconda3/lib/python3.11/site-packages/transformers/models/distilbert/modeling_tf_distilbert.py:23
21 import tensorflow as tf
---> 23 from ...activations_tf import get_tf_activation
24 from ...file_utils import (
25 MULTIPLE_CHOICE_DUMMY_INPUTS,
26 add_code_sample_docstrings,
27 add_start_docstrings,
28 add_start_docstrings_to_model_forward,
29 )
File ~/anaconda3/lib/python3.11/site-packages/transformers/activations_tf.py:107
105 return tf.keras.activations.gelu(x, approximate=True)
--> 107 gelu = tf.keras.activations.gelu
108 gelu_new = approximate_gelu_wrap
File ~/anaconda3/lib/python3.11/site-packages/tensorflow/python/util/lazy_loader.py:210, in KerasLazyLoader.__getattr__(self, item)
207 raise AttributeError(
208 f"`{item}` is not available with Keras 3."
209 )
--> 210 module = self._load()
211 return getattr(module, item)
File ~/anaconda3/lib/python3.11/site-packages/tensorflow/python/util/lazy_loader.py:52, in LazyLoader._load(self)
51 # Import the target module and insert it into the parent's namespace
---> 52 module = importlib.import_module(self.__name__)
53 self._tfll_parent_module_globals[self._tfll_local_name] = module
File ~/anaconda3/lib/python3.11/importlib/__init__.py:126, in import_module(name, package)
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'keras._tf_keras'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 classifier = pipeline("sentiment-analysis")
File ~/anaconda3/lib/python3.11/site-packages/transformers/pipelines/__init__.py:549, in pipeline(task, model, config, tokenizer, feature_extractor, framework, revision, use_fast, use_auth_token, model_kwargs, pipeline_class, **kwargs)
545 # Infer the framework from the model
546 # Forced if framework already defined, inferred if it's None
547 # Will load the correct model if possible
548 model_classes = {"tf": targeted_task["tf"], "pt": targeted_task["pt"]}
--> 549 framework, model = infer_framework_load_model(
550 model,
551 model_classes=model_classes,
552 config=config,
553 framework=framework,
554 revision=revision,
555 task=task,
556 **model_kwargs,
557 )
559 model_config = model.config
561 load_tokenizer = type(model_config) in TOKENIZER_MAPPING or model_config.tokenizer_class is not None
File ~/anaconda3/lib/python3.11/site-packages/transformers/pipelines/base.py:223, in infer_framework_load_model(model, config, model_classes, task, framework, **model_kwargs)
221 classes.append(_class)
222 if look_tf:
--> 223 _class = getattr(transformers_module, f"TF{architecture}", None)
224 if _class is not None:
225 classes.append(_class)
File ~/anaconda3/lib/python3.11/site-packages/transformers/file_utils.py:2768, in _LazyModule.__getattr__(self, name)
2766 elif name in self._class_to_module.keys():
2767 module = self._get_module(self._class_to_module[name])
-> 2768 value = getattr(module, name)
2769 else:
2770 raise AttributeError(f"module {self.__name__} has no attribute {name}")
File ~/anaconda3/lib/python3.11/site-packages/transformers/file_utils.py:2767, in _LazyModule.__getattr__(self, name)
2765 value = self._get_module(name)
2766 elif name in self._class_to_module.keys():
-> 2767 module = self._get_module(self._class_to_module[name])
2768 value = getattr(module, name)
2769 else:
File ~/anaconda3/lib/python3.11/site-packages/transformers/file_utils.py:2779, in _LazyModule._get_module(self, module_name)
2777 return importlib.import_module("." + module_name, self.__name__)
2778 except Exception as e:
-> 2779 raise RuntimeError(
2780 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its traceback):\n{e}"
2781 ) from e
RuntimeError: Failed to import transformers.models.distilbert.modeling_tf_distilbert because of the following error (look up to see its traceback):
No module named 'keras._tf_keras'
When looking for a solution it seems that a change in tensor flow models introduced this. Is a fix available other than having to clone tensor flow and revert to a specific commit?Unfortunately this breaks the pipeline command.