yasuokaの日記: AllenNLPの英語係り受け解析モデルをdeplacyに繫ぐには
私(安岡孝一)の10月25日の日記の読者から、AllenNLPの英語係り受けモデルはbiaffine-dependency-parser-ptb-2020.04.06.tar.gzよりbiaffine-dependency-parser-ptb-2020.04.01.tar.gzの方が性能がいい、との情報をいただいた。早速、Google Colaboratoryで動かしてみよう。
!pip install -U deplacy allennlp allennlp-models urllib3
from allennlp.predictors.predictor import Predictor
predictor=Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/biaffine-dependency-parser-ptb-2020.04.01.tar.gz")
def nlp(t):
s=predictor.predict(t)
return "\n".join(["\t".join([str(i+1),w,"_",p,p,"_",str(h),d,"_","_"]) for i,(w,p,h,d) in enumerate(zip(s["words"],s["pos"],s["predicted_heads"],s["predicted_dependencies"]))])+"\n\n"
doc=nlp("I saw a horse yesterday which had no name.")
import deplacy
deplacy.render(doc)
deplacy.serve(doc,port=None)
「I saw a horse yesterday which had no name.」を係り受け解析してみたところ、私の手元では以下の結果になった。
I PRON <════════╗ nsubj
saw VERB ═════╗═╗═╝═╗ root
a DET <╗ ║ ║ ║ det
horse NOUN ═╝<╗ ║ ║ ║ nsubj
yesterday NOUN <══║═╝ ║ ║ tmod
which DET ═══╝<╗ ║ ║ aux
had AUX ═══╗═╝<╝ ║ ccomp
no DET <╗ ║ ║ advmod
name NOUN ═╝<╝ ║ dobj
. PUNCT <══════════╝ punct
1 I _ PRON PRON _ 2 nsubj _ _
2 saw _ VERB VERB _ 0 root _ _
3 a _ DET DET _ 4 det _ _
4 horse _ NOUN NOUN _ 6 nsubj _ _
5 yesterday _ NOUN NOUN _ 2 tmod _ _
6 which _ DET DET _ 7 aux _ _
7 had _ AUX AUX _ 2 ccomp _ _
8 no _ DET DET _ 9 advmod _ _
9 name _ NOUN NOUN _ 7 dobj _ _
10 . _ PUNCT PUNCT _ 2 punct _ _
SVGで可視化すると、こんな感じ。正直に言って、あまり読めてない。まあ、AllenNLPを使った英語の係り受け解析なら、Camphr-Udifyの方が性能がいいので、そっちを使うべきかな。
AllenNLPの英語係り受け解析モデルをdeplacyに繫ぐには More ログイン