SUSSYMANBI commited on
Commit
a3af4de
1 Parent(s): 7591ced
Files changed (1) hide show
  1. test.py +20 -0
test.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import GPT2Tokenizer, GPT2Model
2
+
3
+ # Load the tokenizer and model
4
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
5
+ model = GPT2Model.from_pretrained('gpt2')
6
+
7
+ # Create a prompt
8
+ prompt = "I need a hug."
9
+
10
+ # Tokenize the prompt
11
+ inputs = tokenizer.encode(prompt, return_tensors='pt')
12
+
13
+ # Generate text using the model
14
+ outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
15
+
16
+ # Decode the generated text
17
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+
19
+ # Print the generated text
20
+ print(generated_text)