提交 2fffef93 编写于 作者: R ranqiu

Fix bugs of reader.py in ctr model

上级 2067c2e8
...@@ -4,50 +4,48 @@ feeding_index = {'dnn_input': 0, 'lr_input': 1, 'click': 2} ...@@ -4,50 +4,48 @@ feeding_index = {'dnn_input': 0, 'lr_input': 1, 'click': 2}
class Dataset(object): class Dataset(object):
def __init__(self):
self.mode = TaskMode.create_train()
def train(self, path): def train(self, path):
''' '''
Load trainset. Load trainset.
''' '''
logger.info("load trainset from %s" % path) logger.info("load trainset from %s" % path)
self.mode = TaskMode.create_train() mode = TaskMode.create_train()
self.path = path return self._parse_creator(path, mode)
return self._parse
def test(self, path): def test(self, path):
''' '''
Load testset. Load testset.
''' '''
logger.info("load testset from %s" % path) logger.info("load testset from %s" % path)
self.path = path mode = TaskMode.create_test()
self.mode = TaskMode.create_test() return self._parse_creator(path, mode)
return self._parse
def infer(self, path): def infer(self, path):
''' '''
Load infer set. Load infer set.
''' '''
logger.info("load inferset from %s" % path) logger.info("load inferset from %s" % path)
self.path = path mode = TaskMode.create_infer()
self.mode = TaskMode.create_infer() return self._parse_creator(path, mode)
return self._parse
def _parse(self): def _parse_creator(self, path, mode):
''' '''
Parse dataset. Parse dataset.
''' '''
with open(self.path) as f:
for line_id, line in enumerate(f): def _parse():
fs = line.strip().split('\t') with open(path) as f:
dnn_input = load_dnn_input_record(fs[0]) for line_id, line in enumerate(f):
lr_input = load_lr_input_record(fs[1]) fs = line.strip().split('\t')
if not self.mode.is_infer(): dnn_input = load_dnn_input_record(fs[0])
click = [int(fs[2])] lr_input = load_lr_input_record(fs[1])
yield dnn_input, lr_input, click if not mode.is_infer():
else: click = [int(fs[2])]
yield dnn_input, lr_input yield dnn_input, lr_input, click
else:
yield dnn_input, lr_input
return _parse
def load_data_meta(path): def load_data_meta(path):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册