Fix issue of storing too many docs during IR-eval.: Maintain topk with heaps #1715
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the current version, the
InformationRetrievalEvaluator
and theutil.semantic_search
accumulates all the docs in each top-k retrieved chunk in the query results:sentence-transformers/sentence_transformers/evaluation/InformationRetrievalEvaluator.py
Lines 162 to 173 in a8cebb2
sentence-transformers/sentence_transformers/util.py
Lines 218 to 222 in a36e6f1
In other words, the
queries_result_list
will hold #trunks * top-K docs for each query instead of just top-K. This will result in a very severe memory burden for a large corpus, e.g. 60GB+ when evaluating on MS MARCO. One could do some simulation about how large RAM it could use:This PR fixes the issue by maintaining exactly top-K docs with heaps efficiently during the whole retrieval process. A test has been made to make sure the new code yields the same final results / scores:
https://colab.research.google.com/drive/1ibA6hjfXKsl97L1wA_FlT1HnVFhnRw0L?usp=sharing