0

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. Commented Jul 17, 2019 at 16:41

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for you reply! I will try to give examples to net one by one. But, why it works fine in 11 lines neural network example? Out is 1D array.. And I now figured out that with what I have now the net always produces same answers - 18 (I am making a weather prediction network). Maybe this will dissappear if I give examples to net one by one
The output of a neural network doesn't have to be a 1D array; you can feed the network as many (or as few) examples as you'd like. Importantly, the number of examples in each training batch will impact how the network learns: en.wikipedia.org/wiki/Stochastic_gradient_descent
But which element of result-array should be used as an answer? I had 1000x44 array, so, what of 1000 results is right?
they all would be used as an answer. if you are trying to predict 1000 examples, then each row of your output array corresponds to 1 prediction.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.