Multi label classification problem

Rexedoziem: <p>I’m working on a multi label classification problem that each data frame has a unit of 1-5 as values in it, which loss function would be the best to use in this scenario?</p>

ptrblck: <aside class="quote no-group" data-username="Rexedoziem" data-post="1" data-topic="160685">
<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/rexedoziem/48/52029_2.png" class="avatar"> Rexedoziem:</div>
<blockquote>
<p>multi label classification problem that each data frame has a unit of 1-5 as values in it</p>
</blockquote>
</aside>
<p>I’m not sure how to understand this description, but assume you are working on a multi-label classification where each sample can belong to 0, 1, or multiple classes. If so, you can use <code>nn.BCEWithLogitsLoss</code> to train the model and can pass a target in the same shape as the model output (<code>[batch_size, nb_classe, *]</code>) where a 0 would indicate an inactive and a 1 an active class.</p>

Rexedoziem: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/9/397b4c6de486ba1bfa698e11010308cc3356b504.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/397b4c6de486ba1bfa698e11010308cc3356b504" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/9/397b4c6de486ba1bfa698e11010308cc3356b504_2_619x500.jpeg" alt="image" data-base62-sha1="8cvnFqq1YEiOPdOgp4k3vMXijqc" width="619" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/9/397b4c6de486ba1bfa698e11010308cc3356b504_2_619x500.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/3/9/397b4c6de486ba1bfa698e11010308cc3356b504.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/9/397b4c6de486ba1bfa698e11010308cc3356b504.jpeg 2x" data-dominant-color="F8F8F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">750×605 55.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

Rexedoziem: <p>That’s the screenshot of the problem. I’m asking if the values in the targets, since it’s not zeros and ones, can I still use BCEloss…</p>

ptrblck: <p>No, I don’t think the labels represent a multi-label classification, but rather some kind of scores. In that case you might want to use a regression loss such as <code>nn.MSELoss</code>.</p>

Rexedoziem: <p>So it can be treated as multioutput regression problem where it’ll having the number of classes as outputs?</p>

ptrblck: <aside class="quote no-group" data-username="Rexedoziem" data-post="6" data-topic="160685">
<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/rexedoziem/48/52029_2.png" class="avatar"> Rexedoziem:</div>
<blockquote>
<p>where it’ll having the number of classes as outputs</p>
</blockquote>
</aside>
<p>No, I don’t think your current targets represent classes, as they are floating point numbers.<br>
E.g. what would “cohesion 2.5; synta… 2.5” represent?</p>

Rexedoziem: <p>But in this case the problem can be treated as multioutput regression problem?</p>

Rexedoziem: <p>Maybe I can screenshot the full data for you to see it……</p>

ptrblck: <aside class="quote no-group" data-username="Rexedoziem" data-post="8" data-topic="160685">
<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/rexedoziem/48/52029_2.png" class="avatar"> Rexedoziem:</div>
<blockquote>
<p>can be treated as multioutput regression</p>
</blockquote>
</aside>
<p>Yes, the use case can be treated as a regression with multiple outputs.<br>
I would not claim they are classes:</p>
<aside class="quote no-group" data-username="Rexedoziem" data-post="6" data-topic="160685">
<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/rexedoziem/48/52029_2.png" class="avatar"> Rexedoziem:</div>
<blockquote>
<p>treated as multioutput regression problem where it’ll having the number of classes as outputs</p>
</blockquote>
</aside>

Rexedoziem: <p>But can I place the 6 targets into the forward function?, and how does that look like….<br>
Then talking about the loss function should I add all the losses to get the final loss?</p>

Rexedoziem: <p>And can I place in the number of targets(6) inside the linear() function…… ?</p>

Rexedoziem: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> please I need a response?</p>