tokenizer.encode_plus stopped returning `attention_mask` and pad_to_max_length
Author: shikharsingla
Pull request: no

# 🐛 Bug
tokenizer.encode_plus stopped returning `attention_mask` and pad_to_max_length

## Information

Model I am using (Bert, XLNet ...):
Bert

Language I am using the model on (English, Chinese ...):
English

The problem arises when using:
my own modified scripts: (give details below)

The tasks I am working on is:
 my own task or dataset: (give details below)

## To reproduce

import torch
import pandas as pd

# If there's a GPU available...
if torch.cuda.is_available():    

    # Tell PyTorch to use the GPU.    
    device = torch.device("cuda")

    print('There are %d GPU(s) available.' % torch.cuda.device_count())

    print('We will use the GPU:', torch.cuda.get_device_name(0))

# If not...
else:
    print('No GPU available, using the CPU instead.')
    device = torch.device("cpu")

# Load the dataset into a pandas dataframe.
df = pd.read_csv("/home/shikhar_singla/Downloads/cola_public/raw/in_domain_train.tsv", delimiter='\t', header=None, names=['sentence_source', 'label', 'label_notes', 'sentence'])

# Report the number of sentences.
print('Number of training sentences: {:,}\n'.format(df.shape[0]))

# Display 10 random rows from the data.
df.sample(10)

df.loc[df.label == 0].sample(5)[['sentence', 'label']]
# Get the lists of sentences and their labels.
sentences = df.sentence.values
labels = df.label.values

from transformers import BertTokenizer

# Load the BERT tokenizer.
print('Loading BERT tokenizer...')
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)

# Print the original sentence.
print(' Original: ', sentences[0])

# Print the sentence split into tokens.
print('Tokenized: ', tokenizer.tokenize(sentences[0]))

# Print the sentence mapped to token ids.
print('Token IDs: ', tokenizer.convert_tokens_to_ids(tokenizer.tokenize(sentences[0])))

max_len = 0

# For every sentence...
for sent in sentences:

    # Tokenize the text and add `[CLS]` and `[SEP]` tokens.
    input_ids = tokenizer.encode(sent, add_special_tokens=True)

    # Update the maximum sentence length.
    max_len = max(max_len, len(input_ids))

print('Max sentence length: ', max_len)

# Tokenize all of the sentences and map the tokens to thier word IDs.
input_ids = []
attention_masks = []

# For every sentence...
for sent in sentences:
    # `encode_plus` will:
    #   (1) Tokenize the sentence.
    #   (2) Prepend the `[CLS]` token to the start.
    #   (3) Append the `[SEP]` token to the end.
    #   (4) Map tokens to their IDs.
    #   (5) Pad or truncate the sentence to `max_length`
    #   (6) Create attention masks for [PAD] tokens.
    encoded_dict = tokenizer.encode_plus(
                        sent,                      # Sentence to encode.
                        add_special_tokens = True, # Add '[CLS]' and '[SEP]'
                        max_length = 64,           # Pad & truncate all sentences.
                        pad_to_max_length = True,
                        return_attention_mask = True,   # Construct attn. masks.
                        return_tensors = 'pt',     # Return pytorch tensors.
                   )
    
    # Add the encoded sentence to the list.    
    input_ids.append(encoded_dict['input_ids'])
    
    # And its attention mask (simply differentiates padding from non-padding).
    attention_masks.append(encoded_dict['attention_mask'])

# Convert the lists into tensors.
input_ids = torch.cat(input_ids, dim=0)
attention_masks = torch.cat(attention_masks, dim=0)
labels = torch.tensor(labels)

# Print sentence 0, now as a list of IDs.
print('Original: ', sentences[0])
print('Token IDs:', input_ids[0])







There are 1 GPU(s) available.
We will use the GPU: GeForce RTX 2080 Ti
Number of training sentences: 8,551

To use data.metrics please install scikit-learn. See https://scikit-learn.org/stable/index.html
Loading BERT tokenizer...
 Original:  Our friends won't buy this analysis, let alone the next one we propose.
Tokenized:  ['our', 'friends', 'won', "'", 't', 'buy', 'this', 'analysis', ',', 'let', 'alone', 'the', 'next', 'one', 'we', 'propose', '.']
Token IDs:  [2256, 2814, 2180, 1005, 1056, 4965, 2023, 4106, 1010, 2292, 2894, 1996, 2279, 2028, 2057, 16599, 1012]
Max sentence length:  47
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-e10b3c7561a8> in <module>
     72     #   (5) Pad or truncate the sentence to `max_length`
     73     #   (6) Create attention masks for [PAD] tokens.
---> 74     encoded_dict = tokenizer.encode_plus(
     75                         sent,                      # Sentence to encode.
     76                         add_special_tokens = True, # Add '[CLS]' and '[SEP]'

~/anaconda3/envs/bert_gpu_torch/lib/python3.8/site-packages/transformers/tokenization_utils.py in encode_plus(self, text, text_pair, add_special_tokens, max_length, stride, truncation_strategy, return_tensors, **kwargs)
    784                 raise ValueError("Input is not valid. Should be a string, a list/tuple of strings or a list/tuple of integers.")
    785 
--> 786         first_ids = get_input_ids(text)
    787         second_ids = get_input_ids(text_pair) if text_pair is not None else None
    788 

~/anaconda3/envs/bert_gpu_torch/lib/python3.8/site-packages/transformers/tokenization_utils.py in get_input_ids(text)
    776         def get_input_ids(text):
    777             if isinstance(text, six.string_types):
--> 778                 return self.convert_tokens_to_ids(self.tokenize(text, **kwargs))
    779             elif isinstance(text, (list, tuple)) and len(text) > 0 and isinstance(text[0], six.string_types):
    780                 return self.convert_tokens_to_ids(text)

~/anaconda3/envs/bert_gpu_torch/lib/python3.8/site-packages/transformers/tokenization_utils.py in tokenize(self, text, **kwargs)
    647 
    648         added_tokens = list(self.added_tokens_encoder.keys()) + self.all_special_tokens
--> 649         tokenized_text = split_on_tokens(added_tokens, text)
    650         return tokenized_text
    651 

~/anaconda3/envs/bert_gpu_torch/lib/python3.8/site-packages/transformers/tokenization_utils.py in split_on_tokens(tok_list, text)
    642                 text_list = tokenized_text
    643 
--> 644             return sum((self._tokenize(token, **kwargs) if token not \
    645                     in self.added_tokens_encoder and token not in self.all_special_tokens \
    646                     else [token] for token in tokenized_text), [])

~/anaconda3/envs/bert_gpu_torch/lib/python3.8/site-packages/transformers/tokenization_utils.py in <genexpr>(.0)
    642                 text_list = tokenized_text
    643 
--> 644             return sum((self._tokenize(token, **kwargs) if token not \
    645                     in self.added_tokens_encoder and token not in self.all_special_tokens \
    646                     else [token] for token in tokenized_text), [])

TypeError: _tokenize() got an unexpected keyword argument 'pad_to_max_length'

## 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: 2.1.1
- Platform: Ubuntu 20.04
- Python version: 3.8.3
- PyTorch version (GPU?): 1.5.0
- Tensorflow version (GPU?):
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: no


Comments:
Hello! You're using `transformers` version 2.1.1, which didn't have all of these features, as you can see in the [documentation of version 2.1.1](https://huggingface.co/transformers/v2.1.1/main_classes/tokenizer.html#transformers.PreTrainedTokenizer.encode_plus).

I would recommend upgrading your `transformers` version to the latest one to have access to all features!