hdallatorre commited on
Commit
719c18a
·
1 Parent(s): 073b473

feat: try other way for labels

Browse files
nucleotide_transformer_downstream_tasks_multilabel.py CHANGED
@@ -44,19 +44,17 @@ _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
- _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,7 +66,6 @@ class NucleotideTransformerDownstreamTasksConfig(datasets.BuilderConfig):
68
  **kwargs,
69
  )
70
  self.task = task
71
- self.num_labels = num_labels
72
  self.dtype = dtype
73
 
74
 
@@ -76,24 +73,18 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
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,15 +126,10 @@ class NucleotideTransformerDownstreamTasks(datasets.GeneratorBasedBuilder):
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
 
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_DTYPE = [
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__(self, *args, task: str, dtype: str = "int32", **kwargs):
 
 
58
  """BuilderConfig downstream tasks dataset.
59
  Args:
60
  task (:obj:`str`): Task name.
 
66
  **kwargs,
67
  )
68
  self.task = task
 
69
  self.dtype = dtype
70
 
71
 
 
73
  VERSION = datasets.Version("1.1.0")
74
  BUILDER_CONFIG_CLASS = NucleotideTransformerDownstreamTasksConfig
75
  BUILDER_CONFIGS = [
76
+ NucleotideTransformerDownstreamTasksConfig(task=task, dtype=dtype)
77
+ for (task, dtype) in _TASKS_DTYPE
 
 
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("int32"),
87
  }
 
 
 
 
 
 
88
 
89
  return datasets.DatasetInfo(
90
  # This is the description that will appear on the datasets page.
 
126
  sequence, name = str(record.seq), str(record.name)
127
  labels = [float(label) for label in name.split("|")[1:]]
128
 
129
+ # yield example
130
+ yield key, {
131
  "sequence": sequence,
132
  "name": name,
133
+ "labels": labels,
134
  }
 
 
 
 
 
 
 
135
  key += 1