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

Add support for FinMTEB benchmark #1379

Open
wants to merge 7 commits into
base: v2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions mteb/abstasks/AbsTaskClassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AbsTaskClassification(AbsTask):
"""

abstask_prompt = "Classify user passages."
sentence_column: str = "text"


def __init__(
self,
Expand Down Expand Up @@ -138,7 +140,7 @@ def _evaluate_subset(
)
# Bootstrap `self.samples_per_label` samples per label for each split
X_sampled, y_sampled, idxs = self._undersample_data(
train_split["text"], # type: ignore
train_split[self.sentence_column], # type: ignore
train_split["label"], # type: ignore
self.samples_per_label,
idxs,
Expand All @@ -148,7 +150,7 @@ def _evaluate_subset(
evaluator = kNNClassificationEvaluator(
X_sampled,
y_sampled,
eval_split["text"], # type: ignore
eval_split[self.sentence_column], # type: ignore
eval_split["label"], # type: ignore
task_name=self.metadata.name,
encode_kwargs=encode_kwargs,
Expand All @@ -158,7 +160,7 @@ def _evaluate_subset(
evaluator = kNNClassificationEvaluatorPytorch(
X_sampled,
y_sampled,
eval_split["text"], # type: ignore
eval_split[self.sentence_column], # type: ignore
eval_split["label"], # type: ignore
task_name=self.metadata.name,
encode_kwargs=encode_kwargs,
Expand All @@ -168,7 +170,7 @@ def _evaluate_subset(
evaluator = logRegClassificationEvaluator(
X_sampled,
y_sampled,
eval_split["text"], # type: ignore
eval_split[self.sentence_column], # type: ignore
eval_split["label"], # type: ignore
task_name=self.metadata.name,
encode_kwargs=encode_kwargs,
Expand Down Expand Up @@ -243,16 +245,16 @@ def _calculate_metrics_from_split(
self, split: str, hf_subset: str | None = None, compute_overall: bool = False
) -> ClassificationDescriptiveStatistics:
if hf_subset:
text = self.dataset[hf_subset][split]["text"]
text = self.dataset[hf_subset][split][self.sentence_column]
label = self.dataset[hf_subset][split]["label"]
elif compute_overall:
text = []
label = []
for hf_subset in self.metadata.eval_langs:
text.extend(self.dataset[hf_subset][split]["text"])
text.extend(self.dataset[hf_subset][split][self.sentence_column])
label.extend(self.dataset[hf_subset][split]["label"])
else:
text = self.dataset[split]["text"]
text = self.dataset[split][self.sentence_column]
label = self.dataset[split]["label"]

total_text_len = sum([len(t) for t in text])
Expand Down
18 changes: 10 additions & 8 deletions mteb/abstasks/AbsTaskPairClassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class AbsTaskPairClassification(AbsTask):
"""

abstask_prompt = "Retrieve text that are semantically similar to the given text."
sentence_1_column: str = "sentence1"
sentence_2_column: str = "sentence2"

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -63,8 +65,8 @@ def _evaluate_subset(
"sentence_transformers.evaluation.PairClassificationEvaluator"
).setLevel(logging.WARN)
evaluator = PairClassificationEvaluator(
data_split["sentence1"],
data_split["sentence2"],
data_split[self.sentence_1_column],
data_split[self.sentence_2_column],
data_split["labels"],
task_name=self.metadata.name,
**kwargs,
Expand Down Expand Up @@ -93,14 +95,14 @@ def _calculate_metrics_from_split(
dataset = self.dataset[split]

sentence1 = (
dataset["sentence1"][0]
if len(dataset["sentence1"]) == 1
else dataset["sentence1"]
dataset[self.sentence_1_column][0]
if len(dataset[self.sentence_1_column]) == 1
else dataset[self.sentence_1_column]
)
sentence2 = (
dataset["sentence2"][0]
if len(dataset["sentence2"]) == 1
else dataset["sentence2"]
dataset[self.sentence_2_column][0]
if len(dataset[self.sentence_2_column]) == 1
else dataset[self.sentence_2_column]
)
labels = (
dataset["labels"][0] if len(dataset["labels"]) == 1 else dataset["labels"]
Expand Down
22 changes: 14 additions & 8 deletions mteb/abstasks/AbsTaskSTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class AbsTaskSTS(AbsTask):
"""

abstask_prompt = "Retrieve semantically similar text."
sentence_1_column: str = "sentence1"
sentence_2_column: str = "sentence2"

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -56,8 +58,8 @@ def normalize(x):

normalized_scores = list(map(normalize, data_split["score"]))
evaluator = STSEvaluator(
data_split["sentence1"],
data_split["sentence2"],
data_split[self.sentence_1_column],
data_split[self.sentence_2_column],
normalized_scores,
task_name=self.metadata.name,
**kwargs,
Expand All @@ -74,20 +76,24 @@ def _calculate_metrics_from_split(
self, split: str, hf_subset: str | None = None, compute_overall: bool = False
) -> STSDescriptiveStatistics:
if hf_subset:
sentence1 = self.dataset[hf_subset][split]["sentence1"]
sentence2 = self.dataset[hf_subset][split]["sentence2"]
sentence1 = self.dataset[hf_subset][split][self.sentence_1_column]
sentence2 = self.dataset[hf_subset][split][self.sentence_2_column]
score = self.dataset[hf_subset][split]["score"]
elif compute_overall:
sentence1 = []
sentence2 = []
score = []
for hf_subset in self.metadata.eval_langs:
sentence1.extend(self.dataset[hf_subset][split]["sentence1"])
sentence2.extend(self.dataset[hf_subset][split]["sentence2"])
sentence1.extend(
self.dataset[hf_subset][split][self.sentence_1_column]
)
sentence2.extend(
self.dataset[hf_subset][split][self.sentence_2_column]
)
score.extend(self.dataset[hf_subset][split]["score"])
else:
sentence1 = self.dataset[split]["sentence1"]
sentence2 = self.dataset[split]["sentence2"]
sentence1 = self.dataset[split][self.sentence_1_column]
sentence2 = self.dataset[split][self.sentence_2_column]
score = self.dataset[split]["score"]

total_sentence1_len = sum([len(s) for s in sentence1])
Expand Down
23 changes: 15 additions & 8 deletions mteb/abstasks/AbsTaskSummarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class AbsTaskSummarization(AbsTask):
"Given a news summary, retrieve other semantically similar summaries."
)

reference_summaries_column: str = "human_summaries"
generated_summaries_column: str = "machine_summaries"

def __init__(self, **kwargs):
super().__init__(**kwargs)

Expand All @@ -66,8 +69,8 @@ def _evaluate_subset(
for x in data_split["relevance"]
]
evaluator = self.evalutor(
machine_summaries=data_split["machine_summaries"],
human_summaries=data_split["human_summaries"],
machine_summaries=data_split[self.generated_summaries_column],
human_summaries=data_split[self.reference_summaries_column],
texts=data_split["text"],
gold_scores=normalized_scores,
task_name=self.metadata.name,
Expand All @@ -85,8 +88,12 @@ def _calculate_metrics_from_split(
) -> SummarizationDescriptiveStatistics:
if hf_subset:
text = self.dataset[hf_subset][split]["text"]
human_summaries = self.dataset[hf_subset][split]["human_summaries"]
machine_summaries = self.dataset[hf_subset][split]["machine_summaries"]
human_summaries = self.dataset[hf_subset][split][
self.reference_summaries_column
]
machine_summaries = self.dataset[hf_subset][split][
self.generated_summaries_column
]
relevance = self.dataset[hf_subset][split]["relevance"]
elif compute_overall:
text = []
Expand All @@ -97,16 +104,16 @@ def _calculate_metrics_from_split(
for hf_subset in self.metadata.eval_langs:
text.extend(self.dataset[hf_subset][split]["text"])
human_summaries.extend(
self.dataset[hf_subset][split]["human_summaries"]
self.dataset[hf_subset][split][self.reference_summaries_column]
)
machine_summaries.extend(
self.dataset[hf_subset][split]["machine_summaries"]
self.dataset[hf_subset][split][self.generated_summaries_column]
)
relevance.extend(self.dataset[hf_subset][split]["relevance"])
else:
text = self.dataset[split]["text"]
human_summaries = self.dataset[split]["human_summaries"]
machine_summaries = self.dataset[split]["machine_summaries"]
human_summaries = self.dataset[split][self.reference_summaries_column]
machine_summaries = self.dataset[split][self.generated_summaries_column]
relevance = self.dataset[split]["relevance"]

total_text_len = sum(len(x) for x in text)
Expand Down
Loading
Loading