What will happen if the input of torch.nn.functional.binary_cross_entropy is zero

hanhaowen: <p>If the input tensot of torch.nn.functional.binary_cross_entropy is zero , and the target tensor is 1.0, the output will be 100.<br>
Here is my code:</p>
<p>input=torch.tensor(0.0)<br>
target=torch.tensor(1.0)<br>
loss=F.binary_cross_entropy(input,target)<br>
print(loss) <span class="hashtag">#tensor</span>(100.)</p>
<p>so I want to know how does the function proceed when the input is zero, cause in the math formula, log(0.0) will cause a math domain problem , but this does not happen in the pytorch.</p>
<p>I am looking forward to hearing from you</p>

CedricLy: <p><a href="https://pytorch.org/docs/master/generated/torch.nn.BCELoss.html#torch.nn.BCELoss" rel="noopener nofollow ugc">BCELoss — PyTorch master documentation</a></p>
<p>Here is the original documentation in the last sentence they reveal clamping the output.</p>
<blockquote>
<p>Our solution [regarding the infinity issue] is that BCELoss clamps its log function outputs to be greater than or equal to -100. This way, we can always have a finite loss value and a linear backward method.</p>
</blockquote>

hanhaowen: <p>Thank you for your answer, but is it always equal to -100? Your answer says that the output will be greater than or equal to -100, so will the output change from time to time? For example, in the former execution the output is -101 but this time it is -100. In my computer, it is always -100, but will it change in some moment?</p>

CedricLy: <p>If the loss of your output creates a value higher or equal to 100 it will clamp it at 100.<br>
So -101 will be -100.</p>
<p>I don’t really understand what you mean by that:</p>
<aside class="quote no-group" data-username="hanhaowen" data-post="4" data-topic="109073">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/bc79bd/48.png" class="avatar"> hanhaowen:</div>
<blockquote>
<p>For example, in the former execution the output is -101 but this time it is -100</p>
</blockquote>
</aside>
<p>Can you elaborate on that?</p>

hanhaowen: <aside class="quote no-group" data-username="CedricLy" data-post="2" data-topic="109073">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/cedricly/48/30907_2.png" class="avatar"> CedricLy:</div>
<blockquote>
<p>Our solution [regarding the infinity issue] is that BCELoss clamps its log function outputs to be greater than or equal to -100</p>
</blockquote>
</aside>
<p>the document says"Our solution [regarding the infinity issue] is that BCELoss clamps its log function outputs to be greater than or equal to -100",so it is greater than or equal to -100,so what exactly is the output? You know “greater than or equal to -100” is an interval instead of a number. So which number in the interval will be output?</p>

ptrblck: <p>Based on the description, the theoretical output in the range <code>[-Inf, +Inf]</code> is clipped to <code>[-100, +Inf]</code>, if I’m not misunderstanding it. Thus the actual value depends on the calculated loss, but is clipped at <code>-100</code> in its minimum.</p>

hanhaowen: <p>Thanks! Now I understand it.</p>