# Error Iterating over KeyDataset

**URL:** <https://discuss.huggingface.co/t/error-iterating-over-keydataset/104620>\
**Category:** 🤗Datasets\
**Created:** [August 30, 2024, 7:01am UTC](https://discuss.huggingface.co/t/error-iterating-over-keydataset/104620 "2024-08-30T07:01:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shreeshail](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/shreeshail/32/12895_2.png) [@Shreeshail](https://discuss.huggingface.co/u/Shreeshail)\
**Post date:** [August 30, 2024, 7:01am UTC](https://discuss.huggingface.co/t/error-iterating-over-keydataset/104620/1 "2024-08-30T07:01:38Z")

</div>

```auto
from datasets import load_dataset, Audio, Dataset
from transformers.pipelines.pt_utils import KeyDataset
from transformers import AutoModelForSpeechSeq2Seq, AutoModelForCausalLM, AutoProcessor, pipeline

pipe = pipeline(
    "automatic-speech-recognition",
    model=model,
    tokenizer=processor.tokenizer,
    feature_extractor=processor.feature_extractor,
    max_new_tokens=416,
    batch_size=16,
    return_timestamps=False,
    torch_dtype=torch_dtype,
    device=device,
    generate_kwargs={"language": "hindi"},
)

audio_dataset = Dataset.from_dict({"audio": audio_files}).cast_column(
    "audio", Audio(sampling_rate=16000)
)

for i, out in tqdm(
        enumerate(pipe(KeyDataset(audio_dataset, "audio"))), total=len(audio_files)
    ):
    pass

```

On iterating over the dataset, I get the following error

```auto
ValueError: The elements of the batch contain different keys. Cannot batch them ({'input_features', 'num_frames', 'is_last'} != {'input_features', 'is_last'})

```

I checked that all files in audio\_files exist and are not empty.
