Repository: huggingface/transformers

Issue:
'BertForSequenceClassification' is not defined   'DUMMY_INPUTS' is not defined
transformers-2.1.1
https://github.com/huggingface/transformers#quick-tour-tf-20-training-and-pytorch-interoperability

i just copied and paste and run the code.

it showed 
```
NameError: name 'BertForSequenceClassification' is not defined
```

i can't even
```
from transformers import BertForSequenceClassification
```
```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-27-7a027f32a339> in <module>
----> 1 from transformers import BertForSequenceClassification

ImportError: cannot import name 'BertForSequenceClassification' from 'transformers' 
```
'BertForSequenceClassification' is not defined   'DUMMY_INPUTS' is not defined
transformers-2.1.1
https://github.com/huggingface/transformers#quick-tour-tf-20-training-and-pytorch-interoperability

i just copied and paste and run the code.

it showed 
```
NameError: name 'BertForSequenceClassification' is not defined
```

i can't even
```
from transformers import BertForSequenceClassification
```
```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-27-7a027f32a339> in <module>
----> 1 from transformers import BertForSequenceClassification

ImportError: cannot import name 'BertForSequenceClassification' from 'transformers' 
```


Discussion:
next time i 
```
import torch
```
it showed
```
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-14-71a5c3f94250> in <module>
----> 1 pytorch_model = BertForSequenceClassification.from_pretrained('model', from_tf=True)

~/miniconda3/envs/tfenv2/lib/python3.7/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    357                 try:
    358                     from transformers import load_tf2_checkpoint_in_pytorch_model
--> 359                     model = load_tf2_checkpoint_in_pytorch_model(model, resolved_archive_file, allow_missing_keys=True)
    360                 except ImportError as e:
    361                     logger.error("Loading a TensorFlow model in PyTorch, requires both PyTorch and TensorFlow to be installed. Please see "

~/miniconda3/envs/tfenv2/lib/python3.7/site-packages/transformers/modeling_tf_pytorch_utils.py in load_tf2_checkpoint_in_pytorch_model(pt_model, tf_checkpoint_path, tf_inputs, allow_missing_keys)
    199 
    200     if tf_inputs is None:
--> 201         tf_inputs = tf.constant(DUMMY_INPUTS)
    202 
    203     if tf_inputs is not None:

NameError: name 'DUMMY_INPUTS' is not defined
```
That's right, you can't import the PyTorch models if you don't have PyTorch installed in your environment. The `DUMMY_INPUTS` is a bug that was fixed with #1509. Could you please install it from source and let me know if you still have the error?
> Indeed, you can't import the PyTorch models if you don't have PyTorch installed in your environment. The `DUMMY_INPUTS` indeed is a bug that was fixed with #1509. Could you please install it from source and let me know if you still have the error?

does```pip install https://github.com/huggingface/transformers``` mean install from source?
I believe the correct way would be to specify it is a git url: 

`pip install git+https://github.com/huggingface/transformers.git`
> I believe the correct way would be to specify it is a git url:
> 
> `pip install git+https://github.com/huggingface/transformers.git`

it worked, but another issues showed up
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-5f3cd63765b9> in <module>
      6 inputs_2 = tokenizer.encode_plus(sentence_0, sentence_2, add_special_tokens=True, return_tensors='pt')
      7 
----> 8 pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
      9 pred_2 = pytorch_model(**inputs_2)[0].argmax().item()
     10 print("sentence_1 is", "a paraphrase" if pred_1 else "not a paraphrase", "of sentence_0")

~/miniconda3/envs/tfenv2/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

TypeError: forward() got an unexpected keyword argument 'special_tokens_mask'
```
Indeed, this is a bug, it seems the readme is not up-to-date since we added the `special_tokens_mask` in 2.1. Thank you for reporting it!

If you add the two lines mentioned below, it should work:

```py
inputs_1 = tokenizer.encode_plus(sentence_0, sentence_1, add_special_tokens=True, return_tensors='pt')
inputs_2 = tokenizer.encode_plus(sentence_0, sentence_2, add_special_tokens=True, return_tensors='pt')

del inputs_1["special_tokens_mask"]  # <---- add this
del inputs_2["special_tokens_mask"]  # <---- add this

pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
pred_2 = pytorch_model(**inputs_2)[0].argmax().item()
print("sentence_1 is", "a paraphrase" if pred_1 else "not a paraphrase", "of sentence_0")
print("sentence_2 is", "a paraphrase" if pred_2 else "not a paraphrase", "of sentence_0")
```
> Indeed, this is a bug, it seems the readme is not up-to-date since we added the `special_tokens_mask` in 2.1. Thank you for reporting it!
> 
> If you add the two lines mentioned below, it should work:
> 
> ```python
> inputs_1 = tokenizer.encode_plus(sentence_0, sentence_1, add_special_tokens=True, return_tensors='pt')
> inputs_2 = tokenizer.encode_plus(sentence_0, sentence_2, add_special_tokens=True, return_tensors='pt')
> 
> del inputs_1["special_tokens_mask"]  # <---- add this
> del inputs_2["special_tokens_mask"]  # <---- add this
> 
> pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
> pred_2 = pytorch_model(**inputs_2)[0].argmax().item()
> print("sentence_1 is", "a paraphrase" if pred_1 else "not a paraphrase", "of sentence_0")
> print("sentence_2 is", "a paraphrase" if pred_2 else "not a paraphrase", "of sentence_0")
> ```

thanks it worked!!
We updated the README accordingly, feel free to open other issues if you encounter other bugs.
@LysandreJik 

i got a similar error when i run `run_tf_glue.py`.

```
...
Dataset glue downloaded and prepared to /root/tensorflow_datasets/glue/mrpc/0.0.2. Subsequent calls will reuse this data.
INFO:absl:Constructing tf.data.Dataset for split None, from /root/tensorflow_datasets/glue/mrpc/0.0.2
Train for 114 steps, validate for 6 steps
Epoch 1/2
114/114 [==============================] - 69s 601ms/step - loss: 0.5447 - accuracy: 0.7314 - val_loss: 0.4515 - val_accuracy: 0.7943
Epoch 2/2
114/114 [==============================] - 35s 306ms/step - loss: 0.2919 - accuracy: 0.8872 - val_loss: 0.4064 - val_accuracy: 0.8542
Traceback (most recent call last):
  File "run_tf_glue.py", line 51, in <module>
    pytorch_model = BertForSequenceClassification.from_pretrained('./save/', from_tf=True)
  File "/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py", line 359, in from_pretrained
    model = load_tf2_checkpoint_in_pytorch_model(model, resolved_archive_file, allow_missing_keys=True)
  File "/usr/local/lib/python3.6/dist-packages/transformers/modeling_tf_pytorch_utils.py", line 201, in load_tf2_checkpoint_in_pytorch_model
    tf_inputs = tf.constant(DUMMY_INPUTS)
NameError: name 'DUMMY_INPUTS' is not defined
```

tf version : 2.0          ( via pip )
torch version : 1.2.0 (via pip )
Have you tried installing from source, as was mentioned in the comment before yourts? `pip install git+https://github.com/huggingface/transformers.git`
@LysandreJik 

i got another error ;;
```
$ pip3 install git+https://github.com/huggingface/transformers.git --upgrade
$ python run_tf_glue.py
...
Train for 114 steps, validate for 6 steps
Epoch 1/2
114/114 [==============================] - 60s 525ms/step - loss: 0.5817 - accuracy: 0.6911 - val_loss: 0.3961 - val_accuracy: 0.8229
Epoch 2/2
114/114 [==============================] - 34s 300ms/step - loss: 0.3505 - accuracy: 0.8460 - val_loss: 0.3403 - val_accuracy: 0.8516
Traceback (most recent call last):
  File "run_tf_glue.py", line 60, in <module>
    pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'special_tokens_mask'
```
next time i 
```
import torch
```
it showed
```
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-14-71a5c3f94250> in <module>
----> 1 pytorch_model = BertForSequenceClassification.from_pretrained('model', from_tf=True)

~/miniconda3/envs/tfenv2/lib/python3.7/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    357                 try:
    358                     from transformers import load_tf2_checkpoint_in_pytorch_model
--> 359                     model = load_tf2_checkpoint_in_pytorch_model(model, resolved_archive_file, allow_missing_keys=True)
    360                 except ImportError as e:
    361                     logger.error("Loading a TensorFlow model in PyTorch, requires both PyTorch and TensorFlow to be installed. Please see "

~/miniconda3/envs/tfenv2/lib/python3.7/site-packages/transformers/modeling_tf_pytorch_utils.py in load_tf2_checkpoint_in_pytorch_model(pt_model, tf_checkpoint_path, tf_inputs, allow_missing_keys)
    199 
    200     if tf_inputs is None:
--> 201         tf_inputs = tf.constant(DUMMY_INPUTS)
    202 
    203     if tf_inputs is not None:

NameError: name 'DUMMY_INPUTS' is not defined
```
That's right, you can't import the PyTorch models if you don't have PyTorch installed in your environment. The `DUMMY_INPUTS` is a bug that was fixed with #1509. Could you please install it from source and let me know if you still have the error?
> Indeed, you can't import the PyTorch models if you don't have PyTorch installed in your environment. The `DUMMY_INPUTS` indeed is a bug that was fixed with #1509. Could you please install it from source and let me know if you still have the error?

does```pip install https://github.com/huggingface/transformers``` mean install from source?
I believe the correct way would be to specify it is a git url: 

`pip install git+https://github.com/huggingface/transformers.git`
> I believe the correct way would be to specify it is a git url:
> 
> `pip install git+https://github.com/huggingface/transformers.git`

it worked, but another issues showed up
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-5f3cd63765b9> in <module>
      6 inputs_2 = tokenizer.encode_plus(sentence_0, sentence_2, add_special_tokens=True, return_tensors='pt')
      7 
----> 8 pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
      9 pred_2 = pytorch_model(**inputs_2)[0].argmax().item()
     10 print("sentence_1 is", "a paraphrase" if pred_1 else "not a paraphrase", "of sentence_0")

~/miniconda3/envs/tfenv2/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

TypeError: forward() got an unexpected keyword argument 'special_tokens_mask'
```
Indeed, this is a bug, it seems the readme is not up-to-date since we added the `special_tokens_mask` in 2.1. Thank you for reporting it!

If you add the two lines mentioned below, it should work:

```py
inputs_1 = tokenizer.encode_plus(sentence_0, sentence_1, add_special_tokens=True, return_tensors='pt')
inputs_2 = tokenizer.encode_plus(sentence_0, sentence_2, add_special_tokens=True, return_tensors='pt')

del inputs_1["special_tokens_mask"]  # <---- add this
del inputs_2["special_tokens_mask"]  # <---- add this

pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
pred_2 = pytorch_model(**inputs_2)[0].argmax().item()
print("sentence_1 is", "a paraphrase" if pred_1 else "not a paraphrase", "of sentence_0")
print("sentence_2 is", "a paraphrase" if pred_2 else "not a paraphrase", "of sentence_0")
```
> Indeed, this is a bug, it seems the readme is not up-to-date since we added the `special_tokens_mask` in 2.1. Thank you for reporting it!
> 
> If you add the two lines mentioned below, it should work:
> 
> ```python
> inputs_1 = tokenizer.encode_plus(sentence_0, sentence_1, add_special_tokens=True, return_tensors='pt')
> inputs_2 = tokenizer.encode_plus(sentence_0, sentence_2, add_special_tokens=True, return_tensors='pt')
> 
> del inputs_1["special_tokens_mask"]  # <---- add this
> del inputs_2["special_tokens_mask"]  # <---- add this
> 
> pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
> pred_2 = pytorch_model(**inputs_2)[0].argmax().item()
> print("sentence_1 is", "a paraphrase" if pred_1 else "not a paraphrase", "of sentence_0")
> print("sentence_2 is", "a paraphrase" if pred_2 else "not a paraphrase", "of sentence_0")
> ```

thanks it worked!!
We updated the README accordingly, feel free to open other issues if you encounter other bugs.
@LysandreJik 

i got a similar error when i run `run_tf_glue.py`.

```
...
Dataset glue downloaded and prepared to /root/tensorflow_datasets/glue/mrpc/0.0.2. Subsequent calls will reuse this data.
INFO:absl:Constructing tf.data.Dataset for split None, from /root/tensorflow_datasets/glue/mrpc/0.0.2
Train for 114 steps, validate for 6 steps
Epoch 1/2
114/114 [==============================] - 69s 601ms/step - loss: 0.5447 - accuracy: 0.7314 - val_loss: 0.4515 - val_accuracy: 0.7943
Epoch 2/2
114/114 [==============================] - 35s 306ms/step - loss: 0.2919 - accuracy: 0.8872 - val_loss: 0.4064 - val_accuracy: 0.8542
Traceback (most recent call last):
  File "run_tf_glue.py", line 51, in <module>
    pytorch_model = BertForSequenceClassification.from_pretrained('./save/', from_tf=True)
  File "/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py", line 359, in from_pretrained
    model = load_tf2_checkpoint_in_pytorch_model(model, resolved_archive_file, allow_missing_keys=True)
  File "/usr/local/lib/python3.6/dist-packages/transformers/modeling_tf_pytorch_utils.py", line 201, in load_tf2_checkpoint_in_pytorch_model
    tf_inputs = tf.constant(DUMMY_INPUTS)
NameError: name 'DUMMY_INPUTS' is not defined
```

tf version : 2.0          ( via pip )
torch version : 1.2.0 (via pip )
Have you tried installing from source, as was mentioned in the comment before yourts? `pip install git+https://github.com/huggingface/transformers.git`
@LysandreJik 

i got another error ;;
```
$ pip3 install git+https://github.com/huggingface/transformers.git --upgrade
$ python run_tf_glue.py
...
Train for 114 steps, validate for 6 steps
Epoch 1/2
114/114 [==============================] - 60s 525ms/step - loss: 0.5817 - accuracy: 0.6911 - val_loss: 0.3961 - val_accuracy: 0.8229
Epoch 2/2
114/114 [==============================] - 34s 300ms/step - loss: 0.3505 - accuracy: 0.8460 - val_loss: 0.3403 - val_accuracy: 0.8516
Traceback (most recent call last):
  File "run_tf_glue.py", line 60, in <module>
    pred_1 = pytorch_model(**inputs_1)[0].argmax().item()
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'special_tokens_mask'
```

Resolving patch:
diff --git a/transformers/tokenization_utils.py b/transformers/tokenization_utils.py
--- a/transformers/tokenization_utils.py
+++ b/transformers/tokenization_utils.py
@@ -744,6 +744,9 @@ def encode_plus(self,
                     stride=0,
                     truncation_strategy='longest_first',
                     return_tensors=None,
+                    return_token_type_ids=True,
+                    return_overflowing_tokens=False,
+                    return_special_tokens_mask=False,
                     **kwargs):
         """
         Returns a dictionary containing the encoded sequence or sequence pair and additional informations:
@@ -770,7 +773,30 @@ def encode_plus(self,
                 - 'do_not_truncate': Does not truncate (raise an error if the input sequence is longer than max_length)
             return_tensors: (optional) can be set to 'tf' or 'pt' to return respectively TensorFlow tf.constant
                 or PyTorch torch.Tensor instead of a list of python integers.
+            return_token_type_ids: (optional) Set to False to avoid returning token_type_ids (default True).
+            return_overflowing_tokens: (optional) Set to True to return overflowing token information (default False).
+            return_special_tokens_mask: (optional) Set to True to return special tokens mask information (default False).
             **kwargs: passed to the `self.tokenize()` method
+
+        Return:
+            A Dictionary of shape::
+
+                {
+                    input_ids: list[int],
+                    token_type_ids: list[int] if return_token_type_ids is True (default)
+                    overflowing_tokens: list[int] if a ``max_length`` is specified and return_overflowing_tokens is True
+                    num_truncated_tokens: int if a ``max_length`` is specified and return_overflowing_tokens is True
+                    special_tokens_mask: list[int] if ``add_special_tokens`` if set to ``True`` and return_special_tokens_mask is True
+                }
+
+            With the fields:
+                ``input_ids``: list of token ids to be fed to a model
+                ``token_type_ids``: list of token type ids to be fed to a model
+
+                ``overflowing_tokens``: list of overflowing tokens if a max length is specified.
+                ``num_truncated_tokens``: number of overflowing tokens a ``max_length`` is specified
+                ``special_tokens_mask``: if adding special tokens, this is a list of [0, 1], with 0 specifying special added
+                tokens and 1 specifying sequence tokens.
         """
 
         def get_input_ids(text):
@@ -792,10 +818,17 @@ def get_input_ids(text):
                                       add_special_tokens=add_special_tokens,
                                       stride=stride,
                                       truncation_strategy=truncation_strategy,
-                                      return_tensors=return_tensors)
+                                      return_tensors=return_tensors,
+                                      return_token_type_ids=return_token_type_ids,
+                                      return_overflowing_tokens=return_overflowing_tokens,
+                                      return_special_tokens_mask=return_special_tokens_mask)
 
     def prepare_for_model(self, ids, pair_ids=None, max_length=None, add_special_tokens=True, stride=0,
-                          truncation_strategy='longest_first', return_tensors=None):
+                          truncation_strategy='longest_first',
+                          return_tensors=None,
+                          return_token_type_ids=True,
+                          return_overflowing_tokens=False,
+                          return_special_tokens_mask=False):
         """
         Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model.
         It adds special tokens, truncates
@@ -820,21 +853,27 @@ def prepare_for_model(self, ids, pair_ids=None, max_length=None, add_special_tok
                 - 'do_not_truncate': Does not truncate (raise an error if the input sequence is longer than max_length)
             return_tensors: (optional) can be set to 'tf' or 'pt' to return respectively TensorFlow tf.constant
                 or PyTorch torch.Tensor instead of a list of python integers.
+            return_token_type_ids: (optional) Set to False to avoid returning token_type_ids (default True).
+            return_overflowing_tokens: (optional) Set to True to return overflowing token information (default False).
+            return_special_tokens_mask: (optional) Set to True to return special tokens mask information (default False).
 
         Return:
             A Dictionary of shape::
 
                 {
                     input_ids: list[int],
-                    overflowing_tokens: list[int] if a ``max_length`` is specified, else None
-                    special_tokens_mask: list[int] if ``add_special_tokens`` if set to ``True``
+                    token_type_ids: list[int] if return_token_type_ids is True (default)
+                    overflowing_tokens: list[int] if a ``max_length`` is specified and return_overflowing_tokens is True
+                    num_truncated_tokens: int if a ``max_length`` is specified and return_overflowing_tokens is True
+                    special_tokens_mask: list[int] if ``add_special_tokens`` if set to ``True`` and return_special_tokens_mask is True
                 }
 
             With the fields:
-                ``input_ids``: list of tokens to be fed to a model
+                ``input_ids``: list of token ids to be fed to a model
+                ``token_type_ids``: list of token type ids to be fed to a model
 
                 ``overflowing_tokens``: list of overflowing tokens if a max length is specified.
-
+                ``num_truncated_tokens``: number of overflowing tokens a ``max_length`` is specified
                 ``special_tokens_mask``: if adding special tokens, this is a list of [0, 1], with 0 specifying special added
                 tokens and 1 specifying sequence tokens.
         """
@@ -843,23 +882,31 @@ def prepare_for_model(self, ids, pair_ids=None, max_length=None, add_special_tok
         len_pair_ids = len(pair_ids) if pair else 0
 
         encoded_inputs = {}
+
+        # Handle max sequence length
         total_len = len_ids + len_pair_ids + (self.num_added_tokens(pair=pair) if add_special_tokens else 0)
         if max_length and total_len > max_length:
             ids, pair_ids, overflowing_tokens = self.truncate_sequences(ids, pair_ids=pair_ids,
                                                                         num_tokens_to_remove=total_len-max_length,
                                                                         truncation_strategy=truncation_strategy,
                                                                         stride=stride)
-            encoded_inputs["overflowing_tokens"] = overflowing_tokens
-            encoded_inputs["num_truncated_tokens"] = total_len - max_length
+            if return_overflowing_tokens:
+                encoded_inputs["overflowing_tokens"] = overflowing_tokens
+                encoded_inputs["num_truncated_tokens"] = total_len - max_length
 
+        # Handle special_tokens
         if add_special_tokens:
             sequence = self.build_inputs_with_special_tokens(ids, pair_ids)
             token_type_ids = self.create_token_type_ids_from_sequences(ids, pair_ids)
-            encoded_inputs["special_tokens_mask"] = self.get_special_tokens_mask(ids, pair_ids)
+            special_tokens_mask = self.get_special_tokens_mask(ids, pair_ids)
         else:
             sequence = ids + pair_ids if pair else ids
             token_type_ids = [0] * len(ids) + ([1] * len(pair_ids) if pair else [])
+            special_tokens_mask = [0] * (len(ids) + (len(pair_ids) if pair else 0))
+        if return_special_tokens_mask:
+            encoded_inputs["special_tokens_mask"] = self.get_special_tokens_mask(ids, pair_ids)
 
+        # Prepare inputs as tensors if asked
         if return_tensors == 'tf' and is_tf_available():
             sequence = tf.constant([sequence])
             token_type_ids = tf.constant([token_type_ids])
@@ -870,12 +917,15 @@ def prepare_for_model(self, ids, pair_ids=None, max_length=None, add_special_tok
             logger.warning("Unable to convert output to tensors format {}, PyTorch or TensorFlow is not available.".format(return_tensors))
 
         encoded_inputs["input_ids"] = sequence
-        encoded_inputs["token_type_ids"] = token_type_ids
+        if return_token_type_ids:
+            encoded_inputs["token_type_ids"] = token_type_ids
 
         if max_length and len(encoded_inputs["input_ids"]) > max_length:
             encoded_inputs["input_ids"] = encoded_inputs["input_ids"][:max_length]
-            encoded_inputs["token_type_ids"] = encoded_inputs["token_type_ids"][:max_length]
-            encoded_inputs["special_tokens_mask"] = encoded_inputs["special_tokens_mask"][:max_length]
+            if return_token_type_ids:
+                encoded_inputs["token_type_ids"] = encoded_inputs["token_type_ids"][:max_length]
+            if return_special_tokens_mask:
+                encoded_inputs["special_tokens_mask"] = encoded_inputs["special_tokens_mask"][:max_length]
 
         return encoded_inputs
 


Test patch:
diff --git a/transformers/tests/tokenization_tests_commons.py b/transformers/tests/tokenization_tests_commons.py
--- a/transformers/tests/tokenization_tests_commons.py
+++ b/transformers/tests/tokenization_tests_commons.py
@@ -223,7 +223,11 @@ def test_maximum_encoding_length_single_input(self):
             sequence = tokenizer.encode(seq_0, add_special_tokens=False)
             num_added_tokens = tokenizer.num_added_tokens()
             total_length = len(sequence) + num_added_tokens
-            information = tokenizer.encode_plus(seq_0, max_length=total_length - 2, add_special_tokens=True, stride=stride)
+            information = tokenizer.encode_plus(seq_0,
+                                                max_length=total_length - 2,
+                                                add_special_tokens=True,
+                                                stride=stride,
+                                                return_overflowing_tokens=True)
 
             truncated_sequence = information["input_ids"]
             overflowing_tokens = information["overflowing_tokens"]
@@ -250,10 +254,12 @@ def test_maximum_encoding_length_pair_input(self):
             )
 
             information = tokenizer.encode_plus(seq_0, seq_1, max_length=len(sequence) - 2, add_special_tokens=True,
-                                                stride=stride, truncation_strategy='only_second')
+                                                stride=stride, truncation_strategy='only_second',
+                                                return_overflowing_tokens=True)
             information_first_truncated = tokenizer.encode_plus(seq_0, seq_1, max_length=len(sequence) - 2,
                                                                 add_special_tokens=True, stride=stride,
-                                                                truncation_strategy='only_first')
+                                                                truncation_strategy='only_first',
+                                                                return_overflowing_tokens=True)
 
             truncated_sequence = information["input_ids"]
             overflowing_tokens = information["overflowing_tokens"]
@@ -285,7 +291,7 @@ def test_special_tokens_mask(self):
 
             # Testing single inputs
             encoded_sequence = tokenizer.encode(sequence_0, add_special_tokens=False)
-            encoded_sequence_dict = tokenizer.encode_plus(sequence_0, add_special_tokens=True)
+            encoded_sequence_dict = tokenizer.encode_plus(sequence_0, add_special_tokens=True, return_special_tokens_mask=True)
             encoded_sequence_w_special = encoded_sequence_dict["input_ids"]
             special_tokens_mask = encoded_sequence_dict["special_tokens_mask"]
             self.assertEqual(len(special_tokens_mask), len(encoded_sequence_w_special))
@@ -297,7 +303,8 @@ def test_special_tokens_mask(self):
             # Testing inputs pairs
             encoded_sequence = tokenizer.encode(sequence_0, add_special_tokens=False) + tokenizer.encode(sequence_1,
                                                                                                          add_special_tokens=False)
-            encoded_sequence_dict = tokenizer.encode_plus(sequence_0, sequence_1, add_special_tokens=True)
+            encoded_sequence_dict = tokenizer.encode_plus(sequence_0, sequence_1, add_special_tokens=True,
+                                                          return_special_tokens_mask=True)
             encoded_sequence_w_special = encoded_sequence_dict["input_ids"]
             special_tokens_mask = encoded_sequence_dict["special_tokens_mask"]
             self.assertEqual(len(special_tokens_mask), len(encoded_sequence_w_special))
@@ -309,7 +316,9 @@ def test_special_tokens_mask(self):
             # Testing with already existing special tokens
             if tokenizer.cls_token_id == tokenizer.unk_token_id and tokenizer.cls_token_id == tokenizer.unk_token_id:
                 tokenizer.add_special_tokens({'cls_token': '
', 'sep_token': '
'})
-            encoded_sequence_dict = tokenizer.encode_plus(sequence_0, add_special_tokens=True)
+            encoded_sequence_dict = tokenizer.encode_plus(sequence_0,
+                                                          add_special_tokens=True,
+                                                          return_special_tokens_mask=True)
             encoded_sequence_w_special = encoded_sequence_dict["input_ids"]
             special_tokens_mask_orig = encoded_sequence_dict["special_tokens_mask"]
             special_tokens_mask = tokenizer.get_special_tokens_mask(encoded_sequence_w_special, already_has_special_tokens=True)