tensorflow/models · error · ValueError
Reference and translation files have different number of…
Error message
Reference and translation files have different number of lines (%d VS %d). If training only a few steps (100-200), the translation may be empty.
What it means
Consistency guard in bleu_on_list: the reference and hypothesis line counts differ. Common when the model was trained only a few steps (100-200) and produced empty or truncated translations, so hypothesis lines were dropped before scoring.
Solutions
- Train longer so the translation file is fully populated
- Check the hypothesis file for empty/failed decode passes and regenerate it
- Ensure both files are tokenized with the same subtokenizer (no dropped lines)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/legacy/transformer/compute_bleu.py:98 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/616d72843d4384c4.
Report an issue: GitHub.
Appendix: source
Thrown at official/legacy/transformer/compute_bleu.py:98
string = uregex.nondigit_punct_re.sub(r"\1 \2 ", string)
string = uregex.punct_nondigit_re.sub(r" \1 \2", string)
string = uregex.symbol_re.sub(r" \1 ", string)
return string.split()
def bleu_wrapper(ref_filename, hyp_filename, case_sensitive=False):
"""Compute BLEU for two files (reference and hypothesis translation)."""
ref_lines = tokenizer.native_to_unicode(
tf.io.gfile.GFile(ref_filename).read()).strip().splitlines()
hyp_lines = tokenizer.native_to_unicode(
tf.io.gfile.GFile(hyp_filename).read()).strip().splitlines()
return bleu_on_list(ref_lines, hyp_lines, case_sensitive)
def bleu_on_list(ref_lines, hyp_lines, case_sensitive=False):
"""Compute BLEU for two list of strings (reference and hypothesis)."""
if len(ref_lines) != len(hyp_lines):
raise ValueError(
"Reference and translation files have different number of "
"lines (%d VS %d). If training only a few steps (100-200), the "
"translation may be empty." % (len(ref_lines), len(hyp_lines)))
if not case_sensitive:
ref_lines = [x.lower() for x in ref_lines]
hyp_lines = [x.lower() for x in hyp_lines]
ref_tokens = [bleu_tokenize(x) for x in ref_lines]
hyp_tokens = [bleu_tokenize(x) for x in hyp_lines]
return metrics.compute_bleu(ref_tokens, hyp_tokens) * 100
def main(unused_argv):
if FLAGS.bleu_variant in ("both", "uncased"):
score = bleu_wrapper(FLAGS.reference, FLAGS.translation, False)
logging.info("Case-insensitive results: %f", score)
if FLAGS.bleu_variant in ("both", "cased"):
score = bleu_wrapper(FLAGS.reference, FLAGS.translation, True)View on GitHub (pinned to e006f5f0d5)