Check if text is set to avoid IndexError (#4209)

Fix for https://github.com/huggingface/transformers/issues/3809
This commit is contained in:
Malte
2020-06-22 17:09:05 +02:00
committed by GitHub
parent 90f4b24520
commit d2a7c86dc3

View File

@@ -236,7 +236,7 @@ class RobertaTokenizer(GPT2Tokenizer):
add_prefix_space = kwargs["add_prefix_space"]
else:
add_prefix_space = add_special_tokens
if add_prefix_space and not text[0].isspace():
if add_prefix_space and len(text) > 0 and not text[0].isspace():
text = " " + text
return text