質問編集履歴
2
新しいエラー
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,7 +68,7 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
out = model.wv.most_similar(
|
71
|
+
out = model.wv.most_similar(positive=[u'レモン'])
|
72
72
|
|
73
73
|
for x in out:
|
74
74
|
|
@@ -94,17 +94,17 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
-
と名詞は出てきたんですけど、
|
97
|
+
と名詞は出てきたんですけど、
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```python3
|
98
102
|
|
99
103
|
---------------------------------------------------------------------------
|
100
104
|
|
101
|
-
|
105
|
+
KeyError Traceback (most recent call last)
|
102
106
|
|
103
|
-
|
104
|
-
|
105
|
-
ValueError Traceback (most recent call last)
|
106
|
-
|
107
|
-
<ipython-input-2
|
107
|
+
<ipython-input-31-32946ebb0ac4> in <module>
|
108
108
|
|
109
109
|
35
|
110
110
|
|
@@ -114,13 +114,13 @@
|
|
114
114
|
|
115
115
|
|
116
116
|
|
117
|
-
<ipython-input-2
|
117
|
+
<ipython-input-31-32946ebb0ac4> in main()
|
118
118
|
|
119
119
|
28 model = word2vec.Word2Vec(recipes, size=200,min_count=1)
|
120
120
|
|
121
121
|
29
|
122
122
|
|
123
|
-
---> 30 out = model.wv.most_similar(
|
123
|
+
---> 30 out = model.wv.most_similar(positive=[u'レモン'])
|
124
124
|
|
125
125
|
31 for x in out:
|
126
126
|
|
@@ -130,20 +130,38 @@
|
|
130
130
|
|
131
131
|
~/anaconda3/lib/python3.7/site-packages/gensim/models/keyedvectors.py in most_similar(self, positive, negative, topn, restrict_vocab, indexer)
|
132
132
|
|
133
|
+
551 mean.append(weight * word)
|
134
|
+
|
135
|
+
552 else:
|
136
|
+
|
137
|
+
--> 553 mean.append(weight * self.word_vec(word, use_norm=True))
|
138
|
+
|
139
|
+
554 if word in self.vocab:
|
140
|
+
|
133
141
|
555 all_words.add(self.vocab[word].index)
|
134
|
-
|
135
|
-
556 if not mean:
|
136
|
-
|
137
|
-
--> 557 raise ValueError("cannot compute similarity with no input")
|
138
|
-
|
139
|
-
558 mean = matutils.unitvec(array(mean).mean(axis=0)).astype(REAL)
|
140
|
-
|
141
|
-
559
|
142
142
|
|
143
143
|
|
144
144
|
|
145
|
+
~/anaconda3/lib/python3.7/site-packages/gensim/models/keyedvectors.py in word_vec(self, word, use_norm)
|
146
|
+
|
147
|
+
466 return result
|
148
|
+
|
149
|
+
467 else:
|
150
|
+
|
151
|
+
--> 468 raise KeyError("word '%s' not in vocabulary" % word)
|
152
|
+
|
153
|
+
469
|
154
|
+
|
155
|
+
470 def get_vector(self, word):
|
156
|
+
|
145
|
-
|
157
|
+
KeyError: "word 'レモン' not in vocabulary"
|
158
|
+
|
159
|
+
|
146
160
|
|
147
161
|
```
|
148
162
|
|
149
163
|
とエラーが出てきました。
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
どうすればいいですか?
|
1
エラーコードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,6 +96,54 @@
|
|
96
96
|
|
97
97
|
と名詞は出てきたんですけど、
|
98
98
|
|
99
|
+
---------------------------------------------------------------------------
|
100
|
+
|
101
|
+
```python3
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
ValueError Traceback (most recent call last)
|
106
|
+
|
107
|
+
<ipython-input-25-6ff033f46253> in <module>
|
108
|
+
|
109
|
+
35
|
110
|
+
|
111
|
+
36 if __name__ == '__main__':
|
112
|
+
|
113
|
+
---> 37 main()
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
<ipython-input-25-6ff033f46253> in main()
|
118
|
+
|
119
|
+
28 model = word2vec.Word2Vec(recipes, size=200,min_count=1)
|
120
|
+
|
121
|
+
29
|
122
|
+
|
123
|
+
---> 30 out = model.wv.most_similar()(positive=[u'レモン'])
|
124
|
+
|
125
|
+
31 for x in out:
|
126
|
+
|
127
|
+
32 print (x[0],x[1])
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
~/anaconda3/lib/python3.7/site-packages/gensim/models/keyedvectors.py in most_similar(self, positive, negative, topn, restrict_vocab, indexer)
|
132
|
+
|
133
|
+
555 all_words.add(self.vocab[word].index)
|
134
|
+
|
135
|
+
556 if not mean:
|
136
|
+
|
137
|
+
--> 557 raise ValueError("cannot compute similarity with no input")
|
138
|
+
|
139
|
+
558 mean = matutils.unitvec(array(mean).mean(axis=0)).astype(REAL)
|
140
|
+
|
141
|
+
559
|
142
|
+
|
143
|
+
|
144
|
+
|
99
145
|
ValueError: cannot compute similarity with no input
|
100
146
|
|
147
|
+
```
|
148
|
+
|
101
149
|
とエラーが出てきました。
|