ã®ã¬ã³ãç»å ´ï¼BM25ãªPerlã¢ã¸ã¥ã¼ã«æ¸ããã
ä¹ ãã¶ãã«ä½ãæ¸ãã¾ãã
æ
å ±æ¤ç´¢ã®ã¢ã«ã´ãªãºã ã§ãBM25ãã¨ãããã®ãããã¾ãã
ä½å¹´ãåã«æç 究æã«éã³ã«è¡ã£ãã¨ãã«ãTF/IDFãã精度ã®ãããã¤ãã¿ãããªæãã§ããªãã¢ãã¦ãã«æãã¦ãããã¾ããã
ãã®æã¯ãååã ãã§ãè¦ãã¦å¸°ãããã¨æã£ã¦ããã®ã§ããã帰ãã«å®ãå±
é
å±ã§å¤§é
ãã®ã¿ãé»è»ã®ãªãã§é¨ãã§ãã¾ãã»ã©é
ã£æã£ã¦ãã£ãããã®ååãå¿ãã¦ãã¾ã£ã¦ã¾ãããï¼ãªã«ãã£ã¦ãã ãã»ã»ã»ï¼
ã§ãæè¿Web+DB pressããã©ãã©è¦ã¦ãããBM25ã®ååãçºè¦ï¼ãããããã ããã ãæãåºãããï¼
ã¨ããããã§ãéãè
°ãä¸ãã¦ã¢ã¸ã¥ã¼ã«åãã¦ã¿ã¾ããã
githubã«ä¸ãã¦ããã¾ãã
Lingua::JA::OkapiBM25
http://github.com/miki/Lingua-JA-OkapiBM25
ãã®ãã¡CPANãããè½ã¨ããããã«ãªãã¾ãã
æ£å¼å称ã¯ãOkapi-BM25ãã¨å¼ã³ã¾ããokapiã£ã¦ãªãã ã岡ã£å¼ã¿ãããªé¿ãã§ãããæ å ±æ¤ç´¢ã®ä¸çã§ã¯ãããªãã«æåãªã¢ã«ã´ãªãºã ãããã§ãã
TF/IDFã®æ¬ ç¹ãè£ã£ã¦ãããã¨ããã°ããã®ã§ããããï¼
èªåã®æµ
ãç解ã«ããã¨ãTF/IDFã¯ææ¸é·ãé·ããã®ã»ã©TFã®å¤ã大ãããªããããå¾åããã£ã¦ãï¼ããã¥ã¡ã³ãã®ãªããç¹å¾´èªãæ½åºãã¦ç¸å¯¾æ¯è¼ããã ããªã大ãã¦åé¡ãªããããããªããã©ãå¤ãã®ããã¹ãã解æãã¤ã¤çµ¶å¯¾è©ä¾¡çã«ã¹ã³ã¢ãªã³ã°ãããããªå ´åãç¹å¾´èªã®ã¹ã³ã¢ã«ã ã©ãåºã¦ãã¾ããã¨ããæ¬ ç¹ããããã§ãã
BM25ã§ã¯ãããã®æ¬ ç¹ãè£ãã¹ããå¹³åçãªææ¸ã®é·ããã¨ãããã®ãé©å½ã«æã£ã¦ãã¦ããã®ææ¸ã大ä½ã©ããããã®é·ããªã®ããæ¯ççã«è¨ç®ãã¦ããã¦ãTFã®å¤ã«ãããããããããªå¦çããã¦ãã¾ãããªã®ã§ãæè¦çãªè¨ãæ¹ã«ãªã£ã¦ãã¾ãã¾ãããTFã®å¤ãææ¸é·ã«å¯¾ãã¦ãã¤ã«ãã«ãªã£ã¦ãããããªã¤ã¡ã¼ã¸ã§ãã
â詳ããç¥ããã人ã¯ãã£ã¡ãè¦ã¦ãã ãã
http://en.wikipedia.org/wiki/Probabilistic_relevance_model_%28BM25%29
ãããæãä¾ãä¸ãã¾ãããã
以ä¸ã®ã®ã¬ã³ã®ï¼ã¤ã®æ¼èª¬ãä¸ãã¾ããã¬ã³ã²ã¿ãªãã ãã§ãç¥ã£ã¦ãä¾ã®ã¢ã¬ã§ãã
ãããTF/IDFã¨BM25ã§è©ä¾¡ãã¦ã¿ã¾ãããã
ï¼ã¤ç®
ã¤ãã§ã«ã¢ã¸ã¥ã¼ã«ã®ä½¿ãæ¹ãç´¹ä»ãã¦ããã¾ãã
以ä¸ã®ä¾ã ã¨ã¹ã³ã¢ã®ä¸ä½ï¼ï¼ä»¶ããªã¹ã表示ãã¾ãã
use strict; use warnings; use Lingua::JA::OkapiBM25; use Data::Dumper; my $text = _text(); my $okapi = Lingua::JA::OkapiBM25->new; my $list = $okapi->bm25($text)->list(20); print Dumper $list; sub _text { my $text = <<"END"; æã ã¯ä¸äººã®è±éã失ã£ããããã¯æåãæå³ããã®ãï¼å¦ï¼å§ã¾ããªã®ã ï¼å°çé£é¦ã«æ¯ã¹æãã¸ãªã³ã®å½åã¯ï¼ï¼åã®>ï¼ä»¥ä¸ã§ãããã«ãé¢ãããä»æ¥ã¾ã§æ¦ãæãã¦ããããã®ã¯ä½æ ãï¼è«¸åï¼æãã¸ãªã³ã®æ¦äºç®çãæ£ããããã ï¼ä¸æ¡>ãã®ã¨ãªã¼ããå®å®ã«ã¾ã§è¨ãä¸ãã£ãå°çé£é¦ãæ¯é ãã¦ï¼ï¼ä½å¹´ãå®å®ã«ä½ãæã ãèªç±ãè¦æ±ãã¦ãä½åº¦é£é¦ã«è¸ã¿>ã«ããããããæãèµ·ããããããã¸ãªã³å ¬å½ã®æ²ããã人é¡ä¸äººä¸äººã®èªç±ã®ããã®æ¦ãããç¥ãè¦æ¨ã¦ã訳ã¯ç¡ãã ç§ã®å¼ã諸åããæãã¦ãããã¬ã«ãã»ã¶ãã¯æ»ãã ãä½æ ã ï¼ æ¦ãã¯ããè½çããã諸åãã¯ãã®æ¦äºã対岸ã®ç«ã¨è¦éããã¦ããã®ã§ã¯ãªãã®ãï¼ããããããã¯é大ãªéã¡ã§ããã>å°çé£é¦ã¯èãªãå¯ä¸ã®å°çãæ±ãã¦çãæ®ããã¨ãã¦ãããæã ã¯ãã®æããããå°çé£é¦ã®ã¨ãªã¼ãå ±ã«æããã°ãªã>ãã®ã ã ã¬ã«ãã¯ã諸åãã®çãèããç®è¦ããããããã«ãæ»ãã ï¼æ¦ãã¯ããããã§ããã æã ã®è»åã¯ã¾ãã¾ã復èãã¤ã¤ãããå°çé£é¦è»ã¨ã¦ãã®ã¾ã¾ã§ã¯ããã¾ãã 諸åã®ç¶ãå ããé£é¦ã®ç¡ææ ®ãªæµæã®åã«æ»ãã§ãã£ãã®ã ããã®æ²ãã¿ãæããå¿ãã¦ã¯ãªããªãï¼ãããã¬ã«ãã¯æ»>ã以ã£ã¦æã ã«ç¤ºãã¦ãããã®ã ï¼æã ã¯ä»ããã®æããçµéããé£é¦è»ã«å©ãã¤ãã¦åãçã®åå©ãå¾ããã¨ãåºæ¥ãã>ãã®åå©ãããæ¦æ»è å ¨ã¦ã¸ã®æ大ã®æ °ãã¨ãªãã å½æ°ãç«ã¦ï¼æ²ãã¿ãæãã«å¤ãã¦ãç«ã¦ãå½æ°ï¼ã¸ãªã³ã¯è«¸åçã®åã欲ãã¦ããã®ã ã ã¸ã¼ã¯ã»ã¸ãªã³ï¼ï¼ END return $text; }
åãããã«Lingua::JA::TFIDFã§è©ä¾¡ããã¦ã¿ã¾ããã³ã¼ãã¯ã»ã¨ãã©åããªã®ã§çç¥ã
ã§ãçµæã¯ãããªãã¾ããã
ããã ãè¦ãã¨è¨èã®å·®ã¯ãã¾ããªãã§ãããã§ãã¹ã³ã¢ã®ã°ãã¤ãå ·åã¯ã ãã¶éãã¾ãã
ï¼ã¤ç®
ç¶ãã¦ããã
sub _text { my $text = <<"END"; ä»ããã«è«¸åçææãªãæ°å ¥çãè¿ãã¦ã大ããªãæå¾ ãç¦ãããªãã æ代ã¯ç¾å¨ãæ°ããªå±é¢ã¸ã¨åããã¤ã¤ããï¼ãããªãå±é¢ã¸ãï¼ï¼äººé¡å²ã®å大ãªçºå±ã¸ã®å±é¢ã§ããï¼ï¼ å®å®ã«é²åºãããã¨ã«ãã£ã¦ãæã ã¯ç¡éã®å¯è½æ§ãæã«ããã誰ã®å¯è½æ§ãï¼ï¼äººé¡å ¨ä½ã®ãï¼ï¼å¦ï¼ï¼æçã¹ãã¼ã¹ã>ã¤ãã«ã®ã¿è¨±ãããå¯è½æ§ã§ããã£ï¼ï¼ã¹ãã¼ã¹ãã¤ãã®æ°ããè½åãããåæ»ãã人é¡å²ãæç ´ããã®ã§ããï¼ ç§»æ°ä¸ä¸ä»¥æ¥ã®å°é£ãªæ代ãçµã¦ããã¤ã¦æ£æ°ã¨ããå¼ã°ãã¦ããã¹ãã¼ã¹ã³ããã¼ã®ä½æ°éã¯é¸ã°ããæ°ã¨ãªã£ãï¼æã>ããã¦ã人é¡å²ã®æååã«ç«ã£ãã®ã ï¼ï¼ 諸åã¯æ´ã«ãã®åè¡ã§ããï¼ï¼ã¨ãªã¼ããèªè² ãããã¨ã«èºèºãããªè«¸åï¼è«¸åã¯ã¨ãªã¼ãã ï¼é¸ã°ããæ°ã®ä¸ããæ´ã«å³>ããé¸æããã¦ããã«ãã諸åçãããã³ããã¼ç¤¾ä¼ã®å®è·è ã§ããã¨å ±ã«æ°äººé¡ã®ãªã¼ãã¼ã§ããï¼ å¥®èµ·ããï¼ æªæ¥ã®å°æããããã¦éé²ããï¼ æã¨æãæ¦ç·ã«å ããï¼ï¼ END return $text; }
çµæã¯ãããªãã¾ãããµãããããã¾ãåãããã§ã¯ããã¾ããã
3ã¤ç®
3ã¤ç®ã®æ¼èª¬ã¯ãããããã¯ããçãã§ãããããã£ãã±ã¼ã¹ã§å·®ãåºã¦ãã¾ãã
sub _text { my $text = <<"END"; æãå¿ åãªãã¸ãªã³è»å µå£«éããä»ãå°çé£é¦è»è¦éã®åæ°ãæãã½ã¼ã©ã»ã¬ã¤ã«ãã£ã¦å®å®ã«æ¶ããããã®è¼ãããæç>ã¸ãªã³ã®æ£ç¾©ã®è¨¼ãã§ããã決å®çææãåããå°çé£é¦è»ã«å¦ä½ã»ã©ã®æ¦åãæ®ã£ã¦ãããã¨ããããã¯æ¢ã«å½¢éª¸ã§ãã>ã æ¢ãã¦è¨ãããã«ã¹ã§ããã¨ï¼ ãããè»å¼±ã®éå£ãããã®ã¢ã»ããªã¢ã»ã¯ã¼ãæããã¨ã¯åºæ¥ãªãã¨ç§ã¯æè¨ããã 人é¡ã¯æçé¸ã°ããåªè¯ç¨®ããã¸ãªã³å½ã æ°ã«ç®¡çéå¶ããã¦ãåãã¦æ°¸ä¹ ã«çã延ã³ããã¨ãåºæ¥ãããã以ä¸æ¦ãç¶ã>ã¦ã¯äººé¡ãã®ãã®ã®å±æ©ã§ãããå°çé£é¦ã®ç¡è½ãªãè ã©ãã«æãç¥ããã¦ãããã°ãªãããä»ãã人é¡ã¯ææ¥ã®æªæ¥ã«å>ãã£ã¦ç«ããã°ãªã¬æã§ããã¨ï¼ ã¸ã¼ã¯ã»ã¸ãªã³ï¼ END return $text; }
å·®ãåºã¦ããã£ã¦ãã£ã¦ãããªãã ã大差ãªãããã«ã¿ãã¾ããããã
çµæ
ããããããªãã ãããã·ã§ã¤æãã«ãªã£ã¦ãã¾ãã¾ããã
ã¨ã¯ããããªãã¨ãç¡äºã«ã®ã¬ã³ã®ï¼ã¤ã®æ¼èª¬ãBM25ã¨TFIDFã§è©ä¾¡ãããã¨ãã§ãã¾ããã
ã§ããªã«ãè¨ãããã£ãã®ãã¨ããã¨ãï¼ã¤ç®ã¨ï¼ã¤ç®ã®æ¼èª¬ã«ããã¹ã¦ï¼ã¤ç®ã®æ¼èª¬ã¯çããã©ããBM25ã ã¨æ¯è¼çå ¬å¹³ã«ã¹ã³ã¢ãåºã¦ãããã¨ãããã¨ã§ãã
ãªã«ãå ¬å¹³ãã¨ããã¨ãï¼ã¤ç®ãï¼ã¤ç®ã®æ¼èª¬ã«ããã¦ãTF/IDFã ã¨1ä½ã®ãã¼ã¯ã¼ãã®ã¹ã³ã¢ã¯40åå¾ãªã®ã«å¯¾ãã¦ã3ã¤ç®ã ãææ¸é·ãçãã®ã§ã第1ä½ã®ãã¼ã¯ã¼ãã§ãã16.91ã¨ãããã¨ã§ãã ãã¶ã ã©ãããã¾ãã
ããã«å¯¾ãã¦BM25ã ã¨ãææ¸é·ã«æããããã©ããã ãããåããããã®ã¹ã³ã¢ã®ç¯å²ã«åã¾ã£ã¦ãã¾ããã
ãããã©ãå¹ãã¦ãããã¨ããã¨ã3ã¤ã®æ¼èª¬ãã¼ã¿ãå¥ã ã«è©ä¾¡ããã¹ã³ã¢ãç©ç®ãã¦ããã¨ãã«å½±é¿ãã§ã¦ãã¾ãã
ä¸è¨ã¯3ã¤ã®æ¼èª¬ã®ã¹ã³ã¢ããã©ãã©ã«è©ä¾¡ãããã¼ã¯ã¼ããã¨ã«è¶³ãããã§ãã£ããã®ã®ä¸ä½20åã§ãã
注ç®ãã¹ãã¯è²ãæ¿ãé¨åãããã¯ã©ã¡ããããã¡ãå´ã«ããç»å ´ããªãã£ãè¨èã§ãã
TFIDFã ã¨ãæããã¨ããæ¦ãããæ²ãã¿ãã®ãããªããæ½è±¡çãªèªå½ãã©ã³ã¯ã¤ã³ãã¦ããã®ã«å¤§ãã¦ãBM25ã ã¨ãå¿ åããæ£æ°ãã形骸ãã®ãããªã¨ã¦ãã®ã¬ã³æ§é¢¨å³ã®èªå½ãè¦åãããã¾ãã
ã½ã¼ã©ã¼ã»ã¬ã¤ã¨ããåºã¡ãã£ã¦ããï¼
ã¤ã¾ããææ¸é·ã®çãã£ã3ã¤ãã®æ¼èª¬ã®å 容ããããããå ¬å¹³ã«åãè¾¼ã¾ãã¦ãããçµæã¨ãã¦ããç¹å¾´çãªèªå½ãä¸ä½ã«é£ãè¾¼ãå½¢ã¨ãªãã¾ããã
注æç¹
ãã£ã¨ã注æç¹ã¨ããããªãã¨ããããBM25ã®ãã¨ãã¾ãç解ããªãã§æ¸ãã¦ã¾ãã
ããããããå
¨ç¶åéãééãããããªãã®ã§ãããã¾ãæ¬æ°ã«ããªãã§ãï¼
ãã¨Lingua::JA::TFIDFãLingua::JA::OkapiBM25ããIDFã®è¨ç®ã¯æ¨æ¸¬å¤ã§ãã
ããããã¯こっちã«ããã¦ããã¾ãããæ£ç¢ºãªãã¼ã¿ã§ã¯ãªãã®ã§ãããã辺ãå«ãã¦ãããªãã¨ãªããããªæããªã®ãããããã«ã¿ã¦ããã ããã¨ãããããã§ãã
ãããã¨ãã®ãµã³ãã«ã§æ²è¼ãããã¼ã¿ã¯ãå®éã«ã¯MeCabã«ã¯ã¦ãªãã¼ã¯ã¼ããwikipediaã®è¦åºãèªãçªã£è¾¼ãã ããã¦ãç¬èªã«æ¡å¼µãã¦ãã®ã§ãã¢ã¸ã¥ã¼ã«è½ã¨ãã¦ãã¦åããã¨ãã£ã¦ãåãçµæã«ã¯ãªãã¾ããããããããã
ãããªä¸éå端ãªå 容ã§ããã°ãæ¸ãããã¢ã¸ã¥ã¼ã«ãä¸ããããã¦ããªãã®æå³ãããã®ã ãããã
ããã¯ãã§ã«å½¢éª¸ã§ããï¼
æ¢ãã¦è¨ããããã«ã¹ãã§ããã¨ï¼
ã¹ããã»ã³ããããæ¸ãããã£ãã ãã§ãããªã¤ã¹ãããµã¤ã