title: How can one add batch mechanism to the input function in Tensorflow tutorial overcoming tf.Sparsetensor objects?
body: <p>How can one add <code>batch</code> mechanism to the <code>input_fn</code> in the <a href="https://www.tensorflow.org/tutorials/wide_and_deep" rel="nofollow noreferrer">TensorFlow Wide &amp; Deep Learning Tutorial</a> overcoming that some features are represented as <code>tf.Sparsetensor</code> objects?</p>
  
  <p>I have made many attempts around adding <code>tf.train.slice_input_producer</code> and <code>tf.train.batch</code>to the original code (see below), but have failed miserably so far.</p>
  
  <p>I would like to keep the global working of that input_fn as it is handy while while training and evaluating the model.</p>
  
  <p>Can someone help, please?</p>
  
  <pre><code>def input_fn(df):
      # Creates a dictionary mapping from each continuous feature column name (k) to
      # the values of that column stored in a constant Tensor.
      continuous_cols = {k: tf.constant(df[k].values)
                         for k in CONTINUOUS_COLUMNS}
      # Creates a dictionary mapping from each categorical feature column name (k)
      # to the values of that column stored in a tf.SparseTensor.
      categorical_cols = {k: tf.SparseTensor(indices=[[i, 0] for i in range(df[k].size)],
                                             values=df[k].values,
                                             shape=[df[k].size, 1]) for k in CATEGORICAL_COLUMNS}
  
      # Merges the two dictionaries into one.
      feature_cols = dict(continuous_cols.items() + categorical_cols.items())
      # Converts the label column into a constant Tensor.
      labels = tf.constant(df[LABEL_COLUMN].values)
  
      '''
      Changes from here: 
      '''
      features_slices, features_slices = tf.train.slice_input_producer([features_cols, labels], ...)
  
      features_batches, labels_batches =  tf.train.batch([features_slices, features_slices], ...)
  
      # Returns the feature and label batches.
      return features_batches, labels_batches
  </code></pre>