code: def _sampled_logits_lookup_grad(
      op,
      keys_grad,
      labels_grad,
      expected_counts_grad,
      mask_grad,
      weights_grad,
  ):
      """Computes the gradients for SampledLogitsLookup.
  
      We uses the gradients w.r.t. the weights output of sampled_logits_lookup() to
      update the embeddings/weights of the sampled keys.
      The gradients for the inputs of sampled_logits_lookup should be provided, but
      none of them needs to be back-propagated. So we set all of them to be zeros.
  
      Args:
        op: The DynamicEmbeddingLookup op.
        keys_grad: The tensor representing the gradient w.r.t. the keys output.
        labels_grad: The tensor representing the gradient w.r.t. the labels output.
        expected_counts_grad: The tensor representing the gradient w.r.t. the
          expected_counts output.
        mask_grad: The tensor representing the gradient w.r.t. the mask output.
        weights_grad: The tensor representing the gradient w.r.t. the weights
          output.
  
      Returns:
        The gradients w.r.t. the input.
      """
      del (
          keys_grad,
          labels_grad,
          expected_counts_grad,
          mask_grad,
      )  # Unused.
  
      (
          pos_keys_grad,
          num_samples_grad,
          dummy_variable_grad,
          resource_grad,
      ) = gen_carls_ops.sampled_logits_lookup_grad(
          keys=op.outputs[0],
          weight_gradients=weights_grad,
          handle=op.inputs[4],
      )
      # Gradient for the input activation.
      inputs_grad = tf.zeros_like(op.inputs[1])
      return (
          pos_keys_grad,
          inputs_grad,
          num_samples_grad,
          dummy_variable_grad,
          resource_grad,
      )
  
file_path: neural-structured-learning/research/carls/candidate_sampling_ops.py
imports: import typing
  from research.carls import context
  from research.carls import dynamic_embedding_config_pb2
  from research.carls.kernels import gen_carls_ops
  import tensorflow
label_desc: Use image node_id 5 for calling a global function with example usage: _sampled_logits_lookup_grad(op, keys_grad, labels_grad, expected_counts_grad, mask_grad, weights_grad) and returns: pos_keys_grad,  inputs_grad,  num_samples_grad,  dummy_variable_grad,  resource_grad