In Multilayer Perceptron neural networks, I know that there are two types of training: online training, and batch training, which consists of dividing the samples and updating the weights using the accumulated error. In other neural networks, for example in Adaline, I know that something similar is done to update the weights, for example in this video: https://youtu.be/MTe2qsS56MQ?si=Sky-220_zA15l7T8 In this case, it shows the " total error", from what it seems to me, the weights are only adjusted at the end of each epoch, using the accumulated error (summed, that is, the total error) of the samples. In the example in the video, he used only one output neuron, as it was just one Adaline, and in the way it was done, it seems like it was just a single batch, as he made a sum of the squared errors of each sample and only at the end I updated the weights using this accumulated error as I mentioned above, it was just a batch. But for me it's confusing, because, if I have a Multilayer Perceptron using several output classes, how would I update the weights using batches? Would I have to calculate the accumulated error(of all samples) of each output neuron?

For example, if I divide 10 samples into 2 batches, how would the weights be updated? Would it add up the error of all samples from each batch, and then update the weights (after the current batch)? When using multiple classes, what would this weight update look like? I would have to add the error (that is, obtain the accumulated error) of all output neurons, for example: "total error of class 1", "total error of class 2", "total error of class 3", etc?

In Multilayer Perceptron,using several output classes, how would I update the weights using batches? Would I have to calculate the accumulated error(of all samples) of each output neuron?


1 Answer 1


So, two things:

  1. Yes you technically calculate the accumulated error for each neuron, but in practice we calculate all neurons at once by treating it as a matrix instead of individual vectors. Likewise, you do not have to calculate error gradients for the individual hidden neurons, but rather you calculate the gradients on a layer-wise basis which can be decomposed into individual neurons.

  2. The size of your minibatches and the number of samples per update step are not necessarily the same thing. While you can perform backprop and weight updates after each minibatch, you can also perform what's called gradient accumulation where, as the name says, you accumulate the gradients between several (or all) minibatches before performing your update step. Accumulating the gradients for all minibatches before performing your update step effectively makes it so you're doing batch gradient descent, even if you don't have the hardware to do "true" batch gradient descent on data of your size.

How you select your minibatch size and number of gradient accumulation steps (minibatches per update step) is an empirical process, for now.

  • $\begingroup$ But then, if I'm not using matrices, does this mean that after processing each sample (in feedforward), I calculate the error of that sample for each of the output neurons individually? And so at the end of the minibatch, I would have the following errors accumulated from each output neuron individually, for example if I have 2 output neurons: errorN1 = sum(...samplesErrorsN1), errorN2 = sum(...samplesErrorsN2), etc... In minibatch, For each output neuron I calculate the sum of the errors of all samples, so I have the accumulated error of each output neuron individually? Am I correct? $\endgroup$
    – will The J
    Dec 26, 2023 at 17:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .