Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -m pip install -U gensim
次のページで公開されているプログラムを使用する.
上のページの注意書きにもある通り,2G バイトのファイルがダウンロードされます.
import gensim.downloader as api wv = api.load('word2vec-google-news-300') for i, word in enumerate(wv.vocab): if i == 10: break print(word)
words = ['car', 'minivan', 'bicycle', 'airplane', 'cereal', 'communism'] for w in words: print(wv[w])
pairs = [ ('car', 'minivan'), # a minivan is a kind of car ('car', 'bicycle'), # still a wheeled vehicle ('car', 'airplane'), # ok, no wheels, but still a vehicle ('car', 'cereal'), # ... and so on ('car', 'communism'), ] for w1, w2 in pairs: print('%r\t%r\t%.2f' % (w1, w2, wv.similarity(w1, w2)))
print(wv.most_similar(positive=['car', 'minivan'], topn=5))