0
votes

I have got some problems writing my simple neural network. I was learning about neural networks in python by "Neural network in 11 lines" guide (https://www.kdnuggets.com/2015/10/neural-network-python-tutorial.html). There was 2D array as input (in first dimension was example number, and in second - example) As an output there was a 1D array. So now I tried to do something similar. I had input array for learning with 1000 examples and each example has 64 neurons:

n0 = np.zeros((1000, 64)) 

After that I filled array with data from dataset. My weights were like:

w0 = 2 * np.random.random((64, 120))-1
w1 = 2 * np.random.random((120, 240))-1
w2 = 2 * np.random.random((240, 240))-1
w3 = 2 * np.random.random((240, 240))-1
w4 = 2 * np.random.random((240, 120))-1
w5 = 2 * np.random.random((120, 44))-1

And forward-function was:

n1 = sigmoid(np.dot(n0, w0))
n2 = sigmoid(np.dot(n1, w1))
#...
n6 = sigmoid(np.dot(n5, w5))

After that n6 size is 1000x44. And how can I get 1D array, not 2D array? Also after weights correction, neurons can get strange numbers like 6.72853722e-172... And in n6 answers are 1.00000000e+000 and 0.00000000e-000, how that could be after sigmoid function?

1
You could use np.flatten() to convert to a 1D array or add another layer with fewer nodes at the end. - Jake P

1 Answers

1
votes

After that n6 size is 1000x44. And how can I get 1D array, not 2D array?

The reason you're getting an output array with dimensions 1000x44 is because n6 has 44 output nodes, and your input data has 1000 examples (meaning, you're training the network on all examples at once).

In other words, your output layer is producing an "activation" for every example in your dataset <-- that's normal & expected. If you were training the network one example at a time, the output array would be 1x44 (or just, 44).


Also after weights correction, neurons can get strange numbers like 6.72853722e-172... And in n6 answers are 1.00000000e+000 and 0.00000000e-000, how that could be after sigmoid function?

Sigmoid produces values between 0 and 1. So: 6.72853722e-172 (or, 6.72 * 10-172), 1.00000000e+000, and 0.00000000e-000 are all between 0 and 1, so that's normal too