Teradata R Package Function Reference - LDAInference - 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 td_lda_inference_mle function uses the model tbl_teradata generated by the function 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 name of the model tbl_teradata generated by the function td_lda_mle.

data

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

docid.column

Required Argument.
Specifies the name of the input column that contains the document identifiers.
Types: character OR vector of Strings (character)

word.column

Required Argument.
Specifies the name of the input column that contains the words (one word in each row).
Types: character OR vector of Strings (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 OR vector of Strings (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 topics must be a positive integer. The default value, "all", specifies all topics and their weights.
Types: character.
Permitted Values: "all", positive integer enclosed in quotes.

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. The value "all" specifies all topic words and their topic identifiers. The default value, "none", specifies no topic words or topic identifiers.
Types: character.
Permitted Values: "all", "none", positive integer enclosed in quotes.

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 Teradata tbl objects.
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 remote tibble objects.
    complaints_testtoken <- tbl(con, "complaints_testtoken")
    complaints_traintoken <- tbl(con, "complaints_traintoken")
    
    # Example 1 - This function td_lda_inference_mle uses the model table from td_lda_mle 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 args                                           
    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.
    td_lda_inference_mle_out <- td_lda_inference_mle(data=complaints_testtoken,
                                                     object=td_lda_out,
                                                     docid.column='doc_id',
                                                     word.column='token',
                                                     count.column='frequency',
                                                     out.topicwordnum='none'
                                                    )