{"record":{"id":"616d72843d4384c4","repo":"tensorflow/models","slug":"reference-and-translation-files-have-different-num","errorCode":null,"errorMessage":"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.","messagePattern":"Reference and translation files have different number of lines \\((.+?) VS (.+?)\\)\\. If training only a few steps \\(100-200\\), the translation may be empty\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/transformer/compute_bleu.py","lineNumber":98,"sourceCode":"  string = uregex.nondigit_punct_re.sub(r\"\\1 \\2 \", string)\n  string = uregex.punct_nondigit_re.sub(r\" \\1 \\2\", string)\n  string = uregex.symbol_re.sub(r\" \\1 \", string)\n  return string.split()\n\n\ndef bleu_wrapper(ref_filename, hyp_filename, case_sensitive=False):\n  \"\"\"Compute BLEU for two files (reference and hypothesis translation).\"\"\"\n  ref_lines = tokenizer.native_to_unicode(\n      tf.io.gfile.GFile(ref_filename).read()).strip().splitlines()\n  hyp_lines = tokenizer.native_to_unicode(\n      tf.io.gfile.GFile(hyp_filename).read()).strip().splitlines()\n  return bleu_on_list(ref_lines, hyp_lines, case_sensitive)\n\n\ndef bleu_on_list(ref_lines, hyp_lines, case_sensitive=False):\n  \"\"\"Compute BLEU for two list of strings (reference and hypothesis).\"\"\"\n  if len(ref_lines) != len(hyp_lines):\n    raise ValueError(\n        \"Reference and translation files have different number of \"\n        \"lines (%d VS %d). If training only a few steps (100-200), the \"\n        \"translation may be empty.\" % (len(ref_lines), len(hyp_lines)))\n  if not case_sensitive:\n    ref_lines = [x.lower() for x in ref_lines]\n    hyp_lines = [x.lower() for x in hyp_lines]\n  ref_tokens = [bleu_tokenize(x) for x in ref_lines]\n  hyp_tokens = [bleu_tokenize(x) for x in hyp_lines]\n  return metrics.compute_bleu(ref_tokens, hyp_tokens) * 100\n\n\ndef main(unused_argv):\n  if FLAGS.bleu_variant in (\"both\", \"uncased\"):\n    score = bleu_wrapper(FLAGS.reference, FLAGS.translation, False)\n    logging.info(\"Case-insensitive results: %f\", score)\n\n  if FLAGS.bleu_variant in (\"both\", \"cased\"):\n    score = bleu_wrapper(FLAGS.reference, FLAGS.translation, True)","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/transformer/compute_bleu.py#L80-L116","documentation":"Error \"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.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/transformer/compute_bleu.py:98 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}