-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reproduction script for "End-to-End Retrieval with Learned Dense …
…and Sparse Representations Using Lucene" (#2317)
- Loading branch information
1 parent
2ebc11c
commit 1ebe6dd
Showing
5 changed files
with
211 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Anserini: A toolkit for reproducible information retrieval research built on Lucene | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import yaml | ||
from typing import Union, Dict, List, Optional, Any | ||
import os | ||
import subprocess | ||
TOPIC_NAMES = ['msmarco-passage-dev-subset', 'dl19-passage', 'dl20-passage'] | ||
EVAL_CMD_MAP = { | ||
'map': '-m map -c -l 2', # AP | ||
'ndcg_cut_10': '-m ndcg_cut.10 -c', # nDCG@10 | ||
'recall_1000_msmarco': '-c -m recall.1000', # R@1000 for MS MARCO | ||
'recall_1000': '-m recall.1000 -c -l 2', # R@1000 | ||
'recip_rank': '-c -M 10 -m recip_rank' # RR@10 | ||
} | ||
TOPIC_EVAL_MAP = { | ||
'msmarco-passage-dev-subset': ['recip_rank', 'recall_1000_msmarco'], | ||
'dl19-passage': ['map', 'ndcg_cut_10', 'recall_1000'], | ||
'dl20-passage': ['map', 'ndcg_cut_10', 'recall_1000'] | ||
} | ||
|
||
|
||
def get_output_run_file_name(topic: str, name: str): | ||
return f'runs/{topic}_{name}.txt' | ||
|
||
|
||
def get_search_command(model_name: str, cmd_template: str, topics: List[str]): | ||
outputs = [get_output_run_file_name( | ||
topic_name, model_name) for topic_name in TOPIC_NAMES] | ||
|
||
for topic, output in zip(topics, outputs): | ||
cmd = cmd_template.format(topic=topic, output=output) | ||
yield cmd | ||
|
||
|
||
def get_eval_command(param: str, qrel: str, run_file: str, cmd_template: str): | ||
cmd = cmd_template.format( | ||
param=param, qrel=qrel, output=run_file) | ||
yield cmd | ||
|
||
|
||
def main(config): | ||
# print all search commands | ||
for model_name, model_config in config['collections'].items(): | ||
print("running model: ", model_name) | ||
# # search | ||
# for cmd in get_search_command(model_name, model_config['search_command'], model_config['topics']): | ||
# p = subprocess.Popen( | ||
# cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
# stdout, stderr = p.communicate() | ||
# if stderr: | ||
# print(stderr.decode('utf-8')) | ||
|
||
# eval | ||
expected_results = model_config['results'] | ||
run_files = [get_output_run_file_name( | ||
topic_name, model_name) for topic_name in TOPIC_NAMES] | ||
eval_cmd = model_config['eval_command'] | ||
metric_precision = model_config['metric_precision'] | ||
|
||
for run_file, topic_name, qrel in zip(run_files, TOPIC_NAMES, model_config['qrels']): | ||
for metric in TOPIC_EVAL_MAP[topic_name]: | ||
for cmd in get_eval_command(EVAL_CMD_MAP[metric], qrel, run_file, eval_cmd): | ||
p = subprocess.Popen( | ||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = p.communicate() | ||
stdout = [out.strip() | ||
for out in stdout.decode('utf-8').split('\t')] | ||
actual_result = round(float(stdout[-1]), metric_precision) | ||
expected_result = expected_results[topic_name][metric] | ||
assert actual_result == expected_result, f'{model_name} {topic_name} {metric} {actual_result} != {expected_result}, expected: {expected_results[topic_name]}' | ||
print( | ||
f"{topic_name} {metric} {actual_result} == {expected_result}") | ||
print(f"{model_name} passed!") | ||
print("="*50) | ||
|
||
|
||
if __name__ == '__main__': | ||
with open('src/main/resources/e2e_sparse_dense_lucene/pre-encoded.yaml') as f: | ||
config = yaml.load(f, Loader=yaml.FullLoader) | ||
main(config) |
78 changes: 78 additions & 0 deletions
78
src/main/resources/e2e_sparse_dense_lucene/pre-encoded.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
collections: | ||
bm25: | ||
name: bm25 | ||
search_command: target/appassembler/bin/SearchCollection -index msmarco-v1-passage -topicReader TsvInt -topics {topic} -output {output} -bm25 -parallelism 12 | ||
topics: | ||
- tools/topics-and-qrels/topics.msmarco-passage.dev-subset.txt | ||
- tools/topics-and-qrels/topics.dl19-passage.txt | ||
- tools/topics-and-qrels/topics.dl20.txt | ||
qrels: | ||
- tools/topics-and-qrels/qrels.msmarco-passage.dev-subset.txt | ||
- tools/topics-and-qrels/qrels.dl19-passage.txt | ||
- tools/topics-and-qrels/qrels.dl20-passage.txt | ||
|
||
eval_command: tools/eval/trec_eval.9.0.4/trec_eval {param} {qrel} {output} | ||
results: | ||
msmarco-passage-dev-subset: | ||
recip_rank: 0.184 | ||
recall_1000_msmarco: 0.853 | ||
dl19-passage: | ||
map: 0.301 | ||
ndcg_cut_10: 0.506 | ||
recall_1000: 0.750 | ||
dl20-passage: | ||
map: 0.286 | ||
ndcg_cut_10: 0.480 | ||
recall_1000: 0.786 | ||
metric_precision: 3 | ||
cosdpr-distil: | ||
name: cosdpr-distil | ||
search_command: target/appassembler/bin/SearchHnswDenseVectors -index msmarco-v1-passage-cos-dpr-distil -topicReader TsvInt -topics {topic} -output {output} -generator VectorQueryGenerator -topicField title -threads 12 -hits 1000 -efSearch 1000 -encoder CosDprDistil | ||
topics: | ||
- tools/topics-and-qrels/topics.msmarco-passage.dev-subset.txt | ||
- tools/topics-and-qrels/topics.dl19-passage.txt | ||
- tools/topics-and-qrels/topics.dl20.txt | ||
qrels: | ||
- tools/topics-and-qrels/qrels.msmarco-passage.dev-subset.txt | ||
- tools/topics-and-qrels/qrels.dl19-passage.txt | ||
- tools/topics-and-qrels/qrels.dl20-passage.txt | ||
eval_command: tools/eval/trec_eval.9.0.4/trec_eval {param} {qrel} {output} | ||
results: | ||
msmarco-passage-dev-subset: | ||
recip_rank: 0.389 | ||
recall_1000_msmarco: 0.975 | ||
dl19-passage: | ||
map: 0.466 | ||
ndcg_cut_10: 0.725 | ||
recall_1000: 0.822 | ||
dl20-passage: | ||
map: 0.487 | ||
ndcg_cut_10: 0.703 | ||
recall_1000: 0.852 | ||
metric_precision: 3 | ||
splade-pp-ed: | ||
name: splade-pp-ed | ||
search_command: target/appassembler/bin/SearchCollection -index msmarco-v1-passage-splade-pp-ed -topicReader TsvInt -topics {topic} -output {output} -impact -pretokenized -parallelism 12 -encoder SpladePlusPlusEnsembleDistil | ||
topics: | ||
- tools/topics-and-qrels/topics.msmarco-passage.dev-subset.txt | ||
- tools/topics-and-qrels/topics.dl19-passage.txt | ||
- tools/topics-and-qrels/topics.dl20.txt | ||
qrels: | ||
- tools/topics-and-qrels/qrels.msmarco-passage.dev-subset.txt | ||
- tools/topics-and-qrels/qrels.dl19-passage.txt | ||
- tools/topics-and-qrels/qrels.dl20-passage.txt | ||
eval_command: tools/eval/trec_eval.9.0.4/trec_eval {param} {qrel} {output} | ||
results: | ||
msmarco-passage-dev-subset: | ||
recip_rank: 0.383 | ||
recall_1000_msmarco: 0.983 | ||
dl19-passage: | ||
map: 0.505 | ||
ndcg_cut_10: 0.731 | ||
recall_1000: 0.873 | ||
dl20-passage: | ||
map: 0.500 | ||
ndcg_cut_10: 0.720 | ||
recall_1000: 0.900 | ||
metric_precision: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters