Use Sentiment Extraction with Teradata Package for Python - Using Sentiment Extraction with Teradata Package for Python - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2022-01-14
dita:mapPath
bol1585763678431.ditamap
dita:ditavalPath
ayr1485454803741.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)