What happens after backpropagation in the learning phase within Neural Network?

Viewed 151

Within a Neural Network during the learning phase ,there are two mechanisms happening. Feedforward and Backpropagation. Taking an example of XOR operation.

A   B   Q
0   0   0
0   1   1
1   0   1
1   1   0

For the first pass(0,0->0) feedforward takes place, then backpropagation happens.After this step all the weights are recalculated .
What happens now?

Question-1:Again the same input 0,0 is feedforward with the new calculated weights(during the backpropagation) and then backprogated until the error becomes nill? If yes, what happens if the error is never nill? Which brings me to the next question.

Question-2:When would the learning for the next pass(0,1->1) happen?

Question-3: Suppose the concluded weights for the 1st pass is 10.3,-2.3,5.5 .The second pass(0,1->1) starts the feedforward with the concluded weights of the first pass?


If I have to describe via code which of the following code would be correct

Common Code for the below options

averageErrorUntilLearn = 0.002;
inputs = [
[0, 0],
[0, 1],
[1, 0],
[1, 1]
];
outputs = [0, 1, 1, 0];
inputNeurons = 2;
hiddenLayers = 1;
outputNeurons = 1;

//initialize the Neural Net
neuralNetObj = NeuralNet();
neuralNetObj.createTopology(inputNeurons, hiddenLayers, outputNeurons);
weightsForTheNetwork = randomWeights();


Question 3 scenario- The weights calculated in each pass is sent down to the next pass

//learn 
while (averageError > averageErrorUntilLearn):
    for i in range(0,len(input)):
        console.log("Current Pass-" + i);
        neuralNetObj.learningParams(inputs[i], outputs[i]);
        neuralNetObj.initializeWeights(weightsForTheNetwork);
        neuralNetObj.feedforward();
        neuralNetObj.backPropagate();
        weightsForTheNetwork=neuralNetObj.getNewWeights();
        averageError = neuralNetObj.getAverageError();

Question 1 scenario- Each pass is calculated with its own weights till it reaches the desired learning and then the weights are sent down the new pass

//learn 
for i in range(0,len(input)):
    while (averageError > averageErrorUntilLearn):
        console.log("Current Pass-" + i);
        neuralNetObj.learningParams(inputs[i], outputs[i]);
        neuralNetObj.initializeWeights(weightsForTheNetwork);
        neuralNetObj.feedforward();
        neuralNetObj.backPropagate();
        weightsForTheNetwork = neuralNetObj.getNewWeights();
        averageError = neuralNetObj.getAverageError();


Or am I complete wrong here and none of the above scenarios are true?

2 Answers

Forward-backward pass is one step of training, which calculates the gradients that are later used to adjust the weights by an approximation method (SGD, RMSProp, Adam, etc).

What you describe is learning one input at a time, that is a forward-backward pass is done for (0,0->0), then a forward-backward pass for (0,1->1) and so on. Each step works with weights calculated on the previous step and it doesn't know what was the data before that.

In practice, however, the training is usually done in batches, that is the network takes a step for batch [(0,0->0), (0,1->1)], then for the next batch and so on. The order is randomized, so the batches can be formed differently. In some models, each next batch is taken randomly, so it's possible that the same input is fed to the network several times in a row, though not very probable. But the usual method is this: shuffle all training data (4 examples in your case) and iterate all of it in batches. Then repeat.

In rare cases, the batch contains all training data, which basically means it's an ordinary gradient descent (not stochastic). In this case, each step will take the same inputs over and over again.

To summarize: you are free to feed the network in any order you want, but usually people do it in random order. Also the error never becomes exactly null, so you just stop after some number of iterations.

1) Yes, the backprop step will continue to update the weights until the feedforward step has a 0 error. Regardless of whether it reaches a 0 error or not, you must define a stopping criteria to tell it when to stop. The simplest is to set a fixed number of iterations to train. This is a good, simple way to get started. Real problems will use something more sophisticated such as periodically checking accuracy on a separate validation step and stopping when the accuracy stops improving. However, just use a fixed number of iterations for an XOR problem. It is up to you to decide and tell it what the stopping criteria is.

2) You do not want to train repeatedly on one instance (such as 0,0->0), and then switch to a different instance. If you're training one instance at a time, go through first instance once (forward and backprop steps), then the next instance, and so on to the end of the training data. Then start over at the beginning again and go through each instance again. In this way it is interleaving the training for each case represented in the training data. As @Maxim said, it's more common to train in batches. In a batch, it will do all the forward passes simultaneously and collect all of the network's guesses about the answers. Then it will calculate the error for every instance of the batch, and backpropagate once to correct for the average error across all instances in the batch. Hence it is learning how to deal with all the cases in the batch simultaneously. This is faster than doing one instance at a time, but the network should be able to learn the problem either way. The important point here is that it is learning about all of the cases in the training data at the same time, rather than one-by-one.

3) Yes, once you do the backprop step it will apply the updates to the weights, and the next training step will use the new weights.

Related