🚀 中国語対聯GPT2モデル
このモデルは中国語の対聯を生成するために使用されます。事前学習技術を活用して、上聯に基づいて適切な下聯を生成し、対聯創作を容易にします。
🚀 クイックスタート
テキスト生成パイプラインを使用して、このモデルを直接呼び出すことができます。
パラメータ skip_special_tokens が True の場合
>>> from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
>>> tokenizer = BertTokenizer.from_pretrained("uer/gpt2-chinese-couplet")
>>> model = GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-couplet")
>>> text_generator = TextGenerationPipeline(model, tokenizer)
>>> text_generator("[CLS]丹 枫 江 冷 人 初 去 -", max_length=25, do_sample=True)
[{'generated_text': '[CLS]丹 枫 江 冷 人 初 去 - 黄 叶 声 从 天 外 来 阅 旗'}]
パラメータ skip_special_tokens が False の場合
>>> from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
>>> tokenizer = BertTokenizer.from_pretrained("uer/gpt2-chinese-couplet")
>>> model = GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-couplet")
>>> text_generator = TextGenerationPipeline(model, tokenizer)
>>> text_generator("[CLS]丹 枫 江 冷 人 初 去 -", max_length=25, do_sample=True)
[{'generated_text': '[CLS]丹 枫 江 冷 人 初 去 - 黄 叶 声 我 酒 不 辞 [SEP] [SEP] [SEP] [SEP] [SEP] [SEP] [SEP] [SEP] [SEP]'}]
✨ 主な機能
- このモデルは UER-py で事前学習されています。このツールは この論文 で紹介されています。また、モデルは TencentPretrain でも事前学習できます。関連内容は この論文 を参照してください。TencentPretrain は UER-py を継承し、パラメータが10億を超えるモデルをサポートし、多モーダル事前学習フレームワークに拡張されています。
pipelines.py
で skip_special_tokens
パラメータを使用しているため、[SEP]
、[UNK]
などの特殊トークンが削除され、ホストされた推論API(右側)の出力結果が正しく表示されない場合があります。
📦 インストール
モデルのダウンロード
以下の方法でモデルをダウンロードできます。
学習手順
1. データ前処理
python3 preprocess.py --corpus_path corpora/couplet.txt \
--vocab_path models/google_zh_vocab.txt \
--dataset_path couplet_dataset.pt --processes_num 16 \
--seq_length 64 --data_processor lm
2. 事前学習モデル
python3 pretrain.py --dataset_path couplet_dataset.pt \
--vocab_path models/google_zh_vocab.txt \
--config_path models/gpt2/config.json \
--output_model_path models/couplet_gpt2_model.bin \
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
--total_steps 25000 --save_checkpoint_steps 5000 --report_steps 1000 \
--learning_rate 5e-4 --batch_size 64
3. Huggingface 形式への変換
python3 scripts/convert_gpt2_from_uer_to_huggingface.py --input_model_path models/couplet_gpt2_model.bin-25000 \
--output_model_path pytorch_model.bin \
--layers_num 12
📚 ドキュメント
学習データ
学習データには70万件の中国語対聯が含まれており、これらの対聯は couplet-clean-dataset で収集されています。
引用情報
@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}
}
🔧 技術詳細
このモデルは事前学習技術に基づいており、特定のツール(UER-py または TencentPretrain)を使用して騰訊クラウドプラットフォーム上で学習されています。大量の中国語対聯データを学習することで、モデルは対聯の言語規則や対仗規則を習得し、対聯の生成を実現します。学習過程では、適切なシーケンス長、学習ステップ数、学習率などのパラメータを設定して、モデルの性能と効果を保証しています。また、モデルを使用する際には、skip_special_tokens
パラメータの設定が出力結果の特殊トークンの表示に影響します。