University topic explanations and practice

University › Artificial Intelligence and Data Science › Deep Learning

Multilayer Perceptron and Feedforward

Apply the forward computation steps of a multilayer perceptron by checking matrix dimensions. Why linear layers need nonlinearity between them.

Save your progress

Learning Outcomes

Topic Explanation

From a single unit to a layer

An artificial neural unit receives multiple digital inputs; It multiplies each input by its own weight, adds those multiplications, and adds bias to the result. The resulting net input passes through an activation function and produces the output of the unit. This scheme alone is quite simple: with two inputs and appropriate weights it can draw a dividing line. But most real problems cannot be separated by a single line. The combination of features such as edges, corners and textures in an image; Phenomena such as words gaining meaning relative to each other in a text require many intermediate steps.

The way to set up these intermediate steps is to arrange the units in layers. Units in the same layer are not connected to each other; each reads only the output of the layer before it. So the first layer takes the raw input, subsequent layers reprocess this output. As the number of layers increases, the network passes the input through a longer transformation chain. Each link of this chain makes the representation produced by the previous one a little more abstract.

Limits of the linear unit

If each layer only computes a weighted sum, the entire chain is reduced to a single linear transformation. Mathematically, the multiplication of two consecutive matrices is also a matrix multiplication; No matter how many layers are added, the result remains in the same class. This means that adding layers does not add any representational power. A linear network can only solve linearly separable problems; It cannot represent relationships based on the product of two properties or a complex boundary.

Therefore, a nonlinear transformation is placed between the layers. This transformation, called the activation function, prevents the chain from becoming linear by thresholding or compressing the net input into a different range. Each layer now non-linearly reshapes the output of the previous one, and adding layers really opens up new representation possibilities. This is where the power of deep networks arises.

Definition of feedforward

Feed forward is the unidirectional flow of information from input to output. Each layer does its own calculation and passes the result to the next layer; There is no backward connection or correction from the previous layer. During training the weights are updated, but at the time of generating a single prediction the weights are fixed and the calculation only proceeds in the forward direction. This feature ensures that the network is fast and predictable during inference.

The distinction between feedforward and training should not be confused. Feedforward is the process of producing an output with available weights; Training is comparing this output with the correct one and adjusting the weights. A student's use of prior knowledge while taking an exam is similar to feedforward, and changing his/her study plan after the exam is similar to education. The network only applies what it knows at the time of prediction.

Hidden layers and intermediate representations

The layers between the input and output are called hidden layers. These do not see labels directly; It is fed only from the numbers produced by the previous layer. The first hidden layer usually captures simple combinations of raw features; Deeper layers combine these simple combinations to achieve complex patterns. The number of hidden layers and the number of units in each layer determine how complex relationships the model can represent.

The importance of intermediate representations is that different answers to different questions can be produced from the same raw data. For example, both the spoken text and the speaker's emotional tone can be extracted from an audio recording; The two tasks read the same input at different layer depths. As depth increases, representations become more task specific. Therefore, hidden layers are not just a pile of parameters, but processing layers where information is reorganized.

Weights, biases and parameter count

Every connection has a weight, every unit has a bias. Weight tells how strong the information carried by that connection will be and in what direction it will affect; Positive weight indicates concomitant increase, negative weight indicates opposite effect. Bias shifts the unit's arousal threshold; It ensures that the unit has a certain base efficiency even if the inputs are zero. These two values ​​are parameters that change with education.

The number of parameters is directly calculated by the layer architecture. If there are m units in the previous layer and n units in the current layer, the number of weights is m times n and the number of biases is n. These values ​​are summed for all layers. The number of parameters indicates the capacity of the model; Too few parameters cannot represent complex relationships, while too many parameters increase the risk of memorizing noise in the data. This balance is the essence of architectural choice.

Batch computation with matrix multiplication

It is possible to write the weighted sum for a single sample; However, it is unnecessary to loop through thousands of examples one by one. A matrix is ​​constructed so that examples are rows and features are columns. The weights are also written as a matrix. Multiplying two matrices gives the net entries of all samples for all units simultaneously. Then the bias vector is added and the activation function is applied.

This notation is not only a quick but also an accurate thinking tool. You can check the accuracy of the calculation by keeping track of the dimensions: if the number of samples is s, the number of features is f, and the number of units is n, the data matrix is ​​s×f, the weight matrix is ​​f×n, and the product is s×n in size. Size mismatch is the earliest sign of a fault in the architecture. Batch computing reduces hundreds of repetitions of the same operation into a single operation.

Choosing between depth and width

Depth is how many transformations are made from input to output; The width tells you how many units are in each layer. A deeper and narrower network or a shallower and wider network can be built with the same parameter budget. Deep networks can represent the same function with fewer units; because repeated transformations naturally establish hierarchical structures. Large networks, on the other hand, hold many simple patterns side by side in a single layer.

Which one is better depends on the type of problem. Depth is often advantageous in areas such as vision and language, where hierarchical structures are evident. On the other hand, excessive depth creates unnecessary capacity in table data when working with limited data. The practical approach is to first select a reasonable depth, monitor the verification performance, and adjust the capacity by measurement. The architecture decision is made not by intuition but by measurement on dedicated data.

Output layer and problem type

The output layer produces the final estimate of the network and its unit is determined by the problem type. If a numerical quantity is estimated, a single unit and non-range limiting output is used. In a two-class separation, a single-unit probability output is sufficient; In more than one class, one unit is opened for each class. The choice of the output unit also determines the choice of the loss function; Incorrect matching can lead to training not progressing at all.

What distinguishes the output layer from hidden layers is that it can be directly interpreted. The numbers of hidden units alone have no meaning; The numbers of output units are read as estimates. Therefore, it is necessary to know in what range of values ​​the output produces. In an output that produces probability, the values ​​must remain between zero and one, and their sum must add up to one. This condition is the basis of the reliability of the interpretation.

The bridge between loss and prediction

Feedforward produces a prediction; How good this prediction is should also be measured. The loss function reduces the difference between the prediction and the label to a single number. Squared error in numerical predictions and class probability-based loss in classification are common. If the loss is large, the model is still far from correct; If it is small, the prediction is close to the label. The educational goal is to reduce this number.

The loss value alone does not indicate the quality of the model; because low loss in the training set can also hide memorization. Therefore, the same measurement is also performed on the reserved validation set. The table makes sense when the two values ​​are read together: if training and validation loss decrease together, learning is progressing; If validation increases while education decreases, generalization is impaired. Forward calculation prepares the input for this measurement.

Cost of forward computation

Each forward calculation involves applying as many matrix multiplications and activations as there are layers. The cost roughly depends on the number of parameters multiplied by the number of samples. As depth increases, the number of operations increases; There is a similar increase as the width increases. Therefore, the choice of architecture is driven not only by accuracy but also by computational budget. For an application running on limited hardware, a small but sufficient network is more valuable than a large but unreachable network.

Batch processing does not reduce this cost but increases efficiency; Since the hardware can perform many multiplications in parallel at the same time, proceeding in blocks instead of one by one provides significant speed. Additionally, since the gradient is not calculated during inference, less processing is required compared to training. This lightness of feedforward allows a trained network to respond with low latency in real use.

Tracing a small network step by step

Let's consider a network with two inputs, two hidden units and one output. Let the inputs be one and two respectively. Let the first hidden unit have weights of zero to fifty and negative to forty, and a bias of zero to ten. The net input is one times fifty plus two times minus forty plus ten, which is minus twenty. Activation converts this value to its range and the output passes to the next layer. The same process is repeated for the second hidden unit.

The output layer adds the two hidden outputs with their own weights and produces the final number. At this point the prediction of the network occurs; The comparison with the truth has not been made yet. Tracing the calculation by hand concretely shows the impact of weights and bias: a small change in a weight directly changes the net input and shifts the estimate at the end of the chain. This sensitivity explains why training proceeds by adjusting the weights.

Commonly confused points

Feedforward and training are often confused. However, feedforward only produces predictions; Does not include weight update. Another confusion is that the number of hidden layers and the number of parameters are not directly related as expected: a narrow but multi-layered network may carry fewer parameters than a wide but low-layered network. When making a decision, it is necessary to calculate the two quantities separately.

The third common mistake is to think that stacking linear layers on top of each other will add depth. Without activation, every layer added is wasted; because the composition still remains linear. Finally, the output layer and the hidden layer should not be treated with the same rule: the range and number of units of the output should be chosen together with the loss function. Making these distinctions clear prevents most architectural errors.

Key Points

Worked Examples

Worked Example

Worked Example

Worked Example

Worked Example

Worked Example

Common Mistakes

Tips

Practice Questions

  1. 1. It is a one-way flow of information from input to output through intermediate layers; There is no return link. To which concept does this definition belong?
  2. 2. Which of the following does "hidden layer" mean?
  3. 3. Which of the following statements is FALSE for «Weight matrix»?
  4. 4. It is a learnable parameter independent of input that shifts the activation threshold of a unit. To which concept does this definition belong?
  5. 5. Which of the following does «linear unit» mean?
  6. 6. Which of the following statements about «nonlinearity» is FALSE?
  7. 7. It is the sum of link weights and biases; directly determines model capacity. To which concept does this definition belong?
  8. 8. Which of the following does «Capacity» mean?
  9. 9. Which of the following statements is FALSE regarding «representation learning»?
  10. 10. It is a batch process that allows a layer to be calculated for all samples at the same time. To which concept does this definition belong?
  11. 11. Which of the following does «Layer width» mean?
  12. 12. Which of the following statements about «Depth» is FALSE?
  13. 13. It is the last layer that produces the prediction of the network; The number of units is chosen according to the problem type. To which concept does this definition belong?
  14. 14. Which of the following does "advanced computing" mean?
  15. 15. Which of the following statements is FALSE regarding «feed forward»?
  16. 16. It is the layer that sits between input and output and produces intermediate representations. To which concept does this definition belong?
  17. VOLUME 17 Which of the following does «Weight matrix» mean?
  18. 18. Which of the following statements about "prejudice" is FALSE?
  19. 19. It is the basic unit of account whose output is equal to the weighted sum of the inputs and does not apply thresholding. To which concept does this definition belong?
  20. 20. Which of the following does «non-linearity» mean?
  21. 21. Which of the following statements is FALSE for "number of parameters"?
  22. 22. It is the ability of the model to represent different functions; It increases with the number of layers and width. To which concept does this definition belong?
  23. 23. Which of the following does «representation learning» mean?
  24. 24. Which of the following statements for «matrix multiplication» is FALSE?
  25. 25. The number of units in a layer; It directly affects representation power and parameter cost. To which concept does this definition belong?
  26. 26 Which of the following does «Depth» mean?
  27. 27 Which of the following statements is FALSE for «output layer»?
  28. 28 It is the process of calculating the output of each layer sequentially, starting from the input while the weights are constant. To which concept does this definition belong?
  29. 29 Which of the following does "feed forward" mean?
  30. 30 Which of the following statements is FALSE for «Hidden layer»?
  31. 31 It keeps the connection strengths of the units in one layer to the units in the previous layer. To which concept does this definition belong?
  32. 32 Which of the following does "prejudice" mean?
  33. 33 Which of the following statements is FALSE for «linear unit»?
  34. 34 It is the transformation that is added between the layers and enables the model to represent non-linear relationships. To which concept does this definition belong?
  35. 35 Which of the following does «number of parameters» mean?
  36. 36 Which of the following statements about «Capacity» is FALSE?
  37. 37 It is the process of transforming raw input into more abstract and distinctive representations in successive layers. To which concept does this definition belong?
  38. 38 Which of the following does "matrix multiplication" mean?
  39. 39 Which of the following statements is FALSE for «Layer width»?
  40. 40 It is the number of consecutive transformations from input to output; establishes a longer chain of representation. To which concept does this definition belong?

Source: Inspired by open curricula of Turkish universities; the explanation is written originally.

Kaynak: Türkiye üniversitelerinin açık ders planlarından esinlenilmiştir; anlatım özgün olarak yazılmıştır.