Teradata R Package Function Reference | 17.00 - 17.00 - SentimentTrainer - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

Description

The TrainSentimentExtractor function trains a model, that is, takes training documents and outputs a maximum entropy classification model, which it installs on ML Engine. See Maximum Entropy for more information.

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.
Types: character

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).
Types: character

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
Types: character

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.
Types: character

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.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_sentiment_trainer_mle" which is a named list containing object of class "tbl_teradata".
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")
    
    # Create object(s) of class "tbl_teradata".
    # The sample dataset contains collection of user reviews for different products.
    sentiment_train <- tbl(con, "sentiment_train")
    
    # Example 1 - Build and output a maximum entropy classification model to a binary file.
    td_sentiment_trainer_mle_out <- td_sentiment_trainer_mle(data = sentiment_train,
                                                             text.column = "review",
                                                             sentiment.column = "category",
                                                             model.file = "sentimentmodel1.bin"
                                                             )