Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments: PySpark with Latent Dirichlet Allocation #2

Open
seanlane opened this issue May 10, 2016 · 7 comments
Open

Comments: PySpark with Latent Dirichlet Allocation #2

seanlane opened this issue May 10, 2016 · 7 comments

Comments

@seanlane
Copy link
Owner

seanlane commented May 10, 2016

Comments for my blog post on Latent Dirichlet Allocation with PySpark: https://sean.lane.sh/blog/2016/PySpark_and_LDA

@DoudouT
Copy link

DoudouT commented Feb 1, 2017

Hi,

A very nice post! Thank you very much!

Do you know how to get the topic distribution for each training document? I read a bit on https://spark.apache.org/docs/latest/mllib-clustering.html#latent-dirichlet-allocation-lda. Based on that, it should be possible to get the topic distribution for each train document through topTopicsPerDocument. But I got error saying that there is no such attribute.

Cheers,
Doudou

@seanlane
Copy link
Owner Author

seanlane commented Feb 5, 2017

Hi Doudou,

Unfortunately, as of the current version of PySpark (2.1), there isn't a way to do that. However, it is possible with the regular Spark project. PySpark is largely a Python wrapper over the original Apache Spark project, which is written in Scala. You can use the topTopicsPerDocument method found here: https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.mllib.clustering.DistributedLDAModel

And while it currently isn't possible in PySpark, you can follow the same process I've written about in this post in Spark to achieve the same results. Good luck!

Sean Lane

@DoudouT
Copy link

DoudouT commented Feb 7, 2017 via email

@seanlane
Copy link
Owner Author

seanlane commented Feb 7, 2017

It's hard to tell, but I would suggest reading through the errors that occur when the transform method doesn't work, they should help you understand what problems are occurring. Good luck!

@mahmoudparsian
Copy link

Hi Sean Lane,

This is a great post and I am thinking about posting the Java version of it in my upcoming book: Data Algorithms, 2nd Edition.

One question: in the last line of your code you refer to "topic_val", which is not defined anywhere in the code. Should that be "topic_indices"?

Thank you,
best regards,
Mahmoud Parsian

@seanlane
Copy link
Owner Author

seanlane commented Jul 7, 2017

Hi Mahmoud,

Thank you for pointing that out, it was actually a holdover from an iteration on this code where I was playing with different number of topics for a different dataset. I have corrected the error, along with some other inconsistencies that I noticed, and it should be correct now. Good luck with your book!

Thanks,
Sean

@mahmoudparsian
Copy link

mahmoudparsian commented Jul 9, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants