0
0

国語研長単位係り受け解析モデルgpt2-{small,medium,large}-japanese-ud-causalリリース

Posted at

6月23日の記事の続きだが、国語研長単位UD-Japanese-GSDLUWとGPT2ForTokenClassificationを使って、係り受け解析モデルgpt2-{small,medium,large}-japanese-ud-causalを作ってみた。単方向モデルで係り受け解析というのは、正直なかなか手強かったのだが、何とか隣接確率行列を作り出すことに成功したようだ。ja_gsdluw-ud-test.conlluによるベンチマーク・プログラムは、Google Colaboratory (GPU版)だと、こんな感じ。

!pip install transformers
models=["KoichiYasuoka/gpt2-small-japanese-ud-causal","KoichiYasuoka/gpt2-medium-japanese-ud-causal","KoichiYasuoka/gpt2-large-japanese-ud-causal"]
import os,sys,subprocess
from transformers import pipeline
url="https://github.com/UniversalDependencies/UD_Japanese-GSDLUW"
d=os.path.basename(url)
!test -d {d} || git clone --depth=1 {url}
!for F in train dev test ; do cp {d}/*-$$F.conllu $$F.conllu ; done
url="https://universaldependencies.org/conll18/conll18_ud_eval.py"
c=os.path.basename(url)
!test -f {c} || curl -LO {url}
for mdl in models:
  nlp=pipeline("universal-dependencies",mdl,trust_remote_code=True,device=0)
  with open("test.conllu","r",encoding="utf-8") as r:
    s=r.read()
  with open("result-test.conllu","w",encoding="utf-8") as w:
    for t in s.split("\n"):
      if t.startswith("# text = "):
        w.write(nlp(t[9:]))
  print("\n***",mdl)
  print(subprocess.run([sys.executable,c,"--verbose","test.conllu","result-test.conllu"],capture_output=True,text=True).stdout)

私(安岡孝一)の手元では、以下の結果が出力された。

*** KoichiYasuoka/gpt2-small-japanese-ud-causal
Metric     | Precision |    Recall |  F1 Score | AligndAcc
-----------+-----------+-----------+-----------+-----------
Tokens     |     96.96 |     97.55 |     97.25 |
Sentences  |    100.00 |    100.00 |    100.00 |
Words      |     96.96 |     97.55 |     97.25 |
UPOS       |     94.49 |     95.06 |     94.78 |     97.45
XPOS       |      0.00 |      0.00 |      0.00 |      0.00
UFeats     |     96.90 |     97.49 |     97.19 |     99.94
AllTags    |      0.00 |      0.00 |      0.00 |      0.00
Lemmas     |      0.00 |      0.00 |      0.00 |      0.00
UAS        |     88.81 |     89.35 |     89.08 |     91.59
LAS        |     87.59 |     88.12 |     87.85 |     90.34
CLAS       |     80.60 |     81.46 |     81.03 |     84.20
MLAS       |     76.84 |     77.66 |     77.25 |     80.27
BLEX       |      0.00 |      0.00 |      0.00 |      0.00

*** KoichiYasuoka/gpt2-medium-japanese-ud-causal
Metric     | Precision |    Recall |  F1 Score | AligndAcc
-----------+-----------+-----------+-----------+-----------
Tokens     |     96.65 |     97.24 |     96.95 |
Sentences  |    100.00 |    100.00 |    100.00 |
Words      |     96.65 |     97.24 |     96.95 |
UPOS       |     94.26 |     94.83 |     94.55 |     97.52
XPOS       |      0.00 |      0.00 |      0.00 |      0.00
UFeats     |     96.62 |     97.20 |     96.91 |     99.96
AllTags    |      0.00 |      0.00 |      0.00 |      0.00
Lemmas     |      0.00 |      0.00 |      0.00 |      0.00
UAS        |     88.63 |     89.16 |     88.90 |     91.70
LAS        |     87.49 |     88.02 |     87.76 |     90.52
CLAS       |     80.51 |     81.73 |     81.11 |     84.99
MLAS       |     76.83 |     77.99 |     77.41 |     81.11
BLEX       |      0.00 |      0.00 |      0.00 |      0.00

*** KoichiYasuoka/gpt2-large-japanese-ud-causal
Metric     | Precision |    Recall |  F1 Score | AligndAcc
-----------+-----------+-----------+-----------+-----------
Tokens     |     96.07 |     96.65 |     96.36 |
Sentences  |    100.00 |    100.00 |    100.00 |
Words      |     96.07 |     96.65 |     96.36 |
UPOS       |     93.78 |     94.34 |     94.06 |     97.61
XPOS       |      0.00 |      0.00 |      0.00 |      0.00
UFeats     |     96.05 |     96.63 |     96.34 |     99.98
AllTags    |      0.00 |      0.00 |      0.00 |      0.00
Lemmas     |      0.00 |      0.00 |      0.00 |      0.00
UAS        |     87.86 |     88.39 |     88.12 |     91.45
LAS        |     86.65 |     87.17 |     86.91 |     90.19
CLAS       |     79.79 |     81.00 |     80.39 |     85.04
MLAS       |     76.07 |     77.22 |     76.64 |     81.07
BLEX       |      0.00 |      0.00 |      0.00 |      0.00

UPOS/LAS/MLASは、smallが94.78/87.85/77.25、mediumが94.55/87.76/77.41、largeが94.06/86.91/76.64となっていて、2022年11月27日の日記と較べると、もう一息の結果だったりする。やっぱり係り受け解析は、GPT-2のような単方向モデルより、BERT・RoBERTa・DeBERTaのような双方向モデルの方が向いてるのかな。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0