def main(): args = KGEArgParser().get_args(sys.argv[1:]) config_def, model_def = Importer().import_model_config(args.model_name.lower()) config = config_def(args) model = model_def(**config.__dict__) trainer = Trainer(model, config) trainer.build_model() trainer.infer_tails(1, 10, topk=5) trainer.infer_heads(10, 20, topk=5) trainer.infer_rels(1, 20, topk=5)
def test_inference_on_pretrained_model(): args = KGEArgParser().get_args([]) config_def, model_def = Importer().import_model_config("transe") config = config_def(args) config.load_from_data = os.path.join(os.path.dirname(__file__), "resource", "pretrained", "TransE", Trainer.TRAINED_MODEL_FILE_NAME) model = model_def(**config.__dict__) # Create the model and load the trained weights. trainer = Trainer(model, config) trainer.build_model() #takes head, relation tails = trainer.infer_tails(1, 10, topk=5) assert len(tails) == 5 #takes relation, tail heads = trainer.infer_heads(10, 20, topk=5) assert len(heads) == 5 #takes head, tail relations = trainer.infer_rels(1, 20, topk=5) assert len(relations) == 5
def main(): # getting the customized configurations from the command-line arguments. args = KGEArgParser().get_args(sys.argv[1:]) # Extracting the corresponding model config and definition from Importer(). config_def, model_def = Importer().import_model_config( args.model_name.lower()) config = config_def(args) model = model_def(**config.__dict__) # Create the model and load the trained weights. trainer = Trainer(model, config) trainer.build_model() trainer.infer_tails(1, 10, topk=5) trainer.infer_heads(10, 20, topk=5) trainer.infer_rels(1, 20, topk=5)
def testing_function_with_args(name, distance_measure=None, bilinear=None, display=False): """Function to test the models with arguments.""" tf.reset_default_graph() # getting the customized configurations from the command-line arguments. args = KGEArgParser().get_args([]) # Preparing data and cache the data for later usage knowledge_graph = KnowledgeGraph(dataset=args.dataset_name, negative_sample=args.sampling) knowledge_graph.prepare_data() # Extracting the corresponding model config and definition from Importer(). config_def, model_def = Importer().import_model_config(name) config = config_def(args=args) config.epochs = 1 config.test_step = 1 config.test_num = 10 config.disp_result = display config.save_model = True model = model_def(config) # Create, Compile and Train the model. While training, several evaluation will be performed. trainer = Trainer(model=model, debug=True) trainer.build_model() trainer.train_model() #can perform all the inference here after training the model trainer.enter_interactive_mode() #takes head, relation trainer.infer_tails(1, 10, topk=5) #takes relation, tail trainer.infer_heads(10, 20, topk=5) #takes head, tail trainer.infer_rels(1, 20, topk=5) trainer.exit_interactive_mode()
def main(): # getting the customized configurations from the command-line arguments. args = KGEArgParser().get_args(sys.argv[1:]) # Preparing data and cache the data for later usage knowledge_graph = KnowledgeGraph(dataset=args.dataset_name, negative_sample=args.sampling) knowledge_graph.prepare_data() sess_infer = tf.InteractiveSession() # Extracting the corresponding model config and definition from Importer(). config_def, model_def = Importer().import_model_config(args.model_name.lower()) config = config_def(args=args) model = model_def(config) # Create, Compile and Train the model. While training, several evaluation will be performed. trainer = Trainer(model=model, debug=args.debug) trainer.build_model() trainer.train_model() #can perform all the inference here after training the model #takes head, relation trainer.infer_tails(1,10,sess_infer,topk=5) #takes relation, tails trainer.infer_heads(10,20,sess_infer,topk=5) sess_infer.close()
def testing_function_with_args(name, l1_flag, display=False): """Function to test the models with arguments.""" # getting the customized configurations from the command-line arguments. args = KGEArgParser().get_args([]) # Preparing data and cache the data for later usage knowledge_graph = KnowledgeGraph(dataset=args.dataset_name) knowledge_graph.prepare_data() # Extracting the corresponding model config and definition from Importer(). config_def, model_def = Importer().import_model_config(name) config = config_def(args) config.epochs = 1 config.test_step = 1 config.test_num = 10 config.disp_result = display config.save_model = True config.l1_flag = l1_flag config.debug = True model = model_def(**config.__dict__) # Create, Compile and Train the model. While training, several evaluation will be performed. trainer = Trainer(model, config) trainer.build_model() trainer.train_model() #can perform all the inference here after training the model trainer.enter_interactive_mode() #takes head, relation tails = trainer.infer_tails(1, 10, topk=5) assert len(tails) == 5 #takes relation, tail heads = trainer.infer_heads(10, 20, topk=5) assert len(heads) == 5 #takes head, tail if not name in ["conve", "proje_pointwise", "tucker"]: relations = trainer.infer_rels(1, 20, topk=5) assert len(relations) == 5 trainer.exit_interactive_mode()