SlideShare a Scribd company logo
1 of 25
Download to read offline
Big Dictionary Matching
R&Dチーム
セーヨー・サンティ
解きたい問題
数百万単語を搭載した辞書が与えられたとする
任意の文章の中に辞書に登録された単語をしっかり特定せよ
みなさんならどうします?
基本的なツール
正規表現
Trie
Aho–Corasick
Patricia Trie
Directed acyclic word graph (DAWG)
その他は割愛 (&知らない)
Trie
K={"aaac#","aab#", "ab#", "abb#", "abba#"}
Aho-Corasick
文字列を1-Passでマッチング完了!速い!(データはTrieと失敗時のジャンプ先)
Patricia Trie
DAWG
K = {“aaa”, “aba”,“bbc”, “cbc”, “cc”}
Trieをさらに圧縮:Suffixも共有
2015年の辞書体験談(Linked List/.NET)
中国語辞書:約350万語
正規表現 → 破たん
Trie → 破たん
Patricia Trie → 破たん
Aho–Corasick → 破たん
Directed acyclic word graph (DAWG) → やっとなんとか収まった
分かったこと
.NETのオバーヘッドが大きい
DAWGはすごい
さらに調べて分かったこと
データの持ち方次第で速度・メモリ使用量が改善できる
Trie実装の系統
Linked List
Table
Tripple-Array
Double-Array
Table Trie
Tripple-Array Trie
check[base[s] + c] = s
next[base[s] + c] = t
Aoe et. al
1989 Jun-ichi Aoe:
“An Efficient Digital Search Algorithm by Using a Double-Array Structure”
IEEE Transactions on Software Engineering archive Volume 15 Issue 9,
September 1989 Page 1066-1077
check[base[s] + c] = s
base[s] + c = t
Double Array Trie
t = BASE[s] + CODE[c]
CHECK[t] = s
一般的には
Data Structure Size: Trie,Aho-Corasick > (Patricia?) > DAWG
Implementation Size: Table > Linked List > Double Array
Speed: Table > Double Array > Linked List
世界のMecab
一般的なCRF Tokenizer, Pos Taggingの10倍速(精度は90%前半)
圧倒的な速さの秘密の一つは辞書マッチングにある
Double Array Trie を採用した
スピード・メモリのTrade offで
Double Array TrieのJava版のオープンソースを利用
でも、せめて、Double Array DAWGが欲しいなあ
理想的には
できればTable DAWG
Aoe et. al
1989 Jun-ichi Aoe:
“An Efficient Digital Search Algorithm by Using a Double-Array Structure”
IEEE Transactions on Software Engineering archive Volume 15 Issue 9,
September 1989 Page 1066-1077
2016 Masao Fuketa, Kazuhiro Morita, and Jun-ichi Aoe:
“Comparisons of Efficient Implementations for DAWG”
International Journal of Computer Theory and Engineering, Vol. 8, No. 1,
February 2016
DAWGを持っている前提 orz
DAWGの実装
単語リスト → Linked List DAWG → Double Array
Python の分かりやすいオープンソース
http://stevehanov.ca/blog/index.php?id=115
Double Array DAWG完成
Python勉強がてら、Juliaをマスターする作戦
Python→Juliaのポーティング
ChineseToolsのDouble Arrayの実装を参考
ついにDouble Array DAWGを手に入れた!
気になるサイズとスピード
中国語350万語→Linked List DAWG 137 sec.
Double Array 生成 12 min.
Array+Character List 24 MB ちなみにdouble array trie: 94MB
中国語350万語(UTF8) 44 MB
中国語350万語(UTF8)のZIPファイル 18 MB
double array読み込み 初回:2 sec.
キャッシュ後:0.18 sec.
Weibo 8万文での辞書マッチング速度
(書き込みなし)
31,548 文/sec/cpu (中央値)
万歳!?
待て!
Table はとてもsparseなのでsparse matrixを使ってみよう
Double Array 作る手間省ける
Sparse matrix は標準技術: Compressed Sparse Columns (CSC)
スピード的には期待できるかもしれない!
気になるサイズと速度
中国語350万語→Linked List DAWG 137 sec.
SparseMatrixの生成 58 sec.
SparseMatrix+Character List 52 MB (Double-Arrayより大きい)
中国語350万語(UTF8) 44 MB
中国語350万語(UTF8)のZIPファイル 18 MB
SparseMatrix読み込み 初回:2.1 sec.
キャッシュ後:0.19 sec.
Weibo 8万文での辞書マッチング速度
(書き込みなし)
55,212 文/sec/cpu (中央値)
(予想通り速い!)
参考資料
1. Comparisons of Efficient Implementations for DAWG: Masao Fuketa, Kazuhiro Morita, and Jun-
ichi Aoe, International Journal of Computer Theory and Engineering, Vol. 8, No. 1, February 2016
2. A Retrieval Method for Double Array Structures by Using Byte N-Gram: Masao Fuketa, Kazuhiro
Morita, and Jun-Ichi Aoe, International Journal of Computer Theory and Engineering, Vol. 6, No. 2,
April 2014
3. Importance of Aho-Corasick String Matching Algorithm in Real World Applications: Saima Hasib,
Mahak Motwani, Amit Saxena, International Journal of Computer Science and Information
Technologies, Vol. 4 (3) , 2013, 467-469
4. Compressing dictionaries with a DAWG: Steve Hanov’s Blog ,
http://stevehanov.ca/blog/index.php?id=115

More Related Content

Similar to Big dictionary matching (6)

おとなのテキストマイニング
おとなのテキストマイニングおとなのテキストマイニング
おとなのテキストマイニング
 
Introduction of tango! (jp)
Introduction of tango! (jp)Introduction of tango! (jp)
Introduction of tango! (jp)
 
Pythonの非同期処理を始める前に
Pythonの非同期処理を始める前にPythonの非同期処理を始める前に
Pythonの非同期処理を始める前に
 
Perl で自然言語処理
Perl で自然言語処理Perl で自然言語処理
Perl で自然言語処理
 
Lisp batton - Common LISP
Lisp batton - Common LISPLisp batton - Common LISP
Lisp batton - Common LISP
 
Apache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory dataApache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory data
 

Recently uploaded

Recently uploaded (12)

論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 

Big dictionary matching