I need help/advice/example regarding the approach in the development of PyTorch custom-loss function in NLP multiclass classification.
The dataset looks something like this:
TEXT LABEL
text1 ‘AC’
text2 ‘AD’
text3 ‘BC’
text4 ‘BC’
text5 ‘BD’
…the rest of the dataset…
Labels ‘AB’ or ‘CD’ are impossible from the business perspective and will not appear in the dataset. The first part of the label is always ‘A’ or ‘B’ and the second is always ‘C’ or ‘D’. So, there are only four possible classes: ‘AC’, ‘AD’, ‘BC’, BD’.
I need multiclass classification to four classes, ‘AC’, ‘AD’, ‘BC’, BD’, but I need a loss function that will include and learn/implement the relation between components A-B/C-D. For example, the penalization factor for the wrong prediction of the first label should be alpha and the second beta. It would be great to learn these parameters alpha and beta. Of course, if someone has a better suggestion, instead of these parameters, I would follow it.
For example, to simplify, let these labels present labels of sentiment analysis. A component means emotionally, B component means unemotionally, C component means positive, D component means negative (expression in the text).
What would be the best way to do that? Are there steps I should do in feature engineering, or it’s possible to implement just through the loss function (preferable)? Some code snippets are more than welcome.
Thank you