-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (42 loc) · 1.74 KB
/
Copy pathmain.py
File metadata and controls
50 lines (42 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
import tensorflow as tf
import logging
import sys
import Seq2Seq as s2s
def main():
print("STARTED \n")
if len(sys.argv) > 1:
mode = sys.argv[1]
else:
raise ValueError("Main mode option not provided")
tf.logging._logger.setLevel(logging.INFO)
if mode.upper() == "TRAINING":
#FOR TRAINING
print("Training Started")
s2s.train_seq2seq('Data/final_question_file', 'Data/final_answer_file', 'Data/vocab_map', 'model/seq2seq')
elif mode.upper() == "INFERENCE":
if len(sys.argv) > 2:
pass
else:
sys.argv.append("COMMAND")
#FOR PREDICTION --- 'file'/'command'
infer_mode = sys.argv[2]
if infer_mode.upper() == "FILE":
print("Entered Inference File Mode")
s2s.predict_seq2seq('Data/prediction_input','Data/vocab_map', 'model/seq2seq', 'FILE')
elif infer_mode.upper() == "COMMAND":
print("Entered Inference Command Mode")
command_line_input = input("Question: ")
ans = s2s.predict_seq2seq('Data/prediction_input','Data/vocab_map', 'model/seq2seq', 'COMMAND', None,
command_line_input)
print("\nQuestion: ", command_line_input)
print("\nAnswer: ", ans.replace('<EOS>',''))
else:
raise ValueError("Correct Inference mode (FILE/COMMAND) was not supplied")
elif mode.upper() == 'TESTING':
s2s.predict_seq2seq('Data/testing_input_file', 'Data/vocab_map', 'model/seq2seq', 'TESTING',
'Data/testing_ref_file')
else:
raise ValueError("Correct Main mode (Training/Inference) was not supplied")
print("\nFINISHED \n")
if __name__ == "__main__":
main()