import{s as ge,n as ye,o as be}from"../chunks/scheduler.25b97de1.js";import{S as we,i as ve,g as n,s as o,r as G,A as _e,h as l,f as s,c as i,j as pe,u as J,x as r,k as X,y as xe,a,v as D,d as Q,t as V,w as Z}from"../chunks/index.d9030fc9.js";import{H as me,E as Te}from"../chunks/EditOnGithub.91d95064.js";function Me(ee){let d,C,$,P,h,H,u,te="🤗 Transformers is an opinionated library built for:",A,f,se="<li>machine learning researchers and educators seeking to use, study or extend large-scale Transformers models.</li> <li>hands-on practitioners who want to fine-tune those models or serve them in production, or both.</li> <li>engineers who just want to download a pretrained model and use it to solve a given machine learning task.</li>",j,p,ae="The library was designed with two strong goals in mind:",z,m,oe="<li>Be as easy and fast to use as possible:</li>",E,g,ie=`<li>We strongly limited the number of user-facing abstractions to learn, in fact, there are almost no abstractions,
just three standard classes required to use each model: <a href="main_classes/configuration">configuration</a>,
<a href="main_classes/model">models</a>, and a preprocessing class (<a href="main_classes/tokenizer">tokenizer</a> for NLP, <a href="main_classes/image_processor">image processor</a> for vision, <a href="main_classes/feature_extractor">feature extractor</a> for audio, and <a href="main_classes/processors">processor</a> for multimodal inputs).</li> <li>All of these classes can be initialized in a simple and unified way from pretrained instances by using a common
<code>from_pretrained()</code> method which downloads (if needed), caches and
loads the related class instance and associated data (configurations’ hyperparameters, tokenizers’ vocabulary,
and models’ weights) from a pretrained checkpoint provided on <a href="https://huggingface.co/models" rel="nofollow">Hugging Face Hub</a> or your own saved checkpoint.</li> <li>On top of those three base classes, the library provides two APIs: <a href="/docs/transformers/pr_31098/en/main_classes/pipelines#transformers.pipeline">pipeline()</a> for quickly
using a model for inference on a given task and <a href="/docs/transformers/pr_31098/en/main_classes/trainer#transformers.Trainer">Trainer</a> to quickly train or fine-tune a PyTorch model (all TensorFlow models are compatible with <code>Keras.fit</code>).</li> <li>As a consequence, this library is NOT a modular toolbox of building blocks for neural nets. If you want to
extend or build upon the library, just use regular Python, PyTorch, TensorFlow, Keras modules and inherit from the base
classes of the library to reuse functionalities like model loading and saving. If you’d like to learn more about our coding philosophy for models, check out our <a href="https://huggingface.co/blog/transformers-design-philosophy" rel="nofollow">Repeat Yourself</a> blog post.</li>`,I,c,ne="<li>Provide state-of-the-art models with performances as close as possible to the original models:</li>",q,y,le=`<li>We provide at least one example for each architecture which reproduces a result provided by the official authors
of said architecture.</li> <li>The code is usually as close to the original code base as possible which means some PyTorch code may be not as
<em>pytorchic</em> as it could be as a result of being converted TensorFlow code and vice versa.</li>`,F,b,re="A few other goals:",U,w,de="<li><p>Expose the models’ internals as consistently as possible:</p> <ul><li>We give access, using a single API, to the full hidden-states and attention weights.</li> <li>The preprocessing classes and base model APIs are standardized to easily switch between models.</li></ul></li> <li><p>Incorporate a subjective selection of promising tools for fine-tuning and investigating these models:</p> <ul><li>A simple and consistent way to add new tokens to the vocabulary and embeddings for fine-tuning.</li> <li>Simple ways to mask and prune Transformer heads.</li></ul></li> <li><p>Easily switch between PyTorch, TensorFlow 2.0 and Flax, allowing training with one framework and inference with another.</p></li>",O,v,S,_,ce="The library is built around three types of classes for each model:",K,x,he='<li><strong>Model classes</strong> can be PyTorch models (<a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a>), Keras models (<a href="https://www.tensorflow.org/api_docs/python/tf/keras/Model" rel="nofollow">tf.keras.Model</a>) or JAX/Flax models (<a href="https://flax.readthedocs.io/en/latest/api_reference/flax.linen/module.html" rel="nofollow">flax.linen.Module</a>) that work with the pretrained weights provided in the library.</li> <li><strong>Configuration classes</strong> store the hyperparameters required to build a model (such as the number of layers and hidden size). You don’t always need to instantiate these yourself. In particular, if you are using a pretrained model without any modification, creating the model will automatically take care of instantiating the configuration (which is part of the model).</li> <li><strong>Preprocessing classes</strong> convert the raw data into a format accepted by the model. A <a href="main_classes/tokenizer">tokenizer</a> stores the vocabulary for each model and provide methods for encoding and decoding strings in a list of token embedding indices to be fed to a model. <a href="main_classes/image_processor">Image processors</a> preprocess vision inputs, <a href="main_classes/feature_extractor">feature extractors</a> preprocess audio inputs, and a <a href="main_classes/processors">processor</a> handles multimodal inputs.</li>',W,T,ue="All these classes can be instantiated from pretrained instances, saved locally, and shared on the Hub with three methods:",N,M,fe=`<li><code>from_pretrained()</code> lets you instantiate a model, configuration, and preprocessing class from a pretrained version either
provided by the library itself (the supported models can be found on the <a href="https://huggingface.co/models" rel="nofollow">Model Hub</a>) or
stored locally (or on a server) by the user.</li> <li><code>save_pretrained()</code> lets you save a model, configuration, and preprocessing class locally so that it can be reloaded using
<code>from_pretrained()</code>.</li> <li><code>push_to_hub()</code> lets you share a model, configuration, and a preprocessing class to the Hub, so it is easily accessible to everyone.</li>`,R,L,Y,k,B;return h=new me({props:{title:"Philosophy",local:"philosophy",headingTag:"h1"}}),v=new me({props:{title:"Main concepts",local:"main-concepts",headingTag:"h2"}}),L=new Te({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/philosophy.md"}}),{c(){d=n("meta"),C=o(),$=n("p"),P=o(),G(h.$$.fragment),H=o(),u=n("p"),u.textContent=te,A=o(),f=n("ul"),f.innerHTML=se,j=o(),p=n("p"),p.textContent=ae,z=o(),m=n("ol"),m.innerHTML=oe,E=o(),g=n("ul"),g.innerHTML=ie,I=o(),c=n("ol"),c.innerHTML=ne,q=o(),y=n("ul"),y.innerHTML=le,F=o(),b=n("p"),b.textContent=re,U=o(),w=n("ul"),w.innerHTML=de,O=o(),G(v.$$.fragment),S=o(),_=n("p"),_.textContent=ce,K=o(),x=n("ul"),x.innerHTML=he,W=o(),T=n("p"),T.textContent=ue,N=o(),M=n("ul"),M.innerHTML=fe,R=o(),G(L.$$.fragment),Y=o(),k=n("p"),this.h()},l(e){const t=_e("svelte-u9bgzb",document.head);d=l(t,"META",{name:!0,content:!0}),t.forEach(s),C=i(e),$=l(e,"P",{}),pe($).forEach(s),P=i(e),J(h.$$.fragment,e),H=i(e),u=l(e,"P",{"data-svelte-h":!0}),r(u)!=="svelte-1p1j4j2"&&(u.textContent=te),A=i(e),f=l(e,"UL",{"data-svelte-h":!0}),r(f)!=="svelte-15p34re"&&(f.innerHTML=se),j=i(e),p=l(e,"P",{"data-svelte-h":!0}),r(p)!=="svelte-l3cofq"&&(p.textContent=ae),z=i(e),m=l(e,"OL",{"data-svelte-h":!0}),r(m)!=="svelte-a039tw"&&(m.innerHTML=oe),E=i(e),g=l(e,"UL",{"data-svelte-h":!0}),r(g)!=="svelte-nj882e"&&(g.innerHTML=ie),I=i(e),c=l(e,"OL",{start:!0,"data-svelte-h":!0}),r(c)!=="svelte-1j3ty0h"&&(c.innerHTML=ne),q=i(e),y=l(e,"UL",{"data-svelte-h":!0}),r(y)!=="svelte-eaof5h"&&(y.innerHTML=le),F=i(e),b=l(e,"P",{"data-svelte-h":!0}),r(b)!=="svelte-16fl7yl"&&(b.textContent=re),U=i(e),w=l(e,"UL",{"data-svelte-h":!0}),r(w)!=="svelte-r5ixu4"&&(w.innerHTML=de),O=i(e),J(v.$$.fragment,e),S=i(e),_=l(e,"P",{"data-svelte-h":!0}),r(_)!=="svelte-60ebt4"&&(_.textContent=ce),K=i(e),x=l(e,"UL",{"data-svelte-h":!0}),r(x)!=="svelte-316anx"&&(x.innerHTML=he),W=i(e),T=l(e,"P",{"data-svelte-h":!0}),r(T)!=="svelte-ff8m9n"&&(T.textContent=ue),N=i(e),M=l(e,"UL",{"data-svelte-h":!0}),r(M)!=="svelte-1p0er3n"&&(M.innerHTML=fe),R=i(e),J(L.$$.fragment,e),Y=i(e),k=l(e,"P",{}),pe(k).forEach(s),this.h()},h(){X(d,"name","hf:doc:metadata"),X(d,"content",Le),X(c,"start","2")},m(e,t){xe(document.head,d),a(e,C,t),a(e,$,t),a(e,P,t),D(h,e,t),a(e,H,t),a(e,u,t),a(e,A,t),a(e,f,t),a(e,j,t),a(e,p,t),a(e,z,t),a(e,m,t),a(e,E,t),a(e,g,t),a(e,I,t),a(e,c,t),a(e,q,t),a(e,y,t),a(e,F,t),a(e,b,t),a(e,U,t),a(e,w,t),a(e,O,t),D(v,e,t),a(e,S,t),a(e,_,t),a(e,K,t),a(e,x,t),a(e,W,t),a(e,T,t),a(e,N,t),a(e,M,t),a(e,R,t),D(L,e,t),a(e,Y,t),a(e,k,t),B=!0},p:ye,i(e){B||(Q(h.$$.fragment,e),Q(v.$$.fragment,e),Q(L.$$.fragment,e),B=!0)},o(e){V(h.$$.fragment,e),V(v.$$.fragment,e),V(L.$$.fragment,e),B=!1},d(e){e&&(s(C),s($),s(P),s(H),s(u),s(A),s(f),s(j),s(p),s(z),s(m),s(E),s(g),s(I),s(c),s(q),s(y),s(F),s(b),s(U),s(w),s(O),s(S),s(_),s(K),s(x),s(W),s(T),s(N),s(M),s(R),s(Y),s(k)),s(d),Z(h,e),Z(v,e),Z(L,e)}}}const Le='{"title":"Philosophy","local":"philosophy","sections":[{"title":"Main concepts","local":"main-concepts","sections":[],"depth":2}],"depth":1}';function $e(ee){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class He extends we{constructor(d){super(),ve(this,d,$e,Me,ge,{})}}export{He as component};
