jayliqinzhang commited on
Commit
7f02aff
1 Parent(s): 27f3f20

Upload mumospee_small.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. mumospee_small.py +28 -29
mumospee_small.py CHANGED
@@ -25,33 +25,11 @@ class MumospeeDatasetConfig(datasets.BuilderConfig):
25
  def __init__(self, split, language=None, tag=None, **kwargs):
26
  super().__init__(**kwargs)
27
  self.split=split
 
 
 
28
 
29
- if language and isinstance(language, str):
30
- self.language = [language]
31
- else:
32
- self.language = language
33
-
34
- if tag and isinstance(tag, str):
35
- self.tag = [tag]
36
- else:
37
- self.tag = tag
38
-
39
- # print(f"lang is {self.language}, tag is {self.tag}")
40
-
41
-
42
- # # Validate each provided language
43
- # for lang in self.language:
44
- # if lang not in self._LANGUAGES:
45
- # raise ValueError(
46
- # f"Invalid language: '{lang}'. Accepted languages are: {', '.join(_LANGUAGES)}."
47
- # )
48
 
49
- # # Validate each provided tag
50
- # for t in self.tag:
51
- # if t not in self._TAGS:
52
- # raise ValueError(
53
- # f"Invalid dataset origin: '{t}'. Accepted tags are: {', '.join(_TAGS)}."
54
- # )
55
 
56
 
57
  class MumospeeDataset(datasets.GeneratorBasedBuilder):
@@ -90,6 +68,23 @@ class MumospeeDataset(datasets.GeneratorBasedBuilder):
90
  license=_LICENSE,
91
  )
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
 
95
  def _split_generators(self, dl_manager):
@@ -134,6 +129,7 @@ class MumospeeDataset(datasets.GeneratorBasedBuilder):
134
  ]
135
 
136
 
 
137
  def _generate_examples(self, filepath):
138
 
139
  data = pd.read_csv(filepath)
@@ -147,11 +143,14 @@ class MumospeeDataset(datasets.GeneratorBasedBuilder):
147
 
148
  data_split = data[data["split"] == split]
149
 
 
 
 
150
 
151
- if language:
152
- data_split = data_split[data_split["language"].isin(language)]
153
- if tag:
154
- data_split = data_split[data_split["tag"].isin(tag)]
155
 
156
 
157
  if data_split.empty:
 
25
  def __init__(self, split, language=None, tag=None, **kwargs):
26
  super().__init__(**kwargs)
27
  self.split=split
28
+ self.language = language
29
+ self.tag = tag
30
+
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
 
 
 
 
 
 
33
 
34
 
35
  class MumospeeDataset(datasets.GeneratorBasedBuilder):
 
68
  license=_LICENSE,
69
  )
70
 
71
+ def _adapt_args(self, arg, accepted_arg):
72
+ """
73
+ Adpat the input and make sure it outs as list
74
+ and all the elements within the list are accpeted.
75
+ """
76
+
77
+ if arg and isinstance(arg, str):
78
+ adapted_arg = [arg]
79
+ for aa in adapted_arg:
80
+ if aa not in accepted_arg:
81
+ raise ValueError(f"Invalid input: '{aa}'. Accepted values are: {', '.join(accepted_arg)}.")
82
+ else:
83
+ adapted_arg = arg
84
+
85
+
86
+ return adapted_arg
87
+
88
 
89
 
90
  def _split_generators(self, dl_manager):
 
129
  ]
130
 
131
 
132
+
133
  def _generate_examples(self, filepath):
134
 
135
  data = pd.read_csv(filepath)
 
143
 
144
  data_split = data[data["split"] == split]
145
 
146
+ language_list = self._adapt_args(language, _LANGUAGES)
147
+ tag_list = self._adapt_args(tag, _TAGS)
148
+
149
 
150
+ if language_list:
151
+ data_split = data_split[data_split["language"].isin(language_list)]
152
+ if tag_list:
153
+ data_split = data_split[data_split["tag"].isin(tag_list)]
154
 
155
 
156
  if data_split.empty: