handson-ml2
handson-ml2 copied to clipboard
16_nlp_with_rnns_and_attention.ipynb cell #18 ---model = keras.models.Sequential... ---generates NotImplementedError: Cannot convert a symbolic Tensor (gru_2/strided_slice:0) to a numpy array
Notebook: 16_nlp_with_rnns_and_attention.ipynb cell 18
model = keras.models.Sequential...
generates NotImplementedError: Cannot convert a symbolic Tensor (gru_2/strided_slice:0) to a numpy array
Hi @sulu987 ,
I cannot reproduce this issue, everything works fine on my system and on Colab.
Questions:
- Are you running on Colab? Or Kaggle? Or your own system?
- If it's on your own system, are you running the most recent notebook version?
- If it's on your own system, what version of TensorFlow are you using?
- Have you made any modification to the code?
- Have you run the cells in order?
Edit: it looks like this may be linked to TensorFlow issue #9706 when using Python 3.8. One workaround is to use Python 3.7 instead.
I got it running - thanks for supporting your readers
Hi @sulu987 , I'm glad things work now! Could you please explain what fixed the issue, in case others run into the same issue? Thanks!
I am facing a similar issue: https://stackoverflow.com/q/69320194/6907424. I ran it locally. I have mentioned the packages installed on my machine.
Hi @hafiz031 ,
I've tried to reproduce this issue, but the code just works fine. Here's a notebook containing your StackOverflow code example (I just added a couple extra cells to do the imports and create a fake dataset, and I replaced lr
with learning_rate
as lr
is deprecated), and it runs without a problem. Could you please check that X_train
, y_train
, X_valid
and y_valid
are regular NumPy arrays or concrete tensors (containing actual values), not symbolic tensors?
@ageron I have printed the types of the respective variables and all of them are <class 'numpy.ndarray'>
. Another observation is when the CPU
version of Tensorflow
is used (in my local machine) the code runs perfectly. It creates problem when I use the GPU
version.
Hi @hafiz031 , That's interesting, thanks for your feedback. I tried running the Colab Notebook containing your code, using with a GPU runtime, but it worked fine. I even tried reverting to an older version of TensorFlow (2.2), but it still worked fine. Could you please provide a link to a Colab Notebook that demonstrates the issue? Thanks.
@ageron et al: FYI I hit the same error but with Chapter 15 trying to initialize the SimpleRNN as part of the "Using a Simple RNN" section. I'm running on Windows with an Anaconda + VSCode setup, tensorflow 2.3.0 and before the "fix" numpy 1.21.2. The full conda list output for what I have after the fix is here; I unfortunately didn't save the full list before the fix but it seems like it only messed with numpy and numpy-base.
The "fix" was forcing numpy 1.19.5 via "pip install numpy==1.19.5" in the Anaconda environment window, it's been working for a while and various other notebooks seem to go through fully fine as well, so I can't find any side effects yet, but it does seem like a hacky fix...but hopefully less hacky than some of the stuff listed at https://github.com/tensorflow/models/issues/9706 with editing *\tensorflow\python\ops\array_ops.py. ; )