MCPcopy Index your code
hub / github.com/alanjeffares/discreteVAE

github.com/alanjeffares/discreteVAE @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
10 symbols 46 edges 4 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

An Introduction to Discrete Variational Autoencoders

This is a simple implementation of a discrete variational autoencoder corresponding to our tutorial on arxiv. The code follows the summarized recipe provided in Section 8 of the text. Specifically, it trains a simple MLP architecture with ReLU activations for both the encoder and decoder on a binarized version of the MNIST dataset. The latent space consists of 4 categorical latent variables with 8 categories each. Stochastic gradient descent and the Adam optimizer is used to maximize the evidence lower bound (ELBO) of the training data. The only package requirements are pytorch and matplotlib.

To run the main training script, run the following command.

python main.py

This should produce a plot similar to this showing the ELBO increasing throughout training.

alt text

Once trained, we can further explore the model by visualizing some of its generated samples. The following command runs some basic visualizations.

python visualize.py

This produces two figures. Firstly, it passes five test examples through the autoencoder showing probabilities and samples of both the input images and the reconstruction from the VAE.

alt text

Secondly, it visualizes a subset of the latent space. This is achieved by creating a single latent sample and showing the output produced as we augment each of the latent variables individually and pass the resulting latent sample through the decoder. The first row, labeled "Cat 1", is our baseline latent and we plot the mode of the distribution of the corresponding image to each latent.

alt text

Core symbols most depended-on inside this repo

decode
called by 4
model.py
encode
called by 3
model.py
sample
called by 3
model.py
get_dataloaders
called by 2
helpers.py
plot_elbo
called by 1
helpers.py
train
called by 1
main.py
test
called by 1
main.py
main
called by 1
main.py

Shape

Function 5
Method 4
Class 1

Languages

Python100%

Modules by API surface

model.py5 symbols
main.py3 symbols
helpers.py2 symbols

For agents

$ claude mcp add discreteVAE \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact