Temperature, top-p, and top-k are inference parameters that influence how a foundation model selects the next token. They change response generation without retraining or fine-tuning the model. For AWS exam scenarios, focus on the trade-off between predictable output and response diversity—and remember that parameter support and valid ranges vary by model.
Temperature: control randomness
Temperature changes the probability distribution used when selecting the next token. A lower temperature makes the model more likely to choose high-probability tokens and generally produces more predictable responses. A higher temperature allows more variation and can produce more creative or less predictable output.
Use a lower temperature for tasks that benefit from consistent wording, such as structured extraction or deterministic-style responses. A higher temperature may be useful for brainstorming or creative generation. Low temperature does not guarantee factual correctness.
Top-p: nucleus sampling
Top-p limits token selection to a set of candidates whose cumulative probability reaches the configured threshold. A lower top-p narrows the candidate pool and tends to make output more focused. A higher top-p allows a broader range of candidates and more diversity.
Top-k: limit the number of candidates
Top-k restricts the next-token candidates to the k most likely options. A smaller k limits the choice set; a larger k allows more possible tokens. Top-k is model-specific: not every foundation model exposes the same inference parameters or uses the same request format.
Quick comparison
| Parameter | What it controls | Lower setting generally means |
|---|---|---|
| Temperature | Shape of the token probability distribution | More predictable, less random output |
| Top-p | Cumulative probability mass of candidate tokens | Narrower candidate pool |
| Top-k | Number of highest-probability candidate tokens | Fewer candidate tokens |
Do not confuse generation parameters
- Maximum new tokens limits how much the model can generate; it does not directly control creativity.
- Stop sequences tell generation to stop when a specified sequence is encountered.
- Temperature, top-p, and top-k influence token selection and diversity.
- Prompt engineering changes the instructions and context; inference parameters change sampling behavior.
Practical tuning advice
Change one parameter at a time and evaluate the result against a representative prompt set. Record the model ID and parameter values because different models can have different defaults, supported parameters, and valid ranges. Do not assume that a parameter value accepted by one model will be accepted by another.
Exam traps
- Lower temperature generally increases predictability; it does not improve knowledge or guarantee accuracy.
- Top-p is based on cumulative probability, while top-k is based on a fixed number of candidates.
- Maximum token count controls response length, not sampling diversity.
- Check the selected model’s documentation for supported parameters and ranges.
Test yourself
Question 1
A team wants more predictable, less random responses from a foundation model. Which parameter should it generally lower?
- Maximum output tokens
- Temperature
- Stop sequence length
- Prompt length
Reveal answer
Correct answer: B. Lower temperature generally makes token selection more deterministic.
Question 2
Which parameter limits the next-token candidate set to the k most likely tokens?
- Top-k
- Top-p
- Temperature
- Maximum new tokens
Reveal answer
Correct answer: A. Top-k uses a fixed number of highest-probability candidates. Top-p uses cumulative probability mass.
Key takeaway
Temperature controls randomness, top-p controls cumulative candidate probability, and top-k controls the number of candidate tokens. Always verify the exact parameter support for the model you invoke.
Related AWS topics
Amazon Bedrock Knowledge Bases · Foundation Model Hallucinations · Evaluating Foundation Models
✦ CloudExamPro Premium
Ready for the AWS Certified AI Practitioner (AIF-C01)?
Move beyond memorizing terms. Practice with realistic, scenario-based questions and detailed explanations that help you understand the AWS AI services and concepts behind each answer.
Original practice questions. No dumps. No shortcuts.