Math in crossentropy loss document

Pakpoom_Singkorapoom: <p>Hello</p>
<p>I am reading this doc about crossentropy loss <a href="https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss" class="inline-onebox" rel="noopener nofollow ugc">CrossEntropyLoss — PyTorch 2.1 documentation</a></p>
<p>There are parts I don’t understand</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/a/3a5a37bb8822527b7681874e0ca361e7541248db.png" alt="image" data-base62-sha1="8kcYZPMLLCM1M8a0mqF4pYNZdMv" width="314" height="78"><br>
How should I read this part? and What is it??</p>
<p>These might be dump question. I am a beginner so please help me.</p>

Pakpoom_Singkorapoom: <p>also I don’t get why yn is in subscription in this<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/e/6/e6cedb7d85b082b9d084dcf95806d66392ef5e4f.png" alt="image" data-base62-sha1="wVP0v9zpTCyt2aHL3RM60uYxTen" width="376" height="80"></p>

KFrank: <p>Hi Pakpoom!</p>
<aside class="quote no-group" data-username="Pakpoom_Singkorapoom" data-post="1" data-topic="195506" data-full="true">
<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/pakpoom_singkorapoom/48/66935_2.png" class="avatar"> Pakpoom_Singkorapoom:</div>
<blockquote>
<p>How should I read this part? and What is it??</p>
</blockquote>
</aside>
<p>This is probably not the best (nor particularly standard) notation.</p>
<p>As a practical matter, it means that you leave out (“ignore”) any terms for<br>
which the <code>target</code> class, <code>y_n</code>, has the <code>ignore_index</code> value.</p>
<p>More mathematically, you should take <code>1{y_n != ignore_index}</code> to mean<br>
<code>0</code> if <code>y_n == ignore_index</code> and <code>1</code> if <code>y_n != ignore_index</code>.</p>
<p>Let me also answer the question in your second post here:</p>
<aside class="quote no-group" data-username="Pakpoom_Singkorapoom" data-post="2" data-topic="195506">
<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/pakpoom_singkorapoom/48/66935_2.png" class="avatar"> Pakpoom_Singkorapoom:</div>
<blockquote>
<p>I don’t get why yn is in subscription</p>
</blockquote>
</aside>
<p><code>n</code> is the index of the sample within the batch you are processing.  <code>y_n</code> is the<br>
ground-truth <code>target</code> integer class label for that sample.</p>
<p><code>CrossEntropyLoss</code> let’s you assign different weights to different classes.<br>
<code>w_(y_n)</code> is the weight of the class with which sample <code>n</code> has been labelled.</p>
<p>Inside of the <code>exp()</code>, <code>x_{n, y_n}</code> goes like this.  <code>x</code> is the so-called <code>input</code> to<br>
<code>CrossEntropyLoss</code>.  That is, it is (typically) the prediction made by your model.<br>
<code>x_n</code> is the prediction for the <code>n</code>th sample in the batch.  But your prediction is a<br>
set of (unnormalized) log-probabilities for each of your classes.  So <code>x_{n, y_n}</code><br>
is the predicted log-probability for sample <code>n</code> for the class <code>y_n</code>, which is the<br>
ground-truth class label assigned to sample <code>n</code>.</p>
<p>Best.</p>
<p>K. Frank</p>