If I reshape the one_hot matrix to (depth ), the tests pass. However, if I reshape the one_hot matrix to (depth, 1), the tests fail. Why is this? Also if the test passes with only depth in the further lines there is following code:
new_y_test = y_test.map(one_hot_matrix)
new_y_train = y_train.map(one_hot_matrix)
which shows a value error even though the previous test passes.
ValueError: Shape must be rank 1 but is rank 0 for ‘{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](one_hot, Reshape/shape)’ with input shapes: [6], .
Because the following code needs the one hot output to be a “rank 1” tensor (same as a 1D numpy array). If you specify it as (depth, 1), then you get a rank 2 tensor. The reason that (depth) doesn’t work is that is treated as a scalar (the shape, not the output) and when you call one_hot_matrix from the “map” method that fails. But you’ll find that [depth] will work, because that is actually a list.
The test cell for one_hot_matrix is too weak and does not catch some of the errors if you generate the wrong shape. A bug is filed about this.
Sir,
Thanks for clarifying the doubt. After successfully completing the one-hot encoding test ( I am getting all test passed remark), when i am moving two the next two cells containing:
1st cell:
new_y_test = y_test.map(one_hot_matrix)
new_y_train = y_train.map(one_hot_matrix)
After running this I am getting a value error.
2nd cell:
print(next(iter(new_y_test)))
After running this I am getting a name error: name ‘new_y_test’ is not defined.
Sir, how to tackle this. I am getting the same name error when I am running compute cost function.
Regards
That probably means that your one_hot_matrix function is not fully correct yet. The test for that cell does not catch all errors. The new_y_test not defined is because the cell that creates new_y_test is failing because of the previous problem, right? Please show us the actual output you get when you run these two cells:
new_y_test = y_test.map(one_hot_matrix)
new_y_train = y_train.map(one_hot_matrix)
print(next(iter(new_y_test)))
new_y_test = y_test.map(one_hot_matrix) new_y_train = y_train.map(one_hot_matrix)
error :
ValueError: Shape must be rank 1 but is rank 0 for '{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](one_hot, Reshape/shape)' with input shapes: [6], [].
print(next(iter(new_y_test)))
Error:
This means you specified the shape as (depth), which passes the first test and then fails later. Try making it a 1D shape, as in (depth,) or [depth] or [depth,].