This repository contains the resources in our paper “Revisiting Pre-trained Models for Chinese Natural Language Processing”, which will be published in “Findings of EMNLP”. You can read our camera-ready paper through ACL Anthology or arXiv pre-print.
Revisiting Pre-trained Models for Chinese Natural Language Processing
Yiming Cui, Wanxiang Che, Ting Liu, Bing Qin, Shijin Wang, Guoping Hu
You may also interested in,
More resources by HFL: https://github.com/ymcui/HFL-Anthology
from modelscope.models import Model
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
if __name__ == '__main__':
task = Tasks.fill_mask
sentence1 = '巴黎是[MASK]国的首都。'
model_id = 'dienstag/chinese-macbert-large'
model = Model.from_pretrained(model_id)
pipeline_ins = pipeline(task=Tasks.fill_mask,
model=model,
model_revision='v1.0.0')
print(pipeline_ins(input=sentence1))
MacBERT is an improved BERT with novel MLM as correction pre-training task, which mitigates the discrepancy of pre-training and fine-tuning.
Instead of masking with [MASK] token, which never appears in the fine-tuning stage, we propose to use similar words for the masking purpose. A similar word is obtained by using Synonyms toolkit (Wang and Hu, 2017), which is based on word2vec (Mikolov et al., 2013) similarity calculations. If an N-gram is selected to mask, we will find similar words individually. In rare cases, when there is no similar word, we will degrade to use random word replacement.
Here is an example of our pre-training task.
Example | |
---|---|
Original Sentence | we use a language model to predict the probability of the next word. |
MLM | we use a language [M] to [M] ##di ##ct the pro [M] ##bility of the next word . |
Whole word masking | we use a language [M] to [M] [M] [M] the [M] [M] [M] of the next word . |
N-gram masking | we use a [M] [M] to [M] [M] [M] the [M] [M] [M] [M] [M] next word . |
MLM as correction | we use a text system to ca ##lc ##ulate the po ##si ##bility of the next word . |
Except for the new pre-training task, we also incorporate the following techniques.
Note that our MacBERT can be directly replaced with the original BERT as there is no differences in the main neural architecture.
For more technical details, please check our paper: Revisiting Pre-trained Models for Chinese Natural Language Processing
If you find our resource or paper is useful, please consider including the following citation in your paper.
@inproceedings{cui-etal-2020-revisiting,
title = "Revisiting Pre-Trained Models for {C}hinese Natural Language Processing",
author = "Cui, Yiming and
Che, Wanxiang and
Liu, Ting and
Qin, Bing and
Wang, Shijin and
Hu, Guoping",
booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: Findings",
month = nov,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.findings-emnlp.58",
pages = "657--668",
}