# Autoencoders: Where does the encoder end and the decoder begin?

Consider a simple Autoencoder neural net:

from torch import nn

class AE(nn.Module):
def __init__(self, x_dim, z_dim, h_dim=42):
super().__init__()
self.encoder = nn.Sequential(
nn.Linear(dim_in, dim_h),
nn.ReLU(),
nn.Linear(dim_h, z_dim)
)
self.decoder = nn.Sequential(
nn.Linear(z_dim, h_dim),
nn.ReLU(),
nn.Linear(h_dim, x_dim),
)

def forward(self, x):
z = self.encoder(x)
x = self.decoder(z)
return x


In popular literature, it is generally implied that the output of AE.encoder is solely responsible for encoding whereas AE.decoder is solely responsible for the decoding. Why is that?

If we consider that encoding is a more complex task than decoding, there is no actual guarantee that the network won't use the first three layers for encoding and only the last for decoding (or vice versa). This might especially be the case if we consider asymmetrical autoencoder architectures.

• The encoder ends at the layer where the representation is most compact, i.e. at the bottleneck, because it wouldn't make sense to have a narrower bottleneck within the encoder or within the decoder. Aug 9 at 16:19

In the case of the VAE, the situation is even clearer, I would say, because the VAE was formulated to model a specific graphical model, where $$x$$, the (original/reconstructed) input depends on a latent variable $$z$$, although, even in this case, the encoder and decoder are trained jointly with the ELBO, which contains 2 terms, one for the encoder and the other for the decoder. It's true that the optimization of this objective takes into account both terms, but, again, the convention is to consider the encoder the part that produces the latent vector.