Last active
August 29, 2019 14:51
-
-
Save prrao87/e3235c48fb924c92a6b36774d37bccff to your computer and use it in GitHub Desktop.
Example sentiment predictor class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleSentiment(Base): | |
"""Predict sentiment scores using using X classifier""" | |
def __init__(self, model_file: str=None) -> None: | |
super().__init__() # Inherit methods from Base class | |
def score(self, text: str) -> int: | |
"""Return a sentiment score on sample text, an integer in the range [1, 2, 3, 4, 5]""" | |
# Apply some sentiment scoring technique here | |
def predict(self, train_file: None, test_file: str, lower_case: bool) -> pd.DataFrame: | |
"""Return a Pandas DataFrame that applies the sentiment scoring method on each | |
row of the test set | |
""" | |
df = self.read_data(test_file, lower_case) | |
df['pred'] = df['text'].apply(self.score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment