🎛️ AI Tuning: The Logical Order for Setting Top K, Top P, and Temperature

There is a very logical order to adjusting Top K, Top P, and Temperature to get the best results without making your AI hallucinate. Think of these settings as a filtering system for a VIP club. To get the perfect output, you should follow this sequence: Top K → Top P → Temperature.


1. First: Top K (The Bouncer) 🚪

Think of Top K as the bouncer at the door. He decides the maximum number of words (tokens) that are even allowed to be considered.

  • What it does: It sets a hard limit (e.g., the 40 most likely words).

  • Why first: This is your coarsest filter. It ensures the AI doesn't accidentally pick "long tail" words (nonsense or highly improbable words).

  • Note: If you set Top K to 1, you are effectively telling the AI: "I don't care about the other settings; just give me the #1 most likely word." This is the strictest setting possible.


2. Next: Top P (The Logic Filter) 🧠

Now that the bouncer has let a group in, Top P refines the selection based on "cumulative probability" or logic.

  • What it does: It looks at the dynamic quality (e.g., 0.8).

  • Why now: Top P works within the group that Top K let through. If the word "Coffee" has a 90% chance of being next in a sentence, a low Top P will instantly discard the remaining 10% of improbable words. It makes the AI "smarter" and more context-aware.

  • Note: If you set this to 0, no single word is allowed in, and when you set it to 1 you will get the complete list of words that passed the Top K.


3. Finally: Temperature (The 'Vibe') 🔥

Now that the list of allowed words is finalized, Temperature determines how the AI actually picks from that list.

  • What it does: It determines the randomness.

    • Low Temp (0.1): The AI plays it safe and picks the #1 most likely word almost every time.

    • High Temp (1.0): The AI gets adventurous and might pick the #3 or #4 word on the list.

  • Why last: Temperature doesn't change which words are available; it only changes how often the AI takes a risk on a less-likely option.

  • Note: Setting Temperature to 0 puts the AI in 'Robot Mode' (Greedy Decoding). It will always give the same answer for the same prompt—perfect for data extraction!


⚠️ Important Note on Tokens: Higher Temperature settings can lead to higher token consumption. When the AI is more "creative," it tends to be more wordy and elaborate. If you need to keep your costs down and your answers concise, keep the Temperature low.


💡 "Golden Combinations" for Zenphi’s Gen-AI actions: