-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
from rankify.dataset.dataset import Document, Question, Answer, Context
from rankify.retrievers.retriever import Retriever
from rankify.models.reranking import Reranking
from rankify.metrics.metrics import Metrics
# Sample Documents
documents = [
Document(question=Question("the cast of a good day to die hard?"), answers=Answer([
"Jai Courtney",
"Sebastian Koch",
"Radivoje Bukvić",
"Yuliya Snigir",
"Sergei Kolesnikov",
"Mary Elizabeth Winstead",
"Bruce Willis"
]), contexts=[]),
Document(question=Question("Who wrote Hamlet?"), answers=Answer(["Shakespeare"]), contexts=[])
]
# BM25 retrieval on Wikipedia
bm25_retriever_wiki = Retriever(method="bm25", n_docs=5, index_type="wiki")
retrieved_documents = bm25_retriever_wiki.retrieve(documents)
# Initialize the reranker
reranker = Reranking(method='upr', model_name='t5-base')
# Apply reranking
reranked_documents = reranker.rank(retrieved_documents)
metrics = Metrics(reranked_documents)
# Calculate retrieval metrics before reranking
before_ranking_metrics = metrics.calculate_retrieval_metrics(ks=[1, 5, 10, 20, 50, 100], use_reordered=False)
print(f"Before Ranking : {before_ranking_metrics}")
# Calculate retrieval metrics after reranking
after_ranking_metrics = metrics.calculate_retrieval_metrics(ks=[1, 5, 10, 20, 50, 100], use_reordered=True)
print(f"After Ranking : {after_ranking_metrics}")
# Calculate retrieval metrics after reranking
after_ranking_metrics_ndcg = metrics.calculate_trec_metrics(ndcg_cuts=[1, 5, 10, 20, 50, 100], use_reordered=True)
print(after_ranking_metrics)
Logs
Oct 16, 2025 6:26:59 PM org.apache.lucene.store.MemorySegmentIndexInputProvider <init>
INFO: Using MemorySegmentIndexInput with Java 21; to disable start with -Dorg.apache.lucene.store.MMapDirectory.enableMemorySegments=false
Retrieving 2 documents with BM25...
Batch search: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1[/1](http://144.25.31.124:8473/1) [00:00<00:00, 17.46it[/s](http://144.25.31.124:8473/s)]
Processing documents: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2[/2](http://144.25.31.124:8473/2) [00:00<00:00, 273.21it[/s](http://144.25.31.124:8473/s)]
Reranking Documents: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2[/2](http://144.25.31.124:8473/2) [00:00<00:00, 25.33it[/s](http://144.25.31.124:8473/s)]
Before Ranking : {'top_1': 100.0, 'top_5': 100.0, 'top_10': 100.0, 'top_20': 100.0, 'top_50': 100.0, 'top_100': 100.0}
After Ranking : {'top_1': 100.0, 'top_5': 100.0, 'top_10': 100.0, 'top_20': 100.0, 'top_50': 100.0, 'top_100': 100.0}
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
Error running `trec_eval`: Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/eval/trec_eval.py", line 79, in <module>
args[-2] = get_qrels_file(args[-2])
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/aamita/miniconda3/envs/rerank_rankify/lib/python3.11/site-packages/pyserini/search/_base.py", line 717, in get_qrels_file
target_path = JRelevanceJudgments.getQrelsPath(JPath.of(qrels.path)).toString()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "jnius/jnius_export_class.pxi", line 896, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 1062, in jnius.JavaMethod.call_staticmethod
File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
java.io.IOException: Error downloading topics from https://raw.githubusercontent.com/castorini/anserini-tools/master/topics-and-qrels/qrels.dl19-passage.txt
io.anserini.eval.RelevanceJudgments.downloadQrels(RelevanceJudgments.java:203)
io.anserini.eval.RelevanceJudgments.getQrelsPath(RelevanceJudgments.java:178)
{'ndcg@1': 0.0, 'ndcg@5': 0.0, 'ndcg@10': 0.0, 'ndcg@20': 0.0, 'ndcg@50': 0.0, 'ndcg@100': 0.0, 'map@100': 0.0, 'mrr@10': 0.0}
Metadata
Metadata
Assignees
Labels
No labels