def lookup_table(lookup_fn: Callable[[common_types.TensorType, tf.Tensor],
                                     Tuple[tf.Tensor, tf.Tensor]],
                 asset_filepath: _AssetFileType, x: common_types.TensorType):
  """Takes a `lookup_fn` and invokes it on `x` and `asset_filepath`.

  If an eager tensor is being tracked by `asset_filepath`, `lookup_fn` is
  invoked on it instead.

  Args:
    lookup_fn: A Callable that should take a tensor and a deferred vocab
      filename as an input and return a lookup `op` along with the table size.
    asset_filepath: Path to an asset used to construct the table. Can be a
      python string, a `tf.Tensor`, a `tf.Placeholder`.
    x: A categorical `Tensor` or `SparseTensor` of type tf.string or
      tf.int[8|16|32|64] to which the table lookup should be applied.

  Returns:
    A tuple of the result from looking x up and the table size.
  """
  # If table is lifted into an initialization scope, add a control dependency
  # on the graph tensor used to track this analyzer in
  # `analyzer_nodes.TENSOR_REPLACEMENTS`.
  asset_filepath, control_dependency = (
      _get_asset_analyzer_output_and_control_dependency(asset_filepath))
  lookup_result, table_size = lookup_fn(x, asset_filepath)
  with contextlib.ExitStack() as stack:
    # tf.control_dependencies([tensor]) adds a dependency to tensor.op. Wrap the
    # `lookup_result` in an identity op to ensure that walking the graph from
    # it encounters the `control_dependency` tensor. The table size should not
    # have the `control_dependency` tensor as its parent, hence it is returned
    # as is.
    if control_dependency is not None:
      stack.enter_context(
          tf.control_dependencies([tf.identity(control_dependency)]))
    return tf.identity(lookup_result), table_size
Takes a `lookup_fn` and invokes it on `x` and `asset_filepath`.

  If an eager tensor is being tracked by `asset_filepath`, `lookup_fn` is
  invoked on it instead.

  Args:
    lookup_fn: A Callable that should take a tensor and a deferred vocab
      filename as an input and return a lookup `op` along with the table size.
    asset_filepath: Path to an asset used to construct the table. Can be a
      python string, a `tf.Tensor`, a `tf.Placeholder`.
    x: A categorical `Tensor` or `SparseTensor` of type tf.string or
      tf.int[8|16|32|64] to which the table lookup should be applied.

  Returns:
    A tuple of the result from looking x up and the table size.
  
tensorflow_transform/tf_utils.py