code: def get_logits_training(
      self,
      decoder_output,  # inference: (beam_size, 1, repr_dim)
      target_ids,  # (beam_size, seq_len, )
      lr_pair_flag=None,
      rr_pair_flag=None,
      labels=None,
  ):
      batch_size, seq_len = decoder_output.size(0), decoder_output.size(
          1
      )
      target_mask = target_ids != self.config.pad_token_id
      # (batch_size, seq_len) indices of tokens
      linearized_indices = (labels >= 0).cumsum(dim=-1) - 1
      # (batch_size, seq_len) bool mask: special tokens
      is_l = target_ids == self.mention_start_id
      is_r = target_ids == self.mention_end_id
  
      if is_r.sum() == 0:  # dummy loss, all actions should be <copy>
          numer = torch.full_like(decoder_output[..., :1], NEGINF)
          denom = torch.full_like(decoder_output[..., :1], NEGINF)
          rr_loss = torch.zeros_like(denom)
  
          return numer, denom, rr_loss
  
      # (batch_size, num_r / num_l) indices of special tokens
      (r_pos, r_pos_mask) = batched_masked_select(
          linearized_indices, is_r
      )
      (l_pos, l_pos_mask) = batched_masked_select(
          linearized_indices, is_l
      )
  
      # (batch_size, num_r / num_l, hidden_dim) embeddings of special tokens
      r_emb, _ = batched_masked_select(decoder_output, is_r)
      l_emb, _ = batched_masked_select(decoder_output, is_l)
  
      # (batch_size, seq_len, num_r / num_l)
      distance_to_previous_r = linearized_indices.unsqueeze(
          2
      ) - r_pos.unsqueeze(1)
      distance_to_previous_l = linearized_indices.unsqueeze(
          2
      ) - l_pos.unsqueeze(1)
      # (batch_size, seq_len, num_r / num_l)
      is_after_r = distance_to_previous_r > 0
      is_after_l = distance_to_previous_l > 0
      # bool mask: is the token after a special token?
      is_after_r = (
          is_after_r
          & target_mask.unsqueeze(2)
          & r_pos_mask.unsqueeze(1)
      )
      is_after_l = (
          is_after_l
          & target_mask.unsqueeze(2)
          & l_pos_mask.unsqueeze(1)
      )
  
      # (batch_size, num_r, num_r) picking r for rr classification
      kept_is_after_r, _ = batched_masked_select(is_after_r, is_r)
      kept_is_after_r = (
          kept_is_after_r
          & r_pos_mask.unsqueeze(2)
          & r_pos_mask.unsqueeze(1)
      )
  
      # ontonotes maximum lookahead
      # [Alice], [Bob], and [Charlie]]: lookahead = 3
      kept_l = min(16, l_emb.size(1))
  
      # keeping the nearest-kept_l left brackets
      # (batch_size, seq_len, kept_l)
      _, prev_l_indices = (
          -distance_to_previous_l + (is_after_l * 10000)
      ).topk(kept_l, dim=2)
  
      # selecting the corresponding embeddings
      # (batch_size, seq_len, kept_l, hidden_dim)
      kept_l_emb = util.batch_select(l_emb, prev_l_indices)
      # expanding the embeddings to match the number of kept_l length
      # (batch_size, seq_len, kept_l, hidden_dim)
      expanded_decoder_output = decoder_output.unsqueeze(2).expand(
          -1, -1, kept_l, -1
      )
      # (batch_size, seq_len, kept_l, 2*hidden_dim)
      lr_pair_emb = torch.cat(
          [kept_l_emb, expanded_decoder_output], dim=-1
      )
      # the current token should be after the left bracket
      # (batch_size, seq_len, kept_l)
      kept_is_after_l = util._batched_index_select(
          is_after_l, prev_l_indices, dim=2
      )
      # (batch_size, seq_len, kept_l)
      lr_score = (
          self.lr_scorer(lr_pair_emb).squeeze(-1)
          + (~kept_is_after_l) * NEGINF
      )
      # (batch_size, seq_len, 1)
      lr_denom = logsumexp(
          lr_score, dim=2, keepdim=True
      ) * is_after_l.any(dim=2, keepdim=True)
      # (batch_size, seq_len, num_l) -> (batch_size, seq_len, kept_l)
      kept_lr_pair_flag = util._batched_index_select(
          lr_pair_flag, prev_l_indices, dim=2
      )
      # (batch_size, seq_len, 1)
      lr_numer = logsumexp(
          lr_score + (~kept_lr_pair_flag) * NEGINF, dim=2, keepdim=True
      ) * is_after_l.any(dim=2, keepdim=True)
  
      # (batch_size, num_r, num_r, 2*dim)
      rr_pair_emb = prepare_pair_embeddings(r_emb, r_emb)
      # (batch_size, num_r, num_r, dim)
      r_distance_emb = self.emb_rr_distance(
          util.relative_position_bucket(
              batched_masked_select(-distance_to_previous_r, is_r)[0],
              bidirectional=False,
              num_buckets=self.linking_distance_num_buckets,
          )
      )
      rr_pair_emb = torch.cat([rr_pair_emb, r_distance_emb], dim=-1)
  
      # (batch_size, num_r, num_r)
      rr_score = (
          self.rr_scorer(rr_pair_emb).squeeze(-1)
          + (~kept_is_after_r) * NEGINF
      )
  
      # padding labels for first-in-a-cluster mentions
      # (batch_size, seq_len, 1+num_r)
      rr_pair_flag = torch.cat(
          [~(rr_pair_flag.any(dim=-1, keepdim=True)), rr_pair_flag],
          dim=-1,
      )
      # (batch_size, num_r, 1+num_r)
      rr_pair_flag, _ = batched_masked_select(rr_pair_flag, is_r)
  
      # padding zero for first-in-a-cluster mentions
      # (batch_size, num_r, 1+num_r)
      rr_score = dummy_padding(rr_score)
      # (batch_size, num_r, 1)
      rr_denom = logsumexp(rr_score, dim=-1, keepdim=True)
      rr_numer = logsumexp(
          rr_score + (~rr_pair_flag) * (NEGINF), dim=-1, keepdim=True
      )
  
      numer, denom = lr_numer, lr_denom
      rr_loss = (rr_denom - rr_numer) * r_pos_mask.unsqueeze(-1)
  
      return numer, denom, rr_loss
  
imports: import sys
  import os
  from typing import Optional, Tuple, Any, Dict, Iterable
  import logging
  import torch
  import torch.utils.checkpoint
  from torch import nn
  import torch.nn.init
  import torch.nn.functional
  from transformers.models.t5.modeling_t5 import T5PreTrainedModel, T5Model, T5_INPUTS_DOCSTRING, _CONFIG_FOR_DOC
  from transformers.file_utils import add_start_docstrings_to_model_forward, replace_return_docstrings
  from .modeling_outputs import MySeq2SeqLMOutput
  from util import logsumexp, dummy_padding, prepare_pair_embeddings, one_hot_ignore_negative, batched_masked_select
label_desc: Use image node_id 4 for calling the T5Coref obj's underlying member method code with example usage: obj.get_logits_training(decoder_output, target_ids, lr_pair_flag, rr_pair_flag, labels) and returns: numer,  denom,  rr_loss, numer,  denom,  rr_loss