The entrance method of Template! Args: example: The input example streaming: If is streaming mode is_training: Use template in training **kwargs: model: The model instance, use only in `is_training=False` Returns:
(self, example: Dict[str, Any], streaming: bool = False, is_training: bool = False, **kwargs)
| 407 | return example |
| 408 | |
| 409 | def encode(self, example: Dict[str, Any], streaming: bool = False, is_training: bool = False, **kwargs) -> Tuple[Dict[str, Any], Dict[str, Any]]: |
| 410 | """The entrance method of Template! |
| 411 | |
| 412 | Args: |
| 413 | example: The input example |
| 414 | streaming: If is streaming mode |
| 415 | is_training: Use template in training |
| 416 | **kwargs: |
| 417 | model: The model instance, use only in `is_training=False` |
| 418 | Returns: |
| 419 | if not streaming mode, returns tuple of (example, tokenizer_kwargs), else return example only |
| 420 | """ |
| 421 | example = self.preprocess(example) |
| 422 | res = self._encode(example, **kwargs) |
| 423 | inputs = res[0] |
| 424 | if not is_training and '_data' in inputs: |
| 425 | model = kwargs.get('model') |
| 426 | assert model is not None |
| 427 | data = inputs.pop('_data') |
| 428 | data = to_device(data, model.device) |
| 429 | inputs.update(self.post_encode(model, data)) |
| 430 | return res if not streaming else inputs |
| 431 | |
| 432 | def _encode(self, example: Dict[str, Any], **kwargs) -> Tuple[Dict[str, Any], Dict[str, Any]]: |
| 433 | """return: inputs, tokenizer_kwargs""" |
no test coverage detected