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

    https://github.com/apache/spark/pull/14112#discussion_r71068992
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/LDA.scala ---
    @@ -728,16 +755,40 @@ object DistributedLDAModel extends 
MLReadable[DistributedLDAModel] {
         private val className = classOf[DistributedLDAModel].getName
     
         override def load(path: String): DistributedLDAModel = {
    +
    +      // Pattern to determine sparkversion
    +      val pattern =
    +        """\\d+.\\d+(.\\d+)?(-SNAPSHOT)?""".r
    +
           val metadata = DefaultParamsReader.loadMetadata(path, sc, className)
           val modelPath = new Path(path, "oldModel").toString
           val oldModel = OldDistributedLDAModel.load(sc, modelPath)
    -      val model = new DistributedLDAModel(
    -        metadata.uid, oldModel.vocabSize, oldModel, sparkSession, None)
    -      DefaultParamsReader.getAndSetParams(model, metadata)
    +      val model = new DistributedLDAModel(metadata.uid, oldModel.vocabSize,
    +        oldModel, sparkSession, None)
    +      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 pattern =>
    +          DefaultParamsReader.getAndSetParams(model, metadata)
    +      }
    --- End diff --
    
    We'd better find a way to reuse the code.


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