BrunoHays commited on
Commit
4f0b4f7
1 Parent(s): 3d54ff6

Update multilingual-TEDX-fr.py

Browse files
Files changed (1) hide show
  1. multilingual-TEDX-fr.py +16 -5
multilingual-TEDX-fr.py CHANGED
@@ -52,13 +52,14 @@ class TEDXConfig(datasets.BuilderConfig):
52
  )
53
  self.single_samples = (name == "single_samples")
54
  self.max = (name == "max")
 
55
  if not self.single_samples and not self.max:
56
  self.max_duration = float(name.split("=")[1][:-1])
57
- else:
58
- self.max_duration = np.inf
59
-
60
 
61
  class TEDX(datasets.GeneratorBasedBuilder):
 
 
 
62
 
63
  BUILDER_CONFIGS = [
64
  TEDXConfig(name="single_samples", description="all samples taken separately, can be very short and imprecise"),
@@ -70,6 +71,9 @@ class TEDX(datasets.GeneratorBasedBuilder):
70
  TEDXConfig(name="max=10s", description="samples are merged in order to reach a max duration of 10 seconds"
71
  "Does not remove single utterances that may exceed "
72
  "the maximum duration"),
 
 
 
73
  ]
74
 
75
  DEFAULT_CONFIG_NAME = "single_samples"
@@ -152,7 +156,14 @@ class TEDX(datasets.GeneratorBasedBuilder):
152
  ]
153
 
154
  return splits
155
-
 
 
 
 
 
 
 
156
  @staticmethod
157
  def merge_utterances(utterance1: Utterance, utterance2: Utterance) -> Utterance:
158
  assert(utterance1.speaker_id == utterance2.speaker_id)
@@ -181,7 +192,7 @@ class TEDX(datasets.GeneratorBasedBuilder):
181
  yield merged_utterance
182
  return
183
  end_time = new_utterance.end_timestamp
184
- if end_time - start_time > self.config.max_duration:
185
  yield merged_utterance
186
  merged_utterance = new_utterance
187
  start_time = merged_utterance.start_timestamp
 
52
  )
53
  self.single_samples = (name == "single_samples")
54
  self.max = (name == "max")
55
+ self.random = (name == "random_merge")
56
  if not self.single_samples and not self.max:
57
  self.max_duration = float(name.split("=")[1][:-1])
 
 
 
58
 
59
  class TEDX(datasets.GeneratorBasedBuilder):
60
+
61
+ random_max_durations = cycle([8, 4, 10, 5, 13, 23, 6, 19, 24, 7, 26, 27, 20, 14, 1, 25, 21, 22,
62
+ 9, 12, 11, 2, 30, 15, 28, 17, 18, 29, 16, 3])
63
 
64
  BUILDER_CONFIGS = [
65
  TEDXConfig(name="single_samples", description="all samples taken separately, can be very short and imprecise"),
 
71
  TEDXConfig(name="max=10s", description="samples are merged in order to reach a max duration of 10 seconds"
72
  "Does not remove single utterances that may exceed "
73
  "the maximum duration"),
74
+ TEDXConfig(name="random_merge", description="samples are merged in order to reach a random max duration between 1 and 30 seconds"
75
+ "Does not remove single utterances that may exceed "
76
+ "the maximum duration"),
77
  ]
78
 
79
  DEFAULT_CONFIG_NAME = "single_samples"
 
156
  ]
157
 
158
  return splits
159
+
160
+ def get_max_duration(self) -> float:
161
+ if self.config.max:
162
+ return np.inf
163
+ if self.config.random:
164
+ return next(self.random_max_durations)
165
+ return self.config.max_duration
166
+
167
  @staticmethod
168
  def merge_utterances(utterance1: Utterance, utterance2: Utterance) -> Utterance:
169
  assert(utterance1.speaker_id == utterance2.speaker_id)
 
192
  yield merged_utterance
193
  return
194
  end_time = new_utterance.end_timestamp
195
+ if end_time - start_time > self.get_max_duration():
196
  yield merged_utterance
197
  merged_utterance = new_utterance
198
  start_time = merged_utterance.start_timestamp