docstr: Tests that predictions are made from extracts for multiple models.
docstr_tok: ["Tests","that","predictions","are","made","from","extracts","for","multiple","models","."]
code: def testMakeSklearnPredictExtractorWithMultiModels(self):
      """Tests that predictions are made from extracts for multiple models."""
      eval_config = tfma.EvalConfig(
          model_specs=[
              tfma.ModelSpec(name="model1"),
              tfma.ModelSpec(name="model2"),
          ]
      )
      eval_export_dir_1 = os.path.join(self._eval_export_dir, "1")
      self._create_sklearn_model(eval_export_dir_1)
      eval_shared_model_1 = (
          sklearn_predict_extractor.custom_eval_shared_model(
              eval_saved_model_path=eval_export_dir_1,
              model_name="model1",
              eval_config=eval_config,
          )
      )
      eval_export_dir_2 = os.path.join(self._eval_export_dir, "2")
      self._create_sklearn_model(eval_export_dir_2)
      eval_shared_model_2 = (
          sklearn_predict_extractor.custom_eval_shared_model(
              eval_saved_model_path=eval_export_dir_2,
              model_name="model2",
              eval_config=eval_config,
          )
      )
  
      feature_extractor = tfma.extractors.FeaturesExtractor(
          self._eval_config
      )
      prediction_extractor = (
          sklearn_predict_extractor._make_sklearn_predict_extractor(
              eval_shared_model={
                  "model1": eval_shared_model_1,
                  "model2": eval_shared_model_2,
              }
          )
      )
      with beam.Pipeline() as pipeline:
          predict_extracts = (
              pipeline
              | "Create"
              >> beam.Create(
                  [e.SerializeToString() for e in self._examples]
              )
              | "BatchExamples" >> self._tfx_io.BeamSource()
              | "InputsToExtracts"
              >> tfma.BatchedInputsToExtracts()  # pylint: disable=no-value-for-parameter
              | feature_extractor.stage_name
              >> feature_extractor.ptransform
              | prediction_extractor.stage_name
              >> prediction_extractor.ptransform
          )
  
          def check_result(actual):
              try:
                  for item in actual:
                      self.assertEqual(
                          item["labels"].shape,
                          item["predictions"].shape,
                      )
                      self.assertIn("model1", item["predictions"][0])
                      self.assertIn("model2", item["predictions"][0])
  
              except AssertionError as err:
                  raise util.BeamAssertException(err)
  
          util.assert_that(predict_extracts, check_result)
  
file_path: tfx/tfx/examples/penguin/experimental/sklearn_predict_extractor_test.py
imports: import os
  import pickle
  import apache_beam
  from apache_beam.testing import util
  from sklearn import neural_network
  import tensorflow_model_analysis
  from tfx.examples.penguin.experimental import sklearn_predict_extractor
  from tfx_bsl.tfxio import tensor_adapter
  from tfx_bsl.tfxio import test_util
  from google.protobuf import text_format
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 3 for calling the SklearnPredictExtractorTest obj's underlying member method code with example usage: obj.testMakeSklearnPredictExtractorWithMultiModels() without return types