Skip to content

Chapter 4 of 6

Generation Parameters and Context Management

Beyond the words of the prompt itself, generation parameters strongly influence output. Temperature is a parameter that controls randomness: lower values yield more deterministic outputs, while higher values produce more creative ones. For factual, precise tasks, a low temperature, typically between 0 and 0.3, reduces randomness and hallucination, whereas creative writing benefits from higher values, around 0.7 to 1.0, where variety and novelty are desired. Top-p, also called nucleus sampling, is a complementary method that considers only the smallest set of tokens whose cumulative probability exceeds the chosen threshold p, dynamically trimming the candidate distribution in a way that is more adaptive than a fixed temperature cutoff.

The text a model processes is broken into tokens, which are roughly four characters or about three-quarters of a word each. The context window is the maximum number of tokens, including both input and output, that a model can handle in a single interaction. Token budgeting allocates this window strategically between instructions, examples, context, and expected output space, while prompt compression reduces the length of a prompt while preserving its essential meaning. The opposite mistake is context stuffing, which overloads the prompt with so much information that the model becomes confused and response quality degrades. To handle long inputs, the split and merge technique processes documents in chunks, prompts each chunk separately, and then synthesizes the results. Summarization chaining applies the same idea hierarchically: a long document is broken into sections, each section is summarized, and then those summaries are summarized again.

Iterative prompt refinement closes the development loop by testing a prompt, analyzing the output, and gradually improving it based on observations. In multi-turn interactions, conversational memory includes prior turns in the prompt so the model can maintain coherent dialogue across exchanges, and context plays a central role in prompting more generally: providing relevant background information helps the model understand the task better and produce more accurate, relevant responses.

All chapters
  1. 1Foundations of Prompting
  2. 2Core Prompting Techniques
  3. 3Reasoning and Decomposition Strategies
  4. 4Generation Parameters and Context Management
  5. 5Reliability, Safety, and Robustness
  6. 6Advanced Methods, Tools, and Automation

Drill it

Reading is not remembering. These come from the Prompt Engineering deck:

Q

What is a prompt?

A prompt is the input text or instruction given to an AI language model to guide its response.

Q

What is prompt engineering?

The practice of designing, crafting, and optimizing input prompts to elicit desired outputs from AI language models.

Q

What is zero-shot prompting?

Asking the model to perform a task without providing any examples, relying solely on the model's pre-trained knowledge.

Q

What is one-shot prompting?

Providing exactly one example of the desired input-output pattern before asking the model to complete a new task.