Number predictions.
@@ -141,11 +141,12 @@ class _PredictManager:
yield self._predictor.dump_line(output)
def _maybe_print_to_console_and_file(self,
+ index: int,
prediction: str,
model_input: str = None) -> None:
if self._print_to_console:
if model_input is not None:
- print("input: ", model_input)
+ print(f"input {index}: ", model_input)
print("prediction: ", prediction)
if self._output_file is not None:
self._output_file.write(prediction)
@@ -171,14 +172,17 @@ class _PredictManager:
def run(self) -> None:
has_reader = self._dataset_reader is not None
+ index = 0
if has_reader:
for batch in lazy_groups_of(self._get_instance_data(), self._batch_size):
for model_input_instance, result in zip(batch, self._predict_instances(batch)):
- self._maybe_print_to_console_and_file(result, str(model_input_instance))
+ self._maybe_print_to_console_and_file(index, result, str(model_input_instance))
+ index = index + 1
else:
for batch_json in lazy_groups_of(self._get_json_data(), self._batch_size):
for model_input_json, result in zip(batch_json, self._predict_json(batch_json)):
- self._maybe_print_to_console_and_file(result, json.dumps(model_input_json))
+ self._maybe_print_to_console_and_file(index, result, json.dumps(model_input_json))
+ index = index + 1
if self._output_file is not None:
self._output_file.close()
