Expanding an Audio Dataset with datasets.map()?
HelloAfter a couple of hours trying to get this to work I need to askI’m trying to expand a dataset (used with Wav2Vec2 for ASR) with following Idea:dataset_expansion = dataset#addingsimple noise to dataset expansiondef add_simple_noise(batch):audio = batch[‘audio_path’]noise = np.asarray(0.01*np.random.randn(len(audio[“array”])))audio[“array”] = audio[“array”] + noisereturn batch#mapsimple noise to training setdataset_expansion = dataset_expansion.map(add_simple_noise)dataset_expansion = dataset_expansion.cast_column(“audio_path”, datasets.Audio(sampling_rate=16_000))The mapping itself seems to work and noise is added.But the mapping does not seem to be correct:By trying to concat the datasets together:dataset = datasets.concatenate_datasets([dataset[“train”],dataset_expansion[“train”]])Throws following error:ArrowInvalid: Schema at index 1 was different:audio_path: stringtext: stringsampling_rate: int64train_or_test: stringvsaudio_path: struct<array: list<item: double>, path: string, sampling_rate: int64>text: stringsampling_rate: int64train_or_test: stringChecking the features:dataset[“train”].features{‘audio_path’: Audio(sampling_rate=16000, mono=True, id=None),‘text’: Value(dtype=‘string’, id=None),‘sampling_rate’: Value(dtype=‘int64’, id=None),‘train_or_test’: Value(dtype=‘string’, id=None)}dataset_expansion[“train”].features{‘audio_path’: Audio(sampling_rate=16000, mono=True, id=None),‘text’: Value(dtype=‘string’, id=None),‘sampling_rate’: Value(dtype=‘int64’, id=None),‘train_or_test’: Value(dtype=‘string’, id=None)}The dataset was loaded as follows:feature_dict = {“audio_path”: datasets.Audio(sampling_rate=16_000),“text”: datasets.Value(“string”)}data_features = datasets.Features(feature_dict)dataset = load_dataset(“csv”,data_files={“train”:“toy_train_data.csv”,“test”:“toy_test_data.csv”},)dataset = dataset.cast_column(“audio_path”, datasets.Audio(sampling_rate=16_000,mono=True))dataset = dataset.remove_columns(“Unnamed: 0”)I might just be missing something really small. But I just can’t seem to find whatever needs to be done to get this to workThe alternative to doing this on the fly would be to make a copy of the data and add noise there.If anyone could point me in the right direction, I’d really appreciate it.Thank you and have a great day.
2022-03-16T10:02:40Z
Additional information:dataset[“train”][0][“audio_path”]{‘path’: ‘./audio/ch_ag_0006.wav’,‘array’: array([-3.0517578e-05, -3.0517578e-05, -3.0517578e-05, …,-1.2207031e-04, -9.1552734e-05,  0.0000000e+00], dtype=float32),‘sampling_rate’: 16000}dataset_expansion[“train”][0][“audio_path”]AttributeError: ‘dict’ object has no attribute ‘endswith’
2022-03-21T12:00:06Z
Hi! Which version ofdatasetsare you using? I’m pretty sure this issue can be resolved by using the newest version ofdatasets, which you can install as follows:pip install -U datasetsLet me know if that doesn’t help.
2022-03-21T13:08:09Z
Hello MarioThank you for your time.That was one of my assumptions at first, as the original version ran on 1.17. (and didn’t work as expected). This version of the script is running on datasets 2.0.0 (and transformers 4.17.0).In the meantime I’m doing the audio expansion locally and uploading the expanded audio to run my tests. Not quite as elegant as I would like, but it worksCheersStefan
2024-12-05T09:39:25Z
Any luck with this one?