【问题标题】:Spark 1.4 Mllib LDA topicDistributions() returning wrong number of documentsSpark 1.4 Mllib LDA topicDistributions() 返回错误数量的文档
【发布时间】:2015-11-08 06:01:26
【问题描述】:

我有一个 LDA 模型在 12,054 个文档的语料库大小和 9,681 个单词和 60 个集群上运行。我试图通过调用 .topicDistributions() 或 .javaTopicDistributions() 来获取文档上的主题分布。这两种方法都返回文档上的主题分布 rdd。据我了解,行数应该是文档数,列数应该是主题数。但是,当我在调用 topicDistributions() 后计算 rdd 时,我得到的计数是 11,665(少于传递给模型的文档数)?每个文档都有正确数量的主题 (60)。这是为什么呢?

这是演示: http://spark.apache.org/docs/latest/mllib-clustering.html

和文档:https://spark.apache.org/docs/1.4.0/api/java/org/apache/spark/mllib/clustering/DistributedLDAModel.html

代码如下:

enter code here

//parse tf vectors from corpus

JavaRDD<Vector> parsedData = data.map(
    new Function<String, Vector>() {
        public Vector call(String s) {
            s = s.substring(1, s.length()-1);
            String[] sarray = s.trim().split(",");
            double[] values = new double[sarray.length];
            for (int i = 0; i < sarray.length; i++)
            {
                values[i] = Double.parseDouble(sarray[i]);
            }
            return Vectors.dense(values);
          }

);

System.out.println(parsedData.count()) //prints 12,054

// Index documents with unique IDs

JavaPairRDD<Long, Vector> corpus =  JavaPairRDD.fromJavaRDD(parsedData.zipWithIndex().map(
     new Function<Tuple2<Vector, Long>, Tuple2<Long, Vector>>() {
       public Tuple2<Long, Vector> call(Tuple2<Vector, Long> doc_id) {
         return doc_id.swap();
       }
     }
));

System.out.println(corpus.count()) //prints 12,054

LDA lda = new LDA()
LDAModel ldaModel = lda.setK(k.intValue()).run(corpus);

RDD<scala.Tuple2<Object,Vector>> topic_dist_over_docs = ((DistributedLDAModel) ldaModel).topicDistributions();
System.out.println(topic_dist_over_docs.count()) //prints 11,655 ???

JavaPairRDD<Long,Vector> topic_dist_over_docs2 = ((DistributedLDAModel) ldaModel).javaTopicDistributions();
System.out.println(topic_dist_over_docs2.count()) //also prints 11,655 ???

【问题讨论】:

    标签: cluster-analysis apache-spark-mllib lda apache-spark-1.4


    【解决方案1】:

    Spark 1.4 中似乎有一个关于 topicDistributions 的错误。更新到 Spark 1.5 的实验版本后,我能够解决这个问题。

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 2017-02-02
      • 2016-01-24
      • 2016-10-18
      • 2016-04-22
      • 2017-12-29
      • 2014-11-14
      • 2016-02-05
      相关资源
      最近更新 更多