🚀 中文古代GPT2模型
本模型用於生成古代中文文本,藉助預訓練技術,能夠依據給定的文本內容生成符合古代中文語境和風格的語句。通過不同的預訓練工具和豐富的訓練數據,為古代中文文本生成提供了有力支持。
🚀 快速開始
你可以使用文本生成管道直接使用該模型:
>>> from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
>>> tokenizer = BertTokenizer.from_pretrained("uer/gpt2-chinese-ancient")
>>> model = GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-ancient")
>>> text_generator = TextGenerationPipeline(model, tokenizer)
>>> text_generator("當是時", max_length=100, do_sample=True)
[{'generated_text': '[CLS]當是時 所 議 者 不 為 無 據 , 況 亦 在 之 列 乎 ? 然 則 今 日 之 事 , 所 當 思 者 在 何 ? 欲 求 國 是 於 天 下 , 莫 在 於 得 人 。 臣 以 為 求 人 之 法 , 不 在 多 用 官 一 途 。 誠 使 得 才 者 眾 , 人 才 者 優 , 則 治 所 當 得 , 而 不 事 於 官 者 , 人 才 乃 其 常 也 。 所 當 講 者'}]
✨ 主要特性
📦 安裝指南
數據預處理
python3 preprocess.py --corpus_path corpora/ancient_chinese.txt \
--vocab_path models/google_zh_ancient_vocab.txt \
--dataset_path ancient_chinese_dataset.pt --processes_num 16 \
--seq_length 320 --data_processor lm
模型預訓練
python3 pretrain.py --dataset_path ancient_chinese_dataset.pt \
--vocab_path models/google_zh_ancient_vocab.txt \
--config_path models/bert_base_config.json \
--output_model_path models/ancient_chinese_gpt2_model.bin \
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
--total_steps 500000 --save_checkpoint_steps 100000 --report_steps 10000 \
--learning_rate 5e-4 --batch_size 32
模型格式轉換
python3 scripts/convert_gpt2_from_uer_to_huggingface.py --input_model_path models/ancient_chinese_gpt2_model.bin-500000 \
--output_model_path pytorch_model.bin \
--layers_num 12
📚 詳細文檔
訓練數據
訓練數據包含 300 萬條古代中文文本,這些文本由 daizhigev20 收集。由於部分古代語料沒有標點,我們使用了由 北京師範大學 ICIP 實驗室 開發的 古代中文標點系統。
訓練過程
該模型在 騰訊雲 上通過 UER-py 進行預訓練。我們以 320 的序列長度進行了 500000 步的預訓練,並使用擴展詞彙表來處理未登錄詞。古代中文語料中出現次數大於或等於 100 的漢字被添加到詞彙表中。
BibTeX 引用和引用信息
@article{radford2019language,
title={Language Models are Unsupervised Multitask Learners},
author={Radford, Alec and Wu, Jeff and Child, Rewon and Luan, David and Amodei, Dario and Sutskever, Ilya},
year={2019}
}
@article{zhao2019uer,
title={UER: An Open-Source Toolkit for Pre-training Models},
author={Zhao, Zhe and Chen, Hui and Zhang, Jinbin and Zhao, Xin and Liu, Tao and Lu, Wei and Chen, Xi and Deng, Haotang and Ju, Qi and Du, Xiaoyong},
journal={EMNLP-IJCNLP 2019},
pages={241},
year={2019}
}
@article{zhao2023tencentpretrain,
title={TencentPretrain: A Scalable and Flexible Toolkit for Pre-training Models of Different Modalities},
author={Zhao, Zhe and Li, Yudong and Hou, Cheng and Zhao, Jing and others},
journal={ACL 2023},
pages={217},
year={2023}
}
📄 許可證
文檔中未提及相關許可證信息。