_float_feature = lambda v: tf.train.Feature(float_list=tf.train.FloatList(
    value=v))
_int_feature = lambda v: tf.train.Feature(int64_list=tf.train.Int64List(
    value=v))
indexes = []
values = []
for item in l[start:]:
    index, value = item.split(':')
indexes.append(int(index))
values.append(float(value))
example = tf.train.Example(features=tf.train.Features(feature={'label':
    _int_feature([label]), 'num_features': _int_feature([num_features]),
    'index': _int_feature(indexes), 'value': _float_feature(values)}))
writer.write(example.SerializeToString())

def decode(batch_serialized_examples):
    features = tf.parse_example(batch_serialized_examples, features={
        'label': tf.FixedLenFeature([], tf.int64), 'index': tf.
        VarLenFeature(tf.int64), 'value': tf.VarLenFeature(tf.float32)})
label = features['label']
index = features['index']
value = features['value']
return label, index, value
How to load sparse data with TensorFlow?