Concepts / Text Generation Strategies

Text Generation Strategies

Text generation is the step where the model produces output one piece at a time, and the weights are part of the calculation that decides what comes next.

  • Programming

The Question Behind Every Word

When a large language model writes a sentence, it is not looking up a stored answer. It computes a next word from the input it receives and from a large collection of numbers built into the model. Those numbers are the subject of this article.

What do you think happens?

If the model's behavior depends on these built-in numbers, who or what decides what the numbers should be?

Reveal answer
Answer:

The numbers are learned during training.

The source frames them as values the model learns, rather than values a person enters. The rest of this article follows that idea from its definition, to its role in text generation, to the steps that come after it in building an LLM.

What a Weight Parameter Is

Definition

A weight parameter is a model parameter that is learned during training, not typed in by hand.

The key word is learned. A value a programmer types into code is chosen by the person writing the program, and it stays that way unless someone edits the code. A weight parameter starts with some value and then changes as the model is trained. Its final value is the product of training rather than a decision made in advance by the author.

FeatureValue typed in by handWeight parameter
Where it comes fromA person writes it into the codeProduced by the training process
Who sets its valueThe programmerTraining, rather than a hand-typed choice
Does it change over timeOnly if someone edits the codeIts value changes as training runs
Role in the modelFixed input chosen by the authorPart of the calculation that the model uses to produce text

A hand-typed value compared with a learned weight parameter

Tracing One Weight Through Training

To make the idea concrete, follow a single weight from before training to after training. The source does not give specific values for any real model, so the numbers below are invented for illustration. What matters is the direction of change: the value moves, and it eventually settles.

Before training0.20 (illustrative)Early training0.35 (illustrative)Later training0.52 (illustrative)Learned value0.58 (illustrative)training adjusts valuetraining continuesvalue settles
What is the starting value of one weight, and how does its value move step by step until it settles on a learned value?
Worked example

Following one weight from start to finish

A weight starts at 0.20 before training. After training, it is 0.58. What changed, and what stayed the same?

  1. 1
    Identify the starting state

    Before training, the weight holds an initial value of 0.20 (illustrative).

  2. 2
    Identify the ending state

    After training, the weight holds a learned value of 0.58 (illustrative).

  3. 3
    Compare the two

    The value moved upward during training. The weight is still the same weight with the same role in the model. Only its value changed.

  4. 4
    Generalize

    A model contains a very large number of weights, and each one begins with some value and ends training with a learned value.

Result

The weight's identity and role stayed fixed while its value was learned. The learned values are what carry the model's ability forward.

Why Weights Drive Text Generation

The source states that weight parameters are used in LLMs for text generation. This is why they matter to the chapter. Text generation is the step where the model produces output one piece at a time, and the weights are part of the calculation that decides what comes next.

This connects training to output. Training determines the learned values, and generation uses those values to compute each next word. A model whose weights were learned differently would compute different next words from the same input.

Key point

A model does not store a finished answer to retrieve. Each word is computed from the input and from the learned numbers inside the model.

Where Weights Sit in the Chapter Workflow

The chapter follows a sequence of stages. It begins by recapping text generation from the previous chapter, then sets up the LLM for text generation and discusses basic ways to evaluate the quality of the text it produces. Evaluation is where the learned weights are tested: if the weights are good, the generated text should be judged well. Evaluation and training both depend on a model whose weights are already defined.

Text generation recapEvaluate generatedtextTraining andvalidation lossesLLM training functionweights are learnedAdditional generationstrategiesSave and load weightsweights are stored andreusedLoad pretrainedOpenAI weightsweights learned elsewhere
In what order do the stages run, and where do weights get used, trained, and stored?

Read this overview as a map rather than a checklist. The first three stages prepare you to judge a model. The middle stages train and improve it. The last stages handle the weights as stored, reusable values. Weight parameters are the common thread through all of them.

Saving and Loading Learned Weights

Because weights are learned, they are valuable. Training takes effort, and the learned values are the result of that effort. The source describes implementing functions to save and load LLM weights. Saving captures the current state of the weights. Loading brings a saved state back into a model, so the model can be used again or have its training continued.

Trained modelcurrent weight valuesSaved weightscaptured stateNew model instanceweights restoredsaveload
What moves between the trained model in memory and stored form when weights are saved, and what happens when they are loaded into a new model instance?

The source also describes loading pretrained weights from OpenAI into the LLM model. This is a different route to learned weights. Instead of learning them within this chapter's own training run, the model receives weights that were already learned elsewhere.

Mistakes Beginners Make with Weights

  • Common mistake

    Treating a weight like a setting you type in

    What it looks like

    Assuming you can choose a weight's final value in the code and the model will use it.

    Why it fails

    A weight parameter is learned during training, not typed in by hand.

    Do this instead

    Think of the weight as a value that training produces, and check the training process to see where its value comes from.

  • Common mistake

    Thinking the model looks up a stored answer

    What it looks like

    Believing a sentence is retrieved whole from storage.

    Why it fails

    The model computes a next word from the input and from the numbers built into it.

    Do this instead

    Connect each generated word to the input and the learned weights used in that calculation.

  • Common mistake

    Assuming saving a model means saving its design only

    What it looks like

    Thinking the model can be reused just because its structure was written down.

    Why it fails

    The learned values are the result of training effort, and saving captures the current state of the weights.

    Do this instead

    Remember that saving stores the weights, and loading restores them into a model.

  • Common mistake

    Confusing pretrained weights from OpenAI with weights learned in this chapter's own training run

Practice: Tracing a Learned Value

EASY

A model has a weight whose value is 0.20 before training and 0.58 after training. Explain, in your own words, why this weight is called a learned weight parameter and not a value a programmer typed in. Then describe what stayed the same about the weight during training.

Hints
  • Ask who or what set the final value.
  • Look at what the source says about whether the weight is still the same weight after training.
  • Think about the difference between changing a value and changing what the weight does in the model.

Key Takeaways

  1. 1
    A weight parameter is a model parameter that is learned during training, not typed in by hand.
  2. 2
    Training changes a weight's value while the weight remains the same weight with the same role in the model.
  3. 3
    Weights are used in LLMs for text generation, linking what training learned to the output the model produces.
  4. 4
    Weights appear across the chapter's stages, and saving and loading them lets a model be reused or trained further.
  5. 5
    Pretrained weights from OpenAI are another source of learned weights, received instead of learned in the chapter's own training run.

At a glance

  • A weight parameter is a model parameter that is learned during training, not typed in by hand.
  • Training changes a weight's value while the weight remains the same weight with the same role in the model.
  • Weights are used in LLMs for text generation, linking what training learned to the output the model produces.
  • Saving and loading weights lets a model be used later or have its training continued.
  • Pretrained weights from OpenAI are another source of learned weights, received instead of learned in the chapter's own training run.

Related concepts

More concepts starting with T