This example uses the sentiment extraction function SentimentExtractor() from the teradataml package to evaluate and classify a set of restaurant reviews.
- Import the required modules.
from teradataml.analytics.mle.SentimentExtractor import SentimentExtractor from teradataml.dataframe.dataframe import DataFrame from teradataml.data.load_example_data import load_example_data
- If the input table "restaurant_reviews" does not already exist, create the table and load the datasets into the table.
load_example_data("sentimentextractor", "restaurant_reviews")
- Create a teradataml DataFrame from the input data table "restaurant_reviews".
tddf_restaurant_reviews = DataFrame("restaurant_reviews")
This example uses the default values for many arguments of the SentimentExtractor() function.One of those is the object argument which specifies the source used to assign sentiment values to words. The default value of the object argument is a built-in dictionary based on the WordNet lexical database.
- Call the sentiment extraction function.
td_sentiment_extractor_out = SentimentExtractor( object = "dictionary", newdata = tddf_restaurant_reviews, level = "document", text_column = "review_text", accumulate = ["id"] )
- Inspect the result.
print(td_sentiment_extractor_out.result)