XLNetTokenizer requires the SentencePiece library but it was not found in your environment - google-colaboratory

I am trying to implement the XLNET on Google Collaboratory. But I get the following issue.
ImportError:
XLNetTokenizer requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the
installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones
that match your environment.
I have also tried the following steps:
!pip install -U transformers
!pip install sentencepiece
from transformers import XLNetTokenizer
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased-spiece.model')
Thank you for your help in advance.

After the
!pip install transformers and
!pip install sentencepiece
please restart your runtime and then execute all other codes.

I got the same error in google colab. Restarting the runtime did it for me.

Related

Difficulty updating keras/tensorflow on mac

I am working on a jupyter notebook script which I used last year to train a neural network.
When I try to import the keras tokenizer:
from keras.preprocessing.text import Tokenizer
I receive this error
I have seen other posts which suggest that I need to update tensorflow. My anaconda environment tells me I have 1.13.1 installed. But when I try to update tensorflow-base to 1.15 in the anaconda navigator, I receive this error:
I can update tensorflow from my command line using:
conda install tensorflow=1.15.0
But this doesn't update tensorflow in my anaconda environment and the error persists in my notebook.
Any help would be much appreciated! As you can probably tell, I am a novice python user.
The error says some packages needed to update Tensorflow/Andaconda requires Python 3.11 or newer. Since not all of the error log can be seen however, I would upgrade to python 3.7 to be safe. You can download this from the official page: https://www.python.org/downloads/
If the problem persists, try using pip to update the packages(In bash) :
pip install tensorflow
pip install conda
If you get an error while using pip, try:
pip3 install tensorflow
pip3 install conda
This same method can be used to update keras:
pip install keras
or if that does not work:
pip3 install keras
If pip is not recognized at a command, Python 3.7 is not added to path. I do not have experience with macOS, but this article should go into enough depth.
https://realpython.com/add-python-to-path/#how-to-add-python-to-path-on-linux-and-macos

Importing TensorFlow "async" syntax error

I am trying to use the module imageai for a project and ran the line "from imageai.Detection import ObjectDetection". However, when I do so, this error appears:
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:114
def TFE_ContextOptionsSetAsync(arg1, async):
^
SyntaxError: invalid syntax
I found someone who had the same issue here: https://github.com/tensorflow/tensorflow/issues/20690 , but I'm not quite sure how to edit the last file of the trace where the error occurs. Does anyone have any tips on how to do this? Thanks!
I have tried looking at the above GitHub error but am not sure how to approach it.
ImageAI uses Pytorch as backend. So you need to install all the required libraries before installing and importing the imageai module.
Please use the code below to install imageai in your system:
pip install cython pillow>=7.0.0 numpy>=1.18.1 opencv-python>=4.1.2 torch>=1.9.0 --extra-index-url https://download.pytorch.org/whl/cpu torchvision>=0.10.0 --extra-index-url https://download.pytorch.org/whl/cpu pytest==7.1.3 tqdm==4.64.1 scipy>=1.7.3 matplotlib>=3.4.3 mock==4.0.3
pip install imageai --upgrade
Now, import the Object detection from imageai:
from imageai.Detection import ObjectDetection
Please refer this link for more details.
Note: You can easily install imageai in Google Colab with this code
!pip install imageai
from imageai.Detection import ObjectDetection
Hints: Please use below code to install, import and check the TensorFlow version
pip install tensorflow
import tensorflow as tf
tf.__version__

Install tensorflow 1.x on colab

Now that Google Colab is not supporting tensorflow 1.x is there a way to install it through e.g. pip and set up your environment in a similar fashion to what the old %tensorflow_version 1.x did? I really really dont want to rewamp all my code to TF 2
It seems that only tf2 is supported by Colab, but that's not true, you still can use pip to uninstall tf2 and install a specific version of tf1. !yes|pip uninstall tensorflow, !pip install tensorflow==1.15.5 Maybe you should install other dependencies. So use !pip install -r requirements.txt Attention! You must restart the runtime in order to use newly installed versions.

Unable render neural network structural graph on kaggle notebook

I got this message on Kaggle notebook
'Failed to import pydot. You must `pip install pydot` and install graphviz (https://graphviz.gitlab.io/download/), ', 'for `pydotprint` to work.'
Rendering NN structural graphs doesn't work. What is the problem? Is it a problem on Kaggle side? Code I was running was very simple.
The first thing to do is to turn on internet support on your kaggle notebook and install the following packages via pip packet manager:
!pip install pydot
!pip install pydotplus
!pip install graphviz

Issue while installing Tensorflow

While installing tensorflow(CPU only) I am facing below error :
>>> import tensorflow as tf
Traceback (most recent call last): File "", line 1, in
ImportError: No module named 'tensorflow'
I have python version 3.5
Did you first try:
pip3 install --upgrade tensorflow
It's maybe due to some missing .py files. Download the package from Github link and paste it on python35/Lib/site-packages
import tensorflow as tf
invokes tensorflow not install it there is great article how to install on tensorflow website.
You have not mentioned platform/OS you working on also steps taken if any before trying this command.
best thing for beginners I feel is Anaconda which is suit of packages required for data science.
Give it a try.
python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
You can search for the appropriate version you wish to install and update in the above mentioned url.
Try to install an old version of Tensorflow as:
pip install tensorflow==1.5.0
After installing the old version retry with the newest version, for example:
pip install tensorflow==1.9.0