class_docstr: A class implementing ranking policies in TF Agents.
  
  The ranking policy needs at initialization the number of items per round to
  rank, a scorer network, and a score penalizer function. This function should
  ensure that similar items don't all get high scores and thus a diverse set of
  items is recommended.
  
  In the case the number of items to rank varies from iteration to iteration,
  the observation contains a `num_actions` value, that specifies the number of
  items available. Note that in this case it can happen that the number of
  ranked items is less than the number of slots. Thus, consumers of the output
  of `policy.action` should always use the `num_actions` value to determine what
  part of the output is the action ranking.
  
  If `num_actions` field is not used, the policy is always presented with
  `num_items` many items, which should be greater than or equal to `num_slots`.
docstr: Initializes an instance of `RankingPolicy`.
  
  Args:
    num_items: The number of items the policy can choose from, to be slotted.
    num_slots: The number of recommendation slots presented to the user, i.e.,
      chosen by the policy.
    time_step_spec: The time step spec.
    network: The network that estimates scores of items, given global and item
      features.
    item_sampler: A distibution that takes scores and item features, and
      samples an ordered list of `num_slots` items. Similarity penalization
      can be implemented within this sampler.
    penalty_mixture_coefficient: A parameter responsible for the balance
      between selecting high scoring items and enforcing diverisity.
    logits_temperature: The "temperature" parameter for sampling. All the
      logits will be divided by this float value. This value must be positive.
    name: The name of this policy instance.
docstr_tok: ["Initializes","an","instance","of","`","RankingPolicy","`",".","Args",":","num_items",":","The","number","of","items","the","policy","can","choose","from",",","to","be","slotted",".","num_slots",":","The","number","of","recommendation","slots","presented","to","the","user",",","i.e.",",","chosen","by","the","policy",".","time_step_spec",":","The","time","step","spec",".","network",":","The","network","that","estimates","scores","of","items",",","given","global","and","item","features",".","item_sampler",":","A","distibution","that","takes","scores","and","item","features",",","and","samples","an","ordered","list","of","`","num_slots","`","items",".","Similarity","penalization","can","be","implemented","within","this","sampler",".","penalty_mixture_coefficient",":","A","parameter","responsible","for","the","balance","between","selecting","high","scoring","items","and","enforcing","diverisity",".","logits_temperature",":","The","``","temperature","''","parameter","for","sampling",".","All","the","logits","will","be","divided","by","this","float","value",".","This","value","must","be","positive",".","name",":","The","name","of","this","policy","instance","."]
code: def __init__(
      self,
      num_items: int,
      num_slots: int,
      time_step_spec: types.TimeStep,
      network: types.Network,
      item_sampler: tfd.Distribution,
      penalty_mixture_coefficient: float = 1.0,
      logits_temperature: float = 1.0,
      name: Optional[Text] = None,
  ):
      """Initializes an instance of `RankingPolicy`.
  
      Args:
        num_items: The number of items the policy can choose from, to be slotted.
        num_slots: The number of recommendation slots presented to the user, i.e.,
          chosen by the policy.
        time_step_spec: The time step spec.
        network: The network that estimates scores of items, given global and item
          features.
        item_sampler: A distibution that takes scores and item features, and
          samples an ordered list of `num_slots` items. Similarity penalization
          can be implemented within this sampler.
        penalty_mixture_coefficient: A parameter responsible for the balance
          between selecting high scoring items and enforcing diverisity.
        logits_temperature: The "temperature" parameter for sampling. All the
          logits will be divided by this float value. This value must be positive.
        name: The name of this policy instance.
      """
      action_spec = tensor_spec.BoundedTensorSpec(
          shape=(num_slots,),
          dtype=tf.int32,
          minimum=0,
          maximum=num_items - 1,
      )
      info_spec = policy_utils.PolicyInfo(
          predicted_rewards_mean=tensor_spec.TensorSpec(
              shape=(num_slots,), dtype=tf.float32
          )
      )
      network.create_variables()
      self._network = network
      assert num_slots <= num_items, (
          "The number of slots have to be less than or equal to the number of "
          "items."
      )
      self._num_slots = num_slots
      self._num_items = num_items
      self._item_sampler = item_sampler
      self._penalty_mixture_coefficient = penalty_mixture_coefficient
      if logits_temperature <= 0:
          raise ValueError(
              f"logits_temperature must be positive; was {logits_temperature}"
          )
      self._logits_temperature = logits_temperature
      if (
          bandit_spec_utils.NUM_ACTIONS_FEATURE_KEY
          in time_step_spec.observation
      ):
          self._use_num_actions = True
      else:
          self._use_num_actions = False
      super(RankingPolicy, self).__init__(
          time_step_spec=time_step_spec,
          action_spec=action_spec,
          name=name,
          info_spec=info_spec,
      )
  
imports: from typing import Optional, Sequence, Text
  import numpy
  import tensorflow
  import tensorflow_probability
  from tf_agents.policies import tf_policy
  from tf_agents.policies import utils
  from tf_agents.specs import bandit_spec_utils
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.typing import types
label_desc: Use image node_id 1 to create a new RankingPolicy object from inherited base classes: tf_policy with example: obj = RankingPolicy(num_items, num_slots, time_step_spec, network, item_sampler, penalty_mixture_coefficient, logits_temperature, name)