code: def test_encode_features(self):
      with tf.Graph().as_default():
          # Inputs.
          vocabulary_size = 4
          # -1 values are ignored.
          input_a = np.array(
              [
                  [3, -1, -1],  # example 0, ids [3]
                  [0, 1, -1],  # example 1, ids [0, 1]
              ]
          )
          input_b = np.array(
              [
                  [0, -1, -1],  # example 0, ids [0]
                  [-1, -1, -1],  # example 1, ids []
              ]
          )
          input_features = {"aaa": input_a, "bbb": input_b}
  
          # Embedding variable.
          embedding_dimension = 2
          embedding_values = (
              (1.0, 2.0),  # id 0
              (3.0, 5.0),  # id 1
              (7.0, 11.0),  # id 2
              (9.0, 13.0),  # id 3
          )
  
          # Expected lookup result, using combiner='mean'.
          expected_lookups_a = (
              # example 0:
              (9.0, 13.0),  # ids [3], embedding = [9, 13]
              # example 1:
              (
                  2.0,
                  3.5,
              ),  # ids [0, 1], embedding = mean([1, 2] + [3, 5]) = [2, 3.5]
          )
          expected_lookups_b = (
              # example 0:
              (1.0, 2.0),  # ids [0], embedding = [1, 2]
              # example 1:
              (0.0, 0.0),  # ids [], embedding = [0, 0]
          )
  
          # Build columns.
          categorical_column_a = (
              feature_column.categorical_column_with_identity(
                  key="aaa", num_buckets=vocabulary_size
              )
          )
          categorical_column_b = (
              feature_column.categorical_column_with_identity(
                  key="bbb", num_buckets=vocabulary_size
              )
          )
          (
              embed_column_a,
              embed_column_b,
          ) = feature_column.shared_embedding_columns(
              [categorical_column_a, categorical_column_b],
              dimension=embedding_dimension,
              initializer=lambda shape, dtype, partition_info: embedding_values,
              shared_embedding_collection_name="custom_collection_name",
          )
  
          feature_columns = {
              "aaa": embed_column_a,
              "bbb": embed_column_b,
          }
  
          cols_to_tensors = feature_lib.encode_features(
              input_features,
              feature_columns.values(),
              mode=tf_estimator.ModeKeys.EVAL,
          )
  
          embedding_lookup_a = cols_to_tensors[feature_columns["aaa"]]
          embedding_lookup_b = cols_to_tensors[feature_columns["bbb"]]
  
          # Assert expected embedding variable and lookups.
          global_vars = tf.compat.v1.get_collection(
              tf.compat.v1.GraphKeys.GLOBAL_VARIABLES
          )
          embedding_var = global_vars[0]
          with tf.compat.v1.Session() as sess:
              sess.run(tf.compat.v1.global_variables_initializer())
              sess.run(tf.compat.v1.tables_initializer())
              self.assertAllEqual(
                  embedding_values, embedding_var.eval()
              )
              self.assertAllEqual(
                  expected_lookups_a, embedding_lookup_a.eval()
              )
              self.assertAllEqual(
                  expected_lookups_b, embedding_lookup_b.eval()
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow import estimator
  from google.protobuf import text_format
  from tensorflow.python.feature_column import feature_column_lib
  from tensorflow_ranking.python import feature
label_desc: Use image node_id 2 for calling the FeatureLibTest obj's underlying member method code with example usage: obj.test_encode_features() without return types