Week1, Dinosaurus, exercise2,sample, error

I stuck this error

ValueError Traceback (most recent call last)
in
19 print("\033[92mAll tests passed!")
20
—> 21 sample_test(sample)

in sample_test(target)
7
8
----> 9 indices = target(parameters, char_to_ix, 0)
10 print(“Sampling:”)
11 print(“list of sampled indices:\n”, indices)

in sample(parameters, char_to_ix, seed)
47
48 # Step 2: Forward propagate x using the equations (1), (2) and (3)
—> 49 a =np.tanh(np.dot(Wax,x)+np.dot(Waa,a_prev)+b)
50 z = np.dot(Wya,a)+by
51 y = softmax(z)

<array_function internals> in dot(*args, **kwargs)

ValueError: shapes (100,27) and (100,27) not aligned: 27 (dim 1) != 100 (dim 0)

I initialize x this
x = np.zeros((vocab_size,1))
initialize a_prev this
a_prev = np.zeros((n_a,1))
The error occur this
a =np.tanh(np.dot(Wax,x)+np.dot(Waa,a_prev)+b)
what is wrong

1 Like

Something else must be going on. Note that just from the error message we can’t say for sure which dot product is the one throwing the exception. But based on your initialization, both x and a_prev should have 1 as their second dimension, right? So where does the second operand with dimension 100 x 27 come from? I suggest you put print statements right before the line that throws the error and print the dimensions of all the objects involved: Wax, x, Waa and a_prev. Something must be causing either x or a_prev to change to be 100 x 27. Once you see which it is, that should give you something to investigate. How did that happen?

I added that logic and here’s what I see for the first few iterations:

vocab_size = 27
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)
Wax (100, 27) x (27, 1) Waa (100, 100) a_prev (100, 1)

With those dimensions you can see that the result of that line will be 100 x 1.

I mistake step4 overwrite x shape
I fix it, All test passed.
Thank you