code: def _rearrange_output(logit, pred):
      """
      Rearrange the word logits so that the decoded word has the highest valued
      logits by swapping the indices predicted with those with maximum logits.
      """
      max_logits, max_logit_indices = torch.max(logit, 2, keepdim=True)
      pred_indices = pred.unsqueeze(2)
      pred_logits = torch.gather(logit, 2, pred_indices)
      logit_rearranged = logit.scatter(2, pred_indices, max_logits)
      logit_rearranged.scatter_(2, max_logit_indices, pred_logits)
      return logit_rearranged
  
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  import torch.jit
  import torch.nn
  import torch.nn.functional
  from caffe2.python import core
  from pytext.common import Padding
  from pytext.config.component import create_loss
  from pytext.config.serialize import MissingValueError
  from pytext.data.utils import Vocabulary
  from pytext.loss import AUCPRHingeLoss, BinaryCrossEntropyLoss, CrossEntropyLoss, KLDivergenceBCELoss, KLDivergenceCELoss, LabelSmoothedCrossEntropyLoss, StructuredLoss, StructuredMarginLoss
  from pytext.models.crf import CRF
  from pytext.utils.label import get_label_weights
  from pytext.utils.usage import log_class_usage
  from .output_layer_base import OutputLayerBase
  from .utils import OutputLayerUtils
label_desc: Use image node_id 1 for calling a global function with example usage: _rearrange_output(logit, pred) and returns: logit_rearranged