Your SlideShare is downloading. ×
Active ModelとNaive Bayesを仲良くする
baby_faceを使ってみた
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Active ModelとNaive Bayesを仲良くする
baby_faceを使ってみた

1,149

Published on

Published in: Technology, Self Improvement
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,149
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Active ModelとNaive Bayes を仲良くする
 baby_faceを使ってみた @chezou
  • 2. Who? • @chezou / github.com/chezou • Software Engineer at Cookpad
  • 3. baby_face • @yoshiori さんが作ったgem • https://github.com/yoshiori/baby_face • ナイーブベイズとActive Modelをつないでくれ る便利なGem • Railsでお手軽に分類ができる!
  • 4. デモアプリ作ってみた • 2chのゲームスレッドをもとに分類 • https://github.com/chezou/merone
  • 5. デモ
  • 6. Model def segment(text) @tagger ||= TinySegmenter.new @tagger.segment(text, ignore_punctuation: true) end ! class Entry < ActiveRecord::Base include BabyFace baby_face_for features: [:comment], categories: [:dragon_quest, :monster_hanter, :skyrim], tokenizer: ->(text) { segment(text) } end
  • 7. サンプルデータ • neconeco_gen用に用意されたデータを使用 • 2chのDQ, モンハン, Skyrimのスレッドのコメ ント
  • 8. データの取得と学習 #neconeco_gen用テストデータを取得 mkdir data cd data wget -i http://www.udp.jp/misc/2ch_data/ cd .. # テストデータをDBに追加・学習 bundle exec bin/rails runner -e development Tasks::CreateBatch.execute
  • 9. 学習スクリプト(抜粋) ! ! ! def self.execute categories = { dragon_quest: "dragon_quest", monster_hanter: "mhf", skyrim: "skyrim" } categories.each do |category, file| self.open_and_create("./data/#{file}.txt", category) end Entry.where.not(comment: nil).first.baby_face.save end def self.create_with_train(text, category) e = Entry.create(comment: text) method = "train_#{category}".intern e.baby_face.send(method) end
  • 10. 実際に使う上でのポイント • 既に分類したいものがたまっている方が楽 • 学習していないカテゴリがあると正常に予測し ない • MeCabはgemで使いづらいからHerokuでやる ならTinySegmenterおすすめ

×