I am not sure if this is nice solution but it works…
- First of all create
metadata.csv
in yourdata_dir
where you put thefile_name
and someid
. - Load the dataset as before… Now the
dataset_mp3["train"][1] == {
"audio": "path/to/audio/file",
"id": "id from the metadata.csv"
}
- Now change the for loop into:
for item in tqdm(KeyPairDataset(dataset_mp3["train"], "audio", "id")):
out = pipe(item["text"])
print(out, item["text_pair"])
It is strange, but take a look here https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/pt_utils.py and you will see how it works
It can be simplifed if you need just file_name
just iterate over KeyDataset and run pipe inside the loop.
Hope this helps.