(
self,
tensor: Union[torch.Tensor, list],
skip_special_tokens: Optional[bool] = None,
)
| 146 | return torch.tensor(tokens, dtype=torch.int, device=device) |
| 147 | |
| 148 | def decode( |
| 149 | self, |
| 150 | tensor: Union[torch.Tensor, list], |
| 151 | skip_special_tokens: Optional[bool] = None, |
| 152 | ) -> str: |
| 153 | if self.backend != HUGGINGFACE and skip_special_tokens is not None: |
| 154 | print(f'WARN: Using {self.backend} does not allow `skip_special_tokens`.') |
| 155 | |
| 156 | tokens = tensor |
| 157 | if isinstance(tensor, torch.Tensor): |
| 158 | tokens = [tensor.item()] if tensor.ndim == 0 else tensor.tolist() |
| 159 | |
| 160 | if skip_special_tokens is not None and self.backend == HUGGINGFACE: |
| 161 | return self.processor.decode(tokens, skip_special_tokens) |
| 162 | |
| 163 | return self.processor.decode(tokens) |
no outgoing calls