# Encoder decoder model

Hi there! I have a simple encoder-decoder model which inputs a 9 * 8 * 4 matrix and outputs a similar size matrix from the decoder.

import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np

criterion = nn.MSELoss()
domains = 9
batch = 8

class MyModel(nn.Module):
def init(self):
super().init()

``````    self.encoder = nn.Sequential(
nn.Linear(4 , 8),
nn.ReLU(),
#nn.Linear(8,4)
)

#self.decoder = nn.Linear(batch_size,feats)

self.decoders = nn.ModuleList()
for _ in range(9):
self.decoders.append(nn.Linear(8, 4))

def forward(self, inputs):

z = []
# for idx, enc in enumerate(self.encoders):
#     out.append(enc(inputs[idx])) # 1 * 64 * 4 ## each domain

for x_ in inputs: # assuming x is a list of tensors
z.append(self.encoder(x_))

z = torch.stack(z)

outs = []
for idx, dec in enumerate(self.decoders):
outs.append(dec(z[idx]))

outs = torch.stack(outs)
print ("outs shape:", ((outs.shape)))
return outs
``````

model = MyModel()

inputs = [torch.randn(8, 4) for _ in range(9)]

inputs_shape = torch.stack(inputs) # to check the shape of inputs

print (“INPUTS:”, inputs_shape.shape)

outs = model(inputs)

But, I have a doubt if the encoder implementation is correct. Since the purpose of encoder is to project to a lower dimension, in my case when I am multiplying with a linear layer 4 * 8, with input 8 * 4, the result is actually an 8 * 8 dimension matrix. Can you plz suggest how should I correct this?