def _get_embed_ncf(self): user_max = self._config["user_max"] ncf = NeuralCF(user_count=user_max, item_count=self._config["movie_max"], class_num=self._config["rate_dim"], hidden_layers=[20, 10], include_mf=False) loaded = ncf.load_model(self._config["ncf_model_path"]) user_embed = loaded.get_weights()[0] item_embed = loaded.get_weights()[1] user_dict = {} for i in range(1, self._config["user_max"] + 1): user_dict[i] = user_embed[i][:] item_dict = {} for i in range(1, self._config["movie_max"] + 1): item_dict[i] = item_embed[i][:] return (user_dict, item_dict)
ncf = NeuralCF(user_count=max_user_id, item_count=max_movie_id, class_num=5, hidden_layers=[20, 10], include_mf = False) ncf.compile(optimizer= "adam", loss= "sparse_categorical_crossentropy", metrics=['accuracy']) ncf.fit(train_rdd, nb_epoch= 10, batch_size= 8000, validation_data=val_rdd) ncf.save_model("../save_model/movie_ncf.zoomodel", over_write=True) # weights = ncf.get_weights() # print(weights) print(len(weights)) for i, weight in enumerate(weights): print(i) print(weight.shape) # loaded = ncf.load_model("../save_model/movie_ncf.zoomodel") user_embed = loaded.get_weights()[0] print(user_embed.shape) # item_embed = loaded.get_weights()[1] print(item_embed.shape)