Skip to content

Commit

Permalink
add eryca dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
bagustris committed May 21, 2024
1 parent 7427a63 commit 15fd939
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 5 deletions.
21 changes: 21 additions & 0 deletions data/erysac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Nkululeko pre-processing for EmoChildRu Dataset

```bash
# grad the dataset from github
git clone https://github.com/hydra-colab/Emotion-Recognition-of-Younger-School-Age-Children

# rename WAV with wav
find Emotion-Recognition-of-Younger-School-Age-Children -name '*.WAV' -exec bash -c 'f="{}"; mv -- "$f" "${f%.WAV}.wav"' \;
# check number of file, should be 2505
find Emotion-Recognition-of-Younger-School-Age-Children/ -name '*.wav' | wc -l
# process database
python3 process_database.py
# resample and run
cd ../..
python3 -m nkululeko.resample --config data/erysac/exp.ini
python3 -m nkululeko.nkululeko --config data/erysac/exp.ini
```


Reference:
[1] E. Lyakso et al., “EmoChildRu: Emotional child Russian speech corpus,” Lect. Notes Comput. Sci. (including Subser. Lect. Notes Artif. Intell. Lect. Notes Bioinformatics), vol. 9319, pp. 144–152, 2015, doi: 10.1007/978-3-319-23132-7_18.
30 changes: 30 additions & 0 deletions data/erysac/exp.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[EXP]
root = ./results/
name = exp_erysac_wavlm_os_knn
[DATA]
databases = ['train', 'dev', 'test']
train = ./data/erysac/erysac_train.csv
train.type = csv
train.absolute_path = False
train.split_strategy = train
dev = ./data/erysac/erysac_dev.csv
dev.type = csv
dev.absolute_path = False
dev.split_strategy = train
test = ./data/erysac/erysac_test.csv
test.type = csv
test.absolute_path = False
test.split_strategy = test
target = emotion
; labels = ['anger', 'neutral', 'fear']
; get the number of classes from the target column automatically
[FEATS]
; type = ['audmodel']
; type = ['hubert-large-ll60k']
type = ['wavlm-large']
scale = standard
[MODEL]
type = knn
; save = True
[RESAMPLE]
replace = True
68 changes: 68 additions & 0 deletions data/erysac/process_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# process_database.py for emochildru datasets

import argparse
from pathlib import Path
from nkululeko.utils.files import find_files
import pandas as pd

gender_map = {"m": "male", "f": "female"}

def process_database(data_dir, output_dir):
# check if data_dir exists
data_dir = Path(data_dir)
if not data_dir.exists():
raise FileNotFoundError(f"Directory {data_dir} not found")

# check if output_dir exists, create if not
output_dir = Path(output_dir)
if not output_dir.exists():
output_dir.mkdir(parents=True)

# find all wav files
wavs = find_files(data_dir, ext=["wav"], relative=True)

# extract filename as df
df = pd.DataFrame({"file": wavs})

# extract emotion from filename's parent
df["emotion"] = df["file"].apply(lambda x: Path(x).parent.name.lower())

# extract speaker first string before _ in the filename
df["speaker"] = df["file"].apply(lambda x: Path(x).stem.split("_")[0])

# extract gender, second string, m for male f for female, map
df["gender"] = df["file"].apply(lambda x: Path(x).stem.split("_")[1])
# map m to male, f to female
df["gender"] = df["gender"].apply(lambda x: gender_map[x])

# extract age, third string, remove the suffix y
df["age"] = df["file"].apply(lambda x: Path(x).stem.split("_")[2][:-1])

# check number of speakers
speakers = df["speaker"].unique()
print(f"Number of speakers: {len(speakers)}")

# allocate 20% of speakers as test
test_speakers = speakers[: len(speakers) // 5]
df_test = df[df["speaker"].isin(test_speakers)]

# allocate 20% train for dev
dev_speakers = speakers[len(speakers) // 5 : len(speakers) // 5 * 2]
df_dev = df[df["speaker"].isin(dev_speakers)]
df_train = df.drop(df_dev.index)

# save to CSV
for split in ["train", "dev", "test"]:
df_split = eval(f"df_{split}")
df_split.to_csv(output_dir / f"erysac_{split}.csv", index=False)
print(f"Saved {split} set to {output_dir / f'erysac_{split}.csv'}"
f"with {len(df_split)} samples")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir", type=str, default="./Emotion-Recognition-of-Younger-School-Age-Children/")
parser.add_argument("--output_dir", type=str, default="./")
args = parser.parse_args()

process_database(args.data_dir, args.output_dir)
10 changes: 5 additions & 5 deletions data/turev/exp.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[EXP]
root = ./results/
name = exp_turev_os_knn
name = exp_wavlm_os_knn
[DATA]
databases = ['train', 'dev', 'test']
train = ./data/turev/turev_train.csv
Expand All @@ -19,10 +19,10 @@ target = emotion
; labels = ['anger', 'neutral', 'fear']
; get the number of classes from the target column automatically
[FEATS]
type = ['os']
; type = ['hubert-xlarge-ll60k']
; no_reuse = False
; scale = standard
; type = ['audmodel']
; type = ['hubert-large-ll60k']
type = ['wavlm-large']
scale = standard
[MODEL]
type = knn
; save = True
Expand Down

0 comments on commit 15fd939

Please sign in to comment.