Skip to content

Instantly share code, notes, and snippets.

@niedfelj
Forked from rakasaka/gist:1169341
Created July 19, 2016 14:20
Show Gist options
  • Select an option

  • Save niedfelj/01427d5bfb3436dbbe364a0415b2b5e4 to your computer and use it in GitHub Desktop.

Select an option

Save niedfelj/01427d5bfb3436dbbe364a0415b2b5e4 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