🚀 中文CPT-Base
本項目是CPT-Base的實現,主要用於中文語言理解和生成任務。它在多箇中文自然語言處理任務中展現出了良好的性能,並且不斷進行更新優化。
🚀 快速開始
若要使用CPT,需將定義CPT架構的文件 modeling_cpt.py
(點擊下載)導入到你的項目中。
>>> from modeling_cpt import CPTForConditionalGeneration
>>> from transformers import BertTokenizer
>>> tokenizer = BertTokenizer.from_pretrained("fnlp/cpt-base")
>>> model = CPTForConditionalGeneration.from_pretrained("fnlp/cpt-base")
>>> inputs = tokenizer.encode("北京是[MASK]的首都", return_tensors='pt')
>>> pred_ids = model.generate(input_ids, num_beams=4, max_length=20)
>>> print(tokenizer.convert_ids_to_tokens(pred_ids[i]))
['[SEP]', '[CLS]', '北', '京', '是', '中', '國', '的', '首', '都', '[SEP]']
⚠️ 重要提示
請使用 BertTokenizer
處理模型詞彙,請勿使用原始的 BartTokenizer
。
✨ 主要特性
模型更新
- 2022年12月30日:發佈了CPT和中文BART的更新版本。在新版本中,對以下部分進行了更改:
- 詞彙表:用一個從訓練數據構建的更大的詞彙表(大小為51271)替換了舊的BERT詞彙表,具體操作包括:1) 添加缺失的6800多箇中文字符(其中大部分是繁體字);2) 移除冗餘的標記(例如帶有 ## 前綴的中文字符標記);3) 添加一些英文標記以減少未登錄詞(OOV)。
- 位置嵌入:將
max_position_embeddings
從512擴展到1024。
模型初始化與訓練
使用舊版本的檢查點並進行詞彙對齊來初始化新版本的模型。複製舊檢查點中找到的標記嵌入,其他新添加的參數則隨機初始化。進一步以批量大小2048、最大序列長度1024、峰值學習率2e - 5和熱身比率0.1對新的CPT和中文BART進行了50K步的訓練。
性能對比
與之前的檢查點相比,更新後的模型性能如下:
|
AFQMC |
IFLYTEK |
CSL - sum |
LCSTS |
AVG |
之前版本 |
|
|
|
|
|
bart - base |
73.0 |
60 |
62.1 |
37.8 |
58.23 |
cpt - base |
75.1 |
60.5 |
63.0 |
38.2 |
59.20 |
bart - large |
75.7 |
62.1 |
64.2 |
40.6 |
60.65 |
cpt - large |
75.9 |
61.8 |
63.7 |
42.0 |
60.85 |
更新版本 |
|
|
|
|
|
bart - base |
73.03 |
61.25 |
61.51 |
38.78 |
58.64 |
cpt - base |
74.40 |
61.23 |
62.09 |
38.81 |
59.13 |
bart - large |
75.81 |
61.52 |
64.62 |
40.90 |
60.71 |
cpt - large |
75.97 |
61.63 |
63.83 |
42.08 |
60.88 |
結果表明,更新後的模型與之前的檢查點相比保持了相當的性能。仍有一些情況顯示更新後的模型略遜於之前的模型,原因如下:1) 額外訓練的幾步並未帶來顯著的性能提升;2) 一些下游任務不受新添加標記和更長編碼序列的影響,但對微調超參數敏感。
⚠️ 重要提示
要使用更新後的模型,請更新 modeling_cpt.py
(新版本下載 點擊此處)和詞彙表(刷新緩存)。
📚 詳細文檔
模型描述
這是CPT - Base的一個實現。若要使用CPT,需將定義CPT架構的文件 modeling_cpt.py
(下載 點擊此處)導入到你的項目中。
相關論文
CPT: A Pre-Trained Unbalanced Transformer for Both Chinese Language Understanding and Generation
作者:Yunfan Shao, Zhichao Geng, Yitao Liu, Junqi Dai, Fei Yang, Li Zhe, Hujun Bao, Xipeng Qiu
代碼倉庫
Github鏈接:https://github.com/fastnlp/CPT
📄 許可證
未提及相關許可證信息。
📝 引用
@article{shao2021cpt,
title={CPT: A Pre-Trained Unbalanced Transformer for Both Chinese Language Understanding and Generation},
author={Yunfan Shao and Zhichao Geng and Yitao Liu and Junqi Dai and Fei Yang and Li Zhe and Hujun Bao and Xipeng Qiu},
journal={arXiv preprint arXiv:2109.05729},
year={2021}
}