Hi everyone! Preparing to deploy a trained model to AWS (code below). Not sure how to configure Model.eval() to take in simulated user-input and provide an output.

image719×92 4.72 KB

This is what I’ve got so far:
model.eval()
with torch.no_grad():
  y_val = model(inputColumns, inputNumColumns)
  loss = loss_function(y_val, test_outputs)
  print(f'Loss: {loss:.8f}')

inputColumns are categorical and inputNumColumns are numerical.
print(inputColumns.shape)
print(inputNumColumns.shape)
torch.Size([3, 1])
torch.Size([3, 1])

I am getting this error:
IndexError: index 1 is out of bounds for dimension 1 with size 1

Any help would be much appreciated!
This is the model:
class Model(nn.Module):

    def __init__(self, embedding_size, num_numerical_cols, output_size, layers, p=0.4):
        super().__init__()
        self.all_embeddings = nn.ModuleList([nn.Embedding(ni, nf) for ni, nf in embedding_size])
        #ni is number of embeddings
        #nf is the embedding dimensions(or number of features)
        self.embedding_dropout = nn.Dropout(p) # p is the dropout rate
        self.batch_norm_num = nn.BatchNorm1d(num_numerical_cols) #Only applied to the numerical column

        all_layers = []
        num_categorical_cols = sum((nf for ni, nf in embedding_size))
        input_size = num_categorical_cols + num_numerical_cols

        for i in layers:
            all_layers.append(nn.Linear(input_size, i))
            all_layers.append(nn.ReLU(inplace=False))
            all_layers.append(nn.BatchNorm1d(i))
            all_layers.append(nn.Dropout(p))
            input_size = i

        all_layers.append(nn.Linear(layers[-1], output_size))

        self.layers = nn.Sequential(*all_layers)

    def forward(self, x_categorical, x_numerical):
        embeddings = []
        for i,e in enumerate(self.all_embeddings):
            embeddings.append(e(x_categorical[:,i]))
        x = torch.cat(embeddings, 1)
        x = self.embedding_dropout(x)

        x_numerical = self.batch_norm_num(x_numerical) #Inputs the batch normalized numbers
        x = torch.cat([x, x_numerical], 1)
        x = self.layers(x)
        return x