return self
def predict(self, X):
y_pred = []
for text in X:
assert isinstance(text, str)
text = self.__pad(self.__text_field.preprocess(text), True)
self.__model.eval()
text = [[self.__text_field.vocab.stoi[x] for x in text]]
x = Variable(torch.tensor(text))
x = x.cuda() if self.cuda and torch.cuda.is_available() else x
_, predicted = torch.max(self.__model(x), 1)
y_pred.append(self.__label_field.vocab.itos[predicted.data[0] + 1])
torch.cuda.empty_cache()
return y_pred