spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From moustachio <>
Subject Get *document*-topic distribution from PySpark LDA model?
Date Wed, 14 Oct 2015 16:02:32 GMT
Hi! I already have a StackOverflow question on this (see  here

), but haven't received any responses, so I thought I'd try here!

Long story short, I'm working in PySpark and have successfully generated an
LDA topic model, but can't figure out how to (or if I can) extract the topic
distributions for each document from the model. I understand the LDA
functionality is still in development, but getting document topic
distributions is arguably the principal use case here, and is not (as far as
I can tell) implemented in the Python API. I can easily get the *word*-topic
distribution, by calling model.topicsMatrix(), but this isn't what I need,
and there don't seems to be any other useful methods in the Python LDA model

The only glimmer of hope came from finding the documentation for
DistributedLDAModel in the Java api, which has a topicDistributions() method
that I think is just what I need here (but I'm 100% sure if the LDAModel in
Pyspark is in fact a DistributedLDAModel under the hood...).

In any case, I am able to indirectly call this method like so, without any
overt failures:

In [127]:'topicDistributions')
Out[127]: MapPartitionsRDD[3156] at mapPartitions at

But if I actually look at the results, all I get are strings telling me that
the result is actually a Scala tuple (I think):

In [128]:'topicDistributions').take(5)
[{u'__class__': u'scala.Tuple2'},
 {u'__class__': u'scala.Tuple2'},
 {u'__class__': u'scala.Tuple2'},
 {u'__class__': u'scala.Tuple2'},
 {u'__class__': u'scala.Tuple2'}]

Maybe this is generally the right approach, but is there way to get the
actual results?

Thanks in advance for any guidance you can offer!

View this message in context:
Sent from the Apache Spark User List mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message