Hi! I am encountering a problem of not being able to get properly graded. In the course 5, week 1’s second coding assignment, Character-Level Language Modeling, it threw me the error:

Cell #9. Can’t compile the student’s code. Error: ValueError('operands could not be broadcast together with shapes (4,) (6,) ')

I am wondering why this time a single error failed the whole assignment. It got score 0.

Second, I suspected that the error was because of the calculation of idx in the while loop (in cell 9). it asks to Sample the index of a character within the vocabulary from the probability distribution y, but y is a 2d array in the shape of (vocab_size, n_a), however, the function np.random.choice required the parameter p to be a 1d vector for indicating the probability. I am wondering if anyone can share some idea on this ?
the command I use was:

idx = np.random.choice(list(range(vocab_size)), p = y[:,-1])

as you can see, i just randomly took the last column (vocab_size,1) of y as the probability distribution. but i think that’s incorrect

Check the additional hint given to you. And, I don’t think you have to convert the range into a list.

Additional Hints
Documentation for the built-in Python function range
Docs for numpy.ravel, which takes a multi-dimensional array and returns its contents inside of a 1D vector.
arr = np.array([[1,2],[3,4]])
print("arr")
print(arr)
print("arr.ravel()")
print(arr.ravel())
Output:
arr
[[1 2]
[3 4]]
arr.ravel()
[1 2 3 4]

Hi! Thanks for the reply! I knew that by arr.ravel() a 2D array can be transformed to 1D vector, but the size of the flattened y (27*100,1) will be incompatible with size of vocab_size (27,1), and consequently caused error in np.random.choice. so I doubted if y was calculated properly with size of (27,100)? I printed their sizes shown below:

x^{<1>} is x in the code. When creating the one-hot vector, make a numpy array of zeros, with the number of rows equal to the number of unique characters, and the number of columns equal to one. It’s a 2D and not a 1D array.

a^{<0>} is a_prev in the code. It is a numpy array of zeros, where the number of rows is n_a, and number of columns is 1.

Saif has covered the actual programming questions, but the point about why you get 0 points on everything is that you have a compile error. That means the grader can’t get far enough to run any actual tests, since the notebook doesn’t even compile. Anytime something like that happens, you end up with 0 score on everything.

Back to the actual question, here’s a thread which shows the shapes of everything on that particular function. Maybe that will give some clues about where your code goes off the rails.

Thanks for the explanation! I was thinking the same thing. But how come the grader failed in compiling? is this because of the error in coding and it caused the compiling failures or soemthing else?

But i would like to inform you that I went through these hints several times and I had to say that i didn’t find these two bullets points about the configuration of the x and a_prev! Below was what shown in my notebook. weird

Hi all. I have one remaining question about storing the course material in my local computer. I am wondering if I would still be able to download them after i finished all the graded stuff (I didn’t subscribe the memberships, but rather I applied for financial aids)? because it says to download them before finishing all graded materials. thanks!