def _make_construct_vocabulary_table_function(
    x, file_format, num_oov_buckets, default_value, store_frequency
):
  """Defines a function to construct a vocabulary lookup table."""
  def construct_table(asset_filepath):
    if file_format == 'tfrecord_gzip':
      initializer = tf_utils.make_tfrecord_vocabulary_lookup_initializer(
          asset_filepath,
          x.dtype,
          return_indicator_as_value=False,
          has_indicator=store_frequency,
      )
    elif file_format == 'text':
      key_index = 1 if store_frequency else tf.lookup.TextFileIndex.WHOLE_LINE
      kwargs = {'delimiter': ' '} if store_frequency else {}
      initializer = tf.lookup.TextFileInitializer(
          asset_filepath,
          key_dtype=x.dtype,
          key_index=key_index,
          value_dtype=tf.int64,
          value_index=tf.lookup.TextFileIndex.LINE_NUMBER,
          **kwargs,
      )
    else:
      raise ValueError(
          '"{}" is not an accepted file_format. It should be one of: {}'.format(
              file_format, analyzers.ALLOWED_VOCABULARY_FILE_FORMATS
          )
      )

    if num_oov_buckets > 0:
      table = tf.lookup.StaticVocabularyTable(
          initializer, num_oov_buckets=num_oov_buckets, lookup_key_dtype=x.dtype
      )
    else:
      table = tf.lookup.StaticHashTable(
          initializer, default_value=default_value
      )
    return table

  return construct_table
Defines a function to construct a vocabulary lookup table.
tensorflow_transform/mappers.py