owner, usernum, itemnum, batch_size=args.batch_size, n_workers=1) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) model = Model(usernum, itemnum, args) sess.run(tf.initialize_all_variables()) best_valid_auc = 0.5 best_iter = 0 for i in range(args.maximum_epochs): for _ in range(oneiteration / args.batch_size): batch = sampler.next_train_batch() batch_u, batch_i, batch_j, batch_oi, batch_oj = batch _, train_loss, train_auc = sess.run( (model.gds, model.loss, model.auc), { model.batch_u: batch_u, model.batch_i: batch_i, model.batch_j: batch_j, model.batch_oi: batch_oi, model.batch_oj: batch_oj }) print train_loss, train_auc if i % 10 == 0: f.write('#iter %d: loss %f, train auc %f \n' % (i, train_loss, train_auc)) _valid_auc = 0.0
class LossHistory(keras.callbacks.Callback): def on_train_begin(self, logs={}): self.losses = 0.0 def on_batch_end(self, batch, logs={}): self.losses += logs.get('loss') for i in range(args.maximum_epochs): history = LossHistory() loss = 0.0 for _ in range(int(oneiteration / args.batch_size)): batch_u, batch_i, batch_j, batch_oi, batch_oj = sampler.next_train_batch( ) if (args.alg == 'posneg'): labels = [0] * len(batch_u) margin = np.full(len(batch_u), 0.2) hist = model.fit([ np.array(batch_u), np.array(batch_i), np.array(batch_j), np.array(batch_oi), np.array(batch_oj), margin ], labels, batch_size=args.batch_size, verbose=0,