T5Tokenizer and T5ForConditionalGeneration producing error in Databricks - pytorch

I am running my code in a Databricks notebook environment.
Error 1:
To get a tokenizer returned, I am running the following code:
tokenizer = T5Tokenizer.from_pretrained("t5-base")
But I get an error: TypeError: 'NoneType' object is not callable.
When I ran this code on Google Colab, I installed the sentencepiece library and restarted the runtime and the error was resolved. I attempted to do the same and then restart the cluster of the Databricks notebook but this error persisted. How can I fix this?
Error 2:
To get a model returned, I am running the following code:
t5_model = T5ForConditionalGeneration.from_pretrained('t5-base')
But I get an error:
ImportError Traceback (most recent call last)
<command-3778897587544926> in <module>
2 from transformers import T5Tokenizer, T5ForConditionalGeneration
3 import torch
----> 4 t5_model = T5ForConditionalGeneration.from_pretrained('t5-base')
/databricks/python/lib/python3.8/site-packages/transformers/utils/import_utils.py in __getattr__(cls, key)
786 if key.startswith("_"):
787 return super().__getattr__(cls, key)
--> 788 requires_backends(cls, cls._backends)
789
790
/databricks/python/lib/python3.8/site-packages/transformers/utils/import_utils.py in requires_backends(obj, backends)
774 failed = [msg.format(name) for available, msg in checks if not available()]
775 if failed:
--> 776 raise ImportError("".join(failed))
777
778
ImportError:
T5ForConditionalGeneration requires the PyTorch library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.
I have installed the torch library using the instructions on the installation page:
pip3 install torch torchvision torchaudio
and imported it as well using import torch.
But, this error persists. It ran without any errors in the Colab notebook.
torch: 1.7.1
transformers: 3.3.0
tokenizers: 0.8.1rc2
sentencepiece: 0.1.96
How can I fix these two errors?

Related

Cannot get matplotlib to show plots since installing Python 3.11 in VSC

I recently upgraded from python 3.10 to 3.11 and use it in VSC (most of my coursework is a notebook, .ipynb).
However, I cannot for the life of me get matplotlib to actually show its plots.
I've tried matplotlib.use('TkAgg') but it is returning a exception ImportError...
matplotlib.use('QtAgg') gave me this error:
ImportError Traceback (most recent call last)
Cell In [14], line 3
1 import numpy as np
2 import matplotlib
----> 3 matplotlib.use("QtAgg")
4 import matplotlib.pyplot as plt
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/matplotlib/__init__.py:1156, in use(backend, force)
1151 if plt is not None:
1152 try:
1153 # we need this import check here to re-raise if the
1154 # user does not have the libraries to support their
1155 # chosen backend installed.
-> 1156 plt.switch_backend(name)
1157 except ImportError:
1158 if force:
and after using python -c 'import matplotlib; import matplotlib.pyplot; print(matplotlib.backends.backend)' in the terminal, I get:
AttributeError: module 'matplotlib' has no attribute 'backends'
I also previously ran into a problem trying to import streamlit, too, getting the error:
-- Running cmake for pyarrow
cmake -DPYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -DPython3_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.11/bin/python3 "" -DPYARROW_BUILD_CUDA=off -DPYARROW_BUILD_SUBSTRAIT=off -DPYARROW_BUILD_FLIGHT=off -DPYARROW_BUILD_GANDIVA=off -DPYARROW_BUILD_DATASET=off -DPYARROW_BUILD_ORC=off -DPYARROW_BUILD_PARQUET=off -DPYARROW_BUILD_PARQUET_ENCRYPTION=off -DPYARROW_BUILD_PLASMA=off -DPYARROW_BUILD_GCS=off -DPYARROW_BUILD_S3=off -DPYARROW_BUILD_HDFS=off -DPYARROW_USE_TENSORFLOW=off -DPYARROW_BUNDLE_ARROW_CPP=off -DPYARROW_BUNDLE_BOOST=off -DPYARROW_GENERATE_COVERAGE=off -DPYARROW_BOOST_USE_SHARED=on -DPYARROW_PARQUET_USE_SHARED=on -DCMAKE_BUILD_TYPE=release /private/var/folders/f1/s2qr53sd25n7q8ps1n__4zxw0000gn/T/pip-install-db_jc8rp/pyarrow_e2de6f877fa149e3b173fed57c7c7327
error: command 'cmake' failed: No such file or directory
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyarrow
Failed to build pyarrow
ERROR: Could not build wheels for pyarrow, which is required to install pyproject.toml-based projects
and this is also unresolved (though currently not as pressing as my lack of plots).
Conda did not work with my MBP (w/ M1 Max) so I am not using it but there are still traces of it so I can't just use the default as one normally would in VSC.

while attempting to import module of sklearn in Jupiter notebook as well as in PYCHARM, i continuously get following error

i have installed scikit-learn using pip command, however while trying to import module of sklearn in Jupiter notebook as well as in PYCHARM, i continuously get following error. I am working in python3.9. I am new to the interface, so it is requested to suggest solution for this issue.
ImportError Traceback (most recent call last)
in
----> 1 import sklearn.linear_model as lm
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/init.py in
79 # it and importing it first would fail if the OpenMP dll cannot be found.
80 from . import _distributor_init # noqa: F401
---> 81 from . import __check_build # noqa: F401
82 from .base import clone
83 from .utils._show_versions import show_versions
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/init.py in
44 from ._check_build import check_build # noqa
45 except ImportError as e:
---> 46 raise_build_error(e)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/init.py in raise_build_error(e)
29 else:
30 dir_content.append(filename + '\n')
---> 31 raise ImportError("""%s
32 ___________________________________________________________________________
33 Contents of %s:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/_check_build.cpython-39-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/../.dylibs/libomp.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/../.dylibs/libomp.dylib
Contents of /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build:
init.py pycache _check_build.cpython-39-darwin.so
setup.py
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform
thanks
As you can see in this bug report, the new sklearn version 0.24 crashes on MacOS<10.15 systems.
Until this bug is fixed, the developers suggest installing the previous version using pip install -U scikit-learn==0.23.

AttributeError: module 'tensorflow' has no attribute 'gfile' even with tensorflow v1

I am having a problem as i upload my model in drive and mount it in Colab module imports are working fine in previous cell as i gave the root path and sys.append() it , I am using (tf.compat.v1) you can see it in ouptut, but still getting this error also tried (tensorflow v2) and used tf.io.gfile but still same error. Kindly help me
<module 'tensorflow_core.compat.v1.version' from '/usr/local/lib/python3.6/dist-packages/tensorflow_core/_api/v2/compat/v1/version/__init__.py'>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-e851eb463895> in <module>()
1 print(tf.version)
----> 2 category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
2 frames
/content/drive/My Drive/models/research/object_detection/utils/label_map_util.py in load_labelmap(path)
136 a StringIntLabelMapProto
137 """
--> 138 with tf.gfile.GFile(path, 'r') as fid:
139 label_map_string = fid.read()
140 label_map = string_int_label_map_pb2.StringIntLabelMap()
AttributeError: module 'tensorflow' has no attribute 'gfile'
Try to downgrade TF 1.15 from TF 2.x, your issue will be resolved.
Please refer code as shown below
!pip uninstall tensorflow
!pip install tensorflow==1.15
import tensorflow as tf
If you are looking for simple solution for Colab, please use %tensorflow_version 1.x magic command, which does for you without un-installation.
%tensorflow_version 1.x
import tensorflow as tf

Jupyter Notebook can't find module

Hi I have been trying to install twython for Jupyter Notebook. I have proved through the python repl that it is universally installed throughout my laptop. But it still won't appear on Jupyter Notebook. Looking for help trying to figure out it is found in a spot that it can be found by my Anaconda 3 Jupyter Notebook.
Context: Homework assignment trying to mine twitter for tweets
Here is the errors I am receiving and I am running Mac OS
/Users/name/twitter/__init__.py:22: UserWarning: The twython library has not been installed. Some functionality from the twitter package will not be available.
"The twython library has not been installed. "
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-38297a1141e0> in <module>
----> 1 import twitter
2 import twython
3 #---------------------------------------------
4 # Define a Function to Login Twitter API
5 def oauth_login():
~/twitter/__init__.py in <module>
34
35
---> 36 from nltk.twitter.common import json2csv
ModuleNotFoundError: No module named 'nltk.twitter
Have you installed nltk package?
If not, do it:
pip3 install -U nltk
then run python3
inside python3 command line, run:
import nltk
nltk.download()
after the download, restart jupyter, and run your code again.

How to fix 'cannot initialize type TensorProto DataType' error while importing torch?

I installed pytorch using pip3 command for my windows pc without GPU support.
But when I tried to import torch it is giving an error.
At first, there was a different error saying numpy version not matching and I updated the numpy to the latest version.
import torch
RuntimeError Traceback (most recent call last)
<ipython-input-10-c031d3dd82fc> in <module>()
----> 1 import torch
C:\Users\iamuraptha\Anaconda3\lib\site-packages\torch\__init__.py in <module>()
82 pass
83
---> 84 from torch._C import *
85
86 __all__ += [name for name in dir(_C)
RuntimeError: generic_type: cannot initialize type "TensorProtoDataType": an object with that name is already defined
I reinstalled anaconda and then created a virtual environment for pytorch.Now everything works fine
If you are running this in colab, remember to restart your runtime after installing your modules with pip.

Resources