I have a rather large ML framework that takes multiple conditional probability terms that are computed via classifiers/neural networks. This arbitrary loss function is computed via a function:

loss_value = arbitrary_loss(probability1, probability2, ..., P(Y|Z))

I wish to have an end-to-end framework that computes everything and trains everything together. So I do not want to have an independently trained classifier. Say at some point I develop some intermediate values (embeddings) Z from the input samples X. I wish to model the conditional probability P(Y|Z) via an MLP softmax layer.

This term P(Y|Z) is then estimated and plugged into the final loss which is the sum and product of other probabilities.

P(Y|Z) = MLP(input_Z) #probability given input Z over labels

My issue is that if I simply take the value of the softmax layer to estimate this probability and plug it in, at no point are the true labels taken into account for a supervised machine learning problem.

How can I fix this without modifying the final loss function?

TLDR: I need a probability term P(Y|Z) modeled via an MLP softmax layer to be used in a complex arbitrary loss function. How do i ensure this term is accurate via the true label values, so that it can be used in the final loss?

  • $\begingroup$ Thanks for the update. Can you tell me for which variable you have access to the true labels? $\endgroup$
    – saleh
    Commented Jul 10 at 6:52
  • $\begingroup$ of course, lets say i have a variable 'labels,' corresponding to the true labels of inputs. Lets say inputs go through a sequence of multiple deterministic mappings until they become 'input_Z'. the variable P(Y|Z) corresponds to the output of the MLP given the intermediate variable 'input_Z'. I hope this clarifies things, thank you for your time! $\endgroup$ Commented Jul 10 at 17:05

1 Answer 1


your question is rather vague. A trained classifier should already estimate conditional probability of Y given input Z.

if your question is how to train such a classifier the answer is via CrossEntropy loss. so you have the output probability from your (untrained) classifier network and also the grountruth. CrossEntropy(prediction,grountruth) would be your loss. Here you can find more explanation https://medium.com/swlh/cross-entropy-loss-in-pytorch-c010faf97bab

if you have a different question please edit your question.

  • $\begingroup$ Hi @saleh, I have edited the question. $\endgroup$ Commented Jul 9 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .