Teradata R Package Function Reference | 17.00 - 17.00 - LDAInference - 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 LDAInference function uses the model tbl_teradata generated by the function LDATrainer (td_lda_mle) to infer the topic distribution in a set of new documents. You can use the distribution for tasks such as classification and clustering.

Usage

  td_lda_inference_mle (
      object = NULL,
      data = NULL,
      docid.column = NULL,
      word.column = NULL,
      count.column = NULL,
      out.topicnum = "all",
      out.topicwordnum = "none",
      data.sequence.column = NULL,
      object.sequence.column = NULL
  )

Arguments

object

Required Argument.
Specifies the model tbl_teradata generated by td_lda_mle.
This argument can accept either a tbl_teradata or an object of "td_lda_mle" class.

data

Required Argument.
Specifies the tbl_teradata that contains the new documents.

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

count.column

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

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 "out.topicnum" must be a positive integer enclosed in quotes or "all".
The value "all" specifies all topics and their weights.
Default Value: "all"
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 integer enclosed in quotes or "all" or "none".
The value "all" specifies all topic words and their topic identifiers.
The value "none" specifies no topic words or topic identifiers.
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)

object.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "object". 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_inference_mle" which is a named list containing objects of class "tbl_teradata".
Named list members can be referenced directly with the "$" operator using following names:

  1. doc.distribution.data

  2. output

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("ldainference_example", "complaints_testtoken")
    loadExampleData("lda_example","complaints_traintoken")
    
    # Create object(s) of class "tbl_teradata".
    complaints_testtoken <- tbl(con, "complaints_testtoken")
    complaints_traintoken <- tbl(con, "complaints_traintoken")
    
    # Example 1 - This example uses the model generated by the td_lda_mle() 
    # function to infer the topic distribution in a set of new documents.
    td_lda_out <- td_lda_mle(data=complaints_traintoken,
                             docid.column='doc_id',
                             word.column='token',
                             topic.num=5,
                             alpha=0.1,
                             eta=0.1,
                             maxiter=50,
                             convergence.delta=0.0001,
                             seed=2,
                             out.topicnum='all',
                             out.topicwordnum='none'
                            )
    td_lda_inference_mle_out <- td_lda_inference_mle(object = td_lda_out,
                                                     data = complaints_testtoken,
                                                     docid.column = "doc_id",
                                                     word.column = "token",
                                                     out.topicnum = '5',
                                                     out.topicwordnum = '5'
                                                     )
   
    # Example 2 - Default case without any optional arguments.
    td_lda_inference_mle_out <- td_lda_inference_mle(object = td_lda_out,
                                                     data = complaints_testtoken,
                                                     docid.column = "doc_id",
                                                     word.column = "token"
                                                     )
                                                     
    # Example 3 - Example with "count.column" argument and 'model.table' tbl_teradata of 
    # "td_lda_out" object.
    td_lda_inference_mle_out <- td_lda_inference_mle(data=complaints_testtoken,
                                                     object=td_lda_out$model.table,
                                                     docid.column='doc_id',
                                                     word.column='token',
                                                     count.column='frequency',
                                                     out.topicwordnum='none'
                                                    )