DeepLLM Quiz
Deep Learning

Choosing the right output and error function for a neural network

10 questions on squared error, binary and multi-class cross-entropy, multi-label outputs, labelling noise, non-convexity and matching losses to outputs.

  • 10 questions
  • Stopwatch
  • Instant feedback

Shown publicly with your score. Don’t use your full real name.

Sample questions

Play now ↑

Answers stay hidden. Start the quiz to play them.

  1. Sample 1

    After the iterative training of a regression network has finished, how can the noise variance be estimated?

    • It must be set before training begins and can never be learned
    • From the average squared gap between the network's outputs and the targets, computed once the weights are fixed
    • From the number of layers
  2. Sample 2

    A network must predict a single yes-or-no outcome. Which output and loss fit it naturally?

    • A softmax with three outputs and an absolute error
    • A linear output with a squared error
    • A single logistic sigmoid output with a cross-entropy loss

How it works

  • One question per screen. An answer is final once sent.
  • You see right away whether you were right, with a short explanation.
  • The stopwatch runs: on equal scores, the faster player ranks first.
  • Only your best attempt counts, so replaying is never risky.

About this quiz

Before a network can learn anything, someone has to decide two things: what its last layer will output and how its mistakes will be scored. These choices are among the first a practitioner makes, and among the easiest to get wrong, with consequences that range from training that is slower than necessary to a model that quietly answers the wrong question. The good news is that they are not arbitrary. Each type of problem has a natural pairing of output and loss, which follows from asking what probability distribution the targets are likely to have.

This quiz goes through the three standard cases. For predicting a continuous quantity, the assumption is that the target varies around the network's output with Gaussian noise, which leads to a linear output and a loss based on squared differences. For a yes-or-no label, the assumption is a Bernoulli distribution, which leads to a single output squashed into the range zero to one and a cross-entropy loss. For one of several exclusive classes, the answer is a vector of outputs that add up to one and a multi-class version of the cross-entropy. You will see what to do when a case may carry several labels at once, and how the model can allow for the possibility that some labels are wrong.

The quiz also covers some realities of training. The error of a real network is not a simple bowl-shaped function, so training finds a good solution and not necessarily the best one. The noise level can be estimated once the weights are found. And some output choices contain redundancy that a penalty on the weights removes. Frequent mistakes include using squared error for classification, mixing up multi-label and multi-class problems, and expecting training to reach the global optimum. A practical consequence is that most deep learning libraries provide matched pairs, for example a combined softmax and cross-entropy function, and using the matched pair is both simpler and numerically safer than assembling the pieces by hand. Getting this choice right matters more than most tuning: a network with the wrong output and loss can train for days and still answer a question nobody asked, for instance by treating exclusive classes as independent or by treating a count as a category. A little time spent writing down what the target actually is, and which distribution it plausibly follows, repays itself many times over. The same reasoning extends to new kinds of target that are not covered by the standard cases: describe the distribution you believe, take its negative logarithm, and you have the loss.

The quiz suits students and practitioners who build or fine-tune networks and want to understand the defaults they use. It needs no mathematics. There are 10 questions, each explained straight after you answer, and the quiz takes about four minutes.

Questions and answers

›How long does the quiz take?

About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation appears after every answer.

›Do I need to know the formulas for the losses?

No. The questions ask which output and which kind of loss suit a described problem, and why. They don't ask you to write or evaluate a formula. If you know what the task is, you can reason about the answer.

›Why does regression use a linear output and squared error?

Because the usual assumption is that the target equals the network's output plus Gaussian noise. Maximising the likelihood of the data under that assumption is the same as minimising the sum of squared differences. An unbounded linear output is sufficient, since the network can approximate any continuous function.

›What is cross-entropy loss?

It is the negative logarithm of the likelihood of the labels when the network outputs probabilities. It is large when the model gives a low probability to the label that actually occurred. It has been found to give faster training and better generalisation than squared error for classification. A practical check is to look at the first predictions of an untrained network. With the right pairing, a freshly initialised classifier outputs probabilities that are roughly equal across classes, and its first loss value is close to the logarithm of the number of classes, which is an easy way to spot a mismatch before wasting training time.

›What is the difference between multi-label and multi-class problems?

In a multi-class problem each case belongs to exactly one of several classes, so the outputs compete, and a softmax is used. In a multi-label problem a case may carry any combination of labels, so each label is a separate yes-or-no question with its own sigmoid output.

›How can a classifier allow for wrong labels?

The model can include a small probability that any given label has been flipped to the wrong value. This probability can be fixed beforehand or treated as a setting to be inferred from the data. It stops a few mislabelled examples from distorting the fit as strongly.

›Does training a network find the best possible weights?

Not usually. The error of a network is not convex, so there can be many valleys, and optimisation finds one good one. It is also common to add penalties or to stop early, so that the final solution differs from the pure maximum likelihood answer.

›Why does a penalty help with softmax outputs?

Adding the same constant to every pre-activation leaves the softmax outputs unchanged. The error then doesn't depend on that direction in weight space, which makes the problem under-determined. A penalty on the size of the weights removes this ambiguity. When in doubt about which loss to use, write down what the target is, a number, a yes-or-no, one class out of several or several independent tags, and the table in the quiz tells you the output and the loss.

More quizzes