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();
}
Aggregations