Support multilabel binary cross entropy #1571
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
BinaryCrossEntropyLoss
only supports the binary case for 1-D inputs and targets. This PR extends the current definition to supportTensor<B, D>
.For multi-label classification the typical shape is
[batch_size, num_classes]
and targets are provided as multi-hot encoded targets.Checklist
run-checks all
script has been executed.Changes
Added support for multilabel BCE loss for input
Tensor<B, D>
log_sigmoid(x)
instead oflog(sigmoid(x))
with logits (numerical stability)Tensor<B, D>
Changed the default config to use
BinaryCrossEntropyLoss
without logits (expects probabilities, not raw predictions/logits). I think this makes more sense as a default and allows to use the config to build the loss with something more natural:This is a bit of an opiniated change, could be reverted if really desired.
Testing
Added unit tests for new multi-label case and updated the binary 1-D tests.