Class LDA
- All Implemented Interfaces:
Serializable,org.apache.spark.internal.Logging,LDAParams,Params,HasCheckpointInterval,HasFeaturesCol,HasMaxIter,HasSeed,DefaultParamsWritable,Identifiable,MLWritable
Terminology: - "term" = "word": an element of the vocabulary - "token": instance of a term appearing in a document - "topic": multinomial distribution over terms representing some concept - "document": one piece of text, corresponding to one row in the input data
Original LDA paper (journal version): Blei, Ng, and Jordan. "Latent Dirichlet Allocation." JMLR, 2003.
Input data (featuresCol):
LDA is given a collection of documents as input data, via the featuresCol parameter.
Each document is specified as a Vector of length vocabSize, where each entry is the
count for the corresponding term (word) in the document. Feature transformers such as
Tokenizer and CountVectorizer
can be useful for converting text to word count vectors.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal IntParamParam for set checkpoint interval (>= 1) or disable checkpoint (-1).Creates a copy of this instance with the same UID and some extra params.final DoubleArrayParamConcentration parameter (commonly named "alpha") for the prior placed on documents' distributions over topics ("theta").Param for features column name.Fits a model to the input data.final 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".static LDAfinal 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.read()final LongParamseed()Param for random seed.setCheckpointInterval(int value) setDocConcentration(double value) setDocConcentration(double[] value) setFeaturesCol(String value) The features for LDA should be aVectorrepresenting the word counts in a document.setK(int value) setKeepLastCheckpoint(boolean value) setLearningDecay(double value) setLearningOffset(double value) setMaxIter(int value) setOptimizeDocConcentration(boolean value) setOptimizer(String value) setSeed(long value) setSubsamplingRate(double value) setTopicConcentration(double 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).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.Methods inherited from class org.apache.spark.ml.PipelineStage
paramsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.spark.ml.util.DefaultParamsWritable
writeMethods inherited from interface org.apache.spark.ml.param.shared.HasCheckpointInterval
getCheckpointIntervalMethods inherited from interface org.apache.spark.ml.param.shared.HasFeaturesCol
getFeaturesColMethods inherited from interface org.apache.spark.ml.param.shared.HasMaxIter
getMaxIterMethods inherited from interface org.apache.spark.ml.util.Identifiable
toStringMethods inherited from interface org.apache.spark.ml.clustering.LDAParams
getDocConcentration, getK, getKeepLastCheckpoint, getLearningDecay, getLearningOffset, getOldDocConcentration, getOldOptimizer, getOldTopicConcentration, getOptimizeDocConcentration, getOptimizer, getSubsamplingRate, getTopicConcentration, getTopicDistributionCol, validateAndTransformSchemaMethods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, 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.MLWritable
saveMethods inherited from interface org.apache.spark.ml.param.Params
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
-
Constructor Details
-
LDA
-
LDA
public LDA()
-
-
Method Details
-
read
-
load
-
k
Description copied from interface:LDAParamsParam for the number of topics (clusters) to infer. Must be > 1. Default: 10. -
docConcentration
Description 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 interfaceLDAParams- Returns:
- (undocumented)
-
topicConcentration
Description 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 interfaceLDAParams- Returns:
- (undocumented)
-
supportedOptimizers
Description copied from interface:LDAParamsSupported values for ParamLDAParams.optimizer().- Specified by:
supportedOptimizersin interfaceLDAParams
-
optimizer
Description 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
-
topicDistributionCol
public final Param<
-