Possible bug: Only truncate works in FeatureExtractionPipeline
Author: koszilard
Pull request: no

Possible Bu:g Only the truncate function is available for feature extraction, seems explicit omit but I do not see the reason why other arguments of the tokenizer could not be passed

See https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/feature_extraction.py#L54


Comments:
I also tried a ZeroShotClassificationPipeline, 
Having a sentence too long raises a "Tensor length mismatch error". 

Could it be possible to truncate to max_length by default? 

Or could it be feasible to let us pass the arguments in the pipeline ? 

Note that :  
```python
my_pipeline(
            reference,
            prediction,
            max_length=512,
            padding=True,
            truncation=True,
            add_special_tokens=True,
        )
```

Changes nothing as the max_length or truncation seems to not be passed down the line.....  (at least for ZeroShot)

A solution could be to implement a custom _parse_thingy (sorry I don't remember the name) for having a custom tokenizing function but that seems overkill to do it everytime. 

Thanks in advance
Have a great day

Hi @Ierezell ,

> Could it be possible to truncate to max_length by default?

This should already be the case, when `truncation=True` the tokenizer will respect `tokenizer.model_max_length` attribute when truncating the input. Do you mind which model is triggering this issue ? It could be a model misconfiguration.

> Or could it be feasible to let us pass the arguments in the pipeline ?

Adding arguments is definitely doable `max_length` is a tricky beast since it means something both linked to the `tokenizer` and the `generate` function, so what the user really mean might actually be ambiguous.
In general, the idea is to add arguments as they're needed since a lot of them are not useful at inference time, or extremely rarely used.
To get *really* customized inference, you do need to step away from pipelines and either subclass or use custom code with the relative components.

That being said, what other arguments do you need in the tokenizer ? We can definitely add some !

Hi @Narsil,

here is a snippet to reproduce the problem

```python
nli = pipeline("zero-shot-classification", model="sentence-transformers/paraphrase-MiniLM-L6-v2")
references = "a "*52
prediction = "b "*513
res = nli(reference, prediction)
```

Note that changing reference to a long string (`"a "*1000`) is still fine but prediction isn't: `"b "*520` raises the error.
(Even if I agree that every input should be of the good format and less than 512 tokens, it's a nice fallback to truncate).

have a great day. 

Hi @Ierezell ,

Multiple things:

The model you are using triggers this warning:

```python
Some weights of BertForSequenceClassification were not initialized from the model checkpoint at sentence-transformers/paraphrase-MiniLM-L6-v2 and are newly initialized: ['classifier.weight', 'classifier.bias']
```

This is a pretty worrying warning, since it means this model probably wasn't fine tuned for this task, so the results are probably going to be aweful.

Then you are using `zero-shot-classification` so what you call `prediction` is actually the `candidate_labels` which is what the model is supposed to classify the incoming text (`references`) as. If this gets truncated it basically means you are going to classify not along the classes you expect which IMO warrants a true error, hiding by truncating seems pretty bad here.

Is this what you intended to do ?

We *can* update the rules to allow more customization on truncation in this pipeline, but doing that is IMO very risky (as results will be super biased/wrong)

```python
nli = pipeline("zero-shot-classification", model="sentence-transformers/paraphrase-MiniLM-L6-v2")
sentence_to_classify = "I like chocolate and pudding"
res = nli(sentence_to_classify, candidate_labels=["food", "science", "fashion"])
```

I took the liberty of rewriting your example into something which feels slightly more explicit into what the pipeline will do with your data


Hi @Narsil,

My bad for the model, it's a test I'm making and for sure I would need to change it :) Thanks for pointing that out. 

For the "UI": I agree that truncating the labels is a really bad thing to do... Maybe just changing the error message could be the solution?  For now, it's a "tensor size error" which does not reflect this "bad behavior/bad inputs".

Something like "It seems your predictions are too long, the model cannot deal with that and we will not auto-truncate." could conciliate both warning the user and not doing horrible things behind the scenes ?

(in my case paraphrasing model are a good metric for information retrieval or question generation or similar task. Like "It's freezing today in Canada  vs It's really cold in Canada today" should match so I can have long labels.)



This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.