adding functionality to iterate pipelines over sentence pairs when using dataset
Author: rohit1998
Pull request: no

### Feature request

to iterate on a dataset using pipelines, doc mentions this sample, [source](https://huggingface.co/docs/transformers/main/en/main_classes/pipelines#pipeline-batching)

```
import datasets
from transformers import pipeline
from transformers.pipelines.pt_utils import KeyDataset
from tqdm.auto import tqdm

pipe = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h", device=0)
dataset = datasets.load_dataset("superb", name="asr", split="test")

# KeyDataset (only *pt*) will simply return the item in the dict returned by the dataset item
# as we're not interested in the *target* part of the dataset.
for out in tqdm(pipe(KeyDataset(dataset, "file"))):
    print(out)
    # {"text": "NUMBER TEN FRESH NELLY IS WAITING ON YOU GOOD NIGHT HUSBAND"}
    # {"text": ....}
    # ....
```


Pipeline supports sending a sentence pair as a dict. [source](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/text_classification.py#L112)
```
pipe = pipeline('text-classification')
out = pipe( {'text':'I like you', 'text_pair':'. I love you'})
```

But there is no way to get pair of sentence using huggingface datasets. We can do this by simply adding a KeyPairDataset in [pt_utils](https://github.com/huggingface/transformers/blob/2ef774211733f0acf8d3415f9284c49ef219e991/src/transformers/pipelines/pt_utils.py). Something like.

```
class KeyPairDataset(Dataset):
    def __init__(self, dataset: Dataset, key1: str, key2: str):
        self.dataset = dataset
        self.key1 = key1
        self.key2 = key2

    def __len__(self):
        return len(self.dataset)

    def __getitem__(self, i):
        return {'text':self.dataset[i][self.key1],'text_pair':self.dataset[i][self.key2]}
```
And then inference this using

```
dataset = Dataset.from_pandas(dataset_df[['sentence1', 'sentence2']])
pipe = pipeline('text-classification', model=args.input_path_model, device=0, num_workers=4)
result = list(tqdm(pipe(KeyPairDataset(dataset, 'sentence1', 'sentence2'), batch_size=32), total=len(dataset)))
```


### Motivation

I am working on models that take sentence pair as input. Just something that could make my life easier instead of making my own datasets and data loaders or overriding the preprocesses function of pipeline datasets.

### Your contribution

I can submit the pr.

Comments:
cc @Narsil 

Hi @rohit1998 ,

Sounds like a good addition.
In general I think it's good if users understand how to create their own, but `KeyPairDataset` should fit quite nicely !

Sure, I will try to add it and tag you to pr soon

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.

Wouldn't it be worth to add some generalisation like:
```python 
class KeyPairDataset(Dataset):
    def __init__(self, dataset: Dataset, key1: str, key2: str):
        self.dataset = dataset
        self.key1 = key1
        self.key2 = key2

    def __len__(self):
        return len(self.dataset)

    def __getitem__(self, i):
        return {self.key1:self.dataset[i][self.key1],self.key2:self.dataset[i][self.key2]}
```

I believe (correct me if i am wrong), but `text` and `text_pair` are conventions used in transformers library for two sentence case. If yes, making it more general would require changes in pipeline api.