Zubnet AIAprenderWiki › Loss Function
Training

Loss Function

Objective Function, Cost Function
Uma função matemática que mede o quão erradas as previsões de um modelo estão. O objetivo inteiro do modelo durante o treinamento é minimizar esse número. Para LLMs, a função de perda tipicamente é cross-entropy — ela mede o quão surpreso o modelo está pelo próximo token real comparado com sua distribuição de probabilidade prevista. Menor perda significa que as previsões do modelo batem mais com a realidade.

Por que importa

A função de perda é a bússola do treinamento. Tudo que um modelo aprende está a serviço de reduzir esse único número. Escolher a função de perda errada significa que o modelo otimiza para a coisa errada. Entender perda te ajuda a interpretar curvas de treinamento, diagnosticar problemas (platô de perda? divergência? overfitting?), e entender por que modelos se comportam como se comportam.

Deep Dive

Cross-entropy loss for language models works like this: at each position in the text, the model predicts a probability distribution over its entire vocabulary. The loss is the negative log probability assigned to the actual next token. If the model predicted the correct token with 90% probability, loss is low (−log(0.9) ≈ 0.1). If it predicted the correct token with 1% probability, loss is high (−log(0.01) ≈ 4.6). Summing across all positions gives the total loss.

Perplexity: Loss Made Intuitive

Perplexity is just 2^(cross-entropy loss), or equivalently e^(loss) when using natural log. It represents "how many options the model is effectively choosing between at each token." A perplexity of 10 means the model is as uncertain as if it were picking randomly among 10 equally likely tokens. Lower perplexity = more confident and accurate predictions. It's the standard metric for comparing language models' raw text modeling ability.

Loss Isn't Everything

A lower loss doesn't always mean a better model for users. A model with slightly higher loss but better alignment (via RLHF/DPO) is usually more useful than a model with minimal loss but no alignment. Loss measures how well the model predicts text; alignment measures how well it follows instructions and avoids harm. The gap between "good at predicting text" and "good at being helpful" is what post-training addresses.

Conceitos relacionados

← Todos os termos
← LoRA LSTM →