Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching mono run file, loading the cache file for duo runs #176

Merged
merged 7 commits into from
May 28, 2021

Conversation

wongalvis14
Copy link
Contributor

@wongalvis14 wongalvis14 commented Apr 10, 2021

Correctness tested by matching metrics on small dev set.
Mono cache will include the rankings of all texts, so for subsequent duo runs any number of hits would work.

Ran in hydra, Python 3.8.8

@@ -213,6 +218,8 @@ def evaluate(self,
mono_out = self.mono_reranker.rerank(example.query, example.documents)
mono_texts.append(sorted(enumerate(mono_out), key=lambda x: x[1].score, reverse=True)[:self.mono_hits])
scores.append(np.array([x.score for x in mono_out]))
if self.mono_cache_writer is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the line below is equivalent and more concise.

Suggested change
if self.mono_cache_writer is not None:
if self.mono_cache_writer:

Copy link
Member

@rodrigonogueira4 rodrigonogueira4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wongalvis14 wongalvis14 changed the title Write mono run file during duo to specified dir WIP: Write mono run file during duo to specified dir Apr 16, 2021
@wongalvis14
Copy link
Contributor Author

The part left WIP is "Loading the 'cache' run file"

Although the rankings in the run file are preserved when loaded, their scores are not recorded in the run file. When the metrics are calculated (called "accumulated" in the code), the document rankings are deduced from the sorted order of the scores. As a result, if the number of documents reranked in the duo stage is n, any document beyond the nth will have a score of 0 and the metrics beyond the nth documents will be inaccurate.

I wonder if there is an alternate format of a run file that records the score, or if there is an existing method to inject the scores based on their pre-existing ranking in a list of documents.

wip

Fix metric calculation logic when loading mono cache file
@wongalvis14
Copy link
Contributor Author

Update: When calculating the recall/precision metrics, any document after the top_k'th will be assigned a score of 0 (to indicate "false"), which is the same as the default score when loaded from a run file. Then, only the documents with a non-zero scores will be treated as "true" (i.e. within top_k'th). So I changed the score to indicate "false" to -1. This fixed the issue.

@wongalvis14
Copy link
Contributor Author

It was working until I merged the branches recently. I suspect that it was due to changing rerank to rescore. Right now, if we change rescore back to rerank in Mono and Duo, it'll work just like before. But if we change them to rerank, even if we sort them, they (a single mono + duo run, and a duo run with cached mono run results) will give different results.

@wongalvis14 wongalvis14 changed the title WIP: Write mono run file during duo to specified dir Write mono run file during duo to specified dir May 28, 2021
@wongalvis14 wongalvis14 changed the title Write mono run file during duo to specified dir Caching mono run file, loading the cache file for duo runs May 28, 2021
pygaggle/data/msmarco.py Outdated Show resolved Hide resolved
Copy link
Member

@ronakice ronakice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Merging.

@ronakice ronakice merged commit 79fb937 into castorini:master May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants