def decode_libsvm(line):
    columns = tf.string_split([line], ' ')
    labels = tf.string_to_number(columns.values[0], out_type=tf.float32)
    splits = tf.string_split(columns.values[1:], ':')
    id_vals = tf.reshape(splits.values,splits.dense_shape)
    feat_ids, feat_vals = tf.split(id_vals,num_or_size_splits=2,axis=1)
    feat_ids = tf.string_to_number(feat_ids, out_type=tf.int32)
    feat_vals = tf.string_to_number(feat_vals, out_type=tf.float32)
    return {"feat_ids": feat_ids, "feat_vals": feat_vals}, labels

# Extract lines from input files using the Dataset API, can pass one filename or filename list
dataset = tf.contrib.data.TextLineDataset(filenames).map(decode_libsvm, num_threads=10).prefetch(1000)