river-torch is a Python library for online deep learning. River-torch's ambition is to enable online machine learning for neural networks. It combines the river API with the capabilities of designing neural networks based on PyTorch.
💈 Installation
pip install river-torch
or
pip install "river[torch]"
You can install the latest development version from GitHub as so:
pip install https://github.com/online-ml/river-torch/archive/refs/heads/master.zip
🍫 Quickstart
We build the development of neural networks on top of the river API and refer to the rivers design principles. The following example creates a simple MLP architecture based on PyTorch and incrementally predicts and trains on the website phishing dataset. For further examples check out the Documentation.
Classification
>>> from river import metrics, datasets, preprocessing, compose
>>> from river_torch import classification
>>> from torch import nn
>>> from torch import optim
>>> from torch import manual_seed
>>> _ = manual_seed(42)
>>> class MyModule(nn.Module):
... def __init__(self, n_features):
... super(MyModule, self).__init__()
... self.dense0 = nn.Linear(n_features, 5)
... self.nonlin = nn.ReLU()
... self.dense1 = nn.Linear(5, 2)
... self.softmax = nn.Softmax(dim=-1)
...
... def forward(self, X, **kwargs):
... X = self.nonlin(self.dense0(X))
... X = self.nonlin(self.dense1(X))
... X = self.softmax(X)
... return X
>>> model_pipeline = compose.Pipeline(
... preprocessing.StandardScaler(),
... classification.Classifier(module=MyModule, loss_fn='binary_cross_entropy', optimizer_fn='adam')
... )
>>> dataset = datasets.Phishing()
>>> metric = metrics.Accuracy()
>>> for x, y in dataset:
... y_pred = model_pipeline.predict_one(x) # make a prediction
... metric = metric.update(y, y_pred) # update the metric
... model_pipeline = model_pipeline.learn_one(x,y) # make the model learn
>>> print(f"Accuracy: {metric.get():.4f}")
Accuracy: 0.6728
Anomaly Detection
>>> from river_torch.anomaly import Autoencoder
>>> from river import metrics
>>> from river.datasets import CreditCard
>>> from torch import nn
>>> import math
>>> from river.compose import Pipeline
>>> from river.preprocessing import MinMaxScaler
>>> dataset = CreditCard().take(5000)
>>> metric = metrics.ROCAUC(n_thresholds=50)
>>> class MyAutoEncoder(nn.Module):
... def __init__(self, n_features, latent_dim=3):
... super(MyAutoEncoder, self).__init__()
... self.linear1 = nn.Linear(n_features, latent_dim)
... self.nonlin = nn.LeakyReLU()
... self.linear2 = nn.Linear(latent_dim, n_features)
... self.sigmoid = nn.Sigmoid()
...
... def forward(self, X, **kwargs):
... X = self.linear1(X)
... X = self.nonlin(X)
... X = self.linear2(X)
... return self.sigmoid(X)
>>> ae = Autoencoder(module=MyAutoEncoder, lr=0.005)
>>> scaler = MinMaxScaler()
>>> model = Pipeline(scaler, ae)
>>> for x, y in dataset:
... score = model.score_one(x)
... model = model.learn_one(x=x)
... metric = metric.update(y, score)
...
>>> print(f"ROCAUC: {metric.get():.4f}")
ROCAUC: 0.7447
🏫 Affiliations
Metadata
Release files for river-torch 0.1.2
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 |
|---|---|---|---|---|
| river_torch-0.1.2.tar.gz | 23.0 kB | Without provenance | Details for river_torch-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| river_torch-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for river_torch-0.1.2-py3-none-any.whl |
Total release size: 57.3 kB
Release files / river_torch-0.1.2.tar.gz
| Download URL | river_torch-0.1.2.tar.gz |
|---|---|
| Size | 23.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc50cd7c4d2a330c21559454434baf4cdd65a2b472e0f0d5a38f64d29231a1da
|
|
BLAKE2b-256 checksum How to use checksums |
2a0bb2fe0b3b3d3461b0bf9393e3cb376342194e61d71b82904d6e837e809234
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Release files / river_torch-0.1.2-py3-none-any.whl
| Download URL | river_torch-0.1.2-py3-none-any.whl |
|---|---|
| Size | 34.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5834665fe03b659c22e330463940db45c381956ea1d2ab33cdefd6529e15dde9
|
|
BLAKE2b-256 checksum How to use checksums |
7844c64629a55cd118ed6dbf161ad4bef9f58073f7a47f5440c6e65315e9882b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Security for river-torch 0.1.2
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.