C3W2_Assignment : Error on def seq_and_pad

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

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

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

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.

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

1 Like

@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

[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

The 3rd parameter of pad_sequences is dtype='int32'. Please read Keyword Arguments from here