docstr: Sample a ranking according to Frechet sort. Note that possible_actions_mask
  is ignored as the list of rankings scales exponentially with slate size and
  number of items and it can be difficult to enumerate them.
docstr_tok: ["Sample","a","ranking","according","to","Frechet","sort",".","Note","that","possible_actions_mask","is","ignored","as","the","list","of","rankings","scales","exponentially","with","slate","size","and","number","of","items","and","it","can","be","difficult","to","enumerate","them","."]
code: def sample_action(self, scores: torch.Tensor) -> rlt.ActorOutput:
      """Sample a ranking according to Frechet sort. Note that possible_actions_mask
      is ignored as the list of rankings scales exponentially with slate size and
      number of items and it can be difficult to enumerate them."""
      assert scores.dim() == 2, "sample_action only accepts batches"
      log_scores = scores if self.log_scores else torch.log(scores)
      perturbed = log_scores + self.gumbel_noise.sample(scores.shape)
      action = torch.argsort(perturbed.detach(), descending=True)
      log_prob = self.log_prob(scores, action)
      # Only truncate the action before returning
      if self.topk is not None:
          action = action[: self.topk]
      return rlt.ActorOutput(action, log_prob)
  
file_path: ReAgent/reagent/samplers/frechet.py
imports: import logging
  import math
  from typing import Optional
  import reagent.core.types
  import torch
  import torch.nn.functional
  from reagent.core.configuration import resolve_defaults
  from reagent.gym.types import Sampler
  from torch.distributions import Gumbel
label_desc: Use image node_id 2 for calling the FrechetSort obj's underlying member method code with example usage: obj.sample_action(scores) and returns: rlt