C3W2_Assignment 4.4 - Training the Model Error

/notebooks/C3W2_Assignment.ipynb
4.4 - Training the Model Error says you will get an error (below) and I do. Can not change the cell. Can this be fixed?

  • You will run into an error if you just pass the datasets as they are right now, because they are not prepared in batches. You must use the method .batch that returns a dataset already divided in batches

Hi @januttall

please don’t post any codes or share any link to your assignment on public post.

Kindly share a screenshot of the error you are mentioning. Do not include any part of grade cell codes.

Regards
DP

This is the error (and the rest of the error is included at the end of this post).

I ran the first four graded functions through the grader successfully.

The fifth graded function passed all tests, but the grader failed all the tests, showing this error on the first function:

image

The rest of error printout:

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 /tmp/autograph_generated_file_jtloxyg.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 "/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py", line 1338, in train_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py", line 1322, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py", line 1303, in run_step  **
    outputs = model.train_step(data)
File "/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py", line 1085, in train_step
    return self.compute_metrics(x, y, y_pred, sample_weight)
File "/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py", line 1179, in compute_metrics
    self.compiled_metrics.update_state(y, y_pred, sample_weight)
File "/usr/local/lib/python3.8/dist-packages/keras/src/engine/compile_utils.py", line 605, in update_state
    metric_obj.update_state(y_t, y_p, sample_weight=mask)
File "/usr/local/lib/python3.8/dist-packages/keras/src/utils/metrics_utils.py", line 77, in decorated
    update_op = update_state_fn(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/keras/src/metrics/base_metric.py", line 140, in update_state_fn
    return ag_update_state(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/keras/src/metrics/base_metric.py", line 728, in update_state  **
    return super().update_state(matches, sample_weight=sample_weight)
File "/usr/local/lib/python3.8/dist-packages/keras/src/metrics/base_metric.py", line 504, in update_state
    ) = losses_utils.squeeze_or_expand_dimensions(
File "/usr/local/lib/python3.8/dist-packages/keras/src/utils/losses_utils.py", line 224, in squeeze_or_expand_dimensions
    sample_weight = tf.squeeze(sample_weight, [-1])

ValueError: Can not squeeze dim[1], expected a dimension of 1, got 104 for '{{node Squeeze}} = Squeeze[T=DT_FLOAT, squeeze_dims=[-1]](Cast_7)' with input shapes: [?,104].

I am also getting this error, which I do not know what to do with:

This warning from tensorflow which can be ignored.

But as per the submission grader output, there is surely an error in your first grader cell. Check if recalled the functions correctly.

Next the training failed because you input shape is not matching, so there is again issue in your model recalling. Having said that you submitting even after having an error is a surprise.

Please send screenshot of codes for Grade cell get_sentence_vectorizer via personal DM

@januttall

Don’t post codes here.