You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/14 23:51:45 UTC

[GitHub] [beam] yeandy commented on a diff in pull request #21868: Updated documentation for ml.inference docs.

yeandy commented on code in PR #21868:
URL: https://github.com/apache/beam/pull/21868#discussion_r897408161


##########
sdks/python/apache_beam/ml/inference/sklearn_inference.py:
##########
@@ -76,29 +85,47 @@ def load_model(self) -> BaseEstimator:
   def run_inference(
       self, batch: Sequence[numpy.ndarray], model: BaseEstimator,
       **kwargs) -> Iterable[PredictionResult]:
+    """Runs inferences on a batch of numpy arrays.
+
+    Returns:
+      An Iterable of type PredictionResult.
+    """
     # vectorize data for better performance
     vectorized_batch = numpy.stack(batch, axis=0)
     predictions = model.predict(vectorized_batch)
     return [PredictionResult(x, y) for x, y in zip(batch, predictions)]
 
   def get_num_bytes(self, batch: Sequence[pandas.DataFrame]) -> int:
-    """Returns the number of bytes of data for a batch."""
+    """
+    Returns:
+      The number of bytes of data for a batch.
+    """
     return sum(sys.getsizeof(element) for element in batch)
 
 
 class SklearnModelHandlerPandas(ModelHandler[pandas.DataFrame,
                                              PredictionResult,
                                              BaseEstimator]):
-  """ Implementation of the ModelHandler interface for scikit-learn that
-      supports pandas dataframes.
-
-      NOTE: This API and its implementation are under development and
-      do not provide backward compatibility guarantees.
-  """
   def __init__(
       self,
       model_uri: str,
       model_file_type: ModelFileType = ModelFileType.PICKLE):
+    """Implementation of the ModelHandler interface for scikit-learn that
+    supports pandas dataframes.
+
+    Example Usage:
+      pcol | RunInference(SklearnModelHandlerPandas(model_uri="my_uri"))
+
+    NOTE::
+      This API and its implementation are under development and
+      do not provide backward compatibility guarantees.
+
+

Review Comment:
   nit: extra line?



##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -19,15 +19,12 @@
 
 """An extensible run inference transform.
 
-Users of this module can extend the ModelHandler class for any MLframework. Then
-pass their extended ModelHandler object into RunInference to create a
-RunInference Beam transform for that framework.
+Users of this module can extend the ModelHandler class for any machine learning
+framework. Then pass their extended ModelHandler object into RunInference to

Review Comment:
   nit: grammar for "Then pass their extended..."



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org