本文整理汇总了Python中corpus.Corpus.readDocsSample方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.readDocsSample方法的具体用法?Python Corpus.readDocsSample怎么用?Python Corpus.readDocsSample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.readDocsSample方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Corpus
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import readDocsSample [as 别名]
import pprint
import sklearn
t0 = time.time()
k=100
alpha = .1
beta = .01
sampleFile = 'ap.txt'
#sampleFile = 'ap2.text'
sample_vocab = 'vocab.txt'
corpus = Corpus()
corpus.num_docs = corpus.getNumOfSampleDocs(sampleFile)
corpus.vocab,corpus.num_terms = corpus.getSampleVocab(sample_vocab)
corpus.readDocsSample(sampleFile)
#document-topic
DTMatrix = matlib.zeros((corpus.num_docs,k),dtype='float_')
#term,topic matrix
TTMatrix =matlib.zeros((corpus.num_terms,k),dtype='float_')
vocab_index_dict = {word.rstrip():index for index, word in enumerate(corpus.vocab)}
vocab_word_dict = {index:word for word,index in vocab_index_dict.iteritems()}
DocVocab = {}
#doc is an int
for doc_num,words in corpus.docs.iteritems():
#sample topic index for word
#each word in a document gets assigned a topic
#words = set(vocab_index_dict.keys()) & set(words)
#print 'On doc %d' % doc_num
for word in words: