docstr: Constructs a FATE DataFrame from predictions and labels. This Dataframe is able to flow through FATE components.
  
  Parameters:
      ctx (Context): The Context Instance.
      predictions (Union[np.ndarray, torch.Tensor, DataFrame, PredictionOutput]): The model's predictions, which can be numpy arrays, torch tensors, pandas DataFrames, or PredictionOutputs.
      labels (Union[np.ndarray, torch.Tensor, DataFrame, PredictionOutput]): The true labels, which can be numpy arrays, torch tensors, pandas DataFrames, or PredictionOutputs.
      match_ids (Union[pd.DataFrame, np.ndarray], optional): Match IDs, if applicable. Defaults to None. If None, will auto generate match_ids.
      sample_ids (Union[pd.DataFrame, np.ndarray], optional): Sample IDs, if applicable. Defaults to None. If None, will auto generate sample_ids.
      match_id_name (str, optional): Column name for match IDs in the resulting DataFrame. If None, Defaults to 'id'.
      sample_id_name (str, optional): Column name for sample IDs in the resulting DataFrame. If None, Defaults to 'sample_id'.
      dataframe_format (Literal['default', 'fate_std'], optional): Output format of the resulting DataFrame. If 'default', simply combines labels and predictions into a DataFrame.
                                                                   If 'fate_std', organizes output according to the FATE framework's format. Defaults to 'default'.
      task_type (Literal['binary', 'multi', 'regression', 'others'], optional):  This parameter is only needed when dataframe_format is 'fate_std'. Defaults to None.
                                                                                 The type of machine learning task, which can be 'binary', 'multi', 'regression', or 'others'.
      threshold (float, optional): This parameter is only needed when dataframe_format is 'fate_std' and task_type is 'binary'. Defaults to 0.5.
      classes (list, optional): This parameter is only needed when dataframe_format is 'fate_std'. List of classes.
  Returns:
      DataFrame: A DataFrame that contains the neural network's predictions and the true labels, possibly along with match IDs and sample IDs, formatted according to the specified format.
docstr_tok: ["Constructs","a","FATE","DataFrame","from","predictions","and","labels",".","This","Dataframe","is","able","to","flow","through","FATE","components",".","Parameters",":","ctx","(","Context",")",":","The","Context","Instance",".","predictions","(","Union","[","np.ndarray",",","torch.Tensor",",","DataFrame",",","PredictionOutput","]",")",":","The","model","'s","predictions",",","which","can","be","numpy","arrays",",","torch","tensors",",","pandas","DataFrames",",","or","PredictionOutputs",".","labels","(","Union","[","np.ndarray",",","torch.Tensor",",","DataFrame",",","PredictionOutput","]",")",":","The","true","labels",",","which","can","be","numpy","arrays",",","torch","tensors",",","pandas","DataFrames",",","or","PredictionOutputs",".","match_ids","(","Union","[","pd.DataFrame",",","np.ndarray","]",",","optional",")",":","Match","IDs",",","if","applicable",".","Defaults","to","None",".","If","None",",","will","auto","generate","match_ids",".","sample_ids","(","Union","[","pd.DataFrame",",","np.ndarray","]",",","optional",")",":","Sample","IDs",",","if","applicable",".","Defaults","to","None",".","If","None",",","will","auto","generate","sample_ids",".","match_id_name","(","str",",","optional",")",":","Column","name","for","match","IDs","in","the","resulting","DataFrame",".","If","None",",","Defaults","to","'id","'",".","sample_id_name","(","str",",","optional",")",":","Column","name","for","sample","IDs","in","the","resulting","DataFrame",".","If","None",",","Defaults","to","'sample_id","'",".","dataframe_format","(","Literal","[","'default","'",",","'fate_std","'","]",",","optional",")",":","Output","format","of","the","resulting","DataFrame",".","If","'default","'",",","simply","combines","labels","and","predictions","into","a","DataFrame",".","If","'fate_std","'",",","organizes","output","according","to","the","FATE","framework","'s","format",".","Defaults","to","'default","'",".","task_type","(","Literal","[","'binary","'",",","'multi","'",",","'regression","'",",","'others","'","]",",","optional",")",":","This","parameter","is","only","needed","when","dataframe_format","is","'fate_std","'",".","Defaults","to","None",".","The","type","of","machine","learning","task",",","which","can","be","'binary","'",",","'multi","'",",","'regression","'",",","or","'others","'",".","threshold","(","float",",","optional",")",":","This","parameter","is","only","needed","when","dataframe_format","is","'fate_std","'","and","task_type","is","'binary","'",".","Defaults","to","0.5.","classes","(","list",",","optional",")",":","This","parameter","is","only","needed","when","dataframe_format","is","'fate_std","'",".","List","of","classes",".","Returns",":","DataFrame",":","A","DataFrame","that","contains","the","neural","network","'s","predictions","and","the","true","labels",",","possibly","along","with","match","IDs","and","sample","IDs",",","formatted","according","to","the","specified","format","."]
code: def get_nn_output_dataframe(
      self,
      ctx,
      predictions: Union[
          np.ndarray, torch.Tensor, DataFrame, PredictionOutput
      ],
      labels: Union[
          np.ndarray, torch.Tensor, DataFrame, PredictionOutput
      ] = None,
      match_ids: Union[pd.DataFrame, np.ndarray] = None,
      sample_ids: Union[pd.DataFrame, np.ndarray] = None,
      match_id_name: str = None,
      sample_id_name: str = None,
      dataframe_format: Literal["default", "fate_std"] = "default",
      task_type: Literal[
          "binary", "multi", "regression", "others"
      ] = None,
      threshold: float = 0.5,
      classes: list = None,
  ) -> DataFrame:
      """
      Constructs a FATE DataFrame from predictions and labels. This Dataframe is able to flow through FATE components.
  
      Parameters:
          ctx (Context): The Context Instance.
          predictions (Union[np.ndarray, torch.Tensor, DataFrame, PredictionOutput]): The model's predictions, which can be numpy arrays, torch tensors, pandas DataFrames, or PredictionOutputs.
          labels (Union[np.ndarray, torch.Tensor, DataFrame, PredictionOutput]): The true labels, which can be numpy arrays, torch tensors, pandas DataFrames, or PredictionOutputs.
          match_ids (Union[pd.DataFrame, np.ndarray], optional): Match IDs, if applicable. Defaults to None. If None, will auto generate match_ids.
          sample_ids (Union[pd.DataFrame, np.ndarray], optional): Sample IDs, if applicable. Defaults to None. If None, will auto generate sample_ids.
          match_id_name (str, optional): Column name for match IDs in the resulting DataFrame. If None, Defaults to 'id'.
          sample_id_name (str, optional): Column name for sample IDs in the resulting DataFrame. If None, Defaults to 'sample_id'.
          dataframe_format (Literal['default', 'fate_std'], optional): Output format of the resulting DataFrame. If 'default', simply combines labels and predictions into a DataFrame.
                                                                       If 'fate_std', organizes output according to the FATE framework's format. Defaults to 'default'.
          task_type (Literal['binary', 'multi', 'regression', 'others'], optional):  This parameter is only needed when dataframe_format is 'fate_std'. Defaults to None.
                                                                                     The type of machine learning task, which can be 'binary', 'multi', 'regression', or 'others'.
          threshold (float, optional): This parameter is only needed when dataframe_format is 'fate_std' and task_type is 'binary'. Defaults to 0.5.
          classes (list, optional): This parameter is only needed when dataframe_format is 'fate_std'. List of classes.
      Returns:
          DataFrame: A DataFrame that contains the neural network's predictions and the true labels, possibly along with match IDs and sample IDs, formatted according to the specified format.
      """
      # check parameters
      assert task_type in [
          BINARY,
          MULTI,
          REGRESSION,
          OTHER,
      ], f"task_type {task_type} is not supported"
      assert dataframe_format in [
          "default",
          "fate_std",
      ], f"dataframe_format {dataframe_format} is not supported"
  
      if match_id_name is None:
          match_id_name = "id"
      if sample_id_name is None:
          sample_id_name = "sample_id"
  
      if isinstance(predictions, PredictionOutput):
          predictions = predictions.predictions
  
      if labels is not None:
          if isinstance(labels, PredictionOutput):
              labels = labels.label_ids
          predictions = convert_to_numpy_array(predictions)
          labels = convert_to_numpy_array(labels)
          assert len(predictions) == len(
              labels
          ), f"predictions length {len(predictions)} != labels length {len(labels)}"
  
      # check match ids
      if match_ids is not None:
          match_ids = convert_to_numpy_array(match_ids).flatten()
      else:
          logger.info(
              "match_ids is not provided, will auto generate match_ids"
          )
          match_ids = np.array(
              [i for i in range(len(predictions))]
          ).flatten()
  
      # check sample ids
      if sample_ids is not None:
          sample_ids = convert_to_numpy_array(sample_ids).flatten()
      else:
          logger.info(
              "sample_ids is not provided, will auto generate sample_ids"
          )
          sample_ids = np.array(
              [i for i in range(len(predictions))]
          ).flatten()
  
      assert len(match_ids) == len(
          predictions
      ), f"match_ids length {len(match_ids)} != predictions length {len(predictions)}"
      assert len(sample_ids) == len(
          predictions
      ), f"sample_ids length {len(sample_ids)} != predictions length {len(predictions)}"
  
      # match id name and sample id name must be str
      assert isinstance(
          match_id_name, str
      ), f"match_id_name must be str, but got {type(match_id_name)}"
      assert isinstance(
          sample_id_name, str
      ), f"sample_id_name must be str, but got {type(sample_id_name)}"
  
      if dataframe_format == "default" or (
          dataframe_format == "fate_std" and task_type == OTHER
      ):
          df = pd.DataFrame()
          if labels is not None:
              df[LABEL] = labels.to_list()
          df[PREDICT_SCORE] = predictions.to_list()
          df[match_id_name] = match_ids.flatten()
          df[sample_id_name] = sample_ids.flatten()
          df = to_dist_df(ctx, sample_id_name, match_id_name, df)
          return df
      elif dataframe_format == "fate_std" and task_type in [
          BINARY,
          MULTI,
          REGRESSION,
      ]:
          df = array_to_predict_df(
              ctx,
              task_type,
              predictions,
              match_ids,
              sample_ids,
              match_id_name,
              sample_id_name,
              labels,
              threshold,
              classes,
          )
          return df
  
imports: import os
  import torch
  import torch
  import logging
  import numpy
  from torch import optim, nn
  import pandas
  from typing import Literal, Type, Callable
  from fate.ml.nn.trainer.trainer_base import TrainingArguments
  from fate.components.core import Role
  from fate.arch import Context
  from typing import Optional, Union
  from transformers.trainer_utils import PredictionOutput
  from fate.arch.dataframe._dataframe import DataFrame
  from fate.components.components.utils import consts
  from torch.optim.lr_scheduler import _LRScheduler
  from fate.ml.utils.predict_tools import to_dist_df, array_to_predict_df
  from fate.ml.utils.predict_tools import BINARY, MULTI, REGRESSION, OTHER, LABEL, PREDICT_SCORE
  from fate.components.components.nn.loader import Loader
label_desc: Use image node_id 11 for calling the NNRunner obj's underlying member method code with example usage: obj.get_nn_output_dataframe(ctx, predictions, labels, match_ids, sample_ids, match_id_name, sample_id_name, dataframe_format, task_type, threshold, classes) and returns: df, df