Esempio n. 1
0
 def __init__(self, config, ft, num_labels, res, H, device_num):
     super(BertGAT, self).__init__(config)
     self.device = torch.device('cuda:' + device_num)
     self.bert = BertModel.from_pretrained('bert-base-uncased')
     self.dropout = nn.Dropout(0.5)
     self.ft = ft
     self.num_labels = num_labels
     self.gat = SpGAT(nfeat=H.shape[1], nclass=num_labels).to(self.device)
     self.FCN = nn.Linear(768, num_labels)
     self.softmax = nn.Softmax()
     self.H = torch.tensor(H).float().to(self.device)
     A = torch.tensor(gen_A(num_labels, res)).float().to(self.device)
     self.adj = gen_adj(A).detach()
     # self.FCN2 = nn.Linear(num_labels, num_labels)
     self.apply(self.init_bert_weights)
Esempio n. 2
0
 def __init__(self, config, ft, num_labels, res, H, device_num):
     super(BertGCN, self).__init__(config)
     self.device = torch.device('cuda:' + device_num)
     self.bert = BertModel.from_pretrained('bert-base-uncased')
     self.dropout = nn.Dropout(0.5)
     self.H = get_tensor(H, self.device)
     self.ft = ft
     self.num_labels = num_labels
     self.FCN = nn.Linear(768, num_labels)
     self.softmax = nn.Softmax(dim=1)
     self.apply(self.init_bert_weights)
     self.gcn_weight1 = Parameter(torch.Tensor(H.shape[1], 1500))
     self.gcn_weight2 = Parameter(torch.Tensor(1500, 768))
     self.lkrelu = nn.LeakyReLU(0.2)
     self.A = torch.tensor(gen_A(num_labels, res)).float().to(self.device)
     # self.A = Parameter(torch.from_numpy(gen_A(num_labels, res)).float()).to(self.device)
     self.adj = gen_adj(self.A).detach()
Esempio n. 3
0
    def __init__(self, config, ft, num_labels, H, device_num, C, c_adj):
        super(BertGCN_Cluster, self).__init__(config)
        self.device = torch.device('cuda:' + device_num)
        self.bert = BertModel.from_pretrained('bert-base-uncased')
        self.dropout = nn.Dropout(0.5)
        self.ft = ft
        self.H = get_tensor(H, self.device)  # m * 3072
        self.C = get_tensor(C, self.device)  # m * C
        self.c_adj = gen_adj(get_tensor(c_adj, self.device)).detach()  # C * C
        self.num_labels = num_labels
        self.FCN = nn.Linear(768, num_labels)
        self.actv = nn.LeakyReLU(0.2)
        # self.actv = nn.Tanh()
        self.softmax = nn.Softmax(dim=1)
        self.apply(self.init_bert_weights)

        self.W1 = Parameter(torch.Tensor(H.shape[1], 768))
        self.W2 = Parameter(torch.Tensor(768, 768))