🚀 中国語RoBERTa-Baseテキスト分類モデル
このモデルは、テキスト分類タスクに特化した中国語RoBERTa-Baseモデルです。UER-pyやTencentPretrainを用いて微調整され、高精度なテキスト分類を実現します。
🚀 クイックスタート
モデルのダウンロード
5つの中国語RoBERTa-Base分類モデルは、UER-py Modelzooページから、または以下のHuggingFaceのリンクからダウンロードできます。
モデルの使用方法
以下は、roberta-base-finetuned-chinanews-chinese
モデルを使用したテキスト分類の例です。
>>> from transformers import AutoModelForSequenceClassification,AutoTokenizer,pipeline
>>> model = AutoModelForSequenceClassification.from_pretrained('uer/roberta-base-finetuned-chinanews-chinese')
>>> tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-finetuned-chinanews-chinese')
>>> text_classification = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
>>> text_classification("北京上个月召开了两会")
[{'label': 'mainland China politics', 'score': 0.7211663722991943}]
✨ 主な機能
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
💻 使用例
基本的な使用法
>>> from transformers import AutoModelForSequenceClassification,AutoTokenizer,pipeline
>>> model = AutoModelForSequenceClassification.from_pretrained('uer/roberta-base-finetuned-chinanews-chinese')
>>> tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-finetuned-chinanews-chinese')
>>> text_classification = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
>>> text_classification("北京上个月召开了两会")
[{'label': 'mainland China politics', 'score': 0.7211663722991943}]
🔧 技術詳細
学習データ
5つの中国語テキスト分類データセットが使用されています。JD full、JD binary、Dianpingデータセットは異なる感情極性のユーザーレビューから構成されています。IfengとChinanewsは異なるトピッククラスのニュース記事の最初の段落から構成されています。これらはGlyphプロジェクトによって収集され、詳細は対応する論文で議論されています。
学習手順
モデルは、UER-pyを使用してTencent Cloud上で微調整されています。事前学習モデルchinese_roberta_L-12_H-768をベースに、シーケンス長512で3エポックの微調整を行います。各エポックの終了時に、開発セットで最良の性能が得られたときにモデルが保存されます。異なるモデルで同じハイパーパラメータを使用しています。
roberta-base-finetuned-chinanews-chinese
の場合の例:
python3 finetune/run_classifier.py --pretrained_model_path models/cluecorpussmall_roberta_base_seq512_model.bin-250000 \
--vocab_path models/google_zh_vocab.txt \
--train_path datasets/glyph/chinanews/train.tsv \
--dev_path datasets/glyph/chinanews/dev.tsv \
--output_model_path models/chinanews_classifier_model.bin \
--learning_rate 3e-5 --epochs_num 3 --batch_size 32 --seq_length 512
最後に、事前学習モデルをHuggingfaceの形式に変換します。
python3 scripts/convert_bert_text_classification_from_uer_to_huggingface.py --input_model_path models/chinanews_classifier_model.bin \
--output_model_path pytorch_model.bin \
--layers_num 12
BibTeXエントリと引用情報
@article{liu2019roberta,
title={Roberta: A robustly optimized bert pretraining approach},
author={Liu, Yinhan and Ott, Myle and Goyal, Naman and Du, Jingfei and Joshi, Mandar and Chen, Danqi and Levy, Omer and Lewis, Mike and Zettlemoyer, Luke and Stoyanov, Veselin},
journal={arXiv preprint arXiv:1907.11692},
year={2019}
}
@article{zhang2017encoding,
title={Which encoding is the best for text classification in chinese, english, japanese and korean?},
author={Zhang, Xiang and LeCun, Yann},
journal={arXiv preprint arXiv:1708.02657},
year={2017}
}
@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}