Class LDAModel
- All Implemented Interfaces:
Serializable,org.apache.spark.internal.Logging,org.apache.spark.ml.clustering.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 Summary
Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter -
Method Summary
Modifier 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 DoubleArrayParamValue fordocConcentration()estimated from data.Param for features column name.abstract booleanIndicates whether this instance is of typeDistributedLDAModelfinal IntParamk()final BooleanParamfinal DoubleParamfinal DoubleParamdoublelogLikelihood(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 BooleanParamfinal 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 DoubleParamfinal String[]final DoubleParamInferred 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.Transformer
transform, transform, transformMethods 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.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, org$apache$spark$ml$clustering$LDAParams$_setter_$docConcentration_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$k_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$keepLastCheckpoint_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$learningDecay_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$learningOffset_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$optimizeDocConcentration_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$optimizer_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$subsamplingRate_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$supportedOptimizers_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$topicConcentration_$eq, org$apache$spark$ml$clustering$LDAParams$_setter_$topicDistributionCol_$eq, validateAndTransformSchemaMethods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logBasedOnLevel, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, MDC, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContextMethods inherited from interface org.apache.spark.ml.util.MLWritable
save, writeMethods inherited from interface org.apache.spark.ml.param.Params
clear, copy, copyValues, defaultCopy, defaultParamMap, estimateMatadataSize, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
-
Method Details
-
checkpointInterval
Description 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 interfaceHasCheckpointInterval- Returns:
- (undocumented)
-
describeTopics
Return 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
-
docConcentration
- Specified by:
docConcentrationin interfaceorg.apache.spark.ml.clustering.LDAParams
-
estimatedDocConcentration
Value 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)
-
featuresCol
Description copied from interface:HasFeaturesColParam for features column name.- Specified by:
featuresColin interfaceHasFeaturesCol- Returns:
- (undocumented)
-
isDistributed
public abstract boolean isDistributed()Indicates whether this instance is of typeDistributedLDAModel -
k
- Specified by:
kin interfaceorg.apache.spark.ml.clustering.LDAParams
-
keepLastCheckpoint
- Specified by:
keepLastCheckpointin interfaceorg.apache.spark.ml.clustering.LDAParams
-
learningDecay
- Specified by:
learningDecayin interfaceorg.apache.spark.ml.clustering.LDAParams
-
learningOffset
- Specified by:
learningOffsetin interfaceorg.apache.spark.ml.clustering.LDAParams
-
logLikelihood
Calculates 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
-
logPerplexity
Calculate 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.
-
maxIter
Description copied from interface:HasMaxIterParam for maximum number of iterations (>= 0).- Specified by:
maxIterin interfaceHasMaxIter- Returns:
- (undocumented)
-
optimizeDocConcentration
- Specified by:
optimizeDocConcentrationin interfaceorg.apache.spark.ml.clustering.LDAParams
-
optimizer
- Specified by:
optimizerin interfaceorg.apache.spark.ml.clustering.LDAParams
-
seed
Description copied from interface:HasSeedParam for random seed. -
setFeaturesCol
The 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
-
subsamplingRate
- Specified by:
subsamplingRatein interfaceorg.apache.spark.ml.clustering.LDAParams
-
supportedOptimizers
- Specified by:
supportedOptimizersin interfaceorg.apache.spark.ml.clustering.LDAParams
-
topicConcentration
- Specified by:
topicConcentrationin interfaceorg.apache.spark.ml.clustering.LDAParams
-
topicDistributionCol
- Specified by:
topicDistributionColin interfaceorg.apache.spark.ml.clustering.LDAParams
-
topicsMatrix
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.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)
-
transform
Transforms 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 classTransformer- Parameters:
dataset- (undocumented)- Returns:
- (undocumented)
-
transformSchema
Description 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 classPipelineStage- Parameters:
schema- (undocumented)- Returns:
- (undocumented)
-
uid
Description copied from interface:IdentifiableAn immutable unique ID for the object and its derivatives.- Specified by:
uidin interfaceIdentifiable- Returns:
- (undocumented)
-
vocabSize
public int vocabSize()
-