def _drop_answer_id_col_from_feature_file(self, train_file_location):
file_without_aid = insert_modifier_in_filename(train_file_location, 'no_aid')
if path.isfile(file_without_aid):
self.logger.info('Found a previously generated version of the training file without answer id column, '
're-using it: %s' % file_without_aid)
else:
self.logger.info('Generating a version of the feature file without answer id (which is what ranker'
' training expects')
temp_file = get_temp_file(file_without_aid)
with smart_file_open(temp_file, 'w') as outfile:
writer = csv.writer(outfile)
with smart_file_open(train_file_location) as infile:
reader = csv.reader(infile)
for row in reader:
writer.writerow(row[:1] + row[2:])
move(temp_file, file_without_aid)
self.logger.info('Done generating file: %s' % file_without_aid)
return file_without_aid
评论列表
文章目录