TypeError: TextInputSequence must be str in converting squad examples to features
Author: sajastu
Pull request: no

### System Info

- `transformers` version: 4.36.1
- Platform: Linux-4.15.0-196-generic-x86_64-with-glibc2.17
- Python version: 3.8.13
- Huggingface_hub version: 0.19.4
- Safetensors version: 0.4.1
- Accelerate version: 0.25.0
- Accelerate config:    not found
- PyTorch version (GPU?): 1.10.0+cu111 (True)
- Tensorflow version (GPU?): 2.9.1 (True)
- Flax version (CPU?/GPU?/TPU?): 0.6.0 (gpu)
- Jax version: 0.3.16
- JaxLib version: 0.3.15
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help?

@ArthurZucker and @younesbelkada

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

Steps to reproduce this behaviour: 

I basically have written a function that calls the `squad_convert_examples_to_features` of HF after doing some input framings. This is a mockup code just to show the behaviour, but it's in fact a part of a larger model. Here's my code:

```python
from transformers import SquadExample, squad_convert_examples_to_features, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("ahotrod/electra_large_discriminator_squad2_512") #an ELECTRA-LARGE tokenizer

qa_pairs = [[['QuestionA?', "AnswerA"], ['QuestionB', 'AnswerB'], ['QuestionC', 'AnswerC'], ["QuestionD", 'AnswerD']]]

context = "Here's the context text..."

def _answer_questions(
        summaries, qa_pairs_lists
) :
    qa_inputs = []
    context_to_input_index = {}
    mapping = {}

    for i, (summary, qa_pairs_list) in enumerate(zip(summaries, [[qa_pairs_lists]])):
        for j, qa_pairs in enumerate(qa_pairs_list):
            for k, qa in enumerate(qa_pairs):
                question = qa["question"]
                key = (question, summary)
                if key not in context_to_input_index:
                    context_to_input_index[key] = len(qa_inputs)
                    qa_inputs.append(key)
                mapping[(i, j, k)] = context_to_input_index[key]

    examples = []
    for i, (question, context) in enumerate(qa_inputs):
        examples.append(SquadExample(
            qas_id=str(i),
            question_text=question,
            context_text=context,
            answer_text=None,
            start_position_character=None,
            title=None,
            is_impossible=True,
            answers=[]
        ))

    features, dataset = squad_convert_examples_to_features(
        examples,
        tokenizer,
        384,
        0,
        512,
        False,
        padding_strategy="max_length",
        return_dataset=False,
        threads=1,
        tqdm_enabled=True,
    )

    # throws 
    """
    Traceback (most recent call last):
      File "test.py", line 55, in <module>
        _answer_questions(
      File "test.py", line 39, in _answer_questions
        features, dataset = squad_convert_examples_to_features(
      File "/path/to/HF_installed/squad.py", line 376, in squad_convert_examples_to_features
        features = list(
      File "lib/python3.8/site-packages/tqdm/std.py", line 1195, in __iter__
        for obj in iterable:
      File "lib/python3.8/multiprocessing/pool.py", line 420, in <genexpr>
        return (item for chunk in result for item in chunk)
      File "lib/python3.8/multiprocessing/pool.py", line 868, in next
        raise value
    TypeError: TextInputSequence must be str
    """


# test 
_answer_questions(
[context],
                          [{'question': v[0], 'answer': v[1] } for v in qa_pairs[0]]
)
```

Here's more debugging info about where this error is coming from:

> Traceback (most recent call last):
>   File "PYTHON_PATH/multiprocessing/pool.py", line 125, in worker
>     result = (True, func(*args, **kwds))
>   File "PYTHON_PATH/multiprocessing/pool.py", line 48, in mapstar
>     return list(map(*args))
>   File "test.py", line 96, in squad_convert_example_to_features
>     encoded_dict = tokenizer.encode_plus(  # TODO(thom) update this logic
>   File "PYTHON_PATH/site-packages/transformers/tokenization_utils_base.py", line 2981, in encode_plus
>     return self._encode_plus(
>   File "PYTHON_PATH/site-packages/transformers/tokenization_utils_fast.py", line 576, in _encode_plus
>     batched_output = self._batch_encode_plus(
>   File "PYTHON_PATH/site-packages/transformers/tokenization_utils_fast.py", line 504, in _batch_encode_plus
>     encodings = self._tokenizer.encode_batch(
> TypeError: TextInputSequence must be str

### Expected behavior

I'm expecting to use the `squad_convert_examples_to_features` function smoothly, getting all the `features` and `dataset` without any bugs. I did some digging around the web for a quick fix or workaround and found out that switching the tokenizer to a regular one (by setting `use_fast=False` when initiating the tokenizer) seems to do the trick. But since this issue has been around for like 2 years now (if I remember correctly), I think it's high time to open a new issue page and flag this potential bug.

Comments:
Hey, not 100% this is of high priority, issue is from [here](https://github.com/huggingface/transformers/blob/cfe84ba756059e609591aa83b6de654b6e39ab4d/src/transformers/data/processors/squad.py#L179-L188):
```python 
        encoded_dict = tokenizer.encode_plus(  # TODO(thom) update this logic
            texts,
            pairs,
            truncation=truncation,
            padding=padding_strategy,
            max_length=max_seq_length,
            return_overflowing_tokens=True,
            stride=max_seq_length - doc_stride - len(truncated_query) - sequence_pair_added_tokens,
            return_token_type_ids=True,
        )
```
in the data processor. The tokenizers works well but at some point it is fed with input ids which is not expected. 


The reason why it works with a slow tokenizer is because the input is ignore (the `texts` is equal to `[3160, 2050, 1029]`. 
If you want to fix the logic feel free to do so but I don't think we have bandwidth for this is it was not really requested a lot. Let's keep this issue open otherwise

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.

> The reason why it works with a slow tokenizer is because the input is ignore (the `texts` is equal to `[3160, 2050, 1029]`. If you want to fix the logic feel free to do so but I don't think we have bandwidth for this is it was not really requested a lot. Let's keep this issue open otherwise

Hi Arthur,

Can you please describe the changes the logic which needs to be done to fix this?

Thank you for the help!

> Hey, not 100% this is of high priority, issue is from [here](https://github.com/huggingface/transformers/blob/cfe84ba756059e609591aa83b6de654b6e39ab4d/src/transformers/data/processors/squad.py#L179-L188):
> ```python 
>         encoded_dict = tokenizer.encode_plus(  # TODO(thom) update this logic
>             texts,
>             pairs,
>             truncation=truncation,
>             padding=padding_strategy,
>             max_length=max_seq_length,
>             return_overflowing_tokens=True,
>             stride=max_seq_length - doc_stride - len(truncated_query) - sequence_pair_added_tokens,
>             return_token_type_ids=True,
>         )
> ```
> in the data processor. The tokenizers works well but at some point it is fed with input ids which is not expected. 
> 

@ArthurZucker 

Can you please describe what change is required to be done here? I will do it and raise a pull request. 

Thank you for the help!

Hey! I don't really know what changes are required, it's part of solving the issue! 🤗