Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/9894#discussion_r45683883
--- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/LDA.scala ---
@@ -486,6 +487,61 @@ class LocalLDAModel private[ml] (
@Since("1.6.0")
override def isDistributed: Boolean = false
+
+ @Since("1.6.0")
+ override def write: MLWriter = new
LocalLDAModel.LocalLDAModelWriter(this)
+}
+
+
+@Since("1.6.0")
+object LocalLDAModel extends MLReadable[LocalLDAModel] {
+
+ private[LocalLDAModel]
+ class LocalLDAModelWriter(instance: LocalLDAModel) extends MLWriter {
+
+ private case class Data(vocabSize: Int,
+ topicsMatrix: Matrix,
+ docConcentration: Vector,
+ topicConcentration: Double)
+
+ override protected def saveImpl(path: String): Unit = {
+ DefaultParamsWriter.saveMetadata(instance, path, sc)
+ val oldModel = instance.oldLocalModel
+ val data = Data(instance.vocabSize,
+ oldModel.topicsMatrix,
+ oldModel.docConcentration,
+ oldModel.topicConcentration)
+ val dataPath = new Path(path, "data").toString
+
sqlContext.createDataFrame(Seq(data)).repartition(1).write.parquet(dataPath)
+ }
+ }
+
+ private class LocalLDAModelReader extends MLReader[LocalLDAModel] {
+
+ private val className = classOf[LocalLDAModel].getName
+
+ override def load(path: String): LocalLDAModel = {
+ val metadata = DefaultParamsReader.loadMetadata(path, sc, className)
+ val dataPath = new Path(path, "data").toString
+ val data = sqlContext.read.parquet(dataPath)
+ .select("vocabSize", "topicsMatrix", "docConcentration",
"topicConcentration")
+ .head()
+ val vocabSize = data.getAs[Int](0)
+ val topicsMatrix = data.getAs[Matrix](1)
+ val docConcentration = data.getAs[Vector](2)
+ val topicConcentration = data.getAs[Double](3)
+ val oldModel = new OldLocalLDAModel(topicsMatrix, docConcentration,
topicConcentration)
--- End diff --
We don't provide an API currently to set gammaShape, but I wonder if we
will in the future. If so, then we might want to store gammaShape with the
Data so that we don't need a new model format in the future.
---
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]