code: def batch_to_feeddict(X, y, w, core):
      """Prepare feed dict for session.run() from mini-batch.
      Convert sparse format into tuple (indices, values, shape) for tf.SparseTensor
      Parameters
      ----------
      X : {numpy.array, scipy.sparse.csr_matrix}, shape (batch_size, n_features)
          Training vector, where batch_size in the number of samples and
          n_features is the number of features.
      y : np.array, shape (batch_size,)
          Target vector relative to X.
      core : TFFMCore
          Core used for extract appropriate placeholders
      Returns
      -------
      fd : dict
          Dict with formatted placeholders
      """
      fd = {}
      if core.input_type == "dense":
          fd[core.train_x] = X.astype(np.float32)
      else:
          # sparse case
          X_sparse = X.tocoo()
          fd[core.raw_indices] = np.hstack(
              (X_sparse.row[:, np.newaxis], X_sparse.col[:, np.newaxis])
          ).astype(np.int64)
          fd[core.raw_values] = X_sparse.data.astype(np.float32)
          fd[core.raw_shape] = np.array(X_sparse.shape).astype(np.int64)
  
      if y is not None:
          fd[core.train_y] = y.astype(np.float32)
      if w is not None:
          fd[core.train_w] = w.astype(np.float32)
  
      return fd
  
imports: import tensorflow
  from .core import TFFMCore
  from sklearn.base import BaseEstimator
  from abc import ABCMeta, abstractmethod
  import six
  from tqdm import tqdm
  import numpy
  import os
label_desc: Use image node_id 2 for calling a global function with example usage: batch_to_feeddict(X, y, w, core) and returns: fd