🚀 中文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}
}