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 InputExample.

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.

AI researcher, avid reader, fantasy and Sci-Fi geek, and fan of the Oxford comma. www.linkedin.com/in/t-rajapakse/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store