File size: 601 Bytes
b5d932a
676e871
 
c7b3623
 
676e871
 
 
 
 
c7b3623
676e871
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from transformers import pipeline

# Initialize the text generation pipeline with the distilgpt2 model
generator = pipeline('text-generation', model='distilgpt2', device=0)  # Use GPU (device 0)


# Generate text with the specified parameters
output = generator(
    'in this course, we will teach how to',
    max_length=20,  # Set maximum length of the generated text
    num_return_sequences=1  # Generate 2 sequences
)

# Print the full output
print(output)

# Print each generated sequence separately
for i, result in enumerate(output):
    print(f"Sequence {i + 1}: {result['generated_text']}")