Ich benutze Python gensim
, um ein Latent Dirichlet Allocation (LDA) Modell aus einem kleinen Korpus von 231 Sätzen zu trainieren. Jedes Mal, wenn ich den Vorgang wiederhole, erzeugt er jedoch verschiedene Themen.LDA-Modell erzeugt verschiedene Themen jedes Mal, wenn ich auf dem gleichen Korpus trainiere
Warum erzeugen dieselben LDA-Parameter und Corpus jedes Mal unterschiedliche Themen?
Und wie stabilisiere ich die Themengeneration?
ich diesen Korpus bin mit (http://pastebin.com/WptkKVF0) und diese Liste der Stoppwörter (http://pastebin.com/LL7dqLcj) und mein Code hier vor sich:
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
Wenn die traing Daten ausreichend ist, sollte das Ergebnis in begrenzten Schleifen zusammenlaufen. Ist es nicht? –
Darf ich wissen, wie setze ich 'numpy.random' auf' numpy.random.seed'? Könntest du mir ein Beispiel zeigen, wie man das 'ldamodel' mit' numpy.random.seed' bezeichnet? – alvas
@ 2er0 Sie setzen 'np.random' * nicht auf *' np.random.seed', Sie setzen den Startwert * mit * 'np.random.seed'. –