reader.py 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
class Dataset:
    def _reader_creator(self, path, is_infer):
        def reader():
            with open(path, 'r') as f:
                for line in f:
                    features = line.rstrip('\n').split('\t')
                    dense_feature = map(float, features[0].split(','))
                    sparse_feature = map(int, features[1].split(','))
                    if not is_infer:
                        label = [float(features[2])]
                        yield [dense_feature, sparse_feature
                               ] + sparse_feature + [label]
                    else:
                        yield [dense_feature, sparse_feature] + sparse_feature

        return reader

    def train(self, path):
        return self._reader_creator(path, False)

W
wangmeng28 已提交
21 22 23
    def test(self, path):
        return self._reader_creator(path, False)

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    def infer(self, path):
        return self._reader_creator(path, True)


feeding = {
    'dense_input': 0,
    'sparse_input': 1,
    'C1': 2,
    'C2': 3,
    'C3': 4,
    'C4': 5,
    'C5': 6,
    'C6': 7,
    'C7': 8,
    'C8': 9,
    'C9': 10,
    'C10': 11,
    'C11': 12,
    'C12': 13,
    'C13': 14,
    'C14': 15,
    'C15': 16,
    'C16': 17,
    'C17': 18,
    'C18': 19,
    'C19': 20,
    'C20': 21,
    'C21': 22,
    'C22': 23,
    'C23': 24,
    'C24': 25,
    'C25': 26,
    'C26': 27,
    'label': 28
}