I haven’t implemented such a function. I would advice against changing the model class to add a predict function. What I recommend is to write a separate
predict_sentiment(model, text) function that takes in a model and a text string to produce the output.
If you are willing to use a notebook instead of implementing a function, check this file I added to the github repo.
The only thing I changed was the line to load the dataset using the processor. Instead, I manually created an
The output you are looking for is the
preds variable in the eval block. However, that is the direct output from the model. If you need probabilities as in your example output, you can apply a softmax to that output as I have done in the notebook.
If you want, you can wrap the code in that file inside a function.
Note: This is a pretty hacky solution.