# Multiple classes present in one-hot encoding

When dealing with classification for multiple classes present in the same sample, can the output layer have the form of one-hot encoding, but instead of only one hot, have multiple? That is, in case of a only single class being present in the sample, the encoding could be [0,1,0]. For multiple classes in the same sample, can it be [0,1,1]? And if yes, what loss function should be used?

• I am a bit confused. When you say input, du you mean sample? To my understanding, you are asking about samples that can belong to multiple multiple classes? Am I correct? Commented Mar 10, 2023 at 20:23
• Yes, by input I mean sample. And also yes, the same sample belongs to more than one class. Commented Mar 10, 2023 at 20:33

As a loss function, you could take the sum of the cross-entropy loss per output element. If you have $$m$$ classes, $$y=(y_1,\ldots, y_m)$$ would be the binary target and $$\hat{y}=(\hat{y}_1,\ldots,\hat{y}_m)$$ would be your prediction, then the loss could be $$\mathcal{L}=\sum_{j=1}^m -y_j\log \hat{y}_j - (1-y_j)\log (1-\hat{y}_j)$$