Close open files to suppress ResourceWarning (#11240)

Co-authored-by: Sudharsan Thirumalai <sudharsan.t@sprinklr.com>
This commit is contained in:
Sudharsan S T
2021-04-14 20:01:04 +05:30
committed by GitHub
parent 7fe5aaa8b0
commit f25444cb22
3 changed files with 6 additions and 3 deletions

View File

@@ -204,7 +204,8 @@ def run_generate():
save_json(preds, save_path)
return
tgt_file = Path(args.data_dir).joinpath(args.type_path + ".target")
labels = [x.rstrip() for x in open(tgt_file).readlines()][: len(preds)]
with open(tgt_file) as f:
labels = [x.rstrip() for x in f.readlines()][: len(preds)]
# Calculate metrics, save metrics, and save _generations.txt
calc_bleu = "translation" in args.task