# Dataset.map Ignore failed batches

**URL:** <https://discuss.huggingface.co/t/dataset-map-ignore-failed-batches/158906>\
**Category:** 🤗Datasets\
**Created:** [June 11, 2025, 11:16am UTC](https://discuss.huggingface.co/t/dataset-map-ignore-failed-batches/158906 "2025-06-11T11:16:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![whh](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@whh](https://discuss.huggingface.co/u/whh)\
**Post date:** [June 11, 2025, 11:16am UTC](https://discuss.huggingface.co/t/dataset-map-ignore-failed-batches/158906/1 "2025-06-11T11:16:01Z")

</div>

I often use the batch mode of dataset.map to process large amounts of data. Since there may be some format problems in the data, some batches may fail in the map (while most batches are OK).

Is there some way to ignore the failed batches and return the successful batches?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [June 11, 2025, 11:39am UTC](https://discuss.huggingface.co/t/dataset-map-ignore-failed-batches/158906/2 "2025-06-11T11:39:10Z")

</div>

For example, how about just use Python Exception?

> [@Saving outcomes if Error while applying map function on dataset](https://discuss.huggingface.co/t/saving-outcomes-if-error-while-applying-map-function-on-dataset/31614):
>
> I use an API (like huggingface\_hub) to let a language model answer questions from my dataset. Since I want to send every single example to the language model, I wrote a function that does that and then use the map function to map this API call to every example of my dataset. My issue is: If there is an Error at any point (e.g. the API throws an Error after one hour, because sth happend) I loose all the information. Lets say the map worked for the first 100 examples and then the API throws an E…

---

<div class="post-metadata">

**Author:** ![whh](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@whh](https://discuss.huggingface.co/u/whh)\
**Post date:** [June 13, 2025, 6:26am UTC](https://discuss.huggingface.co/t/dataset-map-ignore-failed-batches/158906/3 "2025-06-13T06:26:22Z")

</div>

Thanks, It’s helpful !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [June 13, 2025, 6:27pm UTC](https://discuss.huggingface.co/t/dataset-map-ignore-failed-batches/158906/4 "2025-06-13T18:27:07Z")

</div>

Closed on June 13, 2025, 6:27pm UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
