{"record":{"id":"3ee6cb5e55227304","repo":"tensorflow/models","slug":"file-output-is-a-directory-will-not-save-outputs","errorCode":null,"errorMessage":"File output is a directory, will not save outputs to file.","messagePattern":"File output is a directory, will not save outputs to file\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/transformer/translate.py","lineNumber":171,"sourceCode":"      val_outputs = [output for _, output in outputs]\n\n      val_outputs = np.reshape(val_outputs, [params[\"decode_batch_size\"], -1])\n    else:\n      val_outputs, _ = model.predict(text)\n\n    length = len(val_outputs)\n    for j in range(length):\n      if j + i * batch_size < total_samples:\n        translation = _trim_and_decode(val_outputs[j], subtokenizer)\n        translations.append(translation)\n        if print_all_translations:\n          logging.info(\"Translating:\\n\\tInput: %s\\n\\tOutput: %s\",\n                       sorted_inputs[j + i * batch_size], translation)\n\n  # Write translations in the order they appeared in the original file.\n  if output_file is not None:\n    if tf.io.gfile.isdir(output_file):\n      raise ValueError(\"File output is a directory, will not save outputs to \"\n                       \"file.\")\n    logging.info(\"Writing to file %s\", output_file)\n    with tf.io.gfile.GFile(output_file, \"w\") as f:\n      for i in sorted_keys:\n        f.write(\"%s\\n\" % translations[i])\n\n\ndef translate_from_text(model, subtokenizer, txt):\n  encoded_txt = _encode_and_add_eos(txt, subtokenizer)\n  result = model.predict(encoded_txt)\n  outputs = result[\"outputs\"]\n  logging.info(\"Original: \\\"%s\\\"\", txt)\n  translate_from_input(outputs, subtokenizer)\n\n\ndef translate_from_input(outputs, subtokenizer):\n  translation = _trim_and_decode(outputs, subtokenizer)\n  logging.info(\"Translation: \\\"%s\\\"\", translation)","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/transformer/translate.py#L153-L189","documentation":"Error \"File output is a directory, will not save outputs to file.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/transformer/translate.py:171 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"}