# Not sure why padding isn't working for me

**URL:** <https://discuss.huggingface.co/t/not-sure-why-padding-isnt-working-for-me/3343>\
**Category:** Beginners\
**Created:** [January 22, 2021, 4:17pm UTC](https://discuss.huggingface.co/t/not-sure-why-padding-isnt-working-for-me/3343 "2021-01-22T16:17:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thecity2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/thecity2/32/947_2.png) [@thecity2](https://discuss.huggingface.co/u/thecity2)\
**Post date:** [January 22, 2021, 4:17pm UTC](https://discuss.huggingface.co/t/not-sure-why-padding-isnt-working-for-me/3343/1 "2021-01-22T16:17:14Z")

</div>

There doesn’t seem to be any padding occurring here:

```
     train_dataset = dataset.shard(10, 1)

    train_dataset.set_format(columns=['text'])

    train_dataset.cleanup_cache_files()

    encoded_dataset = train_dataset.map(lambda examples: tokenizer(examples['text'], padding=True))

    encoded_dataset[:1]

    {'attention_mask': [[1, 1, 1, 1, 1, 1, 1]],
     'input_ids': [[101, 1714, 22233, 21365, 4515, 8618, 102]],
     'text': ['free instagram followers '],
     'token_type_ids': [[0, 0, 0, 0, 0, 0, 0]]}

```

What am I missing?

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [January 22, 2021, 6:00pm UTC](https://discuss.huggingface.co/t/not-sure-why-padding-isnt-working-for-me/3343/2 "2021-01-22T18:00:49Z")

</div>

You are using the strategy to pad to the length of the longest sample while also passing your samples one by one to the tokenizer, so no padding happens.  
If you want to pass several samples at once, using `batched=True` in your call to map. If you want to pass to a specific max\_length, pass `max_length=xxx` and `padding="max_length"` to your call to the `tokenizer`.

---

<div class="post-metadata">

**Author:** ![thecity2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/thecity2/32/947_2.png) [@thecity2](https://discuss.huggingface.co/u/thecity2)\
**Post date:** [January 22, 2021, 6:29pm UTC](https://discuss.huggingface.co/t/not-sure-why-padding-isnt-working-for-me/3343/3 "2021-01-22T18:29:00Z")

</div>

Thank you so much @sgugger! That makes sense now.
