Deserializes a `tf.SparseTensor` from `sparse_tensor_proto`.

  Args:
    sparse_tensor_proto: A proto representing a `tf.SparseTensor`.
    process_leafs: A function to be applied to the leaf valued of the nested
      structure.

  Returns:
    An instance of `tf.SparseTensor`.

def _from_proto_sparse_tensor(sparse_tensor_proto, process_leafs):
  """Deserializes a `tf.SparseTensor` from `sparse_tensor_proto`.

  Args:
    sparse_tensor_proto: A proto representing a `tf.SparseTensor`.
    process_leafs: A function to be applied to the leaf valued of the nested
      structure.

  Returns:
    An instance of `tf.SparseTensor`.
  """
  if not sparse_tensor_proto.HasField("named_tuple"):
    raise base_errors.ModuleInfoError(
        "Error while deserializing a SparseTensor: expected proto tuple.")
  if sparse_tensor_proto.named_tuple.name != _SPARSE_TENSOR_NAME:
    raise base_errors.ModuleInfoError(
        "Error while deserializing a SparseTensor: The name of the tuple "
        "should have been {} but was {}.".format(
            _SPARSE_TENSOR_NAME, sparse_tensor_proto.named_tuple.name))
  named_tuple_map = sparse_tensor_proto.named_tuple.map
  return tf.SparseTensor(
      indices=process_leafs(named_tuple_map["indices"].value),
      values=process_leafs(named_tuple_map["values"].value),
      dense_shape=process_leafs(named_tuple_map["dense_shape"].value))