Guest User

Untitled

a guest
Feb 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. doc1 = "My favoruite TV series are Spartacus and Breaking Bad"
  2. doc2 = "My name is John Constantine and I am 27 years old."
  3. doc3 = "I am working as a Machine Learning Engineer."
  4. doc4 = "I love pokemons. Tyranitar is my favorite pokemon"
  5. doc5 = "Health experts say that Sugar is not good for your lifestyle."
  6.  
  7. # compile documents
  8. doc_complete = [doc1, doc2, doc3, doc4, doc5]
  9.  
  10. # I have done preprocessing in this step(haven't inclueded the full code.
  11. doc_clean = [clean(doc).split() for doc in doc_complete]
  12.  
  13. I then use gensim to make predicition.
  14. import gensim
  15. from gensim import corpora
  16. dictionary = corpora.Dictionary(doc_clean )
  17. doc_term_matrix = [dictionary.doc2bow(doc) for doc in doc_clean]
  18.  
  19. Lda = gensim.models.ldamodel.LdaModel
  20.  
  21. # Running and Trainign LDA model on the document term matrix.
  22. ldamodel = Lda(doc_term_matrix, num_topics=3, id2word = dictionary, passes=50)
  23. print ldamodel.show_topics(num_topics=3)
  24.  
  25. doc1 a b c
  26. doc2 b c d
  27. doc3 x y z
  28. doc4 l m o
  29. doc5 a c o
Add Comment
Please, Sign In to add comment