TsinghuaAI/CPM-Generate

Model

42

stars

11

commits

1

linked in READMEs

Jul 29, 2021

updated

cpm
endpoints_compatible
gpt2
pytorch
text-generation
text-generation-inference
tf
transformers

README

CPM-Generate

Model description

CPM (Chinese Pre-trained Language Model) is a Transformer-based autoregressive language model, with 2.6 billion parameters and 100GB Chinese training data. To the best of our knowledge, CPM is the largest Chinese pre-trained language model, which could facilitate downstream Chinese NLP tasks, such as conversation, essay generation, cloze test, and language understanding. [Project] [Model] [Paper]

Intended uses & limitations

How to use

from transformers import TextGenerationPipeline, AutoTokenizer, AutoModelWithLMHead

tokenizer = AutoTokenizer.from_pretrained("TsinghuaAI/CPM-Generate")
model = AutoModelWithLMHead.from_pretrained("TsinghuaAI/CPM-Generate")

text_generator = TextGenerationPipeline(model, tokenizer)
text_generator('清华大学', max_length=50, do_sample=True, top_p=0.9)

Limitations and bias

The text generated by CPM is automatically generated by a neural network model trained on a large number of texts, which does not represent the authors' or their institutes' official attitudes and preferences. The text generated by CPM is only used for technical and scientific purposes. If it infringes on your rights and interests or violates social morality, please do not propagate it, but contact the authors and the authors will deal with it promptly.

Training data

We collect different kinds of texts in our pre-training, including encyclopedia, news, novels, and Q&A. The details of our training data are shown as follows.

Data SourceEncyclopediaWebpageStoryNewsDialog
Size~40GB~39GB~10GB~10GB~1GB

Training procedure

Based on the hyper-parameter searching on the learning rate and batch size, we set the learning rate as \(1.5\times10^{-4}\) and the batch size as \(3,072\), which makes the model training more stable. In the first version, we still adopt the dense attention and the max sequence length is \(1,024\). We will implement sparse attention in the future. We pre-train our model for \(20,000\) steps, and the first \(5,000\) steps are for warm-up. The optimizer is Adam. It takes two weeks to train our largest model using \(64\) NVIDIA V100.

Eval results

n_paramn_layersd_modeln_headsd_head
CPM-Small109M127681264
CPM-Medium334M241,0241664
CPM-Large2.6B322,5603280

We evaluate CPM with different numbers of parameters (the details are shown above) on various Chinese NLP tasks in the few-shot (even zero-shot) settings. With the increase of parameters, CPM performs better on most datasets, indicating that larger models are more proficient at language generation and language understanding. We provide results of text classification, chinese idiom cloze test, and short text conversation generation as follows. Please refer to our paper for more detailed results.

Zero-shot performance on text classification tasks

TNEWSIFLYTEKOCNLI
CPM-Small0.6260.5840.378
CPM-Medium0.6180.6350.379
CPM-Large0.7030.7080.442

Performance on Chinese Idiom Cloze (ChID) dataset

SupervisedUnsupervised
CPM-Small0.6570.433
CPM-Medium0.6950.524
CPM-Large0.8040.685

Performance on Short Text Conversation Generation (STC) dataset

AverageExtremaGreedyDist-1Dist-2
Few-shot (Unsupervised)
CDial-GPT0.8990.7970.8101,963 / 0.01120,814 / 0.126
CPM-Large0.9280.8050.8153,229 / 0.00768,008 / 0.154
Supervised
CDial-GPT0.9330.8140.8262,468 / 0.00835,634 / 0.127
CPM-Large0.9340.8100.8193,352 / 0.01167,310 / 0.233

BibTeX entry and citation info

@article{cpm-v1,
  title={CPM: A Large-scale Generative Chinese Pre-trained Language Model},
  author={Zhang, Zhengyan and Han, Xu, and Zhou, Hao, and Ke, Pei, and Gu, Yuxian and Ye, Deming and Qin, Yujia and Su, Yusheng and Ji, Haozhe and Guan, Jian and Qi, Fanchao and Wang, Xiaozhi and Zheng, Yanan and Zeng, Guoyang and Cao, Huanqi and Chen, Shengqi and Li, Daixuan and Sun, Zhenbo and Liu, Zhiyuan and Huang, Minlie and Han, Wentao and Tang, Jie and Li, Juanzi and Sun, Maosong},
  year={2020}
}

Contributors

CX
Canwen Xu

8 commits

JE
jetrunner

1 commits

system

1 commits

TsinghuaAI/CPM-Generate

Model

42

stars

11

commits

1

linked in READMEs

Jul 29, 2021

updated

cpm
endpoints_compatible
gpt2
pytorch
text-generation
text-generation-inference
tf
transformers

README

CPM-Generate

Model description

CPM (Chinese Pre-trained Language Model) is a Transformer-based autoregressive language model, with 2.6 billion parameters and 100GB Chinese training data. To the best of our knowledge, CPM is the largest Chinese pre-trained language model, which could facilitate downstream Chinese NLP tasks, such as conversation, essay generation, cloze test, and language understanding. [Project] [Model] [Paper]

Intended uses & limitations

How to use

from transformers import TextGenerationPipeline, AutoTokenizer, AutoModelWithLMHead

tokenizer = AutoTokenizer.from_pretrained("TsinghuaAI/CPM-Generate")
model = AutoModelWithLMHead.from_pretrained("TsinghuaAI/CPM-Generate")

text_generator = TextGenerationPipeline(model, tokenizer)
text_generator('清华大学', max_length=50, do_sample=True, top_p=0.9)

Limitations and bias

The text generated by CPM is automatically generated by a neural network model trained on a large number of texts, which does not represent the authors' or their institutes' official attitudes and preferences. The text generated by CPM is only used for technical and scientific purposes. If it infringes on your rights and interests or violates social morality, please do not propagate it, but contact the authors and the authors will deal with it promptly.

Training data

We collect different kinds of texts in our pre-training, including encyclopedia, news, novels, and Q&A. The details of our training data are shown as follows.

Data SourceEncyclopediaWebpageStoryNewsDialog
Size~40GB~39GB~10GB~10GB~1GB

Training procedure

Based on the hyper-parameter searching on the learning rate and batch size, we set the learning rate as \(1.5\times10^{-4}\) and the batch size as \(3,072\), which makes the model training more stable. In the first version, we still adopt the dense attention and the max sequence length is \(1,024\). We will implement sparse attention in the future. We pre-train our model for \(20,000\) steps, and the first \(5,000\) steps are for warm-up. The optimizer is Adam. It takes two weeks to train our largest model using \(64\) NVIDIA V100.

Eval results

n_paramn_layersd_modeln_headsd_head
CPM-Small109M127681264
CPM-Medium334M241,0241664
CPM-Large2.6B322,5603280

We evaluate CPM with different numbers of parameters (the details are shown above) on various Chinese NLP tasks in the few-shot (even zero-shot) settings. With the increase of parameters, CPM performs better on most datasets, indicating that larger models are more proficient at language generation and language understanding. We provide results of text classification, chinese idiom cloze test, and short text conversation generation as follows. Please refer to our paper for more detailed results.

Zero-shot performance on text classification tasks

TNEWSIFLYTEKOCNLI
CPM-Small0.6260.5840.378
CPM-Medium0.6180.6350.379
CPM-Large0.7030.7080.442

Performance on Chinese Idiom Cloze (ChID) dataset

SupervisedUnsupervised
CPM-Small0.6570.433
CPM-Medium0.6950.524
CPM-Large0.8040.685

Performance on Short Text Conversation Generation (STC) dataset

AverageExtremaGreedyDist-1Dist-2
Few-shot (Unsupervised)
CDial-GPT0.8990.7970.8101,963 / 0.01120,814 / 0.126
CPM-Large0.9280.8050.8153,229 / 0.00768,008 / 0.154
Supervised
CDial-GPT0.9330.8140.8262,468 / 0.00835,634 / 0.127
CPM-Large0.9340.8100.8193,352 / 0.01167,310 / 0.233

BibTeX entry and citation info

@article{cpm-v1,
  title={CPM: A Large-scale Generative Chinese Pre-trained Language Model},
  author={Zhang, Zhengyan and Han, Xu, and Zhou, Hao, and Ke, Pei, and Gu, Yuxian and Ye, Deming and Qin, Yujia and Su, Yusheng and Ji, Haozhe and Guan, Jian and Qi, Fanchao and Wang, Xiaozhi and Zheng, Yanan and Zeng, Guoyang and Cao, Huanqi and Chen, Shengqi and Li, Daixuan and Sun, Zhenbo and Liu, Zhiyuan and Huang, Minlie and Han, Wentao and Tang, Jie and Li, Juanzi and Sun, Maosong},
  year={2020}
}

Contributors

CX
Canwen Xu

8 commits

JE
jetrunner

1 commits

system

1 commits