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

MonoT5 Reranker assigning same score to every document #325

Open
Spongeorge opened this issue Apr 10, 2023 · 0 comments
Open

MonoT5 Reranker assigning same score to every document #325

Spongeorge opened this issue Apr 10, 2023 · 0 comments

Comments

@Spongeorge
Copy link

Spongeorge commented Apr 10, 2023

For some reason when using the monoT5 reranker class to rerank results from a LuceneSearcher it assigns the same score to every document.

I was able to fix this problem by changing a line in the rescore() method in pygaggle.rerank.transformer.MonoT5 from
for doc, score in zip(batch.documents, batch_log_probs): doc.score = score
to
for i, doc in enumerate(batch.documents): score = batch_log_probs[i] texts[i].score = score

Full method for reference:

def rescore(self, query: Query, texts: List[Text]) -> List[Text]:
        texts = deepcopy(texts)
        batch_input = QueryDocumentBatch(query=query, documents=texts)
        for batch in self.tokenizer.traverse_query_document(batch_input):
            with torch.cuda.amp.autocast(enabled=self.use_amp):
                input_ids = batch.output['input_ids'].to(self.device)
                attn_mask = batch.output['attention_mask'].to(self.device)
                _, batch_scores = greedy_decode(self.model,
                                                input_ids,
                                                length=1,
                                                attention_mask=attn_mask,
                                                return_last_logits=True)

                batch_scores = batch_scores[:, [self.token_false_id, self.token_true_id]]
                batch_scores = torch.nn.functional.log_softmax(batch_scores, dim=1)
                batch_log_probs = batch_scores[:, 1].tolist()
            for doc, score in zip(batch.documents, batch_log_probs):
                doc.score = score
                

        return texts
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

No branches or pull requests

1 participant