Skip to content

Instantly share code, notes, and snippets.

@VcamX
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VcamX/0fe7cfc544caed82b107 to your computer and use it in GitHub Desktop.
Save VcamX/0fe7cfc544caed82b107 to your computer and use it in GitHub Desktop.
The Process of Updating MSet and Training Model
int main() {
/*
* Process of scoring and updating Xapian::MSet
*/
Xapian::Letor letor;
// Suppose we're using svm ranker
Xapian::SVMRanker ranker;
// Choose features we need
std::vector<Feature::FeatureBase> features {
FEATURE_1,
FEATURE_2,
FEATURE_3,
FEATURE_4,
FEATURE_5,
FEATURE_6,
FEATURE_7,
FEATURE_8,
FEATURE_9,
FEATURE_10,
FEATURE_11,
FEATURE_12,
FEATURE_13,
FEATURE_14,
FEATURE_15,
FEATURE_16,
FEATURE_17,
FEATURE_18,
FEATURE_19
};
Xapian::Database database;
Xapian::Query query;
Xapian::MSet mset;
// Update information of features
ranker.update(features);
// Update context of letor
letor.update_context(database, ranker, features);
// Load model file for ranker
letor.load_model_file("model_file");
// Generate letor module information and attach to mset
letor.update_mset(query, mset);
// For now, the mset will contain the new information
/*
* Process of training
*/
Xapian::Letor letor;
// Suppose we're using svm ranker
Xapian::SVMRanker ranker;
// Choose features we need
std::vector<Feature::FeatureBase> features {
FEATURE_1,
FEATURE_2,
FEATURE_3,
FEATURE_4,
FEATURE_5,
FEATURE_6,
FEATURE_7,
FEATURE_8,
FEATURE_9,
FEATURE_10,
FEATURE_11,
FEATURE_12,
FEATURE_13,
FEATURE_14,
FEATURE_15,
FEATURE_16,
FEATURE_17,
FEATURE_18,
FEATURE_19
};
Xapian::Database database;
Xapian::Query query;
Xapian::MSet mset;
// Update information of features
ranker.update(features);
// Update context of letor
letor.update_context(database, ranker, features);
// Train the model
letor.train("training_data_filename", "model_file");
// The model will be saved in 'model_file'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment