DLS Course 5 W1 Assignment 2 Dinosaur

Hi there,

I am stuck in my code and facing this error:

Dict object is not callable.

I feel I am not able to get the logic right and there could be couple of errors. For example, I am not doing the below right i feel:
single_example_ix = [char_to_ix(c) for c in single_example_chars]

help appreciated

This is just a python syntax error. When you use parentheses to “index” something, python thinks you are making a procedure call. If the object in question is not a function, then you need to use square brackets to “index” it, right? You are “calling” char_to_ix as a function because of the parens, but it’s a dictionary, right? The first rule of debugging is “believe the error message”. Sometimes they can be pretty cryptic, but you have to admit this is a pretty clear message in this case.

Got it. I corrected the callability error.

As I mentioned earlier, I know there are a couple of more errors in my code. I am facing problems understanding how to set the last letter of Y as the newline character. in the code, the left side of the equation is the whole Y, whereas I am supposed to just add one ‘newline’ character at the end of Y. There is no hint about how to add only one letter in the end of Y. How can I assign only one letter to the whole Y? I am doing it as below right now and I know it is wrong:

ix_newline = char_to_ix[‘\n’]
Y = Y.add(ix_newline)

Hi @Nitin_Chaswal ,

You can do that by using the + operator to combine two strings of characters:

y = single_example_ix + [ix_newline]

Here is the instruction:

Set the list of labels (integer representation of the characters): Y
  • The goal is to train the RNN to predict the next letter in the name, so the labels are the list of characters that are one time-step ahead of the characters in the input X.
    • For example, Y[0] contains the same value as X[1]
  • The RNN should predict a newline at the last letter, so add ix_newline to the end of the labels.
    • Append the integer representation of the newline character to the end of Y.
    • Note that append is an in-place operation.
    • It might be easier for you to add two lists together.
1 Like

Wonderful! I was not expecting that I would be able to close this assignment with only two doubts. Especially for this assignment, I found it very hard to understand the instructions and hints for some lines.

I successfully finished the assignment. Thanks a ton.

Hi @Nitin_Chaswal ,

Great to hear you have finished this assignment successfully. The instructions and hints could have been written in a clearer and easy to understand way, and I will report your concern to the staff team.