Answers.Body: <p>your question is rather vague. A trained classifier should already estimate conditional probability of Y given input Z.</p>
  <p>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
  <a href="https://medium.com/swlh/cross-entropy-loss-in-pytorch-c010faf97bab" rel="nofollow noreferrer">https://medium.com/swlh/cross-entropy-loss-in-pytorch-c010faf97bab</a></p>
  <p>if you have a different question please edit your question.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-09T17:09:38.300Z
Answers.Text: Hi @saleh, I have edited the question.
Answers.UserDisplayName: QuantumPanda
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-09T12:57:22.977Z
Answers.LastActivityDate: 2024-07-09T12:57:22.977Z
Answers.UserDisplayName: saleh
Body: <p>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:</p>
  <pre><code>loss_value = arbitrary_loss(probability1, probability2, ..., P(Y|Z))
  </code></pre>
  <p>I wish to have an <strong>end-to-end framework</strong> 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.</p>
  <p>This term P(Y|Z) is then estimated and plugged into the final loss which is the sum and product of other probabilities.</p>
  <pre><code>P(Y|Z) = MLP(input_Z) #probability given input Z over labels
  </code></pre>
  <p>My issue is that if I simply take the value of the softmax layer to estimate this probability and plug it in, <strong>at no point are the true labels taken into account for a supervised machine learning problem.</strong></p>
  <p>How can I fix this without modifying the final loss function?</p>
  <p>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?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-07-10T06:52:44.020Z
Comments.Text: Thanks for the update.  Can you tell me for which variable you have access to the true labels?
Comments.UserDisplayName: saleh
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-07-10T17:05:20.863Z
Comments.Text: 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!
Comments.UserDisplayName: QuantumPanda
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-09T06:17:57.940Z
Comments.Text: You can simply add CE loss to your existing arbitrary loss function.
Comments.UserDisplayName: cinch
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-22T17:25:55.053Z
Comments.Text: Thank you @cinch ! I should have updated the answer. Yes this is what I have resorted to and implemented. It works!
Comments.UserDisplayName: QuantumPanda
Tags: <deep-learning><objective-functions><multilayer-perceptrons><softmax>
Title: Using conditional probability as an estimate in a loss function
UserDisplayName: QuantumPanda
ThreadText: # Using conditional probability as an estimate in a loss function
  
  (Asked by: username_0 on 2024-07-08)
  
  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?
  
  **Tags:** deep-learning, objective-functions, multilayer-perceptrons, softmax
  > **Comments:**
  > **username_1**: Thanks for the update.  Can you tell me for which variable you have access to the true labels?  
  > **username_0**: 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!  
  > **username_2**: You can simply add CE loss to your existing arbitrary loss function.  
  > **username_0**: Thank you @cinch ! I should have updated the answer. Yes this is what I have resorted to and implemented. It works!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-07-09. Score: 0
  
  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.
  
  > **Comments:**
  > **username_0**: Hi @saleh, I have edited the question.  
  
  ---
  
  