Spacecutter Lightning
A PyTorch Lightning Callback for Spacecutter.
Installation
pip install spacecutter-lightning
Usage
import torch
import pytorch_lightning as pl
from spacecutter_lightning import ClipCutpoints
from spacecutter import OrdinalLogisticHead, CumulativeLinkLoss
num_classes = 10
num_features = 5
hidden_size = 10
size = 200
x = torch.randn(size, num_features)
y = torch.randint(0, num_classes, (size, 1))
train_dataloader = torch.utils.data.DataLoader(
torch.utils.data.TensorDataset(x, y),
)
model = torch.nn.Sequential(
torch.nn.Linear(num_features, hidden_size),
torch.nn.ReLU(),
torch.nn.Linear(hidden_size, 1),
OrdinalLogisticHead(num_classes),
)
loss_fn = CumulativeLinkLoss()
class LitModel(pl.LightningModule):
def __init__(self):
super().__init__()
self.model = model
self.loss_fn = loss_fn
def forward(self, x):
return self.model(x)
def training_step(self, batch, batch_idx):
x, y = batch
y_hat = self(x)
loss = self.loss_fn(y_hat, y)
self.log("train_loss", loss)
return loss
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=1e-3)
trainer = pl.Trainer(
callbacks=[ClipCutpoints()],
max_epochs=10,
)
trainer.fit(LitModel(), train_dataloader)
Metadata
Release files for spacecutter-lightning 1.0.1
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 | Actions |
|---|---|---|---|---|
| spacecutter_lightning-1.0.1.tar.gz | 2.1 kB | Without provenance | Details for spacecutter_lightning-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spacecutter_lightning-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for spacecutter_lightning-1.0.1-py3-none-any.whl |
Total release size: 4.8 kB
Release files / spacecutter_lightning-1.0.1.tar.gz
| Download URL | spacecutter_lightning-1.0.1.tar.gz |
|---|---|
| Size | 2.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77db2120565ef53e3cd4f92cbadda0ed4a07d7eb96cf60d587bfc5325d6ac690
|
|
BLAKE2b-256 checksum How to use checksums |
0eceddadd5ddc2aabe3c6bf89187612a4768ed2b3c007da3a7969d34d6d1df3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / spacecutter_lightning-1.0.1-py3-none-any.whl
| Download URL | spacecutter_lightning-1.0.1-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4bec94780bd31052ef491897eaa54b004cabfa8b5981e5c0e40da8a7178be98b
|
|
BLAKE2b-256 checksum How to use checksums |
f89fa374a4cab2668a9710705a7272077aad1af5c417d583c902f7169526a04b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for spacecutter-lightning 1.0.1
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.