SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
cl-online-learningによる文書分類
Satoshi Imai
Twitter: @masatoi0
Github: masatoi
文書分類
●
文書をカテゴリに分類するのが目標
– 応用例
●
ニュース記事のジャンル分け
●
スパムフィルタ
● SNSの感情分析
●
経済予測
● Common Lispのみでわりと簡単にできる!
どういうデータになる?
●
文書の中で単語が出現する回数をカウントしたベク
トル
●
文書群全体で出てくる単語の数が次元数になる
●
一つの文書の中で出現する単語は少ない
→ 高次元でかつ疎なベクトル
疎ベクトルの扱い方
●
値の入っている要素のインデックスとその値のペアを保
存しておけばいい (数十〜数百倍の高速化)
●
疎ベクトルの演算をいろいろ定義しておく
– 疎ベクトルと密ベクトルとの和、差、要素積
– 疎ベクトルの定数倍
(defstruct (sparse­vector (:constructor %make­sparse­vector))
  (length 0 :type fixnum)
  (index­vector #() :type (simple­array fixnum))
  (value­vector #() :type (simple­array double­float)))
形態素解析器: cl-igo
● MeCab互換の形態素解析器
– MeCabの辞書をJavaプログラムで変換して使う
– 解析時はCommon Lispのみ
CL­USER> (igo:load­tagger "/path/to/igo/ipadic/")
#<IGO::TAGGER {1003B89C43}>
CL­USER> (igo:parse "隣の客はよく柿食う客だ。")
(("隣" "名詞,一般,*,*,*,*,隣,トナリ,トナリ" 0)
 ("の" "助詞,連体化,*,*,*,*,の,ノ,ノ" 1)
 ("客" "名詞,一般,*,*,*,*,客,キャク,キャク" 2)
 ("は" "助詞,係助詞,*,*,*,*,は,ハ,ワ" 3)
 ("よく" "副詞,一般,*,*,*,*,よく,ヨク,ヨク" 4)
 ("柿" "名詞,一般,*,*,*,*,柿,カキ,カキ" 6)
 ("食う" "動詞,自立,*,*,五段・ワ行促音便,基本形,食う,クウ,クウ" 7)
 ("客" "名詞,一般,*,*,*,*,客,キャク,キャク" 9)
 ("だ" "助動詞,*,*,*,特殊・ダ,基本形,だ,ダ,ダ" 10)
 ("。" "記号,句点,*,*,*,*,。,。,。" 11))
単語とインデックスの対応を取るハッシュ表
●
単語にインデックスを振りたい
– 単語の文字列をキーとするハッシュ表をつくる
– ハッシュ表に登録されていない単語に出会ったらカウン
タをインクリメントしてハッシュ表に登録していく
特徴量: TF-IDF
● Term Frequency–Inverse Document Frequency
● t: 単語、 d: 文書
● :文書d中の単語tの出現回数
● D : 全文書数
● df(t) : 単語tが出現する文書数
●
文書分類でよく使われる特徴量
特徴量: TF-IDF
● Term Frequency–Inverse Document Frequency
● t: 単語、 d: 文書
● :文書d中の単語tの出現頻度
● D : 全文書数
● df(t) : 単語tが出現する文書数
ある1文書の中で単語tがどれだけ重要か
(dを固定すると疎ベクトル)
全文書を横断して単語tがどれだけ
一般的か (密ベクトル)
線形分類器: cl-online-learning
●
線形分類の割と最近の手法までをカバー
– Quicklispから入る
– 二値分類器を複数個組み合わせてマルチクラス分類で
きる
– データが疎ベクトルの場合にも対応
– かなり速い
線形分類器: cl-online-learning
●
一個のデータ点の形式
– ラベル(二値分類の場合は+1/-1、マルチクラス分類の場
合は整数)とデータベクトル(密or疎)のcons
● データ点のシーケンス(リストorベクタ)がデータセッ
トになる
cl-online-learning: 使い方
(defparameter a9a­dim 123)
(defparameter a9a­train (read­data "/path/to/a9a" a9a­dim))
(defparameter a9a­test (read­data "/path/to/a9a.t" a9a­dim))
(defparameter arow­learner (make­arow a9a­dim 10d0))
(train arow­learner a9a­train)
(test arow­learner a9a­test)
データ読み込み
モデル定義、訓練、テスト
マルチクラス、疎ベクトルのとき
(defparameter mnist­dim 780)
(defparameter mnist­train.sp
  (read­data "/path/to/mnist.scale" mnist­dim :sparse­p t :multiclass­p t))
(defparameter mnist­test.sp
  (read­data "/path/to/mnist.scale.t" mnist­dim :sparse­p t :multiclass­p t))
(defparameter mnist­arow
  (make­one­vs­one mnist­dim 10 'sparse­arow 10d0))
(defparameter mnist­arow
  (make­one­vs­rest mnist­dim 10 'sparse­arow 10d0))
(train mnist­arow mnist­train)
(test mnist­arow mnist­test)
データ読み込み
モデル定義、訓練、テスト one-vs-oneはクラス数Kのとき
K(K-1)/2個の二値分類器が必要
マルチクラス、疎ベクトルのとき
(defparameter mnist­dim 780)
(defparameter mnist­train.sp
  (read­data "/path/to/mnist.scale" mnist­dim :sparse­p t :multiclass­p t))
(defparameter mnist­test.sp
  (read­data "/path/to/mnist.scale.t" mnist­dim :sparse­p t :multiclass­p t))
(defparameter mnist­arow
  (make­one­vs­one mnist­dim 10 'sparse­arow 10d0))
(defparameter mnist­arow
  (make­one­vs­rest mnist­dim 10 'sparse­arow 10d0))
(train mnist­arow mnist­train)
(test mnist­arow mnist­test)
データ読み込み
モデル定義、訓練、テスト
one-vs-restはクラス数Kのとき
K-1個の二値分類器が必要
cl-online-learning: ベンチマーク
● a9aデータ (二値分類)
● MNIST (マルチクラス分類)
データ読み込みから学習
完了までの時間
テストデータでの正答率
cl-online-learning
(AROW, Sparse)
26.0 secs 94.65%
LIBLINEAR 146.8 secs 91.69%
データ読み込みから1000
エポック学習するまでの時
間
テストデータでの正答率
cl-online-learning
(AROW, Sparse)
3.829 secs 84.964066%
AROW++ (C++) 58.328 secs 84.989%
文書分類の例: livedoorニュースコーパス
● livedoorニュースの記事を9カテゴリに分けたもの
– http://www.rondhuit.com/download.html#ldcc
●http://news.livedoor.com/article/detail/5914835/
2011-10-05T18:12:00+0900
毎年話題になるベストジーニスト賞の偏り
今年のベストジーニスト一般選出部門に相葉雅紀、黒木メイサが選出された。その選出が“5年ぶりの新顔”と話
題になっている。
・ベストジーニスト2011に相葉雅紀&黒木メイサ 5年ぶり“新顔”
“5年ぶりの新顔”とは一体どういうことなのか、過去の記録を確認してみたところ、
驚くべき結果が明らかになった。
ベストジーニストには、一般選出部門と協議会選出部門がある。“5年ぶりの新顔”が出た一般選出部門は、全国
からの一般投票で選ばれる、とされている。
ところが、男性はジャニーズ事務所の、女性はエイベックスの芸能人ばかりが選出されていることがわかる。
文書分類の例: livedoorニュースコーパス
● 73021次元のデータが7367個
– 実際にはほとんどのデータで数百次元しか値が入ってい
ない疎なデータ
livedoorニュースコーパスの分類
サンプルコード
● https://github.com/masatoi/cl-docclass
– ファイルのリストからtf-idfのリストを作る
– ディレクトリ構造からクラスラベルをつける
– 同じクラスラベルが連続すると学習に悪影響なので順序を
シャッフルする
● 7367個のデータのうち1000個をテストデータ、残りを訓
練データとして学習
– 10回平均でテストデータの正答率が95.5%
学習の進行過程
深層学習での例
●
深層学習でニュース記事を分類する
– http://qiita.com/hogefugabar/items/c27ed578717c
5e7288c0
– Denoising Autoencoderを3層重ねて事前学習してから
ファインチューニング
– テストデータで95%
●
線形分類器とほぼ同等。しかし計算速度は線形分
類器の方がはるかに速い
まとめ
● livedoorニュースコーパスからTF-IDFで特徴量を
作って線形分類器でマルチクラス分類した
●
高次元データでも疎なデータは効率的に計算でき
る
●
文書分類では深層学習でも線形分類器と大して差
はない。問題に応じて適切なモデルを選ぼう

Contenu connexe

En vedette

Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装
Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装
Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装Satoshi imai
 
Lispmeetup #45 Common Lispで音声合成
Lispmeetup #45 Common Lispで音声合成Lispmeetup #45 Common Lispで音声合成
Lispmeetup #45 Common Lispで音声合成Satoshi imai
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lispfukamachi
 
Lispmeetup #39 MGLの紹介: Common Lispによるディープラーニング
Lispmeetup #39 MGLの紹介: Common LispによるディープラーニングLispmeetup #39 MGLの紹介: Common Lispによるディープラーニング
Lispmeetup #39 MGLの紹介: Common LispによるディープラーニングSatoshi imai
 
Lisp meetup #29 cl-online-learningの紹介
Lisp meetup #29 cl-online-learningの紹介Lisp meetup #29 cl-online-learningの紹介
Lisp meetup #29 cl-online-learningの紹介Satoshi imai
 
All inclusive design - excluding no gender
All inclusive design - excluding no genderAll inclusive design - excluding no gender
All inclusive design - excluding no genderSara Lerén
 
Conquering The Context Conundrum
Conquering The Context ConundrumConquering The Context Conundrum
Conquering The Context ConundrumDaniel Eizans
 
WordCamp Phoenix 2012
WordCamp Phoenix 2012WordCamp Phoenix 2012
WordCamp Phoenix 2012Jay Thompson
 
Intro to Git
Intro to GitIntro to Git
Intro to Gitojtibi
 
An Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp PhoenixAn Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp Phoenixvegasgeek
 
All out in the Cloud - CloudEast 2012
All out in the Cloud - CloudEast 2012All out in the Cloud - CloudEast 2012
All out in the Cloud - CloudEast 2012Jan Jongboom
 
What's our Status?
What's our Status?What's our Status?
What's our Status?Dirk Haun
 
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Nathan O'Hanlon
 
On Shrink It and Pink It: Designing Experiences for Women
On Shrink It and Pink It: Designing Experiences for WomenOn Shrink It and Pink It: Designing Experiences for Women
On Shrink It and Pink It: Designing Experiences for WomenJessica Ivins
 
目grep入門
目grep入門目grep入門
目grep入門murachue
 
Building a Responsive Web Design Process
Building a Responsive Web Design ProcessBuilding a Responsive Web Design Process
Building a Responsive Web Design ProcessLydia Whitehead
 

En vedette (20)

Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装
Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装
Lispmeetup #50 cl-random-forest: Common Lispによるランダムフォレストの実装
 
Lispmeetup #45 Common Lispで音声合成
Lispmeetup #45 Common Lispで音声合成Lispmeetup #45 Common Lispで音声合成
Lispmeetup #45 Common Lispで音声合成
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lisp
 
SBLint
SBLintSBLint
SBLint
 
Lispmeetup #39 MGLの紹介: Common Lispによるディープラーニング
Lispmeetup #39 MGLの紹介: Common LispによるディープラーニングLispmeetup #39 MGLの紹介: Common Lispによるディープラーニング
Lispmeetup #39 MGLの紹介: Common Lispによるディープラーニング
 
Lisp meetup #29 cl-online-learningの紹介
Lisp meetup #29 cl-online-learningの紹介Lisp meetup #29 cl-online-learningの紹介
Lisp meetup #29 cl-online-learningの紹介
 
Internship @ pixiv
Internship @ pixivInternship @ pixiv
Internship @ pixiv
 
All inclusive design - excluding no gender
All inclusive design - excluding no genderAll inclusive design - excluding no gender
All inclusive design - excluding no gender
 
Conquering The Context Conundrum
Conquering The Context ConundrumConquering The Context Conundrum
Conquering The Context Conundrum
 
WordCamp Phoenix 2012
WordCamp Phoenix 2012WordCamp Phoenix 2012
WordCamp Phoenix 2012
 
Intro to Git
Intro to GitIntro to Git
Intro to Git
 
Mwhackathon 2012
Mwhackathon 2012Mwhackathon 2012
Mwhackathon 2012
 
An Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp PhoenixAn Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp Phoenix
 
All out in the Cloud - CloudEast 2012
All out in the Cloud - CloudEast 2012All out in the Cloud - CloudEast 2012
All out in the Cloud - CloudEast 2012
 
No Fear
No FearNo Fear
No Fear
 
What's our Status?
What's our Status?What's our Status?
What's our Status?
 
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
 
On Shrink It and Pink It: Designing Experiences for Women
On Shrink It and Pink It: Designing Experiences for WomenOn Shrink It and Pink It: Designing Experiences for Women
On Shrink It and Pink It: Designing Experiences for Women
 
目grep入門
目grep入門目grep入門
目grep入門
 
Building a Responsive Web Design Process
Building a Responsive Web Design ProcessBuilding a Responsive Web Design Process
Building a Responsive Web Design Process
 

Similaire à Lispmeetup48 cl-online-learningによる文書分類

Big Data入門に見せかけたFluentd入門
Big Data入門に見せかけたFluentd入門Big Data入門に見せかけたFluentd入門
Big Data入門に見せかけたFluentd入門Keisuke Takahashi
 
モジュールの凝集度・結合度・インタフェース
モジュールの凝集度・結合度・インタフェースモジュールの凝集度・結合度・インタフェース
モジュールの凝集度・結合度・インタフェースHajime Yanagawa
 
All-but-the-Top: Simple and Effective Postprocessing for Word Representations
All-but-the-Top: Simple and Effective Postprocessing for Word RepresentationsAll-but-the-Top: Simple and Effective Postprocessing for Word Representations
All-but-the-Top: Simple and Effective Postprocessing for Word RepresentationsMakoto Takenaka
 
情報検索とゼロショット学習
情報検索とゼロショット学習情報検索とゼロショット学習
情報検索とゼロショット学習kt.mako
 
Textdata processing
Textdata processingTextdata processing
Textdata processingyuki uchida
 
とある制作会社の目次索引作成技法
とある制作会社の目次索引作成技法とある制作会社の目次索引作成技法
とある制作会社の目次索引作成技法Kenshi Muto
 
201207 ssmjp
201207 ssmjp201207 ssmjp
201207 ssmjpth0x0472
 
リサーチ・ナビ検索システムの技術
リサーチ・ナビ検索システムの技術リサーチ・ナビ検索システムの技術
リサーチ・ナビ検索システムの技術Yoji Kiyota
 
WWW2018 論文読み会 Web Search and Mining
WWW2018 論文読み会 Web Search and MiningWWW2018 論文読み会 Web Search and Mining
WWW2018 論文読み会 Web Search and Miningcyberagent
 
サポーターズ勉強会スライド 2018/2/27
サポーターズ勉強会スライド 2018/2/27サポーターズ勉強会スライド 2018/2/27
サポーターズ勉強会スライド 2018/2/27Kensuke Mitsuzawa
 
リレーショナルデータベースとの上手な付き合い方 long version
リレーショナルデータベースとの上手な付き合い方 long version リレーショナルデータベースとの上手な付き合い方 long version
リレーショナルデータベースとの上手な付き合い方 long version Mikiya Okuno
 
Neural Concept Network v0.2 (ja)
Neural Concept Network v0.2 (ja)Neural Concept Network v0.2 (ja)
Neural Concept Network v0.2 (ja)AkihiroYamamoto
 
Twitterテキストのトピック分析
Twitterテキストのトピック分析Twitterテキストのトピック分析
Twitterテキストのトピック分析Nobuyuki Kawagashira
 
深層生成モデルと世界モデル, 深層生成モデルライブラリPixyzについて
深層生成モデルと世界モデル,深層生成モデルライブラリPixyzについて深層生成モデルと世界モデル,深層生成モデルライブラリPixyzについて
深層生成モデルと世界モデル, 深層生成モデルライブラリPixyzについてMasahiro Suzuki
 
情報検索の基礎 第1章 論理検索
情報検索の基礎 第1章 論理検索情報検索の基礎 第1章 論理検索
情報検索の基礎 第1章 論理検索nishioka1
 

Similaire à Lispmeetup48 cl-online-learningによる文書分類 (16)

AIと金融
AIと金融AIと金融
AIと金融
 
Big Data入門に見せかけたFluentd入門
Big Data入門に見せかけたFluentd入門Big Data入門に見せかけたFluentd入門
Big Data入門に見せかけたFluentd入門
 
モジュールの凝集度・結合度・インタフェース
モジュールの凝集度・結合度・インタフェースモジュールの凝集度・結合度・インタフェース
モジュールの凝集度・結合度・インタフェース
 
All-but-the-Top: Simple and Effective Postprocessing for Word Representations
All-but-the-Top: Simple and Effective Postprocessing for Word RepresentationsAll-but-the-Top: Simple and Effective Postprocessing for Word Representations
All-but-the-Top: Simple and Effective Postprocessing for Word Representations
 
情報検索とゼロショット学習
情報検索とゼロショット学習情報検索とゼロショット学習
情報検索とゼロショット学習
 
Textdata processing
Textdata processingTextdata processing
Textdata processing
 
とある制作会社の目次索引作成技法
とある制作会社の目次索引作成技法とある制作会社の目次索引作成技法
とある制作会社の目次索引作成技法
 
201207 ssmjp
201207 ssmjp201207 ssmjp
201207 ssmjp
 
リサーチ・ナビ検索システムの技術
リサーチ・ナビ検索システムの技術リサーチ・ナビ検索システムの技術
リサーチ・ナビ検索システムの技術
 
WWW2018 論文読み会 Web Search and Mining
WWW2018 論文読み会 Web Search and MiningWWW2018 論文読み会 Web Search and Mining
WWW2018 論文読み会 Web Search and Mining
 
サポーターズ勉強会スライド 2018/2/27
サポーターズ勉強会スライド 2018/2/27サポーターズ勉強会スライド 2018/2/27
サポーターズ勉強会スライド 2018/2/27
 
リレーショナルデータベースとの上手な付き合い方 long version
リレーショナルデータベースとの上手な付き合い方 long version リレーショナルデータベースとの上手な付き合い方 long version
リレーショナルデータベースとの上手な付き合い方 long version
 
Neural Concept Network v0.2 (ja)
Neural Concept Network v0.2 (ja)Neural Concept Network v0.2 (ja)
Neural Concept Network v0.2 (ja)
 
Twitterテキストのトピック分析
Twitterテキストのトピック分析Twitterテキストのトピック分析
Twitterテキストのトピック分析
 
深層生成モデルと世界モデル, 深層生成モデルライブラリPixyzについて
深層生成モデルと世界モデル,深層生成モデルライブラリPixyzについて深層生成モデルと世界モデル,深層生成モデルライブラリPixyzについて
深層生成モデルと世界モデル, 深層生成モデルライブラリPixyzについて
 
情報検索の基礎 第1章 論理検索
情報検索の基礎 第1章 論理検索情報検索の基礎 第1章 論理検索
情報検索の基礎 第1章 論理検索
 

Lispmeetup48 cl-online-learningによる文書分類