質問するログイン新規登録

質問編集履歴

2

新しいエラー

2019/10/08 06:57

投稿

kawauso.love
kawauso.love

スコア23

title CHANGED
File without changes
body CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  model = word2vec.Word2Vec(recipes, size=200,min_count=1)
35
35
 
36
- out = model.wv.most_similar()(positive=[u'レモン'])
36
+ out = model.wv.most_similar(positive=[u'レモン'])
37
37
  for x in out:
38
38
  print (x[0],x[1])
39
39
 
@@ -46,30 +46,39 @@
46
46
 
47
47
  ['片栗粉', '砂糖', 'オリーブ油', 'パウダー', 'チョコ', 'レモン', '卵', '感じ', '餅', '分量', 'カテゴリ', 'シリコン', '半', 'カラメル', '他', 'おから', 'ボウル', 'ボール', 'ハチミツ', '人気', 'ラップ', '饅頭', 'レンジ', '餡', 'バニラ', 'カップ', 'お菓子', '絶品', 'レン', '*', 'トレー', 'バット', '水', 'べら', '大福', '様子', 'トップ', '茶こし', '卵白', '真ん中', '生地', '牛乳', '玉子', '卵黄', '縦', 'エッセンス', 'レシピ', '横', 'ポイント', '見た目', 'だま', 'たま', '容器', 'イン', '木', '材料', '姉妹', '電子', 'ツノ', 'もち', 'ヨーグルト']
48
48
 
49
- と名詞は出てきたんですけど、
49
+   と名詞は出てきたんですけど、
50
+
51
+ ```python3
50
52
  ---------------------------------------------------------------------------
51
- ```python3
52
-
53
- ValueError Traceback (most recent call last)
53
+ KeyError Traceback (most recent call last)
54
- <ipython-input-25-6ff033f46253> in <module>
54
+ <ipython-input-31-32946ebb0ac4> in <module>
55
55
  35
56
56
  36 if __name__ == '__main__':
57
57
  ---> 37 main()
58
58
 
59
- <ipython-input-25-6ff033f46253> in main()
59
+ <ipython-input-31-32946ebb0ac4> in main()
60
60
  28 model = word2vec.Word2Vec(recipes, size=200,min_count=1)
61
61
  29
62
- ---> 30 out = model.wv.most_similar()(positive=[u'レモン'])
62
+ ---> 30 out = model.wv.most_similar(positive=[u'レモン'])
63
63
  31 for x in out:
64
64
  32 print (x[0],x[1])
65
65
 
66
66
  ~/anaconda3/lib/python3.7/site-packages/gensim/models/keyedvectors.py in most_similar(self, positive, negative, topn, restrict_vocab, indexer)
67
+ 551 mean.append(weight * word)
68
+ 552 else:
69
+ --> 553 mean.append(weight * self.word_vec(word, use_norm=True))
70
+ 554 if word in self.vocab:
67
71
  555 all_words.add(self.vocab[word].index)
68
- 556 if not mean:
69
- --> 557 raise ValueError("cannot compute similarity with no input")
70
- 558 mean = matutils.unitvec(array(mean).mean(axis=0)).astype(REAL)
71
- 559
72
72
 
73
+ ~/anaconda3/lib/python3.7/site-packages/gensim/models/keyedvectors.py in word_vec(self, word, use_norm)
74
+ 466 return result
75
+ 467 else:
76
+ --> 468 raise KeyError("word '%s' not in vocabulary" % word)
77
+ 469
78
+ 470 def get_vector(self, word):
73
- ValueError: cannot compute similarity with no input
79
+ KeyError: "word 'レモン' not in vocabulary"
80
+
74
81
  ```
75
- とエラーが出てきました。
82
+ とエラーが出てきました。
83
+
84
+ どうすればいいですか?

1

エラーコードの修正

2019/10/08 06:57

投稿

kawauso.love
kawauso.love

スコア23

title CHANGED
File without changes
body CHANGED
@@ -47,5 +47,29 @@
47
47
  ['片栗粉', '砂糖', 'オリーブ油', 'パウダー', 'チョコ', 'レモン', '卵', '感じ', '餅', '分量', 'カテゴリ', 'シリコン', '半', 'カラメル', '他', 'おから', 'ボウル', 'ボール', 'ハチミツ', '人気', 'ラップ', '饅頭', 'レンジ', '餡', 'バニラ', 'カップ', 'お菓子', '絶品', 'レン', '*', 'トレー', 'バット', '水', 'べら', '大福', '様子', 'トップ', '茶こし', '卵白', '真ん中', '生地', '牛乳', '玉子', '卵黄', '縦', 'エッセンス', 'レシピ', '横', 'ポイント', '見た目', 'だま', 'たま', '容器', 'イン', '木', '材料', '姉妹', '電子', 'ツノ', 'もち', 'ヨーグルト']
48
48
 
49
49
  と名詞は出てきたんですけど、
50
+ ---------------------------------------------------------------------------
51
+ ```python3
52
+
53
+ ValueError Traceback (most recent call last)
54
+ <ipython-input-25-6ff033f46253> in <module>
55
+ 35
56
+ 36 if __name__ == '__main__':
57
+ ---> 37 main()
58
+
59
+ <ipython-input-25-6ff033f46253> in main()
60
+ 28 model = word2vec.Word2Vec(recipes, size=200,min_count=1)
61
+ 29
62
+ ---> 30 out = model.wv.most_similar()(positive=[u'レモン'])
63
+ 31 for x in out:
64
+ 32 print (x[0],x[1])
65
+
66
+ ~/anaconda3/lib/python3.7/site-packages/gensim/models/keyedvectors.py in most_similar(self, positive, negative, topn, restrict_vocab, indexer)
67
+ 555 all_words.add(self.vocab[word].index)
68
+ 556 if not mean:
69
+ --> 557 raise ValueError("cannot compute similarity with no input")
70
+ 558 mean = matutils.unitvec(array(mean).mean(axis=0)).astype(REAL)
71
+ 559
72
+
50
73
  ValueError: cannot compute similarity with no input
74
+ ```
51
75
  とエラーが出てきました。