# Can dataset.map accept multiple arguments like python map

**URL:** <https://discuss.huggingface.co/t/can-dataset-map-accept-multiple-arguments-like-python-map/4128>\
**Category:** 🤗Datasets\
**Created:** [March 3, 2021, 6:48pm UTC](https://discuss.huggingface.co/t/can-dataset-map-accept-multiple-arguments-like-python-map/4128 "2021-03-03T18:48:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajjwal1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/prajjwal1/32/2246_2.png) [@prajjwal1](https://discuss.huggingface.co/u/prajjwal1)\
**Post date:** [March 3, 2021, 6:48pm UTC](https://discuss.huggingface.co/t/can-dataset-map-accept-multiple-arguments-like-python-map/4128/1 "2021-03-03T18:48:37Z")

</div>

In Python, map works as follows:

```auto
map(func, arg_1, arg_2)

```

In `datasets.map`, we are required to pass in a callable (which expects objects of form `dataset[idx]`, which means that certain things like tokenizer have to be defined and should be accessible within the scope of this function, along with that other parameters that we want to pass. Can we pass arguments like a normal func call as shown above ? I’m asking because I have two `preprocess_func` for `train` and `validation` split, and I have to write both functions twice which looks repetitive (since there are slight changes in both).

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](https://discuss.huggingface.co/u/lewtun)\
**Post date:** [March 3, 2021, 7:08pm UTC](https://discuss.huggingface.co/t/can-dataset-map-accept-multiple-arguments-like-python-map/4128/2 "2021-03-03T19:08:23Z")

</div>

Hi @prajjwal1, as described in the [docs](https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=fn_kwargs#datasets.Dataset.map), you can pass a `dict` called `fn_kwargs` that can include the extra arguments for your map function

---

<div class="post-metadata">

**Author:** ![prajjwal1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/prajjwal1/32/2246_2.png) [@prajjwal1](https://discuss.huggingface.co/u/prajjwal1)\
**Post date:** [March 3, 2021, 8:24pm UTC](https://discuss.huggingface.co/t/can-dataset-map-accept-multiple-arguments-like-python-map/4128/3 "2021-03-03T20:24:56Z")

</div>

Okay, thanks. I had a look at docs before posting, but missed it.

---

<div class="post-metadata">

**Author:** ![ndvb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ndvb/32/17239_2.png) [@ndvb](https://discuss.huggingface.co/u/ndvb)\
**Post date:** [April 20, 2023, 12:25pm UTC](https://discuss.huggingface.co/t/can-dataset-map-accept-multiple-arguments-like-python-map/4128/4 "2023-04-20T12:25:55Z")

</div>

Can you show an example?
