You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 8, 2026. It is now read-only.
Reacted by jwijffels, Isaac Godfried, clintonm9, Franck Dernoncourt, soneo1127, QiaoranC, jackylee1, Adrien Mallecourt, Nicolas, Luis Fernando Castillo Mata and 35 more
@jackylee1 Sorry, as others mentioned, we're not releasing training code for now, as this repository is currently for exploring the existing model. You may find the model.py code in this repo useful, and there are plenty of other projects that train transformer models out there!
@branc116 we're not taking requests to train any models as we have limited bandwidth (especially if they require procuring a dataset differently!)
It works: I've used it for retraining on anime plot synopses & Project Gutenberg poetry.
Reacted by Jeff Wu, AeroScripts, Neal McBurnett, Konstantin Lopuhin, Collin Kindrom, Tamlyn Rhodes, Stephen Torrence, rkfg, cagatay odabasi, Arwin Neil Baichoo and 36 more
I was able to train a model (using Chinese dataset) over the default 117M model without problem. However, when I try to generate samples (either conditional or unconditional), I got "FileNotFoundError: [Errno 2] No such file or directory" for encoder.json, hparams.json and vocab.bpe.
What would be the correct procedure for generating samples for the new model described above?
I am not entirely sure because you said you are using Chinese rather than English text.
For English text, all you need to do is copy over those missing files from the 117M model directory, which will have them (assuming you ran the download script as you must've if you did any retraining of 117M, of course).
Since finetuning doesn't affect the BPE encoding details, it is merely further training the Transformer model itself; so, the model still assumes the exact same encoding as for OA's 117M model, and the encoding is defined by those files.
@gwern@nshepperd
Hey Gwen, I'm a little noob in all of this... Do you know how to use finetuning in Colab? That is, if there is a way to use it in Colab...
I don't know of any reason you couldn't do finetuning in Colab (the main restriction I'm aware of is you only get something like 12 GPU-hours? which is more than enough for many finetuning tasks). But I have little familiarity with it or interest in setting up a notebook to do the finetuning. Colab seems like a very restrictive tool compared to running on your own machine.
On a heldout set? No idea. You'll have to code that yourself. (I suppose one dirty hack would be to set the learning rate to zero and 'train' on a 'new' dataset and watch the averaged loss...)
So I noticed that nshepperd's fork doesn't preserve the optimizer state in the checkpoints it generates. Be aware that it affects Adam optimizer because it assigns individual learning rates for the model parameters. If you restart training from a checkpoint that information is lost and your learning rate will be set back to the provided value (1e-4 by default). This results in (slight) loss increase after the checkpoint is loaded and I think it might break the learning process at the late stages (the model stops converging or starts diverging).
To store everything you need to remove this line (or replace it with var_list=None) or, if you use an existing checkpoint and want to update it with optimizer vars, you might want to create a new saver object with var_list=None at around this line after restoring. Then the full checkpoint will be saved later. Note that it's much bigger, about 1.9 Gb instead of 400-500 Mb.
Hi, I am using nshepperd's fork https://github.com/nshepperd/gpt-2/tree/finetuning to finetune model with the custom dataset which I created. But once I trained and use the trained model to generate text, the model is able to generate text only on the text which I trained currently and it is forgetting the default trained one which is released by openAI. So my question is how to finetune this model so that the model will be able to generate text on which I trained and also the default one released by openAI?
Hi, I am using nshepperd's fork https://github.com/nshepperd/gpt-2/tree/finetuning to finetune model with the custom dataset which I created. But once I trained and use the trained model to generate text, the model is able to generate text only on the text which I trained currently and it is forgetting the default trained one which is released by openAI. So my question is how to finetune this model so that the model will be able to generate text on which I trained and also the default one released by openAI?
@HiDhineshRaja have you figure it out why when finetuning model forgets what it was trained on by OpenAI?
And another implementation, same nshepperd's fork but with scripts to process FB2 files: https://github.com/rkfg/gpt-2
It also uses the sentencepiece tokenizer. It's pretty easy to find a lot of Russian (and some other languages as well but not as many) books in FB2 format so this fork primarily targets the Russian audience. Unfortunately there's still no README about these scripts but the basic workflow is:
filterfb2.sh (to pick the books in the same language)
fb2totxt.sh (convert to plain .txt files)
concat.sh (concatenate all .txt into one file and insert <|n|> end of line tokens)
createspmodel.sh (prepare the BPE sentencepiece dictionary and model, also creates hparams.json; you can reuse those for other datasets if you wish)
encode.sh (produces an .npz ready to use with train.py).
I don't use validation as it's easy to make just a huge dataset that would require months to fully sample so basically training IS validation, it's impossible to overfit because the samples don't repeat.
I'm having trouble running your encode.py. After copying encode.py to the src folder, I run the following command:
@rkfg I'm getting the following error while training:
Traceback (most recent call last):
File "train.py", line 221, in <module>
main()
File "train.py", line 92, in main
os.path.join(CHECKPOINT_DIR, args.run_name))
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/summary/writer/writer.py", line 367, in __init__
filename_suffix)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/summary/writer/event_file_writer.py", line 67, in __init__
gfile.MakeDirs(self._logdir)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/file_io.py", line 442, in recursive_create_dir
recursive_create_dir_v2(dirname)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/file_io.py", line 458, in recursive_create_dir_v2
pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(path), status)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py", line 528, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.FailedPreconditionError: models/345M/checkpoint/run1; Not a directory
Open a new issue in my repository because it's not really related to this original one. Post as many details as possible including the command line you're running.
I was able to train a model (using Chinese dataset) over the default 117M model without problem. However, when I try to generate samples (either conditional or unconditional), I got "FileNotFoundError: [Errno 2] No such file or directory" for encoder.json, hparams.json and vocab.bpe.
What would be the correct procedure for generating samples for the new model described above?
@kaihuchen I had that problem too and fixed it here: #156
I was able to train a model (using Chinese dataset) over the default 117M model without problem. However, when I try to generate samples (either conditional or unconditional), I got "FileNotFoundError: [Errno 2] No such file or directory" for encoder.json, hparams.json and vocab.bpe.
What would be the correct procedure for generating samples for the new model described above?
How did you manage to encode the chinese script?
I am trying to train a model for Hindi language. But I have data in hindi script, I can not train this with "nshepperd code".
@Zer0-dev115 Training on Hindi is like retraining entire model (not fine tuning) so you need really large datasets I would think (at least of the order of several hundred MBs if not GBs and could take several days of GPU time.
And you could do it in one of two ways: you can feed in unicode text and also setup a simple bpe and json file for it. Better way is to run learn_bpe.py from BPE github on your Hindi text and generate json and bpe.
Activity
miweru commentedon Feb 15, 2019
that code is not released and maybe wont be released
branc116 commentedon Feb 15, 2019
Can you create a model that accepts other languages (e.g. German, Russian)?
WuTheFWasThat commentedon Feb 20, 2019
@jackylee1 Sorry, as others mentioned, we're not releasing training code for now, as this repository is currently for exploring the existing model. You may find the model.py code in this repo useful, and there are plenty of other projects that train transformer models out there!
@branc116 we're not taking requests to train any models as we have limited bandwidth (especially if they require procuring a dataset differently!)
marcpre commentedon Feb 24, 2019
@openai
Impressive results!
@WuTheFWasThat
Any suggestions for other transformer models, that can be trained and played around?
guotong1988 commentedon Feb 25, 2019
Same question. Thank you.
WuTheFWasThat commentedon Feb 28, 2019
RE other pretrained models: definitely check out Google's BERT model and CMU/Google's Transformer-XL models
gwern commentedon Mar 4, 2019
nshepperd has released training code for retraining GPT-2-small: https://github.com/nshepperd/gpt-2/tree/finetuning
It works: I've used it for retraining on anime plot synopses & Project Gutenberg poetry.
guotong1988 commentedon Mar 4, 2019
Thank you @gwern
kaihuchen commentedon Mar 5, 2019
@nshepperd @gwern Thank you so much for sharing the training code (ref: https://github.com/nshepperd/gpt-2/tree/finetuning) !
I was able to train a model (using Chinese dataset) over the default 117M model without problem. However, when I try to generate samples (either conditional or unconditional), I got "FileNotFoundError: [Errno 2] No such file or directory" for encoder.json, hparams.json and vocab.bpe.
What would be the correct procedure for generating samples for the new model described above?
gwern commentedon Mar 5, 2019
I am not entirely sure because you said you are using Chinese rather than English text.
For English text, all you need to do is copy over those missing files from the 117M model directory, which will have them (assuming you ran the download script as you must've if you did any retraining of 117M, of course).
Since finetuning doesn't affect the BPE encoding details, it is merely further training the Transformer model itself; so, the model still assumes the exact same encoding as for OA's 117M model, and the encoding is defined by those files.
PapayasTehSkeletor commentedon Mar 6, 2019
@gwern @nshepperd
Hey Gwen, I'm a little noob in all of this... Do you know how to use finetuning in Colab? That is, if there is a way to use it in Colab...
gwern commentedon Mar 6, 2019
I don't know of any reason you couldn't do finetuning in Colab (the main restriction I'm aware of is you only get something like 12 GPU-hours? which is more than enough for many finetuning tasks). But I have little familiarity with it or interest in setting up a notebook to do the finetuning. Colab seems like a very restrictive tool compared to running on your own machine.
guotong1988 commentedon Mar 7, 2019
@nshepperd @gwern
Have you eval the perplexity in https://github.com/nshepperd/gpt-2/tree/finetuning
?
Thank you!!
gwern commentedon Mar 7, 2019
On a heldout set? No idea. You'll have to code that yourself. (I suppose one dirty hack would be to set the learning rate to zero and 'train' on a 'new' dataset and watch the averaged loss...)
20 remaining items
rkfg commentedon Apr 14, 2019
So I noticed that nshepperd's fork doesn't preserve the optimizer state in the checkpoints it generates. Be aware that it affects Adam optimizer because it assigns individual learning rates for the model parameters. If you restart training from a checkpoint that information is lost and your learning rate will be set back to the provided value (1e-4 by default). This results in (slight) loss increase after the checkpoint is loaded and I think it might break the learning process at the late stages (the model stops converging or starts diverging).
To store everything you need to remove this line (or replace it with
var_list=None) or, if you use an existing checkpoint and want to update it with optimizer vars, you might want to create a new saver object with var_list=None at around this line after restoring. Then the full checkpoint will be saved later. Note that it's much bigger, about 1.9 Gb instead of 400-500 Mb.sanja7s commentedon Apr 17, 2019
Hi, @gwern and others!
Do you know -- can we fine-tune the gpt-2 for another task such as document scoring?
HiDhineshRaja commentedon Apr 19, 2019
Hi, I am using nshepperd's fork https://github.com/nshepperd/gpt-2/tree/finetuning to finetune model with the custom dataset which I created. But once I trained and use the trained model to generate text, the model is able to generate text only on the text which I trained currently and it is forgetting the default trained one which is released by openAI. So my question is how to finetune this model so that the model will be able to generate text on which I trained and also the default one released by openAI?
tomasrasymas commentedon Apr 30, 2019
@HiDhineshRaja have you figure it out why when finetuning model forgets what it was trained on by OpenAI?
rkfg commentedon Apr 30, 2019
Have you tried a lower learning rate? Something like 1e-6 maybe.
tomasrasymas commentedon Apr 30, 2019
No, I left default value for learning rate parameter. Will try to use lower one.
zendevil commentedon Jul 8, 2019
I'm having trouble running your encode.py. After copying encode.py to the src folder, I run the following command:
And get the following message:
rkfg commentedon Jul 8, 2019
2 issues:
encode.shjust like my post says, notencode.py<>. The<argument>notation means the argument is required, not that you should put it between<and>.rkfg commentedon Jul 8, 2019
Right there, in
scripts.zendevil commentedon Jul 8, 2019
@rkfg I'm getting the following error while training:
rkfg commentedon Jul 8, 2019
Open a new issue in my repository because it's not really related to this original one. Post as many details as possible including the command line you're running.
GrahamboJangles commentedon Jul 19, 2019
@kaihuchen I had that problem too and fixed it here: #156
Zer0-dev115 commentedon Feb 18, 2020
How did you manage to encode the chinese script?
I am trying to train a model for Hindi language. But I have data in hindi script, I can not train this with "nshepperd code".
ravi-annaswamy commentedon Jul 8, 2020
@Zer0-dev115 Training on Hindi is like retraining entire model (not fine tuning) so you need really large datasets I would think (at least of the order of several hundred MBs if not GBs and could take several days of GPU time.
And you could do it in one of two ways: you can feed in unicode text and also setup a simple bpe and json file for it. Better way is to run learn_bpe.py from BPE github on your Hindi text and generate json and bpe.
niccolox commentedon Jan 18, 2023
https://www.youtube.com/watch?v=kCc8FmEb1nY