-
Notifications
You must be signed in to change notification settings - Fork 313
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 Gene-MTEB tasks #1959
base: main
Are you sure you want to change the base?
Add Gene-MTEB tasks #1959
Changes from all commits
cbc474b
a539481
a5f8eda
816ede3
f9a8b36
fd36575
d465435
98a77cd
cdfacab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,254 @@ | ||||||
from __future__ import annotations | ||||||
|
||||||
from mteb.abstasks.AbsTaskClassification import AbsTaskClassification | ||||||
from mteb.abstasks.TaskMetadata import TaskMetadata | ||||||
|
||||||
|
||||||
class HumanMicrobiomeProjectDemonstrationClassificationDisease(AbsTaskClassification): | ||||||
metadata = TaskMetadata( | ||||||
name="HumanMicrobiomeProjectDemonstrationClassificationDisease", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very long title. I will appear very odd in the leaderboard. Would it be worth reducing it? |
||||||
description="A Classification task for predicting the disease from the Human Microbiome Project Demonstration dataset.", | ||||||
reference="https://huggingface.co/datasets/metagene-ai/HumanMicrobiomeProjectDemonstration/tree/main/hmpd/disease", | ||||||
dataset={ | ||||||
"path": "metagene-ai/HumanMicrobiomeProjectDemonstration", | ||||||
"name": "disease", | ||||||
"revision": "main", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to specify exact revision of your dataset |
||||||
}, | ||||||
type="Classification", | ||||||
category="s2s", | ||||||
modalities=["text"], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A text modality seems someone misleadering. It input is a string of base pairs right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keeping "text" here might be fine but it should be clear for the description. I would also make it clear in the task subtypes. |
||||||
eval_splits=["test"], | ||||||
eval_langs=["eng"], | ||||||
main_score="accuracy", | ||||||
date=("2009-10-09", "2012-11-22"), | ||||||
domains=["Medical"], | ||||||
task_subtypes=None, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
license="not specified", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No license? This can really limit how useable the task is |
||||||
annotations_creators="derived", | ||||||
dialect=[], | ||||||
sample_creation="found", | ||||||
bibtex_citation=""" | ||||||
@article{liu2025metagene, | ||||||
title={METAGENE-1: Metagenomic Foundation Model for Pandemic Monitoring}, | ||||||
author={Liu, Ollie and Jaghouar, Sami and Hagemann, Johannes and Wang, Shangshang and Wiemels, Jason and Kaufman, Jeff and Neiswanger, Willie}, | ||||||
journal={arXiv preprint arXiv:2501.02045}, | ||||||
year={2025} | ||||||
} | ||||||
""" | ||||||
) | ||||||
|
||||||
def __init__(self, **kwargs): | ||||||
super().__init__(**kwargs) | ||||||
self.method = "logReg" | ||||||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your tasks can be run with only a logreg? |
||||||
|
||||||
def load_data(self, **kwargs): | ||||||
if self.data_loaded: | ||||||
return | ||||||
|
||||||
from transformers.trainer_utils import set_seed | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move imports to start of file? |
||||||
set_seed(42) | ||||||
|
||||||
import datasets | ||||||
|
||||||
self.dataset = datasets.load_dataset(**self.metadata_dict["dataset"]) # type: ignore | ||||||
|
||||||
self.dataset_transform() | ||||||
|
||||||
full_train_dataset = self.dataset['train'] | ||||||
|
||||||
# by default, we undersample the training data to 8 samples per label | ||||||
desired_train_samples = 8 | ||||||
|
||||||
from collections import Counter | ||||||
label_counts = Counter(full_train_dataset['label']) | ||||||
M = min(label_counts.values()) | ||||||
if M < desired_train_samples: | ||||||
raise ValueError( | ||||||
f"Not enough samples per label to achieve {desired_train_samples} " | ||||||
f"training samples. The smallest label has only {M} samples." | ||||||
) | ||||||
test_size = 1 - (desired_train_samples / M) | ||||||
split_datasets = full_train_dataset.train_test_split( | ||||||
test_size=test_size, | ||||||
shuffle=True, | ||||||
seed=42) | ||||||
new_train_dataset = split_datasets['train'] | ||||||
new_test_dataset = split_datasets['test'] | ||||||
self.dataset = datasets.DatasetDict({ | ||||||
'train': new_train_dataset, | ||||||
'test': new_test_dataset | ||||||
}) | ||||||
Comment on lines
+70
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you upload dataset with these splits created directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or can you create function in this file that would be used in all tasks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would def. upload it directly (unless there is a very strong reason for doing otherwise) |
||||||
print(f"\nSplitting the data with test_size={test_size}") | ||||||
print(f"Train set size: {len(new_train_dataset)} rows") | ||||||
print(f"Test set size: {len(new_test_dataset)} rows\n") | ||||||
|
||||||
self.data_loaded = True | ||||||
|
||||||
def dataset_transform(self): | ||||||
self.dataset = self.dataset.rename_columns({"sequence": "text", "disease": "label"}) | ||||||
|
||||||
|
||||||
class HumanMicrobiomeProjectDemonstrationClassificationSex(AbsTaskClassification): | ||||||
metadata = TaskMetadata( | ||||||
name="HumanMicrobiomeProjectDemonstrationClassificationSex", | ||||||
description="A Classification task for predicting the sex from the Human Microbiome Project Demonstration dataset.", | ||||||
reference="https://huggingface.co/datasets/metagene-ai/HumanMicrobiomeProjectDemonstration/tree/main/hmpd/sex", | ||||||
dataset={ | ||||||
"path": "metagene-ai/HumanMicrobiomeProjectDemonstration", | ||||||
"name": "sex", | ||||||
"revision": "main", | ||||||
}, | ||||||
type="Classification", | ||||||
category="s2s", | ||||||
modalities=["text"], | ||||||
eval_splits=["test"], | ||||||
eval_langs=["eng"], | ||||||
main_score="accuracy", | ||||||
date=("2009-10-09", "2012-11-22"), | ||||||
domains=["Medical"], | ||||||
task_subtypes=None, | ||||||
license="not specified", | ||||||
annotations_creators="derived", | ||||||
dialect=[], | ||||||
sample_creation="found", | ||||||
bibtex_citation=""" | ||||||
@article{liu2025metagene, | ||||||
title={METAGENE-1: Metagenomic Foundation Model for Pandemic Monitoring}, | ||||||
author={Liu, Ollie and Jaghouar, Sami and Hagemann, Johannes and Wang, Shangshang and Wiemels, Jason and Kaufman, Jeff and Neiswanger, Willie}, | ||||||
journal={arXiv preprint arXiv:2501.02045}, | ||||||
year={2025} | ||||||
} | ||||||
""" | ||||||
) | ||||||
|
||||||
def __init__(self, **kwargs): | ||||||
super().__init__(**kwargs) | ||||||
self.method = "logReg" | ||||||
|
||||||
def load_data(self, **kwargs): | ||||||
if self.data_loaded: | ||||||
return | ||||||
|
||||||
from transformers.trainer_utils import set_seed | ||||||
set_seed(42) | ||||||
|
||||||
import datasets | ||||||
self.dataset = datasets.load_dataset(**self.metadata_dict["dataset"]) # type: ignore | ||||||
|
||||||
self.dataset_transform() | ||||||
|
||||||
full_train_dataset = self.dataset['train'] | ||||||
|
||||||
# by default, we undersample the training data to 8 samples per label | ||||||
desired_train_samples = 8 | ||||||
|
||||||
from collections import Counter | ||||||
label_counts = Counter(full_train_dataset['label']) | ||||||
M = min(label_counts.values()) | ||||||
if M < desired_train_samples: | ||||||
raise ValueError( | ||||||
f"Not enough samples per label to achieve {desired_train_samples} " | ||||||
f"training samples. The smallest label has only {M} samples." | ||||||
) | ||||||
test_size = 1 - (desired_train_samples / M) | ||||||
split_datasets = full_train_dataset.train_test_split( | ||||||
test_size=test_size, | ||||||
shuffle=True, | ||||||
seed=42) | ||||||
new_train_dataset = split_datasets['train'] | ||||||
new_test_dataset = split_datasets['test'] | ||||||
self.dataset = datasets.DatasetDict({ | ||||||
'train': new_train_dataset, | ||||||
'test': new_test_dataset | ||||||
}) | ||||||
print(f"\nSplitting the data with test_size={test_size}") | ||||||
print(f"Train set size: {len(new_train_dataset)} rows") | ||||||
print(f"Test set size: {len(new_test_dataset)} rows\n") | ||||||
|
||||||
self.data_loaded = True | ||||||
|
||||||
def dataset_transform(self): | ||||||
self.dataset = self.dataset.rename_columns({"sequence": "text", "host_sex": "label"}) | ||||||
|
||||||
|
||||||
class HumanMicrobiomeProjectDemonstrationClassificationSource(AbsTaskClassification): | ||||||
metadata = TaskMetadata( | ||||||
name="HumanMicrobiomeProjectDemonstrationClassificationSource", | ||||||
description="A Classification task for predicting the source from the Human Microbiome Project Demonstration dataset.", | ||||||
reference="https://huggingface.co/datasets/metagene-ai/HumanMicrobiomeProjectDemonstration/tree/main/hmpd/source", | ||||||
dataset={ | ||||||
"path": "metagene-ai/HumanMicrobiomeProjectDemonstration", | ||||||
"name": "source", | ||||||
"revision": "main", | ||||||
}, | ||||||
type="Classification", | ||||||
category="s2s", | ||||||
modalities=["text"], | ||||||
eval_splits=["test"], | ||||||
eval_langs=["eng"], | ||||||
main_score="accuracy", | ||||||
date=("2009-10-09", "2012-11-22"), | ||||||
domains=["Medical"], | ||||||
task_subtypes=None, | ||||||
license="not specified", | ||||||
annotations_creators="derived", | ||||||
dialect=[], | ||||||
sample_creation="found", | ||||||
bibtex_citation=""" | ||||||
@article{liu2025metagene, | ||||||
title={METAGENE-1: Metagenomic Foundation Model for Pandemic Monitoring}, | ||||||
author={Liu, Ollie and Jaghouar, Sami and Hagemann, Johannes and Wang, Shangshang and Wiemels, Jason and Kaufman, Jeff and Neiswanger, Willie}, | ||||||
journal={arXiv preprint arXiv:2501.02045}, | ||||||
year={2025} | ||||||
} | ||||||
""" | ||||||
) | ||||||
|
||||||
def __init__(self, **kwargs): | ||||||
super().__init__(**kwargs) | ||||||
self.method = "logReg" | ||||||
|
||||||
def load_data(self, **kwargs): | ||||||
if self.data_loaded: | ||||||
return | ||||||
|
||||||
from transformers.trainer_utils import set_seed | ||||||
set_seed(42) | ||||||
|
||||||
import datasets | ||||||
self.dataset = datasets.load_dataset(**self.metadata_dict["dataset"]) # type: ignore | ||||||
|
||||||
self.dataset_transform() | ||||||
|
||||||
full_train_dataset = self.dataset['train'] | ||||||
|
||||||
# by default, we undersample the training data to 8 samples per label | ||||||
desired_train_samples = 8 | ||||||
|
||||||
from collections import Counter | ||||||
label_counts = Counter(full_train_dataset['label']) | ||||||
M = min(label_counts.values()) | ||||||
if M < desired_train_samples: | ||||||
raise ValueError( | ||||||
f"Not enough samples per label to achieve {desired_train_samples} " | ||||||
f"training samples. The smallest label has only {M} samples." | ||||||
) | ||||||
test_size = 1 - (desired_train_samples / M) | ||||||
split_datasets = full_train_dataset.train_test_split( | ||||||
test_size=test_size, | ||||||
shuffle=True, | ||||||
seed=42) | ||||||
new_train_dataset = split_datasets['train'] | ||||||
new_test_dataset = split_datasets['test'] | ||||||
self.dataset = datasets.DatasetDict({ | ||||||
'train': new_train_dataset, | ||||||
'test': new_test_dataset | ||||||
}) | ||||||
print(f"\nSplitting the data with test_size={test_size}") | ||||||
print(f"Train set size: {len(new_train_dataset)} rows") | ||||||
print(f"Test set size: {len(new_test_dataset)} rows\n") | ||||||
|
||||||
self.data_loaded = True | ||||||
|
||||||
def dataset_transform(self): | ||||||
self.dataset = self.dataset.rename_columns({"sequence": "text", "isolation_source": "label"}) |
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.
I think this is from your fork. Please update the README.