tensorflow / tensorflow/text

Problem when running the model to check the shape of the output.

Open
#1,305 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.3k
Forks
379
Avg merge
3h 30m
Merged PRs (30d)
8

Description

While executing the below code:

for input_example_batch, target_example_batch in dataset.take(1): example_batch_predictions = model(input_example_batch) print(example_batch_predictions.shape, "# (batch_size, sequence_length, vocab_size)")
The following error is encountered:


InvalidArgumentError Traceback (most recent call last)
Cell In[42], line 3
1 for input_example_batch, target_example_batch in dataset.take(1):
2 print(input_example_batch.shape)
----> 3 example_batch_predictions = model(input_example_batch)
4 print(
5 example_batch_predictions.shape,
6 "# (batch_size, sequence_length, vocab_size)",
7 )

File ~/Desktop/coursera/venv/lib/python3.11/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback..error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.traceback)
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

Cell In[40], line 17, in MyModel.call(self, inputs, states, return_state, training)
13 # since we are training a text generation model,
14 # we use the previous state, in training. If there is no state,
15 # then we initialize the state
16 if states is None:
---> 17 states = self.gru.get_initial_state(x)
18 x, states = self.gru(x, initial_state=states, training=training)
19 x = self.dense(x, training=training)

InvalidArgumentError: Exception encountered when calling MyModel.call().

{{function_node _wrapped__Pack_N_2_device/job:localhost/replica:0/task:0/device:CPU:0}} Shapes of all inputs must match: values[0].shape = [64,100,256] != values[1].shape = [] [Op:Pack] name:

Arguments received by MyModel.call():
• inputs=tf.Tensor(shape=(64, 100), dtype=int64)
• states=None
• return_state=False
• training=False

Kindly suggest.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the code shown in notebook cells 40–42 and the Keras traceback, especially MyModel.call and the self.gru.get_initial_state(x) call. Compare the GRU state initialization with the inputs passed to model(input_example_batch), then rerun the example and verify that it prints the expected prediction shape without InvalidArgumentError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.