Skip to content
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

Add Hinge metric #120

Merged
merged 39 commits into from
Mar 25, 2021
Merged

Conversation

ethanwharris
Copy link
Member

@ethanwharris ethanwharris commented Mar 22, 2021

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

Fixes #89 - added the multiclass_mode parameter to enable computation in a one-vs-all fashion (e.g. for multi-class SVMs)

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Mar 22, 2021

Codecov Report

Merging #120 (bdae664) into master (26eae39) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #120      +/-   ##
==========================================
- Coverage   96.38%   96.35%   -0.03%     
==========================================
  Files         140       72      -68     
  Lines        4420     2280    -2140     
==========================================
- Hits         4260     2197    -2063     
+ Misses        160       83      -77     
Flag Coverage Δ
Linux 79.07% <88.57%> (+0.30%) ⬆️
Windows 79.07% <88.57%> (+0.30%) ⬆️
cpu 96.35% <100.00%> (+0.11%) ⬆️
gpu ?
macOS 96.35% <100.00%> (+0.11%) ⬆️
pytest 96.35% <100.00%> (-0.03%) ⬇️
python3.6 96.35% <100.00%> (+0.11%) ⬆️
python3.8 96.35% <100.00%> (+0.11%) ⬆️
python3.9 96.35% <100.00%> (+0.11%) ⬆️
torch1.3.1 95.12% <100.00%> (+0.15%) ⬆️
torch1.4.0 95.26% <100.00%> (+0.15%) ⬆️
torch1.8.1 96.35% <100.00%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
torchmetrics/__init__.py 100.00% <ø> (ø)
torchmetrics/classification/__init__.py 100.00% <100.00%> (ø)
torchmetrics/classification/hinge.py 100.00% <100.00%> (ø)
torchmetrics/functional/__init__.py 100.00% <100.00%> (ø)
torchmetrics/functional/classification/__init__.py 100.00% <100.00%> (ø)
torchmetrics/functional/classification/hinge.py 100.00% <100.00%> (ø)
__w/1/s/torchmetrics/utilities/enums.py
__w/1/s/torchmetrics/info.py
...etrics/functional/regression/mean_squared_error.py
.../1/s/torchmetrics/functional/retrieval/__init__.py
... and 68 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26eae39...bdae664. Read the comment docs.

@Borda Borda changed the title [WIP][New Metric] Add HingeLoss metric [WIP] Add HingeLoss metric Mar 23, 2021
@Borda Borda added enhancement New feature or request New metric labels Mar 23, 2021
@ethanwharris ethanwharris changed the title [WIP] Add HingeLoss metric Add HingeLoss metric Mar 23, 2021
@ethanwharris ethanwharris marked this pull request as ready for review March 23, 2021 17:20
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very sure about adding anything named as Loss, could we have it consistent with others?

@ethanwharris
Copy link
Member Author

ethanwharris commented Mar 23, 2021

@Borda Happy to change if needed 😃 although not sure what else to call it. I guess the options are:

  • hinge_loss (consistent with sklearn)
  • hinge (avoids "loss", looks like Keras does this)
  • it's sometimes also called the max-margin objective, so maybe that?

Any other suggestions @SkafteNicki @justusschock ?

@ethanwharris ethanwharris changed the title Add HingeLoss metric Add Hinge metric Mar 24, 2021
@ethanwharris
Copy link
Member Author

@Borda @SkafteNicki Thanks for the comments 😃 I've added check for multiclass_mode and switched hinge loss to just hinge so should all be ready for review now.

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, almost there, just last comments from me :]

docs/source/references/functional.rst Outdated Show resolved Hide resolved
docs/source/references/modules.rst Outdated Show resolved Hide resolved
torchmetrics/classification/hinge.py Outdated Show resolved Hide resolved
torchmetrics/classification/hinge.py Outdated Show resolved Hide resolved
@pep8speaks
Copy link

pep8speaks commented Mar 24, 2021

Hello @ethanwharris! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-03-25 19:51:13 UTC

Copy link
Member

@SkafteNicki SkafteNicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smaller comments else LGTM

torchmetrics/classification/hinge.py Show resolved Hide resolved
torchmetrics/classification/hinge.py Show resolved Hide resolved
torchmetrics/classification/hinge.py Show resolved Hide resolved
@ethanwharris
Copy link
Member Author

@PyTorchLightning/core-metrics I was having a weird issue here where the test was hanging forever rather than reporting an error with ddp and dist_sync_on_step both True. Managed to fix the bug so all works now, but ideally it would report the test failure rather than hang. Is this a known issue?

@SkafteNicki SkafteNicki merged commit 8e87d1b into Lightning-AI:master Mar 25, 2021
@Borda Borda added this to the 0.3 milestone Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Hinge losses
5 participants