Skip to content

Instantly share code, notes, and snippets.

@luizkowalski
Forked from rakasaka/gist:1169341
Created February 23, 2016 22:11
Show Gist options
  • Save luizkowalski/a7140af53bd64aa82a65 to your computer and use it in GitHub Desktop.
Save luizkowalski/a7140af53bd64aa82a65 to your computer and use it in GitHub Desktop.
Unsupervised topic modeling in Ruby using LDA
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