-
Notifications
You must be signed in to change notification settings - Fork 302
[wwb] Update reranker/embedder tests #2983
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||||||||
| from PIL import Image | ||||||||||||
| import torch | ||||||||||||
| import torch.nn.functional as F | ||||||||||||
| from sklearn.metrics.pairwise import cosine_similarity | ||||||||||||
|
|
||||||||||||
| import numpy as np | ||||||||||||
| from sentence_transformers import SentenceTransformer, util | ||||||||||||
|
|
@@ -189,9 +190,10 @@ def evaluate(self, data_gold, data_prediction): | |||||||||||
| with open(prediction, 'rb') as f: | ||||||||||||
| prediction_data = np.load(f) | ||||||||||||
|
|
||||||||||||
| cos_sim = F.cosine_similarity(torch.from_numpy(gold_data), torch.from_numpy(prediction_data)) | ||||||||||||
| metric_per_passages.append(cos_sim.detach().numpy()) | ||||||||||||
| metric_per_gen.append(torch.mean(cos_sim).item()) | ||||||||||||
| cos_sim_all = cosine_similarity(gold_data, prediction_data) | ||||||||||||
| cos_sim = np.diag(cos_sim_all) | ||||||||||||
| metric_per_passages.append(cos_sim) | ||||||||||||
| metric_per_gen.append(np.mean(cos_sim)) | ||||||||||||
|
|
||||||||||||
| metric_dict = {"similarity": np.mean(metric_per_gen)} | ||||||||||||
| return metric_dict, {"similarity": metric_per_gen, "similarity_per_passages": metric_per_passages} | ||||||||||||
|
|
@@ -222,11 +224,11 @@ def evaluate(self, data_gold, data_prediction): | |||||||||||
| scores_diff = self.MISSING_DOCUMENT_PENALTY | ||||||||||||
| if document_idx in prediction_scores: | ||||||||||||
| scores_diff = abs(gold_score - prediction_scores[document_idx]) | ||||||||||||
| per_query_text.append(scores_diff) | ||||||||||||
| per_query_text.append(scores_diff.item()) | ||||||||||||
|
||||||||||||
| per_query_text.append(scores_diff.item()) | |
| if isinstance(scores_diff, torch.Tensor): | |
| per_query_text.append(scores_diff.item()) | |
| else: | |
| per_query_text.append(scores_diff) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -658,7 +658,7 @@ def print_embeds_results(evaluator): | |||||
| ) | ||||||
| logger.info(f"Top-{i+1} example:") | ||||||
| logger.info("## Passages num:\n%s\n", len(e["passages"])) | ||||||
| logger.info("## Similarity:\n%s\n", e["similarity"]) | ||||||
| logger.info(f"## Similarity:\n{e['similarity']:.5}\n") | ||||||
|
|
||||||
|
|
||||||
| def read_cb_config(path): | ||||||
|
|
@@ -687,8 +687,8 @@ def print_rag_results(evaluator): | |||||
| logger.info(f"Top-{i+1} example:") | ||||||
| logger.info("## Query:\n%s\n", e["query"]) | ||||||
| logger.info("## Passages num:\n%s\n", len(e["passages"])) | ||||||
| logger.info("## Similarity:\n%s\n", e["similarity"]) | ||||||
| logger.info("## Top_n scores:\n%s\n", e["per_text_score_list"]) | ||||||
| logger.info(f"## Similarity:\n{e['similarity']:.5}\n") | ||||||
| logger.info("## Difference in scores pre texts:\n%s\n", e['per_text_scores_diff']) | ||||||
|
||||||
| logger.info("## Difference in scores pre texts:\n%s\n", e['per_text_scores_diff']) | |
| logger.info("## Difference in scores per texts:\n%s\n", e['per_text_scores_diff']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
file_typeor remove from arguments