I received the following error for the C3W2 exercise 6.
ValueError Traceback (most recent call last)
Cell In[128], line 7
1 # Try the output for the introduction example
2 #sentence = “Many French citizens are goin to visit Morocco for summer”
3 #sentence = “Sharon Floyd flew to Miami last Friday”
4
5 # New york times news:
6 sentence = “Peter Parker , the White House director of trade and manufacturing policy of U.S , said in an interview on Sunday morning that the White House was working to prepare for the possibility of a second wave of the coronavirus in the fall , though he said it wouldn ’t necessarily come”
----> 7 predictions = predict(sentence, model, sentence_vectorizer, tag_map)
8 for x,y in zip(sentence.split(’ '), predictions):
9 if y != ‘O’:
Cell In[126], line 24, in predict(sentence, model, sentence_vectorizer, tag_map)
22 sentence_vectorized = tf.expand_dims(sentence_vectorized, 0)
23 # Get the model output
—> 24 output = model(sentence_vectorized)
25 # Get the predicted labels for each token, using argmax function and specifying the correct axis to perform the argmax
26 outputs = np.argmax(output, axis = -1)
File /usr/local/lib/python3.8/dist-packages/keras/src/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
—> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File /usr/local/lib/python3.8/dist-packages/keras/src/engine/input_spec.py:235, 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: "
238 f"expected ndim={spec.ndim}, found ndim={ndim}. "
239 f"Full shape received: {tuple(shape)}”
240 )
241 if spec.max_ndim is not None:
242 ndim = x.shape.rank
ValueError: Exception encountered when calling layer ‘sequential’ (type Sequential).
Input 0 of layer “lstm_7” is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (1, 1, 52, 50)
Call arguments received by layer ‘sequential’ (type Sequential):
• inputs=tf.Tensor(shape=(1, 1, 52), dtype=int64)
• training=None
• mask=None
From my understanding in the model building stage for the LSTM for the C3W2 exercise 3,
i have use vocab_size + 1 for the input and mask_zero = True in the sequential stage.
May I know what is the problem that might have occurred in the model building stage for exercise