Self-adjusting Dice Loss implementation
Project description
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sadice-0.1.3.tar.gz
(6.4 kB
view details)
Built Distribution
File details
Details for the file sadice-0.1.3.tar.gz
.
File metadata
- Download URL: sadice-0.1.3.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.9 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ee273d72dedc0ca984402c415f766c8f72a5fc4a69167d09d2c0fe396ddc70c |
|
MD5 | 17a053c2df83ad0451daec6aa0008601 |
|
BLAKE2b-256 | 123f2775ef9dbc1813d9967fd25ba84da83519ba007ecefc13cbad324f30d56a |
File details
Details for the file sadice-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: sadice-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.9 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271b9f25e117d81836c13852837c9fb155589d407fb345b9fd7e87bb14d3ff43 |
|
MD5 | 7c4f9c729ed26ae746047da70c63937d |
|
BLAKE2b-256 | 9fedf566e4791f0c1eb1a2edc459d571ee93a4579fada122f4028c69d4d8f131 |