Perform decoding process of the tokenizer. Parameters ------------ inputs : list or tensor. The token sequence. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns
(self, input, **kwargs)
| 242 | raise NotImplementedError(f'type "{type(input)}" cannot be encoded') |
| 243 | |
| 244 | def decode(self, input, **kwargs) -> Union[str, list[str]]: |
| 245 | """ |
| 246 | Perform decoding process of the tokenizer. |
| 247 | |
| 248 | Parameters |
| 249 | ------------ |
| 250 | inputs : list or tensor. |
| 251 | The token sequence. |
| 252 | |
| 253 | args : Optional. |
| 254 | Positional arguments. |
| 255 | |
| 256 | kwargs : Optional. |
| 257 | Keyword arguments. |
| 258 | |
| 259 | Returns |
| 260 | ------------ |
| 261 | outputs : |
| 262 | The text decoded from the token inputs. |
| 263 | if batch input,return the list of text |
| 264 | [[101, 7592, 1010, 2088, 102],[101, 7592, 1010, 2088, 102]]-> ["Hello,world!","Hello,world!" |
| 265 | if single input,return the text |
| 266 | [101, 7592, 1010, 2088, 102]-> "Hello,world!" |
| 267 | """ |
| 268 | if isinstance(input, list): |
| 269 | input = torch.tensor(input) |
| 270 | if input.dim() == 2: |
| 271 | return self.tokenizer.batch_decode(input, **kwargs) # batch_decode |
| 272 | else: |
| 273 | # Can be list of ints or a Tensor |
| 274 | return self.tokenizer.decode(input, **kwargs) |
| 275 | |
| 276 | def inference(self, inputs, release_gpu: bool = False, use_vllm: bool = False, **kwargs): |
| 277 | """ |
no outgoing calls