
- Control stochasticity and determinism.
- Limit or encourage longer responses.
- Reduce repetition or force early termination.
- Balance creative, novel outputs with factual accuracy.
Deeper descriptions and examples
Temperature
- Definition: A scalar that controls how peaked or flat the sampling distribution is.
- Effect: Low temperature (e.g.,
0.0–0.3) produces near-deterministic outputs; high temperature (e.g.,0.8–1.0) produces more varied, creative text. Values above1.0often increase randomness further. - Example:
- Low temperature:
- High temperature:
- Low temperature:
- Definition: Limits token sampling to the top K most probable tokens at each step.
- Effect: Small
K(e.g.,K = 5) forces compact, focused choices and typically increases coherence. LargeKwidens the candidate pool and increases diversity. - Practical tip: Use Top-K when you want an explicit cap on candidate tokens and predictable variation.
- Definition: Selects the smallest set of tokens whose combined probability reaches at least
P, then samples from that set. - Effect: E.g.,
top_p = 0.9samples from tokens covering the top 90% probability mass. Top-P adapts the size of the candidate pool per step and often yields smoother diversity control than Top-K.

- Response length (hard cap): Use to guarantee an upper bound on tokens generated (
max_tokensor similar). - Length penalty (soft bias): Adjusts scoring during search/beam search to prefer shorter or longer outputs without enforcing a strict cap.
- Practical use: Constrain
max_tokensto manage cost and avoid runaway outputs. Use more explicit prompts to request the expected level of detail:- Short: “Explain gravity.”
- Detailed: “Provide a detailed explanation of the concept of gravity suitable for a university physics student.”

- Penalties: Soft constraints (for example, repetition penalties) that lower the score of tokens or sequences that violate a rule (such as repeating the same phrase).
- Stop sequences: Explicit strings or tokens that immediately terminate generation when produced. Useful for structured outputs, form-filling, or delimiting list termination.
- Example usage: Use repetition penalties in multi-turn dialogues to avoid looping; use stop sequences for JSON responses or when generating a multi-part message.

- High diversity settings (high temperature, large K or P) encourage creativity and novelty but can reduce factual accuracy and coherence.
- Low diversity settings produce consistent and reliable outputs but may be repetitive or lack novelty.
- Choose based on application:
- Low diversity: customer support, legal, finance, healthcare.
- Higher diversity: creative writing, ideation, brainstorming.

- Amazon Bedrock and other inference platforms let you set parameters such as temperature, top-K, top-P, response length, stop sequences, and penalties per API call or as defaults for a model.
- Set parameters per-call when you need different behavior for different tasks (e.g., deterministic summarization vs. creative generation).
- Cost and latency: Broader sampling strategies and larger beam sizes may increase compute and latency because the model examines more candidates. Balance parameter choices with performance budgets.
Monitor and iterate: test multiple configurations, track output quality and operational metrics (latency, token usage, cost), and tune parameters to the needs of your application.
- Hallucinations: Plausible-sounding but incorrect or fabricated information.
- Other risks: bias, toxicity, and unwanted memorized content.
- To reduce hallucinations:
- Prefer conservative sampling (lower temperature, lower top-P/top-K) for factual tasks.
- Use grounding (retrieval-augmented generation), prompt engineering, and verification or validation layers.
- Add human review or programmatic checks in critical workflows.
- In regulated or safety-sensitive domains (legal, healthcare, finance), use conservative parameters and additional verification.

Warning: For mission-critical applications, do not rely on sampling alone for factual accuracy. Use conservative sampling settings, grounding, human review, or other verification mechanisms before taking automated actions.
- Start conservative for accuracy-critical tasks: low temperature, moderate top-P/top-K.
- Increase diversity gradually and validate outputs before deploying changes.
- Use
max_tokensand stop sequences to control output size and format. - Apply repetition penalties when you see looping or repeated phrases.
- Combine parameter tuning with grounding, retrieval, or human verification to reduce hallucinations and ensure compliance.
By understanding these inference parameters and iterating based on measured outputs and operational metrics, you can tailor model behavior to match your application’s requirements — balancing relevance, creativity, predictability, and cost.
Further reading and references
- Amazon Bedrock documentation and service pages for model-specific parameter support.
- Research on sampling methods: nucleus sampling (Top-P) and Top-K.
- Best practices for prompt engineering and retrieval-augmented generation (RAG).