# Zero-Shot Classification Pipeline - Truncating

**URL:** <https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269>\
**Category:** Beginners\
**Created:** [May 20, 2021, 10:33am UTC](https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269 "2021-05-20T10:33:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![valkyrie](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@valkyrie](https://discuss.huggingface.co/u/valkyrie)\
**Post date:** [May 20, 2021, 10:33am UTC](https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269/1 "2021-05-20T10:33:52Z")

</div>

Hi,

Is it possible to specify arguments for truncating and padding the text input to a certain length when using the transformers pipeline for zero-shot classification?

For instance, if I am using the following:  
classifier = pipeline(“zero-shot-classification”, device=0)

Do I need to first specify those arguments such as truncation=True, padding=‘max\_length’, max\_length=256, etc in the tokenizer / config, and then pass it to the pipeline?

Thank you in advance

---

<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:** [May 20, 2021, 12:23pm UTC](https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269/2 "2021-05-20T12:23:18Z")

</div>

hey @valkyrie the pipelines in `transformers` call a `_parse_and_tokenize` function that automatically takes care of padding and truncation - see [here](https://github.com/huggingface/transformers/blob/206f06f2ddcb8ccfc52d13612a7d41219e41e932/src/transformers/pipelines/zero_shot_classification.py#L81) for the zero-shot example.

so the short answer is that you shouldn’t need to provide these arguments when using the pipeline. do you have a special reason to want to do so?

---

<div class="post-metadata">

**Author:** ![valkyrie](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@valkyrie](https://discuss.huggingface.co/u/valkyrie)\
**Post date:** [May 20, 2021, 1:19pm UTC](https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269/3 "2021-05-20T13:19:06Z")

</div>

Hey @lewtun, the reason why I wanted to specify those is because I am doing a comparison with other text classification methods like DistilBERT and BERT for sequence classification, in where I have set the maximum length parameter (and therefore the length to truncate and pad to) to 256 tokens. Because of that I wanted to do the same with zero-shot learning, and also hoping to make it more efficient.

---

<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:** [May 26, 2021, 5:19pm UTC](https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269/4 "2021-05-26T17:19:22Z")

</div>

hey @valkyrie i had a bit of a closer look at the `_parse_and_tokenize` function of the zero-shot pipeline and indeed it seems that you cannot specify the `max_length` parameter for the tokenizer.

so if you really want to change this, one idea could be to subclass `ZeroShotClassificationPipeline` and then override `_parse_and_tokenize` to include the parameters you’d like to pass to the tokenizer’s ` __call__ ` method.

hope that helps!

---

<div class="post-metadata">

**Author:** ![valkyrie](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@valkyrie](https://discuss.huggingface.co/u/valkyrie)\
**Post date:** [May 27, 2021, 7:57am UTC](https://discuss.huggingface.co/t/zero-shot-classification-pipeline-truncating/6269/5 "2021-05-27T07:57:11Z")

</div>

I will try that, thank you!
