r/LanguageTechnology • • Nov 27 '23

How does a neural network know whats right/wrong

Sorry for the stupid question, i am revisiting some fundamentals about CNNs, RNNs and was wondering how exactly do you tell a NN whats right and wrong? I know about the loss-function and how the error gets backproagated through the net.

But for example: If i want to train a model on a classification-task like sentiment-analysis, i iwould train it with labeled data of positiv and negative sample-documents. How exactly would the output of the NN be something like "positiv" or "negativ". Or is that not part of the NN Architecture and relies completly on the implementation and the task?

I feel like i missed something fundamental

0 Upvotes

9 comments sorted by

7

u/Pikalima Nov 27 '23 edited Nov 27 '23

Single-label classification networks output values normalized to [0, 1] and which sum to 1, hence they may be interpreted as class-wise probabilities (regardless of whether they are calibrated or not). This vector is typically scored against the one-hot encoded label (label smoothing is an exception to this), using any valid metric, most commonly binary cross-entropy. This reduces to -log(p) where p is the predicted probability for the actual class. When p=1, your model is as correct as it can be, so the loss is -log(1) = 0. As p goes to 0, -log(p) goes to positive infinity.

For your example, you have two classes, a positive class and a negative class. You might one-hot encode “positive” as [1, 0] and “negative” as [0, 1]. If your network outputs [0.4, 0.6] on a "positive" instance, the cross-entropy loss is -log(0.4) ≈ 0.916. You run backprop to get the partial derivatives of this function with respect to each network parameter.

During inference, you use a pre-determined decision threshold (e.g., t = 0.5) for the positive class above which you consider an instance to be “positive”.

2

u/LouisdeRouvroy Nov 28 '23 edited Nov 28 '23

RNNs and was wondering how exactly do you tell a NN whats right and wrong?

It doesn't know that.

It outputs numerical values. It's up to the user to assign a meaning (ie a classification) to that numerical value (right or wrong).

1

u/IQueryVisiC Nov 28 '23

Unsupervised learning

3

u/LouisdeRouvroy Nov 28 '23

Unsupervised learning

Still. Unsupervised learning brings out patterns out of data selected by the researcher. What these patterns mean are up to the researcher too.

0

u/IQueryVisiC Nov 28 '23

I just think that is is weird that a neural network creates classes. I guess that this heavily depends on the topology chosen by the researcher. Feels like some least square lossy compression algorithm..

1

u/LouisdeRouvroy Nov 28 '23

Feels like some least square lossy compression algorithm.

What?

1

u/gevorgter Nov 28 '23

You have 2 vectors when you train your model. One is the correct vector, and another is what the model is produced. The distance between those 2 shows how "right" or "wrong" you are.

The backpropogation is trying to reduce your distance (actually average of distances over your batch)

1

u/claytonkb Nov 28 '23

how exactly do you tell a NN whats right and wrong?

There are several different ways, based on implementation-details. But for the example you've given (sentiment classification), we will have rows of training data like this:

"Tomorrow's weather forecast is bleak...", "Negative"  
"Presidential approval ratings are up as tax-break for middle-class earners approved...", "Positive"
...

The classifier NN we are training will have just two output labels: Positive or Negative. During training, we feed the input text to the classifier and it will produce one or the other label. Since we've just started training, it will be wrong about 50% of the time. Whenever it's right, we do nothing. Whenever it's wrong, we back-propagate the error into the neural-network. The error is just a number between 0 and 1, and so the back-propagation phase is just a bunch of number-crunching (that's what all the GPUs are needed for).

As a further clarification, we will typically map each output label to the output parameter of the neural net by mapping a range to each label, for example:

(0,0.5] ==> Negative
(0.5,1) ==> Positive

So, the error will just be the numerical distance from the actual output of the neural-net, to the extreme range value of the correct token -- either 0 or 1 in this case.

1

u/olddoglearnsnewtrick Nov 28 '23

Only when you can model right and wrong in term of numeric values.