0
0
Prompt Engineering / GenAIml~10 mins

Content writing assistance in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a pre-trained language model for content writing assistance.

Prompt Engineering / GenAI
from transformers import [1]
model = [1].from_pretrained('gpt2')
Drag options to blanks, or click blank then click option'
AGPT2Model
BGPT2Tokenizer
CBertModel
DGPT2LMHeadModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPT2Tokenizer instead of GPT2LMHeadModel
Using BertModel which is a different architecture
2fill in blank
medium

Complete the code to tokenize input text for the model.

Prompt Engineering / GenAI
from transformers import GPT2Tokenizer
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
inputs = tokenizer('[1]', return_tensors='pt')
Drag options to blanks, or click blank then click option'
AHello, how are you?
Btokenize this text
CGenerate content
DSample input
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variable names instead of string literals
Using empty strings or non-text inputs
3fill in blank
hard

Fix the error in the code to generate text from the model.

Prompt Engineering / GenAI
outputs = model.generate([1]['input_ids'], max_length=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Drag options to blanks, or click blank then click option'
Ainputs
Binput
Ctokens
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable names like 'input' or 'tokens'
Passing raw text instead of token ids
4fill in blank
hard

Fill both blanks to create a function that generates content given a prompt.

Prompt Engineering / GenAI
def generate_content(prompt):
    inputs = tokenizer([1], return_tensors='pt')
    outputs = model.generate(inputs[[2]], max_length=100)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)
Drag options to blanks, or click blank then click option'
Aprompt
Binput_ids
Cattention_mask
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'prompt' as input
Using 'attention_mask' for generation input
5fill in blank
hard

Fill all three blanks to create a pipeline for content writing assistance.

Prompt Engineering / GenAI
from transformers import pipeline
content_generator = pipeline('[1]', model='gpt2')
result = content_generator('[2]', max_length=[3])
print(result[0]['generated_text'])
Drag options to blanks, or click blank then click option'
Atext-generation
BWrite a short story
C50
Dtext-classification
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text-classification' instead of 'text-generation'
Passing numeric prompt instead of string
Setting max_length too low or missing