GiNZA Google Colabにインストールしてみる

記事作成日: 2023-07-04

オープンソースの日本語自然言語処理ライブラリGiNZAをGoogle Colabにインストールしてみました。

install

!pip install -U ginza ja-ginza

Google Colabで上記のコマンドを実行するとインストールが開始しました。

図.画像: Google Colabにインストール
Collecting ginza
  Downloading ginza-5.1.2-py3-none-any.whl (20 kB)
Collecting ja-ginza
  Downloading ja_ginza-5.1.2-py3-none-any.whl (59.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 59.1/59.1 MB 16.7 MB/s eta 0:00:00
Collecting spacy<3.5.0,>=3.2.0 (from ginza)
  Downloading spacy-3.4.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 62.0 MB/s eta 0:00:00
Collecting plac>=1.3.3 (from ginza)
  Downloading plac-1.3.5-py2.py3-none-any.whl (22 kB)
Collecting SudachiPy<0.7.0,>=0.6.2 (from ginza)
  Downloading SudachiPy-0.6.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 53.3 MB/s eta 0:00:00
Collecting SudachiDict-core>=20210802 (from ginza)
  Downloading SudachiDict-core-20230110.tar.gz (9.0 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.10 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (3.0.12)
Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (1.0.4)
Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (1.0.9)
Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (2.0.7)
Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (3.0.8)
Requirement already satisfied: thinc<8.2.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (8.1.10)
Collecting wasabi<1.1.0,>=0.9.1 (from spacy<3.5.0,>=3.2.0->ginza)
  Downloading wasabi-0.10.1-py3-none-any.whl (26 kB)
Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (2.4.6)
Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (2.0.8)
Requirement already satisfied: typer<0.8.0,>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (0.7.0)
Requirement already satisfied: pathy>=0.3.5 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (0.10.2)
Requirement already satisfied: smart-open<7.0.0,>=5.2.1 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (6.3.0)
Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (4.65.0)
Requirement already satisfied: numpy>=1.15.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (1.22.4)
Requirement already satisfied: requests<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (2.27.1)
Requirement already satisfied: pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (1.10.9)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (3.1.2)
Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (67.7.2)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (23.1)
Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /usr/local/lib/python3.10/dist-packages (from spacy<3.5.0,>=3.2.0->ginza) (3.3.0)
Requirement already satisfied: typing-extensions>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4->spacy<3.5.0,>=3.2.0->ginza) (4.6.3)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.2.0->ginza) (1.26.16)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.2.0->ginza) (2023.5.7)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.2.0->ginza) (2.0.12)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.2.0->ginza) (3.4)
Requirement already satisfied: blis<0.8.0,>=0.7.8 in /usr/local/lib/python3.10/dist-packages (from thinc<8.2.0,>=8.1.0->spacy<3.5.0,>=3.2.0->ginza) (0.7.9)
Requirement already satisfied: confection<1.0.0,>=0.0.1 in /usr/local/lib/python3.10/dist-packages (from thinc<8.2.0,>=8.1.0->spacy<3.5.0,>=3.2.0->ginza) (0.0.4)
Requirement already satisfied: click<9.0.0,>=7.1.1 in /usr/local/lib/python3.10/dist-packages (from typer<0.8.0,>=0.3.0->spacy<3.5.0,>=3.2.0->ginza) (8.1.3)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->spacy<3.5.0,>=3.2.0->ginza) (2.1.3)
Building wheels for collected packages: SudachiDict-core
  Building wheel for SudachiDict-core (setup.py) ... done
  Created wheel for SudachiDict-core: filename=SudachiDict_core-20230110-py3-none-any.whl size=71665379 sha256=5cb92f241d51749e354cf489fca2a6a2c589ed32a65b92b1b818f44f3a58cd51
  Stored in directory: /root/.cache/pip/wheels/35/35/8a/5cd8203a86e68ccefc49d4a2975165bb9ee369d2693eb4049b
Successfully built SudachiDict-core
Installing collected packages: wasabi, SudachiPy, plac, SudachiDict-core, spacy, ginza, ja-ginza
  Attempting uninstall: wasabi
    Found existing installation: wasabi 1.1.2
    Uninstalling wasabi-1.1.2:
      Successfully uninstalled wasabi-1.1.2
  Attempting uninstall: spacy
    Found existing installation: spacy 3.5.3
    Uninstalling spacy-3.5.3:
      Successfully uninstalled spacy-3.5.3
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
en-core-web-sm 3.5.0 requires spacy<3.6.0,>=3.5.0, but you have spacy 3.4.4 which is incompatible.
Successfully installed SudachiDict-core-20230110 SudachiPy-0.6.7 ginza-5.1.2 ja-ginza-5.1.2 plac-1.3.5 spacy-3.4.4 wasabi-0.10.1

エラーが出ているので翻訳してみました。

ERROR: pipの依存関係解決ツールは、現在インストールされているすべてのパッケージを考慮していません。この振る舞いが、以下の依存関係の衝突の原因となっています。

en-core-web-sm 3.5.0 には spacy<3.6.0,>=3.5.0 が必要ですが、spacy 3.4.4 があり互換性がありません。

ひとまず気にせず次へ進んでみます。

ランタイムの再起動

メニューバー → [ランタイム] → [ランタイムを再起動]をクリックすると以下のダイアログが出たので「はい」を押してGoogle Colabを再起動しました。

図.画像: ランタイムの再起動

Hello GiNZA

一行書いてインストールしただけですが、早速使ってみました。

図.画像: Hello GiNZA

いや~、吃驚するほど簡単でした。Google Colab & Ginzaは楽だなぁ。

以前自分のPCにMecab入れたときは結構苦労しました。

なお、OSError: [E050] Can't find model 'ja_ginza'. It doesn't seem to be a Python package or a valid path to a data directory.

といエラーが出る場合、ja_ginzaがインストールされていないのでinstallし直した方がいいでしょう。

Window10にインストール

pip install -U ginza ja_ginza

こちらもこの一行コードでインストール完了。特にエラーも発生せず。

参考リンク