Buckets:

rtrm's picture
download
raw
18.4 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Philosophy&quot;,&quot;local&quot;:&quot;philosophy&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Who this library is for&quot;,&quot;local&quot;:&quot;who-this-library-is-for&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;What you can expect&quot;,&quot;local&quot;:&quot;what-you-can-expect&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Core tenets&quot;,&quot;local&quot;:&quot;core-tenets&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Main classes&quot;,&quot;local&quot;:&quot;main-classes&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/transformers/pr_33962/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/entry/start.1776ac26.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/scheduler.31fdf58d.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/singletons.73ad6261.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/index.252883d5.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/paths.7e4d6052.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/entry/app.d2b9a7d8.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/preload-helper.769e5991.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/index.2f76fdf0.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/nodes/0.29a76cb1.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/nodes/514.0457ca57.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/CopyLLMTxtMenu.9922688f.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/globals.7f7f1b26.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/IconCopy.ac192424.js">
<link rel="modulepreload" href="/docs/transformers/pr_33962/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.4975a63c.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Philosophy&quot;,&quot;local&quot;:&quot;philosophy&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Who this library is for&quot;,&quot;local&quot;:&quot;who-this-library-is-for&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;What you can expect&quot;,&quot;local&quot;:&quot;what-you-can-expect&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Core tenets&quot;,&quot;local&quot;:&quot;core-tenets&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Main classes&quot;,&quot;local&quot;:&quot;main-classes&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 max-sm:gap-0.5 h-6 max-sm:h-5 px-2 max-sm:px-1.5 text-[11px] max-sm:text-[9px] font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0"><svg class="w-3 h-3 max-sm:w-2.5 max-sm:h-2.5" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-6 max-sm:h-5 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible w-3 h-3 max-sm:w-2.5 max-sm:h-2.5 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="philosophy" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#philosophy"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Philosophy</span></h1> <p data-svelte-h="svelte-uoye1u">Transformers is a PyTorch-first library. It provides models that are faithful to their papers, easy to use, and easy to hack.</p> <p data-svelte-h="svelte-130kqhs">A longer, in-depth article with examples, visualizations and timelines is available <a href="https://huggingface.co/spaces/transformers-community/Transformers-tenets" rel="nofollow">here</a> as our canonical reference.</p> <blockquote class="note" data-svelte-h="svelte-13l11ww"><p>Our philosophy evolves through practice. What follows are out current, stable principles.</p></blockquote> <h2 class="relative group"><a id="who-this-library-is-for" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#who-this-library-is-for"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Who this library is for</span></h2> <ul data-svelte-h="svelte-n59a3v"><li>Researchers and educators exploring or extending model architectures.</li> <li>Practitioners fine-tuning, evaluating, or serving models.</li> <li>Engineers who want a pretrained model that “just works” with a predictable API.</li></ul> <h2 class="relative group"><a id="what-you-can-expect" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#what-you-can-expect"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>What you can expect</span></h2> <ul data-svelte-h="svelte-12dx85k"><li><p>Three core classes are required for 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">Tokenizers</a> handle NLP, <a href="main_classes/image_processor">image processors</a> handle images, <a href="main_classes/video_processor">video processors</a> handle videos, <a href="main_classes/feature_extractor">feature extractors</a> handle audio, and <a href="main_classes/processors">processors</a> handle multimodal inputs.</p></li> <li><p>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, processors’ parameters
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.</p></li> <li><p>On top of those three base classes, the library provides two APIs: <a href="/docs/transformers/pr_33962/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_33962/en/main_classes/trainer#transformers.Trainer">Trainer</a> to quickly train or fine-tune a PyTorch model.</p></li></ul> <h2 class="relative group"><a id="core-tenets" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#core-tenets"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Core tenets</span></h2> <p data-svelte-h="svelte-186zfg5">The following tenets solidified over time, and they’re detailed in our new philosophy <a href="https://huggingface.co/spaces/transformers-community/Transformers-tenets" rel="nofollow">blog post</a>. They guide maintainer decisions when reviewing PRs and contributions.</p> <blockquote data-svelte-h="svelte-1otm2f0"><ul><li><strong>Source of Truth.</strong> Implementations must be faithful to official results and intended behavior.</li> <li><strong>One Model, One File.</strong> Core inference/training logic is visible top-to-bottom in the model file users read.</li> <li><strong>Code is the Product.</strong> Optimize for reading and diff-ing. Prefer explicit names over clever indirection.</li> <li><strong>Standardize, Don’t Abstract.</strong> Keep model-specific behavior in the model. Use shared interfaces only for generic infra.</li> <li><strong>DRY*</strong> (Repeat when it helps users). End-user modeling files remain self-contained. Infra is factored out.</li> <li><strong>Minimal User API.</strong> Few codepaths, predictable kwargs, stable methods.</li> <li><strong>Backwards Compatibility.</strong> Public surfaces should not break. Old Hub artifacts have to keep working..</li> <li><strong>Consistent Public Surface.</strong> Naming, outputs, and optional diagnostics are aligned and tested.</li></ul></blockquote> <h2 class="relative group"><a id="main-classes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#main-classes"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Main classes</span></h2> <ul data-svelte-h="svelte-kbmqlf"><li><p><a href="main_classes/configuration"><strong>Configuration classes</strong></a> store the hyperparameters required to build a model. These include the number of layers and hidden size. You don’t always need to instantiate these yourself. When using a pretrained model without modification, creating the model automatically instantiates the configuration.</p></li> <li><p><strong>Model classes</strong> are PyTorch models (<a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a>), wrapped by at least a <a href="https://huggingface.co/docs/transformers/v4.57.0/en/main_classes/model#transformers.PreTrainedModel" rel="nofollow">PreTrainedModel</a>.</p></li> <li><p><strong>Modular transformers.</strong> Contributors write a small <code>modular_*.py</code> shard that declares reuse from existing components. The library auto-expands this into the visible <code>modeling_*.py</code> file that users read/debug. Maintainers review the shard; users hack the expanded file. This preserves “One Model, One File” without boilerplate drift. See <a href="https://huggingface.co/docs/transformers/en/modular_transformers" rel="nofollow">the contributing documentation</a> for more information.</p></li> <li><p><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 provides methods for encoding and decoding strings in a list of token embedding indices. <a href="main_classes/image_processor">Image processors</a> preprocess vision inputs, <a href="https://huggingface.co/docs/transformers/en/main_classes/video_processor" rel="nofollow">video processors</a> preprocess videos inputs, <a href="main_classes/feature_extractor">feature extractors</a> preprocess audio inputs, and <a href="main_classes/processors">processors</a> preprocess multimodal inputs.</p></li></ul> <p data-svelte-h="svelte-ff8m9n">All these classes can be instantiated from pretrained instances, saved locally, and shared on the Hub with three methods:</p> <ul data-svelte-h="svelte-1p0er3n"><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></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/philosophy.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1yuubte = {
assets: "/docs/transformers/pr_33962/en",
base: "/docs/transformers/pr_33962/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/transformers/pr_33962/en/_app/immutable/entry/start.1776ac26.js"),
import("/docs/transformers/pr_33962/en/_app/immutable/entry/app.d2b9a7d8.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 514],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
18.4 kB
·
Xet hash:
5e2893d86b825f92bf3e8d7adfd1e229beee13d4e849bfcc2f18b50f50a93edc

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.