docstr: :param eval_greedy: If True, evaluate the greedy policy which
  always picks the most probable output sequence. If False, evaluate
   the stochastic ranking policy.
docstr_tok: [":","param","eval_greedy",":","If","True",",","evaluate","the","greedy","policy","which","always","picks","the","most","probable","output","sequence",".","If","False",",","evaluate","the","stochastic","ranking","policy","."]
code: def create_from_tensors_seq2slate(
      cls,
      seq2slate_net: Seq2SlateTransformerNet,
      reward_network: nn.Module,
      training_input: rlt.PreprocessedRankingInput,
      eval_greedy: bool,
      mdp_ids: Optional[torch.Tensor] = None,
      sequence_numbers: Optional[torch.Tensor] = None,
  ):
      """
      :param eval_greedy: If True, evaluate the greedy policy which
      always picks the most probable output sequence. If False, evaluate
       the stochastic ranking policy.
      """
      assert (
          training_input.slate_reward is not None
          and training_input.tgt_out_probs is not None
          and training_input.tgt_out_idx is not None
          and training_input.tgt_out_seq is not None
      )
      (
          batch_size,
          tgt_seq_len,
          candidate_dim,
      ) = training_input.tgt_out_seq.float_features.shape
      device = training_input.state.float_features.device
  
      rank_output = seq2slate_net(
          training_input, Seq2SlateMode.RANK_MODE, greedy=True
      )
      assert rank_output.ranked_tgt_out_idx is not None
      if eval_greedy:
          model_propensities = torch.ones(batch_size, 1, device=device)
          action_mask = torch.all(
              # pyre-fixme[58]: `-` is not supported for operand types
              #  `Optional[torch.Tensor]` and `int`.
              # pyre-fixme[6]: For 1st param expected `Tensor` but got `bool`.
              (training_input.tgt_out_idx - 2)
              == (rank_output.ranked_tgt_out_idx - 2),
              dim=1,
              keepdim=True,
          ).float()
      else:
          # Fully evaluating a non-greedy ranking model is too expensive because
          # we would need to compute propensities of all possible output sequences.
          # Here we only compute the propensity of the output sequences in the data.
          # As a result, we can still get a true IPS estimation but not correct
          # direct method / doubly-robust.
          model_propensities = torch.exp(
              seq2slate_net(
                  training_input, Seq2SlateMode.PER_SEQ_LOG_PROB_MODE
              ).log_probs
          )
          action_mask = torch.ones(batch_size, 1, device=device).float()
  
      model_rewards_for_logged_action = reward_network(
          training_input.state.float_features,
          training_input.src_seq.float_features,
          # pyre-fixme[16]: `Optional` has no attribute `float_features`.
          training_input.tgt_out_seq.float_features,
          training_input.src_src_mask,
          training_input.tgt_out_idx,
      ).reshape(-1, 1)
  
      ranked_tgt_out_seq = training_input.src_seq.float_features[
          torch.arange(batch_size, device=device).repeat_interleave(
              tgt_seq_len
          ),
          rank_output.ranked_tgt_out_idx.flatten() - 2,
      ].reshape(batch_size, tgt_seq_len, candidate_dim)
      # model_rewards refers to predicted rewards for the slate generated
      # greedily by the ranking model. It would be too expensive to
      # compute model_rewards for all possible slates
      model_rewards = reward_network(
          training_input.state.float_features,
          training_input.src_seq.float_features,
          ranked_tgt_out_seq,
          training_input.src_src_mask,
          rank_output.ranked_tgt_out_idx,
      ).reshape(-1, 1)
      # pyre-fixme[16]: `Optional` has no attribute `reshape`.
      logged_rewards = training_input.slate_reward.reshape(-1, 1)
      logged_propensities = training_input.tgt_out_probs.reshape(-1, 1)
      return cls(
          mdp_id=mdp_ids,
          sequence_number=sequence_numbers,
          model_propensities=model_propensities,
          model_rewards=model_rewards,
          action_mask=action_mask,
          logged_rewards=logged_rewards,
          model_rewards_for_logged_action=model_rewards_for_logged_action,
          logged_propensities=logged_propensities,
      )
  
imports: from __future__ import annotations
  import logging
  import math
  from dataclasses import dataclass, fields
  from typing import cast, Optional, TYPE_CHECKING
  import numpy
  import torch
  import torch.nn
  from reagent.core import types
  from reagent.core.torch_utils import masked_softmax
  from reagent.model_utils.seq2slate_utils import Seq2SlateMode
  from reagent.models.seq2slate import Seq2SlateTransformerNet
label_desc: Use image node_id 2 for calling the EvaluationDataPage obj's underlying member method code with example usage: obj.create_from_tensors_seq2slate(cls, seq2slate_net, reward_network, training_input, eval_greedy, mdp_ids, sequence_numbers) and returns: cls