-
-
Save niedfelj/01427d5bfb3436dbbe364a0415b2b5e4 to your computer and use it in GitHub Desktop.
Unsupervised topic modeling in Ruby using LDA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'lda-ruby' | |
| corpus = Lda::Corpus.new | |
| corpus.add_document(Lda::TextDocument.new(corpus, "a lion is a wild feline animal", [])) | |
| corpus.add_document(Lda::TextDocument.new(corpus, "a dog is a friendly animal", [])) | |
| corpus.add_document(Lda::TextDocument.new(corpus, "a cat is a feline animal", [])) | |
| lda = Lda::Lda.new(corpus) | |
| lda.verbose = false | |
| lda.num_topics = (2) | |
| lda.em('random') | |
| topics = lda.top_words(3) | |
| # Results | |
| # => {0=>["animal", "friendly", "dog"], 1=>["animal", "feline", "cat"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment