는 당신이 인덱스가를 대표하는 스파 스 벡터를 얻을이 코드에서 단어 표현
from gensim import utils, models
from gensim.corpora import Dictionary
lda = models.LdaModel.load('saved_lda.model') # load saved model
dictionary = Dictionary.load('saved_dictionary.dict') # load saved dict
text = ' '
with open('document', 'r') as inp: # convert file to string
for line in inp:
text += line + ' '
tkn_doc = utils.simple_preprocess(text) # filter & tokenize words
doc_bow = dictionary.doc2bow(tkn_doc) # use dictionary to create bow
doc_vec = lda[doc_bow] # this is the topic probability distribution for the document of interest
의 가방에 관심있는 문서를 변환 할 필요가 주제 0 .... n이고 각 '가중치'는 문서의 단어가 모델의 해당 주제에 속할 확률입니다. matplotlib를 사용하여 막대 그래프를 작성하여 분포를 시각화 할 수 있습니다.
![enter image description here](https://i.stack.imgur.com/w4Z5V.png)
당신이 print them like this 할 수있는 각 항목의을 TopN 조건을보고 싶다면
y_axis = []
x_axis = []
for topic_id, dist in enumerate(doc_vec):
x_axis.append(topic_id + 1)
y_axis.append(dist)
width = 1
plt.bar(x_axis, y_axis, width, align='center', color='r')
plt.xlabel('Topics')
plt.ylabel('Probability')
plt.title('Topic Distribution for doc')
plt.xticks(np.arange(2, len(x_axis), 2), rotation='vertical', fontsize=7)
plt.subplots_adjust(bottom=0.2)
plt.ylim([0, np.max(y_axis) + .01])
plt.xlim([0, len(x_axis) + 1])
plt.savefig(output_path)
plt.close()
. 그래프를 참조하여 인쇄 한 상위 단어를 찾아 모델이 문서를 해석 한 방법을 결정할 수 있습니다. hellinger distance, euclidean, jensen shannon 등과 같은 벡터 계산을 사용하여 두 가지 문서 확률 분포 벡터 간의 거리를 찾을 수도 있습니다.
토픽이 쿼리 문자열에 포함되거나 상호 배타적 일 수 있습니까? –
@ NathanMcCoy 상호 배타적입니다. gensim이 주제에 관해 이야기 할 때 단어의 일반적인 영어 의미를 의미하는 것은 아니며 부동 소수점 가중치와 함께 단어 벡터로 구성된 데이터 구조를 의미합니다. – rwallace