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

Implemented CORN loss for ordinal classification #3375

Merged
merged 4 commits into from
May 2, 2023
Merged

Conversation

tgaddair
Copy link
Collaborator

@tgaddair tgaddair commented May 1, 2023

See: https://github.com/Raschka-research-group/coral-pytorch

When using the CORN loss, the vocab needs to be explicitly provided to ensure that the ordering of the categories is properly honored:

output_features:
  - name: rating
     type: category
     preprocessing:
       vocab: ["terrible", "bad", "okay", "good", "great"]
     loss:
       type: corn

We chose to replicate the code here with attribution rather than add an additional dependency due to the self-contained nature of the implementation to just a couple torch-only functions.

Comment on lines 12 to 25
def coral_loss(logits, levels, importance_weights=None, reduction="mean"):
"""Computes the CORAL loss described in.

Cao, Mirjalili, and Raschka (2020)
*Rank Consistent Ordinal Regression for Neural Networks
with Application to Age Estimation*
Pattern Recognition Letters, https://doi.org/10.1016/j.patrec.2020.11.008

Parameters
----------
logits : torch.tensor, shape(num_examples, num_classes-1)
Outputs of the CORAL layer.

levels : torch.tensor, shape(num_examples, num_classes-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it also worth adding a CoralLoss Config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, removed for now as not sure where it would make sense to use it.

@github-actions
Copy link

github-actions bot commented May 1, 2023

Unit Test Results

    6 files  ±    0      6 suites  ±0   3h 50m 47s ⏱️ + 3h 3m 34s
194 tests +161  163 ✔️ +134  31 💤 +27  0 ±0 
363 runs  +277  311 ✔️ +239  52 💤 +38  0 ±0 

Results for commit 45b2613. ± Comparison against base commit 1529e02.

♻️ This comment has been updated with latest results.

@tgaddair tgaddair merged commit 662413e into master May 2, 2023
@tgaddair tgaddair deleted the corn-loss branch May 2, 2023 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants