Download benchmark/fusion.py from WalidAlHassan/embeddingModelRnD: direct link, hf CLI and curl.
- Browser
- Download file 435 Bytes
-
https://huggingface.co/WalidAlHassan/embeddingModelRnD/resolve/main/benchmark/fusion.py
- Command line
-
hf download hf://WalidAlHassan/embeddingModelRnD/benchmark/fusion.py
-
curl -L -o fusion.py https://huggingface.co/WalidAlHassan/embeddingModelRnD/resolve/main/benchmark/fusion.py
435 Bytes
| """Reciprocal Rank Fusion for combining multiple ranked-id lists.""" | |
| def reciprocal_rank_fusion(rankings, k=60): | |
| """rankings: list of ranked-id lists (best first). Returns a single fused ranking.""" | |
| scores = {} | |
| for ranking in rankings: | |
| for rank, doc_id in enumerate(ranking, start=1): | |
| scores[doc_id] = scores.get(doc_id, 0.0) + 1.0 / (k + rank) | |
| return sorted(scores, key=scores.get, reverse=True) | |