Views
No views yet
| CC-100 (PPL) | Wikipedia (PPL) | |
|---|---|---|
| dbmdz/german-gpt2 | 49.47 | 62.92 |
| GerPT2 | 24.78 | 35.33 |
| GerPT2-large | 16.08 | 23.26 |
evaluate.py in the GerPT2 Github repository for the code.1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
3tokenizer = AutoTokenizer.from_pretrained("benjamin/gerpt2-large")
4model = AutoModelForCausalLM.from_pretrained("benjamin/gerpt2-large")
5
6prompt = "<your prompt>"
7
8pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
9print(pipe(prompt)[0]["generated_text"])1output = model.generate(
2 # during training an EOS token was used to mark the beginning of each text
3 # so it can help to insert it at the start
4 torch.tensor(
5 [tokenizer.eos_token_id] + tokenizer.encode(prompt)
6 ).unsqueeze(0),
7 do_sample=True,
8 # try setting bad_words_ids=[[0]] to disallow generating an EOS token, without this the model is
9 # prone to ending generation early because a significant number of texts from the training corpus
10 # is quite short
11 bad_words_ids=[[0]],
12 max_length=max_length,
13)[0]
14print(tokenizer.decode(output))prepare/train_tokenizer.py. As training data for the tokenizer I used a random subset of 5% of the CC-100 data.prepare/generate_aligned_wte.py. This uses a neat trick to semantically map tokens from the English tokenizer to tokens from the German tokenizer using aligned word embeddings. E. g.:Ġ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 -> staffwte_path to the training script. Credit to this blogpost for the idea of initializing GPT2 from English weights.prepare/tokenize_text.py. This generates files for train and validation tokens in JSON Lines format.train.py! run.sh shows how this was executed for the full run with config configs/tpu_large.json.@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}
}