🚀 中国語事前学習Longformerモデル | Longformer_ZH with PyTorch
TransformerのO(n^2)の計算量と比較して、Longformerは最大4K文字レベルの文書シーケンスを線形計算量で処理する効率的な方法を提供します。Longformer Attentionには標準的な自己注意機構とグローバル注意機構が含まれており、モデルが長いシーケンスの情報をより良く学習できるようになっています。
TransformerモデルのO(n^2)の計算量と比較して、Longformerは線形計算量で長文書レベルのシーケンスを処理する効率的な方法を提供します。Longformerの注意機構は、標準的な自己注意機構の代わりに使用でき、ローカルなウィンドウ注意とタスクに応じたグローバル注意を組み合わせています。
中国語のLongformerや長シーケンスレベルの中国語タスクに関するリソースが少ないことに着目し、ここでは事前学習した中国語Longformerモデルのパラメータをオープンソースで公開し、対応するロード方法と事前学習スクリプトを提供します。
中国語のLongformerや長シーケンスレベルの中国語タスクに関するリソースはあまり多くありません。そのため、研究者の皆さんのお役に立てるように、事前学習したLongformerモデルをオープンソースで公開しています。
🚀 クイックスタート
📦 インストール
あなたはGoogle Driveまたは百度雲から私たちのモデルをダウンロードすることができます。
You could get Longformer_zh from Google Drive or Baidu Yun.
- Google Drive: https://drive.google.com/file/d/1IDJ4aVTfSFUQLIqCYBtoRpnfbgHPoxB4/view?usp=sharing
- 百度雲: リンク:https://pan.baidu.com/s/1HaVDENx52I7ryPFpnQmq1w 提取コード:y601
私たちはまた、Huggingfaceを使った自動ダウンロードも提供しています。
We also provide auto load with HuggingFace.Transformers.
from Longformer_zh import LongformerZhForMaksedLM
LongformerZhForMaksedLM.from_pretrained('ValkyriaLenneth/longformer_zh')
💡 使用例
基本的な使用法
from Longformer_zh import LongformerZhForMaksedLM
LongformerZhForMaksedLM.from_pretrained('ValkyriaLenneth/longformer_zh')
⚠️ 注意事項
-
直接 transformers.LongformerModel.from_pretrained
を使ってモデルをロードしてください
-
Please use transformers.LongformerModel.from_pretrained
to load the model directly
-
以下の注意事項は廃止されています
-
The following notices are abondoned, please ignore them.
-
英語版のLongformerとは異なり、中国語版のLongformerはRoberta_zhモデルをベースにしており、本質的には Transformers.BertModel
のサブクラスであり、RobertaModel
ではありません。そのため、オリジナルのコードで直接ロードすることはできません。
-
Different with origin English Longformer, Longformer_Zh is based on Roberta_zh which is a subclass of Transformers.BertModel
not RobertaModel
. Thus it is impossible to load it with origin code.
-
私たちは修正された中国語版のLongformerファイルを提供しており、これを使ってパラメータをロードすることができます。
-
We provide modified Longformer_zh class, you can use it directly to load the model.
-
このパラメータをより多くのタスクに適用したい場合は、Longformer_zh.py
を参考にしてAttention Layerを置き換えてください。
-
If you want to use our model on more down-stream tasks, please refer to Longformer_zh.py
and replace Attention layer with Longformer Attention layer.
📚 ドキュメント
事前学習について
-
私たちの事前学習コーパスは https://github.com/brightmart/nlp_chinese_corpus から取得しており、Longformerの論文に基づき、4種類の異なる中国語コーパスを混合したデータを使用して事前学習を行っています。
-
The corpus of pretraining is from https://github.com/brightmart/nlp_chinese_corpus. Based on the paper of Longformer, we use a mixture of 4 different chinese corpus for pretraining.
-
私たちのモデルはRoberta_zh_mid (https://github.com/brightmart/roberta_zh) をベースにしており、事前学習スクリプトは https://github.com/allenai/longformer/blob/master/scripts/convert_model_to_long.ipynb を参考にしています。
-
The basement of our model is Roberta_zh_mid (https://github.com/brightmart/roberta_zh). Pretraining scripts is modified from https://github.com/allenai/longformer/blob/master/scripts/convert_model_to_long.ipynb.
-
同時に、私たちはオリジナルのモデルに Whole-Word-Masking
機構を導入し、中国語の特性により適合させています。
-
We introduce Whole-Word-Masking
method into pretraining for better fitting Chinese language.
-
Whole-Word-Masking
のコードはTensorFlow版のRoberta_zhから改変したもので、私たちの知る限り、最初のオープンソースのPytorch版WWMです。
-
Our WWM scripts is refacted from Roberta_zh_Tensorflow, as far as we know, it is the first open source Whole-word-masking scripts in Pytorch.
-
モデルの max_seq_length
は4096で、4台のTitan RTXで3Kステップの事前学習に約4日かかります。
-
Max seuence length is 4096 and the pretraining took 4 days on 4 * Titan RTX.
-
私たちは Nvidia.Apex
を使用して混合精度学習を導入し、事前学習を高速化しています。
-
We use Nvidia.Apex
to accelerate pretraining.
-
データの前処理には、Jieba
を使った中国語のトークナイザーと JIONLP
を使ったデータクリーニングを行っています。
-
We use Jieba
Chinese tokenizer and JIONLP
data cleaning.
-
詳細については、私たちの事前学習スクリプトを確認してください。
-
For more details, please check our pretraining scripts.
評価
CCF Sentiment Analysis
- 中国語の長文レベルのタスクが少ないため、CCF-Sentiment-Analysisタスクを使って評価を行いました。
- Since it is hard to acquire open-sourced long sequence level chinese NLP task, we use CCF-Sentiment-Analysis for evaluation.
モデル |
Dev F |
Bert |
80.3 |
Bert-wwm-ext |
80.5 |
Roberta-mid |
80.5 |
Roberta-large |
81.25 |
Longformer_SC |
79.37 |
Longformer_ZH |
80.51 |
事前学習BPC
- 私たちは事前学習のBPC(文字あたりのビット数)を提供しています。BPCが低いほど、言語モデルの性能が良いことを意味します。PPLと同じように考えることができます。
- We also provide BPC scores of pretraining, the lower BPC score, the better performance Langugage Model has. You can also treat it as PPL.
モデル |
BPC |
学習前のLongformer |
14.78 |
学習後のLongformer |
3.10 |
CMRC(中国語機械読解)
モデル |
F1 |
EM |
Bert |
85.87 |
64.90 |
Roberta |
86.45 |
66.57 |
Longformer_zh |
86.15 |
66.84 |
中国語照応解析
モデル |
Conll-F1 |
精度 |
再現率 |
Bert |
66.82 |
70.30 |
63.67 |
Roberta |
67.77 |
69.28 |
66.32 |
Longformer_zh |
67.81 |
70.13 |
65.64 |
📄 謝辞
東京工業大学の奥村・船越研究室に、計算資源を提供していただき、このプロジェクトを完了する機会を与えていただいたことに感謝いたします。
Thanks Okumula·Funakoshi Lab from Tokyo Institute of Technology who provides the devices and oppotunity for me to finish this project.