Zero-Shot Classification Pipeline - Truncating
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
2021-05-20T12:23:18Z
hey@valkyriethe pipelines intransformerscall a_parse_and_tokenizefunction that automatically takes care of padding and truncation - seeherefor 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?
2021-05-20T13:19:06Z
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.
2021-05-26T17:19:22Z
hey@valkyriei had a bit of a closer look at the_parse_and_tokenizefunction of the zero-shot pipeline and indeed it seems that you cannot specify themax_lengthparameter for the tokenizer.so if you really want to change this, one idea could be to subclassZeroShotClassificationPipelineand then override_parse_and_tokenizeto include the parameters you’d like to pass to the tokenizer’s__call__method.hope that helps!
2021-05-27T07:57:11Z
I will try that, thank you!