New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding MultiLabel SoftMargin Loss #2345
Adding MultiLabel SoftMargin Loss #2345
Conversation
src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp
Outdated
Show resolved
Hide resolved
src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp
Outdated
Show resolved
Hide resolved
src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp
Outdated
Show resolved
Hide resolved
Hi @iamshnoo
Thanks |
This comment has been minimized.
This comment has been minimized.
Hmm, That is strange. |
You can zoom in to the pic to find the tab space I am talking about. |
Agreed and you set tab = 2 spaces (this is what mlpack uses). |
Yep, that's what I had done initially before the review pointed out the misalignment. Then I tried changing it to 8 spaces and found the problem persisted in a different format.
Yep, I am gonna try this out and see. Thanks for the suggestion. |
Happy to help! |
Hey there, This code touches the loss function portion of mlpack's codebase. Recently #2339 was merged where the switch was made to templated return type instead of just using double. So before we merge this, kindly make the changes for the same. I'm pasting this in all relevant PRs. Thanks a lot 👍 |
src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss.hpp
Outdated
Show resolved
Hide resolved
src/mlpack/methods/ann/loss_functions/multilabel_softmargin_loss_impl.hpp
Outdated
Show resolved
Hide resolved
reduction(reduction), | ||
weighted(false) | ||
{ | ||
if (weights.n_elem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be easier to understand what happens here, if we provide a second constructor to set the weights. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi zoq, if you look at commit f298c7a, on May 5th, there I re-designed the API of this function to the current format after a long discussion above with @kartikdutt18. The conclusion of that discussion can be seen in this comment.
So, I think initially I had done what you are suggesting (let me know if you mean otherwise) using a overloaded constructor to set the weights. But then Kartik wanted me to design the API like this.
I am okay with both. Even though I would prefer the approach with an overloaded constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I am guessing the other constructor would also have weights as param and probably a reduction also as param. It might ve redundant to have two constructors with same parameters. We would only have one forward function so we would have take into account both cases. For initialization we check if the vector is empty, if yes, we set reset to true and in forward pass we initialize the weights equal to input features and we set reset to false so we don't initialize every iteration. If weights are passed then we set reset to false and copy weights so no initialization in forward pass. Maybe I missed something, let me know what you think.
Regards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of API wouldn't an overloaded constructor be redundant. I am guessing one constructor will be with parameter reduction and one with both reduction and weights parameter. We can simply have one constructor and set weights to default value and in forward pass set them to 1 only in the first pass. This allows us to have a forward function which doesn't depend on which constructors object we are dealing with. I have left a comment explaining something similar.
const InputType& input, const TargetType& target) | ||
{ | ||
if (!weighted) | ||
classWeights.ones(1, input.n_cols); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could go into the other constructor, see comment above, that way we don't set this in each call of forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree! Detailed comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I suggested using a reset parameter so this initialized only in the first pass. I am using my phone so sorry I can't take a look at the code. Similar thing is done in adaptive pooling layers. Regards.
Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
if (!weighted) | ||
classWeights.ones(1, input.n_cols); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, The weights will be initialised every time in forward pass here, You should set weighted to true here to prevent that from happening. As shown here, we use reset to prevent weights from being initialized every time i.e. If user has not passed weights they will be initialized once in forward pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! This was something I missed completely. Corrected in the commit 77463d8.
Thanks to both zoq and you for pointing this out.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍 |
Let's keep this open please! |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍 |
Hey @iamshnoo, just wanted to check on this one---I see it's approved, but it seems like there is still work to do before it's ready for merge? |
I will pull in the recent upstream changes to this branch in the next commit (hopefully in the next couple of days). Other than the merge conflicts and changing boost to catch2, there probably won't be too many other changes to make. Thanks for the reminder. |
5933dff
to
77463d8
Compare
f36c858
to
e7ef286
Compare
e7ef286
to
180f917
Compare
Thank you for updating the PR! I feel it's ready from my end. Nothing more to add. |
In this PR, I am adding the Multi Label Soft Margin Loss function.
Here is a link to a Jupyter notebook to verify the outcomes presented in the test cases added.