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

    https://github.com/apache/spark/pull/14112#discussion_r70504864
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/LDA.scala ---
    @@ -566,26 +565,52 @@ object LocalLDAModel extends 
MLReadable[LocalLDAModel] {
         }
       }
     
    +  private case class Data(
    +                           vocabSize: Int,
    +                           topicsMatrix: Matrix,
    +                           docConcentration: Vector,
    +                           topicConcentration: Double,
    +                           gammaShape: Double)
    +
       private class LocalLDAModelReader extends MLReader[LocalLDAModel] {
     
         private val className = classOf[LocalLDAModel].getName
     
         override def load(path: String): LocalLDAModel = {
    +      // Import implicits for Dataset Encoder
    +      val sparkSession = super.sparkSession
    +      import sparkSession.implicits._
    +
           val metadata = DefaultParamsReader.loadMetadata(path, sc, className)
           val dataPath = new Path(path, "data").toString
           val data = sparkSession.read.parquet(dataPath)
    -        .select("vocabSize", "topicsMatrix", "docConcentration", 
"topicConcentration",
    -          "gammaShape")
    -        .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 gammaShape = data.getAs[Double](4)
    +      val vectorConverted = MLUtils.convertVectorColumnsToML(data, 
"docConcentration")
    +      val Row(vocabSize: Int, topicsMatrix: Matrix, docConcentration: 
Vector,
    +        topicConcentration: Double, gammaShape: Double) = 
MLUtils.convertMatrixColumnsToML(
    +        vectorConverted, "topicsMatrix").as[Data]
           val oldModel = new OldLocalLDAModel(topicsMatrix, docConcentration, 
topicConcentration,
             gammaShape)
           val model = new LocalLDAModel(metadata.uid, vocabSize, oldModel, 
sparkSession)
    -      DefaultParamsReader.getAndSetParams(model, metadata)
    +
    +      metadata.sparkVersion match {
    +        case "1.6" =>
    +          implicit val format = DefaultFormats
    +          metadata.params match {
    +           case JObject(pairs) =>
    +             pairs.foreach { case (paramName, jsonValue) =>
    +               val origParam =
    +                 if (paramName == "topicDistribution") 
"topicDistributionCol" else paramName
    +               val param = model.getParam(origParam)
    +               val value = param.jsonDecode(compact(render(jsonValue)))
    +               model.set(param, value)
    +             }
    +           case _ =>
    +             throw new IllegalArgumentException(
    +               s"Cannot recognize JSON metadata: 
${metadata.metadataJson}.")
    +           }
    +        case "2.x" =>
    --- End diff --
    
    I don't think you can match on "2.x"  You'll need a more robust comparison 
of versions.  (Check out what sparkSession.version returns; it could be things 
like "2.0.1" or "2.0.1-SNAPSHOT".)


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