Commit
·
58e9a17
1
Parent(s):
7cace1f
feat: revert to working version
Browse files
nucleotide_transformer_downstream_tasks_multilabel.py
CHANGED
|
@@ -44,17 +44,19 @@ _LICENSE = "https://github.com/instadeepai/nucleotide-transformer/LICENSE.md"
|
|
| 44 |
# The toy_classification and toy_regression are two manually created configurations
|
| 45 |
# with 5 samples in both the train and test fasta files. It is notably used in order to
|
| 46 |
# test the scripts.
|
| 47 |
-
|
| 48 |
-
("deepstarr", "float32"),
|
| 49 |
-
("toy_classification", "int32"),
|
| 50 |
-
("toy_regression", "float32"),
|
| 51 |
]
|
| 52 |
|
| 53 |
|
| 54 |
class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
|
| 55 |
"""BuilderConfig for The Nucleotide Transformer downstream taks dataset."""
|
| 56 |
|
| 57 |
-
def __init__(
|
|
|
|
|
|
|
| 58 |
"""BuilderConfig downstream tasks dataset.
|
| 59 |
Args:
|
| 60 |
task (:obj:`str`): Task name.
|
|
@@ -66,6 +68,7 @@ class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
|
|
| 66 |
**kwargs,
|
| 67 |
)
|
| 68 |
self.task = task
|
|
|
|
| 69 |
self.dtype = dtype
|
| 70 |
|
| 71 |
|
|
@@ -73,18 +76,24 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
|
|
| 73 |
VERSION = datasets.Version("1.1.0")
|
| 74 |
BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig
|
| 75 |
BUILDER_CONFIGS = [
|
| 76 |
-
NucleotideTransformerDownstreamTasksConfig(
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
]
|
| 79 |
DEFAULT_CONFIG_NAME = "deepstarr"
|
| 80 |
|
| 81 |
def _info(self):
|
| 82 |
-
|
| 83 |
-
features = {
|
| 84 |
"sequence": datasets.Value("string"),
|
| 85 |
"name": datasets.Value("string"),
|
| 86 |
-
# "labels": datasets.Sequence(self.config.dtype),
|
| 87 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
return datasets.DatasetInfo(
|
| 90 |
# This is the description that will appear on the datasets page.
|
|
@@ -126,10 +135,15 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
|
|
| 126 |
sequence, name = str(record.seq), str(record.name)
|
| 127 |
labels = [float(label) for label in name.split("|")[1:]]
|
| 128 |
|
| 129 |
-
|
| 130 |
-
yield key, {
|
| 131 |
"sequence": sequence,
|
| 132 |
"name": name,
|
| 133 |
-
# "labels": labels,
|
| 134 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
key += 1
|
|
|
|
| 44 |
# The toy_classification and toy_regression are two manually created configurations
|
| 45 |
# with 5 samples in both the train and test fasta files. It is notably used in order to
|
| 46 |
# test the scripts.
|
| 47 |
+
_TASKS_NUM_LABELS_DTYPE = [
|
| 48 |
+
("deepstarr", 6, "float32"),
|
| 49 |
+
("toy_classification", 2, "int32"),
|
| 50 |
+
("toy_regression", 2, "float32"),
|
| 51 |
]
|
| 52 |
|
| 53 |
|
| 54 |
class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
|
| 55 |
"""BuilderConfig for The Nucleotide Transformer downstream taks dataset."""
|
| 56 |
|
| 57 |
+
def __init__(
|
| 58 |
+
self, *args, task: str, num_labels=int, dtype: str = "int32", **kwargs
|
| 59 |
+
):
|
| 60 |
"""BuilderConfig downstream tasks dataset.
|
| 61 |
Args:
|
| 62 |
task (:obj:`str`): Task name.
|
|
|
|
| 68 |
**kwargs,
|
| 69 |
)
|
| 70 |
self.task = task
|
| 71 |
+
self.num_labels = num_labels
|
| 72 |
self.dtype = dtype
|
| 73 |
|
| 74 |
|
|
|
|
| 76 |
VERSION = datasets.Version("1.1.0")
|
| 77 |
BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig
|
| 78 |
BUILDER_CONFIGS = [
|
| 79 |
+
NucleotideTransformerDownstreamTasksConfig(
|
| 80 |
+
task=task, num_labels=num_labels, dtype=dtype
|
| 81 |
+
)
|
| 82 |
+
for (task, num_labels, dtype) in _TASKS_NUM_LABELS_DTYPE
|
| 83 |
]
|
| 84 |
DEFAULT_CONFIG_NAME = "deepstarr"
|
| 85 |
|
| 86 |
def _info(self):
|
| 87 |
+
features_dict = {
|
|
|
|
| 88 |
"sequence": datasets.Value("string"),
|
| 89 |
"name": datasets.Value("string"),
|
|
|
|
| 90 |
}
|
| 91 |
+
labels_dict = {
|
| 92 |
+
f"label_{i}": datasets.Value(self.config.dtype)
|
| 93 |
+
for i in range(self.config.num_labels)
|
| 94 |
+
}
|
| 95 |
+
features_dict.update(labels_dict)
|
| 96 |
+
features = datasets.Features(features_dict)
|
| 97 |
|
| 98 |
return datasets.DatasetInfo(
|
| 99 |
# This is the description that will appear on the datasets page.
|
|
|
|
| 135 |
sequence, name = str(record.seq), str(record.name)
|
| 136 |
labels = [float(label) for label in name.split("|")[1:]]
|
| 137 |
|
| 138 |
+
sequence_name_dict = {
|
|
|
|
| 139 |
"sequence": sequence,
|
| 140 |
"name": name,
|
|
|
|
| 141 |
}
|
| 142 |
+
|
| 143 |
+
labels_dict = {
|
| 144 |
+
f"label_{i}": labels[i] for i in range(self.config.num_labels)
|
| 145 |
+
}
|
| 146 |
+
sequence_name_dict.update(labels_dict)
|
| 147 |
+
# yield example
|
| 148 |
+
yield key, sequence_name_dict
|
| 149 |
key += 1
|