keras-io icon indicating copy to clipboard operation
keras-io copied to clipboard

In keras-io/guides/keras_nlp /transformer_pretraining.py there is an documentation bug

Open debrupf2946 opened this issue 1 year ago • 3 comments
trafficstars

Issue Type

Documentation Bug

Source

source

Keras Version

keras-2.15.0

Custom Code

No

OS Platform and Distribution

Google Colab

Python version

3x

GPU model and memory

No response

Current Behavior?

In line 437 pooled_tokens = keras.layers.GlobalAveragePooling1D()(encoded_tokens[0]) encoded_tokens[0] is giving the following error

ValueError                                Traceback (most recent call last)
[<ipython-input-23-599e891a0cf7>](https://localhost:8080/#) in <cell line: 8>()
      6 # Encode and pool the tokens.
      7 encoded_tokens = encoder_model(inputs)
----> 8 pooled_tokens = keras.layers.GlobalAveragePooling1D()(encoded_tokens[0])
      9 
     10 # Predict an output label.

1 frames
[/usr/local/lib/python3.10/dist-packages/keras/src/engine/input_spec.py](https://localhost:8080/#) in assert_input_compatibility(input_spec, inputs, layer_name)
    233             ndim = shape.rank
    234             if ndim != spec.ndim:
--> 235                 raise ValueError(
    236                     f'Input {input_index} of layer "{layer_name}" '
    237                     "is incompatible with the layer: "

ValueError: Input 0 of layer "global_average_pooling1d" is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (128, 256)

Standalone code to reproduce the issue or tutorial link

pooled_tokens = keras.layers.GlobalAveragePooling1D()(encoded_tokens)

Relevant log output

No response

debrupf2946 avatar Feb 05 '24 17:02 debrupf2946