text
stringlengths
5
58.6k
source
stringclasses
470 values
url
stringlengths
49
167
source_section
stringlengths
0
90
file_type
stringclasses
1 value
id
stringlengths
3
6
When you want to train a 🤗 Transformers model with the Keras API, you need to convert your dataset to a format that Keras understands. If your dataset is small, you can just convert the whole thing to NumPy arrays and pass it to Keras. Let's try that first before we do anything more complicated. First, load a datase...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#loading-data-for-keras
#loading-data-for-keras
.md
11_9
If you want to avoid slowing down training, you can load your data as a `tf.data.Dataset` instead. Although you can write your own `tf.data` pipeline if you want, we have two convenience methods for doing this: - [`~TFPreTrainedModel.prepare_tf_dataset`]: This is the method we recommend in most cases. Because it is a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#loading-data-as-a-tfdatadataset
#loading-data-as-a-tfdatadataset
.md
11_10
<frameworkcontent> <pt> <Youtube id="Dh9CL8fyG80"/> [`Trainer`] takes care of the training loop and allows you to fine-tune a model in a single line of code. For users who prefer to write their own training loop, you can also fine-tune a 🤗 Transformers model in native PyTorch. At this point, you may need to restar...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#train-in-native-pytorch
#train-in-native-pytorch
.md
11_11
Create a `DataLoader` for your training and test datasets so you can iterate over batches of data: ```py >>> from torch.utils.data import DataLoader >>> train_dataloader = DataLoader(small_train_dataset, shuffle=True, batch_size=8) >>> eval_dataloader = DataLoader(small_eval_dataset, batch_size=8) ``` Load your mo...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#dataloader
#dataloader
.md
11_12
Create an optimizer and learning rate scheduler to fine-tune the model. Let's use the [`AdamW`](https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html) optimizer from PyTorch: ```py >>> from torch.optim import AdamW >>> optimizer = AdamW(model.parameters(), lr=5e-5) ``` Create the default learning rate s...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#optimizer-and-learning-rate-scheduler
#optimizer-and-learning-rate-scheduler
.md
11_13
To keep track of your training progress, use the [tqdm](https://tqdm.github.io/) library to add a progress bar over the number of training steps: ```py >>> from tqdm.auto import tqdm >>> progress_bar = tqdm(range(num_training_steps)) >>> model.train() >>> for epoch in range(num_epochs): ... for batch in train_d...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#training-loop
#training-loop
.md
11_14
Just like how you added an evaluation function to [`Trainer`], you need to do the same when you write your own training loop. But instead of calculating and reporting the metric at the end of each epoch, this time you'll accumulate all the batches with [`~evaluate.add_batch`] and calculate the metric at the very end. ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#evaluate
#evaluate
.md
11_15
For more fine-tuning examples, refer to: - [🤗 Transformers Examples](https://github.com/huggingface/transformers/tree/main/examples) includes scripts to train common NLP tasks in PyTorch and TensorFlow. - [🤗 Transformers Notebooks](notebooks) contains various notebooks on how to fine-tune a model for specific tas...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/training.md
https://huggingface.co/docs/transformers/en/training/#additional-resources
#additional-resources
.md
11_16
<!--Copyright 2024 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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/
.md
12_0
If you're reading this article, you're almost certainly aware of **chat models**. Chat models are conversational AIs that you can send and receive messages with. The most famous of these is the proprietary ChatGPT, but there are now many open-source chat models which match or even substantially exceed its performance. ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#chatting-with-transformers
#chatting-with-transformers
.md
12_1
If you have no time for details, here's the brief summary: Chat models continue chats. This means that you pass them a conversation history, which can be as short as a single user message, and the model will continue the conversation by adding its response. Let's see this in action. First, let's build a chat: ```pyth...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#quickstart
#quickstart
.md
12_2
There are an enormous number of different chat models available on the [Hugging Face Hub](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending), and new users often feel very overwhelmed by the selection offered. Don't be, though! You really need to just focus on two important considerations: - The ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#choosing-a-chat-model
#choosing-a-chat-model
.md
12_3
The size of a model is easy to spot - it's the number in the model name, like "8B" or "70B". This is the number of **parameters** in the model. Without quantization, you should expect to need about 2 bytes of memory per parameter. This means that an "8B" model with 8 billion parameters will need about 16GB of memory ju...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#size-and-model-naming
#size-and-model-naming
.md
12_4
Even once you know the size of chat model you can run, there's still a lot of choice out there. One way to sift through it all is to consult **leaderboards**. Two of the most popular leaderboards are the [OpenLLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard) and the [LMSys Chatbot Arena...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#but-which-chat-model-is-best
#but-which-chat-model-is-best
.md
12_5
Some models may be specialized for certain domains, such as medical or legal text, or non-English languages. If you're working in these domains, you may find that a specialized model will give you big performance benefits. Don't automatically assume that, though! Particularly when specialized models are smaller or olde...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#specialist-domains
#specialist-domains
.md
12_6
The quickstart above used a high-level pipeline to chat with a chat model, which is convenient, but not the most flexible. Let's take a more low-level approach, to see each of the steps involved in chat. Let's start with a code sample, and then break it down: ```python from transformers import AutoModelForCausalLM, A...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#what-happens-inside-the-pipeline
#what-happens-inside-the-pipeline
.md
12_7
You probably know by now that most machine learning tasks are run on GPUs. However, it is entirely possible to generate text from a chat model or language model on a CPU, albeit somewhat more slowly. If you can fit the model in GPU memory, though, this will usually be the preferable option.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#performance-memory-and-hardware
#performance-memory-and-hardware
.md
12_8
By default, Hugging Face classes like [`TextGenerationPipeline`] or [`AutoModelForCausalLM`] will load the model in `float32` precision. This means that it will need 4 bytes (32 bits) per parameter, so an "8B" model with 8 billion parameters will need ~32GB of memory. However, this can be wasteful! Most modern language...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#memory-considerations
#memory-considerations
.md
12_9
<Tip> For a more extensive guide on language model performance and optimization, check out [LLM Inference Optimization](./llm_optims) . </Tip> As a general rule, larger chat models will be slower in addition to requiring more memory. It's possible to be more concrete about this, though: Generating text from a cha...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/conversations.md
https://huggingface.co/docs/transformers/en/conversations/#performance-considerations
#performance-considerations
.md
12_10
<!--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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/
.md
13_0
In [What 🤗 Transformers can do](task_summary), you learned about natural language processing (NLP), speech and audio, computer vision tasks, and some important applications of them. This page will look closely at how models solve these tasks and explain what's happening under the hood. There are many ways to solve a g...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#how--transformers-solve-tasks
#how--transformers-solve-tasks
.md
13_1
[Wav2Vec2](model_doc/wav2vec2) is a self-supervised model pretrained on unlabeled speech data and finetuned on labeled data for audio classification and automatic speech recognition. <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/wav2vec2_arch...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#speech-and-audio
#speech-and-audio
.md
13_2
To use the pretrained model for audio classification, add a sequence classification head on top of the base Wav2Vec2 model. The classification head is a linear layer that accepts the encoder's hidden states. The hidden states represent the learned features from each audio frame which can have varying lengths. To create...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#audio-classification
#audio-classification
.md
13_3
To use the pretrained model for automatic speech recognition, add a language modeling head on top of the base Wav2Vec2 model for [connectionist temporal classification (CTC)](glossary#connectionist-temporal-classification-ctc). The language modeling head is a linear layer that accepts the encoder's hidden states and tr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#automatic-speech-recognition
#automatic-speech-recognition
.md
13_4
There are two ways to approach computer vision tasks: 1. Split an image into a sequence of patches and process them in parallel with a Transformer. 2. Use a modern CNN, like [ConvNeXT](model_doc/convnext), which relies on convolutional layers but adopts modern network designs. <Tip> A third approach mixes Transfo...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#computer-vision
#computer-vision
.md
13_5
ViT and ConvNeXT can both be used for image classification; the main difference is that ViT uses an attention mechanism while ConvNeXT uses convolutions.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#image-classification
#image-classification
.md
13_6
[ViT](model_doc/vit) replaces convolutions entirely with a pure Transformer architecture. If you're familiar with the original Transformer, then you're already most of the way toward understanding ViT. <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#transformer
#transformer
.md
13_7
<Tip> This section briefly explains convolutions, but it'd be helpful to have a prior understanding of how they change an image's shape and size. If you're unfamiliar with convolutions, check out the [Convolution Neural Networks chapter](https://github.com/fastai/fastbook/blob/master/13_convolutions.ipynb) from the f...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#cnn
#cnn
.md
13_8
[DETR](model_doc/detr), *DEtection TRansformer*, is an end-to-end object detection model that combines a CNN with a Transformer encoder-decoder. <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/detr_architecture.png"/> </div> 1. A pretrained C...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#object-detection
#object-detection
.md
13_9
[Mask2Former](model_doc/mask2former) is a universal architecture for solving all types of image segmentation tasks. Traditional segmentation models are typically tailored towards a particular subtask of image segmentation, like instance, semantic or panoptic segmentation. Mask2Former frames each of those tasks as a *ma...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#image-segmentation
#image-segmentation
.md
13_10
[GLPN](model_doc/glpn), *Global-Local Path Network*, is a Transformer for depth estimation that combines a [SegFormer](model_doc/segformer) encoder with a lightweight decoder. <div class="flex justify-center"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/glpn_architecture.jp...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#depth-estimation
#depth-estimation
.md
13_11
The Transformer was initially designed for machine translation, and since then, it has practically become the default architecture for solving all NLP tasks. Some tasks lend themselves to the Transformer's encoder structure, while others are better suited for the decoder. Still, other tasks make use of both the Transfo...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#natural-language-processing
#natural-language-processing
.md
13_12
[BERT](model_doc/bert) is an encoder-only model and is the first model to effectively implement deep bidirectionality to learn richer representations of the text by attending to words on both sides. 1. BERT uses [WordPiece](tokenizer_summary#wordpiece) tokenization to generate a token embedding of the text. To tell t...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#text-classification
#text-classification
.md
13_13
To use BERT for token classification tasks like named entity recognition (NER), add a token classification head on top of the base BERT model. The token classification head is a linear layer that accepts the final hidden states and performs a linear transformation to convert them into logits. The cross-entropy loss is ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#token-classification
#token-classification
.md
13_14
To use BERT for question answering, add a span classification head on top of the base BERT model. This linear layer accepts the final hidden states and performs a linear transformation to compute the `span` start and end logits corresponding to the answer. The cross-entropy loss is calculated between the logits and the...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#question-answering
#question-answering
.md
13_15
[GPT-2](model_doc/gpt2) is a decoder-only model pretrained on a large amount of text. It can generate convincing (though not always true!) text given a prompt and complete other NLP tasks like question answering despite not being explicitly trained to. <div class="flex justify-center"> <img src="https://huggingface.c...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#text-generation
#text-generation
.md
13_16
Encoder-decoder models like [BART](model_doc/bart) and [T5](model_doc/t5) are designed for the sequence-to-sequence pattern of a summarization task. We'll explain how BART works in this section, and then you can try finetuning T5 at the end. <div class="flex justify-center"> <img src="https://huggingface.co/datasets/...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#summarization
#summarization
.md
13_17
Translation is another example of a sequence-to-sequence task, which means you can use an encoder-decoder model like [BART](model_doc/bart) or [T5](model_doc/t5) to do it. We'll explain how BART works in this section, and then you can try finetuning T5 at the end. BART adapts to translation by adding a separate rando...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/tasks_explained.md
https://huggingface.co/docs/transformers/en/tasks_explained/#translation
#translation
.md
13_18
<!--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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md
https://huggingface.co/docs/transformers/en/benchmarks/
.md
14_0
<Tip warning={true}> Hugging Face's Benchmarking tools are deprecated and it is advised to use external Benchmarking libraries to measure the speed and memory complexity of Transformer models. </Tip> [[open-in-colab]] Let's take a look at how 🤗 Transformers models can be benchmarked, best practices, and alread...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md
https://huggingface.co/docs/transformers/en/benchmarks/#benchmarks
#benchmarks
.md
14_1
The classes [`PyTorchBenchmark`] and [`TensorFlowBenchmark`] allow to flexibly benchmark 🤗 Transformers models. The benchmark classes allow us to measure the _peak memory usage_ and _required time_ for both _inference_ and _training_. <Tip> Here, _inference_ is defined by a single forward pass, and _training_ is d...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md
https://huggingface.co/docs/transformers/en/benchmarks/#how-to-benchmark--transformers-models
#how-to-benchmark--transformers-models
.md
14_2
This section lists a couple of best practices one should be aware of when benchmarking a model. - Currently, only single device benchmarking is supported. When benchmarking on GPU, it is recommended that the user specifies on which device the code should be run by setting the `CUDA_VISIBLE_DEVICES` environment variab...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md
https://huggingface.co/docs/transformers/en/benchmarks/#benchmark-best-practices
#benchmark-best-practices
.md
14_3
Previously all available core models (10 at the time) have been benchmarked for _inference time_, across many different settings: using PyTorch, with and without TorchScript, using TensorFlow, with and without XLA. All of those tests were done across CPUs (except for TensorFlow XLA) and GPUs. The approach is detailed...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/benchmarks.md
https://huggingface.co/docs/transformers/en/benchmarks/#sharing-your-benchmark
#sharing-your-benchmark
.md
14_4
<!--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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/
.md
15_0
Text generation is essential to many NLP tasks, such as open-ended text generation, summarization, translation, and more. It also plays a role in a variety of mixed-modality applications that have text as an output like speech-to-text and vision-to-text. Some of the models that can generate text include GPT2, XLNet, Op...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#text-generation-strategies
#text-generation-strategies
.md
15_1
A decoding strategy for a model is defined in its generation configuration. When using pre-trained models for inference within a [`pipeline`], the models call the `PreTrainedModel.generate()` method that applies a default generation configuration under the hood. The default configuration is also used when no custom con...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#default-text-generation-configuration
#default-text-generation-configuration
.md
15_2
You can override any `generation_config` by passing the parameters and their values directly to the [`generate`] method: ```python >>> my_model.generate(**inputs, num_beams=4, do_sample=True) # doctest: +SKIP ``` Even if the default decoding strategy mostly works for your task, you can still tweak a few things. So...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#customize-text-generation
#customize-text-generation
.md
15_3
If you would like to share your fine-tuned model with a specific generation configuration, you can: * Create a [`GenerationConfig`] class instance * Specify the decoding strategy parameters * Save your generation configuration with [`GenerationConfig.save_pretrained`], making sure to leave its `config_file_name` argume...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#save-a-custom-decoding-strategy-with-your-model
#save-a-custom-decoding-strategy-with-your-model
.md
15_4
The `generate()` supports streaming, through its `streamer` input. The `streamer` input is compatible with any instance from a class that has the following methods: `put()` and `end()`. Internally, `put()` is used to push new tokens and `end()` is used to flag the end of text generation. <Tip warning={true}> The AP...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#streaming
#streaming
.md
15_5
The `generate()` supports watermarking the generated text by randomly marking a portion of tokens as "green". When generating the "green" will have a small 'bias' value added to their logits, thus having a higher chance to be generated. The watermarked text can be detected by calculating the proportion of "green" token...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#watermarking
#watermarking
.md
15_6
Certain combinations of the `generate()` parameters, and ultimately `generation_config`, can be used to enable specific decoding strategies. If you are new to this concept, we recommend reading [this blog post that illustrates how common decoding strategies work](https://huggingface.co/blog/how-to-generate). Here, we...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#decoding-strategies
#decoding-strategies
.md
15_7
[`generate`] uses greedy search decoding by default so you don't have to pass any parameters to enable it. This means the parameters `num_beams` is set to 1 and `do_sample=False`. ```python >>> from transformers import AutoModelForCausalLM, AutoTokenizer >>> prompt = "I look forward to" >>> checkpoint = "distilbert/...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#greedy-search
#greedy-search
.md
15_8
The contrastive search decoding strategy was proposed in the 2022 paper [A Contrastive Framework for Neural Text Generation](https://arxiv.org/abs/2202.06417). It demonstrates superior results for generating non-repetitive yet coherent long outputs. To learn how contrastive search works, check out [this blog post](http...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#contrastive-search
#contrastive-search
.md
15_9
As opposed to greedy search that always chooses a token with the highest probability as the next token, multinomial sampling (also called ancestral sampling) randomly selects the next token based on the probability distribution over the entire vocabulary given by the model. Every token with a non-zero probability has a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#multinomial-sampling
#multinomial-sampling
.md
15_10
Unlike greedy search, beam-search decoding keeps several hypotheses at each time step and eventually chooses the hypothesis that has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability sequences that start with lower probability initial tokens and would've bee...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-decoding
#beam-search-decoding
.md
15_11
As the name implies, this decoding strategy combines beam search with multinomial sampling. You need to specify the `num_beams` greater than 1, and set `do_sample=True` to use this decoding strategy. ```python >>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, set_seed >>> set_seed(0) # For reproduci...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#beam-search-multinomial-sampling
#beam-search-multinomial-sampling
.md
15_12
The diverse beam search decoding strategy is an extension of the beam search strategy that allows for generating a more diverse set of beam sequences to choose from. To learn how it works, refer to [Diverse Beam Search: Decoding Diverse Solutions from Neural Sequence Models](https://arxiv.org/pdf/1610.02424.pdf). This ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#diverse-beam-search-decoding
#diverse-beam-search-decoding
.md
15_13
Speculative decoding (also known as assisted decoding) is a modification of the decoding strategies above, that uses an assistant model (ideally a much smaller one), to generate a few candidate tokens. The main model then validates the candidate tokens in a single forward pass, which speeds up the decoding process. If ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#speculative-decoding
#speculative-decoding
.md
15_14
Universal Assisted Decoding (UAD) adds support for main and assistant models with different tokenizers. To use it, simply pass the tokenizers using the `tokenizer` and `assistant_tokenizer` arguments (see below). Internally, the main model input tokens are re-encoded into assistant model tokens, then candidate tokens a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#universal-assisted-decoding
#universal-assisted-decoding
.md
15_15
Alternatively, you can also set the `prompt_lookup_num_tokens` to trigger n-gram based assisted decoding, as opposed to model based assisted decoding. You can read more about it [here](https://twitter.com/joao_gante/status/1747322413006643259).
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#prompt-lookup
#prompt-lookup
.md
15_16
An LLM can be trained to also use its language modeling head with earlier hidden states as input, effectively skipping layers to yield a lower-quality output -- a technique called early exiting. We use the lower-quality early exit output as an assistant output, and apply self-speculation to fix the output using the rem...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#self-speculative-decoding
#self-speculative-decoding
.md
15_17
**D**ecoding by C**o**ntrasting **La**yers (DoLa) is a contrastive decoding strategy to improve the factuality and reduce the hallucinations of LLMs, as described in this paper of ICLR 2024 [DoLa: Decoding by Contrasting Layers Improves Factuality in Large Language Models](https://arxiv.org/abs/2309.03883). DoLa is a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#dola-decoding
#dola-decoding
.md
15_18
`dola_layers` stands for the candidate layers in premature layer selection, as described in the DoLa paper. The selected premature layer will be contrasted with the final layer. Setting `dola_layers` to `'low'` or `'high'` will select the lower or higher part of the layers to contrast, respectively. - For `N`-layer m...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/generation_strategies.md
https://huggingface.co/docs/transformers/en/generation_strategies/#understanding-the-dolalayers-argument
#understanding-the-dolalayers-argument
.md
15_19
<!--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 agr...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/
.md
16_0
This glossary defines general machine learning and 🤗 Transformers terms to help you better understand the documentation.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#glossary
#glossary
.md
16_1
The attention mask is an optional argument used when batching sequences together. <Youtube id="M6adb1j2jPI"/> This argument indicates to the model which tokens should be attended to, and which should not. For example, consider these two sequences: ```python >>> from transformers import BertTokenizer >>> tokeni...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#attention-mask
#attention-mask
.md
16_2
See [encoder models](#encoder-models) and [masked language modeling](#masked-language-modeling-mlm)
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#autoencoding-models
#autoencoding-models
.md
16_3
See [causal language modeling](#causal-language-modeling) and [decoder models](#decoder-models)
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#autoregressive-models
#autoregressive-models
.md
16_4
The backbone is the network (embeddings and layers) that outputs the raw hidden states or features. It is usually connected to a [head](#head) which accepts the features as its input to make a prediction. For example, [`ViTModel`] is a backbone without a specific head on top. Other models can also use [`VitModel`] as a...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#backbone
#backbone
.md
16_5
A pretraining task where the model reads the texts in order and has to predict the next word. It's usually done by reading the whole sentence but using a mask inside the model to hide the future tokens at a certain timestep.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#causal-language-modeling
#causal-language-modeling
.md
16_6
Color images are made up of some combination of values in three channels: red, green, and blue (RGB) and grayscale images only have one channel. In 🤗 Transformers, the channel can be the first or last dimension of an image's tensor: [`n_channels`, `height`, `width`] or [`height`, `width`, `n_channels`].
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#channel
#channel
.md
16_7
An algorithm which allows a model to learn without knowing exactly how the input and output are aligned; CTC calculates the distribution of all possible outputs for a given input and chooses the most likely output from it. CTC is commonly used in speech recognition tasks because speech doesn't always cleanly align with...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#connectionist-temporal-classification-ctc
#connectionist-temporal-classification-ctc
.md
16_8
A type of layer in a neural network where the input matrix is multiplied element-wise by a smaller matrix (kernel or filter) and the values are summed up in a new matrix. This is known as a convolutional operation which is repeated over the entire input matrix. Each operation is applied to a different segment of the in...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#convolution
#convolution
.md
16_9
Parallelism technique for training on multiple GPUs where the same setup is replicated multiple times, with each instance receiving a distinct data slice. The processing is done in parallel and all setups are synchronized at the end of each training step. Learn more about how DataParallel works [here](perf_train_gpu_...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#dataparallel-dp
#dataparallel-dp
.md
16_10
This input is specific to encoder-decoder models, and contains the input IDs that will be fed to the decoder. These inputs should be used for sequence to sequence tasks, such as translation or summarization, and are usually built in a way specific to each model. Most encoder-decoder models (BART, T5) create their `de...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#decoder-input-ids
#decoder-input-ids
.md
16_11
Also referred to as autoregressive models, decoder models involve a pretraining task (called causal language modeling) where the model reads the texts in order and has to predict the next word. It's usually done by reading the whole sentence with a mask to hide future tokens at a certain timestep. <Youtube id="d_ixlC...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#decoder-models
#decoder-models
.md
16_12
Machine learning algorithms which use neural networks with several layers.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#deep-learning-dl
#deep-learning-dl
.md
16_13
Also known as autoencoding models, encoder models take an input (such as text or images) and transform them into a condensed numerical representation called an embedding. Oftentimes, encoder models are pretrained using techniques like [masked language modeling](#masked-language-modeling-mlm), which masks parts of the i...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#encoder-models
#encoder-models
.md
16_14
The process of selecting and transforming raw data into a set of features that are more informative and useful for machine learning algorithms. Some examples of feature extraction include transforming raw text into word embeddings and extracting important features such as edges or shapes from image/video data.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#feature-extraction
#feature-extraction
.md
16_15
In each residual attention block in transformers the self-attention layer is usually followed by 2 feed forward layers. The intermediate embedding size of the feed forward layers is often bigger than the hidden size of the model (e.g., for `google-bert/bert-base-uncased`). For an input of size `[batch_size, sequence_...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#feed-forward-chunking
#feed-forward-chunking
.md
16_16
Finetuning is a form of transfer learning which involves taking a pretrained model, freezing its weights, and replacing the output layer with a newly added [model head](#head). The model head is trained on your target dataset. See the [Fine-tune a pretrained model](https://huggingface.co/docs/transformers/training) t...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#finetuned-models
#finetuned-models
.md
16_17
The model head refers to the last layer of a neural network that accepts the raw hidden states and projects them onto a different dimension. There is a different model head for each task. For example: * [`GPT2ForSequenceClassification`] is a sequence classification head - a linear layer - on top of the base [`GPT2Mod...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#head
#head
.md
16_18
Vision-based Transformers models split an image into smaller patches which are linearly embedded, and then passed as a sequence to the model. You can find the `patch_size` - or resolution - of the model in its configuration.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#image-patch
#image-patch
.md
16_19
Inference is the process of evaluating a model on new data after training is complete. See the [Pipeline for inference](https://huggingface.co/docs/transformers/pipeline_tutorial) tutorial to learn how to perform inference with 🤗 Transformers.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#inference
#inference
.md
16_20
The input ids are often the only required parameters to be passed to the model as input. They are token indices, numerical representations of tokens building the sequences that will be used as input by the model. <Youtube id="VFp38yj8h3A"/> Each tokenizer works differently but the underlying mechanism remains the s...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#input-ids
#input-ids
.md
16_21
The labels are an optional argument which can be passed in order for the model to compute the loss itself. These labels should be the expected prediction of the model: it will use the standard loss in order to compute the loss between its predictions and the expected value (the label). These labels are different acco...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#labels
#labels
.md
16_22
A generic term that refers to transformer language models (GPT-3, BLOOM, OPT) that were trained on a large quantity of data. These models also tend to have a large number of learnable parameters (e.g. 175 billion for GPT-3).
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#large-language-models-llm
#large-language-models-llm
.md
16_23
A pretraining task where the model sees a corrupted version of the texts, usually done by masking some tokens randomly, and has to predict the original text.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#masked-language-modeling-mlm
#masked-language-modeling-mlm
.md
16_24
A task that combines texts with another kind of inputs (for instance images).
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#multimodal
#multimodal
.md
16_25
All tasks related to generating text (for instance, [Write With Transformers](https://transformer.huggingface.co/), translation).
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#natural-language-generation-nlg
#natural-language-generation-nlg
.md
16_26
A generic way to say "deal with texts".
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#natural-language-processing-nlp
#natural-language-processing-nlp
.md
16_27
All tasks related to understanding what is in a text (for instance classifying the whole text, individual words).
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#natural-language-understanding-nlu
#natural-language-understanding-nlu
.md
16_28
A pipeline in 🤗 Transformers is an abstraction referring to a series of steps that are executed in a specific order to preprocess and transform data and return a prediction from a model. Some example stages found in a pipeline might be data preprocessing, feature extraction, and normalization. For more details, see ...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#pipeline
#pipeline
.md
16_29
Parallelism technique in which the model is split up vertically (layer-level) across multiple GPUs, so that only one or several layers of the model are placed on a single GPU. Each GPU processes in parallel different stages of the pipeline and working on a small chunk of the batch. Learn more about how PipelineParallel...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#pipelineparallel-pp
#pipelineparallel-pp
.md
16_30
A tensor of the numerical representations of an image that is passed to a model. The pixel values have a shape of [`batch_size`, `num_channels`, `height`, `width`], and are generated from an image processor.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#pixel-values
#pixel-values
.md
16_31
An operation that reduces a matrix into a smaller matrix, either by taking the maximum or average of the pooled dimension(s). Pooling layers are commonly found between convolutional layers to downsample the feature representation.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#pooling
#pooling
.md
16_32
Contrary to RNNs that have the position of each token embedded within them, transformers are unaware of the position of each token. Therefore, the position IDs (`position_ids`) are used by the model to identify each token's position in the list of tokens. They are an optional parameter. If no `position_ids` are passe...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#position-ids
#position-ids
.md
16_33
The task of preparing raw data into a format that can be easily consumed by machine learning models. For example, text is typically preprocessed by tokenization. To gain a better idea of what preprocessing looks like for other input types, check out the [Preprocess](https://huggingface.co/docs/transformers/preprocessin...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#preprocessing
#preprocessing
.md
16_34
A model that has been pretrained on some data (for instance all of Wikipedia). Pretraining methods involve a self-supervised objective, which can be reading the text and trying to predict the next word (see [causal language modeling](#causal-language-modeling)) or masking some words and trying to predict them (see [mas...
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#pretrained-model
#pretrained-model
.md
16_35
A type of model that uses a loop over a layer to process texts.
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/glossary.md
https://huggingface.co/docs/transformers/en/glossary/#recurrent-neural-network-rnn
#recurrent-neural-network-rnn
.md
16_36