Is train_model of Siamise has correct loss?

I have successfully passed tests, but have huge loss like this in Exercise 03. Is this ok?

The goal is to find the minimum cost. The minimum doesn’t have to be a small value.

Do all other aspects of the assignment give the expected results?

Yes, I passed all tests in assingment. It is expected anyway, because we load pretrained model.

1 Like


Hello, I have been facing this error for hours, could you please help me out if you can?

you need to share complete image of the error you got @Ndachimya_Edward

Thanks for your prompt response, but unfortunately, the image will be too long for a screenshot. But here is the plain text of the error pasted below:

UnimplementedError Traceback (most recent call last)
Cell In[68], line 9
3 train_generator = train_dataset.shuffle(len(train_Q1),
4 seed=7,
5 reshuffle_each_iteration=True).batch(batch_size=batch_size)
6 val_generator = val_dataset.shuffle(len(val_Q1),
7 seed=7,
8 reshuffle_each_iteration=True).batch(batch_size=batch_size)
----> 9 model = train_model(Siamese, TripletLoss,text_vectorization,
10 train_generator,
11 val_generator,
12 train_steps=train_steps,)

Cell In[67], line 31, in train_model(Siamese, TripletLoss, text_vectorizer, train_dataset, val_dataset, d_feature, lr, train_steps)
26 model.compile(loss=TripletLoss,
27 optimizer=tf.keras.optimizers.Adam(learning_rate=lr)
28 )
30 # Train the model
—> 31 model.fit(train_dataset,
32 epochs=train_steps,
33 validation_data=val_dataset
34 )
36 ### END CODE HERE ###
38 return model

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/tensorflow/python/eager/execute.py:53, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
51 try:
52 ctx.ensure_initialized()
—> 53 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
54 inputs, attrs, num_outputs)
55 except core._NotOkStatusException as e:
56 if name is not None:

UnimplementedError: Graph execution error:

Detected at node ‘SiameseModel/Cast’ defined at (most recent call last):
File “/usr/lib/python3.8/runpy.py”, line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/usr/lib/python3.8/runpy.py”, line 87, in _run_code
exec(code, run_globals)
File “/usr/local/lib/python3.8/dist-packages/ipykernel_launcher.py”, line 17, in
app.launch_new_instance()
File “/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py”, line 1043, in launch_instance
app.start()
File “/usr/local/lib/python3.8/dist-packages/ipykernel/kernelapp.py”, line 728, in start
self.io_loop.start()
File “/usr/local/lib/python3.8/dist-packages/tornado/platform/asyncio.py”, line 195, in start
self.asyncio_loop.run_forever()
File “/usr/lib/python3.8/asyncio/base_events.py”, line 570, in run_forever
self._run_once()
File “/usr/lib/python3.8/asyncio/base_events.py”, line 1859, in _run_once
handle._run()
File “/usr/lib/python3.8/asyncio/events.py”, line 81, in _run
self._context.run(self._callback, *self._args)
File “/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py”, line 516, in dispatch_queue
await self.process_one()
File “/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py”, line 505, in process_one
await dispatch(*args)
File “/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py”, line 412, in dispatch_shell
await result
File “/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py”, line 740, in execute_request
reply_content = await reply_content
File “/usr/local/lib/python3.8/dist-packages/ipykernel/ipkernel.py”, line 422, in do_execute
res = shell.run_cell(
File “/usr/local/lib/python3.8/dist-packages/ipykernel/zmqshell.py”, line 540, in run_cell
return super().run_cell(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py”, line 3009, in run_cell
result = self._run_cell(
File “/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py”, line 3064, in _run_cell
result = runner(coro)
File “/usr/local/lib/python3.8/dist-packages/IPython/core/async_helpers.py”, line 129, in pseudo_sync_runner
coro.send(None)
File “/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py”, line 3269, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File “/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py”, line 3448, in run_ast_nodes
if await self.run_code(code, result, async
=asy):
File “/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py”, line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “/tmp/ipykernel_15/1427930616.py”, line 9, in
model = train_model(Siamese, TripletLoss,text_vectorization,
File “/tmp/ipykernel_15/3884812692.py”, line 31, in train_model
model.fit(train_dataset,
File “/usr/local/lib/python3.8/dist-packages/keras/src/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py”, line 1742, in fit
tmp_logs = self.train_function(iterator)
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 1080, in train_step
y_pred = self(x, training=True)
File “/usr/local/lib/python3.8/dist-packages/keras/src/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py”, line 569, in call
return super().call(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/keras/src/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/base_layer.py”, line 1150, in call
outputs = call_fn(inputs, *args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/keras/src/utils/traceback_utils.py”, line 96, in error_handler
return fn(*args, **kwargs)
File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/functional.py”, line 512, in call
return self._run_internal_graph(inputs, training=training, mask=mask)
File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/functional.py”, line 651, in _run_internal_graph
y = self._conform_to_reference_input(y, ref_input=x)
File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/functional.py”, line 748, in _conform_to_reference_input
tensor = tf.cast(tensor, dtype=ref_input.dtype)
Node: ‘SiameseModel/Cast’
2 root error(s) found.
(0) UNIMPLEMENTED: Cast string to float is not supported
[[{{node SiameseModel/Cast}}]]
(1) CANCELLED: Function was cancelled before it was started
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_81721]

Please Note that the unit test for the function has been passed though.

hi @Ndachimya_Edward

Make sure you have defined inputs of type tf.string

Check exercise 1 or where input1 and input2 need to be of tf.string and not cast string.

Regards
DP

Thank you so much!

1 Like

Happy to help!!

Keep Learning!!!

Regards
DP

1 Like