def make_tfrecord_vocabulary_lookup_initializer(filename_tensor,
                                                key_dtype=tf.string,
                                                value_dtype=tf.int64,
                                                return_indicator_as_value=False,
                                                has_indicator=False):
  """Makes a lookup table initializer from a compressed tfrecord file."""
  with contextlib.ExitStack() as stack:
    # If filename_tensor is a graph tensor (e.g. temporary analyzer output), the
    # following operation cannot be lifted to init scope. Hence, check it is an
    # eager tensor or a string constant.
    if (tf.inside_function() and
        isinstance(filename_tensor, (ops.EagerTensor, str))):
      # Lift the dataset creation out of graph construction to avoid
      # repeated initialization in TF2.
      stack.enter_context(tf.init_scope())

    dataset = _make_tfrecord_vocabulary_dataset(filename_tensor, key_dtype,
                                                value_dtype,
                                                return_indicator_as_value,
                                                has_indicator)
    if tf.inside_function():
      annotators.track_object(dataset, name=None)
    return _DatasetInitializerCompat(dataset)
Makes a lookup table initializer from a compressed tfrecord file.
tensorflow_transform/tf_utils.py