Hi @balaji.ambresh ,
Sorry, just one last question.
Here’s my model
" model = tf.keras.Sequential([
tf.keras.layers.Embedding(num_words, embedding_dim, input_length=maxlen),
tf.keras.layers.GlobalAveragePooling1D(),
tf.keras.layers.Dense(24, activation=‘relu’),
tf.keras.layers.Dense(5, activation=‘softmax’)
])
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), # try: MAE, MSE
optimizer='adam',
metrics=['accuracy']) "
When I run:
"model = create_model(NUM_WORDS, EMBEDDING_DIM, MAXLEN)
history = model.fit(train_padded_seq, train_label_seq, epochs=30, validation_data=(val_padded_seq, val_label_seq))"
I’m getting:
"---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Volumes/GoogleDrive-107870226340842906740/My Drive/My_Research/Intro_Tensorflow/tensorflow-1-public/C3/W2/assignment/C3W2_Assignment.ipynb Cell 30 in <cell line: 3>()
1 model = create_model(NUM_WORDS, EMBEDDING_DIM, MAXLEN)
----> 3 history = model.fit(train_padded_seq, train_label_seq, epochs=30, validation_data=(val_padded_seq, val_label_seq))
File ~/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/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 /var/folders/61/2rsxbqtx2zqbwlb914ssc_zm0000gn/T/autograph_generated_fileayf1gjrd.py:15, in outer_factory..inner_factory..tf__train_function(iterator)
13 try:
14 do_return = True
—> 15 retval = ag_.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False
ValueError: in user code:
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py", line 1160, in train_function *
return step_function(self, iterator)
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py", line 1146, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py", line 1135, in run_step **
outputs = model.train_step(data)
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py", line 994, in train_step
loss = self.compute_loss(x, y, y_pred, sample_weight)
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/training.py", line 1052, in compute_loss
return self.compiled_loss(
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/engine/compile_utils.py", line 265, in __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/losses.py", line 152, in __call__
losses = call_fn(y_true, y_pred)
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/losses.py", line 272, in call **
return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/losses.py", line 1990, in categorical_crossentropy
return backend.categorical_crossentropy(
File "/Users/edsykes/opt/anaconda3/envs/tf2_python_3_8_13/lib/python3.10/site-packages/keras/backend.py", line 5529, in categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
ValueError: Shapes (None, 1) and (None, 5) are incompatible"
It appears that the shapes are not compatible, but I don’t know which ones it is not happy with.
thank you!!
Ed