模型:
German large and small versions of GPT2:
See the GPT2 model card for considerations on limitations and bias. See the GPT2 documentation for details on GPT2.
I evaluated both GerPT2-large and the other German GPT2, dbmdz/german-gpt2 on the CC-100 dataset and on the German Wikipedia:
| CC-100 (PPL) | Wikipedia (PPL) | |
|---|---|---|
| dbmdz/german-gpt2 | 49.47 | 62.92 |
| GerPT2 | 24.78 | 35.33 |
| GerPT2-large | 16.08 | 23.26 |
See the script evaluate.py in the GerPT2 Github repository for the code.
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
tokenizer = AutoTokenizer.from_pretrained("benjamin/gerpt2-large")
model = AutoModelForCausalLM.from_pretrained("benjamin/gerpt2-large")
prompt = "<your prompt>"
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
print(pipe(prompt)[0]["generated_text"])
Also, two tricks might improve the generated text:
output = model.generate(
# during training an EOS token was used to mark the beginning of each text
# so it can help to insert it at the start
torch.tensor(
[tokenizer.eos_token_id] + tokenizer.encode(prompt)
).unsqueeze(0),
do_sample=True,
# try setting bad_words_ids=[[0]] to disallow generating an EOS token, without this the model is
# prone to ending generation early because a significant number of texts from the training corpus
# is quite short
bad_words_ids=[[0]],
max_length=max_length,
)[0]
print(tokenizer.decode(output))
GerPT2-large is trained on the entire German data from the CC-100 Corpus and weights were initialized from the English GPT2 model . GerPT2-large was trained with:
Training took roughly 12 days on 8 TPUv3 cores.
To train GerPT2-large, follow these steps. Scripts are located in the Github repository :
ĠMinde -> Ġleast Ġjed -> Ġwhatsoever flughafen -> Air vermittlung -> employment teilung -> ignment ĠInterpretation -> Ġinterpretation Ġimport -> Ġimported hansa -> irl genehmigungen -> exempt ĠAuflist -> Ġlists Ġverschwunden -> Ġdisappeared ĠFlyers -> ĠFlyers Kanal -> Channel Ġlehr -> Ġteachers Ġnahelie -> Ġconvenient gener -> Generally mitarbeiter -> staff
This helps a lot on a trial run I did, although I wasn't able to do a full comparison due to budget and time constraints. To use this WTE matrix it can be passed via the wte_path to the training script. Credit to this blogpost for the idea of initializing GPT2 from English weights.
GerPT2 is licensed under the MIT License.
Please cite GerPT2 as follows:
@misc{Minixhofer_GerPT2_German_large_2020,
author = {Minixhofer, Benjamin},
doi = {10.5281/zenodo.5509984},
month = {12},
title = {{GerPT2: German large and small versions of GPT2}},
url = {https://github.com/bminixhofer/gerpt2},
year = {2020}
}
Thanks to Hugging Face for awesome tools and infrastructure.Huge thanks to Artus Krohn-Grimberghe at LYTiQ for making this possible by sponsoring the resources used for training.
GerPT2是GPT2的德语大型和小型版本:有关局限性和偏见的注意事项,请参阅 GPT2 model card 。有关GPT2的详细信息,请参阅 GPT2 documentation 。 对比GerPT2-large和另一种德语GPT2( dbmdz/german-gpt2 ),我在 CC-100 数据集和德语维基百科上进行了评估:| CC-100 (PPL) | Wikipedia (PPL) | |
|---|---|---|
| dbmdz/german-gpt2 | 49.47 | 62.92 |
| GerPT2 | 24.78 | 35.33 |
| GerPT2-large | 16.08 | 23.26 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
tokenizer = AutoTokenizer.from_pretrained("benjamin/gerpt2-large")
model = AutoModelForCausalLM.from_pretrained("benjamin/gerpt2-large")
prompt = "<your prompt>"
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
print(pipe(prompt)[0]["generated_text"])
。此外,两个技巧可能会改善生成的文本:output = model.generate(
# during training an EOS token was used to mark the beginning of each text
# so it can help to insert it at the start
torch.tensor(
[tokenizer.eos_token_id] + tokenizer.encode(prompt)
).unsqueeze(0),
do_sample=True,
# try setting bad_words_ids=[[0]] to disallow generating an EOS token, without this the model is
# prone to ending generation early because a significant number of texts from the training corpus
# is quite short
bad_words_ids=[[0]],
max_length=max_length,
)[0]
print(tokenizer.decode(output))
。
GerPT2-large是使用从
CC-100 Corpus
获取的整个德语数据进行训练的,权重从
English GPT2 model
初始化。GerPT2-large的训练详情如下:ĠMinde -> Ġleast Ġjed -> Ġwhatsoever flughafen -> Air vermittlung -> employment teilung -> ignment ĠInterpretation -> Ġinterpretation Ġimport -> Ġimported hansa -> irl genehmigungen -> exempt ĠAuflist -> Ġlists Ġverschwunden -> Ġdisappeared ĠFlyers -> ĠFlyers Kanal -> Channel Ġlehr -> Ġteachers Ġnahelie -> Ġconvenient gener -> Generally mitarbeiter -> staff这对我做的试运行非常有帮助,尽管由于预算和时间限制,我无法进行全面的比较。要使用此WTE矩阵,可以通过wte_path传递给训练脚本。感谢 this blogpost 提出了从英文权重初始化GPT2的想法。 使用prepare/tokenize_text.py对语料进行标记化。这将以JSON Lines格式生成训练和验证标记的文件。 运行训练脚本train.py!run.sh显示了如何在完整运行中使用配置文件configs/tpu_large.json进行执行。 GerPT2的许可证为MIT许可。请引用GerPT2如下:
@misc{Minixhofer_GerPT2_German_large_2020,
author = {Minixhofer, Benjamin},
doi = {10.5281/zenodo.5509984},
month = {12},
title = {{GerPT2: German large and small versions of GPT2}},
url = {https://github.com/bminixhofer/gerpt2},
year = {2020}
}
。
感谢
Hugging Face
提供的出色工具和基础设施。特别感谢
Artus Krohn-Grimberghe
在
LYTiQ
上赞助了用于训练的资源,使这成为可能。