Advertisement
A_GUES

Python gpt-2

Jun 14th, 2023 (edited)
228
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. import torch
  2. from transformers import GPT2LMHeadModel, GPT2Tokenizer
  3.  
  4. model = _pretrained('gpt2')
  5. tokenizer = _pretrained('gpt2')
  6.  
  7. input_text = 'Once upon a time'
  8. input_ids = tokenizer(input_text, return_tensors='pt')['input_ids']
  9.  
  10. output = (input_ids, max_length=100, num_return_sequences=1)
  11.  
  12. output_text = (output[0], skip_special_tokens=True)
  13. print(output_text)
Advertisement
Comments
  • A_GUES
    1 year
    Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement