def infer_feature_schema_v2(
    features: Mapping[str, common_types.TensorType],
    concrete_metadata_fn: function.ConcreteFunction,
    evaluate_schema_overrides: bool) -> schema_pb2.Schema:
  """Given a dict of tensors, creates a `Schema`.

  Infers a schema, in the format of a tf.Transform `Schema`, for the given
  dictionary of tensors.

  If there is an override specified, we override the inferred schema for the
  given feature's tensor.  An override has the meaning that we should set
  is_categorical=True.  If evaluate_schema_overrides is False then we just set
  is_categorical=True, and if evaluate_schema_overrides is True then we also
  compute values of the tensors representing the min and max values and set them
  in the schema.

  If annotations have been specified, they are added to the output schema.

  Args:
    features: A dict mapping column names to `Tensor`, `SparseTensor` or
      `RaggedTensor`. The `Tensor`, `SparseTensor` or `RaggedTensor` should have
      a 0'th dimension which is interpreted as the batch dimension.
    concrete_metadata_fn: A `tf.ConcreteFunction` that returns a dictionary
      containing the deferred annotations added to the graph when invoked with
      any valid input.
    evaluate_schema_overrides: A Boolean used to compute schema overrides. If
      `False`, schema overrides will not be computed.

  Returns:
    A `Schema` proto.
  """
  metadata = collections.defaultdict(list, concrete_metadata_fn())

  if not evaluate_schema_overrides:
    tensor_ranges = {
        tensor.numpy().decode(): (None, None)
        for tensor in metadata[_TF_METADATA_TENSOR_COLLECTION]
    }
    tensor_annotations = {}
    global_annotations = []
  else:
    tensor_ranges = _get_tensor_ranges_v2(metadata)
    tensor_annotations, global_annotations = _get_schema_annotations_v2(
        metadata)

  def _get_metadata_sparse_output_annotations(metadata):
    sparse_output_annotations = metadata[
        _METADATA_SPARSE_OUTPUT_OVERRIDES_FIELD
    ]
    if not sparse_output_annotations:
      return None
    return {
        k: [a.numpy() for a in v]
        for k, v in sparse_output_annotations[0].items()
    }

  return _infer_feature_schema_common(
      features,
      tensor_ranges,
      tensor_annotations,
      global_annotations,
      sparse_output_annotations=_get_metadata_sparse_output_annotations(
          metadata
      ),
      is_evaluation_complete=evaluate_schema_overrides,
  )
Given a dict of tensors, creates a `Schema`.

  Infers a schema, in the format of a tf.Transform `Schema`, for the given
  dictionary of tensors.

  If there is an override specified, we override the inferred schema for the
  given feature's tensor.  An override has the meaning that we should set
  is_categorical=True.  If evaluate_schema_overrides is False then we just set
  is_categorical=True, and if evaluate_schema_overrides is True then we also
  compute values of the tensors representing the min and max values and set them
  in the schema.

  If annotations have been specified, they are added to the output schema.

  Args:
    features: A dict mapping column names to `Tensor`, `SparseTensor` or
      `RaggedTensor`. The `Tensor`, `SparseTensor` or `RaggedTensor` should have
      a 0'th dimension which is interpreted as the batch dimension.
    concrete_metadata_fn: A `tf.ConcreteFunction` that returns a dictionary
      containing the deferred annotations added to the graph when invoked with
      any valid input.
    evaluate_schema_overrides: A Boolean used to compute schema overrides. If
      `False`, schema overrides will not be computed.

  Returns:
    A `Schema` proto.
  
tensorflow_transform/schema_inference.py