Teradata R Package Function Reference - LDA - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The LDA td_lda_mle function uses training data and parameters to build a topic model, using an unsupervised method to estimate the correlation between the topics and words according to the topic number and other parameters. Optionally, the function generates the topic distributions for each training document.

Usage

  td_lda_mle (
      data = NULL,
      topic.num = NULL,
      docid.column = NULL,
      word.column = NULL,
      alpha = 0.1,
      eta = 0.1,
      count.column = NULL,
      maxiter = 50,
      convergence.delta = 1.0E-4,
      seed = NULL,
      out.topicnum = "all",
      out.topicwordnum = "none",
      initmodeltaskcount = NULL,
      data.sequence.column = NULL
  )

Arguments

data

Required Argument.
Specifies the name of the tbl_teradata or view that contains the new documents.

topic.num

Required Argument.
Specifies the number of topics for all the documents in the input table, an INTEGER value in the range [2, 1000], both lower and upper bounds inclusive.
Types: numeric

docid.column

Required Argument.
Specifies the name of the input column that contains the document identifiers.
Types: character

word.column

Required Argument.
Specifies the name of the input column that contains the words (one word in each row).
Types: character

alpha

Optional Argument.
Specifies a hyperparameter of the model, the prior smooth parameter for the topic distribution over documents. As alpha decreases, fewer topics are associated with each document.
Default Value: 0.1.
Types: numeric

eta

Optional Argument.
Specifies a hyperparameter of the model, the prior smooth parameter for the word distribution over topics. As eta decreases, fewer words are associated with each topic.
Default Value: 0.1.
Types: numeric

count.column

Optional Argument.
Specifies the name of the input column that contains the count of the corresponding word in the row.
Types: character

maxiter

Optional Argument.
Specifies the maximum number of iterations to perform if the model does not converge, a positive INTEGER value.
Default Value: 50.
Types: numeric

convergence.delta

Optional Argument.
Specifies the convergence delta of log perplexity, a NUMERIC value in the range (0.0, 1.0), both lower and upper bounds exclusive.
Default Value: 1.0E-4.
Types: numeric

seed

Optional Argument.
Specifies the seed with which to initialize the model, a numeric value. Given the same seed, cluster configuration, and input table, the function generates the same model. By default, the function initializes the model randomly.
Types: numeric

out.topicnum

Optional Argument.
Specifies the number of top-weighted topics and their weights to include in the output tbl_teradata for each training document. The value topics must be a positive numeric value and the value should be enclosed in quotes. The default value "all" specifies all topics and their weights.
Types: character

out.topicwordnum

Optional Argument.
Specifies the number of top topic words and their topic identifiers to include in the output tbl_teradata for each training document. The value "out.topicwordnum" must be a positive numeric value and the value should be enclosed in quotes. The value "all" specifies all topic words and their topic identifiers. The default value "none" specifies no topic words or topic identifiers.
Types: character

initmodeltaskcount

Optional Argument.
Specifies the number of vWorkers that are adopted to generate initalized model. It must be a positive INTEGER value.
By default, all the available vWorkers are used to initialize the model.
Types: numeric

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_lda_mle" which is a named list containing Teradata tbl objects.
Named list members can be referenced directly with the "$" operator using following names:

  1. model.table

  2. doc.distribution.data

  3. output

.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("lda_example", "complaints_traintoken")
    
    # Create remote tibble objects.
    complaints_traintoken <- tbl(con, "complaints_traintoken")
    
    # Example 1 - This function uses training data and parameters from complaints_traintoken to build a topic model.
    td_lda_out <- td_lda_mle(data = complaints_traintoken,
                         topic.num = 5,
                         docid.column = "doc_id",
                         word.column = "token",
                         count.column = "frequency",
                         maxiter = 30,
                         convergence.delta = 1e-3,
                         seed = 2
                        )