vector listlengths 1.02k 1.02k | text stringlengths 2 11.8k |
|---|---|
[
0.03440274,
-0.0065460363,
-0.014569977,
0.035786923,
-0.0018942413,
0.0030188907,
-0.01575951,
-0.0075769653,
-0.018441366,
0.033306926,
0.004520226,
0.029759955,
0.047119927,
-0.030336697,
-0.021599036,
-0.006203595,
0.00058485375,
-0.03944924,
-0.04737946,
-0.03356646,
-0.... |
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 versions are available, v1.1 and v2.0. The first version
(v1.1) was released together with the paper SQuAD: 100,000+ Questions for Machine Comprehension of Text. The second version (v2.0) was released alongside the paper Know What You Don't
Know: Unanswerable Questions for SQuAD.
This library hosts a processor for each of the two versions:
Processors
Those processors are: |
[
0.008498549,
-0.0037075083,
0.0041383104,
0.042714674,
-0.021970904,
-0.04386348,
-0.0035965443,
-0.015391381,
0.00605081,
0.050756313,
-0.036030713,
0.028694026,
0.050312456,
-0.0058908914,
-0.008707423,
0.024359897,
-0.007049488,
-0.07195699,
-0.05717918,
-0.0115468,
0.0169... | [~data.processors.utils.SquadV1Processor]
[~data.processors.utils.SquadV2Processor] |
[
0.03294001,
-0.010776216,
0.024822863,
0.009339878,
-0.022613112,
0.0016140386,
-0.027857587,
-0.018517708,
-0.015276741,
0.0720084,
-0.028697293,
0.043399498,
0.04843773,
-0.019033317,
0.0023036648,
0.041779015,
0.012323041,
-0.056864243,
-0.07742965,
-0.047170807,
0.0111592... |
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.processors.squad.squad_convert_examples_to_features
These processors as well as the aforementioned method can be used with files containing the data as well as with the
tensorflow_datasets package. Examples are given below.
Example usage
Here is an example using the processors as well as the conversion method using data files:
thon
Loading a V2 processor
processor = SquadV2Processor()
examples = processor.get_dev_examples(squad_v2_data_dir)
Loading a V1 processor
processor = SquadV1Processor()
examples = processor.get_dev_examples(squad_v1_data_dir)
features = squad_convert_examples_to_features(
examples=examples,
tokenizer=tokenizer,
max_seq_length=max_seq_length,
doc_stride=args.doc_stride,
max_query_length=max_query_length,
is_training=not evaluate,
) |
[
0.032275215,
0.018963095,
0.0040554875,
0.023854982,
-0.036998417,
-0.04211522,
-0.028592242,
-0.018330522,
0.023854982,
0.050212137,
-0.019651895,
0.038825847,
0.056931455,
-0.009509661,
-0.04087819,
0.015280121,
-0.007387032,
-0.07697695,
-0.051196136,
-0.03525533,
-0.00740... | Another example using these processors is given in the run_squad.py script. |
[
0.05061699,
0.01375034,
-0.02453561,
0.013518474,
-0.012534802,
-0.0012164167,
-0.0060601267,
-0.0072510736,
0.0036466154,
0.056912497,
-0.007658595,
-0.0038222712,
0.03364161,
-0.0410051,
0.0055296463,
0.03968417,
-0.013420107,
-0.012541828,
-0.04673851,
-0.028863769,
-0.011... |
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 customize how a model is trained. Together, these two classes provide a complete training API.
[Seq2SeqTrainer] and [Seq2SeqTrainingArguments] inherit from the [Trainer] and [TrainingArgument] classes and they're adapted for training models for sequence-to-sequence tasks such as summarization or translation. |
[
0.022746451,
-0.0027228717,
-0.0008168615,
0.029043965,
-0.018613271,
-0.016393084,
0.0047336076,
0.013949482,
0.002436621,
0.06808576,
-0.018375894,
0.02837372,
0.054736704,
-0.021559559,
-0.01333509,
0.033009585,
0.012064416,
-0.03644459,
-0.047531568,
-0.04937474,
-0.01704... | 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=tokenizer,
max_seq_length=max_seq_length,
doc_stride=args.doc_stride,
max_query_length=max_query_length,
is_training=not evaluate,
) |
[
0.007879123,
-0.0052069533,
-0.018341115,
-0.013230333,
-0.04687632,
-0.030857038,
0.035802957,
0.007308969,
-0.0007229972,
0.05498213,
0.038083576,
-0.012206802,
0.007164713,
-0.010977192,
-0.011842728,
0.03343991,
0.00842867,
-0.03517098,
-0.052481692,
-0.020388177,
0.03819... | 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 indicate their name to the [Trainer]) but none of them should be named "label" |
[
0.02951457,
0.017961642,
-0.011790021,
0.012170808,
-0.011998377,
-0.024370356,
0.0009825018,
-0.0006493133,
0.0022577783,
0.028796103,
0.03850976,
0.016452864,
0.032790773,
-0.038825884,
0.012156439,
0.012494118,
0.0035617936,
-0.012321686,
-0.08075554,
0.004016223,
0.001654... | 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: |
[
0.01777731,
0.02215483,
0.017713685,
0.009028634,
-0.059860036,
-0.040390253,
0.0075779445,
0.018998945,
0.0028711567,
0.070040315,
0.00020758224,
0.0057295877,
0.011096504,
-0.031915173,
0.00723436,
0.019660663,
-0.011331922,
-0.016021213,
-0.044055153,
-0.008455994,
0.00013... | Trainer[[api-reference]]
[[autodoc]] Trainer
- all
Seq2SeqTrainer
[[autodoc]] Seq2SeqTrainer
- evaluate
- predict
TrainingArguments
[[autodoc]] TrainingArguments
- all
Seq2SeqTrainingArguments
[[autodoc]] Seq2SeqTrainingArguments
- all |
[
0.0072157993,
0.012000228,
-0.019421129,
-0.007596167,
-0.021479588,
-0.004195232,
-0.024179453,
-0.0074097123,
-0.043048676,
0.03845443,
-0.008524711,
0.010187888,
0.035799313,
-0.0642001,
0.03967757,
0.047583256,
0.00019764205,
-0.010366885,
-0.092541225,
0.013849859,
0.014... |
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 offloading to a CPU or NVMe. DeepSpeed is integrated with the [Trainer] class and most of the setup is automatically taken care of for you.
However, if you want to use DeepSpeed without the [Trainer], Transformers provides a [HfDeepSpeedConfig] class. |
[
0.00037785072,
-0.0010249339,
-0.01990998,
0.021686649,
-0.06824667,
0.0133884745,
0.00014849645,
0.011435548,
0.01686426,
0.076537795,
-0.013430776,
0.020318896,
0.03265688,
-0.058827505,
0.032572277,
0.051241405,
0.006288846,
-0.030823806,
-0.08375728,
0.010244051,
0.025014... | Learn more about using DeepSpeed with [Trainer] in the DeepSpeed guide.
HfDeepSpeedConfig
[[autodoc]] integrations.HfDeepSpeedConfig
- all |
[
0.012287332,
-0.00963539,
0.006478842,
-0.04714564,
-0.018887721,
0.023440221,
0.038895153,
-0.01604425,
-0.008530414,
0.023440221,
0.0427552,
-0.015720123,
0.0069392486,
-0.026858281,
-0.0010837972,
0.015410731,
-0.021539664,
0.021465998,
-0.08415496,
-0.0061915484,
0.003926... |
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 attributes. Common attributes present in all config classes are:
hidden_size, num_attention_heads, and num_hidden_layers. Text models further implement:
vocab_size.
PretrainedConfig
[[autodoc]] PretrainedConfig
- push_to_hub
- all |
[
0.009106601,
0.0033454313,
-0.009992371,
-0.028930295,
-0.018593863,
0.0013872193,
0.023630312,
-0.029823385,
-0.011222202,
0.038329713,
0.008586851,
-0.022107664,
0.022444405,
-0.018432815,
-0.016017076,
0.021273136,
-0.03443525,
-0.030189406,
-0.03879822,
0.0293988,
-0.0195... | 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
import transformers
transformers.logging.set_verbosity_info() |
[
0.028973203,
0.02179464,
-0.022657793,
-0.030757055,
-0.014357129,
-0.004966732,
0.01691782,
-0.016630102,
-0.011249774,
0.038065095,
0.016443085,
-0.021147273,
0.01726308,
-0.026024094,
-0.03228196,
0.018600969,
0.0048768204,
-0.054263618,
-0.05702571,
0.008746628,
-0.012105... | 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") |
[
-0.00894131,
-0.031371985,
0.00055929256,
0.00488713,
0.010054367,
-0.017086526,
0.030310525,
-0.0048429025,
-0.00061273406,
0.070292115,
0.004009953,
0.01984337,
0.007953565,
-0.022025255,
-0.04546579,
0.0051598656,
-0.063569546,
-0.08544738,
-0.0640413,
-0.009759517,
-0.009... |
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
[DataCollatorForLanguageModeling]) also apply some random data augmentation (like random masking)
on the formed batch.
Examples of use can be found in the example scripts or example notebooks.
Default data collator
[[autodoc]] data.data_collator.default_data_collator
DefaultDataCollator
[[autodoc]] data.data_collator.DefaultDataCollator
DataCollatorWithPadding
[[autodoc]] data.data_collator.DataCollatorWithPadding
DataCollatorForTokenClassification
[[autodoc]] data.data_collator.DataCollatorForTokenClassification
DataCollatorForSeq2Seq
[[autodoc]] data.data_collator.DataCollatorForSeq2Seq
DataCollatorForLanguageModeling
[[autodoc]] data.data_collator.DataCollatorForLanguageModeling
- numpy_mask_tokens
- tf_mask_tokens
- torch_mask_tokens
DataCollatorForWholeWordMask
[[autodoc]] data.data_collator.DataCollatorForWholeWordMask
- numpy_mask_tokens
- tf_mask_tokens
- torch_mask_tokens
DataCollatorForPermutationLanguageModeling
[[autodoc]] data.data_collator.DataCollatorForPermutationLanguageModeling
- numpy_mask_tokens
- tf_mask_tokens
- torch_mask_tokens |
[
0.030206883,
-0.005493151,
-0.00909111,
0.011501852,
-0.021391703,
-0.022669686,
0.02875463,
-0.0057364036,
-0.017615842,
0.054459527,
-0.0035144547,
0.039936986,
0.030264974,
-0.011530897,
-0.01822579,
0.008960407,
-0.032849986,
-0.05533088,
-0.034825053,
0.019576384,
-0.012... | 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 corresponding int values in parenthesis) are: |
[
0.009189308,
0.009900468,
0.0017639567,
-0.026145604,
-0.00041462568,
-0.033243265,
0.037984334,
-0.023091797,
-0.009426362,
0.05717172,
0.020818872,
0.011106652,
0.026968319,
-0.038988322,
-0.016119637,
-0.0006340309,
-0.026368713,
-0.031709388,
-0.049697563,
0.025057947,
0.... | 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 by the library.
transformers.logging.INFO (int value, 20): reports error, warnings and basic information.
transformers.logging.DEBUG (int value, 10): report all information. |
[
0.001515083,
-0.0029222164,
-0.026407897,
0.003291518,
-0.021271765,
-0.003920277,
-0.00061218825,
-0.0182719,
0.013143345,
0.0730876,
-0.015385668,
-0.0042422325,
0.028589617,
-0.004102087,
0.02152933,
0.024544345,
-0.013673624,
-0.03851341,
-0.059027635,
0.035119623,
0.0227... |
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 warnings,
which allows further classification of warnings in specific buckets, e.g., FutureWarning for a feature or path
that has already been deprecated and DeprecationWarning to indicate an upcoming deprecation.
We use both in the transformers library. We leverage and adapt logging's captureWarning method to allow
management of these warning messages by the verbosity setters above.
What does that mean for developers of the library? We should respect the following heuristic:
- warnings should be favored for developers of the library and libraries dependent on transformers
- logging should be used for end-users of the library using it in every-day projects
See reference of the captureWarnings method below.
[[autodoc]] logging.captureWarnings
Base setters
[[autodoc]] logging.set_verbosity_error
[[autodoc]] logging.set_verbosity_warning
[[autodoc]] logging.set_verbosity_info
[[autodoc]] logging.set_verbosity_debug
Other functions
[[autodoc]] logging.get_verbosity
[[autodoc]] logging.set_verbosity
[[autodoc]] logging.get_logger
[[autodoc]] logging.enable_default_handler
[[autodoc]] logging.disable_default_handler
[[autodoc]] logging.enable_explicit_format
[[autodoc]] logging.reset_format
[[autodoc]] logging.enable_progress_bar
[[autodoc]] logging.disable_progress_bar |
[
-0.00037151284,
0.000013529775,
-0.0024399178,
-0.004579266,
-0.022362376,
-0.009802104,
0.04220704,
0.008224998,
-0.029279012,
0.04684642,
0.02253211,
-0.028996123,
0.03196646,
-0.008939293,
-0.04319715,
0.015360873,
-0.011930844,
-0.051287778,
-0.07026963,
0.02936388,
-0.00... | 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
TRANSFORMERS_NO_ADVISORY_WARNINGS to a true value, like 1. This will disable any warning that is logged using
[logger.warning_advice]. For example: |
[
0.00685702,
0.018337876,
-0.045579854,
0.0035376637,
0.018481027,
-0.028530356,
-0.024851328,
-0.00321557,
0.005797689,
0.05353915,
0.0070681702,
0.058205932,
0.019855294,
-0.05766195,
-0.011394964,
0.004870774,
-0.012812177,
-0.036446705,
-0.047669888,
0.028587617,
-0.009727... |
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).
Callbacks are "read only" pieces of code, apart from the [TrainerControl] object they return, they
cannot change anything in the training loop. For customizations that require changes in the training loop, you should
subclass [Trainer] and override the methods you need (see trainer for examples).
By default, TrainingArguments.report_to is set to "all", so a [Trainer] will use the following callbacks. |
[
0.028390376,
-0.016746398,
-0.008889255,
-0.03564424,
0.002892824,
-0.030905243,
-0.027300116,
-0.0048952685,
-0.01286507,
0.0469248,
0.0027837977,
0.020264303,
0.02282278,
-0.04241839,
-0.0115349535,
0.018578034,
-0.028608428,
-0.054164127,
-0.063380465,
-0.0038122765,
-0.00... |
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 converting logits to segmentation masks.
ImageProcessingMixin
[[autodoc]] image_processing_utils.ImageProcessingMixin
- from_pretrained
- save_pretrained
BatchFeature
[[autodoc]] BatchFeature
BaseImageProcessor
[[autodoc]] image_processing_utils.BaseImageProcessor |
[
-0.013841965,
0.029880086,
-0.018605458,
0.02592082,
0.012016991,
-0.0021980887,
-0.027343681,
-0.008583565,
0.01824974,
0.071328655,
-0.024064913,
0.007423624,
0.035973642,
-0.038324457,
-0.04117018,
0.01874465,
-0.017476447,
-0.017723901,
-0.038077004,
0.028983064,
0.000367... |
[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.TensorBoardCallback] if tensorboard is accessible (either through PyTorch >= 1.4
or tensorboardX).
[~integrations.WandbCallback] if wandb is installed.
[~integrations.CometCallback] if comet_ml is installed.
[~integrations.MLflowCallback] if mlflow is installed.
[~integrations.NeptuneCallback] if neptune is installed.
[~integrations.AzureMLCallback] if azureml-sdk is
installed.
[~integrations.CodeCarbonCallback] if codecarbon is
installed.
[~integrations.ClearMLCallback] if clearml is installed.
[~integrations.DagsHubCallback] if dagshub is installed.
[~integrations.FlyteCallback] if flyte is installed.
[~integrations.DVCLiveCallback] if dvclive is installed. |
[
0.004994107,
0.027314138,
-0.035098247,
-0.027453637,
-0.01092984,
0.009869639,
0.020562328,
0.004359381,
-0.020729728,
0.048852965,
0.0038257926,
0.03562835,
0.015093921,
-0.02209683,
0.0010680483,
0.042463858,
0.0011500047,
-0.054711975,
-0.055493176,
0.018581426,
-0.028960... | 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 = Trainer()
trainer.add_callback(MyCallback)
Alternatively, we can pass an instance of the callback class
trainer.add_callback(MyCallback()) |
[
-0.004029504,
0.0073770355,
-0.029918792,
0.007157044,
-0.027689548,
0.00304871,
-0.016557997,
0.0025298977,
-0.011241546,
0.053736497,
0.0037306827,
0.021867117,
0.026941579,
-0.031620055,
-0.022351097,
0.028422851,
-0.004843471,
-0.02443368,
-0.067229286,
0.03848378,
-0.024... |
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 instantiate the [Trainer], can access that
Trainer's internal state via [TrainerState], and can take some actions on the training loop via
[TrainerControl].
Available Callbacks
Here is the list of the available [TrainerCallback] in the library:
[[autodoc]] integrations.CometCallback
- setup
[[autodoc]] DefaultFlowCallback
[[autodoc]] PrinterCallback
[[autodoc]] ProgressCallback
[[autodoc]] EarlyStoppingCallback
[[autodoc]] integrations.TensorBoardCallback
[[autodoc]] integrations.WandbCallback
- setup
[[autodoc]] integrations.MLflowCallback
- setup
[[autodoc]] integrations.AzureMLCallback
[[autodoc]] integrations.CodeCarbonCallback
[[autodoc]] integrations.NeptuneCallback
[[autodoc]] integrations.ClearMLCallback
[[autodoc]] integrations.DagsHubCallback
[[autodoc]] integrations.FlyteCallback
[[autodoc]] integrations.DVCLiveCallback
- setup
TrainerCallback
[[autodoc]] TrainerCallback
Here is an example of how to register a custom callback with the PyTorch [Trainer]:
thon
class MyCallback(TrainerCallback):
"A callback that prints a message at the beginning of training"
def on_train_begin(self, args, state, control, **kwargs):
print("Starting training") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.