|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIK. - Claude from Anthropic > AIK. - Use Anthropic Claude AI |
MiniRobotLanguage (MRL)
AIK.Set Temperature
Set the Temperature Parameter

See two answers to the same question, using a different setting for temperature.
Intention
The `AIK.SetTemperature` command is an essential tool for finetuning the creativity and randomness of responses generated by Anthropi's AI large language models (LLMs).
It's like adjusting the seasoning in a recipe - a higher temperature spices things up, while a lower temperature keeps things more conservative and focused.
Understanding and effectively using this command can help you craft the perfect responses for your application's needs.
`AIK.SetTemperature` takes a single parameter - the temperature value, which is a floating-point number typically ranging from 0.0 to 1.0.
This parameter is responsible for scaling the logits before the final Softmax layer during text generation, effectively controlling the randomness in the model's output.
- When the temperature is set to a lower value, the LLM's output becomes more deterministic and focused.
- The model is more likely to choose the most probable word sequences, making the text more coherent and less random.
- This is particularly useful when you need the model to produce factual information or adhere closely to a certain writing style.
- Setting a higher temperature makes the model's output more diverse and creative.
- The model is less biased towards the most probable word sequences and is more likely to produce surprising or unexpected responses.
- This is great when you want the model to generate creative content, brainstorm ideas, or be more conversational and less formal.
- Setting the temperature to 0 makes the model completely deterministic, always choosing the most likely word. This might make the text repetitive or robotic.
- Setting the temperature very high (e.g., above 1) can result in very random and potentially nonsensical text.
1. **Story Generation**: A higher temperature (e.g., 0.7) could be used to generate more imaginative and varied stories.
2. **FAQ Responses**: A lower temperature (e.g., 0.2) would be appropriate for generating straightforward and consistent answers to frequently asked questions.
3. **Idea Brainstorming**: A medium to high temperature (e.g., 0.5 to 0.8) might be ideal for generating a wide range of creative ideas.
' Set a low temperature for focused, factual responses
AIK.Set Temperature|0.2
' Set a higher temperature for creative, diverse responses
AIK.Set Temperature|0.8
AIK.Set Key|Any
$$MOD=claude-3-haiku-20240307
$$ASK=Tell me 5 fitting colors to red.
AIK.Set Mes Model|$$MOD
FOR.$$LDA|0|1|.2
AIK.Set Temperature|$$LDA
AIK.Ask Claude|$$ASK|$$RES|0
'AIC.Show Error|$$RES
DBP.Temp=$$LDA
DBP.Result=$$RES
DBP.---------------
NEX.
ENR.
Debug Window
[14:14:06] Temp=0
[14:14:06] Result=
Here are 5 colors that pair well with red:
1. White - Red and white create a classic, clean, and crisp color combination.
2. Black - Red and black is a bold, dramatic, and sophisticated pairing.
3. Gold - Red and gold create a rich, luxurious, and elegant color scheme.
4. Navy blue - Red and navy blue make for a deep, sophisticated, and nautical-inspired palette.
5. Cream - Red and cream produce a warm, cozy, and inviting color scheme.
These colors complement red nicely and can be used in various design applications, from fashion and home decor to branding and graphic design.
[14:14:06] ---------------
[14:14:08] Temp=.2
[14:14:08] Result=
Here are 5 colors that pair well with red:
1. White - Red and white create a classic, clean, and crisp color combination.
2. Black - Red and black together make a bold, dramatic, and sophisticated pairing.
3. Gold - Red and gold have a rich, luxurious, and regal feel when combined.
4. Navy blue - Red and navy blue create a deep, elegant, and nautical-inspired palette.
5. Tan/Beige - Red and neutral tones like tan or beige result in a warm, earthy, and grounded color scheme.
These colors complement red nicely and can be used in various design, fashion, and decor applications.
[14:14:08] ---------------
[14:14:11] Temp=.4
[14:14:11] Result=
Here are 5 colors that pair well with red:
1. White - The classic combination of red and white creates a clean, crisp look.
2. Black - Red and black together make a bold, dramatic color scheme.
3. Cream - Pairing red with a softer neutral like cream adds warmth and elegance.
4. Gray - Different shades of gray, from charcoal to light heather, complement red nicely.
5. Navy - The deep, rich tone of navy blue provides a nice contrast to vibrant red.
These colors work well with red because they either provide a nice contrast or blend harmoniously. The combinations can create a range of moods, from classic and sophisticated to modern and edgy.
[14:14:11] ---------------
[14:14:13] Temp=.6
[14:14:13] Result=
Here are 5 colors that pair well with the color red:
1. White - Red and white create a classic, clean, and crisp color combination.
2. Black - Red and black together make a bold, dramatic, and sophisticated pairing.
3. Yellow - Red and yellow are complementary colors on the color wheel, creating a vibrant and energetic look.
4. Green - Shades of green, like forest green or olive green, can create a rich, earthy contrast with red.
5. Orange - Red and orange are analogous colors, creating a warm, harmonious palette.
These color combinations can work well in fashion, home decor, graphic design, and various other creative applications.
[14:14:13] ---------------
[14:14:16] Temp=.8
[14:14:16] Result=
Here are 5 colors that pair well with the color red:
1. White - Red and white create a clean, classic color combination.
2. Black - Red and black is a bold, dramatic pairing that is often used in fashion and interior design.
3. Cream - Pairing red with a softer neutral like cream creates a warm, inviting palette.
4. Gray - Red and gray make for a sophisticated, modern color scheme.
5. Navy Blue - The contrast between red and navy blue results in a rich, elegant look.
These colors complement red well and can be used together in various design applications, from clothing and home decor to art and graphic design.
[14:14:16] ---------------
[14:14:17] Temp=1
[14:14:18] Result=
Here are 5 fitting colors that complement red:
1. White
2. Black
3. Gold
4. Gray
5. Navy blue
These colors work well with red because they provide a nice contrast or complementary pairing. White and black are classic neutrals that allow red to be the focal point. Gold adds a touch of warmth and elegance. Gray is a modern neutral that tones down the intensity of red. And navy blue is a rich, deep color that creates a sophisticated look when combined with red.
[14:14:18] ---------------
Syntax
AIK.Set Temperature[|P1]
AIK.Ste[|P1]
Parameter Explanation
P1 - `<value>`: A floating-point number or variable representing the temperature.
Commonly used values are between 0.0 and 1.0, but higher values can also be used for more randomness. If omitted value s resettled to 0.
Example
'***********************************
' AIK.-Sample
'***********************************
'$$MOD=claude-3-opus-20240229
'$$MOD=claude-3-sonnet-20240229
'$$MOD=claude-3-haiku-20240307
$$MOD=claude-3-5-sonnet-20240620
AIK.Set Key|Any
$$ASK=Tell me 5 fitting colors to red.
AIK.Set Mes Model|$$MOD
FOR.$$LDA|0|1|.2
AIK.Set Temperature|$$LDA
AIK.Ask Claude|$$ASK|$$RES|0
'AIC.Show Error|$$RES
DBP.Temp=$$LDA
DBP.Result=$$RES
DBP.---------------
NEX.
ENR.
Remarks
Understanding Claude API Parameters: top_k, top_p, and temperature
When Claude generates text, it does so token by token. For each token it generates, it calculates a probability for every token in its vocabulary, and then selects the next token based on these probabilities. The `top_k`, `top_p`, and `temperature` parameters are all ways to influence this selection process.
1. top_k
The `top_k` parameter limits the number of tokens that Claude considers as the next possible token.
- If `top_k` is set to 40, for example, Claude will only consider the 40 tokens it thinks are most likely.
- This can make the output more focused and less random, because it's only choosing from a subset of tokens.
- However, it can also make the output less diverse, because it's ignoring a lot of potential tokens.
- The `top_k` value can be any non-negative integer, with larger values leading to more randomness and smaller values leading to less randomness.
- The minimum value for `top_k` is 0, which means Claude will consider all possible tokens for each step.
- There isn't a strict maximum value for `top_k`, but setting it to a very high value (greater than the size of Claude's vocabulary) is effectively the same as not setting it at all.
- If `top_k` is not set, Claude will use its default behavior, which is to consider all tokens in its vocabulary (equivalent to setting `top_k` to a value larger than 30,000).
- Many developers find that values in the range of 20 to 50 provide a good balance between diversity and focus in Claude's responses.
2. top_p
Also known as nucleus sampling, this parameter is more dynamic than `top_k`.
- Instead of always considering a fixed number of tokens like `top_k`, `top_p` considers however many tokens are needed to reach a certain cumulative probability.
- For example, if `top_p` is set to 0.9, Claude will consider the smallest set of tokens that have a combined probability of 90%.
- This set of tokens can be larger or smaller depending on the specific probabilities for each token.
- Like `top_k`, `top_p` can make the output more focused and less random, but it can also reduce diversity.
- The `top_p` value is a float between 0 and 1, with larger values leading to more randomness and smaller values leading to less randomness.
3. temperature
This parameter controls the "sharpness" of the probability distribution.
- If `temperature` is set to a high value (close to 1), Claude's token selection will be more random and less deterministic, even if some tokens have much higher probabilities than others.
- If `temperature` is set to a low value (close to 0), Claude's token selection will be more deterministic and less random, with Claude strongly favoring tokens that have higher probabilities.
- In other words, a high `temperature` makes Claude more "adventurous" in its token choices, while a low `temperature` makes Claude more "conservative".
Summary
`top_k` and `top_p` are ways to limit the number of tokens that Claude considers for each step of the generation process, while `temperature` is a way to control the randomness of Claude's token selection within those limits. All three parameters can be used together to finely tune the behavior of the model.
The optimal values for these parameters can depend on your specific use case and the desired behavior of Claude. It's a good idea to experiment with different values to see what works best for your needs when using the Anthropic Claude API.
Limitations:
-
See also:
•