Using Sentiment Extraction with Teradata Python Package - Teradata Python Package

Teradata® Python Package User Guide

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-29
dita:mapPath
rkb1531260709148.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage
This example uses the sentiment extraction function SentimentExtractor() from the teradataml package to evaluate and classify a set of restaurant reviews.
  1. 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
  2. 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")
  3. 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.

  4. Call the sentiment extraction function.
    td_sentiment_extractor_out = SentimentExtractor(
        object = "dictionary",
        newdata = tddf_restaurant_reviews,
        level = "document",
        text_column = "review_text",
        accumulate = ["id"]
    )
  5. Inspect the result.
    print(td_sentiment_extractor_out.result)