# C3W3\_Assignment 3 - Error thrown just prior to end of first epoch

**URL:** <https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245>\
**Category:** Natural Language Processing in TensorFlow\
**Created:** [December 30, 2023, 11:25pm UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245 "2023-12-30T23:25:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond\_Hawthorne](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Raymond\_Hawthorne](https://community.deeplearning.ai/u/Raymond_Hawthorne)\
**Post date:** [December 30, 2023, 11:25pm UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/1 "2023-12-30T23:25:07Z")

</div>

When trying to train the model (under a number of different architectures), I’m getting the following error just prior to the first epoch completing:

UnimplementedError: Cast string to float is not supported  
[[node binary\_crossentropy/Cast  
(defined at /opt/conda/lib/python3.8/site-packages/keras/losses.py:1797)  
]] [Op:\_\_inference\_test\_function\_64273]

Errors may have originated from an input operation.  
Input Source operations connected to node binary\_crossentropy/Cast:  
In[0] ExpandDims (defined at /opt/conda/lib/python3.8/site-packages/keras/engine/compile\_utils.py:677)

The cells at the start of the assignment are showing the expected outputs. Anyone else run into this issue and have suggestions on things I may be able to try to resolve?

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [December 31, 2023, 3:36pm UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/2 "2023-12-31T15:36:59Z")

</div>

Hello Raymond,

Can you share a screenshot of the image of your error without sharing any codes.

Kindly look at your model compile statement where your function call from strong to float is creating this error.

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [December 31, 2023, 4:50pm UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/3 "2023-12-31T16:50:20Z")

</div>

Labels should be numeric.

---

<div class="post-metadata">

**Author:** ![Raymond\_Hawthorne](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Raymond\_Hawthorne](https://community.deeplearning.ai/u/Raymond_Hawthorne)\
**Post date:** [January 1, 2024, 12:48am UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/4 "2024-01-01T00:48:33Z")

</div>

## Hello Deepti, The stack trace is pretty long. But here it is: Epoch 1/20 4493/4500 [============================\>.] - ETA: 0s - loss: 0.5779 - accuracy: 0.6899

UnimplementedError Traceback (most recent call last)  
 in   
5  
6 # Train the model and save the training history  
----\> 7 history = model.fit(train\_pad\_trunc\_seq, train\_labels, epochs=20, validation\_data=(val\_pad\_trunc\_seq, val\_labels))

/opt/conda/lib/python3.8/site-packages/keras/utils/traceback\_utils.py in error\_handler(\*args, \*\*kwargs)  
65 except Exception as e: # pylint: disable=broad-except  
66 filtered\_tb = \_process\_traceback\_frames(e. **traceback** )  
—\> 67 raise e.with\_traceback(filtered\_tb) from None  
68 finally:  
69 del filtered\_tb

/opt/conda/lib/python3.8/site-packages/tensorflow/python/eager/execute.py in quick\_execute(op\_name, num\_outputs, inputs, attrs, ctx, name)  
56 try:  
57 ctx.ensure\_initialized()  
—\> 58 tensors = pywrap\_tfe.TFE\_Py\_Execute(ctx.\_handle, device\_name, op\_name,  
59 inputs, attrs, num\_outputs)  
60 except core.\_NotOkStatusException as e:

UnimplementedError: Cast string to float is not supported  
[[node binary\_crossentropy/Cast  
(defined at /opt/conda/lib/python3.8/site-packages/keras/losses.py:1797)  
]] [Op:\_\_inference\_test\_function\_19035]

Errors may have originated from an input operation.  
Input Source operations connected to node binary\_crossentropy/Cast:  
In[0] ExpandDims (defined at /opt/conda/lib/python3.8/site-packages/keras/engine/compile\_utils.py:677)

Operation defined at: (most recent call last)

> > > File “/opt/conda/lib/python3.8/runpy.py”, line 194, in \_run\_module\_as\_main  
> > > return \_run\_code(code, main\_globals, None,
> > > 
> > > File “/opt/conda/lib/python3.8/runpy.py”, line 87, in \_run\_code  
> > > exec(code, run\_globals)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel\_launcher.py”, line 16, in   
> > > app.launch\_new\_instance()
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/traitlets/config/application.py”, line 845, in launch\_instance  
> > > app.start()
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/kernelapp.py”, line 612, in start  
> > > self.io\_loop.start()
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/platform/asyncio.py”, line 199, in start  
> > > self.asyncio\_loop.run\_forever()
> > > 
> > > File “/opt/conda/lib/python3.8/asyncio/base\_events.py”, line 570, in run\_forever  
> > > self.\_run\_once()
> > > 
> > > File “/opt/conda/lib/python3.8/asyncio/base\_events.py”, line 1859, in \_run\_once  
> > > handle.\_run()
> > > 
> > > File “/opt/conda/lib/python3.8/asyncio/events.py”, line 81, in \_run  
> > > self.\_context.run(self.\_callback, \*self.\_args)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/ioloop.py”, line 688, in   
> > > lambda f: self.\_run\_callback(functools.partial(callback, future))
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/ioloop.py”, line 741, in \_run\_callback  
> > > ret = callback()
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 814, in inner  
> > > self.ctx\_run(self.run)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 775, in run  
> > > yielded = self.gen.send(value)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/kernelbase.py”, line 374, in dispatch\_queue  
> > > yield self.process\_one()
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 250, in wrapper  
> > > runner = Runner(ctx\_run, result, future, yielded)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 741, in **init**  
> > > self.ctx\_run(self.run)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 775, in run  
> > > yielded = self.gen.send(value)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/kernelbase.py”, line 358, in process\_one  
> > > yield gen.maybe\_future(dispatch(\*args))
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 234, in wrapper  
> > > yielded = ctx\_run(next, result)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/kernelbase.py”, line 261, in dispatch\_shell  
> > > yield gen.maybe\_future(handler(stream, idents, msg))
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 234, in wrapper  
> > > yielded = ctx\_run(next, result)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/kernelbase.py”, line 536, in execute\_request  
> > > self.do\_execute(
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/tornado/gen.py”, line 234, in wrapper  
> > > yielded = ctx\_run(next, result)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/ipkernel.py”, line 302, in do\_execute  
> > > res = shell.run\_cell(code, store\_history=store\_history, silent=silent)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/ipykernel/zmqshell.py”, line 539, in run\_cell  
> > > return super(ZMQInteractiveShell, self).run\_cell(\*args, \*\*kwargs)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py”, line 2894, in run\_cell  
> > > result = self.\_run\_cell(
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py”, line 2940, in \_run\_cell  
> > > return runner(coro)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/IPython/core/async\_helpers.py”, line 68, in \_pseudo\_sync\_runner  
> > > coro.send(None)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py”, line 3165, in run\_cell\_async  
> > > has\_raised = await self.run\_ast\_nodes(code\_ast.body, cell\_name,
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py”, line 3357, in run\_ast\_nodes  
> > > if (await self.run\_code(code, result, async\_=asy)):
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py”, line 3437, in run\_code  
> > > exec(code\_obj, self.user\_global\_ns, self.user\_ns)
> > > 
> > > File “”, line 7, in   
> > > history = model.fit(train\_pad\_trunc\_seq, train\_labels, epochs=20, validation\_data=(val\_pad\_trunc\_seq, val\_labels))
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/utils/traceback\_utils.py”, line 64, in error\_handler  
> > > return fn(\*args, \*\*kwargs)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/training.py”, line 1252, in fit  
> > > val\_logs = self.evaluate(
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/utils/traceback\_utils.py”, line 64, in error\_handler  
> > > return fn(\*args, \*\*kwargs)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/training.py”, line 1537, in evaluate  
> > > tmp\_logs = self.test\_function(iterator)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/training.py”, line 1366, in test\_function  
> > > return step\_function(self, iterator)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/training.py”, line 1356, in step\_function  
> > > outputs = model.distribute\_strategy.run(run\_step, args=(data,))
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/training.py”, line 1349, in run\_step  
> > > outputs = model.test\_step(data)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/training.py”, line 1305, in test\_step  
> > > self.compiled\_loss(
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/engine/compile\_utils.py”, line 201, in **call**  
> > > loss\_value = loss\_obj(y\_t, y\_p, sample\_weight=sw)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/losses.py”, line 141, in **call**  
> > > losses = call\_fn(y\_true, y\_pred)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/losses.py”, line 245, in call  
> > > return ag\_fn(y\_true, y\_pred, \*\*self.\_fn\_kwargs)
> > > 
> > > File “/opt/conda/lib/python3.8/site-packages/keras/losses.py”, line 1797, in binary\_crossentropy  
> > > y\_true = tf.cast(y\_true, y\_pred.dtype)

---

<div class="post-metadata">

**Author:** ![Raymond\_Hawthorne](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Raymond\_Hawthorne](https://community.deeplearning.ai/u/Raymond_Hawthorne)\
**Post date:** [January 1, 2024, 12:54am UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/5 "2024-01-01T00:54:27Z")

</div>

The labels are of type int.

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [January 1, 2024, 3:29am UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/6 "2024-01-01T03:29:15Z")

</div>

Apparently not. See here:

```auto
UnimplementedError: Cast string to float is not supported
[[node binary_crossentropy/Cast
(defined at /opt/conda/lib/python3.8/site-packages/keras/losses.py:1797)
]] [Op:__inference_test_function_19035]

```

and here:

```auto
File “/opt/conda/lib/python3.8/site-packages/keras/losses.py”, line 1797, in binary_crossentropy
y_true = tf.cast(y_true, y_pred.dtype)

```

If this doesn’t help, please click my name and message your notebook as an attachment.

---

<div class="post-metadata">

**Author:** ![Raymond\_Hawthorne](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Raymond\_Hawthorne](https://community.deeplearning.ai/u/Raymond_Hawthorne)\
**Post date:** [January 1, 2024, 1:49pm UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/7 "2024-01-01T13:49:18Z")

</div>

@balaji.ambresh Yep. You are correct. I accidentally set validation\_labels to be sentences split on the training size instead of the _labels_ with the appropriate split.

Oof. Thank you and Happy New Year!

---

<div class="post-metadata">

**Author:** ![sako](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@sako](https://community.deeplearning.ai/u/sako)\
**Post date:** [February 16, 2024, 2:40pm UTC](https://community.deeplearning.ai/t/c3w3-assignment-3-error-thrown-just-prior-to-end-of-first-epoch/531245/8 "2024-02-16T14:40:01Z")

</div>

got exactly the same error, thanks for the answer mate.
