Class LDAModel
- All Implemented Interfaces:
- Serializable,- org.apache.spark.internal.Logging,- LDAParams,- Params,- HasCheckpointInterval,- HasFeaturesCol,- HasMaxIter,- HasSeed,- Identifiable,- MLWritable
- Direct Known Subclasses:
- DistributedLDAModel,- LocalLDAModel
LDA.
 param: vocabSize Vocabulary size (number of terms or words in the vocabulary) param: sparkSession Used to construct local DataFrames for returning query results
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.spark.internal.Loggingorg.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
- 
Method SummaryModifier and TypeMethodDescriptionfinal IntParamParam for set checkpoint interval (>= 1) or disable checkpoint (-1).describeTopics(int maxTermsPerTopic) Return the topics described by their top-weighted terms.final DoubleArrayParamConcentration parameter (commonly named "alpha") for the prior placed on documents' distributions over topics ("theta").Value fordocConcentration()estimated from data.Param for features column name.abstract booleanIndicates whether this instance is of typeDistributedLDAModelfinal IntParamk()Param for the number of topics (clusters) to infer.final BooleanParamFor EM optimizer only:LDAParams.optimizer()= "em".final DoubleParamFor Online optimizer only:LDAParams.optimizer()= "online".final DoubleParamFor Online optimizer only:LDAParams.optimizer()= "online".doublelogLikelihood(Dataset<?> dataset) Calculates a lower bound on the log likelihood of the entire corpus.doublelogPerplexity(Dataset<?> dataset) Calculate an upper bound on perplexity.final IntParammaxIter()Param for maximum number of iterations (>= 0).final BooleanParamFor Online optimizer only (currently):LDAParams.optimizer()= "online".Optimizer or inference algorithm used to estimate the LDA model.final LongParamseed()Param for random seed.setFeaturesCol(String value) The features for LDA should be aVectorrepresenting the word counts in a document.setSeed(long value) setTopicDistributionCol(String value) final DoubleParamFor Online optimizer only:LDAParams.optimizer()= "online".final String[]Supported values for ParamLDAParams.optimizer().final DoubleParamConcentration parameter (commonly named "beta" or "eta") for the prior placed on topics' distributions over terms.Output column with estimates of the topic mixture distribution for each document (often called "theta" in the literature).Inferred topics, where each topic is represented by a distribution over terms.Transforms the input dataset.transformSchema(StructType schema) Check transform validity and derive the output schema from the input schema.uid()An immutable unique ID for the object and its derivatives.intMethods inherited from class org.apache.spark.ml.Transformertransform, transform, transformMethods inherited from class org.apache.spark.ml.PipelineStageparamsMethods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.spark.ml.param.shared.HasCheckpointIntervalgetCheckpointIntervalMethods inherited from interface org.apache.spark.ml.param.shared.HasFeaturesColgetFeaturesColMethods inherited from interface org.apache.spark.ml.param.shared.HasMaxItergetMaxIterMethods inherited from interface org.apache.spark.ml.util.IdentifiabletoStringMethods inherited from interface org.apache.spark.ml.clustering.LDAParamsgetDocConcentration, getK, getKeepLastCheckpoint, getLearningDecay, getLearningOffset, getOldDocConcentration, getOldOptimizer, getOldTopicConcentration, getOptimizeDocConcentration, getOptimizer, getSubsamplingRate, getTopicConcentration, getTopicDistributionCol, validateAndTransformSchemaMethods inherited from interface org.apache.spark.internal.LogginginitializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContextMethods inherited from interface org.apache.spark.ml.util.MLWritablesave, writeMethods inherited from interface org.apache.spark.ml.param.Paramsclear, copy, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
- 
Method Details- 
checkpointIntervalDescription copied from interface:HasCheckpointIntervalParam for set checkpoint interval (>= 1) or disable checkpoint (-1). E.g. 10 means that the cache will get checkpointed every 10 iterations. Note: this setting will be ignored if the checkpoint directory is not set in the SparkContext.- Specified by:
- checkpointIntervalin interface- HasCheckpointInterval
- Returns:
- (undocumented)
 
- 
describeTopicsReturn the topics described by their top-weighted terms.- Parameters:
- maxTermsPerTopic- Maximum number of terms to collect for each topic. Default value of 10.
- Returns:
- Local DataFrame with one topic per Row, with columns: - "topic": IntegerType: topic index - "termIndices": ArrayType(IntegerType): term indices, sorted in order of decreasing term importance - "termWeights": ArrayType(DoubleType): corresponding sorted term weights
 
- 
describeTopics
- 
docConcentrationDescription copied from interface:LDAParamsConcentration parameter (commonly named "alpha") for the prior placed on documents' distributions over topics ("theta").This is the parameter to a Dirichlet distribution, where larger values mean more smoothing (more regularization). If not set by the user, then docConcentration is set automatically. If set to singleton vector [alpha], then alpha is replicated to a vector of length k in fitting. Otherwise, the LDAParams.docConcentration()vector must be length k. (default = automatic)Optimizer-specific parameter settings: - EM - Currently only supports symmetric distributions, so all values in the vector should be the same. - Values should be greater than 1.0 - default = uniformly (50 / k) + 1, where 50/k is common in LDA libraries and +1 follows from Asuncion et al. (2009), who recommend a +1 adjustment for EM. - Online - Values should be greater than or equal to 0 - default = uniformly (1.0 / k), following the implementation from here. - Specified by:
- docConcentrationin interface- LDAParams
- Returns:
- (undocumented)
 
- 
estimatedDocConcentrationValue fordocConcentration()estimated from data. If Online LDA was used andoptimizeDocConcentration()was set to false, then this returns the fixed (given) value for thedocConcentration()parameter.- Returns:
- (undocumented)
 
- 
featuresColDescription copied from interface:HasFeaturesColParam for features column name.- Specified by:
- featuresColin interface- HasFeaturesCol
- Returns:
- (undocumented)
 
- 
isDistributedpublic abstract boolean isDistributed()Indicates whether this instance is of typeDistributedLDAModel
- 
kDescription copied from interface:LDAParamsParam for the number of topics (clusters) to infer. Must be > 1. Default: 10.
- 
keepLastCheckpointDescription copied from interface:LDAParamsFor EM optimizer only:LDAParams.optimizer()= "em".If using checkpointing, this indicates whether to keep the last checkpoint. If false, then the checkpoint will be deleted. Deleting the checkpoint can cause failures if a data partition is lost, so set this bit with care. Note that checkpoints will be cleaned up via reference counting, regardless. See DistributedLDAModel.getCheckpointFilesfor getting remaining checkpoints andDistributedLDAModel.deleteCheckpointFilesfor removing remaining checkpoints.Default: true - Specified by:
- keepLastCheckpointin interface- LDAParams
- Returns:
- (undocumented)
 
- 
learningDecayDescription copied from interface:LDAParamsFor Online optimizer only:LDAParams.optimizer()= "online".Learning rate, set as an exponential decay rate. This should be between (0.5, 1.0] to guarantee asymptotic convergence. This is called "kappa" in the Online LDA paper (Hoffman et al., 2010). Default: 0.51, based on Hoffman et al. - Specified by:
- learningDecayin interface- LDAParams
- Returns:
- (undocumented)
 
- 
learningOffsetDescription copied from interface:LDAParamsFor Online optimizer only:LDAParams.optimizer()= "online".A (positive) learning parameter that downweights early iterations. Larger values make early iterations count less. This is called "tau0" in the Online LDA paper (Hoffman et al., 2010) Default: 1024, following Hoffman et al. - Specified by:
- learningOffsetin interface- LDAParams
- Returns:
- (undocumented)
 
- 
logLikelihoodCalculates a lower bound on the log likelihood of the entire corpus.See Equation (16) in the Online LDA paper (Hoffman et al., 2010). WARNING: If this model is an instance of DistributedLDAModel(produced whenoptimizer()is set to "em"), this involves collecting a largetopicsMatrix()to the driver. This implementation may be changed in the future.- Parameters:
- dataset- test corpus to use for calculating log likelihood
- Returns:
- variational lower bound on the log likelihood of the entire corpus
 
- 
logPerplexityCalculate an upper bound on perplexity. (Lower is better.) See Equation (16) in the Online LDA paper (Hoffman et al., 2010).WARNING: If this model is an instance of DistributedLDAModel(produced whenoptimizer()is set to "em"), this involves collecting a largetopicsMatrix()to the driver. This implementation may be changed in the future.- Parameters:
- dataset- test corpus to use for calculating perplexity
- Returns:
- Variational upper bound on log perplexity per token.
 
- 
maxIterDescription copied from interface:HasMaxIterParam for maximum number of iterations (>= 0).- Specified by:
- maxIterin interface- HasMaxIter
- Returns:
- (undocumented)
 
- 
optimizeDocConcentrationDescription copied from interface:LDAParamsFor Online optimizer only (currently):LDAParams.optimizer()= "online".Indicates whether the docConcentration (Dirichlet parameter for document-topic distribution) will be optimized during training. Setting this to true will make the model more expressive and fit the training data better. Default: false - Specified by:
- optimizeDocConcentrationin interface- LDAParams
- Returns:
- (undocumented)
 
- 
optimizerDescription copied from interface:LDAParamsOptimizer or inference algorithm used to estimate the LDA model. Currently supported (case-insensitive): - "online": Online Variational Bayes (default) - "em": Expectation-MaximizationFor details, see the following papers: - Online LDA: Hoffman, Blei and Bach. "Online Learning for Latent Dirichlet Allocation." Neural Information Processing Systems, 2010. See here - EM: Asuncion et al. "On Smoothing and Inference for Topic Models." Uncertainty in Artificial Intelligence, 2009. See here 
- 
seedDescription copied from interface:HasSeedParam for random seed.
- 
setFeaturesColThe features for LDA should be aVectorrepresenting the word counts in a document. The vector should be of length vocabSize, with counts for each term (word).- Parameters:
- value- (undocumented)
- Returns:
- (undocumented)
 
- 
setSeed
- 
setTopicDistributionCol
- 
subsamplingRateDescription copied from interface:LDAParamsFor Online optimizer only:LDAParams.optimizer()= "online".Fraction of the corpus to be sampled and used in each iteration of mini-batch gradient descent, in range (0, 1]. Note that this should be adjusted in synch with LDA.maxIterso the entire corpus is used. Specifically, set both so that maxIterations * miniBatchFraction greater than or equal to 1.Note: This is the same as the miniBatchFractionparameter inOnlineLDAOptimizer.Default: 0.05, i.e., 5% of total documents. - Specified by:
- subsamplingRatein interface- LDAParams
- Returns:
- (undocumented)
 
- 
supportedOptimizersDescription copied from interface:LDAParamsSupported values for ParamLDAParams.optimizer().- Specified by:
- supportedOptimizersin interface- LDAParams
 
- 
topicConcentrationDescription copied from interface:LDAParamsConcentration parameter (commonly named "beta" or "eta") for the prior placed on topics' distributions over terms.This is the parameter to a symmetric Dirichlet distribution. Note: The topics' distributions over terms are called "beta" in the original LDA paper by Blei et al., but are called "phi" in many later papers such as Asuncion et al., 2009. If not set by the user, then topicConcentration is set automatically. (default = automatic) Optimizer-specific parameter settings: - EM - Value should be greater than 1.0 - default = 0.1 + 1, where 0.1 gives a small amount of smoothing and +1 follows Asuncion et al. (2009), who recommend a +1 adjustment for EM. - Online - Value should be greater than or equal to 0 - default = (1.0 / k), following the implementation from here. - Specified by:
- topicConcentrationin interface- LDAParams
- Returns:
- (undocumented)
 
- 
topicDistributionColDescription copied from interface:LDAParamsOutput column with estimates of 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. - Specified by:
- topicDistributionColin interface- LDAParams
- Returns:
- (undocumented)
 
- 
topicsMatrixInferred 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.WARNING: If this model is actually a DistributedLDAModelinstance produced by the Expectation-Maximization ("em")optimizer(), then this method could involve collecting a large amount of data to the driver (on the order of vocabSize x k).- Returns:
- (undocumented)
 
- 
transformTransforms the input dataset.WARNING: If this model is an instance of DistributedLDAModel(produced whenoptimizer()is set to "em"), this involves collecting a largetopicsMatrix()to the driver. This implementation may be changed in the future.- Specified by:
- transformin class- Transformer
- Parameters:
- dataset- (undocumented)
- Returns:
- (undocumented)
 
- 
transformSchemaDescription copied from class:PipelineStageCheck transform validity and derive the output schema from the input schema.We check validity for interactions between parameters during transformSchemaand raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled byParam.validate().Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks. - Specified by:
- transformSchemain class- PipelineStage
- Parameters:
- schema- (undocumented)
- Returns:
- (undocumented)
 
- 
uidDescription copied from interface:IdentifiableAn immutable unique ID for the object and its derivatives.- Specified by:
- uidin interface- Identifiable
- Returns:
- (undocumented)
 
- 
vocabSizepublic int vocabSize()
 
-