Skip to content

Commit c09229b

Browse files
author
jasons
committed
saving files
1 parent 7b39b02 commit c09229b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

031-chatbot/advanced/data.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,24 @@ def __init__(self, FLAGS):
332332
self.output_dir = FLAGS.output
333333
self.inputs_dir = FLAGS.input
334334

335-
def load_as_files(self):
335+
def load_as_files(self, lazy=True):
336336
""" Parent load as files class used globally """
337-
questions, answers, questions_vocabs, answers_vocabs = self.sub.load_as_raw()
337+
# Handle lazy load
338+
if lazy:
339+
try:
340+
questions = read_file_data('questions', self.inputs_dir)
341+
answers = read_file_data('answers', self.inputs_dir)
342+
questions_vocabs = read_file_data('questions_vocabs', self.inputs_dir)
343+
answers_vocabs = read_file_data('answers_vocabs', self.inputs_dir)
344+
except Exception as e:
345+
print('Failed to lazy load !', e)
346+
questions, answers, questions_vocabs, answers_vocabs = self.sub.load_as_raw()
347+
save_file_data('questions', questions)
348+
save_file_data('answers', answers)
349+
save_file_data('questions_vocabs', questions_vocabs)
350+
save_file_data('answers_vocabs', answers_vocabs)
351+
else:
352+
questions, answers, questions_vocabs, answers_vocabs = self.sub.load_as_raw()
338353

339354
# It will always use vi as src en as output
340355
save_list_to_file(questions, '{}/train.vi'.format(self.inputs_dir))

0 commit comments

Comments
 (0)