text
stringlengths
2
11.8k
Please note that since the gold labels are available on the test set, evaluation is performed on the test set. An example using these processors is given in the run_xnli.py script. SQuAD The Stanford Question Answering Dataset (SQuAD) is a benchmark that evaluates the performance of models on question answering. Two ...
[~data.processors.utils.SquadV1Processor] [~data.processors.utils.SquadV2Processor]
They both inherit from the abstract class [~data.processors.utils.SquadProcessor] [[autodoc]] data.processors.squad.SquadProcessor - all Additionally, the following method can be used to convert SQuAD examples into [~data.processors.utils.SquadFeatures] that can be used as model inputs. [[autodoc]] data.processor...
Using tensorflow_datasets is as easy as using a data file: thon tensorflow_datasets only handle Squad V1. tfds_examples = tfds.load("squad") examples = SquadV1Processor().get_examples_from_dataset(tfds_examples, evaluate=evaluate) features = squad_convert_examples_to_features( examples=examples, tokenizer=token...
Another example using these processors is given in the run_squad.py script.
Trainer The [Trainer] class provides an API for feature-complete training in PyTorch, and it supports distributed training on multiple GPUs/TPUs, mixed precision for NVIDIA GPUs, AMD GPUs, and torch.amp for PyTorch. [Trainer] goes hand-in-hand with the [TrainingArguments] class, which offers a wide range of options to...
The [Trainer] class is optimized for 🤗 Transformers models and can have surprising behaviors when used with other models. When using it with your own model, make sure:
your model always return tuples or subclasses of [~utils.ModelOutput] your model can compute the loss if a labels argument is provided and that loss is returned as the first element of the tuple (if your model returns tuples) your model can accept multiple label arguments (use label_names in [TrainingArguments] to in...
Trainer[[api-reference]] [[autodoc]] Trainer - all Seq2SeqTrainer [[autodoc]] Seq2SeqTrainer - evaluate - predict TrainingArguments [[autodoc]] TrainingArguments - all Seq2SeqTrainingArguments [[autodoc]] Seq2SeqTrainingArguments - all
Data Collator Data collators are objects that will form a batch by using a list of dataset elements as input. These elements are of the same type as the elements of train_dataset or eval_dataset. To be able to build batches, data collators may apply some processing (like padding). Some of them (like [DataCollatorForLa...
DeepSpeed DeepSpeed, powered by Zero Redundancy Optimizer (ZeRO), is an optimization library for training and fitting very large models onto a GPU. It is available in several ZeRO stages, where each stage progressively saves more GPU memory by partitioning the optimizer state, gradients, parameters, and enabling offlo...
Learn more about using DeepSpeed with [Trainer] in the DeepSpeed guide. HfDeepSpeedConfig [[autodoc]] integrations.HfDeepSpeedConfig - all
Configuration The base class [PretrainedConfig] implements the common methods for loading/saving a configuration either from a local file or directory, or from a pretrained model configuration provided by the library (downloaded from HuggingFace's AWS S3 repository). Each derived config class implements model specific...
Logging 🤗 Transformers has a centralized logging system, so that you can setup the verbosity of the library easily. Currently the default verbosity of the library is WARNING. To change the level of verbosity, just use one of the direct setters. For instance, here is how to change the verbosity to the INFO level. thon ...
You can also use the environment variable TRANSFORMERS_VERBOSITY to override the default verbosity. You can set it to one of the following: debug, info, warning, error, critical. For example: TRANSFORMERS_VERBOSITY=error ./myprogram.py Additionally, some warnings can be disabled by setting the environment variable TRA...
TRANSFORMERS_NO_ADVISORY_WARNINGS=1 ./myprogram.py Here is an example of how to use the same logger as the library in your own module or script: thon from transformers.utils import logging logging.set_verbosity_info() logger = logging.get_logger("transformers") logger.info("INFO") logger.warning("WARN")
All the methods of this logging module are documented below, the main ones are [logging.get_verbosity] to get the current level of verbosity in the logger and [logging.set_verbosity] to set the verbosity to the level of your choice. In order (from the least verbose to the most verbose), those levels (with their corresp...
transformers.logging.CRITICAL or transformers.logging.FATAL (int value, 50): only report the most critical errors. transformers.logging.ERROR (int value, 40): only report errors. transformers.logging.WARNING or transformers.logging.WARN (int value, 30): only reports error and warnings. This the default level used b...
By default, tqdm progress bars will be displayed during model download. [logging.disable_progress_bar] and [logging.enable_progress_bar] can be used to suppress or unsuppress this behavior. logging vs warnings Python has two logging systems that are often used in conjunction: logging, which is explained above, and wa...
Image Processor An image processor is in charge of preparing input features for vision models and post processing their outputs. This includes transformations such as resizing, normalization, and conversion to PyTorch, TensorFlow, Flax and Numpy tensors. It may also include model specific post-processing such as conve...
Callbacks Callbacks are objects that can customize the behavior of the training loop in the PyTorch [Trainer] (this feature is not yet implemented in TensorFlow) that can inspect the training loop state (for progress reporting, logging on TensorBoard or other ML platforms) and take decisions (like early stopping). Cal...
[DefaultFlowCallback] which handles the default behavior for logging, saving and evaluation. [PrinterCallback] or [ProgressCallback] to display progress and print the logs (the first one is used if you deactivate tqdm through the [TrainingArguments], otherwise it's the second one). [~integrations.TensorBoardCallb...
If a package is installed but you don't wish to use the accompanying integration, you can change TrainingArguments.report_to to a list of just those integrations you want to use (e.g. ["azure_ml", "wandb"]). The main class that implements callbacks is [TrainerCallback]. It gets the [TrainingArguments] used to instan...
trainer = Trainer( model, args, train_dataset=train_dataset, eval_dataset=eval_dataset, callbacks=[MyCallback], # We can either pass the callback class this way or an instance of it (MyCallback()) ) Another way to register a callback is to call trainer.add_callback() as follows: thon trainer = Tra...
TrainerState [[autodoc]] TrainerState TrainerControl [[autodoc]] TrainerControl
Backbone A backbone is a model used for feature extraction for higher level computer vision tasks such as object detection and image classification. Transformers provides an [AutoBackbone] class for initializing a Transformers backbone from pretrained model weights, and two utility classes:
[~utils.BackboneMixin] enables initializing a backbone from Transformers or timm and includes functions for returning the output features and indices. [~utils.BackboneConfigMixin] sets the output features and indices of the backbone configuration. timm models are loaded with the [TimmBackbone] and [TimmBackboneConfig]...
BEiT BiT ConvNet ConvNextV2 DiNAT DINOV2 FocalNet MaskFormer NAT ResNet Swin Transformer Swin Transformer v2 ViTDet AutoBackbone [[autodoc]] AutoBackbone BackboneMixin [[autodoc]] utils.BackboneMixin BackboneConfigMixin [[autodoc]] utils.BackboneConfigMixin TimmBackbone [[autodoc]] models.timm_backbone.TimmBackbone Ti...
Quantization Quantization techniques reduces memory and computational costs by representing weights and activations with lower-precision data types like 8-bit integers (int8). This enables loading larger models you normally wouldn't be able to fit into memory, and speeding up inference. Transformers supports the AWQ a...
Learn how to quantize models in the Quantization guide. AqlmConfig [[autodoc]] AqlmConfig AwqConfig [[autodoc]] AwqConfig GPTQConfig [[autodoc]] GPTQConfig BitsAndBytesConfig [[autodoc]] BitsAndBytesConfig HfQuantizer [[autodoc]] quantizers.base.HfQuantizer
Exporting 🤗 Transformers models to ONNX 🤗 Transformers provides a transformers.onnx package that enables you to convert model checkpoints to an ONNX graph by leveraging configuration objects. See the guide on exporting 🤗 Transformers models for more details. ONNX Configurations We provide three abstract classes that...
Encoder-based models inherit from [~onnx.config.OnnxConfig] Decoder-based models inherit from [~onnx.config.OnnxConfigWithPast] Encoder-decoder models inherit from [~onnx.config.OnnxSeq2SeqConfigWithPast]
OnnxConfig [[autodoc]] onnx.config.OnnxConfig OnnxConfigWithPast [[autodoc]] onnx.config.OnnxConfigWithPast OnnxSeq2SeqConfigWithPast [[autodoc]] onnx.config.OnnxSeq2SeqConfigWithPast ONNX Features Each ONNX configuration is associated with a set of features that enable you to export models for different types of topol...