code: def convert(
      prediction_log: prediction_log_pb2.PredictionLog,
      output_example_spec: _OutputExampleSpecType,
  ) -> tf.train.Example:
      """Converts given `prediction_log` to a `tf.train.Example`.
  
      Args:
        prediction_log: The input prediction log.
        output_example_spec: The spec for how to map prediction results to columns
          in example.
  
      Returns:
        A `tf.train.Example` converted from the given prediction_log.
      Raises:
        ValueError: If the inference type or signature name in spec does not match
        that in prediction_log.
      """
      specs = output_example_spec.output_columns_spec
      if prediction_log.HasField("multi_inference_log"):
          example, output_features = _parse_multi_inference_log(
              prediction_log.multi_inference_log, output_example_spec
          )
      else:
          if len(specs) != 1:
              raise ValueError(
                  "Got single inference result, so expect single spec in "
                  "output_example_spec: %s" % output_example_spec
              )
          if prediction_log.HasField("regress_log"):
              if not specs[0].HasField("regress_output"):
                  raise ValueError(
                      "Regression predictions require a regress_output in output_example_spec: %s"
                      % output_example_spec
                  )
              example = tf.train.Example()
              example.CopyFrom(
                  prediction_log.regress_log.request.input.example_list.examples[
                      0
                  ]
              )
              output_features = [
                  (
                      specs[0].regress_output.value_column,
                      [
                          prediction_log.regress_log.response.result.regressions[
                              0
                          ].value
                      ],
                  )
              ]
          elif prediction_log.HasField("classify_log"):
              if not specs[0].HasField("classify_output"):
                  raise ValueError(
                      "Classification predictions require a classify_output in output_example_spec: %s"
                      % output_example_spec
                  )
              example, output_features = _parse_classify_log(
                  prediction_log.classify_log, specs[0].classify_output
              )
          elif prediction_log.HasField("predict_log"):
              if not specs[0].HasField("predict_output"):
                  raise ValueError(
                      "Predict predictions require a predict_output in output_example_spec: %s"
                      % output_example_spec
                  )
              example, output_features = _parse_predict_log(
                  prediction_log.predict_log, specs[0].predict_output
              )
          else:
              raise ValueError(
                  "Unsupported prediction type in prediction_log: %s"
                  % prediction_log
              )
  
      return _add_columns(example, output_features)
  
file_path: tfx/tfx/components/bulk_inferrer/prediction_to_example_utils.py
imports: from typing import Any, List, Tuple, Union
  import numpy
  import tensorflow
  from tfx.proto import bulk_inferrer_pb2
  from tensorflow_serving.apis import classification_pb2
  from tensorflow_serving.apis import prediction_log_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: convert(prediction_log, output_example_spec) and returns: _add_columns