一昨日・昨日の記事の続きだが、HPLT Deliverable 4.1『First language models trained』(2024年2月29日)では、75言語についてLTG-BERTモデルを製作・公開し、うち54言語に対しては係り受け解析モデルも製作したらしい。同レポートTable 3.5によれば、日本語係り受け解析モデルはLASが94.6だったらしいが、これらの係り受け解析モデルは公開されていない。仕方ないので、日本語LTG-BERTモデル「HPLT Bert for Japanese」と国語研長単位UD_Japanese-GSDLUWをもとに、係り受け解析モデルltgbert-base-japanese-ud-goeswithを、かなり苦労しつつ試作してみた。ja_gsdluw-ud-test.conlluによるベンチマーク・プログラムは、Google Colaboratory (GPU版)だと、こんな感じ。
!pip install transformers
models=["KoichiYasuoka/ltgbert-base-japanese-ud-goeswith"]
import os,sys,subprocess
from transformers import pipeline
url="https://github.com/UniversalDependencies/UD_Japanese-GSDLUW"
d=os.path.basename(url)
os.system(f"test -d {d} || git clone --depth=1 {url}")
os.system("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)
os.system(f"test -f {c} || curl -LO {url}")
with open("test.conllu","r",encoding="utf-8") as r:
s=[t[8:].strip() for t in r if t.startswith("# text =")]
for mdl in models:
nlp=pipeline("universal-dependencies",mdl,trust_remote_code=True,aggregation_strategy="simple",device=0)
with open("result.conllu","w",encoding="utf-8") as w:
for t in s:
w.write(nlp(t))
p=subprocess.run([sys.executable,c,"-v","test.conllu","result.conllu"],encoding="utf-8",stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
print(f"\n*** {mdl}",p.stdout,sep="\n",flush=True)
私(安岡孝一)の手元では、以下の結果が出力された。
*** KoichiYasuoka/ltgbert-base-japanese-ud-goeswith
Metric | Precision | Recall | F1 Score | AligndAcc
-----------+-----------+-----------+-----------+-----------
Tokens | 92.56 | 79.98 | 85.81 |
Sentences | 100.00 | 100.00 | 100.00 |
Words | 92.56 | 79.98 | 85.81 |
UPOS | 91.64 | 79.18 | 84.96 | 99.00
XPOS | 0.00 | 0.00 | 0.00 | 0.00
UFeats | 92.56 | 79.98 | 85.81 | 100.00
AllTags | 0.00 | 0.00 | 0.00 | 0.00
Lemmas | 0.00 | 0.00 | 0.00 | 0.00
UAS | 78.98 | 68.24 | 73.22 | 85.32
LAS | 78.20 | 67.57 | 72.50 | 84.48
CLAS | 70.70 | 61.78 | 65.94 | 78.47
MLAS | 68.36 | 59.74 | 63.76 | 75.87
BLEX | 0.00 | 0.00 | 0.00 | 0.00
UPOS/LAS/MLASが84.96/72.50/63.76なので、LASが94.6というTable 3.5の結果には遠く及ばない。うーん、『First language models trained』で使ってるの、もしかしたら国語研長単位UD_Japanese-GSDLUWじゃなくて、国語研短単位UD_Japanese-GSDなのかなあ。