class_docstr: Base Class for implementing AdaptiveModel with frameworks like PyTorch and ONNX.
class_docstr_tok: ["Base","Class","for","implementing","AdaptiveModel","with","frameworks","like","PyTorch","and","ONNX","."]
docstr: Format predictions to strings for inference output
  
  :param logits: model logits
  :type logits: torch.tensor
  :param kwargs: placeholder for passing generic parameters
  :type kwargs: object
  :return: predictions in the right format
docstr_tok: ["Format","predictions","to","strings","for","inference","output",":","param","logits",":","model","logits",":","type","logits",":","torch.tensor",":","param","kwargs",":","placeholder","for","passing","generic","parameters",":","type","kwargs",":","object",":","return",":","predictions","in","the","right","format"]
code: def formatted_preds(
      self, logits, language_model1, language_model2, **kwargs
  ):
      """
      Format predictions to strings for inference output
  
      :param logits: model logits
      :type logits: torch.tensor
      :param kwargs: placeholder for passing generic parameters
      :type kwargs: object
      :return: predictions in the right format
      """
      n_heads = len(self.prediction_heads)
  
      if n_heads == 1:
          preds_final = []
          # This try catch is to deal with the fact that sometimes we collect preds before passing it to
          # formatted_preds (see Inferencer._get_predictions_and_aggregate()) and sometimes we don't
          # (see Inferencer._get_predictions())
          try:
              preds = kwargs["preds"]
              temp = [y[0] for y in preds]
              preds_flat = [
                  item for sublist in temp for item in sublist
              ]
              kwargs["preds"] = preds_flat
          except KeyError:
              kwargs["preds"] = None
          head = self.prediction_heads[0]
          logits_for_head = logits[0]
          preds = head.formatted_preds(logits=logits_for_head, **kwargs)
          # TODO This is very messy - we need better definition of what the output should look like
          if type(preds) == list:
              preds_final += preds
          elif type(preds) == dict and "predictions" in preds:
              preds_final.append(preds)
      return preds_final
  
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 5 for calling the BaseBiAdaptiveModel obj's underlying member method code with example usage: obj.formatted_preds(logits, language_model1, language_model2) and returns: preds_final