0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Camphr-Udifyを5年後の今Google Colaboratoryで動かすには

Last updated at Posted at 2025-07-19

2020年7月12日の日記(archive.org参照)で紹介したCamphr-Udifyだが、さすがに5年もの月日が経過すると動かすのが難しくなってきた。AllenNLPの開発終了もあって、現行のpython3.9以降では動作困難らしく、python3.8にダウングレードする必要があるようだ。Google Colaboratoryだと、こんな感じ。

!apt install python3.8 python3.8-dev python3.8-distutils
import sys
v=".".join(sys.version.split(".")[0:2])
!update-alternatives --remove-all python3
!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python{v} 1
!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
!apt install python3-pip
!pip install "setuptools<57" poetry deplacy cymem==2.0.11 preshed==3.0.10
url="https://github.com/PKSHATechnology-Research/camphr_models"
f="en_udify-0.7.tar.gz"
!test -f {f} || curl -LO {url+"/releases/download/0.7.0/"+f}
!test -d /usr/local/lib/python3.8/dist-packages/camphr || pip install {f} "numpy<1.20" "spacy<2.3" --no-build-isolation
!echo 1 | update-alternatives --config python3
!pip install deplacy
import subprocess
nlp=lambda t:subprocess.run(["python3.8","-c","\n".join(["import spacy,deplacy","n=spacy.load('en_udify')","print(deplacy.to_conllu(n(input())),end='')"])],input=t,stdout=subprocess.PIPE,encoding="utf-8").stdout
doc=nlp("Rainy days and Mondays always get me down")
import deplacy
deplacy.render(doc)
deplacy.serve(doc,port=None)

セッションの再起動を促すメッセージが出るかもしれないが、あえて「キャンセル」して動作を続けたところ、私(安岡孝一)の手元では、以下の結果が出力された。

Rainy   ADJ   <════╗   amod
days    NOUN  ═══╗═╝<╗ nsubj
and     CCONJ <╗ ║   ║ cc
Mondays PROPN ═╝<╝   ║ conj
always  ADV   <════╗ ║ advmod
get     VERB  ═╗═╗═╝═╝ root
me      PRON  <╝ ║     obj
down    ADV   <══╝     advmod

1	Rainy	rainy	ADJ	Degree=Pos	_	2	amod	_	Translit=rainy
2	days	day	NOUN	Number=Plur	_	6	nsubj	_	_
3	and	and	CCONJ	_	_	4	cc	_	_
4	Mondays	Mondays	PROPN	Number=Plur	_	2	conj	_	Translit=mondays
5	always	always	ADV	_	_	6	advmod	_	_
6	get	get	VERB	Mood=Ind|Tense=Pres|VerbForm=Fin	_	0	root	_	_
7	me	I	PRON	Case=Acc|Number=Sing|Person=1|PronType=Prs	_	6	obj	_	_
8	down	down	ADV	_	_	6	advmod	_	SpaceAfter=No

2025-07-19Camphr-Udify.png

5年前と同様の結果が出力されており、まだまだ現役のシステムである。ただ、環境の方がどんどん変化していて、動作が難しくなってきているわけだ。さて、python3.8もサポートが切れてるし、今後どうすればいいのかな。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?