ML challenge - SMS classifier - LSTM Error

Hellooo :wave:,
I’m struggling with the last challenge of the ML course. More specifically so there is a problem with the installation of TF in google colab:

Requirement already satisfied: tf-nightly in /usr/local/lib/python3.7/dist-packages (2.9.0.dev20220116)
Requirement already satisfied: wrapt>=1.11.0 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.13.3)
Requirement already satisfied: flatbuffers>=1.12 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (2.0)
Requirement already satisfied: h5py>=2.9.0 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (3.1.0)
Requirement already satisfied: keras-nightly~=2.9.0.dev in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (2.9.0.dev2022011608)
Requirement already satisfied: protobuf>=3.9.2 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (3.17.3)
Collecting absl-py>=1.0.0
  Using cached absl_py-1.0.0-py3-none-any.whl (126 kB)
Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (0.23.1)
Requirement already satisfied: opt-einsum>=2.3.2 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (3.3.0)
Requirement already satisfied: gast<=0.4.0,>=0.2.1 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (0.4.0)
Requirement already satisfied: astunparse>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.6.3)
Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.15.0)
Requirement already satisfied: libclang>=9.0.1 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (12.0.0)
Requirement already satisfied: google-pasta>=0.1.1 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (0.2.0)
Requirement already satisfied: keras-preprocessing>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.1.2)
Requirement already satisfied: typing-extensions>=3.6.6 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (3.10.0.2)
Requirement already satisfied: tf-estimator-nightly~=2.9.0.dev in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (2.9.0.dev2022011609)
Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.1.0)
Requirement already satisfied: grpcio<2.0,>=1.24.3 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.43.0)
Requirement already satisfied: setuptools<60 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (57.4.0)
Requirement already satisfied: tb-nightly~=2.8.0.a in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (2.8.0a20220114)
Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.7/dist-packages (from tf-nightly) (1.21.5)
Requirement already satisfied: wheel<1.0,>=0.23.0 in /usr/local/lib/python3.7/dist-packages (from astunparse>=1.6.0->tf-nightly) (0.37.1)
Requirement already satisfied: cached-property in /usr/local/lib/python3.7/dist-packages (from h5py>=2.9.0->tf-nightly) (1.5.2)
Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (1.35.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (0.4.6)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (0.6.1)
Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (1.0.1)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (1.8.1)
Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (3.3.6)
Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.7/dist-packages (from tb-nightly~=2.8.0.a->tf-nightly) (2.23.0)
Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tb-nightly~=2.8.0.a->tf-nightly) (4.8)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tb-nightly~=2.8.0.a->tf-nightly) (0.2.8)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tb-nightly~=2.8.0.a->tf-nightly) (4.2.4)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.7/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tb-nightly~=2.8.0.a->tf-nightly) (1.3.0)
Requirement already satisfied: importlib-metadata>=4.4 in /usr/local/lib/python3.7/dist-packages (from markdown>=2.6.8->tb-nightly~=2.8.0.a->tf-nightly) (4.10.0)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tb-nightly~=2.8.0.a->tf-nightly) (3.7.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /usr/local/lib/python3.7/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tb-nightly~=2.8.0.a->tf-nightly) (0.4.8)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tb-nightly~=2.8.0.a->tf-nightly) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tb-nightly~=2.8.0.a->tf-nightly) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tb-nightly~=2.8.0.a->tf-nightly) (1.24.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tb-nightly~=2.8.0.a->tf-nightly) (2021.10.8)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tb-nightly~=2.8.0.a->tf-nightly) (3.1.1)
Installing collected packages: absl-py
  Attempting uninstall: absl-py
    Found existing installation: absl-py 0.12.0
    Uninstalling absl-py-0.12.0:
      Successfully uninstalled absl-py-0.12.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow-metadata 1.5.0 requires absl-py<0.13,>=0.9, but you have absl-py 1.0.0 which is incompatible.
Successfully installed absl-py-1.0.0
WARNING: The following packages were previously imported in this runtime:
  [absl]
You must restart the runtime in order to use newly installed versions.
Requirement already satisfied: tensorflow-datasets in /usr/local/lib/python3.7/dist-packages (4.0.1)
Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (1.15.0)
Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (4.62.3)
Requirement already satisfied: termcolor in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (1.1.0)
Requirement already satisfied: importlib-resources in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (5.4.0)
Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (2.23.0)
Requirement already satisfied: absl-py in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (1.0.0)
Requirement already satisfied: tensorflow-metadata in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (1.5.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (1.21.5)
Requirement already satisfied: protobuf>=3.6.1 in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (3.17.3)
Requirement already satisfied: promise in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (2.3)
Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (0.16.0)
Requirement already satisfied: dm-tree in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (0.1.6)
Requirement already satisfied: dill in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (0.3.4)
Requirement already satisfied: attrs>=18.1.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow-datasets) (21.4.0)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->tensorflow-datasets) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->tensorflow-datasets) (1.24.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->tensorflow-datasets) (2021.10.8)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->tensorflow-datasets) (2.10)
Requirement already satisfied: zipp>=3.1.0 in /usr/local/lib/python3.7/dist-packages (from importlib-resources->tensorflow-datasets) (3.7.0)
Requirement already satisfied: googleapis-common-protos<2,>=1.52.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow-metadata->tensorflow-datasets) (1.54.0)
Collecting absl-py
  Using cached absl_py-0.12.0-py3-none-any.whl (129 kB)
Installing collected packages: absl-py
  Attempting uninstall: absl-py
    Found existing installation: absl-py 1.0.0
    Uninstalling absl-py-1.0.0:
      Successfully uninstalled absl-py-1.0.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tf-nightly 2.9.0.dev20220116 requires absl-py>=1.0.0, but you have absl-py 0.12.0 which is incompatible.
Successfully installed absl-py-0.12.0
WARNING: The following packages were previously imported in this runtime:
  [absl]
You must restart the runtime in order to use newly installed versions.
2.9.0-dev20220116

As you can see, it has compatibility problems and it doesn’t install properly some libraries. This causes me some trouble when running the model.fit() method especially when I use the LSTM layers.

Epoch 1/10
---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
<ipython-input-40-e4e6709223a4> in <module>()
      2                     train_labels,
      3                     epochs=10,
----> 4                     validation_data=(test_pdd, test_labels))

1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     53     ctx.ensure_initialized()
     54     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 55                                         inputs, attrs, num_outputs)
     56   except core._NotOkStatusException as e:
     57     if name is not None:

UnknownError: Graph execution error:

Fail to find the dnn implementation.
	 [[{{node CudnnRNN}}]]
	 [[sequential_2/lstm_2/PartitionedCall]] [Op:__inference_train_function_9736]

Apparently, the error could be given by problems with the TF version:

Do you know how I can fix the problem? Do you think that the problem with the LTSM is connected with the aforementioned error?

Thanks :rocket:

Google Colab already comes with Tensorflow installed, so you should be able to import and use it from the start.

@Jagaya The error occurs when I run the first block of code which is given in the challenge, so I don’t understand why it happens:

# import libraries
try:
   #%tensorflow_version only exists in Colab.
   !pip install tf-nightly
except Exception:
  pass
import tensorflow as tf
import pandas as pd
from tensorflow import keras
!pip install tensorflow-datasets
import tensorflow_datasets as tfds
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)

This is where is the block of code I’m talking about and it gives back the error that I showed you.

Thanks, BTW

hm… ok it seems like a very complicated issue… well I just looked into my solution, ran it through again and got no problem whatsoever. Though it’s some time ago I made it so I cannot say WHY I altered the imports - but I did.

Namely I commented out the !pip install as well a the import tensorflow_datasets.
On top of that, I didn’t use the validation_data argument but instead used validation_split in the model.fit() method.

So you could try that and see if it resolves the error.
As I said, I ran my notebook again and it worked with no problem, including passing the test.

So this is what you’ve done???

# import libraries
try:
   %tensorflow_version only exists in Colab.
   !pip install tf-nightly
except Exception:
  pass
import tensorflow as tf
import pandas as pd
from tensorflow import keras
#!pip install tensorflow-datasets
import tensorflow_datasets as tfds
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)

If I do this it still gives me the same problems.
The strange thing is that if I use dense layers the .fit() works,( butI do not pass the challenge) but as soon I add a LSTM layer it doesn’t work. :pleading_face:

This is my model:

model = tf.keras.Sequential()
model.add(tf.keras.layers.Embedding(vocab_size, embeding_dim, input_length=max_len))
# model.add(tf.keras.layers.LSTM(n_lstm, dropout=drop_lstm))
model.add(tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(n_lstm, dropout=drop_lstm, return_sequences=False)))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))

I don’t think there is something wrong with it, what do you think?

No, I should have just copy-pasted right away xD
Here is what I did:

# import libraries
try:
   #%tensorflow_version only exists in Colab.
   #!pip install tf-nightly
  pass
except Exception:
  pass
import tensorflow as tf
import pandas as pd
from tensorflow import keras
#!pip install tensorflow-datasets
#import tensorflow_datasets as tfds
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)

Note the “pass” in the try-except → I think the try-block cannot be empty. Though no idea.
Also I commented them out so in case I come back, I know what I changed.

hm… I don’t know this dropout or this Bidirectional layer, though I haven’t looked all to much into LSTM after the challenge. My model is complete basic, apart from the provided stuff it’s just a plain LSTM with some neurons.

Two things. One, if you can post a shareable link to your notebook, it will probably be easier to debug the problem. There are a lot of possible issues and errors and it’s easier to work with the whole rather than pieces.

Two, there is currently a dependency bug that is preventing some tensorflow installations (like several of mine). I have no idea if that could affect the tensorflow usage on colab.

1 Like

Thank both of you guys :grinning: @Jagaya @jeremy.a.gray
I’ve done it, and you were very helpful.
@jeremy.a.gray I didn’t want to give the notebook’s link because it would have defeated the purpose of the challenge.

1 Like

y’all the real mvp. thank you so much, can finally get back and grab that certificate .

Hey i am getting the same problem can you tell me how you fixed it

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.