introduction to japanese morphological analysis
DESCRIPTION
TRANSCRIPT
Introduction to Japanese Morphological Analysis
2014/03/26 @a_bicky
お断り• 非 NLPer 向けの初歩的な内容(のつもり)です
‣ 学習済みの形態素解析器がどんな処理をしているかイメージできることがゴールです
‣ HMM とか CRF には言及しません
‣ 未知語の扱いにも言及しません
• 拙い英文が散在していますがご了承ください
‣ all 日本語のスライドは発表後に追加したものです
What’s Morphological Analysis? (形態素解析 in Japanese)
% echo 東京都に住む | mecab東京 名詞,固有名詞,地域,一般,*,*,東京,トウキョウ,トーキョー都 名詞,接尾,地域,*,*,*,都,ト,トに 助詞,格助詞,一般,*,*,*,に,ニ,ニ住む 動詞,自立,*,*,五段・マ行,基本形,住む,スム,スムEOS
• Japanese Morphological Analysis consists of two tasks
‣ Word segmentation
‣ Part-of-speech tagging
Steps of Japanese Morphological Analysis1. Build a word lattice for the input
2. Select the best path in the lattice
Steps of Japanese Morphological Analysis1. Build a word lattice for the input
2. Select the best path in the lattice
Build a word latticeInput 東京都に住む
BOS
京都 [Noun] キョウト に
[Noun] ニ 住む
[Noun] スム
EOS東
[Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Noun] ミヤコ
都 [Suffix] ト に
[Particle] ニ
京 [Noun] キョウ
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS東
[Noun] ヒガシ
東京 [Noun] トウキョウ
common_prefix_search(東京都に住む)
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
京都 [Noun] キョウト
東 [Noun] ヒガシ
東京 [Noun] トウキョウ
京 [Noun] キョウ
common_prefix_search(京都に住む)
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
京都 [Noun] キョウト
東 [Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Noun] ミヤコ
都 [Suffix] ト
京 [Noun] キョウ
common_prefix_search(都に住む)
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
京都 [Noun] キョウト に
[Noun] ニ東
[Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Noun] ミヤコ
都 [Suffix] ト に
[Particle] ニ
京 [Noun] キョウ
common_prefix_search(に住む)
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
京都 [Noun] キョウト に
[Noun] ニ 住む
[Noun] スム
東 [Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Noun] ミヤコ
都 [Suffix] ト に
[Particle] ニ
京 [Noun] キョウ
common_prefix_search(住む)
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
京都 [Noun] キョウト に
[Noun] ニ 住む
[Noun] スム
東 [Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Noun] ミヤコ
都 [Suffix] ト に
[Particle] ニ
京 [Noun] キョウ
common_prefix_search(む)
not matched
Build a word lattice
に Particle, ニ 東 Noun, ヒガシ に Verb, ニ 東京 Noun, トウキョウ 京 Noun, キョウ 都 Noun, ミヤコ 京都 Noun, キョウト 都 Suffix, ト 住む Verb, スム
Dictionary
Input 東京都に住む
BOS
京都 [Noun] キョウト に
[Noun] ニ 住む
[Noun] スム
EOS東
[Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Noun] ミヤコ
都 [Suffix] ト に
[Particle] ニ
京 [Noun] キョウ
trie• A tree data structure
used in common prefix search
• MeCab uses Double-Array,a trie data structure using two arrays
東
東京
京 都
京都
1 京 Noun, キョウ 2 京都 Noun, キョウト 3 東 Noun, ヒガシ 4 東西 Noun, トウザイ 5 東京 Noun, トウキョウ 6 都 Noun, ミヤコ 7 都 Suffix, ト
東西
3 1 6,7
25 4
東 京 都
京 都西
Dictionary
trie• A tree data structure
used in common prefix search
• MeCab uses Double-Array,a trie data structure using two arrays
東
東京
京 都
京都
1 京 Noun, キョウ 2 京都 Noun, キョウト 3 東 Noun, ヒガシ 4 東西 Noun, トウザイ 5 東京 Noun, トウキョウ 6 都 Noun, ミヤコ 7 都 Suffix, ト
東西
3 1 6,7
25 4
東 京 都
京 都西
Dictionarycommon_prefix_search(東京都に住む)
Steps of Japanese Morphological Analysis1. Build a word lattice for the input
2. Select the best path in the lattice
Select the best path• Select the path with the lowest cost
‣ there are two types of costs
- cost to generate each word
- cost to connect the words (contexts)
• Find the path using Viterbi algorithm
‣ there are many many candidate paths!!
‣ Viterbi algorithm is an efficient algorithm
How to determine the cost?
京都 [Noun] キョウト
東 [Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Suffix] ト
BOS
word, left context, right context, cost 京都, 1293, 1293, 2135 東, 1285, 1285, 6245 東京, 1293, 1293, 3003 都, 1303, 1303, 9428
Generating cost (Dictionary)
left context, right context, cost 0, 1285, -283 0, 1293, -310 1285, 1293, -368 1293, 1303, -9617
Connecting cost21356245
3003 9428
-310
-283
-9617
-386
1285, 1285
1293, 1293 1303, 1303
0
1293, 1293
京都 [Noun] キョウト
東 [Noun] ヒガシ
東京 [Noun] トウキョウ
都 [Suffix] ト
BOS
word, left context, right context, cost 京都, 1293, 1293, 2135 東, 1285, 1285, 6245 東京, 1293, 1293, 3003 都, 1303, 1303, 9428
Generating cost (Dictionary)
left context, right context, cost 0, 1285, -283 0, 1293, -310 1285, 1293, -368 1293, 1303, -9617
Connecting cost21356245
3003 9428
-310
-283
-9617
-386
1285, 1285
1293, 1293 1303, 1303
0
1293, 1293
7729
2504
How to determine the cost?
Output of MeCab
% echo 東京都 | mecab -F "%m,%H\n\t%phl,%phr,%pw,%pC,%pc\n" -N2東京,名詞,固有名詞,地域,一般,*,*,東京,トウキョウ,トーキョー 1293,1293,3003,-310,2693都,名詞,接尾,地域,*,*,*,都,ト,ト 1303,1303,9428,-9617,2504EOS東,名詞,一般,*,*,*,*,東,ヒガシ,ヒガシ 1285,1285,6245,-283,5962京都,名詞,固有名詞,地域,一般,*,*,京都,キョウト,キョート 1293,1293,2135,-368,7729EOS
←! left context, right context, generating cost, ! connecting cost, cumulative cost
まとめ• 日本語の形態素解析は一般的に2つのタスクから成る
‣ 単語(形態素)分割
‣ 品詞タグ付け
• 単語分割候補の作成は、入力文の先頭から順に辞書に存在する単語(品詞情報付き)を取り出す簡単なお仕事
‣ 共通接頭辞検索のために trie というデータ構造が使われる
• 品詞タグ付けは、構築した lattice のパスに(既知の)コスト情報を付与して低コストなパスを選択する簡単なお仕事
‣ パスのコストを計算する際には Viterbi アルゴリズムが使われる
触れなかったこと• Viterbi アルゴリズムの詳細
• 未知語の取り扱い
• コストの算出方法(モデルの学習方法)
etc.
!
References• 日本語解析ツール MeCab, Cabocha の紹介
http://chasen.naist.jp/chaki/t/2009-09-30/doc/mecab-cabocha-nlp-seminar-2009.pdf
• 鬱くしい日本語のための形態素解析入門http://www.slideshare.net/torotoki/ss-9720666
• 日本テレビ東京で学ぶMeCabのコスト計算 | mwSoft http://www.mwsoft.jp/programming/munou/mecab_nitteretou.html
• mecab-0.996.tar.gzhttps://code.google.com/p/mecab/downloads/detail?name=mecab-0.996.tar.gz