import{s as ms,o as gs,n as ds}from"../chunks/scheduler.9bc65507.js";import{S as us,i as hs,g as o,s as a,r as d,m as is,A as fs,h as r,f as n,c as l,j as I,u as m,x as p,n as ps,k as C,l as bs,y as i,a as s,v as g,d as u,t as h,w as f}from"../chunks/index.707bf1b6.js";import{D as Ie}from"../chunks/Docstring.570ddb64.js";import{C as Z}from"../chunks/CodeBlock.54a9f38d.js";import{E as cs}from"../chunks/ExampleCodeBlock.bc2be6bc.js";import{H as x,E as ks}from"../chunks/EditOnGithub.922df6ba.js";function _s(Ce){let b,z="Examples:",w,_,M;return _=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwc3JjX2xhbmclM0QlMjJlbmdfTGF0biUyMiUyQyUyMHRndF9sYW5nJTNEJTIyZnJhX0xhdG4lMjIlMEEpJTBBZXhhbXBsZV9lbmdsaXNoX3BocmFzZSUyMCUzRCUyMCUyMiUyMFVOJTIwQ2hpZWYlMjBTYXlzJTIwVGhlcmUlMjBJcyUyME5vJTIwTWlsaXRhcnklMjBTb2x1dGlvbiUyMGluJTIwU3lyaWElMjIlMEFleHBlY3RlZF90cmFuc2xhdGlvbl9mcmVuY2glMjAlM0QlMjAlMjJMZSUyMGNoZWYlMjBkZSUyMGwnT05VJTIwYWZmaXJtZSUyMHF1J2lsJTIwbid5JTIwYSUyMHBhcyUyMGRlJTIwc29sdXRpb24lMjBtaWxpdGFpcmUlMjBlbiUyMFN5cmllLiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihleGFtcGxlX2VuZ2xpc2hfcGhyYXNlJTJDJTIwdGV4dF90YXJnZXQlM0RleHBlY3RlZF90cmFuc2xhdGlvbl9mcmVuY2glMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, src_lang=<span class="hljs-string">&quot;eng_Latn&quot;</span>, tgt_lang=<span class="hljs-string">&quot;fra_Latn&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>example_english_phrase = <span class="hljs-string">&quot; UN Chief Says There Is No Military Solution in Syria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>expected_translation_french = <span class="hljs-string">&quot;Le chef de l&#x27;ONU affirme qu&#x27;il n&#x27;y a pas de solution militaire en Syrie.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(example_english_phrase, text_target=expected_translation_french, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`,wrap:!1}}),{c(){b=o("p"),b.textContent=z,w=a(),d(_.$$.fragment)},l(c){b=r(c,"P",{"data-svelte-h":!0}),p(b)!=="svelte-kvfsh7"&&(b.textContent=z),w=l(c),m(_.$$.fragment,c)},m(c,v){s(c,b,v),s(c,w,v),g(_,c,v),M=!0},p:ds,i(c){M||(u(_.$$.fragment,c),M=!0)},o(c){h(_.$$.fragment,c),M=!1},d(c){c&&(n(b),n(w)),f(_,c)}}}function ys(Ce){let b,z="Examples:",w,_,M;return _=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXJGYXN0JTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwTmxsYlRva2VuaXplckZhc3QuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmZhY2Vib29rJTJGbmxsYi0yMDAtZGlzdGlsbGVkLTYwME0lMjIlMkMlMjBzcmNfbGFuZyUzRCUyMmVuZ19MYXRuJTIyJTJDJTIwdGd0X2xhbmclM0QlMjJmcmFfTGF0biUyMiUwQSklMEFleGFtcGxlX2VuZ2xpc2hfcGhyYXNlJTIwJTNEJTIwJTIyJTIwVU4lMjBDaGllZiUyMFNheXMlMjBUaGVyZSUyMElzJTIwTm8lMjBNaWxpdGFyeSUyMFNvbHV0aW9uJTIwaW4lMjBTeXJpYSUyMiUwQWV4cGVjdGVkX3RyYW5zbGF0aW9uX2ZyZW5jaCUyMCUzRCUyMCUyMkxlJTIwY2hlZiUyMGRlJTIwbCdPTlUlMjBhZmZpcm1lJTIwcXUnaWwlMjBuJ3klMjBhJTIwcGFzJTIwZGUlMjBzb2x1dGlvbiUyMG1pbGl0YWlyZSUyMGVuJTIwU3lyaWUuJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGV4YW1wbGVfZW5nbGlzaF9waHJhc2UlMkMlMjB0ZXh0X3RhcmdldCUzRGV4cGVjdGVkX3RyYW5zbGF0aW9uX2ZyZW5jaCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizerFast

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizerFast.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, src_lang=<span class="hljs-string">&quot;eng_Latn&quot;</span>, tgt_lang=<span class="hljs-string">&quot;fra_Latn&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>example_english_phrase = <span class="hljs-string">&quot; UN Chief Says There Is No Military Solution in Syria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>expected_translation_french = <span class="hljs-string">&quot;Le chef de l&#x27;ONU affirme qu&#x27;il n&#x27;y a pas de solution militaire en Syrie.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(example_english_phrase, text_target=expected_translation_french, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`,wrap:!1}}),{c(){b=o("p"),b.textContent=z,w=a(),d(_.$$.fragment)},l(c){b=r(c,"P",{"data-svelte-h":!0}),p(b)!=="svelte-kvfsh7"&&(b.textContent=z),w=l(c),m(_.$$.fragment,c)},m(c,v){s(c,b,v),s(c,w,v),g(_,c,v),M=!0},p:ds,i(c){M||(u(_.$$.fragment,c),M=!0)},o(c){h(_.$$.fragment,c),M=!1},d(c){c&&(n(b),n(w)),f(_,c)}}}function Ms(Ce){let b,z,w,_,M,c,v,st,V,Mn=`<strong>DISCLAIMER:</strong> The default behaviour for the tokenizer was fixed and thus changed in April 2023.
The previous version adds <code>[self.eos_token_id, self.cur_lang_code]</code> at the end of the token sequence for both target and source tokenization. This is wrong as the NLLB paper mentions (page 48, 6.1.1. Model Architecture) :`,at,X,Tn=`<em>Note that we prefix the source sequence with the source language, as opposed to the target
language as previously done in several works (Arivazhagan et al., 2019; Johnson et al.,
2017). This is primarily because we prioritize optimizing zero-shot performance of our
model on any pair of 200 languages at a minor cost to supervised performance.</em>`,lt,B,wn="Previous behaviour:",ot,H,rt,E,vn="New behaviour",it,S,pt,Y,Jn="Enabling the old behaviour can be done as follows:",ct,A,dt,D,jn='For more details, feel free to check the linked <a href="https://github.com/huggingface/transformers/pull/22313" rel="nofollow">PR</a> and <a href="https://github.com/huggingface/transformers/issues/19943" rel="nofollow">Issue</a>.',mt,Q,gt,P,$n=`The NLLB model was presented in <a href="https://arxiv.org/abs/2207.04672" rel="nofollow">No Language Left Behind: Scaling Human-Centered Machine Translation</a> by Marta R. Costa-jussà, James Cross, Onur Çelebi,
Maha Elbayad, Kenneth Heafield, Kevin Heffernan, Elahe Kalbassi, Janice Lam, Daniel Licht, Jean Maillard, Anna Sun, Skyler Wang, Guillaume Wenzek, Al Youngblood, Bapi Akula,
Loic Barrault, Gabriel Mejia Gonzalez, Prangthip Hansanti, John Hoffman, Semarley Jarrett, Kaushik Ram Sadagopan, Dirk Rowe, Shannon Spruit, Chau Tran, Pierre Andrews,
Necip Fazil Ayan, Shruti Bhosale, Sergey Edunov, Angela Fan, Cynthia Gao, Vedanuj Goswami, Francisco Guzmán, Philipp Koehn, Alexandre Mourachko, Christophe Ropers,
Safiyyah Saleem, Holger Schwenk, and Jeff Wang.`,ut,K,xn="The abstract of the paper is the following:",ht,O,Un=`<em>Driven by the goal of eradicating language barriers on a global scale, machine translation has solidified itself as a key focus of artificial intelligence research today.
However, such efforts have coalesced around a small subset of languages, leaving behind the vast majority of mostly low-resource languages. What does it take to break the
200 language barrier while ensuring safe, high quality results, all while keeping ethical considerations in mind? In No Language Left Behind, we took on this challenge by
first contextualizing the need for low-resource language translation support through exploratory interviews with native speakers. Then, we created datasets and models aimed
at narrowing the performance gap between low and high-resource languages. More specifically, we developed a conditional compute model based on Sparsely Gated Mixture of
Experts that is trained on data obtained with novel and effective data mining techniques tailored for low-resource languages. We propose multiple architectural and training
improvements to counteract overfitting while training on thousands of tasks. Critically, we evaluated the performance of over 40,000 different translation directions using
a human-translated benchmark, Flores-200, and combined human evaluation with a novel toxicity benchmark covering all languages in Flores-200 to assess translation safety.
Our model achieves an improvement of 44% BLEU relative to the previous state-of-the-art, laying important groundwork towards realizing a universal translation system.</em>`,ft,ee,zn="This implementation contains the dense models available on release.",bt,te,qn='<strong>The sparse model NLLB-MoE (Mixture of Expert) is now available! More details <a href="nllb-moe">here</a></strong>',kt,ne,Nn='This model was contributed by <a href="https://huggingface.co/lysandre" rel="nofollow">Lysandre</a>. The authors’ code can be found <a href="https://github.com/facebookresearch/fairseq/tree/nllb" rel="nofollow">here</a>.',_t,se,yt,ae,Gn=`While generating the target text set the <code>forced_bos_token_id</code> to the target language id. The following
example shows how to translate English to French using the <em>facebook/nllb-200-distilled-600M</em> model.`,Mt,le,In=`Note that we’re using the BCP-47 code for French <code>fra_Latn</code>. See <a href="https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200" rel="nofollow">here</a>
for the list of all BCP-47 in the Flores 200 dataset.`,Tt,oe,wt,re,vt,ie,Cn=`English (<code>eng_Latn</code>) is set as the default language from which to translate. In order to specify that you’d like to translate from a different language,
you should specify the BCP-47 code in the <code>src_lang</code> keyword argument of the tokenizer initialization.`,Jt,pe,Zn="See example below for a translation from romanian to german:",jt,ce,$t,de,xt,me,Ln='<li><a href="../tasks/translation">Translation task guide</a></li> <li><a href="../tasks/summarization">Summarization task guide</a></li>',Ut,ge,zt,T,ue,Dt,Ze,Wn="Construct an NLLB tokenizer.",Qt,Le,Rn=`Adapted from <a href="/docs/transformers/main/en/model_doc/roberta#transformers.RobertaTokenizer">RobertaTokenizer</a> and <a href="/docs/transformers/main/en/model_doc/xlnet#transformers.XLNetTokenizer">XLNetTokenizer</a>. Based on
<a href="https://github.com/google/sentencepiece" rel="nofollow">SentencePiece</a>.`,Pt,We,Fn="The tokenization method is <code>&lt;tokens&gt; &lt;eos&gt; &lt;language code&gt;</code> for source language documents, and `&lt;language code&gt;",Kt,L,Ot,$,he,en,Re,Vn=`Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An NLLB sequence has the following format, where <code>X</code> represents the sequence:`,tn,Fe,Xn="<li><code>input_ids</code> (for encoder) <code>X [eos, src_lang_code]</code></li> <li><code>decoder_input_ids</code>: (for decoder) <code>X [eos, tgt_lang_code]</code></li>",nn,Ve,Bn=`BOS is never used. Pairs of sequences are not the expected use case, but they will be handled without a
separator.`,qt,fe,Nt,k,be,sn,Xe,Hn=`Construct a “fast” NLLB tokenizer (backed by HuggingFace’s <em>tokenizers</em> library). Based on
<a href="https://huggingface.co/docs/tokenizers/python/latest/components.html?highlight=BPE#models" rel="nofollow">BPE</a>.`,an,Be,En=`This tokenizer inherits from <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast">PreTrainedTokenizerFast</a> which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.`,ln,He,Sn="The tokenization method is <code>&lt;tokens&gt; &lt;eos&gt; &lt;language code&gt;</code> for source language documents, and `&lt;language code&gt;",on,W,rn,j,ke,pn,Ee,Yn=`Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. The special tokens depend on calling set_lang.`,cn,Se,An="An NLLB sequence has the following format, where <code>X</code> represents the sequence:",dn,Ye,Dn="<li><code>input_ids</code> (for encoder) <code>X [eos, src_lang_code]</code></li> <li><code>decoder_input_ids</code>: (for decoder) <code>X [eos, tgt_lang_code]</code></li>",mn,Ae,Qn=`BOS is never used. Pairs of sequences are not the expected use case, but they will be handled without a
separator.`,gn,R,_e,un,De,Pn=`Create a mask from the two sequences passed to be used in a sequence-pair classification task. nllb does not
make use of token type ids, therefore a list of zeros is returned.`,hn,q,ye,fn,Qe,Kn="Reset the special tokens to the source lang setting.",bn,Pe,On="<li>In legacy mode: No prefix and suffix=[eos, src_lang_code].</li> <li>In default mode: Prefix=[src_lang_code], suffix = [eos]</li>",kn,N,Me,_n,Ke,es="Reset the special tokens to the target lang setting.",yn,Oe,ts="<li>In legacy mode: No prefix and suffix=[eos, tgt_lang_code].</li> <li>In default mode: Prefix=[tgt_lang_code], suffix = [eos]</li>",Gt,Te,It,we,ns="Flash Attention 2 is a faster, optimized version of the attention scores computation which relies on <code>cuda</code> kernels.",Ct,ve,Zt,Je,ss='First, check whether your hardware is compatible with Flash Attention 2. The latest list of compatible hardware can be found in the <a href="https://github.com/Dao-AILab/flash-attention#installation-and-features" rel="nofollow">official documentation</a>.',Lt,je,as='Next, <a href="https://github.com/Dao-AILab/flash-attention#installation-and-features" rel="nofollow">install</a> the latest version of Flash Attention 2:',Wt,$e,Rt,xe,Ft,Ue,ls='To load a model using Flash Attention 2, we can pass the argument <code>attn_implementation=&quot;flash_attention_2&quot;</code> to <a href="https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained" rel="nofollow"><code>.from_pretrained</code></a>. You can use either <code>torch.float16</code> or <code>torch.bfloat16</code> precision.',Vt,ze,Xt,qe,Bt,Ne,os="Below is an expected speedup diagram that compares pure inference time between the native implementation and the Flash Attention 2.",Ht,F,rs='<img src="https://huggingface.co/datasets/visheratin/documentation-images/resolve/main/nllb-speedup.webp"/>',Et,Ge,St,nt,Yt;return M=new x({props:{title:"NLLB",local:"nllb",headingTag:"h1"}}),v=new x({props:{title:"Updated tokenizer behavior",local:"transformers.NllbTokenizer",headingTag:"h2"}}),H=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQXRva2VuaXplciglMjJIb3clMjB3YXMlMjB5b3VyJTIwZGF5JTNGJTIyKS5pbnB1dF9pZHMlMEElMEElMjMlMjAyJTNBJTIwJyUzQyUyRnMlM0UnJTBBJTIzJTIwMjU2MDQ3JTIwJTNBJTIwJ2VuZ19MYXRuJw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer(<span class="hljs-string">&quot;How was your day?&quot;</span>).input_ids
[<span class="hljs-number">13374</span>, <span class="hljs-number">1398</span>, <span class="hljs-number">4260</span>, <span class="hljs-number">4039</span>, <span class="hljs-number">248130</span>, <span class="hljs-number">2</span>, <span class="hljs-number">256047</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 2: &#x27;&lt;/s&gt;&#x27;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 256047 : &#x27;eng_Latn&#x27;</span>`,wrap:!1}}),S=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQXRva2VuaXplciglMjJIb3clMjB3YXMlMjB5b3VyJTIwZGF5JTNGJTIyKS5pbnB1dF9pZHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer(<span class="hljs-string">&quot;How was your day?&quot;</span>).input_ids
[<span class="hljs-number">256047</span>, <span class="hljs-number">13374</span>, <span class="hljs-number">1398</span>, <span class="hljs-number">4260</span>, <span class="hljs-number">4039</span>, <span class="hljs-number">248130</span>, <span class="hljs-number">2</span>]`,wrap:!1}}),A=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwbGVnYWN5X2JlaGF2aW91ciUzRFRydWUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, legacy_behaviour=<span class="hljs-literal">True</span>)`,wrap:!1}}),Q=new x({props:{title:"Overview",local:"overview",headingTag:"h2"}}),se=new x({props:{title:"Generating with NLLB",local:"generating-with-nllb",headingTag:"h2"}}),oe=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQSUwQWFydGljbGUlMjAlM0QlMjAlMjJVTiUyMENoaWVmJTIwc2F5cyUyMHRoZXJlJTIwaXMlMjBubyUyMG1pbGl0YXJ5JTIwc29sdXRpb24lMjBpbiUyMFN5cmlhJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGFydGljbGUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQXRyYW5zbGF0ZWRfdG9rZW5zJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dHMlMkMlMjBmb3JjZWRfYm9zX3Rva2VuX2lkJTNEdG9rZW5pemVyLmxhbmdfY29kZV90b19pZCU1QiUyMmZyYV9MYXRuJTIyJTVEJTJDJTIwbWF4X2xlbmd0aCUzRDMwJTBBKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUodHJhbnNsYXRlZF90b2tlbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;UN Chief says there is no military solution in Syria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.lang_code_to_id[<span class="hljs-string">&quot;fra_Latn&quot;</span>], max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
Le chef de l<span class="hljs-string">&#x27;ONU dit qu&#x27;</span>il n<span class="hljs-string">&#x27;y a pas de solution militaire en Syrie</span>`,wrap:!1}}),re=new x({props:{title:"Generating from any other language than English",local:"generating-from-any-other-language-than-english",headingTag:"h3"}}),ce=new Z({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwdG9rZW4lM0RUcnVlJTJDJTIwc3JjX2xhbmclM0QlMjJyb25fTGF0biUyMiUwQSklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZubGxiLTIwMC1kaXN0aWxsZWQtNjAwTSUyMiUyQyUyMHRva2VuJTNEVHJ1ZSklMEElMEFhcnRpY2xlJTIwJTNEJTIwJTIyJUM1JTlFZWZ1bCUyME9OVSUyMHNwdW5lJTIwYyVDNCU4MyUyMG51JTIwZXhpc3QlQzQlODMlMjBvJTIwc29sdSVDNSVBM2llJTIwbWlsaXRhciVDNCU4MyUyMCVDMyVBRW4lMjBTaXJpYSUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihhcnRpY2xlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEF0cmFuc2xhdGVkX3Rva2VucyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCoqaW5wdXRzJTJDJTIwZm9yY2VkX2Jvc190b2tlbl9pZCUzRHRva2VuaXplci5sYW5nX2NvZGVfdG9faWQlNUIlMjJkZXVfTGF0biUyMiU1RCUyQyUyMG1heF9sZW5ndGglM0QzMCUwQSklMEF0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKHRyYW5zbGF0ZWRfdG9rZW5zJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, token=<span class="hljs-literal">True</span>, src_lang=<span class="hljs-string">&quot;ron_Latn&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, token=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;Şeful ONU spune că nu există o soluţie militară în Siria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.lang_code_to_id[<span class="hljs-string">&quot;deu_Latn&quot;</span>], max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
UN-Chef sagt, es gibt keine militärische Lösung <span class="hljs-keyword">in</span> Syrien`,wrap:!1}}),de=new x({props:{title:"Resources",local:"resources",headingTag:"h2"}}),ge=new x({props:{title:"NllbTokenizer",local:"nllbtokenizer",headingTag:"h2"}}),ue=new Ie({props:{name:"class transformers.NllbTokenizer",anchor:"transformers.NllbTokenizer",parameters:[{name:"vocab_file",val:""},{name:"bos_token",val:" = '<s>'"},{name:"eos_token",val:" = '</s>'"},{name:"sep_token",val:" = '</s>'"},{name:"cls_token",val:" = '<s>'"},{name:"unk_token",val:" = '<unk>'"},{name:"pad_token",val:" = '<pad>'"},{name:"mask_token",val:" = '<mask>'"},{name:"tokenizer_file",val:" = None"},{name:"src_lang",val:" = None"},{name:"tgt_lang",val:" = None"},{name:"sp_model_kwargs",val:": Optional = None"},{name:"additional_special_tokens",val:" = None"},{name:"legacy_behaviour",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.NllbTokenizer.vocab_file",description:`<strong>vocab_file</strong> (<code>str</code>) &#x2014;
Path to the vocabulary file.`,name:"vocab_file"},{anchor:"transformers.NllbTokenizer.bos_token",description:`<strong>bos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the <code>cls_token</code>.</p>

					</div>`,name:"bos_token"},{anchor:"transformers.NllbTokenizer.eos_token",description:`<strong>eos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The end of sequence token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the <code>sep_token</code>.</p>

					</div>`,name:"eos_token"},{anchor:"transformers.NllbTokenizer.sep_token",description:`<strong>sep_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.`,name:"sep_token"},{anchor:"transformers.NllbTokenizer.cls_token",description:`<strong>cls_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.`,name:"cls_token"},{anchor:"transformers.NllbTokenizer.unk_token",description:`<strong>unk_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;unk&gt;&quot;</code>) &#x2014;
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.`,name:"unk_token"},{anchor:"transformers.NllbTokenizer.pad_token",description:`<strong>pad_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;pad&gt;&quot;</code>) &#x2014;
The token used for padding, for example when batching sequences of different lengths.`,name:"pad_token"},{anchor:"transformers.NllbTokenizer.mask_token",description:`<strong>mask_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;mask&gt;&quot;</code>) &#x2014;
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict.`,name:"mask_token"},{anchor:"transformers.NllbTokenizer.tokenizer_file",description:`<strong>tokenizer_file</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The path to a tokenizer file to use instead of the vocab file.`,name:"tokenizer_file"},{anchor:"transformers.NllbTokenizer.src_lang",description:`<strong>src_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as source language for translation.`,name:"src_lang"},{anchor:"transformers.NllbTokenizer.tgt_lang",description:`<strong>tgt_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as target language for translation.`,name:"tgt_lang"},{anchor:"transformers.NllbTokenizer.sp_model_kwargs",description:`<strong>sp_model_kwargs</strong> (<code>Dict[str, str]</code>) &#x2014;
Additional keyword arguments to pass to the model initialization.`,name:"sp_model_kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb.py#L36"}}),L=new cs({props:{anchor:"transformers.NllbTokenizer.example",$$slots:{default:[_s]},$$scope:{ctx:Ce}}}),he=new Ie({props:{name:"build_inputs_with_special_tokens",anchor:"transformers.NllbTokenizer.build_inputs_with_special_tokens",parameters:[{name:"token_ids_0",val:": List"},{name:"token_ids_1",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbTokenizer.build_inputs_with_special_tokens.token_ids_0",description:`<strong>token_ids_0</strong> (<code>List[int]</code>) &#x2014;
List of IDs to which the special tokens will be added.`,name:"token_ids_0"},{anchor:"transformers.NllbTokenizer.build_inputs_with_special_tokens.token_ids_1",description:`<strong>token_ids_1</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
Optional second list of IDs for sequence pairs.`,name:"token_ids_1"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb.py#L287",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>List of <a href="../glossary#input-ids">input IDs</a> with the appropriate special tokens.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>List[int]</code></p>
`}}),fe=new x({props:{title:"NllbTokenizerFast",local:"nllbtokenizerfast",headingTag:"h2"}}),be=new Ie({props:{name:"class transformers.NllbTokenizerFast",anchor:"transformers.NllbTokenizerFast",parameters:[{name:"vocab_file",val:" = None"},{name:"tokenizer_file",val:" = None"},{name:"bos_token",val:" = '<s>'"},{name:"eos_token",val:" = '</s>'"},{name:"sep_token",val:" = '</s>'"},{name:"cls_token",val:" = '<s>'"},{name:"unk_token",val:" = '<unk>'"},{name:"pad_token",val:" = '<pad>'"},{name:"mask_token",val:" = '<mask>'"},{name:"src_lang",val:" = None"},{name:"tgt_lang",val:" = None"},{name:"additional_special_tokens",val:" = None"},{name:"legacy_behaviour",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.NllbTokenizerFast.vocab_file",description:`<strong>vocab_file</strong> (<code>str</code>) &#x2014;
Path to the vocabulary file.`,name:"vocab_file"},{anchor:"transformers.NllbTokenizerFast.bos_token",description:`<strong>bos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the <code>cls_token</code>.</p>

					</div>`,name:"bos_token"},{anchor:"transformers.NllbTokenizerFast.eos_token",description:`<strong>eos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The end of sequence token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the <code>sep_token</code>.</p>

					</div>`,name:"eos_token"},{anchor:"transformers.NllbTokenizerFast.sep_token",description:`<strong>sep_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.`,name:"sep_token"},{anchor:"transformers.NllbTokenizerFast.cls_token",description:`<strong>cls_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.`,name:"cls_token"},{anchor:"transformers.NllbTokenizerFast.unk_token",description:`<strong>unk_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;unk&gt;&quot;</code>) &#x2014;
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.`,name:"unk_token"},{anchor:"transformers.NllbTokenizerFast.pad_token",description:`<strong>pad_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;pad&gt;&quot;</code>) &#x2014;
The token used for padding, for example when batching sequences of different lengths.`,name:"pad_token"},{anchor:"transformers.NllbTokenizerFast.mask_token",description:`<strong>mask_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;mask&gt;&quot;</code>) &#x2014;
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict.`,name:"mask_token"},{anchor:"transformers.NllbTokenizerFast.tokenizer_file",description:`<strong>tokenizer_file</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The path to a tokenizer file to use instead of the vocab file.`,name:"tokenizer_file"},{anchor:"transformers.NllbTokenizerFast.src_lang",description:`<strong>src_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as source language for translation.`,name:"src_lang"},{anchor:"transformers.NllbTokenizerFast.tgt_lang",description:`<strong>tgt_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as target language for translation.`,name:"tgt_lang"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L42"}}),W=new cs({props:{anchor:"transformers.NllbTokenizerFast.example",$$slots:{default:[ys]},$$scope:{ctx:Ce}}}),ke=new Ie({props:{name:"build_inputs_with_special_tokens",anchor:"transformers.NllbTokenizerFast.build_inputs_with_special_tokens",parameters:[{name:"token_ids_0",val:": List"},{name:"token_ids_1",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbTokenizerFast.build_inputs_with_special_tokens.token_ids_0",description:`<strong>token_ids_0</strong> (<code>List[int]</code>) &#x2014;
List of IDs to which the special tokens will be added.`,name:"token_ids_0"},{anchor:"transformers.NllbTokenizerFast.build_inputs_with_special_tokens.token_ids_1",description:`<strong>token_ids_1</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
Optional second list of IDs for sequence pairs.`,name:"token_ids_1"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L194",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>list of <a href="../glossary#input-ids">input IDs</a> with the appropriate special tokens.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>List[int]</code></p>
`}}),_e=new Ie({props:{name:"create_token_type_ids_from_sequences",anchor:"transformers.NllbTokenizerFast.create_token_type_ids_from_sequences",parameters:[{name:"token_ids_0",val:": List"},{name:"token_ids_1",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbTokenizerFast.create_token_type_ids_from_sequences.token_ids_0",description:`<strong>token_ids_0</strong> (<code>List[int]</code>) &#x2014;
List of IDs.`,name:"token_ids_0"},{anchor:"transformers.NllbTokenizerFast.create_token_type_ids_from_sequences.token_ids_1",description:`<strong>token_ids_1</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
Optional second list of IDs for sequence pairs.`,name:"token_ids_1"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L223",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>List of zeros.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>List[int]</code></p>
`}}),ye=new Ie({props:{name:"set_src_lang_special_tokens",anchor:"transformers.NllbTokenizerFast.set_src_lang_special_tokens",parameters:[{name:"src_lang",val:""}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L278"}}),Me=new Ie({props:{name:"set_tgt_lang_special_tokens",anchor:"transformers.NllbTokenizerFast.set_tgt_lang_special_tokens",parameters:[{name:"lang",val:": str"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L301"}}),Te=new x({props:{title:"Using Flash Attention 2",local:"using-flash-attention-2",headingTag:"h2"}}),ve=new x({props:{title:"Installation",local:"installation",headingTag:"h3"}}),$e=new Z({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwZmxhc2gtYXR0biUyMC0tbm8tYnVpbGQtaXNvbGF0aW9u",highlighted:"pip install -U flash-attn --no-build-isolation",wrap:!1}}),xe=new x({props:{title:"Usage",local:"usage",headingTag:"h3"}}),ze=new Z({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwYXR0bl9pbXBsZW1lbnRhdGlvbiUzRCUyMmZsYXNoX2F0dGVudGlvbl8yJTIyKS50byglMjJjdWRhJTIyKS5ldmFsKCklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQSUwQWFydGljbGUlMjAlM0QlMjAlMjIlQzUlOUVlZnVsJTIwT05VJTIwc3B1bmUlMjBjJUM0JTgzJTIwbnUlMjBleGlzdCVDNCU4MyUyMG8lMjBzb2x1JUM1JUEzaWUlMjBtaWxpdGFyJUM0JTgzJTIwJUMzJUFFbiUyMFNpcmlhJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGFydGljbGUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byglMjJjdWRhJTIyKSUwQSUwQXRyYW5zbGF0ZWRfdG9rZW5zJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dHMlMkMlMjBmb3JjZWRfYm9zX3Rva2VuX2lkJTNEdG9rZW5pemVyLmxhbmdfY29kZV90b19pZCU1QiUyMmRldV9MYXRuJTIyJTVEJTJDJTIwbWF4X2xlbmd0aCUzRDMwJTBBKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUodHJhbnNsYXRlZF90b2tlbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, torch_dtype=torch.float16, attn_implementation=<span class="hljs-string">&quot;flash_attention_2&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>).<span class="hljs-built_in">eval</span>()
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;Şeful ONU spune că nu există o soluţie militară în Siria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.lang_code_to_id[<span class="hljs-string">&quot;deu_Latn&quot;</span>], max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-string">&quot;UN-Chef sagt, es gibt keine militärische Lösung in Syrien&quot;</span>`,wrap:!1}}),qe=new x({props:{title:"Expected speedups",local:"expected-speedups",headingTag:"h3"}}),Ge=new ks({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/nllb.md"}}),{c(){b=o("meta"),z=a(),w=o("p"),_=a(),d(M.$$.fragment),c=a(),d(v.$$.fragment),st=a(),V=o("p"),V.innerHTML=Mn,at=a(),X=o("p"),X.innerHTML=Tn,lt=a(),B=o("p"),B.textContent=wn,ot=a(),d(H.$$.fragment),rt=a(),E=o("p"),E.textContent=vn,it=a(),d(S.$$.fragment),pt=a(),Y=o("p"),Y.textContent=Jn,ct=a(),d(A.$$.fragment),dt=a(),D=o("p"),D.innerHTML=jn,mt=a(),d(Q.$$.fragment),gt=a(),P=o("p"),P.innerHTML=$n,ut=a(),K=o("p"),K.textContent=xn,ht=a(),O=o("p"),O.innerHTML=Un,ft=a(),ee=o("p"),ee.textContent=zn,bt=a(),te=o("p"),te.innerHTML=qn,kt=a(),ne=o("p"),ne.innerHTML=Nn,_t=a(),d(se.$$.fragment),yt=a(),ae=o("p"),ae.innerHTML=Gn,Mt=a(),le=o("p"),le.innerHTML=In,Tt=a(),d(oe.$$.fragment),wt=a(),d(re.$$.fragment),vt=a(),ie=o("p"),ie.innerHTML=Cn,Jt=a(),pe=o("p"),pe.textContent=Zn,jt=a(),d(ce.$$.fragment),$t=a(),d(de.$$.fragment),xt=a(),me=o("ul"),me.innerHTML=Ln,Ut=a(),d(ge.$$.fragment),zt=a(),T=o("div"),d(ue.$$.fragment),Dt=a(),Ze=o("p"),Ze.textContent=Wn,Qt=a(),Le=o("p"),Le.innerHTML=Rn,Pt=a(),We=o("p"),We.innerHTML=Fn,Kt=is(`
<tokens> <eos>\` for target language documents.
`),d(L.$$.fragment),Ot=a(),$=o("div"),d(he.$$.fragment),en=a(),Re=o("p"),Re.innerHTML=Vn,tn=a(),Fe=o("ul"),Fe.innerHTML=Xn,nn=a(),Ve=o("p"),Ve.textContent=Bn,qt=a(),d(fe.$$.fragment),Nt=a(),k=o("div"),d(be.$$.fragment),sn=a(),Xe=o("p"),Xe.innerHTML=Hn,an=a(),Be=o("p"),Be.innerHTML=En,ln=a(),He=o("p"),He.innerHTML=Sn,on=is(`
<tokens> <eos>\` for target language documents.
`),d(W.$$.fragment),rn=a(),j=o("div"),d(ke.$$.fragment),pn=a(),Ee=o("p"),Ee.textContent=Yn,cn=a(),Se=o("p"),Se.innerHTML=An,dn=a(),Ye=o("ul"),Ye.innerHTML=Dn,mn=a(),Ae=o("p"),Ae.textContent=Qn,gn=a(),R=o("div"),d(_e.$$.fragment),un=a(),De=o("p"),De.textContent=Pn,hn=a(),q=o("div"),d(ye.$$.fragment),fn=a(),Qe=o("p"),Qe.textContent=Kn,bn=a(),Pe=o("ul"),Pe.innerHTML=On,kn=a(),N=o("div"),d(Me.$$.fragment),_n=a(),Ke=o("p"),Ke.textContent=es,yn=a(),Oe=o("ul"),Oe.innerHTML=ts,Gt=a(),d(Te.$$.fragment),It=a(),we=o("p"),we.innerHTML=ns,Ct=a(),d(ve.$$.fragment),Zt=a(),Je=o("p"),Je.innerHTML=ss,Lt=a(),je=o("p"),je.innerHTML=as,Wt=a(),d($e.$$.fragment),Rt=a(),d(xe.$$.fragment),Ft=a(),Ue=o("p"),Ue.innerHTML=ls,Vt=a(),d(ze.$$.fragment),Xt=a(),d(qe.$$.fragment),Bt=a(),Ne=o("p"),Ne.textContent=os,Ht=a(),F=o("div"),F.innerHTML=rs,Et=a(),d(Ge.$$.fragment),St=a(),nt=o("p"),this.h()},l(e){const t=fs("svelte-u9bgzb",document.head);b=r(t,"META",{name:!0,content:!0}),t.forEach(n),z=l(e),w=r(e,"P",{}),I(w).forEach(n),_=l(e),m(M.$$.fragment,e),c=l(e),m(v.$$.fragment,e),st=l(e),V=r(e,"P",{"data-svelte-h":!0}),p(V)!=="svelte-1bqcebz"&&(V.innerHTML=Mn),at=l(e),X=r(e,"P",{"data-svelte-h":!0}),p(X)!=="svelte-vrv0c7"&&(X.innerHTML=Tn),lt=l(e),B=r(e,"P",{"data-svelte-h":!0}),p(B)!=="svelte-vmuleo"&&(B.textContent=wn),ot=l(e),m(H.$$.fragment,e),rt=l(e),E=r(e,"P",{"data-svelte-h":!0}),p(E)!=="svelte-1qx2sah"&&(E.textContent=vn),it=l(e),m(S.$$.fragment,e),pt=l(e),Y=r(e,"P",{"data-svelte-h":!0}),p(Y)!=="svelte-obd9iw"&&(Y.textContent=Jn),ct=l(e),m(A.$$.fragment,e),dt=l(e),D=r(e,"P",{"data-svelte-h":!0}),p(D)!=="svelte-ib1bh"&&(D.innerHTML=jn),mt=l(e),m(Q.$$.fragment,e),gt=l(e),P=r(e,"P",{"data-svelte-h":!0}),p(P)!=="svelte-12x4cpm"&&(P.innerHTML=$n),ut=l(e),K=r(e,"P",{"data-svelte-h":!0}),p(K)!=="svelte-wu27l3"&&(K.textContent=xn),ht=l(e),O=r(e,"P",{"data-svelte-h":!0}),p(O)!=="svelte-1j7uypk"&&(O.innerHTML=Un),ft=l(e),ee=r(e,"P",{"data-svelte-h":!0}),p(ee)!=="svelte-1ayd4bm"&&(ee.textContent=zn),bt=l(e),te=r(e,"P",{"data-svelte-h":!0}),p(te)!=="svelte-qp2ubt"&&(te.innerHTML=qn),kt=l(e),ne=r(e,"P",{"data-svelte-h":!0}),p(ne)!=="svelte-ywl52z"&&(ne.innerHTML=Nn),_t=l(e),m(se.$$.fragment,e),yt=l(e),ae=r(e,"P",{"data-svelte-h":!0}),p(ae)!=="svelte-gz9jek"&&(ae.innerHTML=Gn),Mt=l(e),le=r(e,"P",{"data-svelte-h":!0}),p(le)!=="svelte-c2ujwv"&&(le.innerHTML=In),Tt=l(e),m(oe.$$.fragment,e),wt=l(e),m(re.$$.fragment,e),vt=l(e),ie=r(e,"P",{"data-svelte-h":!0}),p(ie)!=="svelte-ets0jr"&&(ie.innerHTML=Cn),Jt=l(e),pe=r(e,"P",{"data-svelte-h":!0}),p(pe)!=="svelte-14hvt1f"&&(pe.textContent=Zn),jt=l(e),m(ce.$$.fragment,e),$t=l(e),m(de.$$.fragment,e),xt=l(e),me=r(e,"UL",{"data-svelte-h":!0}),p(me)!=="svelte-6ej6p2"&&(me.innerHTML=Ln),Ut=l(e),m(ge.$$.fragment,e),zt=l(e),T=r(e,"DIV",{class:!0});var J=I(T);m(ue.$$.fragment,J),Dt=l(J),Ze=r(J,"P",{"data-svelte-h":!0}),p(Ze)!=="svelte-7mmiyn"&&(Ze.textContent=Wn),Qt=l(J),Le=r(J,"P",{"data-svelte-h":!0}),p(Le)!=="svelte-1serjol"&&(Le.innerHTML=Rn),Pt=l(J),We=r(J,"P",{"data-svelte-h":!0}),p(We)!=="svelte-1i8rh37"&&(We.innerHTML=Fn),Kt=ps(J,`
<tokens> <eos>\` for target language documents.
`),m(L.$$.fragment,J),Ot=l(J),$=r(J,"DIV",{class:!0});var U=I($);m(he.$$.fragment,U),en=l(U),Re=r(U,"P",{"data-svelte-h":!0}),p(Re)!=="svelte-nkpot4"&&(Re.innerHTML=Vn),tn=l(U),Fe=r(U,"UL",{"data-svelte-h":!0}),p(Fe)!=="svelte-mlrsks"&&(Fe.innerHTML=Xn),nn=l(U),Ve=r(U,"P",{"data-svelte-h":!0}),p(Ve)!=="svelte-46aam0"&&(Ve.textContent=Bn),U.forEach(n),J.forEach(n),qt=l(e),m(fe.$$.fragment,e),Nt=l(e),k=r(e,"DIV",{class:!0});var y=I(k);m(be.$$.fragment,y),sn=l(y),Xe=r(y,"P",{"data-svelte-h":!0}),p(Xe)!=="svelte-g5z8ln"&&(Xe.innerHTML=Hn),an=l(y),Be=r(y,"P",{"data-svelte-h":!0}),p(Be)!=="svelte-fh0aq"&&(Be.innerHTML=En),ln=l(y),He=r(y,"P",{"data-svelte-h":!0}),p(He)!=="svelte-1i8rh37"&&(He.innerHTML=Sn),on=ps(y,`
<tokens> <eos>\` for target language documents.
`),m(W.$$.fragment,y),rn=l(y),j=r(y,"DIV",{class:!0});var G=I(j);m(ke.$$.fragment,G),pn=l(G),Ee=r(G,"P",{"data-svelte-h":!0}),p(Ee)!=="svelte-1vll0v2"&&(Ee.textContent=Yn),cn=l(G),Se=r(G,"P",{"data-svelte-h":!0}),p(Se)!=="svelte-90np8u"&&(Se.innerHTML=An),dn=l(G),Ye=r(G,"UL",{"data-svelte-h":!0}),p(Ye)!=="svelte-mlrsks"&&(Ye.innerHTML=Dn),mn=l(G),Ae=r(G,"P",{"data-svelte-h":!0}),p(Ae)!=="svelte-46aam0"&&(Ae.textContent=Qn),G.forEach(n),gn=l(y),R=r(y,"DIV",{class:!0});var At=I(R);m(_e.$$.fragment,At),un=l(At),De=r(At,"P",{"data-svelte-h":!0}),p(De)!=="svelte-1bcwf97"&&(De.textContent=Pn),At.forEach(n),hn=l(y),q=r(y,"DIV",{class:!0});var et=I(q);m(ye.$$.fragment,et),fn=l(et),Qe=r(et,"P",{"data-svelte-h":!0}),p(Qe)!=="svelte-1euodjq"&&(Qe.textContent=Kn),bn=l(et),Pe=r(et,"UL",{"data-svelte-h":!0}),p(Pe)!=="svelte-rrgzfj"&&(Pe.innerHTML=On),et.forEach(n),kn=l(y),N=r(y,"DIV",{class:!0});var tt=I(N);m(Me.$$.fragment,tt),_n=l(tt),Ke=r(tt,"P",{"data-svelte-h":!0}),p(Ke)!=="svelte-1i6tlcm"&&(Ke.textContent=es),yn=l(tt),Oe=r(tt,"UL",{"data-svelte-h":!0}),p(Oe)!=="svelte-1durotj"&&(Oe.innerHTML=ts),tt.forEach(n),y.forEach(n),Gt=l(e),m(Te.$$.fragment,e),It=l(e),we=r(e,"P",{"data-svelte-h":!0}),p(we)!=="svelte-1oyivwb"&&(we.innerHTML=ns),Ct=l(e),m(ve.$$.fragment,e),Zt=l(e),Je=r(e,"P",{"data-svelte-h":!0}),p(Je)!=="svelte-3ltiwn"&&(Je.innerHTML=ss),Lt=l(e),je=r(e,"P",{"data-svelte-h":!0}),p(je)!=="svelte-1pp3dkd"&&(je.innerHTML=as),Wt=l(e),m($e.$$.fragment,e),Rt=l(e),m(xe.$$.fragment,e),Ft=l(e),Ue=r(e,"P",{"data-svelte-h":!0}),p(Ue)!=="svelte-1djrqq6"&&(Ue.innerHTML=ls),Vt=l(e),m(ze.$$.fragment,e),Xt=l(e),m(qe.$$.fragment,e),Bt=l(e),Ne=r(e,"P",{"data-svelte-h":!0}),p(Ne)!=="svelte-bjnkty"&&(Ne.textContent=os),Ht=l(e),F=r(e,"DIV",{style:!0,"data-svelte-h":!0}),p(F)!=="svelte-1obt1wq"&&(F.innerHTML=rs),Et=l(e),m(Ge.$$.fragment,e),St=l(e),nt=r(e,"P",{}),I(nt).forEach(n),this.h()},h(){C(b,"name","hf:doc:metadata"),C(b,"content",Ts),C($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),C(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),C(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),C(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),C(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),C(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),C(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),bs(F,"text-align","center")},m(e,t){i(document.head,b),s(e,z,t),s(e,w,t),s(e,_,t),g(M,e,t),s(e,c,t),g(v,e,t),s(e,st,t),s(e,V,t),s(e,at,t),s(e,X,t),s(e,lt,t),s(e,B,t),s(e,ot,t),g(H,e,t),s(e,rt,t),s(e,E,t),s(e,it,t),g(S,e,t),s(e,pt,t),s(e,Y,t),s(e,ct,t),g(A,e,t),s(e,dt,t),s(e,D,t),s(e,mt,t),g(Q,e,t),s(e,gt,t),s(e,P,t),s(e,ut,t),s(e,K,t),s(e,ht,t),s(e,O,t),s(e,ft,t),s(e,ee,t),s(e,bt,t),s(e,te,t),s(e,kt,t),s(e,ne,t),s(e,_t,t),g(se,e,t),s(e,yt,t),s(e,ae,t),s(e,Mt,t),s(e,le,t),s(e,Tt,t),g(oe,e,t),s(e,wt,t),g(re,e,t),s(e,vt,t),s(e,ie,t),s(e,Jt,t),s(e,pe,t),s(e,jt,t),g(ce,e,t),s(e,$t,t),g(de,e,t),s(e,xt,t),s(e,me,t),s(e,Ut,t),g(ge,e,t),s(e,zt,t),s(e,T,t),g(ue,T,null),i(T,Dt),i(T,Ze),i(T,Qt),i(T,Le),i(T,Pt),i(T,We),i(T,Kt),g(L,T,null),i(T,Ot),i(T,$),g(he,$,null),i($,en),i($,Re),i($,tn),i($,Fe),i($,nn),i($,Ve),s(e,qt,t),g(fe,e,t),s(e,Nt,t),s(e,k,t),g(be,k,null),i(k,sn),i(k,Xe),i(k,an),i(k,Be),i(k,ln),i(k,He),i(k,on),g(W,k,null),i(k,rn),i(k,j),g(ke,j,null),i(j,pn),i(j,Ee),i(j,cn),i(j,Se),i(j,dn),i(j,Ye),i(j,mn),i(j,Ae),i(k,gn),i(k,R),g(_e,R,null),i(R,un),i(R,De),i(k,hn),i(k,q),g(ye,q,null),i(q,fn),i(q,Qe),i(q,bn),i(q,Pe),i(k,kn),i(k,N),g(Me,N,null),i(N,_n),i(N,Ke),i(N,yn),i(N,Oe),s(e,Gt,t),g(Te,e,t),s(e,It,t),s(e,we,t),s(e,Ct,t),g(ve,e,t),s(e,Zt,t),s(e,Je,t),s(e,Lt,t),s(e,je,t),s(e,Wt,t),g($e,e,t),s(e,Rt,t),g(xe,e,t),s(e,Ft,t),s(e,Ue,t),s(e,Vt,t),g(ze,e,t),s(e,Xt,t),g(qe,e,t),s(e,Bt,t),s(e,Ne,t),s(e,Ht,t),s(e,F,t),s(e,Et,t),g(Ge,e,t),s(e,St,t),s(e,nt,t),Yt=!0},p(e,[t]){const J={};t&2&&(J.$$scope={dirty:t,ctx:e}),L.$set(J);const U={};t&2&&(U.$$scope={dirty:t,ctx:e}),W.$set(U)},i(e){Yt||(u(M.$$.fragment,e),u(v.$$.fragment,e),u(H.$$.fragment,e),u(S.$$.fragment,e),u(A.$$.fragment,e),u(Q.$$.fragment,e),u(se.$$.fragment,e),u(oe.$$.fragment,e),u(re.$$.fragment,e),u(ce.$$.fragment,e),u(de.$$.fragment,e),u(ge.$$.fragment,e),u(ue.$$.fragment,e),u(L.$$.fragment,e),u(he.$$.fragment,e),u(fe.$$.fragment,e),u(be.$$.fragment,e),u(W.$$.fragment,e),u(ke.$$.fragment,e),u(_e.$$.fragment,e),u(ye.$$.fragment,e),u(Me.$$.fragment,e),u(Te.$$.fragment,e),u(ve.$$.fragment,e),u($e.$$.fragment,e),u(xe.$$.fragment,e),u(ze.$$.fragment,e),u(qe.$$.fragment,e),u(Ge.$$.fragment,e),Yt=!0)},o(e){h(M.$$.fragment,e),h(v.$$.fragment,e),h(H.$$.fragment,e),h(S.$$.fragment,e),h(A.$$.fragment,e),h(Q.$$.fragment,e),h(se.$$.fragment,e),h(oe.$$.fragment,e),h(re.$$.fragment,e),h(ce.$$.fragment,e),h(de.$$.fragment,e),h(ge.$$.fragment,e),h(ue.$$.fragment,e),h(L.$$.fragment,e),h(he.$$.fragment,e),h(fe.$$.fragment,e),h(be.$$.fragment,e),h(W.$$.fragment,e),h(ke.$$.fragment,e),h(_e.$$.fragment,e),h(ye.$$.fragment,e),h(Me.$$.fragment,e),h(Te.$$.fragment,e),h(ve.$$.fragment,e),h($e.$$.fragment,e),h(xe.$$.fragment,e),h(ze.$$.fragment,e),h(qe.$$.fragment,e),h(Ge.$$.fragment,e),Yt=!1},d(e){e&&(n(z),n(w),n(_),n(c),n(st),n(V),n(at),n(X),n(lt),n(B),n(ot),n(rt),n(E),n(it),n(pt),n(Y),n(ct),n(dt),n(D),n(mt),n(gt),n(P),n(ut),n(K),n(ht),n(O),n(ft),n(ee),n(bt),n(te),n(kt),n(ne),n(_t),n(yt),n(ae),n(Mt),n(le),n(Tt),n(wt),n(vt),n(ie),n(Jt),n(pe),n(jt),n($t),n(xt),n(me),n(Ut),n(zt),n(T),n(qt),n(Nt),n(k),n(Gt),n(It),n(we),n(Ct),n(Zt),n(Je),n(Lt),n(je),n(Wt),n(Rt),n(Ft),n(Ue),n(Vt),n(Xt),n(Bt),n(Ne),n(Ht),n(F),n(Et),n(St),n(nt)),n(b),f(M,e),f(v,e),f(H,e),f(S,e),f(A,e),f(Q,e),f(se,e),f(oe,e),f(re,e),f(ce,e),f(de,e),f(ge,e),f(ue),f(L),f(he),f(fe,e),f(be),f(W),f(ke),f(_e),f(ye),f(Me),f(Te,e),f(ve,e),f($e,e),f(xe,e),f(ze,e),f(qe,e),f(Ge,e)}}}const Ts='{"title":"NLLB","local":"nllb","sections":[{"title":"Updated tokenizer behavior","local":"transformers.NllbTokenizer","sections":[],"depth":2},{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Generating with NLLB","local":"generating-with-nllb","sections":[{"title":"Generating from any other language than English","local":"generating-from-any-other-language-than-english","sections":[],"depth":3}],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2},{"title":"NllbTokenizer","local":"nllbtokenizer","sections":[],"depth":2},{"title":"NllbTokenizerFast","local":"nllbtokenizerfast","sections":[],"depth":2},{"title":"Using Flash Attention 2","local":"using-flash-attention-2","sections":[{"title":"Installation","local":"installation","sections":[],"depth":3},{"title":"Usage","local":"usage","sections":[],"depth":3},{"title":"Expected speedups","local":"expected-speedups","sections":[],"depth":3}],"depth":2}],"depth":1}';function ws(Ce){return gs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zs extends us{constructor(b){super(),hs(this,b,ws,Ms,ms,{})}}export{zs as component};
