# Code examples from: Temperature and Top-p Explained: Why the Same Prompt Gives Different Answers
# https://www.atulvij.com/temperature-top-p-explained
# Review and adapt before running; examples use sample values.

# ---- Example 1 (python) ----
import numpy as np
def softmax_t(logits, t):
    z = np.array(logits) / t
    e = np.exp(z - z.max())
    return (e / e.sum()).round(2)
print(softmax_t([2.0, 1.0, 0.1], 0.5), softmax_t([2.0, 1.0, 0.1], 2.0))

