Predict single sentence for Glue Tasks
I have trained a custom binary classifier using `run_glue.py` and have the `pytorch_model.bin` file saved to a directory. Is there a way to predict for a given sentence and extract its label?

I know `trainer.predict(test_dataset)` does it. But I am having some trouble converting the string to the format that it takes.

Here is how I managed to do it. I have considered a `pandas` dataframe, but you can easily extend it to predict individual sentence too.

```
import pandas as pd 
import numpy as np
from datasets import Dataset, load_dataset
from scipy.special import softmax
from transformers import Trainer
from transformers import BertTokenizer, BertForSequenceClassification

tokenizer = BertTokenizer.from_pretrained(<model_name_or_path>)
model = BertForSequenceClassification.from_pretrained(<model_name_or_path>)

def preprocess_function(examples):
    # Tokenize the texts
    result = tokenizer(examples['sentence'], padding=False, max_length=None, truncation=True, verbose=False)
    return result

def predict(dataframe):
    eval_dataset = Dataset.from_pandas(dataframe)
    eval_dataset = eval_dataset.map(preprocess_function, batched=False, load_from_cache_file=True)
    # Initialize our Trainer
    trainer = Trainer(model=model, tokenizer=tokenizer)
    predictions = trainer.predict(test_dataset=eval_dataset).predictions
    # Adding a softmax layer to get probabilities. If you want class labels instead -  np.argmax(predictions, axis=1)
    predictions = np.array([softmax(element) for element in predictions])[:, 1]
    return predictions
```<|||||>@Nickil21 
I used the torch model in the trainer. It's much faster than using pandas and creating a dataset.

`import torch
def test_2(trainer, sentence1, sentence2):
    id_tolabel = {0:'negative', 1: 'positive'}
    model = trainer.model.eval()
    tokenized = tokenizer(sentence1, sentence2, return_tensors='pt').to(model.device)
    with torch.no_grad():
        label = torch.argmax(trainer.model.forward(**tokenized).logits, dim=1)[0].cpu().item()
    return id_tolabel[label]
print(test_2(trainer, 'it is not possible', 'this is impossible'))`