Class LocalLDAModel
Object
org.apache.spark.mllib.clustering.LDAModel
org.apache.spark.mllib.clustering.LocalLDAModel
- All Implemented Interfaces:
Serializable
,Saveable
Local LDA model.
This model stores only the inferred topics.
param: topics Inferred topics (vocabSize x k matrix).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionscala.Tuple2<int[],
double[]>[] describeTopics
(int maxTermsPerTopic) Return the topics described by weighted terms.Concentration parameter (commonly named "alpha") for the prior placed on documents' distributions over topics ("theta").long
getSeed()
Random seed for cluster initialization.int
k()
Number of topicsstatic LocalLDAModel
load
(SparkContext sc, String path) double
logLikelihood
(JavaPairRDD<Long, Vector> documents) Java-friendly version oflogLikelihood
double
logLikelihood
(RDD<scala.Tuple2<Object, Vector>> documents) Calculates a lower bound on the log likelihood of the entire corpus.double
logPerplexity
(JavaPairRDD<Long, Vector> documents) Java-friendly version oflogPerplexity
double
logPerplexity
(RDD<scala.Tuple2<Object, Vector>> documents) Calculate an upper bound on perplexity.void
save
(SparkContext sc, String path) Save this model to the given path.setSeed
(long seed) Set the random seed for cluster initialization.double
Concentration parameter (commonly named "beta" or "eta") for the prior placed on topics' distributions over terms.topicDistribution
(Vector document) Predicts the topic mixture distribution for a document (often called "theta" in the literature).topicDistributions
(JavaPairRDD<Long, Vector> documents) Java-friendly version oftopicDistributions
topicDistributions
(RDD<scala.Tuple2<Object, Vector>> documents) Predicts the topic mixture distribution for each document (often called "theta" in the literature).topics()
Inferred topics, where each topic is represented by a distribution over terms.int
Vocabulary size (number of terms or terms in the vocabulary)Methods inherited from class org.apache.spark.mllib.clustering.LDAModel
describeTopics
-
Method Details
-
load
-
topics
-
docConcentration
Description copied from class:LDAModel
Concentration parameter (commonly named "alpha") for the prior placed on documents' distributions over topics ("theta").This is the parameter to a Dirichlet distribution.
- Specified by:
docConcentration
in classLDAModel
- Returns:
- (undocumented)
-
topicConcentration
public double topicConcentration()Description copied from class:LDAModel
Concentration parameter (commonly named "beta" or "eta") for the prior placed on topics' distributions over terms.This is the parameter to a symmetric Dirichlet distribution.
- Specified by:
topicConcentration
in classLDAModel
- Returns:
- (undocumented)
-
k
public int k()Description copied from class:LDAModel
Number of topics -
vocabSize
public int vocabSize()Description copied from class:LDAModel
Vocabulary size (number of terms or terms in the vocabulary) -
topicsMatrix
Description copied from class:LDAModel
Inferred topics, where each topic is represented by a distribution over terms. This is a matrix of size vocabSize x k, where each column is a topic. No guarantees are given about the ordering of the topics.- Specified by:
topicsMatrix
in classLDAModel
- Returns:
- (undocumented)
-
describeTopics
public scala.Tuple2<int[],double[]>[] describeTopics(int maxTermsPerTopic) Description copied from class:LDAModel
Return the topics described by weighted terms.- Specified by:
describeTopics
in classLDAModel
- Parameters:
maxTermsPerTopic
- Maximum number of terms to collect for each topic.- Returns:
- Array over topics. Each topic is represented as a pair of matching arrays: (term indices, term weights in topic). Each topic's terms are sorted in order of decreasing weight.
-
getSeed
public long getSeed()Random seed for cluster initialization.- Returns:
- (undocumented)
-
setSeed
Set the random seed for cluster initialization.- Parameters:
seed
- (undocumented)- Returns:
- (undocumented)
-
save
Description copied from interface:Saveable
Save this model to the given path.This saves: - human-readable (JSON) model metadata to path/metadata/ - Parquet formatted data to path/data/
The model may be loaded using
Loader.load
. -
logLikelihood
Calculates a lower bound on the log likelihood of the entire corpus.See Equation (16) in original Online LDA paper.
- Parameters:
documents
- test corpus to use for calculating log likelihood- Returns:
- variational lower bound on the log likelihood of the entire corpus
-
logLikelihood
Java-friendly version oflogLikelihood
- Parameters:
documents
- (undocumented)- Returns:
- (undocumented)
-
logPerplexity
Calculate an upper bound on perplexity. (Lower is better.) See Equation (16) in original Online LDA paper.- Parameters:
documents
- test corpus to use for calculating perplexity- Returns:
- Variational upper bound on log perplexity per token.
-
logPerplexity
Java-friendly version oflogPerplexity
- Parameters:
documents
- (undocumented)- Returns:
- (undocumented)
-
topicDistributions
public RDD<scala.Tuple2<Object,Vector>> topicDistributions(RDD<scala.Tuple2<Object, Vector>> documents) Predicts the topic mixture distribution for each document (often called "theta" in the literature). Returns a vector of zeros for an empty document.This uses a variational approximation following Hoffman et al. (2010), where the approximate distribution is called "gamma." Technically, this method returns this approximation "gamma" for each document.
- Parameters:
documents
- documents to predict topic mixture distributions for- Returns:
- An RDD of (document ID, topic mixture distribution for document)
-
topicDistribution
Predicts the topic mixture distribution for a document (often called "theta" in the literature). Returns a vector of zeros for an empty document.Note this means to allow quick query for single document. For batch documents, please refer to
topicDistributions()
to avoid overhead.- Parameters:
document
- document to predict topic mixture distributions for- Returns:
- topic mixture distribution for the document
-
topicDistributions
Java-friendly version oftopicDistributions
- Parameters:
documents
- (undocumented)- Returns:
- (undocumented)
-