# C3W2\_Assignment : Error on def seq\_and\_pad

**URL:** <https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509>\
**Category:** Natural Language Processing in TensorFlow\
**Tags:** week-module-3, week-module-4, week-module-2\
**Created:** [March 31, 2022, 7:54am UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509 "2022-03-31T07:54:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_Hossein\_Hashemi](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@M\_Hossein\_Hashemi](https://community.deeplearning.ai/u/M_Hossein_Hashemi)\
**Post date:** [March 31, 2022, 7:54am UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/1 "2022-03-31T07:54:34Z")

</div>

Hi everyone,I have a problem with this error on Seq and Pad function grading, which keeps giving me this massage:

“There was a problem grading your submission. Details:  
operands could not be broadcast together with shapes (120,) (10,)”

and here is my code for seq and pad function :  
###################################################  
def seq\_and\_pad(sentences, tokenizer, padding, maxlen):

```
# Convert sentences to sequences
sequences = tokenizer.texts_to_sequences(sentences)

# Pad the sequences using the correct padding and maxlen
padded_sequences = pad_sequences(sequences, maxlen=120, padding='post')

### END CODE HERE

return padded_sequences

```

######################################################

---

<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:** [March 31, 2022, 8:15am UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/2 "2022-03-31T08:15:41Z")

</div>

Use `padding` and `maxlen` from function parameters and not hardcode them inside `pad_sequences`

---

<div class="post-metadata">

**Author:** ![Aryan\_Sarin](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Aryan\_Sarin](https://community.deeplearning.ai/u/Aryan_Sarin)\
**Post date:** [May 10, 2022, 3:06am UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/5 "2022-05-10T03:06:32Z")

</div>

I have the same issue, and I have not hardcoded the function parameters. My code looks like this: # Convert sentences to sequences  
sequences = tokenizer.texts\_to\_sequences(sentences)

```
# Pad the sequences using the correct padding and maxlen
padded_sequences = pad_sequences(sequences, padding=PADDING, maxlen=MAXLEN)

```

Any help will be appreciated.

---

<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:** [May 10, 2022, 5:22am UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/6 "2022-05-10T05:22:41Z")

</div>

Please make use of function parameters instead of global variables. Look at the function signature:  
`def seq_and_pad(sentences, tokenizer, padding, maxlen)`

---

<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:** [May 19, 2022, 1:34pm UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/7 "2022-05-19T13:34:46Z")

</div>

@Iuri_Catasov Here are a few hints to fix your notebook:

1. Don’t use global variables when function parameters can be used instead. For instance, use `num_words` inside `fit_tokenizer(train_sentences, num_words, oov_token)` instead of `NUM_WORDS`. Grader could just pick your function from the notebook without global state. In this case, you will not pass the tests.
2. Please look at function parameters when you using positional arguments instead of named arguments. Here’s the doc for [pad\_sequences](https://www.tensorflow.org/api_docs/python/tf/keras/utils/pad_sequences)

---

<div class="post-metadata">

**Author:** ![Iuri\_Catasov](https://avatars.discourse-cdn.com/v4/letter/i/b2d939/32.png) [@Iuri\_Catasov](https://community.deeplearning.ai/u/Iuri_Catasov)\
**Post date:** [May 19, 2022, 2:15pm UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/8 "2022-05-19T14:15:04Z")

</div>

[code removed - moderator]

Changed to lower case “pad\_sequences(sequences, maxlen, padding” but have the same error message:  
“TypeError: Cannot interpret ‘120’ as a data type”.

If I do this way pad\_sequences(sequences, maxlen=MAXLEN, padding=PADDING) no error in notebook output as it supposed to be, but Grader evaluate me 0 points for this function

---

<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:** [May 19, 2022, 2:19pm UTC](https://community.deeplearning.ai/t/c3w2-assignment-error-on-def-seq-and-pad/114509/9 "2022-05-19T14:19:31Z")

</div>

The 3rd parameter of `pad_sequences` is `dtype='int32'`. Please read `Keyword Arguments` from [here](https://www.w3schools.com/python/python_functions.asp)
