philipp-zettl/vrom-hf-docs huggingface dataset:
#### create_token_type_ids_from_sequences[[transformers.PythonBackend.create_token_type_ids_from_sequences]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L1292)

Create a mask from the two sequences passed to be used in a sequence-pair classification task.

This method dynamically builds the token type IDs based on the tokenizer's configuration attributes:
- `token_type_ids_pattern`: Pattern to use ("all_zeros" or "bert_style")
- `token_type_ids_include_special_tokens`: Whether to account for special tokens in length calculation

Examples:
```python
# Returns: [0, 0, 0, ..., 1, 1, 1, ...] for sequence pairs
```

**Parameters:**

token_ids_0 (`list[int]`) : List of IDs.

token_ids_1 (`list[int]`, *optional*) : Optional second list of IDs for sequence pairs.

**Returns:**

``list[int]``

Token type IDs according to the configured pattern.
#### get_added_vocab[[transformers.PythonBackend.get_added_vocab]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L488)

Returns the added tokens in the vocabulary as a dictionary of token to index. Results might be different from
the fast call because for now we always add the tokens even if they are already in the vocabulary. This is
something we should change.

**Returns:**

``dict[str, int]``

The added tokens.
#### get_special_tokens_mask[[transformers.PythonBackend.get_special_tokens_mask]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L965)

Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` or `encode_plus` methods.

This method dynamically builds the special tokens mask based on the tokenizer's `special_tokens_pattern`:
- `"none"`: No special tokens (default, returns all 0s)
- `"cls_sep"`: [CLS] seq0 [SEP] or [CLS] seq0 [SEP] seq1 [SEP]
- `"eos"`: seq0 [EOS] or seq0 [EOS] seq1 [EOS]
- `"bos"`: [BOS] seq0 or [BOS] seq0 [BOS] seq1
- `"bos_eos"`: [BOS] seq0 [EOS] or [BOS] seq0 [EOS] seq1 [EOS]
- `"cls_double_sep"`: [CLS] seq0 [SEP] or [CLS] seq0 [SEP] [SEP] seq1 [SEP]
- `"prefix_suffix"`: ` seq0 [seq1] `

**Parameters:**

token_ids_0 (`list[int]`) : List of ids of the first sequence.
#### num_special_tokens_to_add[[transformers.PythonBackend.num_special_tokens_to_add]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L602)

Returns the number of added tokens when encoding a sequence with special tokens.

This encodes a dummy input and checks the number of added tokens, and is therefore not efficient. Do not put
this inside your training loop.

**Parameters:**

pair (`bool`, *optional*, defaults to `False`) : Whether the number of added tokens should be computed in the case of a sequence pair or a single sequence.

**Returns:**

``int``

Number of special tokens added to sequences.
#### prepare_for_model[[transformers.PythonBackend.prepare_for_model]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L1115)

Prepares a sequence of input ids so it can be used by the model. Adds special tokens, truncates, and pads.

**Parameters:**

ids : Tokenized input ids of the first sequence.

pair_ids : Tokenized input ids of the second sequence (optional).
#### prepare_for_tokenization[[transformers.PythonBackend.prepare_for_tokenization]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L836)

Performs any necessary transformations before tokenization.

This method should pop the arguments from kwargs and return the remaining `kwargs` as well. We test the
`kwargs` at the end of the encoding process to be sure all the arguments have been used.

**Parameters:**

text (`str`) : The text to prepare.

is_split_into_words (`bool`, *optional*, defaults to `False`) : Whether or not the input is already pre-tokenized (e.g., split into words). If set to `True`, the tokenizer assumes the input is already split into words (for instance, by splitting it on whitespace) which it will tokenize. This is useful for NER or token classification.

kwargs (`dict[str, Any]`, *optional*) : Keyword arguments to use for the tokenization.

**Returns:**

``tuple[str, dict[str, Any]]``

The prepared text and the unused kwargs.
#### save_vocabulary[[transformers.PythonBackend.save_vocabulary]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L1356)

Default implementation for common vocabulary saving patterns.
Saves self.encoder/self.vocab as JSON, optionally with self.bpe_ranks as merges.
Returns empty tuple if no vocabulary exists.

Override this method if your tokenizer needs custom saving logic (e.g., SentencePiece models,
multiple vocabulary files, or special file formats).

**Parameters:**

save_directory (`str`) : The directory in which to save the vocabulary.

filename_prefix (`str`, *optional*) : An optional prefix to add to the named of the saved files.

**Returns:**

``tuple[str, ...]``

Paths to the files saved, or empty tuple if no files saved.
#### tokenize[[transformers.PythonBackend.tokenize]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L625)

Converts a string into a sequence of tokens, using the tokenizer.

**Parameters:**

text : The sequence to be encoded.

- ****kwargs** : Passed along to the model-specific `prepare_for_tokenization` preprocessing method.

**Returns:**

The list of tokens.
## PreTrainedTokenizerFast[[transformers.TokenizersBackend]]

The [PreTrainedTokenizerFast](/docs/transformers/v5.6.2/en/main_classes/tokenizer#transformers.TokenizersBackend) depend on the [tokenizers](https://huggingface.co/docs/tokenizers) library. The tokenizers obtained from the 🤗 tokenizers library can be
loaded very simply into 🤗 transformers. Take a look at the [Using tokenizers from 🤗 tokenizers](../fast_tokenizers) page to understand how this is done.
#### transformers.TokenizersBackend[[transformers.TokenizersBackend]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L84)

Base class for all fast tokenizers (wrapping HuggingFace tokenizers library).

Inherits from [PreTrainedTokenizerBase](/docs/transformers/v5.6.2/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase).

Handles all the shared methods for tokenization and special tokens, as well as methods for
downloading/caching/loading pretrained tokenizers, as well as adding tokens to the vocabulary.

This class also contains the added tokens in a unified way on top of all tokenizers so we don't have to handle the
specific vocabulary augmentation methods of the various underlying dictionary structures (BPE, sentencepiece...).

Class attributes (overridden by derived classes)
split_special_tokens (`bool`, *optional*, defaults to `False`) : Whether or not the special tokens should be split during the tokenization process. Passing will affect the internal state of the tokenizer. The default behavior is to not split special tokens. This means that if `` is the `bos_token`, then `tokenizer.tokenize("") = ['`]. Otherwise, if `split_special_tokens=True`, then `tokenizer.tokenize("")` will be give `['']`. 

tokenizer_object (`tokenizers.Tokenizer`) : A `tokenizers.Tokenizer` object from 🤗 tokenizers to instantiate from. See [Using tokenizers from 🤗 tokenizers](../fast_tokenizers) for more information.

tokenizer_file (`str`) : A path to a local JSON file representing a previously serialized `tokenizers.Tokenizer` object from 🤗 tokenizers.

**Returns:**

`[BatchEncoding](/docs/transformers/v5.6.2/en/main_classes/tokenizer#transformers.BatchEncoding)`

A [BatchEncoding](/docs/transformers/v5.6.2/en/main_classes/tokenizer#transformers.BatchEncoding) with the following fields:
- **input_ids** -- List of token ids to be fed to a model.

  [What are input IDs?](../glossary#input-ids)

- **token_type_ids** -- List of token type ids to be fed to a model (when `return_token_type_ids=True` or
  if *"token_type_ids"* is in `self.model_input_names`).

  [What are token type IDs?](../glossary#token-type-ids)

- **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
  `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names`).

  [What are attention masks?](../glossary#attention-mask)
- **overflowing_tokens** -- List of overflowing tokens sequences (when a `max_length` is specified and
  `return_overflowing_tokens=True`).
- **num_truncated_tokens** -- Number of tokens truncated (when a `max_length` is specified and
  `return_overflowing_tokens=True`).
- **special_tokens_mask** -- List of 0s and 1s, with 1 specifying added special tokens and 0 specifying
  regular sequence tokens (when `add_special_tokens=True` and `return_special_tokens_mask=True`).
- **length** -- The length of the inputs (when `return_length=True`)
#### add_tokens[[transformers.TokenizersBackend.add_tokens]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_base.py#L1213)

#TODO remove this from here! PreTrainedTOkeniuzerBase should be agnostic of AddedToken.

Add a list of new tokens. If the new tokens are not in the vocabulary, they are added to the end. Added tokens and
tokens from the vocabulary of the tokenization algorithm are therefore not treated in the same way.

Examples:

```python
#### add_special_tokens[[transformers.TokenizersBackend.add_special_tokens]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_base.py#L1106)

Add a dictionary of special tokens (eos, pad, cls, etc.) to the encoder and link them to class attributes. If
special tokens are NOT in the vocabulary, they are added to it (indexed starting from the last index of the
current vocabulary).

When adding new tokens to the vocabulary, you should make sure to also resize the token embedding matrix of the
model so that its embedding matrix matches the tokenizer.

In order to do that, please use the [resize_token_embeddings()](/docs/transformers/v5.6.2/en/main_classes/model#transformers.PreTrainedModel.resize_token_embeddings) method.

Using `add_special_tokens` will ensure your special tokens can be used in several ways:
#### apply_chat_template[[transformers.TokenizersBackend.apply_chat_template]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_base.py#L2968)

Converts a list of dictionaries with `"role"` and `"content"` keys to a list of token
ids. This method is intended for use with chat models, and will read the tokenizer's chat_template attribute to
determine the format and control tokens to use when converting.

**Parameters:**

conversation (Union[list[dict[str, str]], list[list[dict[str, str]]]]) : A list of dicts with "role" and "content" keys, representing the chat history so far.
#### batch_decode[[transformers.TokenizersBackend.batch_decode]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_base.py#L2880)

Convert a list of lists of token ids into a list of strings by calling decode.

This method is provided for backwards compatibility. The `decode` method now handles batched input natively,
so you can use `decode` directly instead of `batch_decode`.

**Parameters:**

sequences (`Union[list[int], list[list[int]], np.ndarray, torch.Tensor]`) : List of tokenized input ids. Can be obtained using the `__call__` method.

skip_special_tokens (`bool`, *optional*, defaults to `False`) : Whether or not to remove special tokens in the decoding.

clean_up_tokenization_spaces (`bool`, *optional*) : Whether or not to clean up the tokenization spaces. If `None`, will default to `self.clean_up_tokenization_spaces`.

kwargs (additional keyword arguments, *optional*) : Will be passed to the underlying model specific decode method.

**Returns:**
#### decode[[transformers.TokenizersBackend.decode]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_base.py#L2832)

Converts a sequence of ids into a string, or a list of sequences into a list of strings,
using the tokenizer and vocabulary with options to remove special tokens and clean up
tokenization spaces.

Similar to doing `self.convert_tokens_to_string(self.convert_ids_to_tokens(token_ids))`.

**Parameters:**

token_ids (`Union[int, list[int], list[list[int]], np.ndarray, torch.Tensor]`) : A single sequence or a batch (list of sequences) of tokenized input ids. Can be obtained using the `__call__` method.

skip_special_tokens (`bool`, *optional*, defaults to `False`) : Whether or not to remove special tokens in the decoding.

kwargs (additional keyword arguments, *optional*) : Will be passed to the underlying model specific decode method.

**Returns:**

``Union[str, list[str]]``
#### encode[[transformers.TokenizersBackend.encode]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_base.py#L2229)

Converts a string to a sequence of ids (integer), using the tokenizer and vocabulary.

Same as doing `self.convert_tokens_to_ids(self.tokenize(text))`.

**Parameters:**

text (`str`, `list[str]` or `list[int]`) : The first sequence to be encoded. This can be a string, a list of strings (tokenized string using the `tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids` method).

text_pair (`str`, `list[str]` or `list[int]`, *optional*) : Optional second sequence to be encoded. This can be a string, a list of strings (tokenized string using the `tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids` method).
#### push_to_hub[[transformers.TokenizersBackend.push_to_hub]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/utils/hub.py#L720)

Upload the tokenizer files to the 🤗 Model Hub.

Examples:

```python
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-cased")
#### convert_to_native_format[[transformers.TokenizersBackend.convert_to_native_format]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L101)

Build a `tokenizers.Tokenizer` backend from the available serialization files (tokenizer.json, sentencepiece
models, tekken.json, vocab/merges).
#### get_added_vocab[[transformers.TokenizersBackend.get_added_vocab]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L635)

Returns the added tokens in the vocabulary as a dictionary of token to index.

**Returns:**

``dict[str, int]``

The added tokens.
#### num_special_tokens_to_add[[transformers.TokenizersBackend.num_special_tokens_to_add]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L732)

Returns the number of added tokens when encoding a sequence with special tokens.

This encodes a dummy input and checks the number of added tokens, and is therefore not efficient. Do not put
this inside your training loop.

**Parameters:**

pair (`bool`, *optional*, defaults to `False`) : Whether the number of added tokens should be computed in the case of a sequence pair or a single sequence.

**Returns:**

``int``

Number of special tokens added to sequences.
#### set_truncation_and_padding[[transformers.TokenizersBackend.set_truncation_and_padding]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L782)

Define the truncation and the padding strategies for fast tokenizers (provided by HuggingFace tokenizers
library) and restore the tokenizer settings afterwards.

The provided tokenizer has no padding / truncation strategy before the managed section. If your tokenizer set a
padding / truncation strategy before, then it will be reset to no padding / truncation when exiting the managed
section.

**Parameters:**

padding_strategy ([PaddingStrategy](/docs/transformers/v5.6.2/en/internal/file_utils#transformers.utils.PaddingStrategy)) : The kind of padding that will be applied to the input

truncation_strategy ([TruncationStrategy](/docs/transformers/v5.6.2/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy)) : The kind of truncation that will be applied to the input
max_length (`int`) : The maximum size of a sequence.

stride (`int`) : The stride to use when handling overflow.

pad_to_multiple_of (`int`, *optional*) : If set will pad the sequence to a multiple of the provided value. This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability `>= 7.5` (Volta).

padding_side (`str`, *optional*) : The side on which the model should have padding applied. Should be selected between ['right', 'left']. Default value is picked from the class attribute of the same name.
#### train_new_from_iterator[[transformers.TokenizersBackend.train_new_from_iterator]]

[Source](https://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L1061)

Trains a tokenizer on a new corpus with the same defaults (in terms of special tokens or tokenization pipeline)
as the current one.

**Parameters:**

text_iterator (generator of `list[str]`) : The training corpus. Should be a generator of batches of texts, for instance a list of lists of texts if you have everything in memory.

vocab_size (`int`) : The size of the vocabulary you want for your tokenizer.

length (`int`, *optional*) : The total number of sequences in the iterator. This is used to provide meaningful progress tracking

new_special_tokens (list of `str` or `AddedToken`, *optional*) : A list of new special tokens to add to the tokenizer you are training.
special_tokens_map (`dict[str, str]`, *optional*) : If you want to rename some of the special tokens this tokenizer uses, pass along a mapping old special token name to new special token name in this argument.

kwargs (`dict[str, Any]`, *optional*) : Additional keyword arguments passed along to the trainer from the 🤗 Tokenizers library.

**Returns:**

`[PreTrainedTokenizerFast](/docs/transformers/v5.6.2/en/main_classes/tokenizer#transformers.TokenizersBackend)`

A new tokenizer of the same type as the original one, trained on
`text_iterator`.
build_inputs_with_special_tokenstransformers.PythonBackend.build_inputs_with_special_tokenshttps://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_python.py#L860[{"name": "token_ids_0", "val": ": list"}, {"name": "token_ids_1", "val": ": list[int] | None = None"}]- **token_ids_0** (`list[int]`) --
  List of IDs to which the special tokens will be added.
- **token_ids_1** (`list[int]`, *optional*) --
  Optional second list of IDs for sequence pairs.0`list[int]`List of input IDs with the appropriate special tokens.

Build model inputs from a sequence or a pair of sequences by adding special tokens.
This method dynamically builds inputs based on the tokenizer's `special_tokens_pattern`:
- `"none"`: No special tokens
- `"cls_sep"`: [CLS] seq0 [SEP] or [CLS] seq0 [SEP] seq1 [SEP]
- `"eos"`: seq0 [EOS] or seq0 [EOS] seq1 [EOS]
- `"bos"`: [BOS] seq0 or [BOS] seq0 [BOS] seq1
- `"bos_eos"`: [BOS] seq0 [EOS] or [BOS] seq0 [EOS] seq1 [EOS]
- `"cls_double_sep"`: [CLS] seq0 [SEP] or [CLS] seq0 [SEP] [SEP] seq1 [SEP]
- `"prefix_suffix"`: ` seq0 [seq1] ` (custom prefix/suffix stored on the tokenizer)

**Parameters:**

model_max_length (`int`, *optional*) : The maximum length (in number of tokens) for the inputs to the transformer model. When the tokenizer is loaded with [from_pretrained()](/docs/transformers/v5.6.2/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.from_pretrained), this will be set to the value stored for the associated model in `max_model_input_sizes` (see above). If no value is provided, will default to VERY_LARGE_INTEGER (`int(1e30)`).
padding_side (`str`, *optional*) : The side on which the model should have padding applied. Should be selected between ['right', 'left']. Default value is picked from the class attribute of the same name.

truncation_side (`str`, *optional*) : The side on which the model should have truncation applied. Should be selected between ['right', 'left']. Default value is picked from the class attribute of the same name.

chat_template (`str`, *optional*) : A Jinja template string that will be used to format lists of chat messages. See https://huggingface.co/docs/transformers/chat_templating for a full description.

model_input_names (`list[string]`, *optional*) : The list of inputs accepted by the forward pass of the model (like `"token_type_ids"` or `"attention_mask"`). Default value is picked from the class attribute of the same name.

bos_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token representing the beginning of a sentence.
eos_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token representing the end of a sentence.

unk_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token representing an out-of-vocabulary token.

sep_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token separating two different sentences in the same input (used by BERT for instance).

pad_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token used to make arrays of tokens the same size for batching purpose. Will then be ignored by attention mechanisms or loss computation.

cls_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token representing the class of the input (used by BERT for instance).

mask_token (`str` or `tokenizers.AddedToken`, *optional*) : A special token representing a masked token (used by masked-language modeling pretraining objectives, like BERT). Will be associated to `self.mask_token` and `self.mask_token_id`.
extra_special_tokens (list of `str` or `tokenizers.AddedToken`, *optional*) : A list of extra model-specific special tokens. Add them here to ensure they are skipped when decoding with `skip_special_tokens` is set to True. If they are not part of the vocabulary, they will be added at the end of the vocabulary.

split_special_tokens (`bool`, *optional*, defaults to `False`) : Whether or not the special tokens should be split during the tokenization process. Passing will affect the internal state of the tokenizer. The default behavior is to not split special tokens. This means that if `` is the `bos_token`, then `tokenizer.tokenize("") = ['`]. Otherwise, if `split_special_tokens=True`, then `tokenizer.tokenize("")` will be give `['']`.

**Returns:**

``list[int]``

List of input IDs with the appropriate special tokens.
convert_to_native_formattransformers.TokenizersBackend.convert_to_native_formathttps://github.com/huggingface/transformers/blob/v5.6.2/src/transformers/tokenization_utils_tokenizers.py#L101[{"name": "trust_remote_code", "val": " = False"}, {"name": "**kwargs", "val": ""}]

Build a `tokenizers.Tokenizer` backend from the available serialization files (tokenizer.json, sentencepiece
models, tekken.json, vocab/merges).

**Parameters:**

model_max_length (`int`, *optional*) : The maximum length (in number of tokens) for the inputs to the transformer model. When the tokenizer is loaded with [from_pretrained()](/docs/transformers/v5.6.2/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.from_pretrained), this will be set to the value stored for the associated model in `max_model_input_sizes` (see above). If no value is provided, will default to VERY_LARGE_INTEGER (`int(1e30)`).