code: def cat_batches(
      data: DefaultDict[str, Union[torch.Tensor, np.ndarray]]
  ) -> DefaultDict[str, Union[torch.Tensor, np.ndarray]]:
      """Concatenates output data from several batches
  
      Args:
          data: dict with keys and list of batch outputs
  
      Returns:
          Concatenated dict
  
      """
  
      for key, value in data.items():
          if len(value[0].shape) == 0:
              if isinstance(value[0], torch.Tensor):
                  data[key] = torch.stack(value)
              else:
                  data[key] = np.stack(value)
          else:
              if isinstance(value[0], torch.Tensor):
                  data[key] = torch.cat(value, dim=0)
              else:
                  data[key] = np.concatenate(value, axis=0)
  
      return data
  
imports: import logging
  import math
  import os
  from typing import Any, DefaultDict, Dict, List, Optional, Tuple, Union, no_type_check
  import networkx
  import numpy
  import pandas
  import pyarrow.parquet
  import torch
  from sklearn.model_selection import GroupShuffleSplit, train_test_split
  from torch import distributed
  from torch.utils.data import DataLoader, Sampler, SequentialSampler
  from llm_studio.src.datasets.conversation_chain_handler import ConversationChainHandler
  from llm_studio.src.utils.exceptions import LLMDataException
  from llm_studio.src.utils.utils import PatchedAttribute, set_seed
label_desc: Use image node_id 15 for calling a global function with example usage: cat_batches(data) and returns: data