Hello, I have a file where i trained a BERT model and saved the state_dict of the model. How can i load the model in another .py file and use it to predict the polarity some keyboard input sentences? I have the below code :
import torch
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-uncased', do_lower_case=True)
model.load_state_dict(torch.load('model.pt'))
model.eval()
inputs = tokenizer("I do not feel good today.", return_tensors="pt")
outputs = model(**inputs)
print(outputs)
Assuming that I do not feel good today.
is the sentence entered from keyboard, i would like the model to return 0 if it is negative or 1 if it is positive. How can I define the model so it will not be linked to the py file where I trained the model? I tried the below but that will start the training again( BertClassifier is the class where i trained the model) :
from bert import BertClassifier
model = BertClassifier(freeze_bert=False)