|
1 | | -import inspect |
2 | | - |
3 | 1 | import tokenizers |
4 | 2 | from tokenizers import decoders |
5 | 3 | from tokenizers import models |
6 | 4 | from tokenizers import normalizers |
7 | 5 | from tokenizers import pre_tokenizers |
8 | | -from tokenizers import processors |
9 | 6 |
|
10 | 7 | from keras_hub.src.api_export import keras_hub_export |
11 | 8 | from keras_hub.src.models.clip.clip_backbone import CLIPBackbone |
@@ -153,24 +150,6 @@ def set_vocabulary_and_merges(self, vocabulary, merges): |
153 | 150 | super().set_vocabulary_and_merges(vocabulary, merges) |
154 | 151 | if self.pad_with_end_token: |
155 | 152 | self.pad_token_id = self.end_token_id |
156 | | - if getattr(self, "_tokenizer") is not None: |
157 | | - # tokenizers <=0.22 use `cls`, >= 0.23 use `cls_token` because `cls` |
158 | | - # collides with the first argument of the Python `__new__`. |
159 | | - cls_token_arg = ( |
160 | | - "cls" |
161 | | - if "cls" |
162 | | - in inspect.signature(processors.RobertaProcessing).parameters |
163 | | - else "cls_token" |
164 | | - ) |
165 | | - preprocessing_args = { |
166 | | - "sep": (str(self.end_token), self.end_token_id), |
167 | | - cls_token_arg: (str(self.start_token), self.start_token_id), |
168 | | - "add_prefix_space": False, |
169 | | - "trim_offsets": False, |
170 | | - } |
171 | | - self._tokenizer.post_processor = processors.RobertaProcessing( |
172 | | - **preprocessing_args |
173 | | - ) |
174 | 153 |
|
175 | 154 | def _bpe_merge_and_update_cache_tf(self, tokens): |
176 | 155 | """Process unseen tokens and add to cache.""" |
@@ -254,28 +233,16 @@ def process_unseen_tokens(): |
254 | 233 | if self.sequence_length: |
255 | 234 | output_shape = tokens.shape.as_list() |
256 | 235 | output_shape[-1] = self.sequence_length |
257 | | - tokens = tokens.to_tensor(shape=output_shape) |
| 236 | + tokens = tokens.to_tensor( |
| 237 | + shape=output_shape, default_value=self.pad_token_id |
| 238 | + ) |
258 | 239 |
|
259 | 240 | # Convert to a dense output if input in scalar |
260 | 241 | if unbatched: |
261 | 242 | tokens = tf.squeeze(tokens, 0) |
262 | 243 | tf.ensure_shape(tokens, shape=[self.sequence_length]) |
263 | 244 | return tokens |
264 | 245 |
|
265 | | - def _tokenize_tokenizers(self, inputs): |
266 | | - outputs = super()._tokenize_tokenizers(inputs) |
267 | | - is_batched = True |
268 | | - if isinstance(outputs, str): |
269 | | - is_batched = False |
270 | | - outputs = [outputs] |
271 | | - elif isinstance(outputs, list) and isinstance(outputs[0], int): |
272 | | - is_batched = False |
273 | | - outputs = [outputs] |
274 | | - outputs = [output[1:-1] for output in outputs] |
275 | | - if not is_batched: |
276 | | - outputs = outputs[0] |
277 | | - return outputs |
278 | | - |
279 | 246 | @preprocessing_function |
280 | 247 | def _detokenize_tf(self, inputs): |
281 | 248 | self._check_vocabulary() |
|
0 commit comments