def __init__(self, config, dataset):
    super(KGNNLS, self).__init__(config, dataset)
    self.embedding_size = config['embedding_size']
    self.neighbor_sample_size = config['neighbor_sample_size']
    self.aggregator_class = config['aggregator']
    self.n_iter = config['n_iter']
    self.reg_weight = config['reg_weight']
    self.ls_weight = config['ls_weight']
    self.user_embedding = nn.Embedding(self.n_users, self.embedding_size)
    self.entity_embedding = nn.Embedding(self.n_entities, self.embedding_size)
    self.relation_embedding = nn.Embedding((self.n_relations + 1), self.embedding_size)
    kg_graph = dataset.kg_graph(form='coo', value_field='relation_id')
    (adj_entity, adj_relation) = self.construct_adj(kg_graph)
    (self.adj_entity, self.adj_relation) = (adj_entity.to(self.device), adj_relation.to(self.device))
    inter_feat = dataset.dataset.inter_feat.values
    pos_users = torch.from_numpy(inter_feat[:, 0])
    pos_items = torch.from_numpy(inter_feat[:, 1])
    pos_label = torch.ones(pos_items.shape)
    (pos_interaction_table, self.offset) = self.get_interaction_table(pos_users, pos_items, pos_label)
    self.interaction_table = self.sample_neg_interaction(pos_interaction_table, self.offset)
    self.softmax = nn.Softmax(dim=(- 1))
    self.linear_layers = torch.nn.ModuleList()
    for i in range(self.n_iter):
        self.linear_layers.append(nn.Linear((self.embedding_size if (not (self.aggregator_class == 'concat')) else (self.embedding_size * 2)), self.embedding_size))
    self.ReLU = nn.ReLU()
    self.Tanh = nn.Tanh()
    self.bce_loss = nn.BCEWithLogitsLoss()
    self.l2_loss = EmbLoss()
    self.apply(xavier_normal_initialization)
def __init__(self, config, dataset):
    super(KGNNLS, self).__init__(config, dataset)
    self.embedding_size = config['embedding_size']
    self.neighbor_sample_size = config['neighbor_sample_size']
    self.aggregator_class = config['aggregator']
    self.n_iter = config['n_iter']
    self.reg_weight = config['reg_weight']
    self.ls_weight = config['ls_weight']
    self.user_embedding = nn.Embedding(self.n_users, self.embedding_size)
    self.entity_embedding = nn.Embedding(self.n_entities, self.embedding_size)
    self.relation_embedding = nn.Embedding((self.n_relations + 1), self.embedding_size)
    kg_graph = dataset.kg_graph(form='coo', value_field='relation_id')
    (adj_entity, adj_relation) = self.construct_adj(kg_graph)
    (self.adj_entity, self.adj_relation) = (adj_entity.to(self.device), adj_relation.to(self.device))
    inter_feat = dataset.dataset.inter_feat.values
    pos_users = torch.from_numpy(inter_feat[:, 0])
    pos_items = torch.from_numpy(inter_feat[:, 1])
    pos_label = torch.ones(pos_items.shape)
    (pos_interaction_table, self.offset) = self.get_interaction_table(pos_users, pos_items, pos_label)
    self.interaction_table = self.sample_neg_interaction(pos_interaction_table, self.offset)
    self.softmax = nn.Softmax(dim=(- 1))
    self.linear_layers = torch.nn.ModuleList()
    for i in range(self.n_iter):
        self.linear_layers.append(nn.Linear((self.embedding_size if (not (self.aggregator_class == 'concat')) else (self.embedding_size * 2)), self.embedding_size))
    self.ReLU = nn.ReLU()
    self.Tanh = nn.Tanh()
    self.bce_loss = nn.BCEWithLogitsLoss()
    self.l2_loss = EmbLoss()
    self.apply(xavier_normal_initialization)