From f872eb98c2b046c9f806b8cf0196d48e77c17899 Mon Sep 17 00:00:00 2001 From: dhanajitb Date: Thu, 28 Mar 2019 22:46:15 +0530 Subject: [PATCH] making unconditional generation work The unconditional generation works now but if the seed is fixed, the sample is the same every time. n_samples > 1 will give different samples though. I am giving the start token as '<|endoftext|>' for the unconditional generation. --- examples/run_gpt2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/run_gpt2.py b/examples/run_gpt2.py index 0350747499..0289b26702 100644 --- a/examples/run_gpt2.py +++ b/examples/run_gpt2.py @@ -106,6 +106,23 @@ def run_model(): print("=" * 40 + " SAMPLE " + str(generated) + " " + "=" * 40) print(text) print("=" * 80) + if args.unconditional: + generated = 0 + for _ in range(args.nsamples // args.batch_size): + out = sample_sequence( + model=model, length=args.length, + context=None, + start_token=enc.encoder['<|endoftext|>'], + batch_size=args.batch_size, + temperature=args.temperature, top_k=args.top_k, device=device + ) + out = out[:,1:].tolist() + for i in range(args.batch_size): + generated += 1 + text = enc.decode(out[i]) + print("=" * 40 + " SAMPLE " + str(generated) + " " + "=" * 40) + print(text) + print("=" * 80) if __name__ == '__main__': run_model()