From bd15912d65952d09c5b1bc59f4892ba371ecfb43 Mon Sep 17 00:00:00 2001 From: YishengCheng Date: Thu, 30 May 2019 13:03:05 +0800 Subject: [PATCH] fix bug for ctr_reader for svm data (#17575) * fix bug for ctr_reader test=develop * fix svm data test=develop fix svm data test=develop --- paddle/fluid/operators/reader/ctr_reader.cc | 4 ++-- .../fluid/operators/reader/ctr_reader_test.cc | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/operators/reader/ctr_reader.cc b/paddle/fluid/operators/reader/ctr_reader.cc index 10ad67ac8..4edc15a26 100644 --- a/paddle/fluid/operators/reader/ctr_reader.cc +++ b/paddle/fluid/operators/reader/ctr_reader.cc @@ -52,9 +52,9 @@ static inline void parse_line( std::unordered_map>* slot_to_data) { std::vector ret; string_split(line, ' ', &ret); - *label = std::stoi(ret[2]) > 0; + *label = std::stoi(ret[0]) > 0; - for (size_t i = 3; i < ret.size(); ++i) { + for (size_t i = 1; i < ret.size(); ++i) { const std::string& item = ret[i]; std::vector feasign_and_slot; string_split(item, ':', &feasign_and_slot); diff --git a/paddle/fluid/operators/reader/ctr_reader_test.cc b/paddle/fluid/operators/reader/ctr_reader_test.cc index 641043981..b64c84004 100644 --- a/paddle/fluid/operators/reader/ctr_reader_test.cc +++ b/paddle/fluid/operators/reader/ctr_reader_test.cc @@ -91,16 +91,16 @@ static inline void check_all_data( TEST(CTR_READER, read_data) { const std::vector ctr_data = { - "aaaa 1 0 0:6002 1:6003 2:6004 3:6005 4:6006 -1\n", - "bbbb 1 0 5:6003 6:6003 7:6003 8:6004 9:6004 -1\n", - "cccc 1 1 10:6002 11:6002 12:6002 13:6002 14:6002 -2\n", - "dddd 1 0 15:6003 16:6003 17:6003 18:6003 19:6004 -3\n", - "1111 1 1 20:6001 21:6001 22:6001 23:6001 24:6001 12\n", - "2222 1 1 25:6004 26:6004 27:6004 28:6005 29:6005 aa\n", - "3333 1 0 30:6002 31:6003 32:6004 33:6004 34:6005 er\n", - "eeee 1 1 35:6003 36:6003 37:6005 38:6005 39:6005 dd\n", - "ffff 1 1 40:6002 41:6003 42:6004 43:6004 44:6005 66\n", - "gggg 1 1 46:6006 45:6006 47:6003 48:6003 49:6003 ba\n", + "0 0:6002 1:6003 2:6004 3:6005 4:6006 \n", + "0 5:6003 6:6003 7:6003 8:6004 9:6004 \n", + "1 10:6002 11:6002 12:6002 13:6002 14:6002 \n", + "0 15:6003 16:6003 17:6003 18:6003 19:6004 \n", + "1 20:6001 21:6001 22:6001 23:6001 24:6001 \n", + "1 25:6004 26:6004 27:6004 28:6005 29:6005 \n", + "0 30:6002 31:6003 32:6004 33:6004 34:6005 \n", + "1 35:6003 36:6003 37:6005 38:6005 39:6005 \n", + "1 40:6002 41:6003 42:6004 43:6004 44:6005 \n", + "1 46:6006 45:6006 47:6003 48:6003 49:6003 \n", }; std::string gz_file_name = "test_ctr_reader_data.gz"; generatedata(ctr_data, gz_file_name); -- GitLab