The issue is model was trained using a glove vector and the embedding dimension was dynamically set using that. That is what I was trying to avoid by reloading the complete model. I was getting error -
RuntimeError: Error(s) in loading state_dict for SentimentNet:
size mismatch for embedding.weight: copying a param with shape torch.Size([1259, 300]) from checkpoint, the shape in current model is torch.Size([1000, 400]).
size mismatch for lstm.weight_ih_l0: copying a param with shape torch.Size([2048, 300]) from checkpoint, the shape in current model is torch.Size([2048, 400]).
I retried setting the initialization parameters -
model_params = {‘weight_matrix’: None,
‘output_size’: 1,
‘hidden_dim’: 512,
‘n_layers’: 2,
‘dropout_prob’: 0.001,
‘vocab_size’ :1259,
‘embedding_dim’: 300
}
model = SentimentNet(**model_params)
model = model.load_state_dict(torch.load(‘state_dict.pt’, map_location=device))
model.eval()

But now I get this error -
model.eval()
AttributeError: ‘_IncompatibleKeys’ object has no attribute ‘eval’