EdwardHayashi-2023 commited on
Commit
a263eb7
1 Parent(s): fd950f4

Update MELD-Audio.py

Browse files
Files changed (1) hide show
  1. MELD-Audio.py +15 -7
MELD-Audio.py CHANGED
@@ -1,7 +1,7 @@
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
  """
4
- Created on Fri Apr 21 12:49:21 2023
5
 
6
  @author: lin.kinwahedward
7
  """
@@ -42,6 +42,7 @@ _HOMEPAGE = "https://affective-meld.github.io/"
42
 
43
  _LICENSE = "CC BY 4.0"
44
 
 
45
  _DATA_URL = "https://drive.google.com/uc?export=download&id=1TPr9v5Vz1qQuxPWcr8RedfuQvLyuG1lm"
46
 
47
  #------------------------------------------------------------------------------
@@ -72,16 +73,14 @@ class MELD_Audio(datasets.GeneratorBasedBuilder):
72
  #--------------------------------------------------------------------------
73
  '''
74
  Define the "column header" (feature) of a datum.
75
- 3 Features:
76
- 1) path_to_file
77
- 2) audio samples
78
- 3) emotion label
79
  '''
80
  def _info(self):
81
 
82
  features = datasets.Features(
83
  {
84
- "path": datasets.Value("string"),
85
  "audio": datasets.Audio(sampling_rate = 16000),
86
  "label": datasets.ClassLabel(
87
  names = [
@@ -105,9 +104,17 @@ class MELD_Audio(datasets.GeneratorBasedBuilder):
105
  )
106
  #--------------------------------------------------------------------------
107
  def _split_generators(self, dl_manager):
 
 
 
 
 
 
108
 
 
109
  dataset_path = dl_manager.download_and_extract(self.config.data_url)
110
 
 
111
  return [
112
  datasets.SplitGenerator(
113
  name = datasets.Split.TRAIN,
@@ -132,6 +139,8 @@ class MELD_Audio(datasets.GeneratorBasedBuilder):
132
  def _generate_examples(self, audio_path, csv_path):
133
  '''
134
  Get the audio file and set the corresponding labels
 
 
135
  '''
136
  key = 0
137
  with open(csv_path, encoding = "utf-8") as csv_file:
@@ -141,7 +150,6 @@ class MELD_Audio(datasets.GeneratorBasedBuilder):
141
  _, _, _, emotion, _, dialogue_id, utterance_id, _, _, _, _ = row
142
  filename = "dia" + dialogue_id + "_utt" + utterance_id + ".mp3"
143
  yield key, {
144
- "path": audio_path + filename,
145
  # huggingface dataset's will use soundfile to read the audio file
146
  "audio": audio_path + filename,
147
  "label": emotion,
 
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
  """
4
+ Created on Mon Apr 24 10:45:46 2023
5
 
6
  @author: lin.kinwahedward
7
  """
 
42
 
43
  _LICENSE = "CC BY 4.0"
44
 
45
+ # The actual place where the data is stored!
46
  _DATA_URL = "https://drive.google.com/uc?export=download&id=1TPr9v5Vz1qQuxPWcr8RedfuQvLyuG1lm"
47
 
48
  #------------------------------------------------------------------------------
 
73
  #--------------------------------------------------------------------------
74
  '''
75
  Define the "column header" (feature) of a datum.
76
+ 2 Features:
77
+ 1) audio samples
78
+ 2) emotion label
 
79
  '''
80
  def _info(self):
81
 
82
  features = datasets.Features(
83
  {
 
84
  "audio": datasets.Audio(sampling_rate = 16000),
85
  "label": datasets.ClassLabel(
86
  names = [
 
104
  )
105
  #--------------------------------------------------------------------------
106
  def _split_generators(self, dl_manager):
107
+ '''
108
+ Split the dataset into datasets.Split.{"TRAIN", "VALIDATION", "TEST", "ALL"}
109
+
110
+ The dataset can be further modified, please see below link for details.
111
+ https://huggingface.co/docs/datasets/process
112
+ '''
113
 
114
+ # Get the dataset and store at the machine where this script is executed!
115
  dataset_path = dl_manager.download_and_extract(self.config.data_url)
116
 
117
+ # "audio_path" and "csv_path" would be the parameters passed to def _generate_examples()
118
  return [
119
  datasets.SplitGenerator(
120
  name = datasets.Split.TRAIN,
 
139
  def _generate_examples(self, audio_path, csv_path):
140
  '''
141
  Get the audio file and set the corresponding labels
142
+
143
+ Must execute till yield, otherwise, error will occur!
144
  '''
145
  key = 0
146
  with open(csv_path, encoding = "utf-8") as csv_file:
 
150
  _, _, _, emotion, _, dialogue_id, utterance_id, _, _, _, _ = row
151
  filename = "dia" + dialogue_id + "_utt" + utterance_id + ".mp3"
152
  yield key, {
 
153
  # huggingface dataset's will use soundfile to read the audio file
154
  "audio": audio_path + filename,
155
  "label": emotion,