Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
"""
@Author: Arunav Mishra, Supratim Das
"""
import os
import gensim
from gensim import similarities
class LDA(object):
# Initialize
def __init__(self):
self.id2wordFile = '/Users/Supra/PycharmProjects/LDA/Input/OP/words.dict'
self.id2word = gensim.corpora.Dictionary.load(self.id2wordFile)
# Load the corpus files generated in the last step
self.corpusFile = '/Users/Supra/PycharmProjects/LDA/Input/OP/corpus.mm'
self.mm = gensim.corpora.MmCorpus(self.corpusFile)
# Run LDA
self.lda = gensim.models.ldamodel.LdaModel(corpus=self.mm, id2word=self.id2word, num_topics=100, update_every=0,
passes=20)
self.ldaFile = '/Users/Supra/PycharmProjects/LDA/Input/OP/lda'
self.dir_lda = os.path.dirname(self.ldaFile)
# Run LDA
def run(self):
try:
os.stat(self.dir_lda)
except:
os.mkdir(self.dir_lda)
self.lda.save(self.ldaFile)
index = similarities.MatrixSimilarity(self.lda[self.mm])
dir = os.path.dirname(self.ldaFile)
try:
os.stat(dir)
except:
os.mkdir(dir)
self.lda.save(self.ldaFile)
ldaIndexFile = '/Users/Supra/PycharmProjects/LDA/Input/OP/lda.index'
index.save(ldaIndexFile)
def main(self):
self.run()
if __name__ == '__main__':
LDA().main()