code: def per_symbol_to_per_seq_log_probs(
      per_symbol_log_probs, tgt_out_idx
  ):
      """Gather per-symbol log probabilities into per-seq log probabilities"""
      # per_symbol_log_probs shape: batch_size, seq_len, candidate_size
      # tgt_out_idx shape: batch_size, seq_len
      # per_symbol_log_probs is log probability of each symbol in the tgt_out_idx
      # shape: batch_size, seq_len
      log_probs = torch.gather(
          per_symbol_log_probs, 2, tgt_out_idx.unsqueeze(2)
      ).squeeze(2)
      # shape: batch_size, 1
      return log_probs.sum(dim=1, keepdim=True)
  
imports: import copy
  import logging
  import math
  from enum import Enum
  import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 7 for calling a global function with example usage: per_symbol_to_per_seq_log_probs(per_symbol_log_probs, tgt_out_idx) and returns: log_probs