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

Class PreTrainedTokenizer

bert/tokenization_utils.py:98–723  ·  view source on GitHub ↗

Base class for all slow tokenizers. Handle all the shared methods for tokenization and special tokens as well as methods downloading/caching/loading pretrained tokenizers as well as adding tokens to the vocabulary. This class also contain the added tokens in a unified way on top of al

Source from the content-addressed store, hash-verified

96
97
98class PreTrainedTokenizer(PreTrainedTokenizerBase):
99 """ Base class for all slow tokenizers.
100
101 Handle all the shared methods for tokenization and special tokens as well as methods
102 downloading/caching/loading pretrained tokenizers as well as adding tokens to the vocabulary.
103
104 This class also contain the added tokens in a unified way on top of all tokenizers so we don't
105 have to handle the specific vocabulary augmentation methods of the various underlying
106 dictionary structures (BPE, sentencepiece...).
107
108 Class attributes (overridden by derived classes):
109
110 - ``vocab_files_names``: a python ``dict`` with, as keys, the ``__init__`` keyword name of each vocabulary file
111 required by the model, and as associated values, the filename for saving the associated file (string).
112 - ``pretrained_vocab_files_map``: a python ``dict of dict`` the high-level keys
113 being the ``__init__`` keyword name of each vocabulary file required by the model, the low-level being the
114 `short-cut-names` (string) of the pretrained models with, as associated values, the `url` (string) to the
115 associated pretrained vocabulary file.
116 - ``max_model_input_sizes``: a python ``dict`` with, as keys, the `short-cut-names` (string) of the pretrained
117 models, and as associated values, the maximum length of the sequence inputs of this model, or None if the
118 model has no maximum input size.
119 - ``pretrained_init_configuration``: a python ``dict`` with, as keys, the `short-cut-names` (string) of the
120 pretrained models, and as associated values, a dictionnary of specific arguments to pass to the
121 ``__init__``method of the tokenizer class for this pretrained model when loading the tokenizer with the
122 ``from_pretrained()`` method.
123
124 Args:
125 - ``model_max_length``: (`Optional`) int: the maximum length in number of tokens for the inputs to the transformer model.
126 When the tokenizer is loaded with `from_pretrained`, this will be set to the value stored for the associated
127 model in ``max_model_input_sizes`` (see above). If no value is provided, will default to VERY_LARGE_INTEGER (`int(1e30)`).
128 no associated max_length can be found in ``max_model_input_sizes``.
129 - ``padding_side``: (`Optional`) string: the side on which the model should have padding applied.
130 Should be selected between ['right', 'left']
131 - ``model_input_names``: (`Optional`) List[string]: the list of the forward pass inputs accepted by the
132 model ("token_type_ids", "attention_mask"...).
133 - ``bos_token``: (`Optional`) string: a beginning of sentence token.
134 Will be associated to ``self.bos_token`` and ``self.bos_token_id``
135 - ``eos_token``: (`Optional`) string: an end of sentence token.
136 Will be associated to ``self.eos_token`` and ``self.eos_token_id``
137 - ``unk_token``: (`Optional`) string: an unknown token.
138 Will be associated to ``self.unk_token`` and ``self.unk_token_id``
139 - ``sep_token``: (`Optional`) string: a separation token (e.g. to separate context and query in an input sequence).
140 Will be associated to ``self.sep_token`` and ``self.sep_token_id``
141 - ``pad_token``: (`Optional`) string: a padding token.
142 Will be associated to ``self.pad_token`` and ``self.pad_token_id``
143 - ``cls_token``: (`Optional`) string: a classification token (e.g. to extract a summary of an input sequence
144 leveraging self-attention along the full depth of the model).
145 Will be associated to ``self.cls_token`` and ``self.cls_token_id``
146 - ``mask_token``: (`Optional`) string: a masking token (e.g. when training a model with masked-language
147 modeling). Will be associated to ``self.mask_token`` and ``self.mask_token_id``
148 - ``additional_special_tokens``: (`Optional`) list: a list of additional special tokens.
149 Adding all special tokens here ensure they won't be split by the tokenization process.
150 Will be associated to ``self.additional_special_tokens`` and ``self.additional_special_tokens_ids``
151
152
153 .. automethod:: __call__
154 """
155

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected