code: def test_cpu_sparse_lookup_with_weights(self):
      mid_level = self._create_mid_level()
      features = self._get_sparse_tensors()
      weights = self._get_sparse_tensors(dtype=dtypes.float32)
      results = mid_level(features, weights=weights)
      weighted_sum = []
      for feature, weight, config in zip(
          nest.flatten(features),
          nest.flatten(weights),
          self.feature_config,
      ):
          table = mid_level.embedding_tables[config.table].numpy()
          # Expand dims here needed to broadcast this multiplication properly.
          weight = np.expand_dims(weight.values.numpy(), axis=1)
          all_lookups = table[feature.values.numpy()] * weight
          # With row starts we can use reduceat in numpy. Get row starts from the
          # ragged tensor API.
          row_starts = ragged_tensor.RaggedTensor.from_sparse(
              feature
          ).row_starts()
          row_starts = row_starts.numpy()
          weighted_sum.append(np.add.reduceat(all_lookups, row_starts))
          if config.table.combiner == "mean":
              weighted_sum[-1] /= np.add.reduceat(weight, row_starts)
      self.assertAllClose(
          results, nest.pack_sequence_as(results, weighted_sum)
      )
  
imports: import numpy
  from tensorflow.python.compat import v2_compat
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.ops import init_ops_v2
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow.python.platform import test
  from tensorflow.python.tpu import tpu_embedding_for_serving
  from tensorflow.python.tpu import tpu_embedding_v2_utils
  from tensorflow.python.util import nest
label_desc: Use image node_id 8 for calling the TPUEmbeddingForServingTest obj's underlying member method code with example usage: obj.test_cpu_sparse_lookup_with_weights() without return types