MCPcopy Create free account
hub / github.com/SooLab/CGFormer / __call__

Method __call__

bert/tokenization_utils_base.py:1551–1670  ·  view source on GitHub ↗

Returns a dictionary containing the encoded sequence or sequence pair and additional information: the mask for sequence classification and the overflowing elements if a ``max_length`` is specified. Args: text (:obj:`str`, :obj:`List[str]`, :obj:`List[List[str]]`

(
        self,
        text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]],
        text_pair: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None,
        add_special_tokens: bool = True,
        padding: Union[bool, str] = False,
        truncation: Union[bool, str] = False,
        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

1549
1550 @add_end_docstrings(ENCODE_KWARGS_DOCSTRING, ENCODE_PLUS_ADDITIONAL_KWARGS_DOCSTRING)
1551 def __call__(
1552 self,
1553 text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]],
1554 text_pair: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None,
1555 add_special_tokens: bool = True,
1556 padding: Union[bool, str] = False,
1557 truncation: Union[bool, str] = False,
1558 max_length: Optional[int] = None,
1559 stride: int = 0,
1560 is_pretokenized: bool = False,
1561 pad_to_multiple_of: Optional[int] = None,
1562 return_tensors: Optional[Union[str, TensorType]] = None,
1563 return_token_type_ids: Optional[bool] = None,
1564 return_attention_mask: Optional[bool] = None,
1565 return_overflowing_tokens: bool = False,
1566 return_special_tokens_mask: bool = False,
1567 return_offsets_mapping: bool = False,
1568 return_length: bool = False,
1569 verbose: bool = True,
1570 **kwargs
1571 ) -> BatchEncoding:
1572 """
1573 Returns a dictionary containing the encoded sequence or sequence pair and additional information:
1574 the mask for sequence classification and the overflowing elements if a ``max_length`` is specified.
1575
1576 Args:
1577 text (:obj:`str`, :obj:`List[str]`, :obj:`List[List[str]]``):
1578 The sequence or batch of sequences to be encoded.
1579 Each sequence can be a string or a list of strings (pre-tokenized string).
1580 If the sequences are provided as list of strings (pretokenized), you must set `is_pretokenized=True`
1581 (to lift the ambiguity with a batch of sequences)
1582 text_pair (:obj:`str`, :obj:`List[str]`, :obj:`List[List[str]]``):
1583 The sequence or batch of sequences to be encoded.
1584 Each sequence can be a string or a list of strings (pre-tokenized string).
1585 If the sequences are provided as list of strings (pretokenized), you must set `is_pretokenized=True`
1586 (to lift the ambiguity with a batch of sequences)
1587 """
1588 # Input type checking for clearer error
1589 assert isinstance(text, str) or (
1590 isinstance(text, (list, tuple))
1591 and (
1592 len(text) == 0
1593 or (
1594 isinstance(text[0], str)
1595 or (isinstance(text[0], (list, tuple)) and (len(text[0]) == 0 or isinstance(text[0][0], str)))
1596 )
1597 )
1598 ), (
1599 "text input must of type `str` (single example), `List[str]` (batch or single pretokenized example) "
1600 "or `List[List[str]]` (batch of pretokenized examples)."
1601 )
1602
1603 assert (
1604 text_pair is None
1605 or isinstance(text_pair, str)
1606 or (
1607 isinstance(text_pair, (list, tuple))
1608 and (

Callers

nothing calls this directly

Calls 2

batch_encode_plusMethod · 0.95
encode_plusMethod · 0.95

Tested by

no test coverage detected