reader.initialize() since = time.time() batch_size = args.batch_size fout = open(args.output, 'w') while True: src_seq, src_mask, utts = reader.read_batch_utt(batch_size) if len(utts) == 0: break with torch.no_grad(): src_seq, src_mask = src_seq.to(device), src_mask.to(device) hypos, scores = beam_search(model, src_seq, src_mask, device, args.beam_size, args.max_len, len_norm=args.len_norm, coverage=args.coverage, lm=lm, lm_scale=args.lm_scale) hypos, scores = hypos.tolist(), scores.tolist() if args.format == 'ctm': write_ctm(hypos, scores, fout, utts, dic, word_dic, args.space) else: write_text(hypos, scores, fout, utts, dic, args.space) fout.close() time_elapsed = time.time() - since print(" Elapsed Time: %.0fm %.0fs" % (time_elapsed // 60, time_elapsed % 60))
since = time.time() batch_size = args.batch_size fout = open(args.output, 'w') while True: src_seq, src_mask, utts = reader.read_batch_utt(batch_size) if len(utts) == 0: break with torch.no_grad(): src_seq, src_mask = src_seq.to(device), src_mask.to(device) hypos, scores = beam_search(model, src_seq, src_mask, device, args.beam_size, args.max_len, len_norm=args.len_norm, coverage=args.coverage, lm=lm, lm_scale=args.lm_scale) hypos, scores = hypos.tolist(), scores.tolist() if args.format == 'ctm': write_ctm(hypos, scores, fout, utts, dic, word_dic, args.space) elif args.format == 'stm': write_stm(hypos, fout, utts, dic, word_dic, args.space) else: write_text(hypos, fout, utts, dic, word_dic, args.space) fout.close() time_elapsed = time.time() - since print(" Elapsed Time: %.0fm %.0fs" % (time_elapsed // 60, time_elapsed % 60))