Self-adjusting Dice Loss
This is an unofficial PyTorch implementation of the Dice Loss for Data-imbalanced NLP Tasks paper.
Usage
Installation
pip install sadice
Text classification example
import torch
from sadice import SelfAdjDiceLoss
criterion = SelfAdjDiceLoss()
# (batch_size, num_classes)
logits = torch.rand(128, 10, requires_grad=True)
targets = torch.randint(0, 10, size=(128, ))
loss = criterion(logits, targets)
loss.backward()
NER example
import torch
from sadice import SelfAdjDiceLoss
criterion = SelfAdjDiceLoss(reduction="none")
# (batch_size, num_tokens, num_classes)
logits = torch.rand(128, 40, 10, requires_grad=True)
targets = torch.randint(0, 10, size=(128, 40))
loss = criterion(logits.view(-1, 10), targets.view(-1))
loss = loss.reshape(-1, 40).mean(-1).mean()
loss.backward()
Metadata
Release files for sadice 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sadice-0.1.3.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sadice-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / sadice-0.1.3.tar.gz
| Download URL | sadice-0.1.3.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ee273d72dedc0ca984402c415f766c8f72a5fc4a69167d09d2c0fe396ddc70c
|
|
BLAKE2b-256 checksum How to use checksums |
123f2775ef9dbc1813d9967fd25ba84da83519ba007ecefc13cbad324f30d56a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.7.9 Darwin/19.6.0
|
Release files / sadice-0.1.3-py3-none-any.whl
| Download URL | sadice-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
271b9f25e117d81836c13852837c9fb155589d407fb345b9fd7e87bb14d3ff43
|
|
BLAKE2b-256 checksum How to use checksums |
9fedf566e4791f0c1eb1a2edc459d571ee93a4579fada122f4028c69d4d8f131
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.7.9 Darwin/19.6.0
|