22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

device_index = (model.device.index

if model.device.type != 'cpu'

else -1)

gpt2_gen = pipeline('text-generation',

model=model,

tokenizer=auto_tokenizer,

device=device_index)

The only parameter we may have to change is, once again, the max_length:

result = gpt2_gen(base_text, max_length=250)

print(result[0]['generated_text'])

Output

Alice was beginning to get very tired of sitting by her sister on

the bank, and of having nothing to do: once or twice she had peeped

into the book her sister was reading, but it had no pictures or

conversations in it, `and what is the use of a book,'thought Alice

`without pictures or conversation?' So she was considering in her

own mind (as well as she could, for the hot day made her feel very

sleepy and stupid), whether the pleasure of making a daisy-chain

would be worth the trouble of getting up and picking the daisies,

when suddenly a White Rabbit with pink eyes ran close by her.

The rabbit was running away quite as quickly as it had jumped to her

feet.She had nothing of the kind, and, as she made it up to Alice,

was beginning to look at the door carefully in one thought.`It's

very curious,'after having been warned,`that I should be talking to

Alice!'`It's not,'she went on, `it wasn't even a cat,' so very very

quietly indeed.'In that instant he began to cry out aloud.Alice

began to sob out, 'I am not to cry out!'`What

This time, I’ve kept the whole thing, the base and the generated text. I tried it out

several times and, in my humble opinion, the output looks more "Alice-y" now.

What do you think?

Putting It All Together | 1015

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!