class_docstr: Ranking agent class.
docstr: Returns the training weights based on all the necessary information.
  
  The input weights might be `None` or of shape `[1]`, or [`batch_size`]. The
  shape of the output shape is always `[batch_size, num_slots]`.
  
  Args:
    reward: The reward tensor or nest. Its structure depends on the feedback
      model.
    observation: The observation nest.
    weights: The input weights, with structure explained above.
  
  Returns:
    A tensor of shape `[batch_size, num_slots]` containing the constructed
      output weights, depending on the feedback model and the positional bias
      model.
docstr_tok: ["Returns","the","training","weights","based","on","all","the","necessary","information",".","The","input","weights","might","be","`","None","`","or","of","shape","`","[","1","]","`",",","or","[","`","batch_size","`","]",".","The","shape","of","the","output","shape","is","always","`","[","batch_size",",","num_slots","]","`",".","Args",":","reward",":","The","reward","tensor","or","nest",".","Its","structure","depends","on","the","feedback","model",".","observation",":","The","observation","nest",".","weights",":","The","input","weights",",","with","structure","explained","above",".","Returns",":","A","tensor","of","shape","`","[","batch_size",",","num_slots","]","`","containing","the","constructed","output","weights",",","depending","on","the","feedback","model","and","the","positional","bias","model","."]
code: def _construct_sample_weights(self, reward, observation, weights):
      """Returns the training weights based on all the necessary information.
  
      The input weights might be `None` or of shape `[1]`, or [`batch_size`]. The
      shape of the output shape is always `[batch_size, num_slots]`.
  
      Args:
        reward: The reward tensor or nest. Its structure depends on the feedback
          model.
        observation: The observation nest.
        weights: The input weights, with structure explained above.
  
      Returns:
        A tensor of shape `[batch_size, num_slots]` containing the constructed
          output weights, depending on the feedback model and the positional bias
          model.
      """
      batch_size = tf.shape(tf.nest.flatten(reward)[0])[0]
      if weights is None:
          weights = tf.ones([batch_size, self._num_slots])
      elif not list(weights.shape):
          weights = weights * tf.ones([batch_size, self._num_slots])
      else:
          tf.debugging.assert_equal(tf.shape(weights), [batch_size])
          weights = tf.reshape(weights, shape=[-1, 1])
          weights = tf.tile(weights, multiples=[1, self._num_slots])
  
      if self._use_num_actions:
          num_slotted_items = observation[
              bandit_spec_utils.NUM_ACTIONS_FEATURE_KEY
          ]
          weights = (
              tf.sequence_mask(
                  num_slotted_items, self._num_slots, dtype=tf.float32
              )
              * weights
          )
      if self._feedback_model == FeedbackModel.CASCADING:
          chosen_index = tf.reshape(reward[CHOSEN_INDEX], shape=[-1])
          multiplier = tf.sequence_mask(
              chosen_index + 1, self._num_slots, dtype=tf.float32
          )
          weights = multiplier * weights
      if self._positional_bias_type is not None:
          batched_range = tf.broadcast_to(
              tf.range(self._num_slots, dtype=tf.float32),
              tf.shape(weights),
          )
          if self._positional_bias_type == "base":
              position_bias_multipliers = tf.pow(
                  batched_range + 1, self._positional_bias_severity
              )
          elif self._positional_bias_type == "exponent":
              position_bias_multipliers = tf.pow(
                  self._positional_bias_severity, batched_range
              )
          else:
              raise ValueError(
                  "non-existing bias type: "
                  + self._positional_bias_type
              )
          weights = position_bias_multipliers * weights
      return weights
  
imports: import enum
  from typing import Optional, Text
  import tensorflow
  from tf_agents.agents import tf_agent
  from tf_agents.bandits.policies import ranking_policy
  from tf_agents.specs import bandit_spec_utils
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import eager_utils
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 5 for calling the RankingAgent obj's underlying member method code with example usage: obj._construct_sample_weights(reward, observation, weights) and returns: weights