I designed a classifier for the customer review dataset. I am getting high training as well as test accuracy. But when I am using the pre-trained model for classifying a single sentence (checked a sentence from both training and test set), the model is predicting the wrong answer with high probability.
This is my code-
def inference(text):
  doc_idx = [fields[0][1].vocab.stoi[token] for token in text]
  doc_idx_tensor = torch.tensor([doc_idx]).cuda()
  len_tensor = torch.tensor([len(doc_idx)])
  with torch.no_grad():
    model = torch.load(PATH)
    model.eval()
    prediction = model(doc_idx_tensor, len_tensor)
    label = torch.argmax(prediction)
    print(prediction , label)
  return

I don’t know what to do. Any help will be highly appreciated. Thanks in advance.
Here is an example -
text - ‘the product is not good’
output - [[-9.544 17.824]] tensor(1, device='cuda:0')