← Lesson
Logs and Exp
Joeven
Run
Reset
Python loads on first run
import math print("exp(0)", math.exp(0)) print("exp(1)", round(math.exp(1), 3)) print("log(exp(2))", math.log(math.exp(2))) chances = [0.5, 0.25, 0.25] log_prod = sum(math.log(p) for p in chances) prod = 1.0 for p in chances: prod *= p print("product of chances", prod) print("exp of sum of logs", math.exp(log_prod)) print("log2(8) bits", math.log(8, 2)) print("log2(0.5) bits", math.log(0.5, 2)) # same softmax shift: subtract max, exp still comparable logits = [1.0, 3.0, 2.0] m = max(logits) shifted = [math.exp(z - m) for z in logits] raw = [math.exp(z) for z in logits] print("shifted exps", [round(x, 3) for x in shifted]) print("raw / min raw", [round(x / min(raw), 3) for x in raw])
Run to execute this in your browser. Nothing is sent to a server.