AnandInguva commented on code in PR #23266:
URL: https://github.com/apache/beam/pull/23266#discussion_r973084809
##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -82,6 +82,33 @@ def _to_microseconds(time_ns: int) -> int:
return int(time_ns / _NANOSECOND_TO_MICROSECOND)
+def _convert_to_result(
+ batch: Iterable,
+ predictions: Union[Iterable, Dict[Any, Iterable]],
+ drop_example: bool = False) -> Iterable[PredictionResult]:
+ if isinstance(predictions, dict):
+ # Go from one dictionary of type: {key_type1: Iterable<val_type1>,
+ # key_type2: Iterable<val_type2>, ...} where each Iterable is of
+ # length batch_size, to a list of dictionaries:
+ # [{key_type1: value_type1, key_type2: value_type2}]
+ predictions_per_tensor = [
+ dict(zip(predictions.keys(), v)) for v in zip(*predictions.values())
+ ]
+ if not drop_example:
+ return [
+ PredictionResult(x, y) for x, y in zip(batch, predictions_per_tensor)
+ ]
+ else:
+ return [
+ PredictionResult(None, y) for x,
+ y in zip(batch, predictions_per_tensor)
+ ]
Review Comment:
Done. PTAL
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]