Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cpt 16 Q8 GRU does not support ragged tensor #157

Open
Guo749 opened this issue Aug 24, 2024 · 0 comments
Open

[BUG] Cpt 16 Q8 GRU does not support ragged tensor #157

Guo749 opened this issue Aug 24, 2024 · 0 comments

Comments

@Guo749
Copy link

Guo749 commented Aug 24, 2024

Thanks for helping us improve this project!

Describe the bug
Please provide a clear and concise description of what the bug is, and specify the notebook name and the cell number at which the problem occurs (or the chapter and page in the book).

When executing code in q8 cpt 16, there is one issue

ValueError: Exception encountered when calling GRU.call().

Cannot index into an inner ragged dimension.

Arguments received by GRU.call():
  • sequences=tf.Tensor(shape=(None, None, 5), dtype=float32)
  • initial_state=None
  • mask=None
  • training=True

To Reproduce
Please copy the code that fails here, using code blocks like this:

np.random.seed(42)
tf.random.set_seed(42)

embedding_size = 5

model = tf.keras.Sequential([
    tf.keras.layers.InputLayer(input_shape=[None], dtype=tf.int32, ragged=True),
    tf.keras.layers.Embedding(input_dim=len(POSSIBLE_CHARS),
                              output_dim=embedding_size),
    tf.keras.layers.GRU(30),
    tf.keras.layers.Dense(1, activation="sigmoid")
])
optimizer = tf.keras.optimizers.SGD(learning_rate=0.02, momentum = 0.95,
                                    nesterov=True)
model.compile(loss="binary_crossentropy", optimizer=optimizer,
              metrics=["accuracy"])
history = model.fit(X_train, y_train, epochs=20,
                    validation_data=(X_valid, y_valid))

And if you got an exception, please copy the full stacktrace here:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-14-6882d7d9cf12>](https://localhost:8080/#) in <cell line: 17>()
     15 model.compile(loss="binary_crossentropy", optimizer=optimizer,
     16               metrics=["accuracy"])
---> 17 history = model.fit(X_train, y_train, epochs=20,
     18                     validation_data=(X_valid, y_valid))

1 frames
[/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
    120             # To get the full stack trace, call:
    121             # `keras.config.disable_traceback_filtering()`
--> 122             raise e.with_traceback(filtered_tb) from None
    123         finally:
    124             del filtered_tb

[/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
    120             # To get the full stack trace, call:
    121             # `keras.config.disable_traceback_filtering()`
--> 122             raise e.with_traceback(filtered_tb) from None
    123         finally:
    124             del filtered_tb

ValueError: Exception encountered when calling GRU.call().

Cannot index into an inner ragged dimension.

Arguments received by GRU.call():
  • sequences=tf.Tensor(shape=(None, None, 5), dtype=float32)
  • initial_state=None
  • mask=None
  • training=True

Expected behavior
A clear and concise description of what you expected to happen.

shoud train successfully

Screenshots
If applicable, add screenshots to help explain your problem.

https://screenbud.com/shot/f025e559-e87e-4751-b852-aa714fbdacf7

Versions (please complete the following information):

  • colab

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant