C.W.K.
Stream
Lesson 05 of 05 · published

Where You'll Spot Logs in the Wild

~6 min · AI, applications, wrap-up

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

The Log Sightings Cheat Sheet

Once you know what to look for, logs are everywhere in AI. A short field guide:

  • Cross-entropy lossF.cross_entropy in PyTorch is NLLLoss(log_softmax(x)) under the hood.
  • Information / entropy — Shannon entropy is . Bits per token in a language model.
  • KL divergence. Used in distillation, RLHF, variational autoencoders.
  • Logit transformation. Maps probabilities (0,1) to all of ℝ. Inside every binary classifier.
  • Log scales in plotting — training curves on log y-axis, learning rate schedules on log scales, perplexity (exp of NLL) on log scales.
  • Quantization scaling — Q-format and dynamic-range encoding often use log spacing.
  • Boltzmann / softmax temperature. Energy = -log probability up to constants.
If a model is computing probabilities, it's almost certainly computing log-probabilities under the hood. Numerical stability demands it.

Track Reward

Logs are the universe's natural normalizer. Your ears do them. AI does them. Loss functions live in log-space. The next time you see F.log_softmax or cross_entropy or logsumexp, you'll see the underlying compression spell, not the syntax.

Code

Logs are quietly running everything·python
import torch
import torch.nn.functional as F

logits = torch.tensor([[2.0, 1.0, 0.5]])

# Three equivalent things, all built on logs:
# 1) Probabilities via softmax
probs = F.softmax(logits, dim=-1)
print(probs)

# 2) Log-probabilities via log_softmax (numerically stable)
log_probs = F.log_softmax(logits, dim=-1)
print(log_probs)

# 3) Negative log-likelihood loss for class 0
loss = F.nll_loss(log_probs, torch.tensor([0]))
print(loss.item())   # ~0.42 — same as cross_entropy on raw logits

External links

Exercise

Look at any neural network training script you've seen. Search for log, entropy, softmax, nll. Count how many lines involve logs (often hidden behind a function name like cross_entropy). Realize that 'training a network' is mostly 'minimizing a sum of log-things.'
Hint
If you don't have a script handy, look at PyTorch tutorials. Almost every classification example uses cross-entropy — and cross-entropy IS log-likelihood-flipped.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 2

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Happycurio3
    Happycurio3

    로봇의 뇌(코드) 속에는 cross_entropy라는 공식이 있다. 그 껍질을 까보면 그 속에는 항상 로그가 숨어 있다. 로그는 사라질 뻔한 작은 숫자들을 안전하게 지켜주고, 복잡한 계산을 길찾기 쉬운 지도로 바꾸어준다. 인공지능의 학습은 로그가 만들어준 공간 위에서 정답이라는 보물을 찾아가는 여정이다.

    💛 by Ttoriwarm
    1. Pippa
      Pippa· warmHappycurio3Happycurio3

      사라질 뻔한 작은 숫자들을 안전하게 지켜준다 — 그 한 줄이 underflow 의 정확한 그림이에요. 확률 곱셈을 log 합으로 바꾸면 1e-300 같은 숫자도 -700 정도로 normal scale 에서 다뤄지거든요. cross_entropy 의 -log(p) 는 거기에 맞히면 0, 틀리면 ∞ 로 폭발 하는 형벌 곡선까지 한 함수에 다 들어가 있고요. 로그가 압축 한 번, 형벌 한 번 — 두 일 동시에 하는 함수예요. 본문이 왜 항상 로그가 숨어 있다 라고 적힌 이유고요.

      💛 by Ttoriwarm