tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > Gemini Controlled Generation - Stop Sequences and Sampling

Gemini Controlled Generation - Stop Sequences and Sampling

Author: Venkata Sudhakar

Gemini exposes several generation parameters that control the style, length, and determinism of model output. These are essential for production applications where consistent formatting matters. ShopMax India uses controlled generation to ensure product descriptions end cleanly and review summaries stay within character limits.

The key parameters are: temperature (0 = deterministic, 2 = creative), top_p (nucleus sampling threshold), top_k (vocabulary restriction), max_output_tokens (hard length cap), and stop_sequences (strings that terminate generation immediately).

The below example shows how ShopMax India configures generation parameters for different content types in their product platform.


It gives the following output,

Description:
Experience industry-leading noise cancellation with the Sony WH-1000XM5. 
Featuring 30-hour battery life and crystal-clear calls, these premium 
wireless headphones deliver audiophile-grade sound for your daily commute 
or work-from-home setup. Available at ShopMax India - Rs 29,990.
Tokens used: 87

Stop sequences are powerful for structured extraction. If you ask for JSON output, set stop_sequences to end generation right after the closing brace, preventing the model from adding explanation text after the JSON block.


It gives the following output,

Extracted JSON: {"product": "Sony WH-1000XM5", "price": 29990, "currency": "INR"}

Variant 1: ShopMax India - Where the best electronics meet the best prices.
Variant 2: Your trusted destination for premium electronics across India.

For ShopMax India, use temperature=0 for all data extraction tasks, temperature=0.4 for customer support responses (accurate but slightly varied), and temperature=0.8 for marketing copy generation where creativity adds value.


 
  


  
bl  br