UnicodeEncodeError: surrogates not allowed with GPT2Tokenizer
Author: g-karthik
Pull request: no

## Environment info
     
- `transformers` version: 3.1.0
- Platform: EC2
- Python version: 3.6

### Who can help
@mfuntowicz @LysandreJik 


## Information

Model I am using: GPT-2

The problem arises when using the `GPT2Tokenizer` on a piece of text from a file that was written `utf-8` strings and is being opened in `utf-8`.

## To reproduce

```
tokenizer = GPT2Tokenizer.from_pretrained("gpt2-xl")
text = "some utf-8 string" # this string is loaded from a file containing a dictionary {"text": "<some text>"} in each row - the file itself was written by converting TFRecords to text and "<some text>" was decoded explicitly to "utf-8" prior to being dumped into this dictionary and written
text_ids = tokenizer.encode(text)
```

Stack trace I get:

```
Traceback (most recent call last):
text_ids = tokenizer.encode(text)
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 1730, in encode
**kwargs,
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 2045, in encode_plus
**kwargs,
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 448, in _encode_plus
first_ids = get_input_ids(text)
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 419, in get_input_ids
tokens = self.tokenize(text, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 350, in tokenize
tokenized_text = split_on_tokens(no_split_token, text)
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 344, in split_on_tokens
for token in tokenized_text
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 344, in <genexpr>
for token in tokenized_text
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_gpt2.py", line 237, in _tokenize
self.byte_encoder[b] for b in token.encode("utf-8")
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed
```

## Expected behavior

It should tokenize and then convert the tokens to ids just fine, since `text`  is a `utf-8` string.


I'm trying to specifically identify the `text` itself from my file that leads to this error, but I am unable to print it either. I used a try-except block to catch the above `UnicodeEncodeError` and tried to print the `text`, but print itself expectedly failed because print is using the `ascii` codec. Is there a good way for me to identify the exact piece of text that led to this failure? Perhaps it'll help assist with debugging this issue.

Comments:
Unfortunately, if simply printing the string is impossible, this is out of our expertise. You have probably already seen those threads, but they may help you debug what's going on:

https://stackoverflow.com/questions/27366479/python-3-os-walk-file-paths-unicodeencodeerror-utf-8-codec-cant-encode-s
https://stackoverflow.com/questions/38147259/how-to-work-with-surrogate-pairs-in-python

Let us know if you find an answer!

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/master/CONTRIBUTING.md) are likely to be ignored.