From 8906f8999e0fd99a8f5e968ea34894e1a5cbad8a Mon Sep 17 00:00:00 2001 From: Lin zihan <893833413@qq.com> Date: Sat, 18 Jul 2020 16:30:44 +0800 Subject: [PATCH] FIX: check nfm --- model/context_aware_recommender/nfm.py | 6 ++++-- properties/model/NFM.config | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 properties/model/NFM.config diff --git a/model/context_aware_recommender/nfm.py b/model/context_aware_recommender/nfm.py index e92ccd784..e9ff95c5b 100644 --- a/model/context_aware_recommender/nfm.py +++ b/model/context_aware_recommender/nfm.py @@ -40,7 +40,7 @@ def __init__(self, config, dataset): self.first_order_linear = FMFirstOrderLinear(self.field_dims, self.offsets) self.embedding = FMEmbedding(self.field_dims, self.offsets, self.embedding_size) self.fm = BaseFactorizationMachine(reduce_sum=False) - self.mlp_layers = MLPLayers(self.layers, self.dropout, activation='sigmoid') + self.mlp_layers = MLPLayers(size_list, self.dropout, activation='sigmoid') self.predict_layer = nn.Linear(self.mlp_hidden_size[-1], 1, bias=False) self.sigmoid = nn.Sigmoid() self.loss = nn.BCELoss() @@ -69,7 +69,9 @@ def forward(self, interaction): # todo: check (batch) or (batch, 1) x.append(interaction[field].unsqueeze(1)) x = torch.cat(x, dim=1) - y = self.predict_layer(self.mlp_layers(self.embedding(x)))+self.first_order_linear(x) + emb_x = self.fm(self.embedding(x)) + + y = self.predict_layer(self.mlp_layers(emb_x))+self.first_order_linear(x) y = self.sigmoid(y) return y.squeeze() diff --git a/properties/model/NFM.config b/properties/model/NFM.config new file mode 100644 index 000000000..c35263ed9 --- /dev/null +++ b/properties/model/NFM.config @@ -0,0 +1,5 @@ +[model] + +embedding_size=64 +mlp_hidden_size=[64, 64, 64] +dropout=0.0