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").longgetSeed()Random seed for cluster initialization.intk()Number of topicsstatic LocalLDAModelload(SparkContext sc, String path) doublelogLikelihood(JavaPairRDD<Long, Vector> documents) Java-friendly version oflogLikelihooddoublelogLikelihood(RDD<scala.Tuple2<Object, Vector>> documents) Calculates a lower bound on the log likelihood of the entire corpus.doublelogPerplexity(JavaPairRDD<Long, Vector> documents) Java-friendly version oflogPerplexitydoublelogPerplexity(RDD<scala.Tuple2<Object, Vector>> documents) Calculate an upper bound on perplexity.voidsave(SparkContext sc, String path) Save this model to the given path.setSeed(long seed) Set the random seed for cluster initialization.doubleConcentration 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 oftopicDistributionstopicDistributions(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.intVocabulary 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:LDAModelConcentration parameter (commonly named "alpha") for the prior placed on documents' distributions over topics ("theta").This is the parameter to a Dirichlet distribution.
- Specified by:
docConcentrationin classLDAModel- Returns:
- (undocumented)
-
topicConcentration
public double topicConcentration()Description copied from class:LDAModelConcentration 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:
topicConcentrationin classLDAModel- Returns:
- (undocumented)
-
k
public int k()Description copied from class:LDAModelNumber of topics -
vocabSize
public int vocabSize()Description copied from class:LDAModelVocabulary size (number of terms or terms in the vocabulary) -
topicsMatrix
Description copied from class:LDAModelInferred 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:
topicsMatrixin classLDAModel- Returns:
- (undocumented)
-
describeTopics
public scala.Tuple2<int[],double[]>[] describeTopics(int maxTermsPerTopic) Description copied from class:LDAModelReturn the topics described by weighted terms.- Specified by:
describeTopicsin 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:SaveableSave 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)
-