Skip to content
ml-recall

#tied-weights

1 question from Autoencoders & VAEs

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

mediumAI-checkedAutoencoders & VAEs

This autoencoder ties its decoder weights to the transpose of its encoder weights. How many trainable parameters does it have?

import torch
import torch.nn as nn

class TiedAutoencoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.encoder = nn.Linear(784, 128)
        self.decoder_bias = nn.Parameter(torch.zeros(784))

    def forward(self, x):
        codings = torch.relu(self.encoder(x))
        return torch.sigmoid(codings @ self.encoder.weight + self.decoder_bias)

print(sum(p.numel() for p in TiedAutoencoder().parameters()))

An integer, without separators