(self, model, output_path, args)
| 52 | return model |
| 53 | |
| 54 | def infer(self, model, output_path, args): |
| 55 | output = open(output_path, 'w') |
| 56 | |
| 57 | with torch.no_grad(): |
| 58 | if args.mode == 'infer': |
| 59 | orig_data = registry.construct('dataset', self.config['data'][args.section]) |
| 60 | preproc_data = self.model_preproc.dataset(args.section) |
| 61 | if args.limit: |
| 62 | sliced_orig_data = itertools.islice(orig_data, args.limit) |
| 63 | sliced_preproc_data = itertools.islice(preproc_data, args.limit) |
| 64 | else: |
| 65 | sliced_orig_data = orig_data |
| 66 | sliced_preproc_data = preproc_data |
| 67 | assert len(orig_data) == len(preproc_data) |
| 68 | self._inner_infer(model, args.beam_size, args.output_history, sliced_orig_data, sliced_preproc_data, output, args.use_heuristic) |
| 69 | elif args.mode == 'debug': |
| 70 | data = self.model_preproc.dataset(args.section) |
| 71 | if args.limit: |
| 72 | sliced_data = itertools.islice(data, args.limit) |
| 73 | else: |
| 74 | sliced_data = data |
| 75 | self._debug(model, sliced_data, output) |
| 76 | elif args.mode == 'visualize_attention': |
| 77 | model.visualize_flag = True |
| 78 | model.decoder.visualize_flag = True |
| 79 | data = registry.construct('dataset', self.config['data'][args.section]) |
| 80 | if args.limit: |
| 81 | sliced_data = itertools.islice(data, args.limit) |
| 82 | else: |
| 83 | sliced_data = data |
| 84 | self._visualize_attention(model, args.beam_size, args.output_history, sliced_data, args.res1, args.res2, args.res3, output) |
| 85 | |
| 86 | def _infer_one(self, model, data_item, preproc_item, beam_size, output_history=False, use_heuristic=True): |
| 87 | if use_heuristic: |
no test coverage detected