मैं 231 वाक्यों के एक छोटे से कॉर्पस से लेटेंट ड्रिचलेट आवंटन (एलडीए) मॉडल को प्रशिक्षित करने के लिए पाइथन gensim
का उपयोग कर रहा हूं। हालांकि, हर बार जब मैं प्रक्रिया दोहराता हूं, तो यह विभिन्न विषयों को उत्पन्न करता है।एलडीए मॉडल हर बार अलग-अलग विषयों को उत्पन्न करता है जब मैं उसी कॉर्पस पर ट्रेन करता हूं
वही एलडीए पैरामीटर और कॉर्पस हर बार विभिन्न विषयों को क्यों उत्पन्न करता है?
और मैं विषय पीढ़ी को कैसे स्थिर करूं?
मैं इस कोष (http://pastebin.com/WptkKVF0) और stopwords की इस सूची (http://pastebin.com/LL7dqLcj) का उपयोग कर रहा हूँ और यहाँ मेरे कोड है:
from gensim import corpora, models, similarities
from gensim.models import hdpmodel, ldamodel
from itertools import izip
from collections import defaultdict
import codecs, os, glob, math
stopwords = [i.strip() for i in codecs.open('stopmild','r','utf8').readlines() if i[0] != "#" and i != ""]
def generateTopics(corpus, dictionary):
# Build LDA model using the above corpus
lda = ldamodel.LdaModel(corpus, id2word=dictionary, num_topics=50)
corpus_lda = lda[corpus]
# Group topics with similar words together.
tops = set(lda.show_topics(50))
top_clusters = []
for l in tops:
top = []
for t in l.split(" + "):
top.append((t.split("*")[0], t.split("*")[1]))
top_clusters.append(top)
# Generate word only topics
top_wordonly = []
for i in top_clusters:
top_wordonly.append(":".join([j[1] for j in i]))
return lda, corpus_lda, top_clusters, top_wordonly
#######################################################################
# Read textfile, build dictionary and bag-of-words corpus
documents = []
for line in codecs.open("./europarl-mini2/map/coach.en-es.all","r","utf8"):
lemma = line.split("\t")[3]
documents.append(lemma)
texts = [[word for word in document.lower().split() if word not in stopwords]
for document in documents]
dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
lda, corpus_lda, topic_clusters, topic_wordonly = generateTopics(corpus, dictionary)
for i in topic_wordonly:
print i
हैं, तो परिणाम सीमित छोरों में अभिसरण चाहिए:
विशेष रूप से, आप बस अनुसरण विकल्प जोड़ने। यही है ना –
क्या मुझे पता है कि मैं 'numpy.random' को' numpy.random.seed' पर कैसे सेट करूं? क्या आप मुझे 'numpy.random.seed' के साथ 'ldamodel' को कॉल करने का उदाहरण दिखा सकते हैं? – alvas
@ 2er0 आप 'np.random' * से *' np.random.seed' सेट नहीं करते हैं, तो आप * * np.random.seed' के साथ बीज * सेट करते हैं। –