def parse_args(): """ Argument Parser """ parser = argparse.ArgumentParser(description="NER Main Parser") parser.add_argument("-c", "--config", dest="config_file", type=str, metavar="PATH", default="./config/config.ini", help="Configuration file path") parser.add_argument("-l", "--log_dir", dest="log_dir", type=str, metavar="PATH", default="./logs", help="Log file path") parser.add_argument("-d", "--device", dest="device", type=str, default="cuda:3", help="device[‘cpu’,‘cuda:0’,‘cuda:1’,..]") parser.add_argument("-v", "--verbose", action='store_true', default=False, help="Print data description") parser.add_argument("-e", "--eval", action='store_true', default=False, help="For evaluation purpose only") parser.add_argument("-p", "--pos", action='store_true', default=False, help="Use POS one-hot-encoding") parser.add_argument("-r", "--char", action='store_true', default=False, help="Use character-level CNN") parser.add_argument("-g", "--grapheme", action='store_true', default=False, help="Use grapheme-level CNN") parser.add_argument("-k", "--kfold", dest="kfold", type=int, default=5, metavar="INT", help="K-fold cross validation [default:1]") args = parser.parse_args() if os.path.exists(args.log_dir): shutil.rmtree(args.log_dir) os.mkdir(args.log_dir) # Init Logger log_file = os.path.join(args.log_dir, 'complete.log') data_log = os.path.join(args.log_dir, 'data_log.log') logger = utilities.get_logger(log_file) config = Configuration(config_file=args.config_file, logger=logger) config.device = args.device config.verbose = args.verbose config.eval = args.eval config.kfold = args.kfold config.log_dir = args.log_dir config.log_file = log_file config.data_log = data_log config.use_pos = args.pos config.use_char = args.char config.use_graph = args.grapheme logger.info("***************************************") logger.info("Data file : {}".format(config.data_file)) logger.info("Device : {}".format(config.device)) logger.info("Verbose : {}".format(config.verbose)) logger.info("Eval mode : {}".format(config.eval)) logger.info("K-fold : {}".format(config.kfold)) logger.info("Log directory: {}".format(config.log_dir)) logger.info("Data log file: {}".format(config.data_log)) logger.info("Use POS one-hot-encoding: {}".format(config.use_pos)) logger.info("Use character-level CNN: {}".format(config.use_char)) logger.info("Use grapheme-level CNN: {}".format(config.use_graph)) logger.info("***************************************") # if not config.eval: # if os.path.exists(config.output_dir): # shutil.rmtree(config.output_dir) # os.mkdir(config.output_dir) # if os.path.exists(config.results_dir): # shutil.rmtree(config.results_dir) # os.mkdir(config.results_dir) return config, logger
def parse_args(): """ Argument Parser """ parser = argparse.ArgumentParser(description="NepSA Main Parser") parser.add_argument("-c", "--config", dest="config_file", type=str, metavar="PATH", default="./config/config.ini", help="Configuration file path") parser.add_argument("-r", "--root_path", dest="root_path", type=str, metavar="PATH", default=None, help="Data root file path") parser.add_argument("-l", "--log_dir", dest="log_dir", type=str, metavar="PATH", default="./logs", help="Log file path") parser.add_argument("-d", "--device", dest="device", type=str, default="cuda:0", help="device[‘cpu’,‘cuda:0’,‘cuda:1’,..]") parser.add_argument("-v", "--verbose", action='store_true', default=False, help="Print data description") parser.add_argument("-s", "--csv", action='store_true', default=True, help="CSV file splitter") parser.add_argument("-e", "--eval", action='store_true', default=False, help="For evaluation purpose only") parser.add_argument("-i", "--infer", action='store_true', default=False, help="For inference purpose only") parser.add_argument("-t", "--train_type", type=int, choices=[1, 2, 3, 4], default=3, help="""1: Text-> AspectCategory, 2: Text+AspectTerm -> AspectCategory, 3: Text+AspectTerm+AspectCategory -> SS, 4: Text -> SS""") parser.add_argument("-m", "--model", type=str, choices=['lstm', 'cnn'], default='lstm', help="LSTM or CNN model [default: LSTM]") parser.add_argument("-k", "--kfold", dest="kfold", type=int, default=1, metavar="INT", help="K-fold cross validation [default:1]") parser.add_argument("-n", "--model_name", dest="model_name", type=str, default='', metavar="PATH", help="Model file name") parser.add_argument("--txt", dest="txt", type=str, default="रबि लामिछाने नेपालि जन्ता को हिरो हुन", help="Input text (For inference purpose only)") parser.add_argument("--at", dest="at", type=str, default="हिरो हुन", help="Input aspect term (For inference purpose only)") parser.add_argument( "--ac", dest="ac", type=str, default='GENERAL', help="Input aspect category (For inference purpose only)") args = parser.parse_args() # If log dir does not exist, create it if not os.path.exists(args.log_dir): os.mkdir(args.log_dir) # Init Logger log_suffix = '_' + args.model + '_' + str(args.train_type) + '.log' log_file = os.path.join(args.log_dir, 'complete' + log_suffix) data_log = os.path.join(args.log_dir, 'datalog' + log_suffix) # Logger logger = utilities.get_logger(log_file) # Configuration config = Configuration(config_file=args.config_file, logger=logger, args=args) config.device = args.device config.verbose = args.verbose config.eval = args.eval config.kfold = args.kfold config.log_dir = args.log_dir config.log_file = log_file config.data_log = data_log config.csv = args.csv config.train_type = args.train_type config.model = args.model model_filename = os.path.basename( config.data_file).split('.')[0] + '_' + config.model + '_' + str( config.train_type) config.model_name = args.model_name if args.model_name else model_filename config.root_path = args.root_path if args.root_path else os.path.join( config.data_path, config.model_name) config.infer = args.infer config.txt = args.txt config.at = args.at config.ac = args.ac logger.info("*******************************ARGS") logger.info("Data file : {}".format(config.data_file)) logger.info("Device : {}".format(config.device)) logger.info("Verbose : {}".format(config.verbose)) logger.info("Eval mode : {}".format(config.eval)) logger.info("K-fold : {}".format(config.kfold)) logger.info("Log directory: {}".format(config.log_dir)) logger.info("Data log file: {}".format(config.data_log)) logger.info("Split csv file: {}".format(config.csv)) logger.info("Training Type: {}".format(config.train_type)) logger.info("Model: {}".format(config.model)) logger.info("Model name: {}".format(config.model_name)) logger.info("Root path: {}".format(config.root_path)) logger.info("Inference mode: {}".format(config.infer)) if config.infer: logger.info("Text: {}".format(config.txt)) logger.info("Aspect Term: {}".format(config.at)) logger.info("Aspect Category: {}".format(config.ac)) logger.info("***************************************") return config, logger