MCPcopy Index your code
hub / github.com/SooLab/CGFormer / _batch_encode_plus

Method _batch_encode_plus

bert/tokenization_utils.py:476–557  ·  view source on GitHub ↗
(
        self,
        batch_text_or_text_pairs: Union[
            List[TextInput],
            List[TextInputPair],
            List[PreTokenizedInput],
            List[PreTokenizedInputPair],
            List[EncodedInput],
            List[EncodedInputPair],
        ],
        add_special_tokens: bool = True,
        padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
        truncation_strategy: TruncationStrategy = TruncationStrategy.DO_NOT_TRUNCATE,
        max_length: Optional[int] = None,
        stride: int = 0,
        is_pretokenized: bool = False,
        pad_to_multiple_of: Optional[int] = None,
        return_tensors: Optional[Union[str, TensorType]] = None,
        return_token_type_ids: Optional[bool] = None,
        return_attention_mask: Optional[bool] = None,
        return_overflowing_tokens: bool = False,
        return_special_tokens_mask: bool = False,
        return_offsets_mapping: bool = False,
        return_length: bool = False,
        verbose: bool = True,
        **kwargs
    )

Source from the content-addressed store, hash-verified

474 )
475
476 def _batch_encode_plus(
477 self,
478 batch_text_or_text_pairs: Union[
479 List[TextInput],
480 List[TextInputPair],
481 List[PreTokenizedInput],
482 List[PreTokenizedInputPair],
483 List[EncodedInput],
484 List[EncodedInputPair],
485 ],
486 add_special_tokens: bool = True,
487 padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
488 truncation_strategy: TruncationStrategy = TruncationStrategy.DO_NOT_TRUNCATE,
489 max_length: Optional[int] = None,
490 stride: int = 0,
491 is_pretokenized: bool = False,
492 pad_to_multiple_of: Optional[int] = None,
493 return_tensors: Optional[Union[str, TensorType]] = None,
494 return_token_type_ids: Optional[bool] = None,
495 return_attention_mask: Optional[bool] = None,
496 return_overflowing_tokens: bool = False,
497 return_special_tokens_mask: bool = False,
498 return_offsets_mapping: bool = False,
499 return_length: bool = False,
500 verbose: bool = True,
501 **kwargs
502 ) -> BatchEncoding:
503 def get_input_ids(text):
504 if isinstance(text, str):
505 tokens = self.tokenize(text, **kwargs)
506 return self.convert_tokens_to_ids(tokens)
507 elif isinstance(text, (list, tuple)) and len(text) > 0 and isinstance(text[0], str):
508 if is_pretokenized:
509 tokens = list(itertools.chain(*(self.tokenize(t, is_pretokenized=True, **kwargs) for t in text)))
510 return self.convert_tokens_to_ids(tokens)
511 else:
512 return self.convert_tokens_to_ids(text)
513 elif isinstance(text, (list, tuple)) and len(text) > 0 and isinstance(text[0], int):
514 return text
515 else:
516 raise ValueError(
517 "Input is not valid. Should be a string, a list/tuple of strings or a list/tuple of integers."
518 )
519
520 if return_offsets_mapping:
521 raise NotImplementedError(
522 "return_offset_mapping is not available when using Python tokenizers."
523 "To use this feature, change your tokenizer to one deriving from "
524 "transformers.PreTrainedTokenizerFast."
525 )
526
527 input_ids = []
528 for ids_or_pair_ids in batch_text_or_text_pairs:
529 if not isinstance(ids_or_pair_ids, (list, tuple)):
530 ids, pair_ids = ids_or_pair_ids, None
531 elif is_pretokenized and not isinstance(ids_or_pair_ids[0], (list, tuple)):
532 ids, pair_ids = ids_or_pair_ids, None
533 else:

Callers

nothing calls this directly

Calls 2

BatchEncodingClass · 0.85

Tested by

no test coverage detected