def main(args):
    exp_path = args["exp_path"]
    isTraining = args["isTraining"]
    model_name = args["model_name"]

    if isTraining:
        data_path = "data/Train"
        rel_path = "../Corpus/TDT2/Train/QDRelevanceTDT2_forHMMOutSideTrain"
    else:
        data_path = "data/Test"
        rel_path = "../Corpus/TDT2/AssessmentTrainSet/AssessmentTrainSet.txt"

    # Read data
    with open(data_path + "/qry_IDs.pkl", "rb") as f:
        qry_IDs = pickle.load(f)
    with open(data_path + "/doc_IDs.pkl", "rb") as f:
        doc_IDs = pickle.load(f)

    qry_tf = np.load(data_path + "/x_qry_tf_mdl.npy")
    doc = np.load(data_path + "/doc_mdl.npy")

    #mean = np.load(exp_path + "/mean.npy")
    #stdv = np.load(exp_path + "/stdv.npy")
    #valid_idx = np.nonzero(stdv)

    # Load model
    model = load_model(exp_path + "/" + model_name)
    # Evaluation
    evaluate_model = EvaluateModel(rel_path, isTraining)

    with tf.device('/device:GPU:0'):
        # Train
        #qry_tf[:, valid_idx] = (qry_tf[:, valid_idx] - mean[valid_idx]) / stdv[valid_idx]
        rel_mdl = model.predict(qry_tf)
        #rel_mdl = rel_mdl * stdv[-1] + mean[-1]

    qry_docs_ranking = cosineFast(rel_mdl, qry_IDs, doc, doc_IDs)
    mAP = evaluate_model.mAP(qry_docs_ranking)
    print(mAP)
Exemple #2
0
for eqe_list in EQE2:
    query_model, query_model_dict = eqe_list
    qry_mdl, qry_IDs = query_model
    # pseudo relevance feedback (swm)
    for step in range(2):
        # kl divergence
        query_result = np.dot(qry_mdl, np.log(doc_mdl.T))
        result = np.argsort(-query_result, axis=1)
        query_docs_point_dict = defaultdict(dict)

        for q_idx in xrange(len(qry_IDs)):
            docs_ranking = []
            for doc_idx in result[q_idx]:
                docs_ranking.append(doc_IDs[doc_idx])
            query_docs_point_dict[qry_IDs[q_idx]] = docs_ranking
        mAP = evaluate_model.mAP(query_docs_point_dict)
        mAP_list.append(mAP)
        print "mAP"
        print mAP

        if step < 1:
            # save one-shot result
            Pickle.dump(query_model_dict, open("model/query_model.pkl", "wb"),
                        True)
            Pickle.dump(query_docs_point_dict,
                        open("model/query_docs_point_dict.pkl", "wb"), True)
        # load one-shot result
        query_docs_point_fb = Pickle.load(
            open("model/query_docs_point_dict.pkl", "rb"))
        query_model_fb = Pickle.load(open("model/query_model.pkl", "rb"))
        # swm