模型:

uer/roberta-base-finetuned-chinanews-chinese

英文

中文 RoBERTa-Base 文本分类模型

模型描述

这是由 UER-py Fine-tune 的 5 个中文 RoBERTa-Base 分类模型。您可以从以下链接中直接下载 5 个中文 RoBERTa-Base 分类模型,也可以从 UER-py Modelzoo page (以 UER-py 格式)进行下载:

Dataset Link
JD full 1236321
JD binary 1237321
Dianping 1238321
Ifeng 1239321
Chinanews 12310321

如何使用

您可以在文本分类流水线中直接使用该模型(以 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}]

训练数据

使用了 5 个中文文本分类数据集。JD full、JD binary 和 Dianping 数据集包含了不同情感极性的用户评论。Ifeng 和 Chinanews 包含了不同主题类别的新闻文章的首段。它们是由 Glyph 项目收集的,更多细节在相应的 paper 中进行了讨论。

训练过程

使用 UER-py Tencent Cloud 上对模型进行 Fine-tune。我们在512个序列长度上进行了三个epoch的Fine-tune,基于预训练模型 chinese_roberta_L-12_H-768 进行。在每个epoch结束时,当在开发集上取得最佳性能时保存模型。我们在不同模型上使用相同的超参数。

以 roberta-base-finetuned-chinanews-chinese 为例

python3 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{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{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}
}