Skip to content

Main content

Beam Score Length Penalty Factor Tool

GNMT-style length penalty ((5+length)/6)^alpha; normalize a supplied cumulative log score by division.

Loading tool…

Description

Return a supplied beam length penalty and normalized score.

Autoregressive sequence log scores accumulate token log probabilities and commonly become more negative as a sequence grows. A length-normalization convention changes how candidate scores are compared. This helper computes a supplied length-penalty factor without searching candidates, normalizing a distribution or choosing the penalty parameter.

Return a supplied beam length penalty and normalized score.

When to use this tool

Use Beam Score Length Penalty Factor when checking the stated probability, score, guidance or scale contribution.

How to use the tool and how it works

  1. Enter logScore, length, alpha. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read penalty, normalizedScore. Use the output convention below.

Return a supplied beam length penalty and normalized score. Require whole length >= 1 and alpha >= 0; penalty = ((5+length)/6)^alpha, normalizedScore = logScore/penalty.1

GNMT uses a length-normalization factor of the form implemented here. This local factor does not include coverage penalties or perform beam search.2

Input fieldMeaning and unitsAccepted input
logScoreLog ScoreRequired. Finite number.
lengthLengthRequired. Safe integer; minimum 1.
alphaAlphaRequired. Finite number; minimum 0.
Output fieldInterpretationReturned shape
penalty((5+length)/6)^alpha under this length-normalization convention.Required. Finite number.
normalizedScoreNormalized ScoreRequired. Finite number.
json
{
  "input": {
    "logScore": -12,
    "length": 7,
    "alpha": 1
  },
  "output": {
    "penalty": 2,
    "normalizedScore": -6
  }
}

Limitations and assumptions

  • This is one scoring convention and supplied length; no beam search, tokenizer or optimal sequence is computed.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Use the full distribution and model-specific decoding or training objective for normalized probabilities, preference optimization or actual generation.

References

  1. Calculation and input contract: artificial-intelligence/beam-score-length-penalty-factor — tool.io

  2. Google’s Neural Machine Translation System: Bridging the Gap between Human and Machine Translation — Yonghui Wu and coauthors

Similar or alternative tools