source
stringclasses 470
values | url
stringlengths 49
167
| file_type
stringclasses 1
value | chunk
stringlengths 1
512
| chunk_id
stringlengths 5
9
|
---|---|---|---|---|
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#usage-layoutlmv2processor | .md | image = Image.open(
"name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
).convert("RGB")
question = "What's his name?"
words = ["hello", "world"]
boxes = [[1, 2, 3, 4], [5, 6, 7, 8]] # make sure to normalize your bounding boxes
encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
print(encoding.keys())
# dict_keys(['input_ids', 'token_type_ids', 'attention_mask', 'bbox', 'image'])
``` | 132_4_21 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | This is the configuration class to store the configuration of a [`LayoutLMv2Model`]. It is used to instantiate an
LayoutLMv2 model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the LayoutLMv2
[microsoft/layoutlmv2-base-uncased](https://huggingface.co/microsoft/layoutlmv2-base-uncased) architecture. | 132_5_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | [microsoft/layoutlmv2-base-uncased](https://huggingface.co/microsoft/layoutlmv2-base-uncased) architecture.
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.
Args:
vocab_size (`int`, *optional*, defaults to 30522):
Vocabulary size of the LayoutLMv2 model. Defines the number of different tokens that can be represented by | 132_5_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | Vocabulary size of the LayoutLMv2 model. Defines the number of different tokens that can be represented by
the `inputs_ids` passed when calling [`LayoutLMv2Model`] or [`TFLayoutLMv2Model`].
hidden_size (`int`, *optional*, defaults to 768):
Dimension of the encoder layers and the pooler layer.
num_hidden_layers (`int`, *optional*, defaults to 12):
Number of hidden layers in the Transformer encoder.
num_attention_heads (`int`, *optional*, defaults to 12): | 132_5_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | Number of hidden layers in the Transformer encoder.
num_attention_heads (`int`, *optional*, defaults to 12):
Number of attention heads for each attention layer in the Transformer encoder.
intermediate_size (`int`, *optional*, defaults to 3072):
Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`, | 132_5_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
`"relu"`, `"selu"` and `"gelu_new"` are supported.
hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
The dropout ratio for the attention probabilities.
max_position_embeddings (`int`, *optional*, defaults to 512): | 132_5_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | The dropout ratio for the attention probabilities.
max_position_embeddings (`int`, *optional*, defaults to 512):
The maximum sequence length that this model might ever be used with. Typically set this to something large
just in case (e.g., 512 or 1024 or 2048).
type_vocab_size (`int`, *optional*, defaults to 2):
The vocabulary size of the `token_type_ids` passed when calling [`LayoutLMv2Model`] or
[`TFLayoutLMv2Model`].
initializer_range (`float`, *optional*, defaults to 0.02): | 132_5_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | [`TFLayoutLMv2Model`].
initializer_range (`float`, *optional*, defaults to 0.02):
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
layer_norm_eps (`float`, *optional*, defaults to 1e-12):
The epsilon used by the layer normalization layers.
max_2d_position_embeddings (`int`, *optional*, defaults to 1024):
The maximum value that the 2D position embedding might ever be used with. Typically set this to something
large just in case (e.g., 1024). | 132_5_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | large just in case (e.g., 1024).
max_rel_pos (`int`, *optional*, defaults to 128):
The maximum number of relative positions to be used in the self-attention mechanism.
rel_pos_bins (`int`, *optional*, defaults to 32):
The number of relative position bins to be used in the self-attention mechanism.
fast_qkv (`bool`, *optional*, defaults to `True`):
Whether or not to use a single matrix for the queries, keys, values in the self-attention layers.
max_rel_2d_pos (`int`, *optional*, defaults to 256): | 132_5_7 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | max_rel_2d_pos (`int`, *optional*, defaults to 256):
The maximum number of relative 2D positions in the self-attention mechanism.
rel_2d_pos_bins (`int`, *optional*, defaults to 64):
The number of 2D relative position bins in the self-attention mechanism.
image_feature_pool_shape (`List[int]`, *optional*, defaults to [7, 7, 256]):
The shape of the average-pooled feature map.
coordinate_size (`int`, *optional*, defaults to 128):
Dimension of the coordinate embeddings. | 132_5_8 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | coordinate_size (`int`, *optional*, defaults to 128):
Dimension of the coordinate embeddings.
shape_size (`int`, *optional*, defaults to 128):
Dimension of the width and height embeddings.
has_relative_attention_bias (`bool`, *optional*, defaults to `True`):
Whether or not to use a relative attention bias in the self-attention mechanism.
has_spatial_attention_bias (`bool`, *optional*, defaults to `True`):
Whether or not to use a spatial attention bias in the self-attention mechanism. | 132_5_9 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | Whether or not to use a spatial attention bias in the self-attention mechanism.
has_visual_segment_embedding (`bool`, *optional*, defaults to `False`):
Whether or not to add visual segment embeddings.
detectron2_config_args (`dict`, *optional*):
Dictionary containing the configuration arguments of the Detectron2 visual backbone. Refer to [this
file](https://github.com/microsoft/unilm/blob/master/layoutlmft/layoutlmft/models/layoutlmv2/detectron2_config.py)
for details regarding default values.
Example: | 132_5_10 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | for details regarding default values.
Example:
```python
>>> from transformers import LayoutLMv2Config, LayoutLMv2Model | 132_5_11 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2config | .md | >>> # Initializing a LayoutLMv2 microsoft/layoutlmv2-base-uncased style configuration
>>> configuration = LayoutLMv2Config()
>>> # Initializing a model (with random weights) from the microsoft/layoutlmv2-base-uncased style configuration
>>> model = LayoutLMv2Model(configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
``` | 132_5_12 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2featureextractor | .md | No docstring available for LayoutLMv2FeatureExtractor
Methods: __call__ | 132_6_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2imageprocessor | .md | Constructs a LayoutLMv2 image processor.
Args:
do_resize (`bool`, *optional*, defaults to `True`):
Whether to resize the image's (height, width) dimensions to `(size["height"], size["width"])`. Can be
overridden by `do_resize` in `preprocess`.
size (`Dict[str, int]` *optional*, defaults to `{"height": 224, "width": 224}`):
Size of the image after resizing. Can be overridden by `size` in `preprocess`.
resample (`PILImageResampling`, *optional*, defaults to `Resampling.BILINEAR`): | 132_7_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2imageprocessor | .md | resample (`PILImageResampling`, *optional*, defaults to `Resampling.BILINEAR`):
Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in the
`preprocess` method.
apply_ocr (`bool`, *optional*, defaults to `True`):
Whether to apply the Tesseract OCR engine to get words + normalized bounding boxes. Can be overridden by
`apply_ocr` in `preprocess`.
ocr_lang (`str`, *optional*): | 132_7_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2imageprocessor | .md | `apply_ocr` in `preprocess`.
ocr_lang (`str`, *optional*):
The language, specified by its ISO code, to be used by the Tesseract OCR engine. By default, English is
used. Can be overridden by `ocr_lang` in `preprocess`.
tesseract_config (`str`, *optional*, defaults to `""`):
Any additional custom configuration flags that are forwarded to the `config` parameter when calling
Tesseract. For example: '--psm 6'. Can be overridden by `tesseract_config` in `preprocess`.
Methods: preprocess | 132_7_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizer | .md | Construct a LayoutLMv2 tokenizer. Based on WordPiece. [`LayoutLMv2Tokenizer`] can be used to turn words, word-level
bounding boxes and optional word labels to token-level `input_ids`, `attention_mask`, `token_type_ids`, `bbox`, and
optional `labels` (for token classification).
This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods. | 132_8_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizer | .md | this superclass for more information regarding those methods.
[`LayoutLMv2Tokenizer`] runs end-to-end tokenization: punctuation splitting and wordpiece. It also turns the
word-level bounding boxes into token-level bounding boxes.
Methods: __call__
- save_vocabulary | 132_8_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | Construct a "fast" LayoutLMv2 tokenizer (backed by HuggingFace's *tokenizers* library). Based on WordPiece.
This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.
Args:
vocab_file (`str`):
File containing the vocabulary.
do_lower_case (`bool`, *optional*, defaults to `True`):
Whether or not to lowercase the input when tokenizing. | 132_9_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | do_lower_case (`bool`, *optional*, defaults to `True`):
Whether or not to lowercase the input when tokenizing.
unk_token (`str`, *optional*, defaults to `"[UNK]"`):
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.
sep_token (`str`, *optional*, defaults to `"[SEP]"`):
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for | 132_9_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.
pad_token (`str`, *optional*, defaults to `"[PAD]"`):
The token used for padding, for example when batching sequences of different lengths.
cls_token (`str`, *optional*, defaults to `"[CLS]"`): | 132_9_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | cls_token (`str`, *optional*, defaults to `"[CLS]"`):
The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.
mask_token (`str`, *optional*, defaults to `"[MASK]"`):
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict. | 132_9_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | modeling. This is the token which the model will try to predict.
cls_token_box (`List[int]`, *optional*, defaults to `[0, 0, 0, 0]`):
The bounding box to use for the special [CLS] token.
sep_token_box (`List[int]`, *optional*, defaults to `[1000, 1000, 1000, 1000]`):
The bounding box to use for the special [SEP] token.
pad_token_box (`List[int]`, *optional*, defaults to `[0, 0, 0, 0]`):
The bounding box to use for the special [PAD] token.
pad_token_label (`int`, *optional*, defaults to -100): | 132_9_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | The bounding box to use for the special [PAD] token.
pad_token_label (`int`, *optional*, defaults to -100):
The label to use for padding tokens. Defaults to -100, which is the `ignore_index` of PyTorch's
CrossEntropyLoss.
only_label_first_subword (`bool`, *optional*, defaults to `True`):
Whether or not to only label the first subword, in case word labels are provided.
tokenize_chinese_chars (`bool`, *optional*, defaults to `True`): | 132_9_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2tokenizerfast | .md | tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
Whether or not to tokenize Chinese characters. This should likely be deactivated for Japanese (see [this
issue](https://github.com/huggingface/transformers/issues/328)).
strip_accents (`bool`, *optional*):
Whether or not to strip all accents. If this option is not specified, then it will be determined by the
value for `lowercase` (as in the original LayoutLMv2).
Methods: __call__ | 132_9_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2processor | .md | Constructs a LayoutLMv2 processor which combines a LayoutLMv2 image processor and a LayoutLMv2 tokenizer into a
single processor.
[`LayoutLMv2Processor`] offers all the functionalities you need to prepare data for the model.
It first uses [`LayoutLMv2ImageProcessor`] to resize document images to a fixed size, and optionally applies OCR to
get words and normalized bounding boxes. These are then provided to [`LayoutLMv2Tokenizer`] or | 132_10_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2processor | .md | get words and normalized bounding boxes. These are then provided to [`LayoutLMv2Tokenizer`] or
[`LayoutLMv2TokenizerFast`], which turns the words and bounding boxes into token-level `input_ids`,
`attention_mask`, `token_type_ids`, `bbox`. Optionally, one can provide integer `word_labels`, which are turned
into token-level `labels` for token classification tasks (such as FUNSD, CORD).
Args:
image_processor (`LayoutLMv2ImageProcessor`, *optional*): | 132_10_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2processor | .md | Args:
image_processor (`LayoutLMv2ImageProcessor`, *optional*):
An instance of [`LayoutLMv2ImageProcessor`]. The image processor is a required input.
tokenizer (`LayoutLMv2Tokenizer` or `LayoutLMv2TokenizerFast`, *optional*):
An instance of [`LayoutLMv2Tokenizer`] or [`LayoutLMv2TokenizerFast`]. The tokenizer is a required input.
Methods: __call__ | 132_10_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2model | .md | The bare LayoutLMv2 Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.
Parameters:
config ([`LayoutLMv2Config`]): Model configuration class with all the parameters of the model. | 132_11_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2model | .md | behavior.
Parameters:
config ([`LayoutLMv2Config`]): Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
Methods: forward | 132_11_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2forsequenceclassification | .md | LayoutLMv2 Model with a sequence classification head on top (a linear layer on top of the concatenation of the
final hidden state of the [CLS] token, average-pooled initial visual embeddings and average-pooled final visual
embeddings, e.g. for document image classification tasks such as the
[RVL-CDIP](https://www.cs.cmu.edu/~aharley/rvl-cdip/) dataset.
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use | 132_12_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2forsequenceclassification | .md | This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.
Parameters:
config ([`LayoutLMv2Config`]): Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the | 132_12_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2forsequenceclassification | .md | Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. | 132_12_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2fortokenclassification | .md | LayoutLMv2 Model with a token classification head on top (a linear layer on top of the text part of the hidden
states) e.g. for sequence labeling (information extraction) tasks such as
[FUNSD](https://guillaumejaume.github.io/FUNSD/), [SROIE](https://rrc.cvc.uab.es/?ch=13),
[CORD](https://github.com/clovaai/cord) and [Kleister-NDA](https://github.com/applicaai/kleister-nda).
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use | 132_13_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2fortokenclassification | .md | This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.
Parameters:
config ([`LayoutLMv2Config`]): Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the | 132_13_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2fortokenclassification | .md | Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. | 132_13_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2forquestionanswering | .md | LayoutLMv2 Model with a span classification head on top for extractive question-answering tasks such as
[DocVQA](https://rrc.cvc.uab.es/?ch=17) (a linear layer on top of the text part of the hidden-states output to
compute `span start logits` and `span end logits`).
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior. | 132_14_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/layoutlmv2.md | https://huggingface.co/docs/transformers/en/model_doc/layoutlmv2/#layoutlmv2forquestionanswering | .md | it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.
Parameters:
config ([`LayoutLMv2Config`]): Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. | 132_14_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/ | .md | <!--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 | 133_0_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/ | .md | 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.
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
--> | 133_0_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribert | .md | <Tip warning={true}>
This model is in maintenance mode only, so we won't accept any new PRs changing its code.
If you run into any issues running this model, please reinstall the last version that supported this model: v4.30.0.
You can do so by running the following command: `pip install -U transformers==4.30.0`.
</Tip> | 133_1_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#overview | .md | The RetriBERT model was proposed in the blog post [Explain Anything Like I'm Five: A Model for Open Domain Long Form
Question Answering](https://yjernite.github.io/lfqa.html). RetriBERT is a small model that uses either a single or
pair of BERT encoders with lower-dimension projection for dense semantic indexing of text.
This model was contributed by [yjernite](https://huggingface.co/yjernite). Code to train and use the model can be | 133_2_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#overview | .md | This model was contributed by [yjernite](https://huggingface.co/yjernite). Code to train and use the model can be
found [here](https://github.com/huggingface/transformers/tree/main/examples/research-projects/distillation). | 133_2_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | This is the configuration class to store the configuration of a [`RetriBertModel`]. It is used to instantiate a
RetriBertModel model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the RetriBERT
[yjernite/retribert-base-uncased](https://huggingface.co/yjernite/retribert-base-uncased) architecture. | 133_3_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | [yjernite/retribert-base-uncased](https://huggingface.co/yjernite/retribert-base-uncased) architecture.
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.
Args:
vocab_size (`int`, *optional*, defaults to 30522):
Vocabulary size of the RetriBERT model. Defines the number of different tokens that can be represented by
the `inputs_ids` passed when calling [`RetriBertModel`] | 133_3_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | the `inputs_ids` passed when calling [`RetriBertModel`]
hidden_size (`int`, *optional*, defaults to 768):
Dimensionality of the encoder layers and the pooler layer.
num_hidden_layers (`int`, *optional*, defaults to 12):
Number of hidden layers in the Transformer encoder.
num_attention_heads (`int`, *optional*, defaults to 12):
Number of attention heads for each attention layer in the Transformer encoder.
intermediate_size (`int`, *optional*, defaults to 3072): | 133_3_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | intermediate_size (`int`, *optional*, defaults to 3072):
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
`"relu"`, `"silu"` and `"gelu_new"` are supported.
hidden_dropout_prob (`float`, *optional*, defaults to 0.1): | 133_3_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | `"relu"`, `"silu"` and `"gelu_new"` are supported.
hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
The dropout ratio for the attention probabilities.
max_position_embeddings (`int`, *optional*, defaults to 512):
The maximum sequence length that this model might ever be used with. Typically set this to something large | 133_3_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | The maximum sequence length that this model might ever be used with. Typically set this to something large
just in case (e.g., 512 or 1024 or 2048).
type_vocab_size (`int`, *optional*, defaults to 2):
The vocabulary size of the *token_type_ids* passed into [`BertModel`].
initializer_range (`float`, *optional*, defaults to 0.02):
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
layer_norm_eps (`float`, *optional*, defaults to 1e-12): | 133_3_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertconfig | .md | layer_norm_eps (`float`, *optional*, defaults to 1e-12):
The epsilon used by the layer normalization layers.
share_encoders (`bool`, *optional*, defaults to `True`):
Whether or not to use the same Bert-type encoder for the queries and document
projection_dim (`int`, *optional*, defaults to 128):
Final dimension of the query and document representation after projection | 133_3_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizer | .md | Constructs a RetriBERT tokenizer.
[`RetriBertTokenizer`] is identical to [`BertTokenizer`] and runs end-to-end tokenization: punctuation splitting
and wordpiece.
This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer
to: this superclass for more information regarding those methods.
Args:
vocab_file (`str`):
File containing the vocabulary.
do_lower_case (`bool`, *optional*, defaults to `True`): | 133_4_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizer | .md | Args:
vocab_file (`str`):
File containing the vocabulary.
do_lower_case (`bool`, *optional*, defaults to `True`):
Whether or not to lowercase the input when tokenizing.
do_basic_tokenize (`bool`, *optional*, defaults to `True`):
Whether or not to do basic tokenization before WordPiece.
never_split (`Iterable`, *optional*):
Collection of tokens which will never be split during tokenization. Only has an effect when
`do_basic_tokenize=True`
unk_token (`str`, *optional*, defaults to `"[UNK]"`): | 133_4_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizer | .md | `do_basic_tokenize=True`
unk_token (`str`, *optional*, defaults to `"[UNK]"`):
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.
sep_token (`str`, *optional*, defaults to `"[SEP]"`):
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last | 133_4_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizer | .md | sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.
pad_token (`str`, *optional*, defaults to `"[PAD]"`):
The token used for padding, for example when batching sequences of different lengths.
cls_token (`str`, *optional*, defaults to `"[CLS]"`):
The classifier token which is used when doing sequence classification (classification of the whole sequence | 133_4_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizer | .md | The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.
mask_token (`str`, *optional*, defaults to `"[MASK]"`):
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict.
tokenize_chinese_chars (`bool`, *optional*, defaults to `True`): | 133_4_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizer | .md | tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
Whether or not to tokenize Chinese characters. This should likely be deactivated for Japanese (see this
[issue](https://github.com/huggingface/transformers/issues/328)).
strip_accents (`bool`, *optional*):
Whether or not to strip all accents. If this option is not specified, then it will be determined by the
value for `lowercase` (as in the original BERT). | 133_4_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizerfast | .md | Construct a "fast" RetriBERT tokenizer (backed by HuggingFace's *tokenizers* library).
[`RetriBertTokenizerFast`] is identical to [`BertTokenizerFast`] and runs end-to-end tokenization: punctuation
splitting and wordpiece.
This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.
Args:
vocab_file (`str`):
File containing the vocabulary. | 133_5_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizerfast | .md | Args:
vocab_file (`str`):
File containing the vocabulary.
do_lower_case (`bool`, *optional*, defaults to `True`):
Whether or not to lowercase the input when tokenizing.
unk_token (`str`, *optional*, defaults to `"[UNK]"`):
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.
sep_token (`str`, *optional*, defaults to `"[SEP]"`):
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for | 133_5_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizerfast | .md | The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.
pad_token (`str`, *optional*, defaults to `"[PAD]"`):
The token used for padding, for example when batching sequences of different lengths.
cls_token (`str`, *optional*, defaults to `"[CLS]"`): | 133_5_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizerfast | .md | cls_token (`str`, *optional*, defaults to `"[CLS]"`):
The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.
mask_token (`str`, *optional*, defaults to `"[MASK]"`):
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict. | 133_5_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizerfast | .md | modeling. This is the token which the model will try to predict.
clean_text (`bool`, *optional*, defaults to `True`):
Whether or not to clean the text before tokenization by removing any control characters and replacing all
whitespaces by the classic one.
tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
Whether or not to tokenize Chinese characters. This should likely be deactivated for Japanese (see [this
issue](https://github.com/huggingface/transformers/issues/328)). | 133_5_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retriberttokenizerfast | .md | issue](https://github.com/huggingface/transformers/issues/328)).
strip_accents (`bool`, *optional*):
Whether or not to strip all accents. If this option is not specified, then it will be determined by the
value for `lowercase` (as in the original BERT).
wordpieces_prefix (`str`, *optional*, defaults to `"##"`):
The prefix for subwords. | 133_5_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertmodel | .md | Bert Based model to embed queries or document for document retrieval.
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. | 133_6_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertmodel | .md | etc.)
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.
Parameters:
config ([`RetriBertConfig`]): Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the | 133_6_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/retribert.md | https://huggingface.co/docs/transformers/en/model_doc/retribert/#retribertmodel | .md | Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
Methods: forward | 133_6_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/ | .md | <!--Copyright 2023 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 | 134_0_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/ | .md | 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.
--> | 134_0_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#overview | .md | Bark is a transformer-based text-to-speech model proposed by Suno AI in [suno-ai/bark](https://github.com/suno-ai/bark).
Bark is made of 4 main models:
- [`BarkSemanticModel`] (also referred to as the 'text' model): a causal auto-regressive transformer model that takes as input tokenized text, and predicts semantic text tokens that capture the meaning of the text. | 134_1_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#overview | .md | - [`BarkCoarseModel`] (also referred to as the 'coarse acoustics' model): a causal autoregressive transformer, that takes as input the results of the [`BarkSemanticModel`] model. It aims at predicting the first two audio codebooks necessary for EnCodec.
- [`BarkFineModel`] (the 'fine acoustics' model), this time a non-causal autoencoder transformer, which iteratively predicts the last codebooks based on the sum of the previous codebooks embeddings. | 134_1_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#overview | .md | - having predicted all the codebook channels from the [`EncodecModel`], Bark uses it to decode the output audio array.
It should be noted that each of the first three modules can support conditional speaker embeddings to condition the output sound according to specific predefined voice.
This model was contributed by [Yoach Lacombe (ylacombe)](https://huggingface.co/ylacombe) and [Sanchit Gandhi (sanchit-gandhi)](https://github.com/sanchit-gandhi). | 134_1_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#overview | .md | The original code can be found [here](https://github.com/suno-ai/bark). | 134_1_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#optimizing-bark | .md | Bark can be optimized with just a few extra lines of code, which **significantly reduces its memory footprint** and **accelerates inference**. | 134_2_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-half-precision | .md | You can speed up inference and reduce memory footprint by 50% simply by loading the model in half-precision.
```python
from transformers import BarkModel
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model = BarkModel.from_pretrained("suno/bark-small", torch_dtype=torch.float16).to(device)
``` | 134_3_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-cpu-offload | .md | As mentioned above, Bark is made up of 4 sub-models, which are called up sequentially during audio generation. In other words, while one sub-model is in use, the other sub-models are idle.
If you're using a CUDA device, a simple solution to benefit from an 80% reduction in memory footprint is to offload the submodels from GPU to CPU when they're idle. This operation is called *CPU offloading*. You can use it with one line of code as follows:
```python
model.enable_cpu_offload()
``` | 134_4_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-cpu-offload | .md | ```python
model.enable_cpu_offload()
```
Note that 🤗 Accelerate must be installed before using this feature. [Here's how to install it.](https://huggingface.co/docs/accelerate/basic_tutorials/install) | 134_4_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-better-transformer | .md | Better Transformer is an 🤗 Optimum feature that performs kernel fusion under the hood. You can gain 20% to 30% in speed with zero performance degradation. It only requires one line of code to export the model to 🤗 Better Transformer:
```python
model = model.to_bettertransformer()
```
Note that 🤗 Optimum must be installed before using this feature. [Here's how to install it.](https://huggingface.co/docs/optimum/installation) | 134_5_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | Flash Attention 2 is an even faster, optimized version of the previous optimization.
##### Installation | 134_6_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | ##### Installation
First, check whether your hardware is compatible with Flash Attention 2. The latest list of compatible hardware can be found in the [official documentation](https://github.com/Dao-AILab/flash-attention#installation-and-features). If your hardware is not compatible with Flash Attention 2, you can still benefit from attention kernel optimisations through Better Transformer support covered [above](https://huggingface.co/docs/transformers/main/en/model_doc/bark#using-better-transformer). | 134_6_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | Next, [install](https://github.com/Dao-AILab/flash-attention#installation-and-features) the latest version of Flash Attention 2:
```bash
pip install -U flash-attn --no-build-isolation
```
##### Usage | 134_6_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | ```bash
pip install -U flash-attn --no-build-isolation
```
##### Usage
To load a model using Flash Attention 2, we can pass the `attn_implementation="flash_attention_2"` flag to [`.from_pretrained`](https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained). We'll also load the model in half-precision (e.g. `torch.float16`), since it results in almost no degradation to audio quality but significantly lower memory usage and faster inference: | 134_6_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | ```python
model = BarkModel.from_pretrained("suno/bark-small", torch_dtype=torch.float16, attn_implementation="flash_attention_2").to(device)
```
##### Performance comparison | 134_6_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | ```
##### Performance comparison
The following diagram shows the latency for the native attention implementation (no optimisation) against Better Transformer and Flash Attention 2. In all cases, we generate 400 semantic tokens on a 40GB A100 GPU with PyTorch 2.1. Flash Attention 2 is also consistently faster than Better Transformer, and its performance improves even more as batch sizes increase:
<div style="text-align: center"> | 134_6_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | <div style="text-align: center">
<img src="https://huggingface.co/datasets/ylacombe/benchmark-comparison/resolve/main/Bark%20Optimization%20Benchmark.png">
</div> | 134_6_6 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | </div>
To put this into perspective, on an NVIDIA A100 and when generating 400 semantic tokens with a batch size of 16, you can get 17 times the [throughput](https://huggingface.co/blog/optimizing-bark#throughput) and still be 2 seconds faster than generating sentences one by one with the native model implementation. In other words, all the samples will be generated 17 times faster. | 134_6_7 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#using-flash-attention-2 | .md | At batch size 8, on an NVIDIA A100, Flash Attention 2 is also 10% faster than Better Transformer, and at batch size 16, 25%. | 134_6_8 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#combining-optimization-techniques | .md | You can combine optimization techniques, and use CPU offload, half-precision and Flash Attention 2 (or 🤗 Better Transformer) all at once.
```python
from transformers import BarkModel
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
# load in fp16 and use Flash Attention 2
model = BarkModel.from_pretrained("suno/bark-small", torch_dtype=torch.float16, attn_implementation="flash_attention_2").to(device) | 134_7_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#combining-optimization-techniques | .md | # enable CPU offload
model.enable_cpu_offload()
```
Find out more on inference optimization techniques [here](https://huggingface.co/docs/transformers/perf_infer_gpu_one). | 134_7_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#usage-tips | .md | Suno offers a library of voice presets in a number of languages [here](https://suno-ai.notion.site/8b8e8749ed514b0cbf3f699013548683?v=bc67cff786b04b50b3ceb756fd05f68c).
These presets are also uploaded in the hub [here](https://huggingface.co/suno/bark-small/tree/main/speaker_embeddings) or [here](https://huggingface.co/suno/bark/tree/main/speaker_embeddings).
```python
>>> from transformers import AutoProcessor, BarkModel | 134_8_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#usage-tips | .md | >>> processor = AutoProcessor.from_pretrained("suno/bark")
>>> model = BarkModel.from_pretrained("suno/bark")
>>> voice_preset = "v2/en_speaker_6"
>>> inputs = processor("Hello, my dog is cute", voice_preset=voice_preset) | 134_8_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#usage-tips | .md | >>> voice_preset = "v2/en_speaker_6"
>>> inputs = processor("Hello, my dog is cute", voice_preset=voice_preset)
>>> audio_array = model.generate(**inputs)
>>> audio_array = audio_array.cpu().numpy().squeeze()
```
Bark can generate highly realistic, **multilingual** speech as well as other audio - including music, background noise and simple sound effects.
```python
>>> # Multilingual speech - simplified Chinese
>>> inputs = processor("惊人的!我会说中文") | 134_8_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#usage-tips | .md | >>> # Multilingual speech - French - let's use a voice_preset as well
>>> inputs = processor("Incroyable! Je peux générer du son.", voice_preset="fr_speaker_5")
>>> # Bark can also generate music. You can help it out by adding music notes around your lyrics.
>>> inputs = processor("♪ Hello, my dog is cute ♪") | 134_8_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#usage-tips | .md | >>> audio_array = model.generate(**inputs)
>>> audio_array = audio_array.cpu().numpy().squeeze()
```
The model can also produce **nonverbal communications** like laughing, sighing and crying.
```python
>>> # Adding non-speech cues to the input text
>>> inputs = processor("Hello uh ... [clears throat], my dog is cute [laughter]") | 134_8_4 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#usage-tips | .md | >>> audio_array = model.generate(**inputs)
>>> audio_array = audio_array.cpu().numpy().squeeze()
```
To save the audio, simply take the sample rate from the model config and some scipy utility:
```python
>>> from scipy.io.wavfile import write as write_wav
>>> # save audio to disk, but first take the sample rate from the model config
>>> sample_rate = model.generation_config.sample_rate
>>> write_wav("bark_generation.wav", sample_rate, audio_array)
``` | 134_8_5 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#barkconfig | .md | This is the configuration class to store the configuration of a [`BarkModel`]. It is used to instantiate a Bark
model according to the specified sub-models configurations, defining the model architecture.
Instantiating a configuration with the defaults will yield a similar configuration to that of the Bark
[suno/bark](https://huggingface.co/suno/bark) architecture.
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the | 134_9_0 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#barkconfig | .md | Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.
Args:
semantic_config ([`BarkSemanticConfig`], *optional*):
Configuration of the underlying semantic sub-model.
coarse_acoustics_config ([`BarkCoarseConfig`], *optional*):
Configuration of the underlying coarse acoustics sub-model.
fine_acoustics_config ([`BarkFineConfig`], *optional*): | 134_9_1 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#barkconfig | .md | Configuration of the underlying coarse acoustics sub-model.
fine_acoustics_config ([`BarkFineConfig`], *optional*):
Configuration of the underlying fine acoustics sub-model.
codec_config ([`AutoConfig`], *optional*):
Configuration of the underlying codec sub-model.
Example:
```python
>>> from transformers import (
... BarkSemanticConfig,
... BarkCoarseConfig,
... BarkFineConfig,
... BarkModel,
... BarkConfig,
... AutoConfig,
... ) | 134_9_2 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#barkconfig | .md | >>> # Initializing Bark sub-modules configurations.
>>> semantic_config = BarkSemanticConfig()
>>> coarse_acoustics_config = BarkCoarseConfig()
>>> fine_acoustics_config = BarkFineConfig()
>>> codec_config = AutoConfig.from_pretrained("facebook/encodec_24khz")
>>> # Initializing a Bark module style configuration
>>> configuration = BarkConfig.from_sub_model_configs(
... semantic_config, coarse_acoustics_config, fine_acoustics_config, codec_config
... ) | 134_9_3 |
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/bark.md | https://huggingface.co/docs/transformers/en/model_doc/bark/#barkconfig | .md | >>> # Initializing a model (with random weights)
>>> model = BarkModel(configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
```
Methods: all | 134_9_4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.