def make_data_reader(self, config_dict): config = NestedNamespace() config.load_from_json(config_dict) config.tokenizers = self.tokenizers data_reader_factory = DataReaderFactory(config) return data_reader_factory.create()
def load_from_config(cls, config_path): with open(config_path, "r", encoding="utf-8") as in_file: machine_config = NestedNamespace() machine_config.load_from_json(json.load(in_file)) machine_name = machine_config.name config = getattr(machine_config, machine_name, {}) return cls(config)
def test_eval_squad_bidaf(): config = NestedNamespace() config.data_file_path = SYNTHETIC_DATA_PATH config.checkpoint_path = "./logs/test/bidaf/checkpoint/model_1.pkl" config.cude_devices = None set_gpu_env(config) experiment = Experiment(Mode.EVAL, config) experiment()
def test_eval_nlu_bert_for_tok_cls(): config = NestedNamespace() config.data_file_path = SYNTHETIC_DATA_PATH config.checkpoint_path = "./logs/test/tok_cls/bert/checkpoint/model_1.pkl" config.cude_devices = None set_gpu_env(config) experiment = Experiment(Mode.EVAL, config) experiment()
def load_and_setting(config_path): config = NestedNamespace() with open(config_path, "r") as f: defined_config = json.load(f) config.load_from_json(defined_config) config.data_reader.wikisql = NestedNamespace() config.data_reader.wikisql.is_test = True config = optimize_config(config, is_test=True) set_gpu_env(config) return config
def load_and_setting(config_path): config = NestedNamespace() with open(config_path, "r") as f: defined_config = json.load(f) config.load_from_json(defined_config) config = optimize_config(config, is_test=True) set_gpu_env(config) config.data_reader.train_file_path = SYNTHETIC_DATA_PATH config.data_reader.valid_file_path = SYNTHETIC_DATA_PATH return config
def test_train_base_config_argparse(): train_config = args.config(argv=["--base_config", "test/bidaf"], mode=Mode.TRAIN) config = NestedNamespace() with open("base_config/test/bidaf.json", "r") as f: defined_config = json.load(f) config.load_from_json(defined_config) args.set_gpu_env(config) assert train_config == config
def load_and_setting(config_path): config = NestedNamespace() config_path = add_config_extension(config_path) defined_config = read_config(config_path) config.load_from_json(defined_config) config = optimize_config(config, is_test=True) set_gpu_env(config) config.data_reader.train_file_path = SYNTHETIC_DATA_PATH config.data_reader.valid_file_path = SYNTHETIC_DATA_PATH return config
def open_qa_config(request): config_path = request.param machine_config = NestedNamespace() with open(config_path, "r") as f: defined_config = json.load(f) machine_config.load_from_json(defined_config) claf_name = machine_config.name config = getattr(machine_config, claf_name, {}) config.knowledge_base.wiki = WIKI_SYNTHETIC_DATA_PATH config.reasoning.reading_comprehension.checkpoint_path = "./logs/test/bidaf/checkpoint/model_1.pkl" return machine_config
def test_qa_predict_wikisql_sqlnet_1_example(): config = NestedNamespace() config.checkpoint_path = "./logs/test/sqlnet/checkpoint/model_1.pkl" config.cude_devices = None config.interactive = False set_gpu_env(config) config.column = [ "Player", "No.", "Nationality", "Position", "Years in Toronto", "School/Club Team" ] config.db_path = "data/wikisql/dev.db" config.table_id = "1-10015132-11" config.question = "What position does the player who played for butler cc (ks) play?" experiment = Experiment(Mode.PREDICT, config) experiment()
def test_qa_predict_squad_bert_long_1_example(): config = NestedNamespace() config.checkpoint_path = "./logs/test/bert_for_qa/checkpoint/model_1.pkl" config.cude_devices = None config.interactive = False set_gpu_env(config) config.context = "hi ho hi ho 1 hi ho hi ho 2 hi ho hi ho 3 hi ho hi ho 4 hi ho hi ho 5 hi ho hi ho 6 hi ho hi ho 7 hi ho hi ho 8 hi ho hi ho hi 9 ho hi ho hi ho hi 10 ho hi ho hi ho hi ho 11 hi ho hi ho hi 12 ANSWER ho hi ho hi ho hi 13 ho hi ho hi ho hi 14 ho hi ho hi ho hi 15 ho hi ho hi ho hi 16 ho hi ho hi ho hi 17 ho hi ho hi ho hi 18 ho hi ho hi ho hi 19 ho hi ho hi ho hi 20 ho hi ho hi ho hi 21 ho hi ho hi ho hi 22 ho hi ho hi ho hi 23 ho hi ho hi ho hi 24 ho hi ho hi 25 ho hi ho hi ho 1 hi ho hi ho 2 hi ho hi ho 3 hi ho hi ho 4 hi ho hi ho 5 hi ho hi ho 6 hi ho hi ho 7 hi ho hi ho 8 hi ho hi ho hi 9 ho hi ho hi ho hi 10 ho hi ho hi ho hi ho 11 hi ho hi ho hi 12 ho hi ho hi ho hi 13 ho hi ho hi ho hi 14 ho hi ho hi ho hi 15 ho hi ho hi ho hi 16 ho hi ho hi ho hi 17 ho hi ho hi ho hi 18 ho hi ho hi ho hi 19 ho hi ho hi ho hi 20 ho hi ho hi ho hi 21 ho hi ho hi ho hi 22 ho hi ho hi ho hi 23 ho hi ho hi ho hi 24 ho hi ho hi 25 ho hi ho hi ho 1 hi ho hi ho 2 hi ho hi ho 3 hi ho hi ho 4 hi ho hi ho 5 hi ho hi ho 6 hi ho hi ho 7 hi ho hi ho 8 hi ho hi ho hi 9 ho hi ho hi ho hi 10 ho hi ho hi ho hi ho 11 hi ho hi ho hi 12 ho hi ho hi ho hi 13 ho hi ho hi ho hi 14 ho hi ho hi ho hi 15 ho hi ho hi ho hi 16 ho hi ho hi ho hi 17 ho hi ho hi ho hi 18 ho hi ho hi ho hi 19 ho hi ho hi ho hi 20 ho hi ho hi ho hi 21 ho hi ho hi ho hi 22 ho hi ho hi ho hi 23 ho hi ho hi ho hi 24 ho hi ho hi 25 ho hi ho hi ho 1 hi ho hi ho 2 hi ho hi ho 3 hi ho hi ho 4 hi ho hi ho 5 hi ho hi ho 6 hi ho hi ho 7 hi ho hi ho 8 hi ho hi ho hi 9 ho hi ho hi ho hi 10 ho hi ho hi ho hi ho 11 hi ho hi ho hi 12 ho hi ho hi ho hi 13 ho hi ho hi ho hi 14 ho hi ho hi ho hi 15 ho hi ho hi ho hi 16 ho hi ho hi ho hi 17 ho hi ho hi ho hi 18 ho hi ho hi ho hi 19 ho hi ho hi ho hi 20 ho hi ho hi ho hi 21 ho hi ho hi ho hi 22 ho hi ho hi ho hi 23 ho hi ho hi ho hi 24 ho hi ho hi 25 ho" config.question = "good hi ho hi ho hi good hi ho hi ho hi good hi ho hi ho hi good hi ho hi ho hi good hi ho hi ho hi" experiment = Experiment(Mode.PREDICT, config) experiment()
def test_qa_predict_squad_bert_short_1_example(): config = NestedNamespace() config.checkpoint_path = "./logs/test/bert_for_qa/checkpoint/model_1.pkl" config.cude_devices = None config.interactive = False set_gpu_env(config) config.context = "Westwood One will carry the game throughout North America, with Kevin Harlan as play-by-play announcer, Boomer Esiason and Dan Fouts as color analysts, and James Lofton and Mark Malone as sideline reporters. Jim Gray will anchor the pre-game and halftime coverage." config.question = "What radio network carried the Super Bowl?" experiment = Experiment(Mode.PREDICT, config) experiment()
def load_and_setting(config_path): config = NestedNamespace() with open(config_path, "r") as f: defined_config = json.load(f) config.load_from_json(defined_config) config = optimize_config(config, is_test=True) set_gpu_env(config) config.data_reader.multitask_bert.readers[0][ "train_file_path"] = SYNTHETIC_SEQ_CLS_DATA_PATH config.data_reader.multitask_bert.readers[0][ "valid_file_path"] = SYNTHETIC_SEQ_CLS_DATA_PATH config.data_reader.multitask_bert.readers[1][ "train_file_path"] = SYNTHETIC_REG_DATA_PATH config.data_reader.multitask_bert.readers[1][ "valid_file_path"] = SYNTHETIC_REG_DATA_PATH config.data_reader.multitask_bert.readers[2][ "train_file_path"] = SYNTHETIC_QA_DATA_PATH config.data_reader.multitask_bert.readers[2][ "valid_file_path"] = SYNTHETIC_QA_DATA_PATH return config
def test_predict_nlu_bert_for_tok_cls_1_example(): config = NestedNamespace() config.checkpoint_path = "./logs/test/tok_cls/bert/checkpoint/model_1.pkl" config.cude_devices = None config.interactive = False set_gpu_env(config) config.sequence = "hi, how are you?" experiment = Experiment(Mode.PREDICT, config) experiment()
def train_config(request): config_path = request.param config = NestedNamespace() with open(config_path, "r") as f: defined_config = json.load(f) config.load_from_json(defined_config) config.nsml = NestedNamespace() config.nsml.pause = 0 config = optimize_config(config, is_test=True) set_gpu_env(config) config.data_reader.train_file_path = SQUAD_SYNTHETIC_DATA_PATH config.data_reader.valid_file_path = SQUAD_SYNTHETIC_DATA_PATH return config
help=""" NSML mode setting """, ) parser.add_argument( "--iteration", type=int, default=0, help=""" NSML default setting """, ) parser.add_argument( "--pause", type=int, default=0, help=""" NSML default setting """, ) args = parser.parse_args() with open(args.base_config, "r") as f: defined_config = json.load(f) config = NestedNamespace() config.load_from_json(defined_config) config.nsml = args set_logging_config() if args.mode == "train_and_evaluate": re_train_and_evaluate(config) elif args.mode == "test" or args.mode == "infer": test(config) else: raise ValueError(f"Unrecognized mode. {config.mode}")