handson-ml2 icon indicating copy to clipboard operation
handson-ml2 copied to clipboard

[Chap 16] TypeError: '_NestedVariant' object is not subscriptable

Open lucacox opened this issue 5 years ago • 4 comments

In chapter 16 notebook running this cell:

batch_size = 32
dataset = dataset.shuffle(10000).batch(batch_size)
dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))

produces this error in Colab:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-22-58d8a4056e3e> in <module>()
      6 batch_size = 32
      7 dataset = dataset.shuffle(10000).batch(batch_size)
----> 8 dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))

10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
    256       except Exception as e:  # pylint:disable=broad-except
    257         if hasattr(e, 'ag_error_metadata'):
--> 258           raise e.ag_error_metadata.to_exception(e)
    259         else:
    260           raise

TypeError: in user code:

    <ipython-input-15-6240017d8f77>:8 None  *
        dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))

    TypeError: '_NestedVariant' object is not subscriptable

lucacox avatar Sep 27 '20 14:09 lucacox

I can't reproduce your error.

ibeauregard avatar Oct 27 '20 17:10 ibeauregard

Hi @lucacox ,

I can't reproduce the error either. Could you please make sure you're using the latest versions of the code and the libraries and try again? You can find the instructions to update these here.

ageron avatar Mar 26 '21 22:03 ageron

The solution of your problem is to run whole script from the begining, or just restart the kernel (clear workspace if working in jupyter lab or jupyter notebook).

The issue occures when you run lines BETWEEN

train_size = dataset_size * 90 // 100
dataset = tf.data.Dataset.from_tensor_slices(encoded[:train_size])

AND

batch_size = 32
dataset = dataset.shuffle(10000).batch(batch_size)
dataset = dataset.map(lambda windows: (windows[:, :-1], windows[:, 1:]))

more than once.

Yarxin avatar Mar 20 '22 08:03 Yarxin

Thanks. Rerunning the entire script from the beginning helps.

asoisaac avatar Mar 07 '23 05:03 asoisaac