Perform encoding process of the tokenizer. Parameters ------------ inputs : str or list. The text sequence. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns --
(self, input: Union[str, list[str]], *args, **kwargs)
| 208 | return tokenized_datasets |
| 209 | |
| 210 | def encode(self, input: Union[str, list[str]], *args, **kwargs) -> Union[list[int], list[list[int]]]: |
| 211 | """ |
| 212 | Perform encoding process of the tokenizer. |
| 213 | |
| 214 | Parameters |
| 215 | ------------ |
| 216 | inputs : str or list. |
| 217 | The text sequence. |
| 218 | |
| 219 | args : Optional. |
| 220 | Positional arguments. |
| 221 | |
| 222 | kwargs : Optional. |
| 223 | Keyword arguments. |
| 224 | |
| 225 | Returns |
| 226 | ------------ |
| 227 | outputs : |
| 228 | if string input,return the tokenized inputs. |
| 229 | "Hello,world!"-> [101, 7592, 1010, 2088, 102] |
| 230 | if batch input,return {input_ids,attention_mask,token_type_ids} |
| 231 | ["Hello,world!","Hello!"] -> |
| 232 | { |
| 233 | 'input_ids': tensor([[ 101, 7592, 1010, 2088, 102],...), |
| 234 | 'attention_mask': tensor([[1, 1, 1, 1, 1],[0,0,1,1,1]]) |
| 235 | } |
| 236 | """ |
| 237 | if isinstance(input, list): |
| 238 | return self.tokenizer(text=input, **kwargs) # batch encode,will automatically do left padding |
| 239 | elif isinstance(input, str): |
| 240 | return self.tokenizer.encode(text=input, **kwargs) |
| 241 | else: |
| 242 | raise NotImplementedError(f'type "{type(input)}" cannot be encoded') |
| 243 | |
| 244 | def decode(self, input, **kwargs) -> Union[str, list[str]]: |
| 245 | """ |
no outgoing calls