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

    https://github.com/apache/spark/pull/6948#discussion_r33017051
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/clustering/LDAModel.scala ---
    @@ -354,4 +445,126 @@ class DistributedLDAModel private (
       // TODO:
       // override def topicDistributions(documents: RDD[(Long, Vector)]): 
RDD[(Long, Vector)] = ???
     
    +  override protected def formatVersion = "1.0"
    +
    +  override def save(sc: SparkContext, path: String): Unit = {
    +    DistributedLDAModel.SaveLoadV1_0.save(
    +      sc, path, graph, globalTopicTotals, k, vocabSize, docConcentration, 
topicConcentration,
    +      iterationTimes)
    +  }
    +}
    +
    +
    +@Experimental
    +object DistributedLDAModel extends Loader[DistributedLDAModel]{
    +
    +
    +  object SaveLoadV1_0 {
    +
    +    val formatVersionV1_0 = "1.0"
    +
    +    val classNameV1_0 = 
"org.apache.spark.mllib.clustering.DistributedLDAModel"
    +
    +    // Store the weight of each topic separately in a row.
    +    case class Data(globalTopicTotals: Double)
    +
    +    // Store each term and document vertex with an id and the topicWeights.
    +    case class VertexData(id: Long, topicWeights: Vector)
    +
    +    // Store each edge with the source id, destination id and tokenCounts.
    +    case class EdgeData(srcId: Long, dstId: Long, tokenCounts: Double)
    +
    +    def save(
    +        sc: SparkContext,
    +        path: String,
    +        graph: Graph[LDA.TopicCounts, LDA.TokenCount],
    +        globalTopicTotals: LDA.TopicCounts,
    +        k: Int,
    +        vocabSize: Int,
    +        docConcentration: Double,
    +        topicConcentration: Double,
    +        iterationTimes: Array[Double]): Unit = {
    +
    +      val sqlContext = new SQLContext(sc)
    +      import sqlContext.implicits._
    +
    +      val metadata = compact(render
    +        (("class" -> classNameV1_0) ~ ("version" -> formatVersionV1_0) ~
    +         ("k" -> k) ~ ("vocabSize" -> vocabSize) ~ ("docConcentration" -> 
docConcentration) ~
    +         ("topicConcentration" -> topicConcentration) ~
    +         ("iterationTimes" -> iterationTimes.toSeq)))
    +      sc.parallelize(Seq(metadata), 
1).saveAsTextFile(Loader.metadataPath(path))
    +
    +      val newPath = new Path(Loader.dataPath(path), 
"globalTopicTotals").toString
    +      sc.parallelize(globalTopicTotals.toArray.toSeq.map(w => Data(w)), 
1).toDF()
    +        .write.parquet(newPath)
    +
    +      val verticesPath = new Path(Loader.dataPath(path), 
"topicCounts").toString
    +      graph.vertices.map { case (ind, vertex) =>
    +        VertexData(ind, Vectors.fromBreeze(vertex))
    +      }.toDF().write.parquet(verticesPath)
    +
    +      val edgesPath = new Path(Loader.dataPath(path), 
"tokenCounts").toString
    --- End diff --
    
    What exactly do the tokenCounts denote? It is unclear from the 
documentation. And it seems it has no role to play in the local Version./


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to