DLS Course 5 Week 1 Assignment 2 Dinosaur shape input problem

Hello friends,

It would be nice if someone could explain function def sample(parameters, char_to_ix, seed), specifically a(t+1) calculation. The formula is π‘ŽβŸ¨π‘‘+1⟩=tanh(π‘Šπ‘Žπ‘₯π‘₯βŸ¨π‘‘+1⟩+π‘Šπ‘Žπ‘Žπ‘ŽβŸ¨π‘‘βŸ©+𝑏). As a result, in python for me it looks like a = np.tanh(np.dot(Wax, x) + np.dot(Waa, a_prev) + b). x and a_prev I initialize as x = 0, a_prev = 0. However, when I try to run the function it gives error at a(t+1) calculation saying : ValueError: operands could not be broadcast together with shapes (100,27) (100,100) . These shapes come from Wax = (100, 27), Waa = (100, 100).

It would be nice if someone could explain how we are supposed to sum up these different kind of matrices. Maybe the problem is in my formula implementation or x and a_prev initialization?

Best regards,

Your code for β€œa = …” is correct.
The problem is your initialization of x and a_prev. They’re vectors, not scalars.

Hi @TMosh, can you help me?

I have the same issue (and same code for β€œa=…”), but my initialization of x is a np array of size β€˜vocab_size’, and my vector β€˜a_prev’ is another np array of size β€˜na’.

I can’t see my mistake…

Ok… they should be 2D vectors