| 32 | |
| 33 | |
| 34 | def eval(sess, test_file, model, model_path, batch_size, maxlen, best_auc = [1.0]): |
| 35 | print("Testing starts------------") |
| 36 | data_load_test= DataLoader(test_file, 'test_sample', batch_size, 4 ) |
| 37 | producer1 = threading.Thread(target=data_load_test.data_read, args=(0,2)) |
| 38 | producer2 = threading.Thread(target=data_load_test.data_read, args=(1,2)) |
| 39 | producer1.start() |
| 40 | producer2.start() |
| 41 | loss_sum = 0. |
| 42 | accuracy_sum = 0. |
| 43 | aux_loss_sum = 0. |
| 44 | iterations = 0 |
| 45 | stored_arr = [] |
| 46 | |
| 47 | for data in data_load_test.next(): |
| 48 | iterations +=1 |
| 49 | user_id, item_id, cate_id,shop_id, node_id, product_id, brand_id, \ |
| 50 | label, hist_item, hist_cate, hist_shop, hist_node, hist_product, \ |
| 51 | hist_brand, hist_mask, neg_hist_item, neg_hist_cate, \ |
| 52 | neg_hist_shop, neg_hist_node, neg_hist_product, neg_hist_brand = data |
| 53 | target = label |
| 54 | prob, loss, acc, aux_loss = model.calculate(sess, [user_id, item_id, \ |
| 55 | cate_id, shop_id, node_id, product_id, brand_id, \ |
| 56 | hist_item, hist_cate, hist_shop, hist_node, hist_product, hist_brand, \ |
| 57 | neg_hist_item, neg_hist_cate, neg_hist_shop, neg_hist_node, neg_hist_product, neg_hist_brand, hist_mask, label]) |
| 58 | loss_sum += loss |
| 59 | aux_loss_sum = aux_loss |
| 60 | accuracy_sum += acc |
| 61 | prob_1 = prob[:, 0].tolist() |
| 62 | target_1 = target[:, 0].tolist() |
| 63 | # user_l = user_id.tolist() |
| 64 | for p ,t in zip(prob_1, target_1): |
| 65 | stored_arr.append([p, t]) |
| 66 | |
| 67 | #test_auc = calc_gauc(stored_arr, user_l) |
| 68 | test_auc = calc_auc(stored_arr) |
| 69 | accuracy_sum = accuracy_sum / iterations |
| 70 | loss_sum = loss_sum / iterations |
| 71 | aux_loss_sum = aux_loss_sum / iterations |
| 72 | if best_auc[0] < test_auc: |
| 73 | best_auc[0] = test_auc |
| 74 | model.save(sess, model_path) |
| 75 | producer1.join() |
| 76 | producer2.join() |
| 77 | return test_auc, loss_sum, accuracy_sum, aux_loss_sum, best_auc[0] |
| 78 | |
| 79 | def train( |
| 80 | train_file, |