@@ -89,11 +89,7 @@ def finalize(self):
8989 def text (self ):
9090 if self ._current_tokens :
9191 self ._current_text = self ._tokenizer .decode (self ._current_tokens )
92- if self ._current_text .endswith ("\ufffd " ) or (
93- self ._tokenizer .clean_up_tokenization_spaces
94- and len (self ._current_text ) > 0
95- and self ._current_text [- 1 ] == " "
96- ):
92+ if self ._current_text .endswith ("\ufffd " ):
9793 self ._current_text = self ._current_text [:- 1 ]
9894 if self ._current_text and self ._current_text [- 1 ] == "\n " :
9995 self ._text += self ._current_text
@@ -161,8 +157,6 @@ class BPEStreamingDetokenizer(StreamingDetokenizer):
161157 _space_matches = ("." , "?" , "!" , "," , "n't" , "'m" , "'s" , "'ve" , "'re" )
162158
163159 def __init__ (self , tokenizer ):
164- self .clean_spaces = tokenizer .clean_up_tokenization_spaces
165-
166160 # Extract the tokens in a list from id to text
167161 self .tokenmap = [None ] * len (tokenizer .vocab )
168162 for value , tokenid in tokenizer .vocab .items ():
@@ -197,8 +191,6 @@ def _maybe_trim_space(self, current_text):
197191 return current_text
198192 elif not self .text :
199193 return current_text [1 :]
200- elif self .clean_spaces and current_text [1 :].startswith (self ._space_matches ):
201- return current_text [1 :]
202194 return current_text
203195
204196 def add_token (self , token ):
@@ -208,10 +200,7 @@ def add_token(self, token):
208200 text = self ._decode_bytes (self ._unflushed )
209201
210202 # For multi-byte utf-8 wait until they are complete
211- # For single spaces wait until the next token to clean it if needed
212- if not text .endswith ("\ufffd " ) and not (
213- len (v ) == 1 and self ._byte_decoder .get (v [0 ]) == 32
214- ):
203+ if not text .endswith ("\ufffd " ):
215204 self .text += self ._maybe_trim_space (text )
216205 self ._unflushed = ""
217206
0 commit comments