質問編集履歴
1
ソースコードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
LDAを実行したいのですが
|
1
|
-
|
2
|
+
以下のエラーが表示されます。何が原因か教えてください。
|
3
|
+

|
2
4
|
|
3
5
|
やりたいことのイメージとしては、フォルダの各テキストファイルのトピックを知りたいといった感じです。
|
4
6
|
|
5
|
-
ソースコードは以下の通りです。
|
7
|
+
ソースコードは以下の通りです(LDA.py)。
|
8
|
+
```python
|
6
9
|
import os
|
7
10
|
import codecs as cd
|
8
11
|
import gensim
|
@@ -21,6 +24,7 @@
|
|
21
24
|
for i, line in enumerate(lines):
|
22
25
|
word_vector = []
|
23
26
|
|
27
|
+
|
24
28
|
if len(line)<30:
|
25
29
|
continue
|
26
30
|
else:
|
@@ -30,12 +34,14 @@
|
|
30
34
|
if token.part_of_speech[:2] == '名詞':
|
31
35
|
word_vector += [token.base_form]
|
32
36
|
|
37
|
+
|
33
38
|
wvs += [word_vector]
|
34
39
|
|
35
40
|
dictionary = corpora.Dictionary(wvs)
|
36
41
|
dictionary.filter_extremes(no_below=2, no_above=0.3)
|
37
42
|
dictionary.save_as_text('dict.txt')
|
38
43
|
|
44
|
+
|
39
45
|
corpus = [dictionary.doc2bow(text) for text in wvs]
|
40
46
|
corpora.MmCorpus.serialize('cop.mm', corpus)
|
41
47
|
|
@@ -49,5 +55,6 @@
|
|
49
55
|
|
50
56
|
for i in range(topic_N):
|
51
57
|
print('TOPIC:', i, '__', lda.print_topic(i))
|
58
|
+
```
|
52
59
|
|
53
60
|
環境はwindows10,ubuntu16.04です。
|