cLang-8データセット:ツールの動かし方の備忘録

ACL2021,"A Simple Recipe for Multilingual Grammatical Error Correction"の論文[Rothe+ 2021]で,cLang-8データセットが報告されました.cLang-8データセットはCleaned LANG-8 Corpusの呼称で,既に公開されているLang-8コーパス[Mizumoto+ 2011]のノイズを取り払うことで綺麗にしたようなデータセットです.

この記事では公開されているツールの動かし方の備忘録を残しておきます.cLang8は直接公開されておらず,Lang8からcLang8を作るようなスクリプトが公開されています.このスクリプトを使って,各自の環境でcLang8を作ることになります.基本的に公式のリファレンスの通りにやれば動きます.

手順

Official Repository:

github.com

1. Git Large File Storageをインストール

$ brew install git-lfs

でインストールした後,

$ git-lfs install

とやるとGit LFS initialized.と言ってくれるのでこれで完了.インストールできたか確認したいときは

$ git-lfs version

を実行してみる.

詳細は公式サイトを参照.

2. 公式リポジトリをclone

$ git clone https://github.com/google-research-datasets/clang8.git

3. Lang-8コーパスをダウンロード

以下のGoogle Formにアクセスして,必要事項を書き込んで送信.すぐにリンク付きのメールが送られてきます.リンクは2つ掲載されていますが,... raw format containing all the data up to 2010.と書いてあるほうのリンクを選びます.300MBくらいのzipなので,適当な手段でダウンロードして解凍.

解凍結果のディレクトリ構造が

├── lang-8-20111007-L1-v2.dat
└── README

みたいになっていればok.

docs.google.com

4. run.shを書き換える

cloneしたリポジトリの中にあるrun.shLANG8_DIR=を編集します.

readonly LANG8_DIR='<INSERT LANG8 DIRECTORY HERE>'
↓
readonly LANG8_DIR='/lang-8-20111007-2.0/'

みたいな感じです.

5. run.shを実行

結構時間かかります(CPU次第?).

$ sh run.sh

6. 出力を確認

結果はoutput_data/に保存されます.各tsvの行数は公式リポジトリの記載の通りになるはずです.試しに英語のものを見てみて,

$ wc output_data/clang8_source_target_en.spacy_tokenized.tsv 
 2372119  56656257 267513611 output_data/clang8_source_target_en.spacy_tokenized.tsv

みたいになればokです.

出力にはソースとターゲットがタブ区切りになったペアが1行1ペアの形式で格納されます.

7. 蛇足

fairseqの学習などのためにソースとターゲットを別々のファイルにする場合は

$ cut -f 1 clang8_source_target_en.spacy_tokenized.tsv > train.src
$ cut -f 2 clang8_source_target_en.spacy_tokenized.tsv > train.trg

などのように書けます.また,ERRANT [Felice+ 2016, Bryant+ 2017] を用いてreferenceのM2ファイルを作る場合,

$ errant_parallel -orig train.src -cor train.trg -out ref.m2

のように書けます.

エラーたち

いくつかエラーが出ました.

Could not find a version that satisfies the requirement ...

  Could not find a version that satisfies the requirement thinc<8.1.0,>=8.0.8 (from versions: 6.12.0, 6.12.1, 7.0.0.dev1, 7.0.0.dev2, 7.0.0.dev6, 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.8, 7.1.0, 7.1.1, 7.2.0.dev3, 7.2.0, 7.3.0, 7.3.1, 7.4.0.dev0, 7.4.0.dev1, 7.4.0.dev2, 7.4.0, 7.4.1, 8.0.0.dev0, 8.0.0.dev2, 8.0.0.dev4, 8.0.0a0, 8.0.0a1, 8.0.0a2, 8.0.0a3, 8.0.0a6, 8.0.0a8, 8.0.0a9, 8.0.0a11, 8.0.0a12, 8.0.0a13, 8.0.0a14, 8.0.0a16, 8.0.0a17, 8.0.0a18, 8.0.0a19, 8.0.0a20, 8.0.0a21, 8.0.0a22, 8.0.0a23, 8.0.0a24, 8.0.0a25)
No matching distribution found for thinc<8.1.0,>=8.0.8
You are using pip version 10.0.1, however version 21.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

原因:pipのバージョンが低いです.とりあえずupgradeしとけばいいので,run.sh

virtualenv -p python3 .
source ./bin/activate

pip install -r requirements.txt

↓

virtualenv -p python3 .
source ./bin/activate
pip install --upgrade pip
pip install -r requirements.txt

のように追記して対応.

clang8/run.sh: 12: clang8/run.sh: source: not found

お使いのbashか何かにはsourceコマンドがありません.代わりにピリオドなら動きます.run.shを次のように編集

source ./bin/activate
↓
. ./bin/activate

ValueError: not enough values to unpack (expected 5, got 1)

このissueにもある通り,データが正確にcloneできていません.git-lfsが動いていない状態でcloneしたリポジトリrun.shを実行した場合にこのエラーが出ます.git-lfsを正しくインストールしましょう.

参考文献

Rothe, S., Mallinson, J., Malmi, E., Krause, S., & Severyn, A. (2021). A Simple Recipe for Multilingual Grammatical Error Correction. arXiv preprint arXiv:2106.03830.

Mizumoto, T., Komachi, M., Nagata, M., & Matsumoto, Y. (2011, November). Mining revision log of language learning SNS for automated Japanese error correction of second language learners. In Proceedings of 5th International Joint Conference on Natural Language Processing (pp. 147-155).

Felice, M., Bryant, C., & Briscoe, E. (2016). Automatic extraction of learner errors in ESL sentences using linguistically enhanced alignments. Association for Computational Linguistics.

Bryant, C., Felice, M., & Briscoe, E. (2017, July). Automatic annotation and evaluation of error types for grammatical error correction. Association for Computational Linguistics.