Learnergy: Energy-based Machine Learners
Learnergy provides PyTorch implementations of Restricted Boltzmann Machines (RBMs) and Deep Belief Networks (DBNs) for unsupervised feature learning, generative modeling, and classification. It also includes dataset adapters, image-quality metrics, and visualization helpers.
Installation
Learnergy requires Python 3.11 or newer. Add it to a project managed by uv with:
uv add learnergy
Add the optional torchvision dependency to run the examples:
uv add "learnergy[examples]"
For a consumer installation in an existing Python environment, pip is also supported:
pip install learnergy
pip install "learnergy[examples]"
Quick start
import torch
from torch.utils.data import TensorDataset
from learnergy.models.bernoulli import RBM
samples = torch.bernoulli(torch.rand(1_024, 784))
targets = torch.zeros(1_024)
dataset = TensorDataset(samples, targets)
model = RBM(n_visible=784, n_hidden=128, learning_rate=0.1)
mse, pseudo_likelihood = model.fit(dataset, batch_size=128, epochs=5)
reconstruction_mse, reconstructed = model.reconstruct(dataset)
Stack RBMs into a DBN:
from learnergy.models.deep import DBN
model = DBN(
model=("gaussian", "sigmoid"),
n_visible=784,
n_hidden=(256, 128),
steps=(1, 1),
learning_rate=(0.01, 0.01),
momentum=(0, 0),
decay=(0, 0),
temperature=(1, 1),
)
model.fit(dataset, batch_size=128, epochs=(5, 5))
Available models
| Family | Models |
|---|---|
| Bernoulli | RBM, ConvRBM, DiscriminativeRBM, HybridDiscriminativeRBM, DropoutRBM, DropConnectRBM, EDropoutRBM |
| Gaussian | GaussianRBM, GaussianReluRBM, GaussianSeluRBM, VarianceGaussianRBM, GaussianConvRBM |
| Extra | SigmoidRBM |
| Deep | DBN, ConvDBN, ResidualDBN |
The learnergy.core.Dataset, learnergy.math, and learnergy.visual modules
remain available for array-backed datasets, SSIM/scaling helpers, convergence
plots, image mosaics, and tensor rendering.
See examples/applications for complete training and
classification programs.
Numerical behavior
When enabled, Gaussian normalization uses statistics from the current batch, not stored training statistics. Batches of two or more samples use sample standard deviation; a singleton batch is centered to zero. Representations therefore depend on batch composition. Disable the corresponding normalization flags when supplying externally standardized features.
VarianceGaussianRBM.sigma is a learnable scale: the effective visible variance
is sigma**2 plus a dtype-dependent epsilon. Its visible_sampling method
returns conditional means followed by sampled states, and Gibbs sampling uses
those states.
Gaussian convolutional representations support gradient-based fine-tuning.
Use torch.no_grad() when extracting frozen features without an autograd graph.
The corrected variance-Gaussian sampling and stabilized likelihood calculations can change training trajectories, including with a fixed random seed.
Development
The repository uses uv for reproducible environments and packaging:
uv sync --locked
uv run pytest
uv build
Citation
@misc{roder2020learnergy,
title={Learnergy: Energy-based Machine Learners},
author={Mateus Roder and Gustavo Henrique de Rosa and João Paulo Papa},
year={2020},
eprint={2003.07443},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
Support
Open an issue for bug reports and questions.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file learnergy-2.0.1.tar.gz.
File metadata
- Download URL: learnergy-2.0.1.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5e211417b0af8a2f1f199907421d60619cd49be755f6522683031d1ceb105b7
|
|
| MD5 |
e930337aaf63c4bb8571ebea81cbb98b
|
|
| BLAKE2b-256 |
177945c43fcafa2433ea53f3f45fcc1699f9e8af5030587d3a7637278702d25f
|
File details
Details for the file learnergy-2.0.1-py3-none-any.whl.
File metadata
- Download URL: learnergy-2.0.1-py3-none-any.whl
- Upload date:
- Size: 40.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64284659ff04c9ebe3d71684aed58fdbd1a21d6ddaea90d147d10157f6390d86
|
|
| MD5 |
e23a3b81dbce08e72ddc09accb562928
|
|
| BLAKE2b-256 |
ee0967dfe422615bd63025ffdac1bd0a5da27becbb6e5c6f57ae2126011da736
|