spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkbradley <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-5565] [ML] LDA wrapper for Pipelines AP...
Date Mon, 09 Nov 2015 04:03:53 GMT
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9513#discussion_r44239852
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/LDA.scala ---
    @@ -0,0 +1,740 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.ml.clustering
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.annotation.{Experimental, Since}
    +import org.apache.spark.ml.util.{SchemaUtils, Identifiable}
    +import org.apache.spark.ml.{Estimator, Model}
    +import org.apache.spark.ml.param.shared.{HasCheckpointInterval, HasFeaturesCol, HasSeed,
HasMaxIter}
    +import org.apache.spark.ml.param._
    +import org.apache.spark.mllib.clustering.{DistributedLDAModel => OldDistributedLDAModel,
    +    EMLDAOptimizer => OldEMLDAOptimizer, LDA => OldLDA, LDAModel => OldLDAModel,
    +    LDAOptimizer => OldLDAOptimizer, LocalLDAModel => OldLocalLDAModel,
    +    OnlineLDAOptimizer => OldOnlineLDAOptimizer}
    +import org.apache.spark.mllib.linalg.{VectorUDT, Vectors, Matrix, Vector}
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.{SQLContext, DataFrame, Row}
    +import org.apache.spark.sql.functions.{col, monotonicallyIncreasingId, udf}
    +import org.apache.spark.sql.types.StructType
    +
    +
    +private[clustering] trait LDAParams extends Params with HasFeaturesCol with HasMaxIter
    +  with HasSeed with HasCheckpointInterval {
    +
    +  /**
    +   * Param for the number of topics (clusters). Must be > 1. Default: 10.
    +   * @group param
    +   */
    +  @Since("1.6.0")
    +  final val k = new IntParam(this, "k", "number of clusters to create", ParamValidators.gt(1))
    +
    +  /** @group getParam */
    +  @Since("1.6.0")
    +  def getK: Int = $(k)
    +
    +  /**
    +   * Concentration 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 set to a singleton vector [-1], then docConcentration is set automatically. If
set to
    +   * singleton vector [alpha] where alpha != -1, then alpha is replicated to a vector
of
    +   * length k in fitting. Otherwise, the [[docConcentration]] vector must be length k.
    +   * (default = [-1] = automatic)
    +   *
    +   * Optimizer-specific parameter settings:
    +   *  - EM
    +   *     - Currently only supports symmetric distributions, so all values in the vector
should be
    +   *       the same.
    +   *     - Values should be > 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 >= 0
    +   *     - default = uniformly (1.0 / k), following the implementation from
    +   *       [[https://github.com/Blei-Lab/onlineldavb]].
    +   * @group param
    +   */
    +  @Since("1.6.0")
    +  final val docConcentration = new DoubleArrayParam(this, "docConcentration",
    +    "Concentration parameter (commonly named \"alpha\") for the prior placed on documents'"
+
    +      " distributions over topics (\"theta\").", validDocConcentration)
    +
    +  /** Check that the docConcentration is valid, independently of other Params */
    +  private def validDocConcentration(alpha: Array[Double]): Boolean = {
    +    if (alpha.length == 1) {
    +      alpha(0) == -1 || alpha(0) >= 1.0
    +    } else if (alpha.length > 1) {
    +      alpha.forall(_ >= 1.0)
    +    } else {
    +      false
    +    }
    +  }
    +
    +  /** @group getParam */
    +  @Since("1.6.0")
    +  def getDocConcentration: Array[Double] = $(docConcentration)
    +
    +  /**
    +   * Alias for [[getDocConcentration]]
    +   * @group getParam
    +   */
    +  @Since("1.6.0")
    +  def getAlpha: Array[Double] = getDocConcentration
    --- End diff --
    
    Hm, yeah, I neglected to mention this in the design doc.  I'm OK with removing alpha and
beta from everything but the doc.  I'll go ahead and take those out.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message