damccorm commented on code in PR #23087:
URL: https://github.com/apache/beam/pull/23087#discussion_r966326215


##########
sdks/python/apache_beam/ml/inference/sklearn_inference.py:
##########
@@ -183,6 +195,18 @@ def run_inference(
     splits = [
         vectorized_batch.iloc[[i]] for i in range(vectorized_batch.shape[0])
     ]
+    if isinstance(predictions, dict):
+      # Go from one dictionary of type: {key_type1: Iterable<value_type1>,
+      # key_type2: Iterable<value_type2>, ...} where each Iterable is of
+      # length batch_size, to a list of dictionaries:
+      # [{key_type1: value_type1, key_type2: value_type2}]
+      predictions_per_split = [
+          dict(zip(predictions, v)) for v in zip(*predictions.values())
+      ]
+      return [
+          PredictionResult(example, inference) for example,
+          inference in zip(splits, predictions_per_split)
+      ]

Review Comment:
   I think it can be refactored cleanly - done



-- 
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]

Reply via email to