|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Response Behavior Settings > AIU. - Artificial Intelligence Utility |
MiniRobotLanguage (MRL)
AIU.SetTopP
Set the Top P (Nucleus Sampling) Value for AIU Operations
Intention
SetTopP Command: Configuring Nucleus Sampling
The SetTopP command sets the Top P (nucleus sampling) value for AIU operations, such as AIU.Chat or AIU.GenerateResponses.
Top P controls the randomness of AI-generated text by limiting the sampling pool to the smallest set of tokens whose cumulative probability exceeds the specified value.
It’s part of the AIU - OpenAI API suite.
This command configures the Top P parameter, also known as nucleus sampling, which filters the token probability distribution during text generation.
Unlike temperature (which scales all probabilities), Top P selects only the most probable tokens whose combined probability meets or exceeds P, offering a dynamic balance between creativity and coherence.
Adjusting Top P is useful for:
•Text Diversity: Lower values (e.g., 0.1) produce more focused, deterministic outputs; higher values (e.g., 0.9) increase variety.
•Quality Control: Avoids low-probability tokens that might lead to incoherent results.
•Customization: Tailor AI responses to specific use cases, like creative writing or factual answers.
The command requires one parameter: a numeric value between 0 and 1 (inclusive), representing the Top P threshold.
Once set, this value affects subsequent text generation operations until changed or reset via Init_AIU().
Technical Details
- Range: 0.0 to 1.0 (inclusive). Values outside this range may cause errors or be clamped by the API.
- Default: Typically 1.0 (full sampling), unless specified otherwise during initialization.
- Effect: A smaller Top P (e.g., 0.5) considers only the top 50% of the probability mass, reducing randomness; a larger Top P (e.g., 0.9) includes 90%, increasing diversity.
- Interaction: Often used with temperature; OpenAI advises using one or the other, not both, for optimal control.
For more details, see OpenAI’s official documentation: OpenAI Chat API - top_p.
Example Usage
AIU.SetTopP|0.7
AIU.GetTopP|$$TOP
DBP.Top P Value: $$TOP
This sets Top P to 0.7 and verifies it with AIU.GetTopP.
Illustration
┌────────────────────┐
│ Top P Setting │
├────────────────────┤
│ Top P = 0.7 │
└────────────────────┘
The configured Top P value for nucleus sampling.
Syntax
AIU.SetTopP|P1
AIU.Set_TopP|P1
Parameter Explanation
P1 - (Required) A numeric value between 0.0 and 1.0 specifying the Top P threshold for nucleus sampling.
Example
AIU.SetTopP|0.3
AIU.Chat|Tell me a story|$$RES
DBP.Story with Top P 0.3: $$RES
ENR.
Remarks
- The value must be a valid float or integer within the range [0, 1].
- Persists across operations until modified or reset.
Limitations
- Values outside [0, 1] may result in an error or unexpected behavior depending on API implementation.
- Exactly one parameter is required; deviations cause an error.
See also:
• AIU.Chat
• OpenAI API - top_p Parameter