# How to train a neural network *not* to give a certain output?

I have a neural network with a softmax layer as final layer. The loss function I use is the categorical crossentropy loss. I want to classify an input to belong to exactly one of N classes. But for some of the inputs, I don't know which class they belong to, but only which class(es) they do not belong to. What is the best way to implement this as a training example?

The approach I used is best explained by an example: Suppose we want to separate 4 classes and are given a training example that we know does not belong to classes 2 and 3, then I would supply the following vector as target vector:

[0.5, 0, 0, 0.5]

If instead we knew that the training example does not belong to class 1, then I would supply the following vector as target vector:

[0, 1/3, 1/3, 1/3]

Is this the correct approach? Is my choice of activation function in the final layer correct?

Usually when doing multi-class classification, we encode the classes using one-hot encoding. For example, in four-class classification, belonging to third class would be encoded as [0, 0, 1, 0]. In your case, you seem to have missing information in the data, since you know only something like "it's not class one, or two", i.e. [0, 0, ?, ?].

Simple solution could be to redefine the problem, and treat it as a multi-label classification problem, where for each training example you would code as 0's the classes that are not positive, while positive, or unknown classes are coded as 1's.

[0, 0, ?, ?] -> [0, 0, 1, 1]
[1, 0, 0, 0] -> [1, 0, 0, 0]
[?, ?, 0, ?] -> [1, 1, 0, 1]


This would make your algorithm learn to classify the possible positives, so you could choose among them to make proper classification.

Notice, that this makes it a noisy labels problem. You have data, but imprecise. Imagine that you had three, very similar, examples, and you would know that the first is "not class one", second is "not class one, or four", while third is "not class three, or four". From this, you could deduce that the examples are certainly not from class four, and probably not from class one, or two, so they likely come from class two. This is how, given enough data, your algorithm could learn the correct answer given noisy labels.

If you additionally have a subset of good data, where all the examples have proper labels, than you could use this data to learn a standard multi-class classifier. Next, you could combine both results, so that first classifier is used to filter the likely classes, and second to make the classification. For example, if the first classifier returns the probabilities of being non-negative $$(p_1, p_2, p_3, p_4)$$, and the second one probabilities of belonging to the class $$(q_1, q_2, q_3, q_4)$$, than you could combine those to make classification by taking

$$\operatorname{arg\max}_i\; (p_1 q_1,\, p_2 q_2,\, p_3 q_3,\, p_4 q_4)$$

• I appreciate that we can, arbitrarily, relabel the positives as 0 and the negatives as 1, or vice-versa, but I'm not grasping what the purpose is of using the coding 1s are not positive and the rest as 0s. It seems to fly in the face of convention without a payoff -- or at least, not one that I can perceive. Can you elaborate? – Sycorax Aug 5 '20 at 0:05
• @Sycorax it sounded simpler for me like this, but you're right, it isn't. Fixed. – Tim Aug 5 '20 at 6:19

To answer the question about your approach of providing target distributions: yes, that is a correct approach, and softmax is the right final layer for this approach.

• Can you elaborate? Why is this the correct approach? – Sycorax Aug 4 '20 at 23:53