Teradata R Package Function Reference - 16.20 - SentimentTrainer - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

The SentimentTrainer function trains a model; that is, takes training documents and outputs a maximum entropy classification model, which it installs on ML Engine. For information about maximum entropy, see https://en.wikipedia.org/wiki/Maximum_entropy method.

Usage

  td_sentiment_trainer_mle (
      data = NULL,
      text.column = NULL,
      sentiment.column = NULL,
      language = "en",
      model.file = NULL,
      data.sequence.column = NULL
  )

Arguments

data

Required Argument.
Specifies the name of the tbl_teradata that contains the training data.

text.column

Required Argument.
Specifies the name of the input tbl_teradata column that contains the training data.

sentiment.column

Required Argument.
Specifies the name of the input tbl_teradata column that contains the sentiment values, which are "POS" (positive), "NEG" (negative), and "NEU" (neutral).

language

Optional Argument.
Specifies the language of the training data: "en" (English), "zh_CN" (Simplified Chinese), "zh_TW" (Traditional Chinese).
Default Value: "en"
Permitted Values: en, zh_CN, zh_TW

model.file

Required Argument.
Specifies the name of the file to which the function outputs the model. If a file of the same name already exists, it gets overwritten.

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_sentiment_trainer_mle" which is a named list containing Teradata tbl object. Named list member can be referenced directly with the "$" operator using name: output.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("sentimenttrainer_example", "sentiment_train")
    
    # The sample dataset contains collection of user reviews for different products.
    sentiment_train <- tbl(con, "sentiment_train")
    
    # Example 1 - Build a model and output a maximum entropy classification 
    # model to a binary file
    td_sentiment_trainer_out <- td_sentiment_trainer_mle(data = sentiment_train,
                                                     text.column = "review",
                                                     sentiment.column = "category",
                                                     model.file = "sentimentmodel1.bin"
                                                     )