class_docstr: PyTorch implementation containing all the modelling needed for your NLP task. Combines 2 language
  models for representation of 2 sequences and a prediction head. Allows for gradient flow back to the 2 language model components.
class_docstr_tok: ["PyTorch","implementation","containing","all","the","modelling","needed","for","your","NLP","task",".","Combines","2","language","models","for","representation","of","2","sequences","and","a","prediction","head",".","Allows","for","gradient","flow","back","to","the","2","language","model","components","."]
docstr: Collect losses from each prediction head.
  
  :param logits: logits, can vary in shape and type, depending on task.
  :type logits: object
  :return: The per sample per prediciton head loss whose first two dimensions have length n_pred_heads, batch_size
docstr_tok: ["Collect","losses","from","each","prediction","head",".",":","param","logits",":","logits",",","can","vary","in","shape","and","type",",","depending","on","task",".",":","type","logits",":","object",":","return",":","The","per","sample","per","prediciton","head","loss","whose","first","two","dimensions","have","length","n_pred_heads",",","batch_size"]
code: def logits_to_loss_per_head(self, logits, **kwargs):
      """
      Collect losses from each prediction head.
  
      :param logits: logits, can vary in shape and type, depending on task.
      :type logits: object
      :return: The per sample per prediciton head loss whose first two dimensions have length n_pred_heads, batch_size
      """
      all_losses = []
      for head, logits_for_one_head in zip(
          self.prediction_heads, logits
      ):
          # check if PredictionHead connected to Processor
          assert hasattr(head, "label_tensor_name"), (
              f"Label_tensor_names are missing inside the {head.task_name} Prediction Head. Did you connect the model"
              " with the processor through either 'model.connect_heads_with_processor(processor.tasks)'"
              " or by passing the processor to the Adaptive Model?"
          )
          all_losses.append(
              head.logits_to_loss(logits=logits_for_one_head, **kwargs)
          )
      return all_losses
  
imports: import copy
  import json
  import logging
  import os
  from argparse import Namespace
  from pathlib import Path
  import multiprocessing
  import numpy
  import torch
  from torch import nn
  from farm.data_handler.processor import TextSimilarityProcessor
  from farm.data_handler.data_silo import DataSilo
  from farm.modeling.language_model import LanguageModel
  from farm.modeling.prediction_head import PredictionHead, TextSimilarityHead
  from farm.modeling.tokenization import Tokenizer
  from farm.utils import MLFlowLogger, stack
label_desc: Use image node_id 4 for calling the BiAdaptiveModel obj's underlying member method code with example usage: obj.logits_to_loss_per_head(logits) and returns: all_losses