code: def testValidation(self):
      # Test no feature spec.
      with self.assertRaisesRegex(
          ValueError, "ModelAgnosticConfig must have feature_spec set."
      ):
          model_agnostic_predict.ModelAgnosticConfig(
              label_keys=["label"],
              prediction_keys=["probabilities"],
              feature_spec=None,
          )
  
      # Test no prediction keys.
      feature_map = {
          "age": tf.io.FixedLenFeature([], tf.int64),
          "language": tf.io.VarLenFeature(tf.string),
          "probabilities": tf.io.FixedLenFeature(
              [2], tf.int64, default_value=[9, 9]
          ),
          "label": tf.io.FixedLenFeature([], tf.int64),
      }
  
      with self.assertRaisesRegex(
          ValueError,
          "ModelAgnosticConfig must have prediction keys set.",
      ):
          model_agnostic_predict.ModelAgnosticConfig(
              label_keys=["label"],
              prediction_keys=[],
              feature_spec=feature_map,
          )
  
      # Test no label keys.
      with self.assertRaisesRegex(
          ValueError, "ModelAgnosticConfig must have label keys set."
      ):
          model_agnostic_predict.ModelAgnosticConfig(
              label_keys=[],
              prediction_keys=["predictions"],
              feature_spec=feature_map,
          )
  
      # Test prediction key not in feature spec.
      with self.assertRaisesRegex(
          ValueError,
          "Prediction key not_prob not defined in feature_spec.",
      ):
          model_agnostic_predict.ModelAgnosticConfig(
              label_keys=["label"],
              prediction_keys=["not_prob"],
              feature_spec=feature_map,
          )
  
      # Test label key not in feature spec.
      with self.assertRaisesRegex(
          ValueError, "Label key not_label not defined in feature_spec."
      ):
          model_agnostic_predict.ModelAgnosticConfig(
              label_keys=["not_label"],
              prediction_keys=["probabilities"],
              feature_spec=feature_map,
          )
  
imports: import numpy
  import tensorflow
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.model_agnostic_eval import model_agnostic_predict
label_desc: Use image node_id 1 for calling the ModelAgnosticPredictTest obj's underlying member method code with example usage: obj.testValidation() without return types