🚀 中国語の単語ベースRoBERTaミニモデル
このプロジェクトは、中国語の単語ベースRoBERTaモデルのセットを提供します。これらのモデルは、中国語の文字ベースのモデルと比較して、多くの場合でより良い性能を発揮し、より高速に動作します。
🚀 クイックスタート
このモデルを使って、マスクされた言語モデリングを行うことができます。以下は、単語ベースのRoBERTa-Mediumモデルを使った例です。
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='uer/roberta-medium-word-chinese-cluecorpussmall')
>>> unmasker("[MASK]的首都是北京。")
[
{'sequence': '中国 的首都是北京。',
'score': 0.21525809168815613,
'token': 2873,
'token_str': '中国'},
{'sequence': '北京 的首都是北京。',
'score': 0.15194718539714813,
'token': 9502,
'token_str': '北京'},
{'sequence': '我们 的首都是北京。',
'score': 0.08854265511035919,
'token': 4215,
'token_str': '我们'},
{'sequence': '美国 的首都是北京。',
'score': 0.06808705627918243,
'token': 7810,
'token_str': '美国'},
{'sequence': '日本 的首都是北京。',
'score': 0.06071401759982109,
'token': 7788,
'token_str': '日本'}
]
✨ 主な機能
- 高速性:文字ベースのモデルと比較して、シーケンス長が短いため、より高速に動作します。
- 高性能:多くの中国語タスクで、文字ベースのモデルよりも良い結果を達成します。
📦 インストール
このモデルは、HuggingFaceから直接ダウンロードすることができます。以下のリンクから、5種類の中国語RoBERTaミニモデルをダウンロードできます。
💻 使用例
基本的な使用法
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='uer/roberta-medium-word-chinese-cluecorpussmall')
>>> unmasker("[MASK]的首都是北京。")
[
{'sequence': '中国 的首都是北京。',
'score': 0.21525809168815613,
'token': 2873,
'token_str': '中国'},
{'sequence': '北京 的首都是北京。',
'score': 0.15194718539714813,
'token': 9502,
'token_str': '北京'},
{'sequence': '我们 的首都是北京。',
'score': 0.08854265511035919,
'token': 4215,
'token_str': '我们'},
{'sequence': '美国 的首都是北京。',
'score': 0.06808705627918243,
'token': 7810,
'token_str': '美国'},
{'sequence': '日本 的首都是北京。',
'score': 0.06071401759982109,
'token': 7788,
'token_str': '日本'}
]
高度な使用法
from transformers import AlbertTokenizer, BertModel
tokenizer = AlbertTokenizer.from_pretrained('uer/roberta-medium-word-chinese-cluecorpussmall')
model = BertModel.from_pretrained("uer/roberta-medium-word-chinese-cluecorpussmall")
text = "用你喜欢的任何文本替换我。"
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
from transformers import AlbertTokenizer, TFBertModel
tokenizer = AlbertTokenizer.from_pretrained('uer/roberta-medium-word-chinese-cluecorpussmall')
model = TFBertModel.from_pretrained("uer/roberta-medium-word-chinese-cluecorpussmall")
text = "用你喜欢的任何文本替换我。"
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
📚 ドキュメント
モデルの詳細
これらのモデルは、UER-pyによって事前学習された、5種類の中国語の単語ベースRoBERTaモデルです。また、TencentPretrainによっても事前学習することができます。
評価結果
文字ベースのモデルと比較して、単語ベースのモデルは、ほとんどの場合で良い結果を達成します。以下は、6つの中国語タスクの開発セットでのスコアです。
Model |
Score |
book_review |
chnsenticorp |
lcqmc |
tnews(CLUE) |
iflytek(CLUE) |
ocnli(CLUE) |
RoBERTa-Tiny(char) |
72.3 |
83.4 |
91.4 |
81.8 |
62.0 |
55.0 |
60.3 |
RoBERTa-Tiny(word) |
74.4(+2.1) |
86.7 |
93.2 |
82.0 |
66.4 |
58.2 |
59.6 |
RoBERTa-Mini(char) |
75.9 |
85.7 |
93.7 |
86.1 |
63.9 |
58.3 |
67.4 |
RoBERTa-Mini(word) |
76.9(+1.0) |
88.5 |
94.1 |
85.4 |
66.9 |
59.2 |
67.3 |
RoBERTa-Small(char) |
76.9 |
87.5 |
93.4 |
86.5 |
65.1 |
59.4 |
69.7 |
RoBERTa-Small(word) |
78.4(+1.5) |
89.7 |
94.7 |
87.4 |
67.6 |
60.9 |
69.8 |
RoBERTa-Medium(char) |
78.0 |
88.7 |
94.8 |
88.1 |
65.6 |
59.5 |
71.2 |
RoBERTa-Medium(word) |
79.1(+1.1) |
90.0 |
95.1 |
88.0 |
67.8 |
60.6 |
73.0 |
RoBERTa-Base(char) |
79.7 |
90.1 |
95.2 |
89.2 |
67.0 |
60.9 |
75.5 |
RoBERTa-Base(word) |
80.4(+0.7) |
91.1 |
95.7 |
89.4 |
68.0 |
61.5 |
76.8 |
学習データ
学習データには、CLUECorpusSmallが使用されています。単語分割には、Googleのsentencepieceが使用されています。
学習手順
モデルは、UER-pyを使って、Tencent Cloud上で事前学習されています。シーケンス長128で1,000,000ステップ、シーケンス長512で250,000ステップの事前学習が行われています。
BibTeX entry and citation info
@article{devlin2018bert,
title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},
author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
journal={arXiv preprint arXiv:1810.04805},
year={2018}
}
@article{turc2019,
title={Well-Read Students Learn Better: On the Importance of Pre-training Compact Models},
author={Turc, Iulia and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
journal={arXiv preprint arXiv:1908.08962v2 },
year={2019}
}
@article{zhao2019uer,
title={UER: An Open-Source Toolkit for Pre-training Models},
author={Zhao, Zhe and Chen, Hui and Zhang, Jinbin and Zhao, Xin and Liu, Tao and Lu, Wei and Chen, Xi and Deng, Haotang and Ju, Qi and Du, Xiaoyong},
journal={EMNLP-IJCNLP 2019},
pages={241},
year={2019}
}
@article{zhao2023tencentpretrain,
title={TencentPretrain: A Scalable and Flexible Toolkit for Pre-training Models of Different Modalities},
author={Zhao, Zhe and Li, Yudong and Hou, Cheng and Zhao, Jing and others},
journal={ACL 2023},
pages={217},
year={2023}