Ejemplo n.º 1
0
    def __init__(self, args, logger):
        super(GraphSAGE, self).__init__(args, logger)

        self.adj = utils.build_adj(self.graph, self.num_node)

        edge_dist_dict, node_dist_dict = utils.makeDist(
            args.link_file, args.negative_power)
        self.edges_alias_sampler = utils.VoseAlias(edge_dist_dict)
        self.nodes_alias_sampler = utils.VoseAlias(node_dist_dict)

        self.taxo_parent2children, self.taxo_child2parents, self.nodeid2category, self.category2nodeid, self.category2id, self.nodeid2path \
            = utils.read_taxos(args.taxo_file, args.taxo_assign_file, args.extend_label)
        self.root_nodes = [
            i for i in self.root_nodes if i in self.nodeid2category
        ]

        edgedistdict, taxodistdict = self.make_dist()
        self.taxo_edge_alias_sampler = utils.VoseAlias(edgedistdict)
        self.taxo_alias_sampler = utils.VoseAlias(taxodistdict)
        self.num_category = len(self.category2id)
        self.taxo_rootid = self.category2id['root']

        self.print(f"num of category: {self.num_category}")

        if args.rand_init:
            taxo_init_embed = utils.init_embed(self.num_category,
                                               self.embed_dim)
        else:
            taxo_init_embed = self.init_taxo_embed(self.pre_train_embedding)

        self.model = TaxoGCNModel(self.pre_train_embedding, taxo_init_embed,
                                  args.dropout)
        self.model.to(args.device)
Ejemplo n.º 2
0
    def __init__(self, args, logger):
        super(PTE, self).__init__(args, logger)
        edge_dist_dict, node_dist_dict = utils.makeDist(
            args.link_file, args.negative_power)
        self.edges_alias_sampler = utils.VoseAlias(edge_dist_dict)
        self.nodes_alias_sampler = utils.VoseAlias(node_dist_dict)

        self.taxo_parent2children, self.taxo_child2parents, self.nodeid2category, self.category2nodeid, self.category2id, self.nodeid2path \
         = utils.read_taxos(args.taxo_file, args.taxo_assign_file, args.extend_label)

        edgedistdict, taxodistdict = self.make_dist()
        self.taxo_edge_alias_sampler = utils.VoseAlias(edgedistdict)
        self.taxo_alias_sampler = utils.VoseAlias(taxodistdict)
        self.num_category = len(self.category2id)
        self.taxo_rootid = self.category2id['root']

        self.category2level = utils.category2level(range(self.num_category),
                                                   self.taxo_child2parents)
        level2category = defaultdict(list)
        for cate, level in self.category2level.items():
            level2category[level].append(cate)
        self.level2category = dict(level2category)

        self.print(f"num of category: {self.num_category}")

        if args.rand_init:
            taxo_init_embed = utils.init_embed(self.num_category,
                                               self.embed_dim)
        else:
            taxo_init_embed = self.init_taxo_embed(self.pre_train_embedding)

        self.model = TaxoSkipGramModel(self.pre_train_embedding,
                                       taxo_init_embed)
        self.model.to(args.device)
Ejemplo n.º 3
0
    def __init__(self, args, logger):
        super(LINE, self).__init__(args, logger)
        self.print(f"Reading data from {args.data_dir}")
        edge_dist_dict, node_dist_dict = utils.makeDist(args.link_file, args.negative_power)
        self.edges_alias_sampler = utils.VoseAlias(edge_dist_dict)
        self.nodes_alias_sampler = utils.VoseAlias(node_dist_dict)

        self.model = SkipGramModel(self.pre_train_embedding)
        self.model.to(args.device)
Ejemplo n.º 4
0
    def __init__(self, args, logger=None):
        """initialize the parameters, prepare the data and build the network"""
        super(AbstractGAN, self).__init__(args, logger)

        # build the model
        self.generator = None
        self.discriminator = None
        self.all_score = None
        self.task_stats = {
            task: {
                'best_acc': -1,
                'best_acc_d': -1,
                'best_acc_g': -1,
                'd_acc': [],
                'g_acc': []
            }
            for task in args.task.split('|')
        }
        self.stats = {
            'd_g_loss': [],
            'd_t_loss': [],
            'g_g_loss': [],
            'g_t_loss': []
        }

        edge_dist_dict, node_dist_dict = utils.makeDist(
            args.link_file, args.negative_power)
        # self.edges_alias_sampler = utils.VoseAlias(edge_dist_dict)
        self.nodes_alias_sampler = utils.VoseAlias(node_dist_dict)
Ejemplo n.º 5
0
    def __init__(self, args, logger=None):
        super(TaxoGAN_V1, self).__init__(args, logger)

        self.taxo_parent2children, self.taxo_child2parents, self.nodeid2category, self.category2nodeid, self.category2id, self.nodeid2path \
            = utils.read_taxos(args.taxo_file, args.taxo_assign_file)
        self.root_nodes = [
            i for i in self.root_nodes if i in self.nodeid2category
        ]
        categories = list(self.category2nodeid.keys())
        self.nodeid2neg_category = {
            node:
            [i for i in categories if i not in self.nodeid2category[node]]
            for node in self.root_nodes
        }

        edgedistdict, taxodistdict = self.make_dist()
        self.taxo_edge_alias_sampler = utils.VoseAlias(edgedistdict)
        self.taxo_alias_sampler = utils.VoseAlias(taxodistdict)
        self.num_category = len(self.category2id)
        self.taxo_rootid = self.category2id['root']
        self.category2level = utils.category2level(range(self.num_category),
                                                   self.taxo_child2parents)

        self.print(f"num of category: {self.num_category}")

        if args.rand_init:
            taxo_init_embed = utils.init_embed(self.num_category,
                                               self.embed_dim)
        else:
            taxo_init_embed = self.init_taxo_embed(self.pre_train_embedding)

        max_level = 0
        for _, paths in self.nodeid2path.items():
            for p in paths:
                max_level = max(max_level, len(p))
        self.max_level = max_level

        # build the model
        self.generator = Generator(args.lambda_g, self.pre_train_embedding,
                                   taxo_init_embed, args.lambda_taxo,
                                   max_level + 1, args.transform)
        self.discriminator = Discriminator(args.lambda_d,
                                           self.pre_train_embedding,
                                           taxo_init_embed, args.lambda_taxo,
                                           max_level + 1, args.transform)
        self.generator.to(args.device)
        self.discriminator.to(args.device)