yasuokaの日記: Stanzaの日本語モデルがUniDic品詞対応に
多言語係り受け解析ツールStanza 1.2が、無事にリリースされたとの連絡をいただいた。これまでのStanza 1.1.1はUniversal Dependencies 2.5準拠だったのが、今回のStanza 1.2はUniversal Dependencies 2.7に対応した。その結果、日本語モデルがUniDic品詞となっているのが、私(安岡孝一)個人としてはうれしい。とりあえず、あたらしい日本語モデルをダウンロードしてみよう。
$ pip3 install -U 'stanza>=1.2'
$ python3
>>> import stanza
>>> stanza.download("ja")
ダウンロードがうまくいったなら、「国境の長いトンネルを抜けると雪国であった。」を係り受け解析してみよう。
>>> nlp=stanza.Pipeline("ja")
>>> doc=nlp("国境の長いトンネルを抜けると雪国であった。")
>>> print(doc)
[
[
{
"id": 1,
"text": "国境",
"lemma": "国境",
"upos": "NOUN",
"xpos": "名詞-普通名詞-一般",
"head": 3,
"deprel": "nsubj",
"misc": "start_char=0|end_char=2"
},
{
"id": 2,
"text": "の",
"lemma": "の",
"upos": "ADP",
"xpos": "助詞-格助詞",
"head": 1,
"deprel": "case",
"misc": "start_char=2|end_char=3"
},
{
"id": 3,
"text": "長い",
"lemma": "長い",
"upos": "ADJ",
"xpos": "形容詞-一般",
"head": 4,
"deprel": "acl",
"misc": "start_char=3|end_char=5"
},
{
"id": 4,
"text": "トンネル",
"lemma": "トンネル",
"upos": "NOUN",
"xpos": "名詞-普通名詞-サ変可能",
"head": 6,
"deprel": "obj",
"misc": "start_char=5|end_char=9"
},
{
"id": 5,
"text": "を",
"lemma": "を",
"upos": "ADP",
"xpos": "助詞-格助詞",
"head": 4,
"deprel": "case",
"misc": "start_char=9|end_char=10"
},
{
"id": 6,
"text": "抜ける",
"lemma": "抜ける",
"upos": "VERB",
"xpos": "動詞-非自立可能",
"head": 8,
"deprel": "acl",
"misc": "start_char=10|end_char=13"
},
{
"id": 7,
"text": "と",
"lemma": "と",
"upos": "SCONJ",
"xpos": "助詞-接続助詞",
"head": 6,
"deprel": "mark",
"misc": "start_char=13|end_char=14"
},
{
"id": 8,
"text": "雪国",
"lemma": "雪国",
"upos": "PROPN",
"xpos": "名詞-固有名詞-地名-一般",
"head": 0,
"deprel": "root",
"misc": "start_char=14|end_char=16"
},
{
"id": 9,
"text": "で",
"lemma": "だ",
"upos": "AUX",
"xpos": "助動詞",
"head": 8,
"deprel": "cop",
"misc": "start_char=16|end_char=17"
},
{
"id": 10,
"text": "あっ",
"lemma": "ある",
"upos": "AUX",
"xpos": "動詞-非自立可能",
"head": 8,
"deprel": "aux",
"misc": "start_char=17|end_char=19"
},
{
"id": 11,
"text": "た",
"lemma": "た",
"upos": "AUX",
"xpos": "助動詞",
"head": 8,
"deprel": "aux",
"misc": "start_char=19|end_char=20"
},
{
"id": 12,
"text": "。",
"lemma": "。",
"upos": "PUNCT",
"xpos": "補助記号-句点",
"head": 8,
"deprel": "punct",
"misc": "start_char=20|end_char=21"
}
]
]
係り受けのうち「国境」⇐nsubj=「長い」は解析ミスで、どう考えても「国境」⇐nmod=「トンネル」が正しいのだが、それを除いては、品詞分析も係り受け解析もほぼ完璧なようだ。さて、日本語以外のモデルは、どんな感じかな。
Stanzaの日本語モデルがUniDic品詞対応に More ログイン