Github user witgo commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2388#discussion_r18740868
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/feature/TopicModeling.scala ---
    @@ -0,0 +1,674 @@
    +/*
    + * 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.mllib.feature
    +
    +import java.util.Random
    +
    +import breeze.linalg.{DenseVector => BDV, SparseVector => BSV, Vector => 
BV, sum => brzSum}
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.SparkContext._
    +import org.apache.spark.annotation.Experimental
    +import org.apache.spark.broadcast.Broadcast
    +import org.apache.spark.graphx._
    +import org.apache.spark.mllib.linalg.distributed.{MatrixEntry, RowMatrix}
    +import org.apache.spark.mllib.linalg.{DenseVector => SDV, SparseVector => 
SSV, Vector => SV}
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.serializer.KryoRegistrator
    +import org.apache.spark.storage.StorageLevel
    +
    +import TopicModeling._
    +
    +class TopicModeling private[mllib](
    +  @transient var corpus: Graph[VD, ED],
    +  val numTopics: Int,
    +  val numTerms: Int,
    +  val alpha: Double,
    +  val beta: Double,
    +  @transient val storageLevel: StorageLevel)
    +  extends Serializable with Logging {
    +
    +  def this(docs: RDD[(TopicModeling.DocId, SSV)],
    +    numTopics: Int,
    +    alpha: Double,
    +    beta: Double,
    +    storageLevel: StorageLevel = StorageLevel.MEMORY_AND_DISK,
    +    computedModel: Broadcast[TopicModel] = null) {
    +    this(initializeCorpus(docs, numTopics, storageLevel, computedModel),
    +      numTopics, docs.first()._2.size, alpha, beta, storageLevel)
    +  }
    +
    +
    +  /**
    +   * The number of documents in the corpus
    +   */
    +  val numDocs = docVertices.count()
    +
    +  /**
    +   * The number of terms in the corpus
    +   */
    +  private val sumTerms = corpus.edges.map(e => 
e.attr.size.toDouble).sum().toLong
    +
    +  /**
    +   * The total counts for each topic
    +   */
    +  @transient private var globalTopicCounter: BV[Count] = 
collectGlobalCounter(corpus, numTopics)
    +  assert(brzSum(globalTopicCounter) == sumTerms)
    +  @transient private val sc = corpus.vertices.context
    +  @transient private val seed = new Random().nextInt()
    +  @transient private var innerIter = 1
    +  @transient private var cachedEdges: EdgeRDD[ED, VD] = null
    +  @transient private var cachedVertices: VertexRDD[VD] = null
    +
    +  private def termVertices = corpus.vertices.filter(t => t._1 >= 0)
    +
    +  private def docVertices = corpus.vertices.filter(t => t._1 < 0)
    +
    +  private def gibbsSampling(cachedEdges: EdgeRDD[ED, VD],
    +    cachedVertices: VertexRDD[VD]): (EdgeRDD[ED, VD], VertexRDD[VD]) = {
    +
    +    val corpusTopicDist = collectTermTopicDist(corpus, globalTopicCounter,
    +      sumTerms, numTerms, numTopics, alpha, beta)
    +
    +    val corpusSampleTopics = sampleTopics(corpusTopicDist, 
globalTopicCounter,
    +      sumTerms, innerIter + seed, numTerms, numTopics, alpha, beta)
    +    corpusSampleTopics.edges.setName(s"edges-$innerIter").cache().count()
    +    Option(cachedEdges).foreach(_.unpersist())
    +    val edges = corpusSampleTopics.edges
    +
    +    corpus = updateCounter(corpusSampleTopics, numTopics)
    +    corpus.vertices.setName(s"vertices-$innerIter").cache()
    +    globalTopicCounter = collectGlobalCounter(corpus, numTopics)
    +    assert(brzSum(globalTopicCounter) == sumTerms)
    +    Option(cachedVertices).foreach(_.unpersist())
    +    val vertices = corpus.vertices
    +
    +    if (innerIter % 10 == 0 && sc.getCheckpointDir.isDefined) {
    --- End diff --
    
    This is only a temporary solution.
    The related PR #2631


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to