How to create forward functions for 6 targets

Rexedoziem: <p>How can I place in 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>

srishti-git1110: <p>Hi <a class="mention" href="/u/rexedoziem">@Rexedoziem</a>,</p>
<p>Can you please elaborate more on placing 6 targets inside the forward function?</p>
<p>Maybe by means of some pseudo code, please demonstrate what exactly you are trying to achieve and what’s the form of data (inputs and outputs) you have at hand.</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>Like this is a multioutput classification problem and it has 6 targets variables and I need to put it inside the forward function when working with my model, but I don’t know how to do that?</p>

srishti-git1110: <p>So, you could return the predictions corresponding to the 6 target variables from the forward function.</p>
<p>And in the training loop, use these 6 predictions and corresponding 6 ground truth to calculate the average loss. (Averaged over all 6 values as well the mini batch)</p>

Rexedoziem: <p>def forward(self, x):<br>
# Do your stuff here<br>
…<br>
x1 = F.log_softmax(x) # class probabilities<br>
x2 = … # bounding box calculation<br>
return x1, x2, x3, x4……</p>
<p>Can I do this for the 6 targets? By placing it up to x6?</p>

srishti-git1110: <p>Yes, you should be fine returning 6 values x1 through x6 as a tuple.</p>

Rexedoziem: <p>Thanks, but still have a question?</p>

srishti-git1110: <p>Sure, you can put your relevant doubts here. The community is here to help.</p>

Rexedoziem: <p>Alright.</p>
<p>using KFolds cross validation, since the target is 6 variables, can we put the 6 targets inside a list and get the values of it? e.g</p>
<p>targets_list = [‘cohesion’, ‘syntax’, ‘vocabulary’, ‘grammar’………]<br>
X = df.targets_list.values.</p>

Rexedoziem: <p>This is a screenshot</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/8/e87c80de875ee6d52ff95fb062ee891343d42bf1.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/e87c80de875ee6d52ff95fb062ee891343d42bf1" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/8/e87c80de875ee6d52ff95fb062ee891343d42bf1_2_375x500.jpeg" alt="image" data-base62-sha1="xaFwgz9pjVjz3mpwUUXuSsFA2ad" width="375" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/8/e87c80de875ee6d52ff95fb062ee891343d42bf1_2_375x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/e/8/e87c80de875ee6d52ff95fb062ee891343d42bf1_2_562x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/e/8/e87c80de875ee6d52ff95fb062ee891343d42bf1_2_750x1000.jpeg 2x" data-dominant-color="4E4F4D"><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">1920×2560 519 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>