Upload
sleepyyoshi
View
1.691
Download
0
Embed Size (px)
DESCRIPTION
DSIRNLP#3 LT Fig4.5: 辞書挟み込み型転置インデクスの発表資料
Citation preview
DSIRNLP#3 LT Fig4.5: 辞書挟み込み型転置インデクス
を用いた検索エンジン
2012-09-30
Yoshihiko Suhara
@sleepy_yoshi
1
背景
• 昨年のGWの出来事 – ブッチャー本 [1] 読んでたら辞書挟み込み型インデクスについて記述があり,実装したくなった
– 偶然にも明日からGW
– とりあえずやっつけで実装
– ちゃんと仕上げようとするとそのまま忘れ去るので,区切りをつける意味でとりあえず公開…するの忘れて一年が経った
ブッチャー本 2
辞書挟み込み型転置インデクス って何よ?
3
通常の転置インデクス
• 辞書と呼ばれるデータ構造を利用して文書IDや出現位置が記載された転置リストを取得する
– 辞書にはトライ木やハッシュなどを利用
4
辞書 転置リスト
通常の転置インデクス
辞書挟み込み型転置インデクス
• 辞書を明示的に持たず,転置リストの先頭に付与した状態で連結したもの
5
…
辞書を転置リストの間に挟み込んでいる
語彙 転置リスト 語彙 転置リスト 語彙 転置リスト
通常の転置インデクスとの比較
辞書 転置リスト
通常の転置インデクス
辞書挟み込み型転置インデクス
…
辞書を挟み込んでいる 6
Fig4.5: 辞書挟み込み型転置インデクス
• 辞書をインデクスに挟み込んだ形式の転置インデクス[1][2] – 文献[1]の図4.5で説明されていたからFig4.5と命名
ブッチャー本 Fig4.5 (p.115)
7
さて,どのように検索するのか?
検索処理
• 二段階の処理 (1) メモリ上のインデクスを二分探索
(2) ディスク上のインデクスを線形探索
apple Pos asus ・・・ Pos Pos Pos Pos ・・・ book Pos Pos ・・・
apple 1025
book 1997
cookie 3005
・・・ ・・・
・・・
In-memory index
On-disk index
8
検索処理の例: asus
apple Pos asus ・・・ Pos Pos Pos Pos ・・・ book Pos Pos ・・・
apple 1025
book 1997
cookie 3005
・・・ ・・・
・・・
In-memory index
On-disk index
(1) 二分探索
発見! (2) 線形探索
9
補足: 検索範囲
apple Pos asus ・・・ Pos Pos Pos Pos ・・・ book Pos Pos ・・・
apple 1025
book 1997
cookie 3005
・・・ ・・・
・・・
In-memory index
On-disk index
10
In-memory indexのアイテム間だけ探索する
実装してみた
11
Fig4.5の実装
• インデクス構築処理 – 一度通常の転置インデクスを構築してからOn-diskインデクスとIn-
memoryインデクスを構築 – 転置インデクスはやる気のない実装
• 辞書はstd::map • 転置リストはstd::vector
• インデクス検索処理 – 構築したOn-diskインデクスはmmapで読み込む – On-diskインデクスにはDocID: Pos, Pos; DocID: Pos, Posではなくて全てフラットなPosition情報だけを利用 • 位置情報を取得した後に文書IDをルックアップすることでDocIDを取得 • WSDM ’09のGoogle講演を参考 [3]
12
使い方
13
インデクス構築
• 入力フォーマット – 各行が<DocName>¥t<Text>
• Textはトークン毎にスペース区切り
• 改行を含めることができない
Usage: ./index_writer <input filename> <output index path> [block size] # 例 $ ./index_write sample.dat hoge 1024 Index construction done.
http://www.hoge.com/ 飛ばねえ 豚 は ただ の 豚 だ http://www.bar.com/ 豚肉 は おいしい http://www.piyo.com/ 豚 は 豚 で も ただ の 豚 ・・・
sample.dat
14
検索
Usage: ./index_searcher <index basename> <query> # 例 $ ./index_searcher hoge 豚 5 position found === http://www.hoge.com/ http://www.piyo.com/
• クエリはインデクスに格納されているトークンである必要がある – 上記例の場合「豚」と「豚肉」をまったく別のトークンとして扱っている
• AND検索,フレーズ検索には現在未対応 15
使い方補足
16
block sizeて何よ?
Usage: ./index_writer <input filename> <output index path> [block size] # 例 $ ./index_write sample.dat hoge 1024
apple Pos amazon ・・・ PF Pos Pos PF ・・・ book Pos PF ・・・
apple 1025
book 1997
cookie 3005
・・・ ・・・
・・・
block size = この幅の上限
17
apple Pos amazon ・・・ PF Pos Pos PF ・・・ book Pos PF ・・・
apple 1025
book 1997
cookie 3005
・・・ ・・・
・・・
In-memory index (*.inmem)
On-disk index (*.index)
DocID Start position
1 1
2 120
3 180
… …
N 17280
DocID-Position table (*.docpos) DocID-DocName table (*.docname)
DocID Doc Name
1 http://hoge.com/index.html
2 http://hoge.com/link.html
3 http://fuga.ne.jp/index.html
… …
N http://piyo.co.jp/inde.html
生成されるインデクス
18
まとめ
19
TODO (できるといいな…)
• やっつけ実装なので,思いつくだけでもたくさん – ベンチマーク – インデックスの圧縮
• 差分値を取る • Variable-byte符号
– AND検索,フレーズ検索の実装 – Bi-gramインデクスの実装 – スニペット表示部分の実装 – ベンチマーク – 全体的なコード書き直し – など
20
明日のために
• Dictionary Interleaving 形式のインデクスは辞書を明示的に持たないため,複数インデクスをマージしやすい – Merge-based index construction に適した形式
• 山田さんの記事[4]を参考
• 複数インデクスを入力して,マージ結果を出力するような使い方ができる検索エンジンができるんじゃないかな
21
References
• [1] Stefan Buttcher, Charles L. A. Clarke and Gordon V. Cormack, “Information Retrieval”, The MIT Press, 2010.
• [2] Stefan Buttcher, “Multi-User File System Search”, Ph.D thesis, University of Waterloo, Canada, 2007. – 著者のひとりButtcher氏の博士論文.Interleaving Dictionaryの初出?
– 4.4.2 Interleaving Posting Lists and Dictionary Entries
• [3] Jeffrey Dean, “Challenges in Building Large-Scale Information Retrieval Systems”, WSDM ‘09 Tutorial, 2009. – フラットな形式のインデクスについてはid:llameradaさんの翻訳記事が参考になる • http://d.hatena.ne.jp/llamerada/20090317/1237302640
• [4] 山田浩之. 検索エンジンはいかにして動くのか? – 第10回 動的な索引構築
• http://gihyo.jp/dev/serial/01/search-engine/0010
22
THANK YOU!
23