# C4W3\_Assignment - TypeError

**URL:** <https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054>\
**Category:** NLP with Attention Models\
**Tags:** week-module-3\
**Created:** [August 25, 2024, 7:14pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054 "2024-08-25T19:14:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sk\_369](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sk\_369](https://community.deeplearning.ai/u/sk_369)\
**Post date:** [August 25, 2024, 7:14pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/1 "2024-08-25T19:14:44Z")

</div>

Hi,

Getting bellow error while testing the model.

TypeError: in user code:

```
File "/tf/transformer_utils.py", line 547, in create_padding_mask *
    seq = 1 - tf.cast(tf.math.equal(decoder_token_ids, 0), tf.float32)

TypeError: Failed to convert elements of <transformer_utils.Transformer object at 0x7f3ce95c69d0> to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.

```

---

<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:** [August 25, 2024, 8:50pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/2 "2024-08-25T20:50:41Z")

</div>

Hi @sk_369

A detailed post with error encountered with which grade cell and how you have recalled the codes without mentioning directly the codes would benefit you more from getting faster response.

According rather than copy pasting the errors, click a screenshot which will capture the issue in toto.

When you have lengthy error, you can always click two different sections of the error.

So kindly provide details about which grade cell you encountered this issue as the error indicated.

Also when I just copy pasted your error on the search tool, I got a similar thread, so I advise you to use it search similar error assignment threads which previously learners must have encountered. Referring them sometimes helps you debugging.

> [@C4W3\_Assignment in Natural Language Processing with Attention Models](https://community.deeplearning.ai/t/c4w3-assignment-in-natural-language-processing-with-attention-models/632765/10):
>
> Hi @Pavamana For exercise 2 GRADED FUNCTION: parse\_squad Create the question/context sequence for the context part you have used ’ context: ’ + context which is incorrect. It should be ’ context: ’ + paragraph[‘context’] Remember the point mentions Create the answer sequence using the first answer from the available answers. So it is paragraph from the article from which context was extracted. Also in exercise 3, kindly remove the below return statement, it is not any issue but it …

Regards  
DP

---

<div class="post-metadata">

**Author:** ![sk\_369](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sk\_369](https://community.deeplearning.ai/u/sk_369)\
**Post date:** [August 25, 2024, 9:04pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/3 "2024-08-25T21:04:52Z")

</div>

![image](https://global.discourse-cdn.com/dlai/original/3X/d/8/d857fbe558ad1fe8bc0343410f1fedad5b8d1fbf.png)

---

<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:** [August 25, 2024, 9:35pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/4 "2024-08-25T21:35:57Z")

</div>

My previous tagged comment link should help you resolve your issue. check the last comment in that thread, cross check your next word codes.

You recalling with incorrect arguments assigned for that grade cell, using global variable can throw error.

Also you do not require again to apply the padding mask, as the model argument for that cell mentions it is already padded.

So next word require you to use the correct call arguments for input, output and model, also in the correct sequence.

you cant feed first model and then input and output.

For answer question grade cell, input is recalled as tokenized question and output as tokenized answer

Regards  
DP

---

<div class="post-metadata">

**Author:** ![sk\_369](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sk\_369](https://community.deeplearning.ai/u/sk_369)\
**Post date:** [August 25, 2024, 9:44pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/5 "2024-08-25T21:44:35Z")

</div>

I resolved the issue after going through the thread u provided.

Now the test case is failing with bellow error.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/c/c/cc5c993e1a3a7d1fc0171035ddbc39d7da898739.png)

---

<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:** [August 25, 2024, 10:05pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/6 "2024-08-25T22:05:52Z")

</div>

@sk_369

i just noticed your next code in the error, perhaps you haven’t still didn’t change the output while predicting next word?

Remember output is not recalled argument for answer question grade cell.

Your last code line also needs correction.  
remember the instruction mentions to stop prediction next word once it reaches decode maxlen.

---

<div class="post-metadata">

**Author:** ![sk\_369](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sk\_369](https://community.deeplearning.ai/u/sk_369)\
**Post date:** [August 25, 2024, 10:10pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/7 "2024-08-25T22:10:04Z")

</div>

Sent.

---

<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:** [August 25, 2024, 10:37pm UTC](https://community.deeplearning.ai/t/c4w3-assignment-typeerror/683054/8 "2024-08-25T22:37:27Z")

</div>

hi @sk_369

I noticed one of the code line is completely missing in your code, so by any chance you deleted the code after we are suppose to add dimension, which creates id for end of sequence eos.

This code line is not present in your code cell 👇🏻  
Get the id of the EOS token

or probably you are using an obselete copy, in any case, please get a fresh copy and re-do the assignment as you might fail the grader if you are working on an old copy or edited out cell.

Regards  
DP
