An open source, non-profit web search engine
New learning to rank dataset
Daoud Clarke66f79be3fd6f
diff --git a/devdata/rankeval-2026-04/learning-to-rank.csv.gz b/devdata/rankeval-2026-04/learning-to-rank.csv.gznew file mode 100644index 0000000..59537c3Binary files /dev/null and b/devdata/rankeval-2026-04/learning-to-rank.csv.gz differdiff --git a/devdata/rankeval-2026-04/model.pickle b/devdata/rankeval-2026-04/model.picklenew file mode 100644index 0000000..56f1de9Binary files /dev/null and b/devdata/rankeval-2026-04/model.pickle differdiff --git a/mwmbl/rankeval/evaluation/evaluate.py b/mwmbl/rankeval/evaluation/evaluate.pyindex 107222c..97a16a1 100644--- a/mwmbl/rankeval/evaluation/evaluate.py+++ b/mwmbl/rankeval/evaluation/evaluate.py@@ -2,6 +2,7 @@Perform an evaluation using NDCG against a gold standard set of results."""from abc import ABC, abstractmethod+import timeimport numpy as npimport pandas as pd@@ -32,11 +33,12 @@ def evaluate(ranking_model: RankingModel, fraction: float = 1.0, use_test=False)# TODO:# - output feature importances from XGBoost# - experiment with more features-if use_test:- dataset = pd.read_csv(RANKINGS_DATASET_TEST_PATH)+ path = RANKINGS_DATASET_TEST_PATHelse:- dataset = pd.read_csv(RANKINGS_DATASET_TRAIN_PATH)+ path = RANKINGS_DATASET_TRAIN_PATH+ print("Evaluating against dataset", path)+ dataset = pd.read_csv(path)ndcg_scores = []proportions = []@@ -49,6 +51,8 @@ def evaluate(ranking_model: RankingModel, fraction: float = 1.0, use_test=False)else:random_queries = set(queries)+ wiki_counts = []+ durations = []for query, rankings in dataset.groupby('query'):if query not in random_queries:continue@@ -58,7 +62,10 @@ def evaluate(ranking_model: RankingModel, fraction: float = 1.0, use_test=False)scores = top_ranked.set_index('url')['score'].to_dict()print(f"Query: '{query}'", scores)+ start_time = time.perf_counter()predicted_urls = ranking_model.predict(query)+ end_time = time.perf_counter()+print("Predicted", predicted_urls)top_urls = predicted_urls[:NUM_RESULTS_FOR_EVAL]y_true = [scores.get(url, 0.0) for url in top_urls] + [0.0] * (10 - len(top_urls))@@ -73,12 +80,23 @@ def evaluate(ranking_model: RankingModel, fraction: float = 1.0, use_test=False)score = ndcg_score([y_true], [y_predicted])ndcg_scores.append(score)+ wiki_count = sum(1 for url in top_urls if "en.wikipedia.org" in url)+ wiki_counts.append(wiki_count)+ durations.append(end_time - start_time)+print("ndcg_score_mean: ", np.mean(ndcg_scores))print("ndcg_score_sem:", sem(ndcg_scores))print()print("proportion_score_mean:", np.mean(proportions))print("proportion_score_sem:", sem(proportions))+ print()+ print("wiki_count_mean:", np.mean(wiki_counts))+ print("wiki_count_sem:", sem(wiki_counts))+ print()+ print("predict_time_mean:", np.mean(durations))+ print("predict_time_sem:", sem(durations))- print("Dataset\tFraction\tNDCG\tSEM\tProportion\tSEM")+ print("Dataset\tFraction\tNDCG\tSEM\tProportion\tSEM\tWiki Count\tSEM\tPredict time\tSEM")print(f"{'Test' if use_test else 'Train'}\t{fraction}\t{np.mean(ndcg_scores)}\t{sem(ndcg_scores)}\t"- f"{np.mean(proportions)}\t{sem(proportions)}")+ f"{np.mean(proportions)}\t{sem(proportions)}\t{np.mean(wiki_counts)}\t{sem(wiki_counts)}"+ f"\t{np.mean(durations)}\t{sem(durations)}")diff --git a/mwmbl/rankeval/evaluation/evaluate_remote.py b/mwmbl/rankeval/evaluation/evaluate_remote.pyindex 1a2b96f..8c8b8e3 100644--- a/mwmbl/rankeval/evaluation/evaluate_remote.py+++ b/mwmbl/rankeval/evaluation/evaluate_remote.py@@ -30,19 +30,22 @@ def run():# ranker = HeuristicAndWikiRanker(RemoteIndex(), DummyCompleter())model = pickle.load(open(MODEL_PATH, 'rb'))- ranker = LTRRanker(RemoteIndex(), DummyCompleter(), model, 1000, True, 5)+ ranker = LTRRanker(RemoteIndex(), DummyCompleter(), model, 1000, True, 3)# ranker = HeuristicRanker(RemoteIndex(), DummyCompleter())+ # ranker = HeuristicAndWikiRanker(RemoteIndex(), DummyCompleter(), max_wiki_results=3)model = MwmblRankingModel(ranker)- evaluate(model, fraction=0.01, use_test=False)+ evaluate(model, fraction=0.1, use_test=False)def single_query(query: str):- ranker = HeuristicAndWikiRanker(RemoteIndex(), DummyCompleter())+ model = pickle.load(open(MODEL_PATH, 'rb'))+ ranker = LTRRanker(RemoteIndex(), DummyCompleter(), model, 1000, True, 3)+ # ranker = HeuristicAndWikiRanker(RemoteIndex(), DummyCompleter())results = ranker.search(query, [])for result in results:print(result)if __name__ == '__main__':- run()- # single_query("beethoven - wikipedia")+ # run()+ single_query("how to implement raft consensus in rust")diff --git a/mwmbl/rankeval/ltr/evaluate.py b/mwmbl/rankeval/ltr/evaluate.pyindex df8c580..898de52 100644--- a/mwmbl/rankeval/ltr/evaluate.py+++ b/mwmbl/rankeval/ltr/evaluate.py@@ -27,7 +27,7 @@ PREDICTORS = {'xgb': make_pipeline(FeatureExtractor(), ThresholdPredictor(0.0, XGBClassifier(scale_pos_weight=0.1, reg_lambda=2))),'xgb_limit_terms': RankingPredictor(FeatureExtractor(), ThresholdPredictor(0.0, XGBClassifier(scale_pos_weight=0.1, reg_lambda=2))),'xgb_regressor': make_pipeline(FeatureExtractor(), XGBRegressor(objective="reg:pseudohubererror")),- 'xgb_ranker': make_pipeline(FeatureExtractor(), XGBRanker(objective="rank:map", reg_lambda=2)),+ 'xgb_ranker': make_pipeline(FeatureExtractor(), XGBRanker(objective="rank:ndcg", reg_lambda=2)),}diff --git a/mwmbl/rankeval/paths.py b/mwmbl/rankeval/paths.pyindex 27ab7f7..4b054f2 100644--- a/mwmbl/rankeval/paths.py+++ b/mwmbl/rankeval/paths.py@@ -2,6 +2,7 @@ import osfrom pathlib import PathROOT_DIR = Path(__file__).parent.parent.parent+OLD_DATA_DIR = ROOT_DIR / 'devdata' / 'rankeval-2024-06'DATA_DIR = ROOT_DIR / 'devdata' / 'rankeval-2026-04'QUERIES_DATASET_PATH = DATA_DIR / 'queries.csv'diff --git a/mwmbl/tinysearchengine/rank.py b/mwmbl/tinysearchengine/rank.pyindex 7750fc6..db834d7 100644--- a/mwmbl/tinysearchengine/rank.py+++ b/mwmbl/tinysearchengine/rank.py@@ -316,13 +316,18 @@ class HeuristicRanker(Ranker):if len(results) == 0:return []- wiki_results = [result for result in results if result.state == DocumentState.FROM_WIKI]- wiki_urls = {result.url for result in wiki_results}- other_results = [result for result in results if result.url not in wiki_urls]- results_and_scores = [(score_result(terms, result, is_complete), result) for result in other_results]+ # wiki_results = [result for result in results if result.state == DocumentState.FROM_WIKI]+ # wiki_urls = {result.url for result in wiki_results}+ # other_results = [result for result in results if result.url not in wiki_urls]+ # results_and_scores = [(score_result(terms, result, is_complete), result) for result in other_results]+ # ordered_results = sorted(results_and_scores, key=itemgetter(0), reverse=True)+ # filtered_results = [result for score, result in ordered_results if score > self.score_threshold]+ # return wiki_results + filtered_results++ results_and_scores = [(score_result(terms, result, is_complete), result) for result in results]ordered_results = sorted(results_and_scores, key=itemgetter(0), reverse=True)filtered_results = [result for score, result in ordered_results if score > self.score_threshold]- return wiki_results + filtered_results+ return filtered_resultsWIKI_SEARCH_API_URL = "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={query}&format=json"@@ -349,6 +354,7 @@ def get_wiki_results(s: str, max_wiki_results: int) -> list[Document]:response = session.get(WIKI_SEARCH_API_URL.format(query=escaped_query), headers=headers)try:wiki_response = response.json()+ print("Wiki response", json.dumps(wiki_response, indent=2))except json.JSONDecodeError:logger.exception(f"Failed to decode JSON response from Wikipedia API for query {s}, status: {response.status_code}, content: {response.content}")return []@@ -381,13 +387,11 @@ class HeuristicAndWikiRanker(HeuristicRanker):def search(self, s: str, additional_results: list[Document]) -> list[Document]:s_shortened = s[:MAX_QUERY_CHARS]- results = super().search(s_shortened, additional_results)+ wiki_results = get_wiki_results(s_shortened, self.max_wiki_results)+ results = super().search(s_shortened, additional_results=wiki_results)if len(results) == 0 and self.return_none_if_no_mwmbl_results:return []- wiki_results = get_wiki_results(s_shortened, self.max_wiki_results)-- return wiki_results + results-+ return results