2525"""
2626
2727import argparse
28+ import copy
2829import json
2930import os
3031import shutil
@@ -155,12 +156,21 @@ def create_manifest_entry(
155156 Manifest entry dict with proper format for nemo-skills
156157 """
157158 instruction = sample .get ("instruction" , sample .get ("text" , "Process the audio" ))
159+ if isinstance (instruction , dict ):
160+ try :
161+ instruction = instruction ["text" ]
162+ except KeyError as exc :
163+ raise ValueError (
164+ f"Instruction dict missing required 'text' field for { dataset_name } sample { sample_id } : { instruction } "
165+ ) from exc
166+ if not isinstance (instruction , str ):
167+ raise ValueError (f"Instruction must be a string for { dataset_name } sample { sample_id } : { instruction !r} " )
158168 reference = sample .get ("reference" , sample .get ("answer" , "" ))
159169 task_type = sample .get ("task_type" , "unknown" )
160170
161- # Create absolute audio path with /data/ prefix for cluster deployment
162- # Format: /data/ audiobench/{category}/audio/{dataset_name}/{filename}
163- audio_rel_path = f"/data/audiobench/ { category } / audio/{ dataset_name } /{ audio_filename } "
171+ # Paths are resolved relative to the manifest directory by the inference code.
172+ # The combined category manifest lives at audiobench/{category}/test.jsonl.
173+ audio_rel_path = f"audio/{ dataset_name } /{ audio_filename } "
164174
165175 # Create audio metadata (both singular and plural forms for compatibility)
166176 audio_metadata = {"path" : audio_rel_path , "duration" : duration }
@@ -203,6 +213,28 @@ def create_manifest_entry(
203213 return entry
204214
205215
216+ def make_dataset_manifest_entry (entry : Dict ) -> Dict :
217+ """Adjust category-relative audio paths for per-dataset manifests."""
218+ entry = copy .deepcopy (entry )
219+
220+ def rewrite (path : str ) -> str :
221+ return f"../{ path } " if path .startswith ("audio/" ) else path
222+
223+ if isinstance (entry .get ("audio_path" ), list ):
224+ entry ["audio_path" ] = [rewrite (path ) for path in entry ["audio_path" ]]
225+ elif isinstance (entry .get ("audio_path" ), str ):
226+ entry ["audio_path" ] = rewrite (entry ["audio_path" ])
227+
228+ for message in entry .get ("messages" , []):
229+ if "audio" in message and "path" in message ["audio" ]:
230+ message ["audio" ]["path" ] = rewrite (message ["audio" ]["path" ])
231+ for audio in message .get ("audios" , []):
232+ if "path" in audio :
233+ audio ["path" ] = rewrite (audio ["path" ])
234+
235+ return entry
236+
237+
206238def process_dataset (
207239 dataset_name : str ,
208240 output_dir : Path ,
@@ -473,7 +505,7 @@ def process_dataset(
473505 manifest_path = dataset_dir / f"{ split } .jsonl"
474506 with open (manifest_path , "w" , encoding = "utf-8" ) as f :
475507 for entry in manifest_entries :
476- f .write (json .dumps (entry , ensure_ascii = False ) + "\n " )
508+ f .write (json .dumps (make_dataset_manifest_entry ( entry ) , ensure_ascii = False ) + "\n " )
477509
478510 print (f"✓ Saved { successful } samples to { manifest_path } " )
479511 if failed > 0 :
@@ -566,6 +598,7 @@ def main():
566598
567599 total_samples = 0
568600 total_datasets = 0
601+ combined_entries = {"judge" : [], "nonjudge" : []}
569602
570603 for name in target_datasets :
571604 # Normalize dataset name: allow passing without _test suffix
@@ -575,23 +608,33 @@ def main():
575608 if f"{ dataset_name } _test" in JUDGE_DATASETS or f"{ dataset_name } _test" in NONJUDGE_DATASETS :
576609 dataset_name = f"{ dataset_name } _test"
577610
578- # Determine category for logging
579- category = "judge" if name in JUDGE_DATASETS else "nonjudge"
611+ if dataset_name in JUDGE_DATASETS :
612+ category = "judge"
613+ elif dataset_name in NONJUDGE_DATASETS :
614+ category = "nonjudge"
615+ else :
616+ raise ValueError (f"Unsupported AudioBench dataset name: { name } " )
617+
618+ num_samples , manifest_entries = process_dataset (
619+ dataset_name = dataset_name ,
620+ output_dir = output_dir ,
621+ save_audio = args .save_audio ,
622+ split = args .split ,
623+ max_samples = args .max_samples ,
624+ )
625+ total_samples += num_samples
626+ total_datasets += 1
627+ combined_entries [category ].extend (manifest_entries )
628+ print (f"✓ Completed { dataset_name } : { num_samples } samples" )
580629
581- try :
582- num_samples , _ = process_dataset (
583- dataset_name = dataset_name ,
584- output_dir = output_dir ,
585- save_audio = args .save_audio ,
586- split = args .split ,
587- max_samples = args .max_samples ,
588- )
589- total_samples += num_samples
590- total_datasets += 1
591- print (f"✓ Completed { dataset_name } : { num_samples } samples" )
592- except Exception as e :
593- print (f"✗ Failed { dataset_name } : { e } " )
630+ for category , entries in combined_entries .items ():
631+ if not entries :
594632 continue
633+ combined_manifest = output_dir / category / f"{ args .split } .jsonl"
634+ with open (combined_manifest , "w" , encoding = "utf-8" ) as f :
635+ for entry in entries :
636+ f .write (json .dumps (entry , ensure_ascii = False ) + "\n " )
637+ print (f"✓ Saved combined { category } manifest with { len (entries )} samples to { combined_manifest } " )
595638
596639 print ("\n " + "=" * 60 )
597640 print ("AudioBench Preparation Summary" )
0 commit comments