class_docstr: Credit: G. Glavaš & I. Vulić Based on paper "Is Supervised Syntactic Parsing Beneficial for Language Understanding?
  An Empirical Investigation" (https://arxiv.org/pdf/2008.06788.pdf)
code: def _get_loss(
      self, arc_preds, rel_preds, labels_arc, labels_rel, loss_fn
  ):
      if labels_arc is None or labels_rel is None:
          return None
      if len(arc_preds.shape) == 2:
          arc_preds = arc_preds.unsqueeze(0)
  
      mask = labels_arc.ne(self.model_config.pad_token_id)
      arc_scores, arcs = arc_preds[mask], labels_arc[mask]
      loss = loss_fn(arc_scores, arcs)
  
      rel_scores, rels = rel_preds[mask], labels_rel[mask]
      rel_scores = rel_scores[torch.arange(len(arcs)), arcs]
      rel_loss = loss_fn(rel_scores, rels)
      loss += rel_loss
  
      return loss
  
imports: from dataclasses import dataclass
  from typing import Optional, Tuple
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from transformers.utils import ModelOutput
  from .base import PredictionHead
label_desc: Use image node_id 5 for calling the BiaffineParsingHead obj's underlying member method code with example usage: obj._get_loss(arc_preds, rel_preds, labels_arc, labels_rel, loss_fn) and returns: loss, None