Search in sources :

Example 1 with RankNet

use of Ranker.RankNet in project IR_Base by Linda-sunshine.

the class L2RMetricLearning method L2RModelTraining.

protected void L2RModelTraining() {
    // select the training pairs
    createTrainingCorpus();
    if (m_ranker == 0) {
        ArrayList<Feature[]> fvs = new ArrayList<Feature[]>();
        ArrayList<Integer> labels = new ArrayList<Integer>();
        for (_Query q : m_queries) q.extractPairs4RankSVM(fvs, labels);
        Model rankSVM = SVM.libSVMTrain(fvs, labels, RankFVSize, SolverType.L2R_L1LOSS_SVC_DUAL, m_tradeoff, -1);
        m_weights = rankSVM.getFeatureWeights();
        System.out.format("RankSVM training performance:\nMAP: %.4f\n", evaluate(OptimizationType.OT_MAP));
    } else if (m_ranker == 1) {
        // all the rest use LambdaRank with different evaluator
        LambdaRank lambdaRank;
        if (m_multithread) {
            /**
             ** multi-thread version ***
             */
            lambdaRank = new LambdaRankParallel(RankFVSize, m_tradeoff, m_queries, OptimizationType.OT_MAP, 10);
            lambdaRank.setSigns(getRankingFVSigns());
            // lambdaRank specific parameters
            lambdaRank.train(100, 100, 1.0, 0.95);
        } else {
            /**
             ** single-thread version ***
             */
            lambdaRank = new LambdaRank(RankFVSize, m_tradeoff, m_queries, OptimizationType.OT_MAP);
            lambdaRank.setSigns(getRankingFVSigns());
            // lambdaRank specific parameters
            lambdaRank.train(300, 20, 1.0, 0.98);
        }
        m_weights = lambdaRank.getWeights();
    } else if (m_ranker == 2) {
        RankNet ranknet = new RankNet(RankFVSize, 5.0);
        ArrayList<double[]> rfvs = new ArrayList<double[]>();
        for (_Query q : m_queries) q.extractPairs4RankNet(rfvs);
        ranknet.setSigns(getRankingFVSigns());
        double likelihood = ranknet.train(rfvs);
        m_weights = ranknet.getWeights();
        System.out.format("RankNet training performance:\nlog-likelihood: %.4f\t MAP: %.4f\n", likelihood, evaluate(OptimizationType.OT_MAP));
    }
    for (int i = 0; i < RankFVSize; i++) System.out.format("%.5f ", m_weights[i]);
    System.out.println();
}
Also used : structures._Query(structures._Query) ArrayList(java.util.ArrayList) LambdaRankParallel(Ranker.LambdaRankParallel) Feature(Classifier.supervised.liblinear.Feature) LambdaRank(Ranker.LambdaRank) RankNet(Ranker.RankNet) Model(Classifier.supervised.liblinear.Model)

Aggregations

Feature (Classifier.supervised.liblinear.Feature)1 Model (Classifier.supervised.liblinear.Model)1 LambdaRank (Ranker.LambdaRank)1 LambdaRankParallel (Ranker.LambdaRankParallel)1 RankNet (Ranker.RankNet)1 ArrayList (java.util.ArrayList)1 structures._Query (structures._Query)1