Description
This GitHub repository, `karpathy/pytorch-made`, offers a concise implementation of MADE (Masked Autoencoder Density Estimation) using PyTorch. The core concept behind MADE is to transform a standard auto-encoder into an autoregressive density model. This is achieved by strategically masking connections within a Multi-Layer Perceptron (MLP) and by ordering the input dimensions. Crucially, the model ensures that each output dimension depends only on input dimensions that appear earlier in the defined order.
Read More
Similar to other autoregressive models like char-rnn and pixel cnns, MADE facilitates very efficient likelihood evaluation, requiring only a single forward pass through the network. However, the process of sampling new data points is linear with respect to the number of dimensions. The original paper's implementation, while functional, was noted for its verbosity and reliance on Theano. This PyTorch version aims for simplicity and clarity, with the core logic contained in approximately 150 lines of code.
The repository includes examples demonstrating how to use the MADE model, particularly with the binarized MNIST dataset. Users can reproduce results from the original paper, such as training a 1-layer MLP to achieve a binary cross-entropy loss of 94.5. The examples also illustrate how to train larger model ensembles, leveraging weight sharing within a single MLP and averaging predictions at test time for improved performance, achieving a test loss of 79.3 with 10 orderings.
The primary class, `MADE`, is implemented in `made.py` and inherits from PyTorch's `nn.Module`, making it easy to integrate into larger neural network architectures. The instantiation process involves specifying input and output dimensions, hidden layer sizes, and the number of masks to use. The output dimension parameter is flexible, allowing for various output distributions such as Gaussian or binned softmax predictions. The simplest case, as demonstrated with binary predictions for MNIST, uses a single output parameter per input dimension.
- CategoryAI Models & LLMs
- Pricing ModelOpen source
- DeploymentCloud, Self-hosted
- PlatformsWeb
PyTorch MADE's Core Features
Implementation of Masked Autoencoder Density Estimation (MADE)
Built using PyTorch for ease of integration
Enables autoregressive density modeling
Efficient likelihood evaluation via single forward pass
Linear sampling complexity with respect to dimensions
Includes examples for binarized MNIST dataset
Supports training of model ensembles
Flexible output layer for various distributions
Concise codebase (~150 lines for core logic)
Masking of MLP connections for autoregression
Input dimension ordering for conditional dependencies
Getting Started with PyTorch MADE
Access model: Clone the GitHub repository.
Set up environment: Install PyTorch and other dependencies.
Integrate via API: Instantiate the `MADE` class from `made.py`.
Configure model: Specify input/output dimensions, hidden layers, and number of masks.
Train model: Use `run.py` script with specified dataset and parameters.
Evaluate likelihood: Perform a single forward pass.
Sample data: Execute sampling process linearly with dimensions.
PyTorch MADE's Use Cases
- Density Estimation
- Autoregressive Modeling
- Image Generation
- Probabilistic Modeling
- Machine Learning Research
- Data Compression








