def construct_model(args): kg = KnowledgeGraph(args) if args.model.endswith('.gc'): kg.load_fuzzy_facts() fn = ConvE(args, kg.num_entities) lf = EmbeddingBasedMethod(args, kg, fn) return lf
def construct_model(args): """ Construct NN graph. """ kg = KnowledgeGraph(args) if args.model.endswith('.gc'): kg.load_fuzzy_facts() if args.model in ['point', 'point.gc']: pn = GraphSearchPolicy(args) lf = PolicyGradient(args, kg, pn) elif args.model.startswith('point.rs'): fn_model = args.model.split('.')[2] fn_args = copy.deepcopy(args) fn_args.model = fn_model fn_args.relation_only = False if fn_model == 'complex': fn = ComplEx(fn_args) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'distmult': fn = DistMult(fn_args) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'conve': fn = ConvE(fn_args, kg.num_entities) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'tucker': fn = TuckER(fn_args, kg.num_entities) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'PTransE': fn = PTransE(fn_args) fn_kg = KnowledgeGraph(fn_args) pn = GraphSearchPolicy(args, fn_kg=fn_kg, fn=fn) lf = RewardShapingPolicyGradient(args, kg, pn, fn_kg, fn) elif args.model == 'complex': fn = ComplEx(args) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'distmult': fn = DistMult(args) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'tucker': fn = TuckER(args, kg.num_entities) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'conve': fn = ConvE(args, kg.num_entities) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'TransE': fn = TransE(args) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'PTransE': fn = PTransE(args) lf = EmbeddingBasedMethod(args, kg, fn) else: raise NotImplementedError return lf
def construct_model(args): """ Construct NN graph. """ kg = KnowledgeGraph(args) if args.model.endswith('.gc'): kg.load_fuzzy_facts() if args.model in ['point', 'point.gc']: pn = GraphSearchPolicy(args) parameters = pn.named_parameters() for name, value in parameters: print('parameter: {} | size: {}'.format(name, value.size())) # print('pn parameters: {}'.format(pn.named_parameters())) #print(args.device_ids) #print(type(args.device_ids[0])) #lf = nn.DataParallel(PolicyGradient(args, kg, pn), device_ids=args.device_ids) lf = PolicyGradient(args, kg, pn) elif args.model.startswith('point.rs'): pn = GraphSearchPolicy(args) fn_model = args.model.split('.')[2] fn_args = copy.deepcopy(args) fn_args.model = fn_model fn_args.relation_only = False if fn_model == 'complex': fn = ComplEx(fn_args) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'distmult': fn = DistMult(fn_args) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'conve': fn = ConvE(fn_args, kg.num_entities) fn_kg = KnowledgeGraph(fn_args) elif fn_model == 'cpg-conve': fn = CPG_ConvE(fn_args, kg.num_entities) fn_kg = KnowledgeGraph(fn_args) lf = RewardShapingPolicyGradient(args, kg, pn, fn_kg, fn) elif args.model == 'complex': fn = ComplEx(args) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'distmult': fn = DistMult(args) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'conve': fn = ConvE(args, kg.num_entities) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == 'cpg-conve': fn = CPG_ConvE(args, kg.num_entities) lf = EmbeddingBasedMethod(args, kg, fn) else: raise NotImplementedError return lf
def construct_model(args): """ Construct NN graph. """ kg = KnowledgeGraph(args) # NOTE: initialize a KG instance if args.model.endswith( ".gc"): # CAVEAT: not sure what model needs fuzzy facts kg.load_fuzzy_facts() if args.model in ["point", "point.gc"]: pn = GraphSearchPolicy(args) lf = PolicyGradient(args, kg, pn) elif args.model.startswith("point.rs"): pn = GraphSearchPolicy(args) fn_model = args.model.split(".")[-1] fn_args = copy.deepcopy(args) fn_args.model = fn_model fn_args.relation_only = False if fn_model == "complex": fn = ComplEx(fn_args) fn_kg = KnowledgeGraph(fn_args) elif fn_model == "distmult": fn = DistMult(fn_args) fn_kg = KnowledgeGraph(fn_args) elif fn_model == "conve": fn = ConvE(fn_args, kg.num_entities) fn_kg = KnowledgeGraph(fn_args) lf = RewardShapingPolicyGradient(args, kg, pn, fn_kg, fn) elif args.model == "complex": fn = ComplEx(args) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == "distmult": print("jxtu: embedding model: distmult") fn = DistMult(args) lf = EmbeddingBasedMethod( args, kg, fn) # NOTE: embedding-based learning framework elif args.model == "conve": fn = ConvE(args, kg.num_entities) lf = EmbeddingBasedMethod(args, kg, fn) elif args.model == "TransE": fn = TransE(args) lf = EmbeddingBasedMethod(args, kg, fn) else: raise NotImplementedError return lf