Skip to main content

Learnergy: Energy-based Machine Learners

Latest release CI DOI License

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

Follow the coding conventions when changing the library or its examples.

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

learnergy-2.0.2.tar.gz (40.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

learnergy-2.0.2-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file learnergy-2.0.2.tar.gz.

File metadata

  • Download URL: learnergy-2.0.2.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for learnergy-2.0.2.tar.gz
Algorithm Hash digest
SHA256 b6a6522e1fee06487f961a6dcfc367bdf033353fbc698b0ec65d612e86b3bf10
MD5 3fb46fe7b0536d6dab8fd338960df123
BLAKE2b-256 d2569357b81670a7591d19404c8a21dfe438f461736e0b85eb1e0f305b67d038

See more details on using hashes here.

File details

Details for the file learnergy-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: learnergy-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for learnergy-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a490309a77ce0c7f46333c4509531807b1e44c6a9f79c3a0bf381315a8f4ec1
MD5 777adfc93a8f25a109b54b41d41aaaf7
BLAKE2b-256 145107847e32ab7fb6f57f042b25eeebb361bae53e05c2130935410bdb0e52a3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 files

2.0.1

2 files

2.0.0

2 files

1.2.0

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page