---
local: tokenizer
sections:
- local: transformers.PreTrainedTokenizer
  title: PreTrainedTokenizer
- local: transformers.PreTrainedTokenizerFast
  title: PreTrainedTokenizerFast
- local: transformers.BatchEncoding
  title: BatchEncoding
title: Tokenizer
---
<script>
import Tip from "./Tip.svelte";
import Youtube from "./Youtube.svelte";
import Docstring from "./Docstring.svelte";
import CodeBlock from "./CodeBlock.svelte";
import CodeBlockFw from "./CodeBlockFw.svelte";
import DocNotebookDropdown from "./DocNotebookDropdown.svelte";
import IconCopyLink from "./IconCopyLink.svelte";
export let fw: "pt" | "tf"
</script>
<!--Copyright 2020 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

<h1 id="tokenizer">Tokenizer</h1>

A tokenizer is in charge of preparing the inputs for a model. The library contains tokenizers for all the models. Most
of the tokenizers are available in two flavors: a full python implementation and a "Fast" implementation based on the
Rust library [🤗 Tokenizers](https://github.com/huggingface/tokenizers). The "Fast" implementations allows:

1. a significant speed-up in particular when doing batched tokenization and
2. additional methods to map between the original string (character and words) and the token space (e.g. getting the
   index of the token comprising a given character or the span of characters corresponding to a given token). Currently
   no "Fast" implementation is available for the SentencePiece-based tokenizers (for T5, ALBERT, CamemBERT, XLM-RoBERTa
   and XLNet models).

The base classes [PreTrainedTokenizer](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizer) and [PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast)
implement the common methods for encoding string inputs in model inputs (see below) and instantiating/saving python and
"Fast" tokenizers either from a local file or directory or from a pretrained tokenizer provided by the library
(downloaded from HuggingFace's AWS S3 repository). They both rely on
[PreTrainedTokenizerBase](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase) that contains the common methods, and
[SpecialTokensMixin](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.SpecialTokensMixin).

[PreTrainedTokenizer](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizer) and [PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast) thus implement the main
methods for using all the tokenizers:

- Tokenizing (splitting strings in sub-word token strings), converting tokens strings to ids and back, and
  encoding/decoding (i.e., tokenizing and converting to integers).
- Adding new tokens to the vocabulary in a way that is independent of the underlying structure (BPE, SentencePiece...).
- Managing special tokens (like mask, beginning-of-sentence, etc.): adding them, assigning them to attributes in the
  tokenizer for easy access and making sure they are not split during tokenization.

[BatchEncoding](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.BatchEncoding) holds the output of the
[PreTrainedTokenizerBase](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase)'s encoding methods (`__call__`,
`encode_plus` and `batch_encode_plus`) and is derived from a Python dictionary. When the tokenizer is a pure python
tokenizer, this class behaves just like a standard python dictionary and holds the various model inputs computed by
these methods (`input_ids`, `attention_mask`...). When the tokenizer is a "Fast" tokenizer (i.e., backed by
HuggingFace [tokenizers library](https://github.com/huggingface/tokenizers)), this class provides in addition
several advanced alignment methods which can be used to map between the original string (character and words) and the
token space (e.g., getting the index of the token comprising a given character or the span of characters corresponding
to a given token).


<h2 id="transformers.PreTrainedTokenizer">PreTrainedTokenizer</h2>

<div class="docstring">

<docstring><name>class transformers.PreTrainedTokenizer</name><anchor>transformers.PreTrainedTokenizer</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L333</source><parameters>[{"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **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/pr_15592/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.
- **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. Will be associated to `self.bos_token` and
  `self.bos_token_id`.
- **eos_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token representing the end of a sentence. Will be associated to `self.eos_token` and
  `self.eos_token_id`.
- **unk_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token representing an out-of-vocabulary token. Will be associated to `self.unk_token` and
  `self.unk_token_id`.
- **sep_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token separating two different sentences in the same input (used by BERT for instance). Will be
  associated to `self.sep_token` and `self.sep_token_id`.
- **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. Will be associated to `self.pad_token` and `self.pad_token_id`.
- **cls_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token representing the class of the input (used by BERT for instance). Will be associated to
  `self.cls_token` and `self.cls_token_id`.
- **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`.
- **additional_special_tokens** (tuple or list of `str` or `tokenizers.AddedToken`, *optional*) --
  A tuple or a list of additional special tokens. Add them here to ensure they won't be split by the
  tokenization process. Will be associated to `self.additional_special_tokens` and
  `self.additional_special_tokens_ids`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Base class for all slow tokenizers.

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

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 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)

- **vocab_files_names** (`Dict[str, str]`) -- A dictionary with, as keys, the `__init__` keyword name of each
  vocabulary file required by the model, and as associated values, the filename for saving the associated file
  (string).
- **pretrained_vocab_files_map** (`Dict[str, Dict[str, str]]`) -- A dictionary of dictionaries, with the
  high-level keys being the `__init__` keyword name of each vocabulary file required by the model, the
  low-level being the `short-cut-names` of the pretrained models with, as associated values, the `url` to the
  associated pretrained vocabulary file.
- **max_model_input_sizes** (`Dict[str, Optional[int]]`) -- A dictionary with, as keys, the `short-cut-names`
  of the pretrained models, and as associated values, the maximum length of the sequence inputs of this model,
  or `None` if the model has no maximum input size.
- **pretrained_init_configuration** (`Dict[str, Dict[str, Any]]`) -- A dictionary with, as keys, the
  `short-cut-names` of the pretrained models, and as associated values, a dictionary of specific arguments to
  pass to the `__init__` method of the tokenizer class for this pretrained model when loading the tokenizer
  with the [from_pretrained()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.from_pretrained) method.
- **model_input_names** (`List[str]`) -- A list of inputs expected in the forward pass of the model.
- **padding_side** (`str`) -- The default value for the side on which the model should have padding applied.
  Should be `'right'` or `'left'`.
- **truncation_side** (`str`) -- The default value for the side on which the model should have truncation
  applied. Should be `'right'` or `'left'`.





<div class="docstring">
<docstring><name>\_\_call\_\_</name><anchor>transformers.PreTrainedTokenizerBase.__call__</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L2379</source><parameters>[{"name": "text", "val": ": typing.Union[str, typing.List[str], typing.List[typing.List[str]]]"}, {"name": "text_pair", "val": ": typing.Union[str, typing.List[str], typing.List[typing.List[str]], NoneType] = None"}, {"name": "add_special_tokens", "val": ": bool = True"}, {"name": "padding", "val": ": typing.Union[bool, str, transformers.file_utils.PaddingStrategy] = False"}, {"name": "truncation", "val": ": typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = False"}, {"name": "max_length", "val": ": typing.Optional[int] = None"}, {"name": "stride", "val": ": int = 0"}, {"name": "is_split_into_words", "val": ": bool = False"}, {"name": "pad_to_multiple_of", "val": ": typing.Optional[int] = None"}, {"name": "return_tensors", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "return_token_type_ids", "val": ": typing.Optional[bool] = None"}, {"name": "return_attention_mask", "val": ": typing.Optional[bool] = None"}, {"name": "return_overflowing_tokens", "val": ": bool = False"}, {"name": "return_special_tokens_mask", "val": ": bool = False"}, {"name": "return_offsets_mapping", "val": ": bool = False"}, {"name": "return_length", "val": ": bool = False"}, {"name": "verbose", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **text** (`str`, `List[str]`, `List[List[str]]`) --
  The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
  (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
  `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
- **text_pair** (`str`, `List[str]`, `List[List[str]]`) --
  The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
  (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
  `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).

- **add_special_tokens** (`bool`, *optional*, defaults to `True`) --
  Whether or not to encode the sequences with the special tokens relative to their model.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
    sequence if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or
    to the maximum acceptable input length for the model if that argument is not provided. This will
    truncate token by token, removing a token from the longest sequence in the pair if a pair of
    sequences (or a batch of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **stride** (`int`, *optional*, defaults to 0) --
  If set to a number along with `max_length`, the overflowing tokens returned when
  `return_overflowing_tokens=True` will contain some tokens from the end of the truncated sequence
  returned to provide some overlap between truncated and overflowing sequences. The value of this
  argument defines the number of overlapping tokens.
- **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.
- **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).
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.

- **return_token_type_ids** (`bool`, *optional*) --
  Whether to return token type IDs. If left to the default, will return the token type IDs according to
  the specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are token type IDs?](../glossary#token-type-ids)
- **return_attention_mask** (`bool`, *optional*) --
  Whether to return the attention mask. If left to the default, will return the attention mask according
  to the specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are attention masks?](../glossary#attention-mask)
- **return_overflowing_tokens** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return overflowing token sequences. If a pair of sequences of input ids (or a batch
  of pairs) is provided with `truncation_strategy = longest_first` or `True`, an error is raised instead
  of returning overflowing tokens.
- **return_special_tokens_mask** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return special tokens mask information.
- **return_offsets_mapping** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return `(char_start, char_end)` for each token.

  This is only available on fast tokenizers inheriting from [PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast), if using
  Python's tokenizer, this method will raise `NotImplementedError`.
- **return_length**  (`bool`, *optional*, defaults to `False`) --
  Whether or not to return the lengths of the encoded inputs.
- **verbose** (`bool`, *optional*, defaults to `True`) --
  Whether or not to print more information and warnings.
  **kwargs -- passed to the `self.tokenize()` method</paramsdesc><paramgroups>0</paramgroups><rettype>[BatchEncoding](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.BatchEncoding)</rettype><retdesc>A [BatchEncoding](/docs/transformers/pr_15592/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`)</retdesc></docstring>

Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences.








</div>
<div class="docstring">
<docstring><name>batch\_decode</name><anchor>transformers.PreTrainedTokenizerBase.batch_decode</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L3250</source><parameters>[{"name": "sequences", "val": ": typing.Union[typing.List[int], typing.List[typing.List[int]], ForwardRef('np.ndarray'), ForwardRef('torch.Tensor'), ForwardRef('tf.Tensor')]"}, {"name": "skip_special_tokens", "val": ": bool = False"}, {"name": "clean_up_tokenization_spaces", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **sequences** (`Union[List[int], List[List[int]], np.ndarray, torch.Tensor, tf.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*, defaults to `True`) --
  Whether or not to clean up the tokenization spaces.
- **kwargs** (additional keyword arguments, *optional*) --
  Will be passed to the underlying model specific decode method.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>The list of decoded sentences.</retdesc></docstring>

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








</div>
<div class="docstring">
<docstring><name>decode</name><anchor>transformers.PreTrainedTokenizerBase.decode</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L3283</source><parameters>[{"name": "token_ids", "val": ": typing.Union[int, typing.List[int], ForwardRef('np.ndarray'), ForwardRef('torch.Tensor'), ForwardRef('tf.Tensor')]"}, {"name": "skip_special_tokens", "val": ": bool = False"}, {"name": "clean_up_tokenization_spaces", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **token_ids** (`Union[int, List[int], np.ndarray, torch.Tensor, tf.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*, defaults to `True`) --
  Whether or not to clean up the tokenization spaces.
- **kwargs** (additional keyword arguments, *optional*) --
  Will be passed to the underlying model specific decode method.</paramsdesc><paramgroups>0</paramgroups><rettype>`str`</rettype><retdesc>The decoded sentence.</retdesc></docstring>

Converts a sequence of ids in a string, 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))`.








</div>
<div class="docstring">
<docstring><name>encode</name><anchor>transformers.PreTrainedTokenizerBase.encode</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L2189</source><parameters>[{"name": "text", "val": ": typing.Union[str, typing.List[str], typing.List[int]]"}, {"name": "text_pair", "val": ": typing.Union[str, typing.List[str], typing.List[int], NoneType] = None"}, {"name": "add_special_tokens", "val": ": bool = True"}, {"name": "padding", "val": ": typing.Union[bool, str, transformers.file_utils.PaddingStrategy] = False"}, {"name": "truncation", "val": ": typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = False"}, {"name": "max_length", "val": ": typing.Optional[int] = None"}, {"name": "stride", "val": ": int = 0"}, {"name": "return_tensors", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **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).

- **add_special_tokens** (`bool`, *optional*, defaults to `True`) --
  Whether or not to encode the sequences with the special tokens relative to their model.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
    sequence if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or
    to the maximum acceptable input length for the model if that argument is not provided. This will
    truncate token by token, removing a token from the longest sequence in the pair if a pair of
    sequences (or a batch of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **stride** (`int`, *optional*, defaults to 0) --
  If set to a number along with `max_length`, the overflowing tokens returned when
  `return_overflowing_tokens=True` will contain some tokens from the end of the truncated sequence
  returned to provide some overlap between truncated and overflowing sequences. The value of this
  argument defines the number of overlapping tokens.
- **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.
- **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).
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.

**kwargs -- Passed along to the `.tokenize()` method.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[int]`, `torch.Tensor`, `tf.Tensor` or `np.ndarray`</rettype><retdesc>The tokenized ids of the text.</retdesc></docstring>

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))`.








</div>
<div class="docstring">
<docstring><name>push\_to\_hub</name><anchor>transformers.file_utils.PushToHubMixin.push_to_hub</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/file_utils.py#L2825</source><parameters>[{"name": "repo_path_or_name", "val": ": typing.Optional[str] = None"}, {"name": "repo_url", "val": ": typing.Optional[str] = None"}, {"name": "use_temp_dir", "val": ": bool = False"}, {"name": "commit_message", "val": ": typing.Optional[str] = None"}, {"name": "organization", "val": ": typing.Optional[str] = None"}, {"name": "private", "val": ": typing.Optional[bool] = None"}, {"name": "use_auth_token", "val": ": typing.Union[bool, str, NoneType] = None"}, {"name": "**model_card_kwargs", "val": ""}]</parameters><paramsdesc>- **repo_path_or_name** (`str`, *optional*) --
  Can either be a repository name for your tokenizer in the Hub or a path to a local folder (in which case
  the repository will have the name of that local folder). If not specified, will default to the name
  given by `repo_url` and a local directory with that name will be created.
- **repo_url** (`str`, *optional*) --
  Specify this in case you want to push to an existing repository in the hub. If unspecified, a new
  repository will be created in your namespace (unless you specify an `organization`) with `repo_name`.
- **use_temp_dir** (`bool`, *optional*, defaults to `False`) --
  Whether or not to clone the distant repo in a temporary directory or in `repo_path_or_name` inside the
  current working directory. This will slow things down if you are making changes in an existing repo
  since you will need to clone the repo before every push.
- **commit_message** (`str`, *optional*) --
  Message to commit while pushing. Will default to `"add tokenizer"`.
- **organization** (`str`, *optional*) --
  Organization in which you want to push your tokenizer (you must be a member of this organization).
- **private** (`bool`, *optional*) --
  Whether or not the repository created should be private (requires a paying subscription).
- **use_auth_token** (`bool` or `str`, *optional*) --
  The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
  when running `transformers-cli login` (stored in `~/.huggingface`). Will default to `True` if
  `repo_url` is not specified.</paramsdesc><paramgroups>0</paramgroups><rettype>`str`</rettype><retdesc>The url of the commit of your tokenizer in the given repository.</retdesc></docstring>

Upload the tokenizer files to the 🤗 Model Hub while synchronizing a local clone of the repo in
`repo_path_or_name`.







Examples:

```python
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")

# Push the tokenizer to your namespace with the name "my-finetuned-bert" and have a local clone in the
# *my-finetuned-bert* folder.
tokenizer.push_to_hub("my-finetuned-bert")

# Push the tokenizer to your namespace with the name "my-finetuned-bert" with no local clone.
tokenizer.push_to_hub("my-finetuned-bert", use_temp_dir=True)

# Push the tokenizer to an organization with the name "my-finetuned-bert" and have a local clone in the
# *my-finetuned-bert* folder.
tokenizer.push_to_hub("my-finetuned-bert", organization="huggingface")

# Make a change to an existing repo that has been cloned locally in *my-finetuned-bert*.
tokenizer.push_to_hub("my-finetuned-bert", repo_url="https://huggingface.co/sgugger/my-finetuned-bert")
```


</div>
<div class="docstring">
<docstring><name>convert\_ids\_to\_tokens</name><anchor>transformers.PreTrainedTokenizer.convert_ids_to_tokens</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L881</source><parameters>[{"name": "ids", "val": ": typing.Union[int, typing.List[int]]"}, {"name": "skip_special_tokens", "val": ": bool = False"}]</parameters><paramsdesc>- **ids** (`int` or `List[int]`) --
  The token id (or token ids) to convert to tokens.
- **skip_special_tokens** (`bool`, *optional*, defaults to `False`) --
  Whether or not to remove special tokens in the decoding.</paramsdesc><paramgroups>0</paramgroups><rettype>`str` or `List[str]`</rettype><retdesc>The decoded token(s).</retdesc></docstring>

Converts a single index or a sequence of indices in a token or a sequence of tokens, using the vocabulary and
added tokens.








</div>
<div class="docstring">
<docstring><name>convert\_tokens\_to\_ids</name><anchor>transformers.PreTrainedTokenizer.convert_tokens_to_ids</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L560</source><parameters>[{"name": "tokens", "val": ": typing.Union[str, typing.List[str]]"}]</parameters><paramsdesc>- **tokens** (`str` or `List[str]`) -- One or several token(s) to convert to token id(s).</paramsdesc><paramgroups>0</paramgroups><rettype>`int` or `List[int]`</rettype><retdesc>The token id or list of token ids.</retdesc></docstring>

Converts a token string (or a sequence of tokens) in a single integer id (or a sequence of ids), using the
vocabulary.








</div>
<div class="docstring">
<docstring><name>get\_added\_vocab</name><anchor>transformers.PreTrainedTokenizer.get_added_vocab</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L369</source><parameters>[]</parameters><rettype>`Dict[str, int]`</rettype><retdesc>The added tokens.</retdesc></docstring>

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






</div>
<div class="docstring">
<docstring><name>num\_special\_tokens\_to\_add</name><anchor>transformers.PreTrainedTokenizer.num_special_tokens_to_add</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L458</source><parameters>[{"name": "pair", "val": ": bool = False"}]</parameters><paramsdesc>- **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.</paramsdesc><paramgroups>0</paramgroups><rettype>`int`</rettype><retdesc>Number of special tokens added to sequences.</retdesc></docstring>

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

<Tip>

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.

</Tip>








</div>
<div class="docstring">
<docstring><name>prepare\_for\_tokenization</name><anchor>transformers.PreTrainedTokenizer.prepare_for_tokenization</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L819</source><parameters>[{"name": "text", "val": ": str"}, {"name": "is_split_into_words", "val": ": bool = False"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **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 --
  Keyword arguments to use for the tokenization.</paramsdesc><paramgroups>0</paramgroups><rettype>`Tuple[str, Dict[str, Any]]`</rettype><retdesc>The prepared text and the unused kwargs.</retdesc></docstring>

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.








</div>
<div class="docstring">
<docstring><name>tokenize</name><anchor>transformers.PreTrainedTokenizer.tokenize</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils.py#L481</source><parameters>[{"name": "text", "val": ": str"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **text** (`str`) --
  The sequence to be encoded.
- ****kwargs** (additional keyword arguments) --
  Passed along to the model-specific `prepare_for_tokenization` preprocessing method.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>The list of tokens.</retdesc></docstring>

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

Split in words for word-based vocabulary or sub-words for sub-word-based vocabularies
(BPE/SentencePieces/WordPieces). Takes care of added tokens.








</div></div>

<h2 id="transformers.PreTrainedTokenizerFast">PreTrainedTokenizerFast</h2>

The [PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast) 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.

<div class="docstring">

<docstring><name>class transformers.PreTrainedTokenizerFast</name><anchor>transformers.PreTrainedTokenizerFast</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L77</source><parameters>[{"name": "*args", "val": ""}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **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/pr_15592/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.
- **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. Will be associated to `self.bos_token` and
  `self.bos_token_id`.
- **eos_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token representing the end of a sentence. Will be associated to `self.eos_token` and
  `self.eos_token_id`.
- **unk_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token representing an out-of-vocabulary token. Will be associated to `self.unk_token` and
  `self.unk_token_id`.
- **sep_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token separating two different sentences in the same input (used by BERT for instance). Will be
  associated to `self.sep_token` and `self.sep_token_id`.
- **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. Will be associated to `self.pad_token` and `self.pad_token_id`.
- **cls_token** (`str` or `tokenizers.AddedToken`, *optional*) --
  A special token representing the class of the input (used by BERT for instance). Will be associated to
  `self.cls_token` and `self.cls_token_id`.
- **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`.
- **additional_special_tokens** (tuple or list of `str` or `tokenizers.AddedToken`, *optional*) --
  A tuple or a list of additional special tokens. Add them here to ensure they won't be split by the
  tokenization process. Will be associated to `self.additional_special_tokens` and
  `self.additional_special_tokens_ids`.

- **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.</paramsdesc><paramgroups>0</paramgroups></docstring>

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

Inherits from [PreTrainedTokenizerBase](/docs/transformers/pr_15592/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)

- **vocab_files_names** (`Dict[str, str]`) -- A dictionary with, as keys, the `__init__` keyword name of each
  vocabulary file required by the model, and as associated values, the filename for saving the associated file
  (string).
- **pretrained_vocab_files_map** (`Dict[str, Dict[str, str]]`) -- A dictionary of dictionaries, with the
  high-level keys being the `__init__` keyword name of each vocabulary file required by the model, the
  low-level being the `short-cut-names` of the pretrained models with, as associated values, the `url` to the
  associated pretrained vocabulary file.
- **max_model_input_sizes** (`Dict[str, Optional[int]]`) -- A dictionary with, as keys, the `short-cut-names`
  of the pretrained models, and as associated values, the maximum length of the sequence inputs of this model,
  or `None` if the model has no maximum input size.
- **pretrained_init_configuration** (`Dict[str, Dict[str, Any]]`) -- A dictionary with, as keys, the
  `short-cut-names` of the pretrained models, and as associated values, a dictionary of specific arguments to
  pass to the `__init__` method of the tokenizer class for this pretrained model when loading the tokenizer
  with the [from_pretrained()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.from_pretrained) method.
- **model_input_names** (`List[str]`) -- A list of inputs expected in the forward pass of the model.
- **padding_side** (`str`) -- The default value for the side on which the model should have padding applied.
  Should be `'right'` or `'left'`.
- **truncation_side** (`str`) -- The default value for the side on which the model should have truncation
  applied. Should be `'right'` or `'left'`.





<div class="docstring">
<docstring><name>\_\_call\_\_</name><anchor>transformers.PreTrainedTokenizerBase.__call__</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L2379</source><parameters>[{"name": "text", "val": ": typing.Union[str, typing.List[str], typing.List[typing.List[str]]]"}, {"name": "text_pair", "val": ": typing.Union[str, typing.List[str], typing.List[typing.List[str]], NoneType] = None"}, {"name": "add_special_tokens", "val": ": bool = True"}, {"name": "padding", "val": ": typing.Union[bool, str, transformers.file_utils.PaddingStrategy] = False"}, {"name": "truncation", "val": ": typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = False"}, {"name": "max_length", "val": ": typing.Optional[int] = None"}, {"name": "stride", "val": ": int = 0"}, {"name": "is_split_into_words", "val": ": bool = False"}, {"name": "pad_to_multiple_of", "val": ": typing.Optional[int] = None"}, {"name": "return_tensors", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "return_token_type_ids", "val": ": typing.Optional[bool] = None"}, {"name": "return_attention_mask", "val": ": typing.Optional[bool] = None"}, {"name": "return_overflowing_tokens", "val": ": bool = False"}, {"name": "return_special_tokens_mask", "val": ": bool = False"}, {"name": "return_offsets_mapping", "val": ": bool = False"}, {"name": "return_length", "val": ": bool = False"}, {"name": "verbose", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **text** (`str`, `List[str]`, `List[List[str]]`) --
  The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
  (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
  `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
- **text_pair** (`str`, `List[str]`, `List[List[str]]`) --
  The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
  (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
  `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).

- **add_special_tokens** (`bool`, *optional*, defaults to `True`) --
  Whether or not to encode the sequences with the special tokens relative to their model.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
    sequence if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or
    to the maximum acceptable input length for the model if that argument is not provided. This will
    truncate token by token, removing a token from the longest sequence in the pair if a pair of
    sequences (or a batch of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **stride** (`int`, *optional*, defaults to 0) --
  If set to a number along with `max_length`, the overflowing tokens returned when
  `return_overflowing_tokens=True` will contain some tokens from the end of the truncated sequence
  returned to provide some overlap between truncated and overflowing sequences. The value of this
  argument defines the number of overlapping tokens.
- **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.
- **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).
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.

- **return_token_type_ids** (`bool`, *optional*) --
  Whether to return token type IDs. If left to the default, will return the token type IDs according to
  the specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are token type IDs?](../glossary#token-type-ids)
- **return_attention_mask** (`bool`, *optional*) --
  Whether to return the attention mask. If left to the default, will return the attention mask according
  to the specific tokenizer's default, defined by the `return_outputs` attribute.

  [What are attention masks?](../glossary#attention-mask)
- **return_overflowing_tokens** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return overflowing token sequences. If a pair of sequences of input ids (or a batch
  of pairs) is provided with `truncation_strategy = longest_first` or `True`, an error is raised instead
  of returning overflowing tokens.
- **return_special_tokens_mask** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return special tokens mask information.
- **return_offsets_mapping** (`bool`, *optional*, defaults to `False`) --
  Whether or not to return `(char_start, char_end)` for each token.

  This is only available on fast tokenizers inheriting from [PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast), if using
  Python's tokenizer, this method will raise `NotImplementedError`.
- **return_length**  (`bool`, *optional*, defaults to `False`) --
  Whether or not to return the lengths of the encoded inputs.
- **verbose** (`bool`, *optional*, defaults to `True`) --
  Whether or not to print more information and warnings.
  **kwargs -- passed to the `self.tokenize()` method</paramsdesc><paramgroups>0</paramgroups><rettype>[BatchEncoding](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.BatchEncoding)</rettype><retdesc>A [BatchEncoding](/docs/transformers/pr_15592/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`)</retdesc></docstring>

Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences.








</div>
<div class="docstring">
<docstring><name>batch\_decode</name><anchor>transformers.PreTrainedTokenizerBase.batch_decode</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L3250</source><parameters>[{"name": "sequences", "val": ": typing.Union[typing.List[int], typing.List[typing.List[int]], ForwardRef('np.ndarray'), ForwardRef('torch.Tensor'), ForwardRef('tf.Tensor')]"}, {"name": "skip_special_tokens", "val": ": bool = False"}, {"name": "clean_up_tokenization_spaces", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **sequences** (`Union[List[int], List[List[int]], np.ndarray, torch.Tensor, tf.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*, defaults to `True`) --
  Whether or not to clean up the tokenization spaces.
- **kwargs** (additional keyword arguments, *optional*) --
  Will be passed to the underlying model specific decode method.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>The list of decoded sentences.</retdesc></docstring>

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








</div>
<div class="docstring">
<docstring><name>decode</name><anchor>transformers.PreTrainedTokenizerBase.decode</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L3283</source><parameters>[{"name": "token_ids", "val": ": typing.Union[int, typing.List[int], ForwardRef('np.ndarray'), ForwardRef('torch.Tensor'), ForwardRef('tf.Tensor')]"}, {"name": "skip_special_tokens", "val": ": bool = False"}, {"name": "clean_up_tokenization_spaces", "val": ": bool = True"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **token_ids** (`Union[int, List[int], np.ndarray, torch.Tensor, tf.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*, defaults to `True`) --
  Whether or not to clean up the tokenization spaces.
- **kwargs** (additional keyword arguments, *optional*) --
  Will be passed to the underlying model specific decode method.</paramsdesc><paramgroups>0</paramgroups><rettype>`str`</rettype><retdesc>The decoded sentence.</retdesc></docstring>

Converts a sequence of ids in a string, 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))`.








</div>
<div class="docstring">
<docstring><name>encode</name><anchor>transformers.PreTrainedTokenizerBase.encode</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L2189</source><parameters>[{"name": "text", "val": ": typing.Union[str, typing.List[str], typing.List[int]]"}, {"name": "text_pair", "val": ": typing.Union[str, typing.List[str], typing.List[int], NoneType] = None"}, {"name": "add_special_tokens", "val": ": bool = True"}, {"name": "padding", "val": ": typing.Union[bool, str, transformers.file_utils.PaddingStrategy] = False"}, {"name": "truncation", "val": ": typing.Union[bool, str, transformers.tokenization_utils_base.TruncationStrategy] = False"}, {"name": "max_length", "val": ": typing.Optional[int] = None"}, {"name": "stride", "val": ": int = 0"}, {"name": "return_tensors", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **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).

- **add_special_tokens** (`bool`, *optional*, defaults to `True`) --
  Whether or not to encode the sequences with the special tokens relative to their model.
- **padding** (`bool`, `str` or [PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy), *optional*, defaults to `False`) --
  Activates and controls padding. Accepts the following values:

  - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
    sequence if provided).
  - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
    acceptable input length for the model if that argument is not provided.
  - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
    lengths).
- **truncation** (`bool`, `str` or [TruncationStrategy](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.tokenization_utils_base.TruncationStrategy), *optional*, defaults to `False`) --
  Activates and controls truncation. Accepts the following values:

  - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or
    to the maximum acceptable input length for the model if that argument is not provided. This will
    truncate token by token, removing a token from the longest sequence in the pair if a pair of
    sequences (or a batch of pairs) is provided.
  - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the
    maximum acceptable input length for the model if that argument is not provided. This will only
    truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
  - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
    greater than the model maximum admissible input size).
- **max_length** (`int`, *optional*) --
  Controls the maximum length to use by one of the truncation/padding parameters.

  If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
  is required by one of the truncation/padding parameters. If the model has no specific maximum input
  length (like XLNet) truncation/padding to a maximum length will be deactivated.
- **stride** (`int`, *optional*, defaults to 0) --
  If set to a number along with `max_length`, the overflowing tokens returned when
  `return_overflowing_tokens=True` will contain some tokens from the end of the truncated sequence
  returned to provide some overlap between truncated and overflowing sequences. The value of this
  argument defines the number of overlapping tokens.
- **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.
- **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).
- **return_tensors** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  If set, will return tensors instead of list of python integers. Acceptable values are:

  - `'tf'`: Return TensorFlow `tf.constant` objects.
  - `'pt'`: Return PyTorch `torch.Tensor` objects.
  - `'np'`: Return Numpy `np.ndarray` objects.

**kwargs -- Passed along to the `.tokenize()` method.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[int]`, `torch.Tensor`, `tf.Tensor` or `np.ndarray`</rettype><retdesc>The tokenized ids of the text.</retdesc></docstring>

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))`.








</div>
<div class="docstring">
<docstring><name>push\_to\_hub</name><anchor>transformers.file_utils.PushToHubMixin.push_to_hub</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/file_utils.py#L2825</source><parameters>[{"name": "repo_path_or_name", "val": ": typing.Optional[str] = None"}, {"name": "repo_url", "val": ": typing.Optional[str] = None"}, {"name": "use_temp_dir", "val": ": bool = False"}, {"name": "commit_message", "val": ": typing.Optional[str] = None"}, {"name": "organization", "val": ": typing.Optional[str] = None"}, {"name": "private", "val": ": typing.Optional[bool] = None"}, {"name": "use_auth_token", "val": ": typing.Union[bool, str, NoneType] = None"}, {"name": "**model_card_kwargs", "val": ""}]</parameters><paramsdesc>- **repo_path_or_name** (`str`, *optional*) --
  Can either be a repository name for your tokenizer in the Hub or a path to a local folder (in which case
  the repository will have the name of that local folder). If not specified, will default to the name
  given by `repo_url` and a local directory with that name will be created.
- **repo_url** (`str`, *optional*) --
  Specify this in case you want to push to an existing repository in the hub. If unspecified, a new
  repository will be created in your namespace (unless you specify an `organization`) with `repo_name`.
- **use_temp_dir** (`bool`, *optional*, defaults to `False`) --
  Whether or not to clone the distant repo in a temporary directory or in `repo_path_or_name` inside the
  current working directory. This will slow things down if you are making changes in an existing repo
  since you will need to clone the repo before every push.
- **commit_message** (`str`, *optional*) --
  Message to commit while pushing. Will default to `"add tokenizer"`.
- **organization** (`str`, *optional*) --
  Organization in which you want to push your tokenizer (you must be a member of this organization).
- **private** (`bool`, *optional*) --
  Whether or not the repository created should be private (requires a paying subscription).
- **use_auth_token** (`bool` or `str`, *optional*) --
  The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
  when running `transformers-cli login` (stored in `~/.huggingface`). Will default to `True` if
  `repo_url` is not specified.</paramsdesc><paramgroups>0</paramgroups><rettype>`str`</rettype><retdesc>The url of the commit of your tokenizer in the given repository.</retdesc></docstring>

Upload the tokenizer files to the 🤗 Model Hub while synchronizing a local clone of the repo in
`repo_path_or_name`.







Examples:

```python
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")

# Push the tokenizer to your namespace with the name "my-finetuned-bert" and have a local clone in the
# *my-finetuned-bert* folder.
tokenizer.push_to_hub("my-finetuned-bert")

# Push the tokenizer to your namespace with the name "my-finetuned-bert" with no local clone.
tokenizer.push_to_hub("my-finetuned-bert", use_temp_dir=True)

# Push the tokenizer to an organization with the name "my-finetuned-bert" and have a local clone in the
# *my-finetuned-bert* folder.
tokenizer.push_to_hub("my-finetuned-bert", organization="huggingface")

# Make a change to an existing repo that has been cloned locally in *my-finetuned-bert*.
tokenizer.push_to_hub("my-finetuned-bert", repo_url="https://huggingface.co/sgugger/my-finetuned-bert")
```


</div>
<div class="docstring">
<docstring><name>convert\_ids\_to\_tokens</name><anchor>transformers.PreTrainedTokenizerFast.convert_ids_to_tokens</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L292</source><parameters>[{"name": "ids", "val": ": typing.Union[int, typing.List[int]]"}, {"name": "skip_special_tokens", "val": ": bool = False"}]</parameters><paramsdesc>- **ids** (`int` or `List[int]`) --
  The token id (or token ids) to convert to tokens.
- **skip_special_tokens** (`bool`, *optional*, defaults to `False`) --
  Whether or not to remove special tokens in the decoding.</paramsdesc><paramgroups>0</paramgroups><rettype>`str` or `List[str]`</rettype><retdesc>The decoded token(s).</retdesc></docstring>

Converts a single index or a sequence of indices in a token or a sequence of tokens, using the vocabulary and
added tokens.








</div>
<div class="docstring">
<docstring><name>convert\_tokens\_to\_ids</name><anchor>transformers.PreTrainedTokenizerFast.convert_tokens_to_ids</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L234</source><parameters>[{"name": "tokens", "val": ": typing.Union[str, typing.List[str]]"}]</parameters><paramsdesc>- **tokens** (`str` or `List[str]`) -- One or several token(s) to convert to token id(s).</paramsdesc><paramgroups>0</paramgroups><rettype>`int` or `List[int]`</rettype><retdesc>The token id or list of token ids.</retdesc></docstring>

Converts a token string (or a sequence of tokens) in a single integer id (or a sequence of ids), using the
vocabulary.








</div>
<div class="docstring">
<docstring><name>get\_added\_vocab</name><anchor>transformers.PreTrainedTokenizerFast.get_added_vocab</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L155</source><parameters>[]</parameters><rettype>`Dict[str, int]`</rettype><retdesc>The added tokens.</retdesc></docstring>

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






</div>
<div class="docstring">
<docstring><name>num\_special\_tokens\_to\_add</name><anchor>transformers.PreTrainedTokenizerFast.num_special_tokens_to_add</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L271</source><parameters>[{"name": "pair", "val": ": bool = False"}]</parameters><paramsdesc>- **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.</paramsdesc><paramgroups>0</paramgroups><rettype>`int`</rettype><retdesc>Number of special tokens added to sequences.</retdesc></docstring>

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

<Tip>

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.

</Tip>








</div>
<div class="docstring">
<docstring><name>set\_truncation\_and\_padding</name><anchor>transformers.PreTrainedTokenizerFast.set_truncation_and_padding</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L321</source><parameters>[{"name": "padding_strategy", "val": ": PaddingStrategy"}, {"name": "truncation_strategy", "val": ": TruncationStrategy"}, {"name": "max_length", "val": ": int"}, {"name": "stride", "val": ": int"}, {"name": "pad_to_multiple_of", "val": ": typing.Optional[int]"}]</parameters><paramsdesc>- **padding_strategy** ([PaddingStrategy](/docs/transformers/pr_15592/en/internal/file_utils#transformers.file_utils.PaddingStrategy)) --
  The kind of padding that will be applied to the input
- **truncation_strategy** ([TruncationStrategy](/docs/transformers/pr_15592/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).</paramsdesc><paramgroups>0</paramgroups></docstring>

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.




</div>
<div class="docstring">
<docstring><name>train\_new\_from\_iterator</name><anchor>transformers.PreTrainedTokenizerFast.train_new_from_iterator</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_fast.py#L604</source><parameters>[{"name": "text_iterator", "val": ""}, {"name": "vocab_size", "val": ""}, {"name": "new_special_tokens", "val": " = None"}, {"name": "special_tokens_map", "val": " = None"}, {"name": "**kwargs", "val": ""}]</parameters><paramsdesc>- **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.
- **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 --
  Additional keyword arguments passed along to the trainer from the 🤗 Tokenizers library.</paramsdesc><paramgroups>0</paramgroups><rettype>[PreTrainedTokenizerFast](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast)</rettype><retdesc>A new tokenizer of the same type as the original one, trained on
`text_iterator`.</retdesc></docstring>

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








</div></div>

<h2 id="transformers.BatchEncoding">BatchEncoding</h2>

<div class="docstring">

<docstring><name>class transformers.BatchEncoding</name><anchor>transformers.BatchEncoding</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L167</source><parameters>[{"name": "data", "val": ": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}, {"name": "encoding", "val": ": typing.Union[tokenizers.Encoding, typing.Sequence[tokenizers.Encoding], NoneType] = None"}, {"name": "tensor_type", "val": ": typing.Union[NoneType, str, transformers.file_utils.TensorType] = None"}, {"name": "prepend_batch_axis", "val": ": bool = False"}, {"name": "n_sequences", "val": ": typing.Optional[int] = None"}]</parameters><paramsdesc>- **data** (`dict`) --
  Dictionary of lists/arrays/tensors returned by the encode/batch_encode methods ('input_ids',
  'attention_mask', etc.).
- **encoding** (`tokenizers.Encoding` or `Sequence[tokenizers.Encoding]`, *optional*) --
  If the tokenizer is a fast tokenizer which outputs additional information like mapping from word/character
  space to token space the `tokenizers.Encoding` instance or list of instance (for batches) hold this
  information.
- **tensor_type** (`Union[None, str, TensorType]`, *optional*) --
  You can give a tensor_type here to convert the lists of integers in PyTorch/TensorFlow/Numpy Tensors at
  initialization.
- **prepend_batch_axis** (`bool`, *optional*, defaults to `False`) --
  Whether or not to add a batch axis when converting to tensors (see `tensor_type` above).
- **n_sequences** (`Optional[int]`, *optional*) --
  You can give a tensor_type here to convert the lists of integers in PyTorch/TensorFlow/Numpy Tensors at
  initialization.</paramsdesc><paramgroups>0</paramgroups></docstring>

Holds the output of the [encode_plus()](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode_plus) and
`batch_encode` methods (tokens, attention_masks, etc).

This class is derived from a python dictionary and can be used as a dictionary. In addition, this class exposes
utility methods to map from word/character space to token space.





<div class="docstring">
<docstring><name>char\_to\_token</name><anchor>transformers.BatchEncoding.char_to_token</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L523</source><parameters>[{"name": "batch_or_char_index", "val": ": int"}, {"name": "char_index", "val": ": typing.Optional[int] = None"}, {"name": "sequence_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_or_char_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprise one sequence, this can be the index of
  the word in the sequence
- **char_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the word in the
  sequence.
- **sequence_index** (`int`, *optional*, defaults to 0) --
  If pair of sequences are encoded in the batch this can be used to specify which sequence in the pair (0
  or 1) the provided character index belongs to.</paramsdesc><paramgroups>0</paramgroups><rettype>`int`</rettype><retdesc>Index of the token.</retdesc></docstring>

Get the index of the token in the encoded output comprising a character in the original string for a sequence
of the batch.

Can be called as:

- `self.char_to_token(char_index)` if batch size is 1
- `self.char_to_token(batch_index, char_index)` if batch size is greater or equal to 1

This method is particularly suited when the input sequences are provided as pre-tokenized sequences (i.e. words
are defined by the user). In this case it allows to easily associate encoded tokens with provided tokenized
words.








</div>
<div class="docstring">
<docstring><name>char\_to\_word</name><anchor>transformers.BatchEncoding.char_to_word</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L609</source><parameters>[{"name": "batch_or_char_index", "val": ": int"}, {"name": "char_index", "val": ": typing.Optional[int] = None"}, {"name": "sequence_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_or_char_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprise one sequence, this can be the index of
  the character in the original string.
- **char_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the character in the
  original string.
- **sequence_index** (`int`, *optional*, defaults to 0) --
  If pair of sequences are encoded in the batch this can be used to specify which sequence in the pair (0
  or 1) the provided character index belongs to.</paramsdesc><paramgroups>0</paramgroups><rettype>`int` or `List[int]`</rettype><retdesc>Index or indices of the associated encoded token(s).</retdesc></docstring>

Get the word in the original string corresponding to a character in the original string of a sequence of the
batch.

Can be called as:

- `self.char_to_word(char_index)` if batch size is 1
- `self.char_to_word(batch_index, char_index)` if batch size is greater than 1

This method is particularly suited when the input sequences are provided as pre-tokenized sequences (i.e. words
are defined by the user). In this case it allows to easily associate encoded tokens with provided tokenized
words.








</div>
<div class="docstring">
<docstring><name>convert\_to\_tensors</name><anchor>transformers.BatchEncoding.convert_to_tensors</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L648</source><parameters>[{"name": "tensor_type", "val": ": typing.Union[str, transformers.file_utils.TensorType, NoneType] = None"}, {"name": "prepend_batch_axis", "val": ": bool = False"}]</parameters><paramsdesc>- **tensor_type** (`str` or [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType), *optional*) --
  The type of tensors to use. If `str`, should be one of the values of the enum
  [TensorType](/docs/transformers/pr_15592/en/internal/file_utils#transformers.TensorType). If `None`, no modification is done.
- **prepend_batch_axis** (`int`, *optional*, defaults to `False`) --
  Whether or not to add the batch dimension during the conversion.</paramsdesc><paramgroups>0</paramgroups></docstring>

Convert the inner content to tensors.




</div>
<div class="docstring">
<docstring><name>sequence\_ids</name><anchor>transformers.BatchEncoding.sequence_ids</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L301</source><parameters>[{"name": "batch_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_index** (`int`, *optional*, defaults to 0) -- The index to access in the batch.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[Optional[int]]`</rettype><retdesc>A list indicating the sequence id corresponding to each token. Special tokens added
by the tokenizer are mapped to `None` and other tokens are mapped to the index of their corresponding
sequence.</retdesc></docstring>

Return a list mapping the tokens to the id of their original sentences:

- `None` for special tokens added around or between sequences,
- `0` for tokens corresponding to words in the first sequence,
- `1` for tokens corresponding to words in the second sequence when a pair of sequences was jointly
  encoded.








</div>
<div class="docstring">
<docstring><name>to</name><anchor>transformers.BatchEncoding.to</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L731</source><parameters>[{"name": "device", "val": ": typing.Union[str, ForwardRef('torch.device')]"}]</parameters><paramsdesc>- **device** (`str` or `torch.device`) -- The device to put the tensors on.</paramsdesc><paramgroups>0</paramgroups><rettype>[BatchEncoding](/docs/transformers/pr_15592/en/main_classes/tokenizer#transformers.BatchEncoding)</rettype><retdesc>The same instance after modification.</retdesc></docstring>

Send all values to device by calling `v.to(device)` (PyTorch only).








</div>
<div class="docstring">
<docstring><name>token\_to\_chars</name><anchor>transformers.BatchEncoding.token_to_chars</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L487</source><parameters>[{"name": "batch_or_token_index", "val": ": int"}, {"name": "token_index", "val": ": typing.Optional[int] = None"}]</parameters><paramsdesc>- **batch_or_token_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprise one sequence, this can be the index of
  the token in the sequence.
- **token_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the token or tokens in
  the sequence.</paramsdesc><paramgroups>0</paramgroups><rettype>[CharSpan](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.CharSpan)</rettype><retdesc>Span of characters in the original string.</retdesc></docstring>

Get the character span corresponding to an encoded token in a sequence of the batch.

Character spans are returned as a [CharSpan](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.CharSpan) with:

- **start** -- Index of the first character in the original string associated to the token.
- **end** -- Index of the character following the last character in the original string associated to the
  token.

Can be called as:

- `self.token_to_chars(token_index)` if batch size is 1
- `self.token_to_chars(batch_index, token_index)` if batch size is greater or equal to 1








</div>
<div class="docstring">
<docstring><name>token\_to\_sequence</name><anchor>transformers.BatchEncoding.token_to_sequence</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L359</source><parameters>[{"name": "batch_or_token_index", "val": ": int"}, {"name": "token_index", "val": ": typing.Optional[int] = None"}]</parameters><paramsdesc>- **batch_or_token_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprises one sequence, this can be the index of
  the token in the sequence.
- **token_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the token in the
  sequence.</paramsdesc><paramgroups>0</paramgroups><rettype>`int`</rettype><retdesc>Index of the word in the input sequence.</retdesc></docstring>

Get the index of the sequence represented by the given token. In the general use case, this method returns `0`
for a single sequence or the first sequence of a pair, and `1` for the second sequence of a pair

Can be called as:

- `self.token_to_sequence(token_index)` if batch size is 1
- `self.token_to_sequence(batch_index, token_index)` if batch size is greater than 1

This method is particularly suited when the input sequences are provided as pre-tokenized sequences (i.e.,
words are defined by the user). In this case it allows to easily associate encoded tokens with provided
tokenized words.








</div>
<div class="docstring">
<docstring><name>token\_to\_word</name><anchor>transformers.BatchEncoding.token_to_word</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L398</source><parameters>[{"name": "batch_or_token_index", "val": ": int"}, {"name": "token_index", "val": ": typing.Optional[int] = None"}]</parameters><paramsdesc>- **batch_or_token_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprise one sequence, this can be the index of
  the token in the sequence.
- **token_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the token in the
  sequence.</paramsdesc><paramgroups>0</paramgroups><rettype>`int`</rettype><retdesc>Index of the word in the input sequence.</retdesc></docstring>

Get the index of the word corresponding (i.e. comprising) to an encoded token in a sequence of the batch.

Can be called as:

- `self.token_to_word(token_index)` if batch size is 1
- `self.token_to_word(batch_index, token_index)` if batch size is greater than 1

This method is particularly suited when the input sequences are provided as pre-tokenized sequences (i.e.,
words are defined by the user). In this case it allows to easily associate encoded tokens with provided
tokenized words.








</div>
<div class="docstring">
<docstring><name>tokens</name><anchor>transformers.BatchEncoding.tokens</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L286</source><parameters>[{"name": "batch_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_index** (`int`, *optional*, defaults to 0) -- The index to access in the batch.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[str]`</rettype><retdesc>The list of tokens at that index.</retdesc></docstring>

Return the list of tokens (sub-parts of the input strings after word/subword splitting and before conversion to
integer indices) at a given batch index (only works for the output of a fast tokenizer).








</div>
<div class="docstring">
<docstring><name>word\_ids</name><anchor>transformers.BatchEncoding.word_ids</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L343</source><parameters>[{"name": "batch_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_index** (`int`, *optional*, defaults to 0) -- The index to access in the batch.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[Optional[int]]`</rettype><retdesc>A list indicating the word corresponding to each token. Special tokens added by the
tokenizer are mapped to `None` and other tokens are mapped to the index of their corresponding word
(several tokens will be mapped to the same word index if they are parts of that word).</retdesc></docstring>

Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer.








</div>
<div class="docstring">
<docstring><name>word\_to\_chars</name><anchor>transformers.BatchEncoding.word_to_chars</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L564</source><parameters>[{"name": "batch_or_word_index", "val": ": int"}, {"name": "word_index", "val": ": typing.Optional[int] = None"}, {"name": "sequence_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_or_word_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprise one sequence, this can be the index of
  the word in the sequence
- **word_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the word in the
  sequence.
- **sequence_index** (`int`, *optional*, defaults to 0) --
  If pair of sequences are encoded in the batch this can be used to specify which sequence in the pair (0
  or 1) the provided word index belongs to.</paramsdesc><paramgroups>0</paramgroups><rettype>`CharSpan` or `List[CharSpan]`</rettype><retdesc>Span(s) of the associated character or characters in the string. CharSpan
are NamedTuple with:

- start: index of the first character associated to the token in the original string
- end: index of the character following the last character associated to the token in the original
  string</retdesc></docstring>

Get the character span in the original string corresponding to given word in a sequence of the batch.

Character spans are returned as a CharSpan NamedTuple with:

- start: index of the first character in the original string
- end: index of the character following the last character in the original string

Can be called as:

- `self.word_to_chars(word_index)` if batch size is 1
- `self.word_to_chars(batch_index, word_index)` if batch size is greater or equal to 1








</div>
<div class="docstring">
<docstring><name>word\_to\_tokens</name><anchor>transformers.BatchEncoding.word_to_tokens</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L436</source><parameters>[{"name": "batch_or_word_index", "val": ": int"}, {"name": "word_index", "val": ": typing.Optional[int] = None"}, {"name": "sequence_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_or_word_index** (`int`) --
  Index of the sequence in the batch. If the batch only comprises one sequence, this can be the index of
  the word in the sequence.
- **word_index** (`int`, *optional*) --
  If a batch index is provided in *batch_or_token_index*, this can be the index of the word in the
  sequence.
- **sequence_index** (`int`, *optional*, defaults to 0) --
  If pair of sequences are encoded in the batch this can be used to specify which sequence in the pair (0
  or 1) the provided word index belongs to.</paramsdesc><paramgroups>0</paramgroups><retdesc>Optional [TokenSpan](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.TokenSpan) Span of tokens in the encoded sequence. Returns `None` if
no tokens correspond to the word.</retdesc></docstring>

Get the encoded token span corresponding to a word in a sequence of the batch.

Token spans are returned as a [TokenSpan](/docs/transformers/pr_15592/en/internal/tokenization_utils#transformers.TokenSpan) with:

- **start** -- Index of the first token.
- **end** -- Index of the token following the last token.

Can be called as:

- `self.word_to_tokens(word_index, sequence_index: int = 0)` if batch size is 1
- `self.word_to_tokens(batch_index, word_index, sequence_index: int = 0)` if batch size is greater or equal to
  1

This method is particularly suited when the input sequences are provided as pre-tokenized sequences (i.e. words
are defined by the user). In this case it allows to easily associate encoded tokens with provided tokenized
words.






</div>
<div class="docstring">
<docstring><name>words</name><anchor>transformers.BatchEncoding.words</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/tokenization_utils_base.py#L322</source><parameters>[{"name": "batch_index", "val": ": int = 0"}]</parameters><paramsdesc>- **batch_index** (`int`, *optional*, defaults to 0) -- The index to access in the batch.</paramsdesc><paramgroups>0</paramgroups><rettype>`List[Optional[int]]`</rettype><retdesc>A list indicating the word corresponding to each token. Special tokens added by the
tokenizer are mapped to `None` and other tokens are mapped to the index of their corresponding word
(several tokens will be mapped to the same word index if they are parts of that word).</retdesc></docstring>

Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer.








</div></div>
