Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How To Use Gensim

Shohei Umemoto
September 12, 2015
580

How To Use Gensim

Shohei Umemoto

September 12, 2015
Tweet

Transcript

  1. 番組 ム 監督 作曲 ゲ 収録 ドラマ 制作 選手 アニメ

    小学校 isbn tbs 優勝 ラジオ 明治 鉄道 フジテレビ 高等 劇場 nhk 攻撃 試合 グ 市立 リ 選挙 チ km cm バス 神社 シ px 野球 国道 ret 江戸 fc 丁目 jr 京都 ダム 大正 廃止 設置 設定 ホ cd リリ ス 企業 文学 必要 対応 店舗 ガン 採用 状態 自分 法人 th love 事件 楽曲 医療 施設 製造 バンド 機関 改称 メンバ 空港 文化 専攻 学部 テ マ 工場 業務 管理 現代 書房 dvd live 小説 問題 共著 のち 講談社 公開 人口 作詞 政府 路線 記録 道路 議員 販売 教会 会社 獲得 搭載 戦闘 方面 装備 専門 病院 ライブ 追加 経済 大会 ドイツ 出場 製作 企画 中学校 原作 アルバム 漫画 教育 海軍 フランス イギリス 主義 選手権 戦争 株式会社 政治 世紀 編曲 都市 ズン 部隊 シングル 教授 営業 ロシア 事業 大統領 運行 プロ 委員 列車 サッカ 回戦 車両 クラブ 出版 合併 文庫 科学 指定 大阪 女子 成績 センタ 決勝 エンジン 区間 学科 システム モデル 元年 キャラクタ 交通 運転 公園 機能 県立 社会 能力 地区 交差点 郵便 地方 編入 設立 航空 課程
  2. 鳤剅׾אֻ׷ from gensim import corpora, models
 
 documents = ['ޗഐ͸ೣͰ͋Δɻ',


    '໊લ͸·ͩແ͍ɻ',
 'Ͳ͜ͰੜΕ͔ͨͱΜͱݟ౰͕͔ͭ͵ɻ'] 
  3. 鳤剅׾אֻ׷ from gensim import corpora, models
 
 documents = ['ޗഐ͸ೣͰ͋Δɻ',


    '໊લ͸·ͩແ͍ɻ',
 'Ͳ͜ͰੜΕ͔ͨͱΜͱݟ౰͕͔ͭ͵ɻ']
 
 texts = [['ޗഐ', '͸', 'ೣ', 'Ͱ', '͋Δ', 'ɻ'],
 ['໊લ', '͸', '·ͩ', 'ແ͍', 'ɻ'],
 ['Ͳ͜', 'Ͱ', 'ੜΕ', 'ͨ', '͔', 'ͱΜͱ', 'ݟ౰', '͕', '͔ͭ', '͵', 'ɻ']] 
  4. 鳤剅׾אֻ׷ from gensim import corpora, models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 texts

    = [['ޗഐ', '͸', 'ೣ', 'Ͱ', '͋Δ', 'ɻ'],
 ['໊લ', '͸', '·ͩ', 'ແ͍', 'ɻ'],
 ['Ͳ͜', 'Ͱ', 'ੜΕ', 'ͨ', '͔', 'ͱΜͱ', 'ݟ౰', '͕', '͔ͭ', '͵', 'ɻ']]
 
 texts = [['ޗഐ', 'ೣ'],
 ['໊લ'],
 ['Ͳ͜', 'ݟ౰']] 
  5. 鳤剅׾אֻ׷ from gensim import corpora, models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 texts

    = [['ޗഐ', ‘ೣ’], ...]
 
 dictionary = corpora.Dictionary(texts)
 
  6. ؝٦ػأ׾אֻ׷ from gensim import corpora, models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 texts

    = [['ޗഐ', ‘ೣ’], ...]
 
 dictionary = corpora.Dictionary(texts)
 
 corpus = [dictionary.doc2bow(t) for t in texts] 
  7. ٌرٕ׾אֻ׷ from gensim import corpora, models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 texts

    = [['ޗഐ', ‘ೣ’], ...]
 
 dictionary = corpora.Dictionary(texts)
 
 corpus = [dictionary.doc2bow(t) for t in texts]
 
 model = models.HdpModel(corpus, dictionary) 
  8. زؾحؙ׾⳿⸂ׅ׷ from gensim import corpora, models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 texts

    = [['ޗഐ', ‘ೣ’], ...]
 
 dictionary = corpora.Dictionary(texts)
 
 corpus = [dictionary.doc2bow(t) for t in texts]
 
 model = models.HdpModel(corpus, dictionary)
 
 print(model.show_topics()) 
  9. ؝٦ػأ׾אֻ׷ from gensim import models
 
 sentences = ['ޗഐ͸ೣͰ͋Δɻ',
 '໊લ͸·ͩແ͍ɻ',


    'Ͳ͜ͰੜΕ͔ͨͱΜͱݟ౰͕͔ͭ͵ɻ']
 
 sentences = [[‘ޗഐ ͸ ೣ Ͱ ͋Δ ɻ'],
 [‘໊લ ͸ ·ͩ ແ͍ ɻ'],
 [‘Ͳ͜ Ͱ ੜΕ ͨ ͔ ͱΜͱ ݟ౰ ͕ ͔ͭ ͵ ɻ']] 
  10. ٌرٕ׾אֻ׷ from gensim import models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 sentences =

    [[‘ޗഐ ͸ ೣ Ͱ ͋Δ ɻ’], ...]
 
 model = models.Word2Vec(sentences) 
  11. ⡂גְ׷⽃铂׾⳿⸂ׅ׷ from gensim import models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 sentences =

    [[‘ޗഐ ͸ ೣ Ͱ ͋Δ ɻ’], ...]
 
 model = models.Word2Vec(sentences)
 
 print(model.most_similar(positive=[’ೣ’])) 
  12. ⡂גְ׷⽃铂׾⳿⸂ׅ׷ from gensim import models
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 sentences =

    [[‘ޗഐ ͸ ೣ Ͱ ͋Δ ɻ’], ...]
 
 model = models.Word2Vec(sentences)
 
 print(model.most_similar(positive=[’ೣ’]))
 
 print(model.most_similar(positive=[’ޗഐ’, ’ೣ’], negative=[’໊લ’]))