Bird
Raised Fist0
NLPml~20 mins

Why text generation creates content in NLP - Challenge Your Understanding

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Text Generation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does text generation produce new content?

Text generation models create new sentences instead of copying existing ones. Why is this possible?

ABecause the model stores all sentences from training and randomly selects one to output.
BBecause the model learns patterns and relationships in language, allowing it to predict and create new sequences.
CBecause the model uses a fixed dictionary of phrases and repeats them in order.
DBecause the model only copies the first sentence it saw during training.
Attempts:
2 left
💡 Hint

Think about how the model understands language structure rather than memorizing exact sentences.

Predict Output
intermediate
2:00remaining
Output of a simple text generation step

Given a trained language model that predicts the next word, what is the output of this code snippet?

NLP
import random

vocab = ['hello', 'world', 'machine', 'learning']

# Simulate next word prediction probabilities
probs = [0.1, 0.7, 0.1, 0.1]

next_word = random.choices(vocab, weights=probs, k=1)[0]
print(next_word)
ASyntaxError because random.choices is used incorrectly
B"hello" always because it is first in vocab
C"world" most likely, but could be any word from vocab
D"machine" always because it has the highest probability
Attempts:
2 left
💡 Hint

random.choices picks based on weights but can pick any word.

Model Choice
advanced
2:00remaining
Choosing a model type for creative text generation

You want to build a system that writes creative stories with varied vocabulary and style. Which model type is best?

AA simple Markov chain model based on word transitions
BA bag-of-words model that ignores word order
CA rule-based system with fixed sentence templates
DA large transformer-based language model trained on diverse text
Attempts:
2 left
💡 Hint

Consider which model can capture complex language patterns and creativity.

Metrics
advanced
2:00remaining
Evaluating text generation quality

Which metric best measures how well a text generation model produces fluent and coherent sentences?

ABLEU score comparing generated text to reference text
BMean squared error between predicted and actual word embeddings
CAccuracy of classifying text sentiment
DNumber of words generated per second
Attempts:
2 left
💡 Hint

Think about metrics that compare generated text to human-written examples.

🔧 Debug
expert
3:00remaining
Why does this text generation code produce repetitive output?

Consider this code snippet generating text word by word. It produces repetitive phrases like "the the the...". What is the most likely cause?

NLP
import random

vocab = ['the', 'cat', 'sat', 'on', 'mat']
probs = [0.9, 0.025, 0.025, 0.025, 0.025]

output = []
for _ in range(5):
    next_word = random.choices(vocab, weights=probs, k=1)[0]
    output.append(next_word)
print(' '.join(output))
AThe probability distribution is too skewed, causing the model to pick "the" repeatedly.
BThe vocab list is too small to generate varied text.
Crandom.choices is not suitable for text generation and causes repetition.
DThe loop runs only 5 times, so repetition is expected.
Attempts:
2 left
💡 Hint

Look at the probabilities assigned to each word.

Practice

(1/5)
1. What is the main reason text generation models create new content?
easy
A. They predict the next word based on previous words
B. They copy sentences from a fixed list
C. They randomly select words without context
D. They translate text from one language to another

Solution

  1. Step 1: Understand how text generation works

    Text generation models use previous words to predict the next word, creating new sentences.
  2. Step 2: Compare options with this understanding

    Only They predict the next word based on previous words describes this process correctly; others describe unrelated or incorrect methods.
  3. Final Answer:

    They predict the next word based on previous words -> Option A
  4. Quick Check:

    Next word prediction = C [OK]
Hint: Text generation predicts next words, not copy or random picks [OK]
Common Mistakes:
  • Thinking text is copied from a list
  • Believing words are chosen randomly
  • Confusing generation with translation
2. Which of the following is the correct way to start generating text using a model like GPT-2?
easy
A. model.train(start_text)
B. model.generate(start_text)
C. model.predict_label(start_text)
D. model.translate(start_text)

Solution

  1. Step 1: Identify the function for text generation

    Text generation uses a method like generate to produce new text from a start.
  2. Step 2: Eliminate unrelated functions

    train is for learning, predict_label is for classification, and translate is for language translation.
  3. Final Answer:

    model.generate(start_text) -> Option B
  4. Quick Check:

    Text generation method = generate [OK]
Hint: Use generate() to create text, not train() or translate() [OK]
Common Mistakes:
  • Confusing training with generating
  • Using classification methods for generation
  • Mixing translation with generation
3. Given this Python code using a text generation model:
start_text = 'Once upon a time'
output = model.generate(start_text, max_length=10)
print(output)

What is the expected output type?
medium
A. A list of numbers representing word indexes
B. An error because max_length is invalid
C. A string containing a sentence starting with 'Once upon a time'
D. A boolean indicating success or failure

Solution

  1. Step 1: Understand the generate function output

    The generate function returns generated text as a string starting with the input.
  2. Step 2: Analyze the code snippet

    It prints the output, which should be a string sentence starting with 'Once upon a time'.
  3. Final Answer:

    A string containing a sentence starting with 'Once upon a time' -> Option C
  4. Quick Check:

    Output type = string sentence [OK]
Hint: Generate outputs text strings, not lists or booleans [OK]
Common Mistakes:
  • Expecting numeric lists instead of text
  • Assuming max_length causes errors
  • Thinking output is a success flag
4. This code tries to generate text but raises an error:
start = 'Hello'
output = model.generate(start, max_len=20)
print(output)

What is the likely cause of the error?
medium
A. The parameter name should be max_length, not max_len
B. The start text must be a list, not a string
C. The model.generate method does not exist
D. The print statement is missing parentheses

Solution

  1. Step 1: Check parameter names for generate()

    The correct parameter to limit output length is max_length, not max_len.
  2. Step 2: Verify other code parts

    Start text as string is valid, model.generate exists, and print uses parentheses correctly.
  3. Final Answer:

    The parameter name should be max_length, not max_len -> Option A
  4. Quick Check:

    Correct param name = max_length [OK]
Hint: Use exact parameter names like max_length to avoid errors [OK]
Common Mistakes:
  • Using wrong parameter names
  • Thinking input must be a list
  • Ignoring Python 3 print syntax
5. You want to generate a story summary using a text generation model. Which approach best explains why the model creates new content rather than copying existing text?
hard
A. The model translates the original story into another language and back
B. The model searches a database for exact matching summaries and returns them
C. The model randomly selects words from a dictionary without context
D. The model predicts each next word based on learned patterns, creating unique sentences

Solution

  1. Step 1: Understand text generation for summaries

    Models generate summaries by predicting next words using learned language patterns, not copying exact text.
  2. Step 2: Evaluate options based on this understanding

    Only The model predicts each next word based on learned patterns, creating unique sentences describes this predictive generation; others describe copying, random selection, or translation.
  3. Final Answer:

    The model predicts each next word based on learned patterns, creating unique sentences -> Option D
  4. Quick Check:

    Generation = prediction of next words [OK]
Hint: Generation predicts words, it doesn't copy or translate [OK]
Common Mistakes:
  • Thinking generation copies exact text
  • Confusing generation with translation
  • Assuming random word selection