JOVANA
Explore Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Advanced Decoding and Choosing Your Settings

Contrastive decoding, confidence from logprobs, sampling for reasoning, and a practical cheat-sheet for picking decode settings per task.

Contrastive decoding

Contrastive decoding is a clever twist: instead of trusting one distribution, you compare two. A capable expert model is contrasted against a weak amateur one (or against an early layer of the same model), and you favour tokens the expert likes more than the amateur does. The intuition is that bland, generic, repetitive tokens look attractive to both, so subtracting the amateur's preferences cancels them out — cutting degeneration and often sharpening factuality, without simply lowering temperature.

Confidence you can act on

The log-probabilities you saw earlier are more than a debug curiosity. Averaged over a span, they estimate how sure the model is — a sudden plunge in token logprobs often marks where an answer turns shaky or invented. You can surface a per-answer confidence, route low-confidence cases to a human or a stronger model, or compare two candidate continuations. It is an imperfect signal — a model can be confidently wrong — but it is cheap and frequently useful.

\text{confidence} = \exp\!\left(\frac{1}{N}\sum_{i=1}^{N}\log p(t_i)\right)

Span confidence as the geometric mean of token probabilities — averaging the log-probs turns them into one number you can act on.

Sampling as a reasoning tool

Randomness is not only for creativity — it powers a whole class of reasoning tricks. In self-consistency, you deliberately sample several different chains of thought at a moderate temperature, then take a majority vote over their final answers. Because each sampled path explores a slightly different route, the consensus is usually more reliable than any single greedy pass. Here, the diversity sampling provides is the entire point — turn temperature to zero and the method evaporates.

Decoding speed is a separate axis

A cheat-sheet by task

There is no universally best decoder — the right strategy follows the task, which is the whole lesson of sampling versus greedy. A starting map:

  1. Extraction, classification, structured output: temperature ~0 (greedy) plus constrained or JSON-mode decoding — you want determinism and a valid shape.
  2. Code and math: low temperature (0–0.3); sample several and vote, or check, when correctness matters.
  3. General chat and Q&A: moderate temperature (~0.7) with top-p ~0.9 — a balanced default.
  4. Creative writing and brainstorming: higher temperature (0.9–1.2), top-p or min-p, and a gentle repetition penalty to fight loops.
  5. Reasoning with self-consistency: moderate temperature so paths diverge, then aggregate the answers.
p_i = \frac{\exp(z_i / T)}{\sum_{j}\exp(z_j / T)}

Temperature T rescales the logits before softmax — low T sharpens toward greedy, high T flattens toward creative sampling.

Putting it together

Step back and the whole field is one idea seen from many angles: the model hands you a distribution, and decoding is the policy that turns it into text. Greedy and beam chase the most probable; temperature, top-k, top-p and min-p trade probability for diversity; logit bias, stop sequences and grammars impose shape; contrastive decoding and logprobs refine quality and confidence. Master that one choose step and you can make the very same weights behave like a careful clerk or a daring poet — entirely by how you decode.

Decoding is the policy inside the autoregressive loop — each step turns the model's distribution into one chosen token, then feeds it back.

Diagram: an autoregressive next-token generation loop feeding each chosen token back as input.