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

    https://github.com/apache/spark/pull/6948#discussion_r34755378
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/clustering/LDAModel.scala ---
    @@ -354,4 +445,140 @@ 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 thisFormatVersion = "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: Vector)
    +
    +    // 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 = SQLContext.getOrCreate(sc)
    +      import sqlContext.implicits._
    +
    +      val metadata = compact(render
    +        (("class" -> classNameV1_0) ~ ("version" -> thisFormatVersion) ~
    +         ("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").toUri.toString
    +      
sc.parallelize(Seq(Data(Vectors.fromBreeze(globalTopicTotals)))).toDF()
    +        .write.parquet(newPath)
    +
    +      val verticesPath = new Path(Loader.dataPath(path), 
"topicCounts").toUri.toString
    +      graph.vertices.map { case (ind, vertex) =>
    +        VertexData(ind, Vectors.fromBreeze(vertex))
    +      }.toDF().write.parquet(verticesPath)
    +
    +      val edgesPath = new Path(Loader.dataPath(path), 
"tokenCounts").toUri.toString
    +      graph.edges.map { case Edge(srcId, dstId, prop) =>
    +        EdgeData(srcId, dstId, prop)
    +      }.toDF().write.parquet(edgesPath)
    +    }
    +
    +    def load(
    +        sc: SparkContext,
    +        path: String,
    +        vocabSize: Int,
    +        docConcentration: Double,
    +        topicConcentration: Double,
    +        iterationTimes: Array[Double]): DistributedLDAModel = {
    +
    +      val dataPath = new Path(Loader.dataPath(path), 
"globalTopicTotals").toUri.toString
    +      val vertexDataPath = new Path(Loader.dataPath(path), 
"topicCounts").toUri.toString
    +      val edgeDataPath = new Path(Loader.dataPath(path), 
"tokenCounts").toUri.toString
    +      val sqlContext = new SQLContext(sc)
    --- End diff --
    
    Use SQLContext.getOrCreate


---
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