How do i get the CLS token from the model output?
## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->


- `transformers` version: 4.8.2
- Platform: Linux-5.4.104+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.7.11
- PyTorch version (GPU?): 1.9.0+cu102 (False)- Tensorflow version (GPU?): 2.6.0 (False)- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- funnel: @sgugger
- rag: @patrickvonplaten, @lhoestq

Library:
- tokenizers: @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

Model hub:

- for issues with a model report at https://discuss.huggingface.co/ and tag the model's creator.

Examples:
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

## Information

Model I am using (Bert, XLNet ...): roBerta

The problem arises when using:
* [X ] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [ X] my own task or dataset: (give details below)

My dataset is like a bunch of sentences with labels with them ranging from 0, 1, 2 , 3

## To reproduce

Steps to reproduce the behavior:

1. Looping throw each sentence
2. getting input Id's
3. trying to get the CLS vector for each example

My questions are;
Am i doing it right?
How do i know i am getting the CLS token?

```
for idx, row in df.iterrows(): #Looping through each Row
  input_ids = torch.tensor(tokenizer.encode(row.Sentence)).unsqueeze(0) #Getting the input id's of the sentence
  output = model(input_ids) #Passing it to model
  print( output.last_hidden_state) #Here is where i want to get the [CLS] token vector
```
 


## Expected behavior

How do i get the [CLS] token for each example of Sentence?

Asking this becuase, the transformer [documentation](https://huggingface.co/transformers/main_classes/output.html) does not specify how to get the [CLS] token vector

Any Help is much Appreciated


You can get the final hidden state of the [CLS] token as follows:

`cls_token_final_hidden_state = output.last_hidden_state[:,0,:]`

This is because the last hidden states are of shape (batch_size, sequence_length, hidden_size), and the [CLS] token is the first element across the sequence (also called time) dimension.<|||||>Ah i see that makes sense.

Huge thanks again Niels!