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

public abstract class LDAModel extends Model<LDAModel> implements org.apache.spark.ml.clustering.LDAParams, org.apache.spark.internal.Logging, MLWritable
Model fitted by 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:
  • Method Details

    • checkpointInterval

      public final IntParam checkpointInterval()
      Description copied from interface: HasCheckpointInterval
      Param for set checkpoint interval (&gt;= 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:
      checkpointInterval in interface HasCheckpointInterval
      Returns:
      (undocumented)
    • describeTopics

      public Dataset<Row> describeTopics(int maxTermsPerTopic)
      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

      public Dataset<Row> describeTopics()
    • docConcentration

      public final DoubleArrayParam docConcentration()
      Specified by:
      docConcentration in interface org.apache.spark.ml.clustering.LDAParams
    • estimatedDocConcentration

      public Vector estimatedDocConcentration()
      Value for docConcentration() estimated from data. If Online LDA was used and optimizeDocConcentration() was set to false, then this returns the fixed (given) value for the docConcentration() parameter.
      Returns:
      (undocumented)
    • featuresCol

      public final Param<String> featuresCol()
      Description copied from interface: HasFeaturesCol
      Param for features column name.
      Specified by:
      featuresCol in interface HasFeaturesCol
      Returns:
      (undocumented)
    • isDistributed

      public abstract boolean isDistributed()
      Indicates whether this instance is of type DistributedLDAModel
    • k

      public final IntParam k()
      Specified by:
      k in interface org.apache.spark.ml.clustering.LDAParams
    • keepLastCheckpoint

      public final BooleanParam keepLastCheckpoint()
      Specified by:
      keepLastCheckpoint in interface org.apache.spark.ml.clustering.LDAParams
    • learningDecay

      public final DoubleParam learningDecay()
      Specified by:
      learningDecay in interface org.apache.spark.ml.clustering.LDAParams
    • learningOffset

      public final DoubleParam learningOffset()
      Specified by:
      learningOffset in interface org.apache.spark.ml.clustering.LDAParams
    • logLikelihood

      public double logLikelihood(Dataset<?> dataset)
      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 when optimizer() is set to "em"), this involves collecting a large topicsMatrix() 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

      public double logPerplexity(Dataset<?> dataset)
      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 when optimizer() is set to "em"), this involves collecting a large topicsMatrix() 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

      public final IntParam maxIter()
      Description copied from interface: HasMaxIter
      Param for maximum number of iterations (&gt;= 0).
      Specified by:
      maxIter in interface HasMaxIter
      Returns:
      (undocumented)
    • optimizeDocConcentration

      public final BooleanParam optimizeDocConcentration()
      Specified by:
      optimizeDocConcentration in interface org.apache.spark.ml.clustering.LDAParams
    • optimizer

      public final Param<String> optimizer()
      Specified by:
      optimizer in interface org.apache.spark.ml.clustering.LDAParams
    • seed

      public final LongParam seed()
      Description copied from interface: HasSeed
      Param for random seed.
      Specified by:
      seed in interface HasSeed
      Returns:
      (undocumented)
    • setFeaturesCol

      public LDAModel setFeaturesCol(String value)
      The features for LDA should be a Vector representing 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

      public LDAModel setSeed(long value)
    • setTopicDistributionCol

      public LDAModel setTopicDistributionCol(String value)
    • subsamplingRate

      public final DoubleParam subsamplingRate()
      Specified by:
      subsamplingRate in interface org.apache.spark.ml.clustering.LDAParams
    • supportedOptimizers

      public final String[] supportedOptimizers()
      Specified by:
      supportedOptimizers in interface org.apache.spark.ml.clustering.LDAParams
    • topicConcentration

      public final DoubleParam topicConcentration()
      Specified by:
      topicConcentration in interface org.apache.spark.ml.clustering.LDAParams
    • topicDistributionCol

      public final Param<String> topicDistributionCol()
      Specified by:
      topicDistributionCol in interface org.apache.spark.ml.clustering.LDAParams
    • topicsMatrix

      public Matrix 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 DistributedLDAModel instance 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

      public Dataset<Row> transform(Dataset<?> dataset)
      Transforms the input dataset.

      WARNING: If this model is an instance of DistributedLDAModel (produced when optimizer() is set to "em"), this involves collecting a large topicsMatrix() to the driver. This implementation may be changed in the future.

      Specified by:
      transform in class Transformer
      Parameters:
      dataset - (undocumented)
      Returns:
      (undocumented)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: PipelineStage
      Check transform validity and derive the output schema from the input schema.

      We check validity for interactions between parameters during transformSchema and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by Param.validate().

      Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.

      Specified by:
      transformSchema in class PipelineStage
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • vocabSize

      public int vocabSize()