code: def transform_to_shard_dict(data, feature_cols, label_cols=None):
      def single_col_to_numpy(col_series, dtype):
          if dtype == np.ndarray:
              # In this case, directly calling to_numpy will make the result
              # ndarray have type np.object.
              # Need to explicitly specify the dtype.
              dtype = col_series.iloc[0].dtype
              return np.array(
                  [i.tolist() for i in col_series], dtype=dtype
              )
          else:
              return col_series.to_numpy()
  
      def to_shard_dict(df):
          result = dict()
          col_types = df.dtypes
          if len(feature_cols) == 1:
              featureLists = df[feature_cols[0]].tolist()
              result["x"] = np.stack(featureLists, axis=0)
          else:
              result["x"] = [
                  single_col_to_numpy(
                      df[feature_col], col_types[feature_col]
                  )
                  for feature_col in feature_cols
              ]
  
          if label_cols:
              y = [
                  single_col_to_numpy(
                      df[label_col], col_types[label_col]
                  )
                  for label_col in label_cols
              ]
              if len(label_cols) == 1:
                  y = y[0]
              result["y"] = y
  
          return result
  
      data = data.transform_shard(to_shard_dict)
      data._set_class_name("builtins.dict")
      return data
  
imports: from contextlib import closing
  import socket
  import sys
  import tempfile
  import shutil
  from bigdl.dllib.utils import log4Error
  from bigdl.dllib.utils.common import callBigDlFunc
  from bigdl.dllib.utils.file_utils import get_file_list, is_local_path
  from bigdl.orca.data import SparkXShards
  from bigdl.orca.data.utils import get_size
  from bigdl.orca.data.file import put_local_dir_tree_to_remote, put_local_file_to_remote, get_remote_file_to_local, get_remote_dir_to_local
  from bigdl.dllib.utils.utils import convert_row_to_numpy
  from functools import partial
  import numpy
  from bigdl.orca.common import SafePickle
  import os
  import subprocess
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 15 for calling a global function with example usage: transform_to_shard_dict(data, feature_cols, label_cols) and returns: data, result, np, col_series