Github user yu-iskw commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8643#discussion_r43722360
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/api/python/LDAModelWrapper.scala ---
    @@ -0,0 +1,45 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.spark.mllib.api.python
    +
    +import scala.collection.JavaConverters
    +
    +import org.apache.spark.SparkContext
    +import org.apache.spark.mllib.clustering.LDAModel
    +import org.apache.spark.mllib.linalg.Matrix
    +
    +/**
    + * Wrapper around LDAModel to provide helper methods in Python
    + */
    +private[python] class LDAModelWrapper(model: LDAModel) {
    +
    +  def topicsMatrix(): Matrix = model.topicsMatrix
    +
    +  def vocabSize(): Int = model.vocabSize
    +
    +  def describeTopics(): java.util.List[Array[Any]] = 
describeTopics(this.model.vocabSize)
    +
    +  def describeTopics(maxTermsPerTopic: Int): java.util.List[Array[Any]] = {
    +
    +    val seq = model.describeTopics(maxTermsPerTopic).map { case (terms, 
termWeights) =>
    +        Array.empty[Any] ++ terms ++ termWeights
    +      }.toSeq
    +    JavaConverters.seqAsJavaListConverter(seq).asJava
    --- End diff --
    
    @davies thank you for tha comment. Could you please give me more 
information about the type conversion?
    
    How do we deserialize the return value in Python? Especially, I don't know 
how to deserialize `scala.Tuple2` in Python. I tried to serialize the entire 
list with `SerDe.dumps()` at `LDAModelWrapper.describeTopics()`, and then 
confirm the return value in Python. 
    
https://github.com/yu-iskw/spark/commit/54e5fda86ac3f3bac76b165615a0231d88a717aa
    
    The testing result is as follow:
    ```
    **********************************************************************
    Failed example:
        model.describeTopics()
    Expected:
        [([1, 0], [0.5..., 0.49...]), ([0, 1], [0.5..., 0.49...])]
    Got:
        ({u'__class__': u'scala.Tuple2'}, {u'__class__': u'scala.Tuple2'})
    ```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to