Hi experts,
Can’t seem to figure this one out in “sample” function.
Have defined a_prev as np.zeros( ( n_a, 1 ) ) as hint suggests should be 2-d array, ie:
a_prev = np.zeros( ( n_a, 1 ) )
Before the while loop starts, print( a_prev.dtype ) shows:
a_prev.dtype: float64
In while loop, it causes an error:
Waa.shape: (100, 100), Wax.shape: (100, 27), Wya.shape: (27, 100), by.shape: (27, 1), b.shape: (100, 1)
>>> x.dtype: float64
>>> a_prev.dtype: float64
x.dtype: float64
a_prev.dtype in while loop: float64
Waa.dtype: float64
y.shape: (27, 1)
x.dtype: float64
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-5ed45dfbad4e> in <module>
19 print("\033[92mAll tests passed!")
20
---> 21 sample_test(sample)
<ipython-input-20-5ed45dfbad4e> 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)
<ipython-input-19-d3a599f6e85a> in sample(parameters, char_to_ix, seed)
60 # print( f"a_prev: {a_prev}" )
61 print( f"x.dtype: {x.dtype}" )
---> 62 print( f"a_prev.dtype in while loop: {a_prev.dtype}" )
63 print( f"Waa.dtype: {Waa.dtype}" )
64
AttributeError: 'NoneType' object has no attribute 'dtype'
The problem is that it’s stopping me from computing the following:
a = np.tanh( np.dot( Wax, x ) + np.dot( Waa, a_prev ) + b )
When I remove the print, I get following error instead:
Waa.shape: (100, 100), Wax.shape: (100, 27), Wya.shape: (27, 100), by.shape: (27, 1), b.shape: (100, 1)
y.shape: (27, 1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-5ed45dfbad4e> in <module>
19 print("\033[92mAll tests passed!")
20
---> 21 sample_test(sample)
<ipython-input-22-5ed45dfbad4e> 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)
<ipython-input-21-ab0148d39385> in sample(parameters, char_to_ix, seed)
63 # print( f"Waa.dtype: {Waa.dtype}" )
64
---> 65 a2 = np.dot( Waa, a_prev )
66 a = np.tanh( np.dot( Wax, x ) + np.dot( Waa, a_prev ) + b )
67 # a = Wax * x + Waa * a_prev + b
<__array_function__ internals> in dot(*args, **kwargs)
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
For some reason it thinks a_prev has NoneType instead of float64 even though the print does
show float64. I break up the tanh input parameters separately to find out where it fails originally
that’s why above error points to a2, the 2nd parameter term to tanh, although not used for
actual computation of a (the line below a2).
Have restarted kernel to no avail. I have tested the original initialisation separately on my laptop
but there is no issue with print a_prev.dtype.
x is also defined similar way just different dimension vocab_size but no issue at all.
Any idea what’s going on?
Thanks,
MCW