u++の備忘録

言語処理100本ノック 2020「62. 類似度の高い単語10件」

問題文

nlp100.github.io

問題の概要

most_similar *1 を使います。topn で上位何件を返すかを指定できます。デフォルトで topn=10 となっていますが、分かりやすさのために敢えて明示的に指定しています。

from gensim.models import KeyedVectors

model = KeyedVectors.load_word2vec_format('ch07/GoogleNews-vectors-negative300.bin', binary=True)
result = model.most_similar(positive=['United_States'], topn=10)
print(result)