Week1 - Assignment 2

Can someone help me with the model() part of this assignment I’m a bit lost


    # Set the index `idx` (see instructions above)
    idx = j % len(examples)
    # Set the input X (see instructions above)
    single_example = idx
    single_example_chars = [j for j in single_example]
    single_example_ix = char_to_ix[single_example_chars]
    X = [None] + single_example_ix
    # Set the labels Y (see instructions above)
    ix_newline = [char_to_ix["\n"]]
    Y = X[1:] + ix_newline

    # Perform one optimization step: Forward-prop -> Backward-prop -> Clip -> Update parameters
    # Choose a learning rate of 0.01
    curr_loss, gradients, a_prev = optimize(X, Y, a_prev, parameters, learning_rate = 0.01)
    ### END CODE HERE ###

Try removing the square brackets around the outside of “char_to_ix[”\n"]

Generally its a good idea to:

  • not post your code on the Forums. The course Honor Code does not allow it.
  • do post the entire call stack for any asserts or error messages.

Also, do not re-use the ‘j’ variable in your code for single_example_chars. Use a different variable name there.

okok I changed the variable but I still get the same error message for that line?:
TypeError: ‘int’ object is not iterable

nvm I got it thank you

How did you solve that? @DDigits

1 Like