🚀 中文CPT-Large
本項目是CPT-Large模型的實現,可用於中文語言理解與生成任務,如文本分類、摘要生成等。通過更新詞彙表和位置嵌入等操作,模型在多個任務上取得了不錯的效果。
✨ 主要特性
- 詞彙表更新:使用從訓練數據構建的更大的詞彙表(大小為51271),添加了缺失的6800多箇中文字符(大多為繁體字),移除了冗餘標記,並添加了一些英文標記以減少OOV。
- 位置嵌入擴展:將最大位置嵌入從512擴展到1024。
- 多任務表現:在AFQMC、IFLYTEK、CSL - sum、LCSTS等多個任務上進行了評估,相比之前的版本有一定的性能提升。
📦 安裝指南
若要使用更新後的模型,請更新 modeling_cpt.py
(新版本下載此處)和詞彙表(刷新緩存)。
💻 使用示例
基礎用法
>>> from modeling_cpt import CPTForConditionalGeneration
>>> from transformers import BertTokenizer
>>> tokenizer = BertTokenizer.from_pretrained("fnlp/cpt-large")
>>> model = CPTForConditionalGeneration.from_pretrained("fnlp/cpt-large")
>>> input_ids = 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[0]))
['[SEP]', '[CLS]', '北', '京', '是', '中', '國', '的', '首', '都', '[SEP]']
注意:請使用 BertTokenizer
處理模型詞彙表,請勿使用原始的 BartTokenizer
。
📚 詳細文檔
新聞
2022年12月30日
發佈了CPT和中文BART的更新版本。在新版本中,我們更改了以下部分:
- 詞彙表:我們用一個從訓練數據構建的更大的、大小為51271的詞彙表替換了舊的BERT詞彙表,其中:1) 添加了缺失的6800多箇中文字符(大多為繁體字);2) 移除了冗餘標記(例如,帶有##前綴的中文字符標記);3) 添加了一些英文標記以減少OOV。
- 位置嵌入:我們將最大位置嵌入從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) 一些下游任務不受新添加的標記和更長的編碼序列的影響,但對微調超參數敏感。
模型描述
這是CPT - Large的一個實現。要使用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}
}