예제 #1
0
    def train(self):
        self.train_dataset, \
        self.test_dataset = self.data_process.generate_data(batch_size=self.batch_size,
                                                            epoch=self.epoch)

        autoint = AutoInt(user_num=self.user_num,
                          movie_num=self.movie_num,
                          year_num=self.year_num,
                          genre_num=self.genre_num,
                          embedding_size=self.embedding_size,
                          att_embedding_size=16,
                          head_num=2,
                          att_layer_num=3,
                          use_res=True)

        autoint_model = autoint.get_autoint_model()
        autoint_model.summary()
        autoint_model.compile(optimizer="adam",
                              loss=keras.losses.binary_crossentropy,
                              metrics=["accuracy"])

        autoint_model.fit(self.train_dataset,
                          epochs=self.epoch,
                          steps_per_epoch=1270010 // self.batch_size + 1,
                          callbacks=[
                              get_callback(self.test_dataset, self.model_path,
                                           self.version)
                          ])
예제 #2
0
    def train(self):
        self.train_dataset, \
        self.test_dataset = self.data_process.generate_data(batch_size=self.batch_size,
                                                            epoch=self.epoch)

        fm = FM(user_num=self.user_num,
                movie_num=self.movie_num,
                year_num=self.year_num,
                genre_num=self.genre_num,
                embedding_size=self.embedding_size,
                is_sigmoid=True)

        fm_model = fm.get_fm_model()
        fm_model.summary()
        fm_model.compile(optimizer="adam",
                         loss=keras.losses.binary_crossentropy,
                         metrics=["accuracy"])

        fm_model.fit(self.train_dataset,
                     epochs=self.epoch,
                     steps_per_epoch=1270010 // self.batch_size + 1,
                     callbacks=[
                         get_callback(self.test_dataset, self.model_path,
                                      self.version)
                     ])
                                embedding_dim=embedding_size,
                                embedding_name='movie_id'),
                     maxlen=20),
    VarLenSparseFeat(SparseFeat("user_recent_click_labels",
                                vocabulary_size=genre_num,
                                embedding_dim=embedding_size,
                                embedding_name='current_label'),
                     maxlen=20),
    VarLenSparseFeat(SparseFeat("user_like_genres",
                                vocabulary_size=genre_num,
                                embedding_dim=embedding_size,
                                embedding_name='current_label'),
                     maxlen=2),
]

dnn_feature_columns = feature_columns
linear_feature_columns = feature_columns

feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns)

model = WDL(linear_feature_columns, dnn_feature_columns, task='binary')
model.summary()
model.compile(optimizer="adam",
              loss=keras.losses.binary_crossentropy,
              metrics=["accuracy"])

model.fit(train_dataset,
          epochs=epoch,
          steps_per_epoch=1270010 // batch_size + 1,
          callbacks=[get_callback(test_dataset, model_path, version)])
예제 #4
0
                                embedding_dim=embedding_size,
                                embedding_name='movie_id'),
                     maxlen=20),
    VarLenSparseFeat(SparseFeat("user_recent_click_labels",
                                vocabulary_size=genre_num,
                                embedding_dim=embedding_size,
                                embedding_name='current_label'),
                     maxlen=20),
    VarLenSparseFeat(SparseFeat("user_like_genres",
                                vocabulary_size=genre_num,
                                embedding_dim=embedding_size,
                                embedding_name='current_label'),
                     maxlen=2),
]

dnn_feature_columns = feature_columns
linear_feature_columns = feature_columns

feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns)

model = DeepFM(linear_feature_columns, dnn_feature_columns, task='binary')
model.summary()
model.compile(optimizer="adam",
              loss=keras.losses.binary_crossentropy,
              metrics=["accuracy"])

model.fit(train_dataset,
          epochs=epoch,
          steps_per_epoch=1270010 // batch_size + 1,
          callbacks=[get_callback(test_dataset, model_path)])