I want to add a method to an object that has already been instantiated.
The object is an instance of type vaderSentiment.vaderSentiment.SentimentIntensityAnalyzer
(Vader is a popular NLP model).
In order to get the predicted negative tone of a text I need to do the following:
# Import model
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
# Instantiate model
vader = SentimentIntensityAnalyzer()
# Get negative score
vader.polarity_scores('This text is awful').get('neg')
> 0.5
I would like to add a predict_proba
method such that vader.predict_proba('This text is awful')
would return 0.5
.
Based on this question I tried:
# Define function
predict_proba(self, text):
return self.polarity_scores(text).get('negative')
# Add method to instance
vader.predict_proba = predict_proba
# Attempt
vader.predict_proba('This text is awful')
Which throws:
TypeError: predict_proba() missing 1 required positional argument: 'text'