code: def link_func(predictions, link, link_param=np.nan):
      """Applies the link function to predictions to generate scores.
  
      Args:
          predictions: Numpy array of predictions for samples.
          link: string containing the type of link function to use
          link_param: Optional. numeric parameter that is specified by the link function.
  
      Returns:
          Scores converted by the link function.
      """
  
      # For handling classification in the the link_func, the rule is that the last
      # dimension needs to be an array that contains the probabilities for 1 sample.
      # For "logit", if we treated an array of three values [0.75, 0.75, 0.75] as 3
      # samples, then it would be ambiguous when we recieve values like [0.75, 0.25]
      # whether this was meant to be 2 samples or the False/True probabilities for 1
      # sample. We handle monoclassification and multiclass in the same way.
  
      predictions = np.array(predictions, np.float64, copy=False)
      if link == "monoclassification":
          if predictions.ndim == 0:
              if predictions == 1.0:
                  return -np.inf
              elif np.isnan(predictions):
                  return np.nan
              else:
                  msg = "monoclassification with 1 element must be 1.0 or NaN"
                  _log.error(msg)
                  raise ValueError(msg)
          scores = np.full(predictions.shape[:-1], -np.inf, np.float64)
          if 1 == predictions.shape[-1]:
              predictions = predictions.squeeze(-1)
              bools = np.isnan(predictions)
              scores[bools] = np.nan
              bools |= predictions == 1.0
              if not bools.all():
                  msg = "monoclassification with 1 element must have all 1.0s or NaN"
                  _log.error(msg)
                  raise ValueError(msg)
          elif 0 != predictions.shape[-1]:
              msg = f"predictions must have 1 element in the last dimensions, but has {predictions.shape[-1]}."
              _log.error(msg)
              raise ValueError(msg)
          return scores
      elif link == "logit":
          if predictions.ndim == 0:
              val = predictions
          elif predictions.shape[-1] == 1:
              val = predictions.squeeze(-1)
          elif predictions.shape[-1] == 2:
              val = predictions[..., 1]
              val /= predictions.sum(axis=-1)
          else:
              msg = f"predictions must have 1 or 2 elements in the last dimensions, but has {predictions.shape[-1]}."
              _log.error(msg)
              raise ValueError(msg)
  
          with np.errstate(divide="ignore"):
              # val == 1.0 and val == 0.0 gives warning otherwise
              val /= 1.0 - val
              np.log(val, out=val)
          if val.ndim == 0:
              val = val.item()
  
          return val
      elif link == "vlogit":
          if predictions.shape[-1] <= 1:
              msg = f"predictions must have 2 or more elements in the last dimensions, but has {predictions.shape[-1]}."
              _log.error(msg)
              raise ValueError(msg)
  
          val = 1.0 - predictions
          with np.errstate(divide="ignore"):
              # val == 0.0 and log(0.0) gives warning otherwise
              np.divide(predictions, val, out=val)
              np.log(val, out=val)
  
          return val
      elif link == "mlogit":
          # accept multinominal with 2 classes, even though it's weird
          if predictions.shape[-1] <= 1:
              msg = f"predictions must have 2 or more elements in the last dimensions, but has {predictions.shape[-1]}."
              _log.error(msg)
              raise ValueError(msg)
  
          val = predictions / predictions.max(axis=-1, keepdims=True)
          with np.errstate(divide="ignore"):
              # log(0.0) gives warning otherwise
              np.log(val, out=val)
  
          return val
      elif link == "identity":
          return predictions.copy()
      elif link == "log":
          with np.errstate(divide="ignore"):
              # log(0.0) gives warning otherwise
              return np.log(predictions)
      else:
          raise ValueError(f"Unsupported link function: {link}")
  
imports: import numpy
  import logging
label_desc: Use image node_id 2 for calling a global function with example usage: link_func(predictions, link, link_param) and returns: scores, val, unknown, val, np, val, predictions, np