handy-nn
Delightful and useful neural networks models, including OrdinalRegressionLoss, etc.
Install
$ pip install handy-nn
Usage
from handy_nn import OrdinalRegressionLoss
# Initialize the loss function
num_classes = 5
criterion = OrdinalRegressionLoss(num_classes)
# For training
logits = model(inputs) # Shape: (batch_size, 1)
loss = criterion(logits, targets)
loss.backward() # shape: torch.Size([])
# To get class probabilities
probas = criterion.predict_probas(logits) # Shape: (batch_size, num_classes)
Shapes
| Variable | Shape |
|---|---|
logits |
(batch_size, 1) |
targets |
(batch_size,) or one-hot (batch_size, num_classes) |
loss |
torch.Size([]) |
probas |
(batch_size, num_classes) |
APIs
OrdinalRegressionLoss(num_classes, learn_thresholds=True, init_scale=2.0)
- num_classes
int: Number of ordinal classes (ranks) - learn_thresholds
bool=True: Whether to learn threshold parameters or use fixed ones, defaults toTrue. - init_scale
float=2.0: Scale for initializing thresholds, defaults to2.0
Creates the loss function for ordinal regression.
The goal of ordinal regression is to model the relationship between one or more independent variables and an ordinal dependent variable. It predicts the probability that an observation falls into a specific ordinal category or a category higher than a certain threshold. This is particularly useful in fields like social sciences, medicine, and customer surveys where outcomes are often ordinal.
TrendAwareLoss()
criterion = TrendAwareLoss()
loss = criterion(logits, targets)
loss.backward()
TrendAwareLoss penalizes "too-early / too-late" misclassification inside a label segment more heavily by multiplying per-sample cross-entropy with the segment remaining-length weight.
This loss function is useful for those situations where misclassification leads to an indirect loss, such as financial trading, etc.
License
Metadata
Release files for handy-nn 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| handy_nn-0.0.6.tar.gz | 6.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| handy_nn-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.0 kB
Release files / handy_nn-0.0.6.tar.gz
| Download URL | handy_nn-0.0.6.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9ba501f4be4a7d3abff83a6c8885b0519e91037992ad1b799fc623fb7ec62d4
|
|
BLAKE2b-256 checksum How to use checksums |
ee6c236adbdbfa5ccb97842190813255c0c8e3a62e7fac09ed3c384b47c316e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / handy_nn-0.0.6-py3-none-any.whl
| Download URL | handy_nn-0.0.6-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab78f85dc101ed59ef913a76bcbb808f5aa0a86ae8dd1063efa1083423f2876b
|
|
BLAKE2b-256 checksum How to use checksums |
c40c1403ef048f9da11d752f8d02600b721ae8b5593d493dae5a9e2e0519a62a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Security for handy-nn 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.