vector listlengths 1.02k 1.02k | text stringlengths 2 11.8k |
|---|---|
[
0.021815518,
-0.034645792,
-0.040069316,
-0.0113462275,
0.006695084,
-0.014705574,
-0.013390168,
-0.0055112173,
0.010051058,
0.042362846,
0.0029276235,
0.009160629,
0.035050534,
-0.05177981,
-0.00097559346,
0.022409137,
0.0122231655,
-0.028979424,
-0.034322,
-0.026294647,
-0.... |
Semantic segmentation
- Semantic segmentation task guide
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
MobileViTConfig
[[autodoc]] Mobile... |
[
0.020993195,
0.00597521,
-0.028989218,
0.000918634,
-0.010482059,
-0.008003293,
-0.0072073243,
-0.04748184,
-0.02709925,
0.039253205,
0.017620327,
0.002124398,
-0.0054627378,
-0.023551922,
-0.049633496,
0.025427353,
-0.0268521,
-0.032594696,
-0.046115246,
0.030326735,
-0.0137... | XLM
Overview
The XLM model was proposed in Cross-lingual Language Model Pretraining by
Guillaume Lample, Alexis Conneau. It's a transformer pretrained using one of the following objectives:
a causal language modeling (CLM) objective (next token prediction),
a masked language modeling (MLM) objective (BERT-like), or
a... |
[
0.022359358,
0.0095399935,
-0.024574,
-0.015786417,
-0.0072330753,
-0.035576224,
0.014877846,
-0.022927215,
-0.015573471,
0.027455874,
-0.00027217195,
0.008986332,
0.010178832,
-0.041198008,
-0.020357665,
-0.010221421,
-0.0017497086,
-0.030465513,
-0.034582473,
0.0014160927,
... |
The abstract from the paper is the following:
Recent studies have demonstrated the efficiency of generative pretraining for English natural language understanding.
In this work, we extend this approach to multiple languages and show the effectiveness of cross-lingual pretraining. We
propose two methods to learn cross... |
[
0.052098993,
0.007032509,
-0.019180866,
0.03408665,
-0.023911955,
-0.041610792,
0.008607164,
-0.04357733,
0.006594313,
0.044432346,
0.009177174,
0.024880974,
0.019551372,
-0.030780585,
-0.049761947,
0.00971156,
-0.0075312685,
-0.019779377,
-0.033773143,
0.015062537,
0.0015149... | XLM has many different checkpoints, which were trained using different objectives: CLM, MLM or TLM. Make sure to
select the correct objective for your task (e.g. MLM checkpoints are not suitable for generation).
XLM has multilingual checkpoints which leverage a specific lang parameter. Check out the multi-lingual pag... |
[
0.0099919345,
-0.0010699437,
-0.026450466,
0.020303722,
-0.009449575,
-0.021708297,
-0.015047005,
-0.014671526,
-0.016187351,
0.036407635,
0.0038730048,
0.012571621,
0.009157536,
-0.04566947,
-0.032040942,
0.024336655,
-0.03704734,
-0.030316519,
-0.05918674,
-0.004620488,
-0.... | Resources
Text classification task guide
Token classification task guide
Question answering task guide
Causal language modeling task guide
Masked language modeling task guide
Multiple choice task guide
XLMConfig
[[autodoc]] XLMConfig
XLMTokenizer
[[autodoc]] XLMTokenizer
- build_inputs_with_special_tokens
- g... |
[
0.0066985874,
0.011729841,
-0.03469225,
0.008782756,
0.008117284,
-0.0018583827,
-0.027116116,
-0.042970415,
-0.029075965,
0.05197987,
0.03229363,
0.04963975,
-0.029836504,
-0.057274386,
-0.039255477,
-0.008402486,
-0.020549161,
-0.035657547,
-0.03650584,
-0.033639196,
-0.002... |
Causal language modeling (CLM) which is the traditional autoregressive training (so this model could be in the previous section as well). One of the languages is selected for each training sample, and the model input is a sentence of 256 tokens, that may span over several documents in one of those languages.
Masked l... |
[
0.0058512865,
-0.025863841,
-0.007348917,
0.014806505,
0.02743958,
-0.009393302,
0.007960195,
0.012626282,
0.014711418,
0.074059695,
0.027575418,
0.04202874,
0.05857399,
-0.011003,
-0.040670346,
0.06580065,
-0.0009449335,
-0.062268827,
-0.03697551,
-0.0012938712,
0.009135206,... | TFXLMModel
[[autodoc]] TFXLMModel
- call
TFXLMWithLMHeadModel
[[autodoc]] TFXLMWithLMHeadModel
- call
TFXLMForSequenceClassification
[[autodoc]] TFXLMForSequenceClassification
- call
TFXLMForMultipleChoice
[[autodoc]] TFXLMForMultipleChoice
- call
TFXLMForTokenClassification
[[autodoc]] TFXLMForTokenCla... |
[
0.013470109,
-0.02126788,
-0.0029563166,
0.017490834,
-0.004819456,
0.0122178625,
-0.0013673175,
0.0042204084,
0.021254342,
0.07315826,
0.024936624,
0.015202947,
0.040505093,
-0.010911465,
-0.03725602,
0.07082976,
-0.0074051754,
-0.042806517,
-0.043537557,
0.012948903,
0.0095... | XLMModel
[[autodoc]] XLMModel
- forward
XLMWithLMHeadModel
[[autodoc]] XLMWithLMHeadModel
- forward
XLMForSequenceClassification
[[autodoc]] XLMForSequenceClassification
- forward
XLMForMultipleChoice
[[autodoc]] XLMForMultipleChoice
- forward
XLMForTokenClassification
[[autodoc]] XLMForTokenClassificat... |
[
0.017573083,
0.019076427,
-0.019514296,
0.012077846,
-0.006633693,
-0.013763635,
0.00869167,
-0.011574298,
-0.017106025,
0.059316453,
0.0053857705,
-0.014026356,
0.046443146,
-0.04804866,
-0.013858506,
-0.009443343,
-0.02488547,
-0.044137046,
-0.040225428,
-0.00032292728,
0.0... |
import evaluate
from datasets import load_dataset
from transformers import AutoTokenizer, LongT5ForConditionalGeneration
dataset = load_dataset("scientific_papers", "pubmed", split="validation")
model = (
LongT5ForConditionalGeneration.from_pretrained("Stancld/longt5-tglobal-large-16384-pubmed-3k_steps")
.t... |
[
0.028797975,
0.0039170496,
-0.010168282,
0.036850903,
0.005944871,
0.012619173,
0.022991696,
-0.049630553,
-0.016645638,
0.061564058,
-0.00011665213,
0.0010120869,
-0.007505855,
-0.045720797,
-0.003069085,
-0.0345459,
-0.011838681,
-0.044553705,
-0.037784576,
-0.0014743644,
0... |
LongT5
Overview
The LongT5 model was proposed in LongT5: Efficient Text-To-Text Transformer for Long Sequences
by Mandy Guo, Joshua Ainslie, David Uthus, Santiago Ontanon, Jianmo Ni, Yun-Hsuan Sung and Yinfei Yang. It's an
encoder-decoder transformer pre-trained in a text-to-text denoising generative setting. LongT5 m... |
[
0.013859086,
-0.024933368,
-0.024774648,
0.031137852,
-0.021499258,
0.0025196697,
0.013072703,
0.011319576,
-0.00082651305,
0.061698545,
0.019233901,
0.025092088,
0.022538148,
-0.03284048,
-0.010612553,
0.004278208,
-0.006204484,
-0.023158597,
-0.07774363,
0.02893021,
0.02786... | Resources
Translation task guide
Summarization task guide
LongT5Config
[[autodoc]] LongT5Config
LongT5Model
[[autodoc]] LongT5Model
- forward
LongT5ForConditionalGeneration
[[autodoc]] LongT5ForConditionalGeneration
- forward
LongT5EncoderModel
[[autodoc]] LongT5EncoderModel
- forward
FlaxLongT5Model
[[... |
[
0.0037475894,
-0.018455943,
-0.0007491781,
-0.0013641497,
-0.07061641,
0.02651513,
0.00801162,
0.010668568,
0.021568175,
-0.011144237,
0.011905307,
0.010179309,
-0.014637004,
0.004678541,
-0.041777298,
0.017259978,
-0.03590619,
-0.019611139,
-0.029790448,
-0.0037170108,
0.005... | thon |
[
0.03286962,
0.01982387,
-0.015754161,
0.020008212,
-0.014974253,
-0.0014410592,
0.007898351,
-0.032557655,
-0.030770956,
0.038570046,
0.013322264,
0.0001585298,
0.00045775343,
-0.031791925,
-0.015016793,
-0.035308607,
-0.018802898,
-0.058308832,
-0.035960894,
-0.016179567,
0.... |
[LongT5ForConditionalGeneration] is an extension of [T5ForConditionalGeneration] exchanging the traditional
encoder self-attention layer with efficient either local attention or transient-global (tglobal) attention.
Unlike the T5 model, LongT5 does not use a task prefix. Furthermore, it uses a different pre-training ... |
[
0.00019852332,
0.01687415,
0.011593851,
-0.03485994,
0.005387186,
-0.005447756,
-0.006167473,
-0.01899767,
0.0011811191,
0.059743606,
0.0010849194,
-0.019610496,
0.035857566,
-0.01758674,
-0.01445134,
0.029700782,
-0.010467958,
-0.036057092,
-0.045007233,
0.033976328,
0.00323... | PatchTST
Overview
The PatchTST model was proposed in A Time Series is Worth 64 Words: Long-term Forecasting with Transformers by Yuqi Nie, Nam H. Nguyen, Phanwadee Sinthong and Jayant Kalagnanam.
At a high level the model vectorizes time series into patches of a given size and encodes the resulting sequence of vectors ... |
[
0.038531736,
-0.021172082,
0.014543984,
0.024649834,
0.0010604231,
-0.02588669,
0.013110685,
-0.026366882,
0.0035123103,
0.037833273,
0.029335339,
-0.012630493,
0.01986247,
-0.04283891,
-0.02403868,
-0.009749344,
0.016704846,
0.0045690956,
-0.06769246,
-0.016297411,
0.0181745... |
CPM
Overview
The CPM model was proposed in CPM: A Large-scale Generative Chinese Pre-trained Language Model by Zhengyan Zhang, Xu Han, Hao Zhou, Pei Ke, Yuxian Gu, Deming Ye, Yujia Qin,
Yusheng Su, Haozhe Ji, Jian Guan, Fanchao Qi, Xiaozhi Wang, Yanan Zheng, Guoyang Zeng, Huanqi Cao, Shengqi Chen,
Daixuan Li, Zhenbo S... |
[
0.017047701,
-0.013313171,
0.007198235,
0.038571138,
-0.0153657375,
0.014111392,
-0.0021541254,
-0.015679324,
0.036062445,
0.06226117,
0.0029630358,
-0.009792451,
0.0030895395,
-0.05242596,
-0.03802949,
0.03318315,
0.005477073,
0.004493552,
-0.053566273,
-0.002328736,
0.03782... | CPM's architecture is the same as GPT-2, except for tokenization method. Refer to GPT-2 documentation for
API reference information.
CpmTokenizer
[[autodoc]] CpmTokenizer
CpmTokenizerFast
[[autodoc]] CpmTokenizerFast |
[
-0.012676662,
-0.020928781,
-0.0057519036,
-0.00046132866,
-0.034890667,
-0.0003577382,
-0.002149063,
0.0059204577,
0.0067210887,
0.06017376,
0.0032130596,
0.016939672,
0.020956874,
-0.024636969,
-0.032559004,
0.02372397,
-0.016054764,
-0.002400138,
-0.045397196,
-0.0070687314,... | A blog post explaining PatchTST in depth can be found here. The blog can also be opened in Google Colab.
PatchTSTConfig
[[autodoc]] PatchTSTConfig
PatchTSTModel
[[autodoc]] PatchTSTModel
- forward
PatchTSTForPrediction
[[autodoc]] PatchTSTForPrediction
- forward
PatchTSTForClassification
[[autodoc]] PatchTSTFo... |
[
-0.008373018,
0.045296427,
-0.026434515,
-0.046799812,
0.00043848722,
-0.0070714764,
-0.023399906,
-0.025905548,
0.013850628,
0.044461213,
0.013620945,
-0.0030537504,
0.016244907,
-0.04563051,
0.011734753,
-0.0024377801,
-0.027255809,
-0.013641825,
-0.04682765,
0.0067617516,
... |
The abstract from the paper is the following:
We propose an efficient design of Transformer-based models for multivariate time series forecasting and self-supervised representation learning. It is based on two key components: (i) segmentation of time series into subseries-level patches which are served as input token... |
[
0.007796904,
-0.007934903,
-0.030608024,
0.04631223,
0.016421799,
-0.013165038,
0.026247278,
-0.012978741,
0.015138414,
0.02278352,
0.005544082,
-0.025640085,
0.0140275275,
-0.05381934,
-0.014089627,
-0.006372072,
-0.015731806,
-0.050700575,
-0.036100358,
0.0035948558,
0.0187... | Longformer |
[
0.0034246477,
0.015647888,
-0.017505454,
0.050085474,
0.0011218014,
-0.0024633766,
0.025638992,
-0.011619341,
-0.00053605676,
0.045988128,
0.0066428995,
0.052592803,
-0.025746012,
-0.0576992,
-0.046355054,
-0.0074608396,
0.0076251924,
-0.053999357,
-0.043266755,
-0.021297028,
... |
Since the Longformer is based on RoBERTa, it doesn't have token_type_ids. You don't need to indicate which
token belongs to which segment. Just separate your segments with the separation token tokenizer.sep_token (or
</s>).
A transformer model replacing the attention matrices by sparse matrices to go faster. Ofte... |
[
0.013997364,
0.0115436725,
-0.023993324,
-0.001394829,
-0.02536739,
0.022634357,
0.021894474,
-0.008863487,
-0.029474493,
0.05155016,
0.006749538,
0.030924058,
0.011619171,
-0.037356503,
-0.0118305655,
0.022694755,
-0.052214548,
-0.035242554,
-0.045933098,
-0.0014439028,
0.02... |
Longformer Self Attention
Longformer self attention employs self attention on both a "local" context and a "global" context. Most tokens only
attend "locally" to each other meaning that each token attends to its \(\frac{1}{2} w\) previous tokens and
\(\frac{1}{2} w\) succeeding tokens with \(w\) being the window leng... |
[
0.04189001,
-0.0005706408,
-0.0143517535,
0.021033505,
0.018599756,
0.008311627,
0.023231257,
-0.03660951,
-0.0093220025,
0.055342015,
-0.009558002,
0.0058594393,
0.012876754,
-0.03643251,
-0.0036100636,
-0.009513753,
-0.008024002,
-0.047642514,
-0.045872513,
-0.021608757,
0.... |
Overview
The Longformer model was presented in Longformer: The Long-Document Transformer by Iz Beltagy, Matthew E. Peters, Arman Cohan.
The abstract from the paper is the following:
Transformer-based models are unable to process long sequences due to their self-attention operation, which scales
quadratically with the... |
[
0.02142704,
0.0028819218,
-0.04130184,
0.015301769,
-0.000043038603,
0.017759487,
0.000064498454,
-0.020118287,
-0.019250857,
0.047662992,
0.020909628,
0.021168334,
-0.019174768,
-0.076151215,
-0.02246187,
0.021853147,
0.01166465,
-0.04964134,
-0.03783212,
-0.024866326,
0.024... |
For more information please also refer to [~LongformerModel.forward] method.
Using Longformer self attention, the memory and time complexity of the query-key matmul operation, which usually
represents the memory and time bottleneck, can be reduced from \(\mathcal{O}(n_s \times n_s)\) to
\(\mathcal{O}(n_s \times w)\),... |
[
0.013444869,
0.011378635,
-0.03466681,
0.019184407,
-0.04376398,
-0.020432757,
0.019844454,
-0.010051367,
0.020949315,
0.06640646,
0.014836707,
0.050708823,
-0.007604888,
0.008939331,
-0.044997983,
0.028539855,
-0.023532107,
-0.048671287,
-0.016515521,
0.02251334,
0.016013311... | 0: the token attends "locally",
1: the token attends "globally". |
[
0.03088414,
-0.0066066585,
-0.032900628,
0.0057045445,
-0.008404253,
-0.012397435,
-0.001915334,
-0.024105018,
-0.0052534877,
0.04584862,
0.0004493987,
-0.0014692519,
0.0264797,
-0.04951014,
0.0037344866,
0.0013465378,
-0.030459614,
-0.022818178,
-0.050199993,
-0.040144075,
-... | Resources
Text classification task guide
Token classification task guide
Question answering task guide
Masked language modeling task guide
Multiple choice task guide |
[
0.005142662,
-0.028678387,
-0.010244238,
0.031307925,
0.0029530933,
0.016831776,
0.019557182,
-0.0012711141,
0.00008880679,
0.08129652,
0.010066196,
0.027979916,
0.03314312,
-0.03251313,
-0.03851176,
0.05187857,
-0.014065283,
-0.07121663,
-0.05182379,
-0.017900025,
0.02392604... | LongformerModel
[[autodoc]] LongformerModel
- forward
LongformerForMaskedLM
[[autodoc]] LongformerForMaskedLM
- forward
LongformerForSequenceClassification
[[autodoc]] LongformerForSequenceClassification
- forward
LongformerForMultipleChoice
[[autodoc]] LongformerForMultipleChoice
- forward
LongformerFo... |
[
-0.007518971,
-0.038412135,
-0.0072669764,
0.017871177,
0.0034036282,
-0.00066489086,
0.013696241,
0.022270864,
0.02592138,
0.06184081,
0.033045333,
0.028359596,
0.043588236,
-0.000022985983,
-0.051733788,
0.04977232,
-0.013083282,
-0.069414265,
-0.039747022,
-0.013607702,
0.... | TFLongformerModel
[[autodoc]] TFLongformerModel
- call
TFLongformerForMaskedLM
[[autodoc]] TFLongformerForMaskedLM
- call
TFLongformerForQuestionAnswering
[[autodoc]] TFLongformerForQuestionAnswering
- call
TFLongformerForSequenceClassification
[[autodoc]] TFLongformerForSequenceClassification
- call
TF... |
[
0.029979002,
0.006599965,
0.00783122,
0.009768688,
0.01829503,
-0.04939806,
0.0116396025,
0.01229775,
0.016313192,
0.03922265,
-0.03922265,
0.018368978,
0.039932564,
-0.06211732,
0.004803,
-0.011218092,
0.018620405,
-0.03744787,
-0.02005502,
0.038897276,
-0.02918035,
0.0261... | You may specify output_segmentation=True in the forward of GroupViTModel to get the segmentation logits of input texts.
Resources
A list of official Hugging Face and community (indicated by π) resources to help you get started with GroupViT.
The quickest way to get started with GroupViT is by checking the example n... |
[
0.01657145,
-0.032350987,
-0.0041171983,
0.009011642,
0.013968412,
-0.03311357,
-0.015266264,
-0.013887754,
-0.0019926068,
0.045344178,
-0.018125938,
-0.0015013292,
0.043291077,
-0.02487184,
-0.004883445,
0.00243439,
0.00018858272,
-0.022114819,
-0.03449208,
0.007163852,
0.00... |
GroupViT
Overview
The GroupViT model was proposed in GroupViT: Semantic Segmentation Emerges from Text Supervision by Jiarui Xu, Shalini De Mello, Sifei Liu, Wonmin Byeon, Thomas Breuel, Jan Kautz, Xiaolong Wang.
Inspired by CLIP, GroupViT is a vision-language model that can perform zero-shot semantic segmentation on ... |
[
-0.011346754,
-0.040260952,
0.0030919905,
0.006093874,
-0.02676499,
0.012768435,
-0.012181074,
0.041702658,
0.0063141347,
0.056012917,
0.0072752717,
0.0033005704,
0.03390677,
-0.00093944446,
0.0054063946,
0.028246742,
-0.01672645,
-0.029928733,
-0.03556206,
0.009938422,
-0.01... | GroupViTConfig
[[autodoc]] GroupViTConfig
- from_text_vision_configs
GroupViTTextConfig
[[autodoc]] GroupViTTextConfig
GroupViTVisionConfig
[[autodoc]] GroupViTVisionConfig
GroupViTModel
[[autodoc]] GroupViTModel
- forward
- get_text_features
- get_image_features
GroupViTTextModel
[[autodoc]] GroupViTT... |
[
0.017152926,
-0.027997043,
-0.005418673,
0.025776774,
0.012461933,
-0.0129831545,
-0.0010373662,
0.026765063,
0.0007843707,
0.041508187,
-0.010796731,
0.00038837772,
0.042022638,
-0.017396614,
-0.004149465,
0.022216221,
0.013585606,
-0.046788093,
-0.01605633,
0.0008622155,
-0... | TFGroupViTModel
[[autodoc]] TFGroupViTModel
- call
- get_text_features
- get_image_features
TFGroupViTTextModel
[[autodoc]] TFGroupViTTextModel
- call
TFGroupViTVisionModel
[[autodoc]] TFGroupViTVisionModel
- call |
[
0.009983732,
-0.016833885,
0.040080678,
-0.023917234,
0.012519746,
-0.030898558,
-0.019078402,
-0.0025068643,
0.0038368138,
0.05739553,
0.0035999736,
-0.016950483,
0.05252755,
-0.01706708,
0.008147309,
0.03987663,
-0.0013299497,
-0.009983732,
-0.018786907,
0.0003491118,
0.020... | Pix2Struct
Overview
The Pix2Struct model was proposed in Pix2Struct: Screenshot Parsing as Pretraining for Visual Language Understanding by Kenton Lee, Mandar Joshi, Iulia Turc, Hexiang Hu, Fangyu Liu, Julian Eisenschlos, Urvashi Khandelwal, Peter Shaw, Ming-Wei Chang, Kristina Toutanova.
The abstract from the paper is... |
[
-0.011423942,
-0.014276482,
-0.016274638,
0.0305649,
0.0081166485,
-0.014717454,
0.010473095,
-0.010073463,
0.0029834541,
0.045833573,
-0.0105006555,
0.019843759,
0.027905285,
-0.05760202,
-0.044841383,
0.0077170176,
-0.012154303,
-0.063334666,
-0.08692669,
-0.016632928,
0.01... |
LongformerConfig
[[autodoc]] LongformerConfig
LongformerTokenizer
[[autodoc]] LongformerTokenizer
LongformerTokenizerFast
[[autodoc]] LongformerTokenizerFast
Longformer specific outputs
[[autodoc]] models.longformer.modeling_longformer.LongformerBaseModelOutput
[[autodoc]] models.longformer.modeling_longformer.Longfo... |
[
0.015582111,
-0.023529733,
-0.0081191,
-0.023171866,
-0.009133056,
-0.029300334,
0.0027921055,
-0.026094444,
0.013054677,
0.03143262,
-0.010087366,
0.011958711,
0.004913211,
-0.004447239,
0.021143956,
0.02242631,
-0.007873067,
-0.0012683764,
-0.04819271,
-0.0023410444,
-0.030... |
Visually-situated language is ubiquitous -- sources range from textbooks with diagrams to web pages with images and tables, to mobile apps with buttons and forms. Perhaps due to this diversity, previous work has typically relied on domain-specific recipes with limited sharing of the underlying data, model architectur... |
[
0.0061291996,
-0.031789366,
0.009754237,
-0.0025997553,
-0.00950682,
-0.0076774317,
-0.031099597,
0.011995987,
0.016419508,
0.040666398,
-0.0080673015,
-0.017829036,
0.026661081,
-0.032539114,
0.026616096,
0.018728735,
-0.02310727,
-0.0370676,
-0.06567803,
0.0033926151,
-0.01... |
Tips:
Pix2Struct has been fine tuned on a variety of tasks and datasets, ranging from image captioning, visual question answering (VQA) over different inputs (books, charts, science diagrams), captioning UI components etc. The full list can be found in Table 1 of the paper.
We therefore advise you to use these models... |
[
-0.008314518,
-0.049071044,
0.010689139,
-0.019371556,
-0.014180835,
-0.0032442007,
-0.023759589,
0.018381573,
0.009150652,
0.05147911,
0.013993542,
-0.00157026,
0.046475682,
-0.014167458,
0.014903256,
0.06400105,
-0.022729471,
-0.026181033,
-0.054957427,
0.0024950244,
-0.019... |
Pix2StructConfig
[[autodoc]] Pix2StructConfig
- from_text_vision_configs
Pix2StructTextConfig
[[autodoc]] Pix2StructTextConfig
Pix2StructVisionConfig
[[autodoc]] Pix2StructVisionConfig
Pix2StructProcessor
[[autodoc]] Pix2StructProcessor
Pix2StructImageProcessor
[[autodoc]] Pix2StructImageProcessor
- preproces... |
[
0.0309582,
-0.029862072,
-0.013146125,
-0.012827655,
0.0018015746,
0.016264165,
-0.0021700365,
-0.00550656,
0.0014183003,
0.046185486,
0.0313137,
0.011464902,
0.035016835,
-0.05169575,
-0.004628917,
0.03418733,
-0.008006175,
-0.020930113,
-0.047874115,
-0.00489184,
0.00197562... |
Custom Layers and Utilities
This page lists all the custom layers used by the library, as well as the utility functions it provides for modeling.
Most of those are only useful if you are studying the code of the models in the library.
Pytorch custom modules
[[autodoc]] pytorch_utils.Conv1D
[[autodoc]] modeling_utils.P... |
[
0.01025535,
-0.015375689,
0.017679106,
-0.050939303,
-0.06314596,
-0.027641028,
0.042987373,
-0.011392388,
0.012580776,
0.0416376,
0.05102733,
0.008032624,
0.039583594,
-0.023577033,
0.019469025,
-0.0018320984,
-0.006660842,
-0.013769164,
-0.05821635,
0.012485411,
0.001287420... |
General Utilities
This page lists all of Transformers general utility functions that are found in the file utils.py.
Most of those are only useful if you are studying the general code in the library.
Enums and namedtuples
[[autodoc]] utils.ExplicitEnum
[[autodoc]] utils.PaddingStrategy
[[autodoc]] utils.TensorType
Spe... |
[
0.009755474,
-0.022150664,
0.033028338,
-0.028412022,
-0.018120952,
-0.0022954056,
0.059272476,
0.0023687312,
-0.0018012559,
0.047693428,
0.008614147,
0.019026361,
0.011642807,
-0.022112407,
-0.010265564,
0.012586474,
-0.022418462,
-0.03315586,
-0.08533808,
0.0232091,
0.02810... | Fine-tuning Notebook
All models |
[
0.018823246,
0.031482488,
0.009015571,
-0.015150768,
-0.035918266,
0.018564012,
-0.043781687,
-0.014387469,
-0.00041292864,
0.04527948,
0.047785405,
0.0034798519,
0.02140118,
-0.06688229,
0.027017908,
0.044069722,
0.0018290376,
-0.06682468,
-0.022826964,
-0.04136217,
0.016014... |
Utilities for FeatureExtractors
This page lists all the utility functions that can be used by the audio [FeatureExtractor] in order to compute special features from a raw audio using common algorithms such as Short Time Fourier Transform or log mel spectrogram.
Most of those are only useful if you are studying the cod... |
[
-0.044957343,
-0.0046599526,
-0.017189573,
-0.027682463,
0.0018856634,
-0.053601895,
0.007976303,
0.0063163503,
-0.018668246,
0.020658767,
0.012895734,
-0.010151658,
0.02648815,
-0.045668244,
-0.029687202,
-0.016464455,
-0.0062523694,
-0.039611373,
-0.06261611,
0.0014715639,
... | The generation_output object is a [~generation.GenerateDecoderOnlyOutput], as we can
see in the documentation of that class below, it means it has the following attributes:
sequences: the generated sequences of tokens
scores (optional): the prediction scores of the language modelling head, for each generation step
hid... |
[
0.0048327195,
0.008516649,
0.014551343,
-0.027344044,
-0.034123324,
-0.050943885,
0.019061409,
0.00014647962,
0.02639381,
0.048391018,
-0.013891852,
-0.018692661,
0.013154358,
-0.030237295,
-0.012480685,
-0.004818537,
0.0051837387,
-0.032222856,
-0.024521708,
0.01796935,
0.01... |
Utilities for Generation
This page lists all the utility functions used by [~generation.GenerationMixin.generate].
Generate Outputs
The output of [~generation.GenerationMixin.generate] is an instance of a subclass of
[~utils.ModelOutput]. This output is a data structure containing all the information returned
by [~gen... |
[
-0.025322739,
-0.0073325844,
-0.027877033,
-0.01457709,
-0.022577606,
-0.05792668,
-0.004374595,
-0.0029396396,
-0.02228401,
0.019979274,
-0.012309053,
-0.0043085357,
0.039224554,
-0.022504207,
-0.031913992,
-0.02723112,
-0.016764387,
-0.017336901,
-0.029726693,
-0.0019927893,
... |
Here we have the scores since we passed along output_scores=True, but we don't have hidden_states and
attentions because we didn't pass output_hidden_states=True or output_attentions=True.
You can access each attribute as you would usually do, and if that attribute has not been returned by the model, you
will get Non... |
[
-0.019426163,
0.021749007,
0.01943999,
-0.011462128,
-0.031994406,
0.0077773784,
-0.025095008,
0.012270975,
-0.007756639,
0.083732985,
0.00553058,
-0.0038506663,
0.02983748,
-0.019149633,
-0.0078119445,
-0.003126506,
-0.0011104367,
-0.03805039,
-0.062219027,
0.016038682,
0.04... | Time Series Utilities
This page lists all the utility functions and classes that can be used for Time Series based models.
Most of those are only useful if you are studying the code of the time series models or you wish to add to the collection of distributional output classes.
Distributional Output
[[autodoc]] time_se... |
[
0.014261157,
-0.002420259,
0.004751341,
-0.009780914,
-0.05042414,
-0.01528134,
-0.00031256475,
-0.008325548,
-0.024512924,
0.050309993,
0.026182314,
0.016594023,
0.00565381,
-0.014460913,
-0.0052828346,
0.0044410056,
-0.03858146,
-0.053220727,
-0.056930482,
0.0044267373,
-0.... |
Utilities for Tokenizers
This page lists all the utility functions used by the tokenizers, mainly the class
[~tokenization_utils_base.PreTrainedTokenizerBase] that implements the common methods between
[PreTrainedTokenizer] and [PreTrainedTokenizerFast] and the mixin
[~tokenization_utils_base.SpecialTokensMixin].
Most... |
[
0.025648262,
-0.014758655,
0.043474015,
-0.00999621,
-0.04398051,
-0.024846315,
-0.0070240786,
-0.011656383,
-0.028265145,
0.048004318,
0.03334415,
-0.004027326,
0.025226185,
-0.016418828,
0.0052196956,
0.013984845,
-0.005012174,
-0.077437215,
-0.045584407,
0.014301403,
0.019... |
Utilities for Image Processors
This page lists all the utility functions used by the image processors, mainly the functional
transformations used to process the images.
Most of those are only useful if you are studying the code of the image processors in the library.
Image Transformations
[[autodoc]] image_transforms.... |
[
0.008497049,
-0.014871605,
0.04024248,
0.0030528533,
-0.036393687,
0.019413741,
0.008985222,
0.011475615,
-0.005295621,
0.08557894,
0.022710681,
-0.012147738,
0.023955876,
-0.024309626,
-0.012303388,
0.027677316,
-0.013944782,
-0.014220706,
-0.064410605,
-0.0008941004,
0.0304... |
Utilities for pipelines
This page lists all the utility functions the library provides for pipelines.
Most of those are only useful if you are studying the code of the models in the library.
Argument handling
[[autodoc]] pipelines.ArgumentHandler
[[autodoc]] pipelines.ZeroShotClassificationArgumentHandler
[[autodoc]] ... |
[
0.0051144357,
0.010331379,
0.026710754,
0.013384664,
-0.073396,
0.0035987762,
0.008391042,
0.008720534,
-0.0029361327,
0.05087344,
0.017587509,
0.040739756,
0.022493266,
-0.008508195,
0.035087153,
0.010514431,
-0.0070401286,
-0.021365674,
-0.06449241,
0.033593457,
0.011422361... |
Utilities for Trainer
This page lists all the utility functions used by [Trainer].
Most of those are only useful if you are studying the code of the Trainer in the library.
Utilities
[[autodoc]] EvalPrediction
[[autodoc]] IntervalStrategy
[[autodoc]] enable_full_determinism
[[autodoc]] set_seed
[[autodoc]] torch_distr... |
[
0.009762788,
0.025979752,
-0.07598262,
-0.028262492,
0.009701644,
-0.06163397,
-0.020721298,
-0.011237058,
0.009891872,
0.036768414,
0.011984384,
-0.002963825,
0.013248043,
-0.017908636,
0.018819015,
0.020694122,
-0.017840698,
0.007928444,
0.014742694,
-0.014987273,
-0.028588... | Agents & Tools
Transformers Agents is an experimental API which is subject to change at any time. Results returned by the agents
can vary as the APIs or underlying models are prone to change. |
[
-0.030221092,
-0.034416087,
0.002821634,
-0.025498156,
-0.03492976,
-0.065350614,
0.028037982,
-0.0046801316,
0.0053115212,
0.057074774,
-0.0062104487,
-0.016894132,
0.0030196123,
0.02522705,
-0.019961901,
-0.002274073,
0.003931025,
-0.0007557948,
0.012235404,
0.014175947,
0.... | Calling to_raw on the type should return the underlying object
Calling to_string on the type should return the object as a string: that can be the string in case of an AgentText
but will be the path of the serialized version of the object in other instances
Displaying it in an ipython kernel should display the object... |
[
0.0015334778,
0.0048927055,
-0.036621273,
-0.013300263,
-0.040842135,
-0.021089116,
-0.020572895,
0.037714444,
0.035497736,
0.07585401,
-0.010248491,
-0.006604583,
0.021195397,
0.0011785764,
0.0024748207,
0.023913145,
-0.011751602,
-0.018614296,
-0.030031873,
-0.011561816,
0.... |
To learn more about agents and tools make sure to read the introductory guide. This page
contains the API docs for the underlying classes.
Agents
We provide three types of agents: [HfAgent] uses inference endpoints for opensource models, [LocalAgent] uses a model of your choice locally and [OpenAiAgent] uses OpenAI c... |
[
0.01421496,
-0.023194987,
-0.0018178747,
-0.0040526306,
-0.008344455,
-0.062928535,
-0.001298482,
0.023823727,
0.003075352,
0.06167106,
0.0042918245,
0.003731427,
0.032585062,
-0.008822843,
0.0055834725,
0.02024265,
0.020898726,
-0.009185052,
-0.0065983385,
-0.0055287993,
-0.... | AgentText
[[autodoc]] transformers.tools.agent_types.AgentText
AgentImage
[[autodoc]] transformers.tools.agent_types.AgentImage
AgentAudio
[[autodoc]] transformers.tools.agent_types.AgentAudio |
[
0.0237894,
-0.016534068,
-0.020407433,
0.009192016,
0.011143152,
-0.03740399,
-0.007313145,
-0.0118585685,
0.0017641517,
0.044572607,
-0.009314866,
0.0021769614,
0.03685478,
-0.01802271,
-0.020624226,
-0.025437025,
-0.0017777013,
-0.0019041637,
-0.0021317962,
0.020956641,
0.0... | Generation
Each framework has a generate method for text generation implemented in their respective GenerationMixin class:
PyTorch [~generation.GenerationMixin.generate] is implemented in [~generation.GenerationMixin].
TensorFlow [~generation.TFGenerationMixin.generate] is implemented in [~generation.TFGenerationMixin... |
[
0.005748816,
0.009584928,
-0.018042218,
-0.013581621,
0.0062626763,
0.010491321,
-0.05207121,
-0.008307413,
0.010762526,
0.06548868,
-0.0045105545,
-0.0027334532,
0.011704603,
-0.06086394,
-0.023908794,
0.036997966,
0.017599726,
-0.053013287,
-0.038254067,
-0.05155735,
0.0355... |
Feature Extractor
A feature extractor is in charge of preparing input features for audio or vision models. This includes feature extraction from sequences, e.g., pre-processing audio files to generate Log-Mel Spectrogram features, feature extraction from images, e.g., cropping image files, but also padding, normalizat... |
[
0.023358952,
0.0037100313,
-0.056321938,
-0.028215228,
0.022531487,
-0.0101669775,
0.032366123,
-0.0024230506,
-0.032366123,
0.06218202,
-0.002007622,
-0.0213242,
-0.0014192396,
-0.041970152,
-0.016060976,
0.014731605,
-0.042431362,
-0.056267675,
-0.07618111,
0.008139008,
0.0... | Tokenizer
A tokenizer is in charge of preparing the inputs for a model. The library contains tokenizers for all the models. Most
of the tokenizers are available in two flavors: a full python implementation and a "Fast" implementation based on the
Rust library π€ Tokenizers. The "Fast" implementations allows: |
[
0.014884165,
0.0062259827,
-0.003980302,
0.007274216,
0.0062483647,
-0.027828539,
0.011802882,
-0.023650527,
0.009288614,
0.07442828,
0.023560999,
-0.006155106,
-0.014876704,
-0.053508386,
-0.018830894,
-0.0046666893,
-0.03587121,
-0.040496863,
-0.03027566,
0.021158643,
0.002... | a significant speed-up in particular when doing batched tokenization and
additional methods to map between the original string (character and words) and the token space (e.g. getting the
index of the token comprising a given character or the span of characters corresponding to a given token). |
[
0.010689713,
-0.022826154,
0.008534234,
0.010602032,
-0.010792007,
-0.028276958,
-0.014350373,
0.018003726,
0.0043767174,
0.042700395,
0.0154317655,
0.0084757805,
0.03732266,
-0.016352411,
-0.006725824,
-0.00544715,
0.0084757805,
-0.0335524,
-0.043606427,
0.01497875,
0.001390... |
Regardless of your framework of choice, you can parameterize the generate method with a [~generation.GenerationConfig]
class instance. Please refer to this class for the complete list of generation parameters, which control the behavior
of the generation method.
To learn how to inspect a model's generation configurat... |
[
0.008498719,
0.021656634,
-0.024647724,
-0.0077437568,
-0.022461928,
-0.014459327,
0.016594792,
-0.01468941,
-0.014897924,
0.049813136,
0.002933568,
-0.0063416837,
0.0012609669,
-0.038165145,
0.0055220104,
-0.015933301,
-0.015314951,
-0.044233605,
-0.055220105,
-0.00076395,
-... |
The base classes [PreTrainedTokenizer] and [PreTrainedTokenizerFast]
implement the common methods for encoding string inputs in model inputs (see below) and instantiating/saving python and
"Fast" tokenizers either from a local file or directory or from a pretrained tokenizer provided by the library
(downloaded from H... |
[
0.022088556,
-0.028058847,
-0.03162887,
-0.015335899,
0.018336236,
-0.011135427,
0.020371908,
-0.0035510317,
-0.024777466,
0.028165188,
-0.002854118,
0.041867994,
-0.029426089,
-0.050010677,
-0.043934047,
0.0014583915,
-0.036885154,
-0.07285881,
-0.04630393,
-0.0041662906,
-0... | Tokenizing (splitting strings in sub-word token strings), converting tokens strings to ids and back, and
encoding/decoding (i.e., tokenizing and converting to integers).
Adding new tokens to the vocabulary in a way that is independent of the underlying structure (BPE, SentencePiece).
Managing special tokens (like mas... |
[
0.029118685,
0.024775015,
-0.037296586,
-0.0060663926,
0.0057546943,
0.015403946,
-0.012756183,
0.010416768,
-0.021959672,
0.043999784,
0.025539178,
0.0192918,
0.019305207,
-0.04314177,
-0.0027851781,
0.005905516,
-0.01650327,
-0.03423993,
-0.093683876,
0.016892055,
0.0085733... | Optimization
The .optimization module provides:
an optimizer with weight decay fixed that can be used to fine-tuned models, and
several schedules in the form of schedule objects that inherit from _LRSchedule:
a gradient accumulation class to accumulate the gradients of multiple batches |
[
0.053686377,
-0.0069709574,
-0.025362277,
-0.0027200074,
-0.030818969,
0.0072244466,
-0.018384648,
0.00967262,
-0.02073276,
0.051605098,
0.016183294,
-0.014275453,
0.05075124,
-0.07028326,
-0.008018268,
0.023721267,
-0.022974141,
-0.0012891268,
-0.0493904,
0.012447662,
0.0393... | AdamW (PyTorch)
[[autodoc]] AdamW
AdaFactor (PyTorch)
[[autodoc]] Adafactor
AdamWeightDecay (TensorFlow)
[[autodoc]] AdamWeightDecay
[[autodoc]] create_optimizer
Schedules
Learning Rate Schedules (Pytorch)
[[autodoc]] SchedulerType
[[autodoc]] get_scheduler
[[autodoc]] get_constant_schedule
[[autodoc]] get_constant_sch... |
[
0.034616273,
0.013292649,
-0.017709685,
-0.0026671838,
-0.04458576,
0.0009900255,
-0.028496116,
0.016588118,
-0.03514244,
0.08208211,
0.021199007,
0.018554322,
0.025712967,
-0.05652145,
-0.012212621,
-0.008584836,
-0.011631068,
-0.020257443,
-0.038548682,
-0.0028679583,
0.007... | [[autodoc]] get_cosine_schedule_with_warmup
[[autodoc]] get_cosine_with_hard_restarts_schedule_with_warmup
[[autodoc]] get_linear_schedule_with_warmup
[[autodoc]] get_polynomial_decay_schedule_with_warmup
[[autodoc]] get_inverse_sqrt_schedule
Warmup (TensorFlow)
[[autodoc]] WarmUp
Gradient Strategies
GradientAccumul... |
[
0.011014978,
0.0048404667,
-0.0060615186,
-0.045984436,
-0.012152196,
0.006181801,
0.012706226,
-0.014412053,
0.007165932,
0.029975902,
0.0196972,
0.003524647,
0.012757255,
-0.025835263,
0.006382272,
0.025572827,
0.0015217583,
-0.024202334,
-0.054732267,
0.0016511532,
0.02202... | Models
The base classes [PreTrainedModel], [TFPreTrainedModel], and
[FlaxPreTrainedModel] implement the common methods for loading/saving a model either from a local
file or directory, or from a pretrained model configuration provided by the library (downloaded from HuggingFace's AWS
S3 repository).
[PreTrainedModel] a... |
[
0.027360383,
0.00036045484,
0.0066823284,
-0.01356099,
-0.011471448,
-0.020488735,
0.015776746,
0.0013541707,
-0.023251418,
-0.00052107085,
0.07129687,
-0.0032640335,
0.00073624816,
-0.028257905,
-0.019591212,
0.013336609,
-0.023125203,
-0.073765054,
-0.03522772,
-0.0107702585,... | resize the input token embeddings when new tokens are added to the vocabulary
prune the attention heads of the model. |
[
0.0021091965,
-0.010076849,
-0.014127421,
0.0036062303,
0.0039971755,
-0.017331265,
-0.013234922,
-0.013082358,
-0.02796497,
0.048942514,
-0.007940954,
0.0031180256,
0.006926403,
-0.020794466,
-0.025661256,
-0.0029673688,
-0.025417153,
-0.05208533,
-0.0760989,
0.0055075586,
0... |
[BatchEncoding] holds the output of the
[~tokenization_utils_base.PreTrainedTokenizerBase]'s encoding methods (__call__,
encode_plus and batch_encode_plus) and is derived from a Python dictionary. When the tokenizer is a pure python
tokenizer, this class behaves just like a standard python dictionary and holds the va... |
[
0.025688274,
-0.02617125,
-0.006535266,
0.009931189,
-0.018081406,
0.011297105,
0.004056242,
-0.0239073,
-0.013259194,
0.024314811,
0.042532053,
-0.012874323,
0.0381249,
-0.05856081,
0.0046788277,
0.079811744,
-0.022201791,
-0.0042486773,
-0.05699114,
-0.008067205,
-0.0037958... |
Large model loading
In Transformers 4.20.0, the [~PreTrainedModel.from_pretrained] method has been reworked to accommodate large models using Accelerate. This requires Accelerate >= 0.9.0 and PyTorch >= 1.9.0. Instead of creating the full model, then loading the pretrained weights inside it (which takes twice the siz... |
[
0.015615442,
-0.0065185055,
-0.00975603,
0.0116463965,
-0.005674721,
-0.013457092,
-0.005855791,
-0.01941066,
0.0077280505,
0.04800517,
0.009241792,
0.018613955,
0.018425642,
-0.05918803,
-0.020989588,
0.020019054,
0.011740552,
0.016759802,
-0.050641544,
-0.004490526,
0.01374... | The other methods that are common to each model are defined in [~modeling_utils.ModuleUtilsMixin]
(for the PyTorch models) and [~modeling_tf_utils.TFModuleUtilsMixin] (for the TensorFlow models) or
for text generation, [~generation.GenerationMixin] (for the PyTorch models),
[~generation.TFGenerationMixin] (for the Tens... |
[
0.033925913,
0.018665956,
0.017485924,
0.022366965,
-0.026550714,
0.005172696,
-0.018223444,
-0.0096481005,
0.006614212,
0.050473176,
0.005430828,
-0.03502549,
0.023935871,
-0.06259532,
0.009145246,
0.061951667,
0.0028293943,
-0.06500902,
-0.04945406,
-0.029742165,
-0.0043312... | from transformers import AutoModelForSeq2SeqLM
t0pp = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0pp", low_cpu_mem_usage=True) |
[
-0.00341422,
0.0024034667,
-0.022355484,
0.007224814,
-0.0058519193,
0.016532391,
0.025382338,
0.013354194,
0.01692156,
0.06365043,
0.017570172,
0.0017107134,
0.018276436,
-0.06261265,
0.0055816644,
0.049553934,
-0.023119405,
-0.04303899,
-0.07529661,
-0.011617357,
0.02966317... |
Moreover, you can directly place the model on different devices if it doesn't fully fit in RAM (only works for inference for now). With device_map="auto", Accelerate will determine where to put each layer to maximize the use of your fastest devices (GPUs) and offload the rest on the CPU, or even the hard drive if you... |
[
0.028790807,
0.019612713,
0.018369846,
0.014395404,
-0.028025966,
0.010195606,
-0.024215419,
-0.014299799,
0.024952944,
0.056488983,
0.011588709,
-0.028408388,
0.03288817,
-0.05452225,
0.00009229738,
0.062716976,
0.0022996452,
-0.04378716,
-0.055724144,
-0.02446126,
0.0052104... | from transformers import AutoModelForSeq2SeqLM
t0pp = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0pp", device_map="auto") |
[
0.030685116,
0.0053071026,
-0.025510406,
0.005658892,
-0.011529614,
-0.0028389029,
0.0125887655,
0.0058215475,
0.017778605,
0.046300028,
0.01298973,
0.022559915,
0.04390937,
-0.040066168,
-0.0064419075,
0.026660342,
0.012951903,
-0.049326174,
-0.053260162,
-0.022938183,
0.035... |
You can inspect how the model was split across devices by looking at its hf_device_map attribute:
py
t0pp.hf_device_map
python out
{'shared': 0,
'decoder.embed_tokens': 0,
'encoder': 0,
'decoder.block.0': 0,
'decoder.block.1': 1,
'decoder.block.2': 1,
'decoder.block.3': 1,
'decoder.block.4': 1,
'decoder.block... |
[
0.0178745,
0.0017523516,
-0.028434837,
0.002828417,
0.011341062,
-0.01662808,
-0.014820083,
-0.011443789,
0.012943603,
0.08163373,
0.018244317,
-0.0026007055,
0.025983086,
-0.036570817,
-0.05089781,
0.020339947,
-0.030571558,
-0.0415565,
-0.054842528,
-0.015751475,
0.02848962... | Pipelines
The pipelines are a great and easy way to use models for inference. These pipelines are objects that abstract most of
the complex code from the library, offering a simple API dedicated to several tasks, including Named Entity
Recognition, Masked Language Modeling, Sentiment Analysis, Feature Extraction and Qu... |
[
-0.01327267,
-0.007839147,
-0.023024173,
0.010996054,
-0.018197749,
0.0060140598,
0.01830399,
0.010836691,
0.037457917,
0.04437883,
-0.0076797837,
0.008711849,
0.017104972,
-0.011838402,
-0.033724267,
0.008286881,
-0.03093162,
-0.008203406,
-0.07266957,
-0.024496386,
0.029808... | pipe = pipeline("text-classification")
pipe("This restaurant is awesome")
[{'label': 'POSITIVE', 'score': 0.9998743534088135}]
If you want to use a specific model from the hub you can ignore the task if the model on
the hub already defines it:
thon
pipe = pipeline(model="FacebookAI/roberta-large-mnli")
pipe("This res... |
[
-0.009505623,
-0.020963429,
-0.018290441,
0.030724337,
-0.0055599636,
-0.020422824,
0.018290441,
-0.005083181,
0.024327187,
0.07388257,
0.00571764,
-0.011585448,
0.009723366,
0.0019137012,
-0.039584238,
0.002151154,
-0.029177608,
-0.030874506,
-0.06295035,
-0.005871562,
0.011... | To call a pipeline on many items, you can call it with a list.
thon
pipe = pipeline("text-classification")
pipe(["This restaurant is awesome", "This restaurant is awful"])
[{'label': 'POSITIVE', 'score': 0.9998743534088135},
{'label': 'NEGATIVE', 'score': 0.9996669292449951}] |
[
0.010187449,
-0.01664625,
-0.010592434,
0.01605972,
0.024382846,
-0.023042208,
-0.036197215,
-0.010557521,
0.01131163,
0.06948972,
0.0040777726,
0.0033079535,
0.01928563,
-0.036392722,
-0.017777413,
0.01936942,
-0.05027391,
-0.031588774,
-0.081723034,
-0.025849167,
0.01594800... | The [pipeline] which is the most powerful object encapsulating all other pipelines.
Task-specific pipelines are available for audio, computer vision, natural language processing, and multimodal tasks.
The pipeline abstraction
The pipeline abstraction is a wrapper around all the other available pipelines. It is instant... |
[
0.018425096,
0.02331401,
-0.012313954,
0.031059884,
-0.011137558,
-0.016133418,
-0.032572392,
-0.002289769,
0.017600091,
0.044672456,
-0.027393198,
-0.012650066,
0.018073706,
-0.03764464,
-0.00941116,
0.027958479,
-0.014246603,
-0.023359844,
-0.029547377,
-0.012894512,
0.0050... |
To iterate over full datasets it is recommended to use a dataset directly. This means you don't need to allocate
the whole dataset at once, nor do you need to do batching yourself. This should work just as fast as custom loops on
GPU. If it doesn't don't hesitate to create an issue.
thon
import datasets
from transfor... |
[
0.016976746,
-0.015508168,
-0.038858537,
0.0074970834,
-0.00453423,
-0.013628391,
0.0015851448,
-0.029738676,
0.019120866,
0.052340068,
-0.0059550777,
-0.030193934,
0.038652934,
-0.032249942,
-0.011484269,
-0.018430635,
-0.02684558,
-0.046553876,
-0.05145892,
-0.023923112,
-0... |
For ease of use, a generator is also possible:
thon
from transformers import pipeline
pipe = pipeline("text-classification")
def data():
while True:
# This could come from a dataset, a database, a queue or HTTP request
# in a server
# Caveat: because this is iterative, you cannot use num_w... |
[
0.01965353,
0.012742237,
0.004728391,
0.026076447,
-0.03128582,
-0.004247412,
-0.028370347,
0.005042877,
-0.0023456963,
0.089920826,
-0.04572998,
-0.019890321,
0.027142001,
-0.01901716,
-0.025070092,
0.013097421,
-0.014007581,
-0.02578046,
-0.067129835,
0.0005864241,
0.013896... |
[[autodoc]] pipeline
Pipeline batching
All pipelines can use batching. This will work
whenever the pipeline uses its streaming ability (so when passing lists or Dataset or generator).
thon
from transformers import pipeline
from transformers.pipelines.pt_utils import KeyDataset
import datasets
dataset = datasets.load_... |
[
0.027067758,
-0.020534161,
-0.022326827,
0.009015178,
-0.02050453,
0.029675271,
0.00078614283,
0.0007208624,
0.01847482,
0.058757924,
0.022415718,
-0.015467291,
0.011896776,
-0.055528164,
-0.0011065261,
0.038964532,
0.0026315877,
-0.029853055,
-0.050372403,
0.015496921,
0.013... | However, this is not automatically a win for performance. It can be either a 10x speedup or 5x slowdown depending
on hardware, data and the actual model being used.
Example where it's mostly a speedup:
thon
from transformers import pipeline
from torch.utils.data import Dataset
from tqdm.auto import tqdm
pipe = pipelin... |
[
0.0052647563,
0.020065675,
0.023471447,
0.05284623,
-0.0043068826,
-0.018518886,
0.011423527,
-0.008564098,
0.013367656,
0.077992186,
-0.031702064,
-0.0023024438,
0.039677247,
-0.03385905,
-0.02315925,
0.03559032,
-0.009429731,
-0.06936423,
-0.049639132,
0.023599163,
-0.00050... | dataset = MyDataset()
for batch_size in [1, 8, 64, 256]:
print("-" * 30)
print(f"Streaming batch_size={batch_size}")
for out in tqdm(pipe(dataset, batch_size=batch_size), total=len(dataset)):
pass
On GTX 970
Streaming no batching
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ... |
[
0.034847796,
0.006869713,
0.007650202,
0.054676447,
-0.01601761,
-0.038644772,
0.014892581,
-0.010828411,
-0.008135371,
0.065589234,
0.0032485235,
-0.005547803,
0.033554014,
0.0080439625,
-0.038869776,
0.026578827,
-0.0054423315,
-0.083758466,
-0.06525172,
0.011876095,
-0.006... | Streaming batch_size=256
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5000/5000 [00:01<00:00, 2554.43it/s]
(diminishing returns, saturated the GPU)
Example where it's most a slowdown:
thon
class MyDataset(Dataset):
def len(self):
return 5000
def __getitem__(self, i):
if i... |
[
0.026331209,
0.017112495,
0.004487323,
0.064823866,
-0.0076148515,
-0.05174194,
0.013848988,
0.003221668,
0.0018287499,
0.087640524,
0.03793479,
-0.0012839602,
0.03757218,
-0.04421077,
-0.046832733,
0.005536806,
0.008360996,
-0.098072596,
-0.051965088,
0.021938024,
0.00117151... | This is a occasional very long sentence compared to the other. In that case, the whole batch will need to be 400
tokens long, so the whole batch will be [64, 400] instead of [64, 4], leading to the high slowdown. Even worse, on
bigger batches, the program simply crashes.
Streaming no batching
100%|ββββββββββββββββββββ... |
[
0.03579491,
0.029694725,
0.010917178,
0.03703107,
0.004921128,
-0.063635394,
0.015989468,
0.013053587,
-0.0007478267,
0.06471032,
0.02735677,
0.018475225,
0.05895948,
-0.005472026,
-0.03582178,
0.038858436,
-0.009620554,
-0.08685371,
-0.046329144,
0.010809686,
-0.00045600213,... | Streaming batch_size=8
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5000/5000 [00:04<00:00, 1205.95it/s]
Streaming batch_size=64
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5000/5000 [00:02<00:00, 2478.24it/s]
Streaming batch_size=256
100%|βββββββββββββββ... |
[
0.020904865,
0.046755254,
-0.00088384544,
0.022709314,
0.01844547,
-0.078647204,
0.016600924,
0.016707852,
-0.01138139,
0.062073015,
0.0130789075,
0.00521285,
0.05576413,
0.00048494543,
-0.0602552,
0.017549928,
-0.0074650687,
-0.082603626,
-0.0533582,
0.011281142,
-0.00646593... | Streaming no batching
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 1000/1000 [00:05<00:00, 183.69it/s]
Streaming batch_size=8
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 1000/1000 [00:03<00:00, 265.74it/s]
Streaming batch_size=64
100%|ββββββββββββββββββββ... |
[
0.019604025,
0.0005605438,
-0.0048621655,
0.049264297,
-0.024561528,
-0.024561528,
0.016849859,
0.004992812,
0.028883453,
0.038643096,
0.005886151,
-0.013940327,
0.043191,
-0.004254836,
-0.018276375,
0.0479084,
-0.010592953,
-0.02485813,
-0.034942623,
0.009717269,
0.001179348... |
Streaming batch_size=256
0%| | 0/1000 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/home/nicolas/src/transformers/test.py", line 42, in
for out in tqdm(pipe(dataset, batch_size=256), total=len(dataset)):
.
q = q ... |
[
0.035125103,
-0.009420042,
-0.0198228,
-0.016425408,
-0.0040817843,
-0.031418856,
0.03175579,
0.002818291,
0.031446934,
0.06727398,
0.0054189805,
-0.024160793,
0.010873059,
-0.045317277,
-0.01357553,
0.05472328,
0.0067280997,
-0.037259,
-0.038887504,
0.0075598992,
0.021956699... | There are no good (general) solutions for this problem, and your mileage may vary depending on your use cases. Rule of
thumb:
For users, a rule of thumb is:
Measure performance on your load, with your hardware. Measure, measure, and keep measuring. Real numbers are the
only way to go.
If you are latency constrained ... |
[
0.01004689,
-0.008695512,
0.025867203,
0.0063146823,
0.00013398801,
-0.010542159,
0.02810299,
0.005776962,
0.033423595,
0.07765821,
0.013152936,
-0.019173993,
-0.00516495,
-0.052724946,
-0.019754166,
0.059375703,
-0.0039904546,
-0.05496073,
-0.052923054,
0.0069762208,
0.04635... | If you are using throughput (you want to run your model on a bunch of static data), on GPU, then:
If you have no clue about the size of the sequence_length ("natural" data), by default don't batch, measure and
try tentatively to add it, add OOM checks to recover when it will fail (and it will at some point if you ... |
[
0.0024045631,
0.016655998,
0.013730504,
-0.005675045,
-0.0359339,
-0.0193745,
-0.00774152,
0.0015869426,
0.018919116,
0.084784135,
0.0009599278,
-0.012743839,
-0.0028392475,
-0.051554937,
-0.03375358,
0.038362615,
0.00039996993,
-0.06999107,
-0.052079316,
-0.0017715109,
0.022... | If your sequence_length is super regular, then batching is more likely to be VERY interesting, measure and push
it until you get OOMs.
The larger the GPU the more likely batching is going to be more interesting
As soon as you enable batching, make sure you can handle OOMs nicely. |
[
0.003921526,
-0.014746686,
-0.009780148,
0.0070419977,
-0.013749009,
-0.00009785609,
0.020288527,
-0.00793044,
-0.01186289,
0.069502406,
-0.020725466,
-0.006197249,
0.011571597,
-0.02136631,
-0.0016275971,
0.0067434227,
-0.055899043,
-0.08272709,
-0.08657215,
-0.0019662248,
-... | Subclass your pipeline of choice
thon
class MyPipeline(TextClassificationPipeline):
def postprocess():
# Your code goes here
scores = scores * 100
# And here
my_pipeline = MyPipeline(model=model, tokenizer=tokenizer, )
or if you use pipeline function, then:
my_pipeline = pipeline(model="xxx... |
[
0.000722565,
-0.022818023,
-0.023481417,
-0.033473805,
0.019127889,
0.008382272,
-0.011630143,
0.0069103646,
-0.0035381066,
0.058268193,
0.0038456179,
0.0034102648,
-0.0029818222,
-0.047709156,
0.002206134,
0.016266998,
-0.02729594,
-0.035933893,
-0.046548214,
0.003904356,
0.... |
Model outputs
All models have outputs that are instances of subclasses of [~utils.ModelOutput]. Those are
data structures containing all the information returned by the model, but that can also be used as tuples or
dictionaries.
Let's see how this looks in an example:
thon
from transformers import BertTokenizer, BertF... |
[
0.020403223,
0.028572561,
-0.033052955,
-0.043730777,
-0.005231596,
-0.0021731243,
0.027311614,
-0.013266791,
-0.010523557,
0.06471082,
-0.02110077,
0.008913835,
0.023086093,
-0.075013034,
-0.014608226,
0.05687684,
-0.006700467,
-0.04963309,
-0.062457208,
0.004765447,
0.02083... | Keras callbacks
When training a Transformers model with Keras, there are some library-specific callbacks available to automate common
tasks:
KerasMetricCallback
[[autodoc]] KerasMetricCallback
PushToHubCallback
[[autodoc]] PushToHubCallback |
[
-0.020134825,
-0.017431408,
-0.0073217545,
-0.017346926,
-0.006360774,
-0.030526083,
0.002173646,
-0.007779364,
-0.017853817,
0.030920332,
0.01754405,
-0.015826253,
0.009412678,
-0.036355328,
-0.01277787,
-0.0028759006,
0.0028882208,
-0.025752863,
-0.065388896,
-0.00044066928,
... | The outputs object is a [~modeling_outputs.SequenceClassifierOutput], as we can see in the
documentation of that class below, it means it has an optional loss, a logits, an optional hidden_states and
an optional attentions attribute. Here we have the loss since we passed along labels, but we don't have
hidden_states an... |
[
0.034156337,
0.009689277,
-0.007130463,
-0.013489279,
-0.027954036,
-0.016190046,
-0.025741009,
0.019611504,
-0.026847523,
0.094519585,
0.006518969,
-0.0068611144,
0.03098239,
-0.044726457,
-0.040708065,
0.03770883,
-0.025056718,
-0.043649063,
-0.0658667,
-0.0036107297,
0.002... |
Pipeline chunk batching
zero-shot-classification and question-answering are slightly specific in the sense, that a single input might yield
multiple forward pass of a model. Under normal circumstances, this would yield issues with batch_size argument.
In order to circumvent this issue, both of these pipelines are a b... |
[
0.016144846,
-0.024581742,
-0.012675593,
0.0032600167,
-0.016860293,
-0.0656593,
-0.03955217,
0.011089456,
-0.05755988,
0.08930961,
0.020046066,
0.012385364,
0.004778658,
-0.030453822,
-0.055400036,
0.010306513,
0.003563745,
0.009928539,
-0.045086775,
0.026633594,
0.044654805... | When passing output_hidden_states=True you may expect the outputs.hidden_states[-1] to match outputs.last_hidden_states exactly.
However, this is not always the case. Some models apply normalization or subsequent process to the last hidden state when it's returned. |
[
-0.021287026,
-0.00091461994,
-0.03344062,
-0.025270138,
0.019463258,
-0.047359623,
-0.03262357,
0.019434078,
0.011008267,
0.059498627,
0.03650455,
-0.016545229,
0.04123176,
-0.05118224,
0.011453266,
0.029909804,
-0.017187195,
-0.025897514,
-0.08526483,
-0.008148598,
0.000760... |
That should enable you to do all the custom code you want.
Implementing a pipeline
Implementing a new pipeline
Audio
Pipelines available for audio tasks include the following.
AudioClassificationPipeline
[[autodoc]] AudioClassificationPipeline
- call
- all
AutomaticSpeechRecognitionPipeline
[[autodoc]] Automa... |
[
0.0073001524,
-0.02178216,
-0.018714035,
0.004781543,
-0.006662868,
-0.012112224,
-0.010257611,
-0.01373024,
-0.0047281175,
0.016699146,
-0.029536426,
-0.0012440407,
0.025247157,
-0.03260455,
0.0034001234,
0.044022247,
-0.00415189,
-0.04747198,
-0.07943543,
-0.026163014,
0.02... |
Processors
Processors can mean two different things in the Transformers library:
- the objects that pre-process inputs for multi-modal models such as Wav2Vec2 (speech and text)
or CLIP (text and vision)
- deprecated objects that were used in older versions of the library to preprocess data for GLUE or SQUAD.
Multi-m... |
[
-0.01593737,
-0.0031320488,
-0.017638471,
-0.020859411,
0.005451891,
0.008115091,
-0.0017499038,
-0.013030159,
-0.0003764733,
0.05543918,
-0.008331215,
0.0035085222,
-0.020873353,
-0.036057778,
-0.03187474,
0.0065987404,
-0.013329944,
-0.048802096,
-0.022239812,
-0.01444542,
... |
Additionally, the following method can be used to load values from a data file and convert them to a list of
[~data.processors.utils.InputExample].
[[autodoc]] data.processors.glue.glue_convert_examples_to_features
XNLI
The Cross-Lingual NLI Corpus (XNLI) is a benchmark that evaluates the
quality of cross-lingual tex... |
[
-0.0000030117553,
-0.029915797,
0.00026993244,
0.02007474,
-0.0077575888,
-0.008884815,
-0.02973848,
0.010974614,
-0.006396053,
0.059172988,
-0.0023114448,
0.019264152,
0.021809908,
-0.048432685,
-0.05137107,
0.009410431,
-0.027560022,
-0.06646829,
-0.04470904,
-0.014159975,
... | [~data.processors.utils.MrpcProcessor]
[~data.processors.utils.MnliProcessor]
[~data.processors.utils.MnliMismatchedProcessor]
[~data.processors.utils.Sst2Processor]
[~data.processors.utils.StsbProcessor]
[~data.processors.utils.QqpProcessor]
[~data.processors.utils.QnliProcessor]
[~data.processors.utils.RteProcessor]
... |
[
-0.019941999,
0.0017093142,
0.014593918,
0.01206232,
-0.010229986,
-0.040194783,
-0.009601943,
0.006643017,
-0.013286034,
0.072050184,
0.0051570786,
0.008112768,
0.000027315034,
-0.029472722,
-0.018556418,
0.03265826,
-0.02332178,
-0.07184299,
-0.05941162,
0.035714306,
0.0172... | [~data.processors.utils.XnliProcessor] |
[
-0.03075047,
-0.0008477695,
-0.02812921,
-0.04044631,
-0.030327687,
-0.022689395,
0.012930136,
-0.0063593723,
-0.015276586,
0.050424006,
-0.017756917,
-0.0012798016,
0.0043546725,
-0.0068103415,
-0.017954215,
-0.013916631,
-0.007638293,
-0.02281623,
-0.036359403,
-0.0021773363,... |
You can access each attribute as you would usually do, and if that attribute has not been returned by the model, you
will get None. Here for instance outputs.loss is the loss computed by the model, and outputs.attentions is
None.
When considering our outputs object as tuple, it only considers the attributes that don'... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.