File tree 1 file changed +4
-8
lines changed
1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change @@ -420,7 +420,7 @@ to generate the tokens following the initial sequence in PyTorch, and creating a
420
420
sequence = f"Hugging Face is based in DUMBO, New York City, and is"
421
421
422
422
input = tokenizer.encode(sequence, return_tensors="pt")
423
- generated = model.generate(input, max_length=50)
423
+ generated = model.generate(input, max_length=50, do_sample=True )
424
424
425
425
resulting_string = tokenizer.decode(generated.tolist()[0])
426
426
print(resulting_string)
@@ -432,14 +432,10 @@ to generate the tokens following the initial sequence in PyTorch, and creating a
432
432
model = TFAutoModelWithLMHead.from_pretrained("gpt2")
433
433
434
434
sequence = f"Hugging Face is based in DUMBO, New York City, and is"
435
- generated = tokenizer.encode(sequence)
436
-
437
- for i in range(50):
438
- predictions = model(tf.constant([generated]))[0]
439
- token = tf.argmax(predictions[0], axis=1)[-1].numpy()
440
- generated += [token]
435
+ input = tokenizer.encode(sequence, return_tensors="tf")
436
+ generated = model.generate(input, max_length=50, do_sample=True)
441
437
442
- resulting_string = tokenizer.decode(generated)
438
+ resulting_string = tokenizer.decode(generated.tolist()[0] )
443
439
print(resulting_string)
444
440
445
441
You can’t perform that action at this time.
0 commit comments