Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: fix layer error in GCMC (issue 1631) #1635

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion recbole/config/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def _merge_external_config_dict(self):
self.external_config_dict = external_config_dict

def _get_model_and_dataset(self, model, dataset):

if model is None:
try:
model = self.external_config_dict["model"]
Expand Down
1 change: 0 additions & 1 deletion recbole/data/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ def _discretization(self):
dis_info = {}

if self.config["discretization"]:

dis_info = self.config["discretization"]

for field in dis_info.keys():
Expand Down
4 changes: 0 additions & 4 deletions recbole/evaluator/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,13 @@ def eval_batch_collect(
positive_i(Torch.Tensor): the positive item id for each user.
"""
if self.register.need("rec.items"):

# get topk
_, topk_idx = torch.topk(
scores_tensor, max(self.topk), dim=-1
) # n_users x k
self.data_struct.update_tensor("rec.items", topk_idx)

if self.register.need("rec.topk"):

_, topk_idx = torch.topk(
scores_tensor, max(self.topk), dim=-1
) # n_users x k
Expand All @@ -169,7 +167,6 @@ def eval_batch_collect(
self.data_struct.update_tensor("rec.topk", result)

if self.register.need("rec.meanrank"):

desc_scores, desc_index = torch.sort(scores_tensor, dim=-1, descending=True)

# get the index of positive items in the ranking list
Expand All @@ -188,7 +185,6 @@ def eval_batch_collect(
self.data_struct.update_tensor("rec.meanrank", result)

if self.register.need("rec.score"):

self.data_struct.update_tensor("rec.score", scores_tensor)

if self.register.need("data.label"):
Expand Down
1 change: 0 additions & 1 deletion recbole/evaluator/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class Register(object):
"""

def __init__(self, config):

self.config = config
self.metrics = [metric.lower() for metric in self.config["metrics"]]
self._build_register()
Expand Down
1 change: 0 additions & 1 deletion recbole/model/context_aware_recommender/fignn.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def __init__(self, config, dataset):
self.apply(self._init_weights)

def fignn_layer(self, in_feature):

emb_feature = self.att_embedding(in_feature)
emb_feature = self.dropout_layer(emb_feature)
# multi-head self-attention network
Expand Down
1 change: 0 additions & 1 deletion recbole/model/context_aware_recommender/fm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class FM(ContextRecommender):
"""Factorization Machine considers the second-order interaction with features to predict the final score."""

def __init__(self, config, dataset):

super(FM, self).__init__(config, dataset)

# define layers and loss
Expand Down
1 change: 0 additions & 1 deletion recbole/model/general_recommender/dmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def _init_weights(self, module):
normal_(module.weight.data, 0, 0.01)

def forward(self, user, item):

user = self.get_user_embedding(user)

# Following lines construct tensor of shape [B,n_users] using the tensor of shape [B,H]
Expand Down
2 changes: 1 addition & 1 deletion recbole/model/general_recommender/gcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def forward(self, user_X, item_X):
v_hidden = self.dropout(v_hidden)

u_hidden = self.dense_layer_u(u_hidden)
v_hidden = self.dense_layer_u(v_hidden)
v_hidden = self.dense_layer_v(v_hidden)

u_outputs = self.dense_activate(u_hidden)
v_outputs = self.dense_activate(v_hidden)
Expand Down
1 change: 0 additions & 1 deletion recbole/model/general_recommender/itemknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def compute_similarity(self, method, block_size=100):

# Compute all similarities using vectorization
while start_block < end_local:

end_block = min(start_block + block_size, end_local)
this_block_size = end_block - start_block

Expand Down
5 changes: 0 additions & 5 deletions recbole/model/general_recommender/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def get_used_ids(self):
return cur

def sampler(self, key_ids):

key_ids = np.array(key_ids.cpu())
key_num = len(key_ids)
total_num = key_num
Expand Down Expand Up @@ -121,14 +120,12 @@ def get_user_id_list(self):
return np.arange(1, self.n_users)

def forward(self, h, t):

h_embedding = self.user_embedding(h)
t_embedding = self.item_embedding(t)

return torch.sum(h_embedding.mul(t_embedding), dim=1)

def context_forward(self, h, t, field):

if field == "uu":
h_embedding = self.user_embedding(h)
t_embedding = self.item_context_embedding(t)
Expand All @@ -139,7 +136,6 @@ def context_forward(self, h, t, field):
return torch.sum(h_embedding.mul(t_embedding), dim=1)

def calculate_loss(self, interaction):

user = interaction[self.USER_ID]
pos_item = interaction[self.ITEM_ID]
neg_item = interaction[self.NEG_ITEM_ID]
Expand Down Expand Up @@ -178,7 +174,6 @@ def calculate_loss(self, interaction):
)

def predict(self, interaction):

user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]

Expand Down
3 changes: 0 additions & 3 deletions recbole/model/general_recommender/macridvae.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def reparameterize(self, mu, logvar):
return mu

def forward(self, rating_matrix):

cores = F.normalize(self.k_embedding.weight, dim=1)
items = F.normalize(self.item_embedding.weight, dim=1)

Expand Down Expand Up @@ -127,7 +126,6 @@ def forward(self, rating_matrix):
return logits, mulist, logvarlist

def calculate_loss(self, interaction):

user = interaction[self.USER_ID]

rating_matrix = self.get_rating_matrix(user)
Expand Down Expand Up @@ -169,7 +167,6 @@ def reg_loss(self):
return loss_1 + loss_2 + loss_3

def predict(self, interaction):

user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]

Expand Down
4 changes: 0 additions & 4 deletions recbole/model/general_recommender/multidae.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def mlp_layers(self, layer_dims):
return nn.Sequential(*mlp_modules)

def forward(self, rating_matrix):

h = F.normalize(rating_matrix)

h = F.dropout(h, self.drop_out, training=self.training)
Expand All @@ -64,7 +63,6 @@ def forward(self, rating_matrix):
return self.decoder(h)

def calculate_loss(self, interaction):

user = interaction[self.USER_ID]

rating_matrix = self.get_rating_matrix(user)
Expand All @@ -77,7 +75,6 @@ def calculate_loss(self, interaction):
return ce_loss

def predict(self, interaction):

user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]

Expand All @@ -88,7 +85,6 @@ def predict(self, interaction):
return scores[[torch.arange(len(item)).to(self.device), item]]

def full_sort_predict(self, interaction):

user = interaction[self.USER_ID]

rating_matrix = self.get_rating_matrix(user)
Expand Down
3 changes: 0 additions & 3 deletions recbole/model/general_recommender/multivae.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def reparameterize(self, mu, logvar):
return mu

def forward(self, rating_matrix):

h = F.normalize(rating_matrix)

h = F.dropout(h, self.drop_out, training=self.training)
Expand All @@ -83,7 +82,6 @@ def forward(self, rating_matrix):
return z, mu, logvar

def calculate_loss(self, interaction):

user = interaction[self.USER_ID]
rating_matrix = self.get_rating_matrix(user)

Expand All @@ -108,7 +106,6 @@ def calculate_loss(self, interaction):
return ce_loss + kl_loss

def predict(self, interaction):

user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]

Expand Down
2 changes: 0 additions & 2 deletions recbole/model/general_recommender/ngcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def get_ego_embeddings(self):
return ego_embeddings

def forward(self):

A_hat = (
self.sparse_dropout(self.norm_adj_matrix)
if self.node_dropout != 0
Expand Down Expand Up @@ -195,7 +194,6 @@ def calculate_loss(self, interaction):
return mf_loss + self.reg_weight * reg_loss

def predict(self, interaction):

user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]

Expand Down
4 changes: 0 additions & 4 deletions recbole/model/general_recommender/ract.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def reparameterize(self, mu, logvar):
return mu

def forward(self, rating_matrix):

t = F.normalize(rating_matrix)

h = F.dropout(t, self.drop_out, training=self.training) * (1 - self.drop_out)
Expand All @@ -127,7 +126,6 @@ def forward(self, rating_matrix):
return z, mu, logvar

def calculate_actor_loss(self, interaction):

user = interaction[self.USER_ID]
rating_matrix = self.get_rating_matrix(user)

Expand Down Expand Up @@ -211,7 +209,6 @@ def calculate_ac_loss(self, interaction):
return -1 * y

def calculate_loss(self, interaction):

# actor_pretrain
if self.train_stage == "actor_pretrain":
return self.calculate_actor_loss(interaction).mean()
Expand All @@ -223,7 +220,6 @@ def calculate_loss(self, interaction):
return self.calculate_ac_loss(interaction).mean()

def predict(self, interaction):

user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]

Expand Down
5 changes: 0 additions & 5 deletions recbole/model/knowledge_aware_recommender/mcclk.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self, item_only=False, attention=True):
def forward(
self, entity_emb, user_emb, relation_emb, edge_index, edge_type, inter_matrix
):

from torch_scatter import scatter_softmax, scatter_mean

n_entities = entity_emb.shape[0]
Expand Down Expand Up @@ -169,7 +168,6 @@ def edge_sampling(self, edge_index, edge_type, rate=0.5):
return edge_index[:, random_indices], edge_type[random_indices]

def forward(self, user_emb, entity_emb):

# node dropout
if self.node_dropout_rate > 0.0:
edge_index, edge_type = self.edge_sampling(
Expand Down Expand Up @@ -263,7 +261,6 @@ def build_adj(self, context, topk):
return L_norm

def _build_graph_separately(self, entity_emb):

# node dropout
if self.node_dropout_rate > 0.0:
edge_index, edge_type = self.edge_sampling(
Expand Down Expand Up @@ -455,7 +452,6 @@ def get_edges(self, graph):
return index.to(self.device), type.to(self.device)

def forward(self):

user_emb = self.user_embedding.weight
entity_emb = self.entity_embedding.weight
# Construct a k-Nearest-Neighbor item-item semantic graph and Structural View Encoder
Expand Down Expand Up @@ -503,7 +499,6 @@ def sim(self, z1: torch.Tensor, z2: torch.Tensor):
return torch.mm(z1, z2.t())

def calculate_loss(self, interaction):

if self.restore_user_e is not None or self.restore_item_e is not None:
self.restore_user_e, self.restore_item_e = None, None

Expand Down
3 changes: 0 additions & 3 deletions recbole/model/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ def __init__(
hidden_act="gelu",
layer_norm_eps=1e-12,
):

super(TransformerEncoder, self).__init__()
layer = TransformerLayer(
n_heads,
Expand Down Expand Up @@ -825,7 +824,6 @@ def __init__(
hidden_act="gelu",
layer_norm_eps=1e-12,
):

super(LightTransformerEncoder, self).__init__()
layer = LightTransformerLayer(
n_heads,
Expand Down Expand Up @@ -1354,7 +1352,6 @@ class FMFirstOrderLinear(nn.Module):
"""

def __init__(self, config, dataset, output_dim=1):

super(FMFirstOrderLinear, self).__init__()
self.field_names = dataset.fields(
source=[
Expand Down
1 change: 0 additions & 1 deletion recbole/model/sequential_recommender/dien.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _init_weights(self, module):
constant_(module.bias.data, 0)

def forward(self, user, item_seq, neg_item_seq, item_seq_len, next_items):

max_length = item_seq.shape[1]
# concatenate the history item seq with the target item to get embedding together
item_seq_next_item = torch.cat(
Expand Down
1 change: 0 additions & 1 deletion recbole/model/sequential_recommender/din.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def _init_weights(self, module):
constant_(module.bias.data, 0)

def forward(self, user, item_seq, item_seq_len, next_items):

max_length = item_seq.shape[1]
# concatenate the history item seq with the target item to get embedding together
item_seq_next_item = torch.cat((item_seq, next_items.unsqueeze(1)), dim=-1)
Expand Down
6 changes: 0 additions & 6 deletions recbole/model/sequential_recommender/fossil.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def inverse_seq_item_embedding(self, seq_item_embedding, seq_item_len):
return short_item_embedding

def reg_loss(self, user_embedding, item_embedding, seq_output):

reg_1 = self.reg_weight
loss_1 = (
reg_1 * torch.norm(user_embedding, p=2)
Expand All @@ -103,12 +102,10 @@ def reg_loss(self, user_embedding, item_embedding, seq_output):
return loss_1

def init_weights(self, module):

if isinstance(module, nn.Embedding) or isinstance(module, nn.Linear):
xavier_normal_(module.weight.data)

def forward(self, seq_item, seq_item_len, user):

seq_item_embedding = self.item_embedding(seq_item)

high_order_seq_item_embedding = self.inverse_seq_item_embedding(
Expand Down Expand Up @@ -152,7 +149,6 @@ def get_similarity(self, seq_item_embedding, seq_item_len):
return similarity

def calculate_loss(self, interaction):

seq_item = interaction[self.ITEM_SEQ]
user = interaction[self.USER_ID]
seq_item_len = interaction[self.ITEM_SEQ_LEN]
Expand All @@ -176,7 +172,6 @@ def calculate_loss(self, interaction):
return loss + self.reg_loss(user_lambda, pos_items_embedding, seq_output)

def predict(self, interaction):

item_seq = interaction[self.ITEM_SEQ]
item_seq_len = interaction[self.ITEM_SEQ_LEN]
test_item = interaction[self.ITEM_ID]
Expand All @@ -187,7 +182,6 @@ def predict(self, interaction):
return scores

def full_sort_predict(self, interaction):

item_seq = interaction[self.ITEM_SEQ]
user = interaction[self.USER_ID]
item_seq_len = interaction[self.ITEM_SEQ_LEN]
Expand Down
Loading