Unable to generate chunks (If length is greater than 512 in bert), we can use to split into chunks
Author: nithinreddyy
Pull request: no

I'm working Question & Answering hugging face pipeline, my sentence length is 3535, bert only takes 512 length, so i'm trying to divide into chunks and work on it.

In the code, i'm working on question and answering model from hugging face, if the length of the sentence is greater than 512, bert won't take it and we've to add extra argument Truncation=True, which doesn't consider some content from the sentence, which is a drawback. That's why i'm splitting the sentence into chunks and adding back.

Below is the code

```
from transformers import pipeline

def load_qa_model():
    model = pipeline(task='question-answering', model=model, tokenizer=tokenizer)
    return model

def generate_chunks(inp_str):
    max_chunk = 500
    inp_str = inp_str.replace('.', '.<eos>')
    inp_str = inp_str.replace('?', '?<eos>')
    inp_str = inp_str.replace('!', '!<eos>')

    sentences = inp_str.split('<eos>')
    current_chunk = 0
    chunks = []
    for sentence in sentences:
        if len(chunks) == current_chunk + 1:
            if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:
                chunks[current_chunk].extend(sentence.split(' '))
            else:
                current_chunk += 1
                chunks.append(sentence.split(' '))
        else:
            chunks.append(sentence.split(' '))

    for chunk_id in range(len(chunks)):
        chunks[chunk_id] = ' '.join(chunks[chunk_id])
    return chunks

sentence = ""  # Consider random sentence where the length is greater than 512
vect = generate_chunks(sentence)

qa = load_qa_model()
question = "Who released this article?"
answers = qa(question=question, context=vect)
print(answers['answer'])
```
Below is the link for the sentence (Article)

https://drive.google.com/file/d/1m8rYuOaFSW7bxqm_nYo_8Ryi9RUCY3Tq/view?usp=sharing

The output is below

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_11012\2006680085.py in <module>
      1 qa = load_qa_model()
      2 question = "Who released this article?"
----> 3 answers = qa(question=question, context=vect)
      4 print(answers['answer'])

c:\users\nithi\miniconda3\lib\site-packages\transformers\pipelines\question_answering.py in __call__(self, *args, **kwargs)
    248 
    249         # Convert inputs to features
--> 250         examples = self._args_parser(*args, **kwargs)
    251         if len(examples) == 1:
    252             return super().__call__(examples[0], **kwargs)

c:\users\nithi\miniconda3\lib\site-packages\transformers\pipelines\question_answering.py in __call__(self, *args, **kwargs)
     80                 inputs = [{"question": kwargs["question"], "context": kwargs["context"]}]
     81             else:
---> 82                 raise ValueError("Arguments can't be understood")
     83         else:
     84             raise ValueError(f"Unknown arguments {kwargs}")

ValueError: Arguments can't be understood

```

**How to overcome this issue?**

Comments:
Hey! I recommend taking a look at how it is done in our examples: https://github.com/huggingface/transformers/blob/master/examples/pytorch/question-answering/run_qa_no_trainer.py#L388

Please note that the question answering pipeline does accept longer sequences, see the list of arguments here: https://github.com/huggingface/transformers/blob/f65fe3663a6c62975a9c04654703252644c9a652/src/transformers/pipelines/question_answering.py#L209-L237

Using the argument `doc_stride` in combination with `max_seq_len` and `max_question_len` should help you out.

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/master/CONTRIBUTING.md) are likely to be ignored.

do you guys know if BERT handles 512 word tokens or is it characters 512