import{s as gt,o as Mt,n as ye}from"../chunks/scheduler.d586627e.js";import{S as bt,i as yt,g as d,s as c,u as h,A as jt,h as u,f as a,c as m,j as Y,v as $,y as w,k as Z,o as G,a as n,w as g,d as M,t as b,x as y}from"../chunks/index.b757c891.js";import{T as ke}from"../chunks/Tip.4380e997.js";import{Y as wt}from"../chunks/Youtube.cab44801.js";import{I as Le}from"../chunks/IconCopyLink.c074b82b.js";import{C as F}from"../chunks/CodeBlock.36019a2e.js";import{F as $t,M as De}from"../chunks/Markdown.1f113748.js";function _t(_){let t,i='Consulte a <a href="https://huggingface.co/tasks/text-classification" rel="nofollow">página de tarefas de classificação de texto</a> para obter mais informações sobre outras formas de classificação de texto e seus modelos, conjuntos de dados e métricas associados.';return{c(){t=d("p"),t.innerHTML=i},l(s){t=u(s,"P",{"data-svelte-h":!0}),w(t)!=="svelte-19mu0yp"&&(t.innerHTML=i)},m(s,p){n(s,t,p)},p:ye,d(s){s&&a(t)}}}function Tt(_){let t,i;return t=new F({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nJTBBJTBBZGF0YV9jb2xsYXRvciUyMCUzRCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nKHRva2VuaXplciUzRHRva2VuaXplcik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorWithPadding

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorWithPadding(tokenizer=tokenizer)`}}),{c(){h(t.$$.fragment)},l(s){$(t.$$.fragment,s)},m(s,p){g(t,s,p),i=!0},p:ye,i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){b(t.$$.fragment,s),i=!1},d(s){y(t,s)}}}function vt(_){let t,i;return t=new De({props:{$$slots:{default:[Tt]},$$scope:{ctx:_}}}),{c(){h(t.$$.fragment)},l(s){$(t.$$.fragment,s)},m(s,p){g(t,s,p),i=!0},p(s,p){const f={};p&2&&(f.$$scope={dirty:p,ctx:s}),t.$set(f)},i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){b(t.$$.fragment,s),i=!1},d(s){y(t,s)}}}function Jt(_){let t,i;return t=new F({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nJTBBJTBBZGF0YV9jb2xsYXRvciUyMCUzRCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nKHRva2VuaXplciUzRHRva2VuaXplciUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorWithPadding

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){h(t.$$.fragment)},l(s){$(t.$$.fragment,s)},m(s,p){g(t,s,p),i=!0},p:ye,i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){b(t.$$.fragment,s),i=!1},d(s){y(t,s)}}}function Ut(_){let t,i;return t=new De({props:{$$slots:{default:[Jt]},$$scope:{ctx:_}}}),{c(){h(t.$$.fragment)},l(s){$(t.$$.fragment,s)},m(s,p){g(t,s,p),i=!0},p(s,p){const f={};p&2&&(f.$$scope={dirty:p,ctx:s}),t.$set(f)},i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){b(t.$$.fragment,s),i=!1},d(s){y(t,s)}}}function kt(_){let t,i='Se você não estiver familiarizado com o fine-tuning de um modelo com o <code>Trainer</code>, dê uma olhada no tutorial básico <a href="../training#finetune-with-trainer">aqui</a>!';return{c(){t=d("p"),t.innerHTML=i},l(s){t=u(s,"P",{"data-svelte-h":!0}),w(t)!=="svelte-796e4s"&&(t.innerHTML=i)},m(s,p){n(s,t,p)},p:ye,d(s){s&&a(t)}}}function xt(_){let t,i="O <code>Trainer</code> aplicará o preenchimento dinâmico por padrão quando você definir o argumento <code>tokenizer</code> dele. Nesse caso, você não precisa especificar um data collator explicitamente.";return{c(){t=d("p"),t.innerHTML=i},l(s){t=u(s,"P",{"data-svelte-h":!0}),w(t)!=="svelte-yhi952"&&(t.innerHTML=i)},m(s,p){n(s,t,p)},p:ye,d(s){s&&a(t)}}}function Ct(_){let t,i="Carregue o DistilBERT com <code>AutoModelForSequenceClassification</code> junto com o número de rótulos esperados:",s,p,f,T,z,J,Q="Nesse ponto, restam apenas três passos:",X,C,H="<li>Definir seus hiperparâmetros de treinamento em <code>TrainingArguments</code>.</li> <li>Passar os argumentos de treinamento para o <code>Trainer</code> junto com o modelo, conjunto de dados, tokenizador e o data collator.</li> <li>Chamar a função <code>train()</code> para executar o fine-tuning do seu modelo.</li>",U,I,R,k,V;return p=new F({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMkMlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMFRyYWluZXIlMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkJTIyJTJDJTIwbnVtX2xhYmVscyUzRDIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>, num_labels=<span class="hljs-number">2</span>)`}}),T=new ke({props:{$$slots:{default:[kt]},$$scope:{ctx:_}}}),I=new F({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjIuJTJGcmVzdWx0cyUyMiUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX2Vwb2NocyUzRDUlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBKSUwQSUwQXRyYWluZXIlMjAlM0QlMjBUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBhcmdzJTNEdHJhaW5pbmdfYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0b2tlbml6ZWRfaW1kYiU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEdG9rZW5pemVkX2ltZGIlNUIlMjJ0ZXN0JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVyJTNEdG9rZW5pemVyJTJDJTBBJTIwJTIwJTIwJTIwZGF0YV9jb2xsYXRvciUzRGRhdGFfY29sbGF0b3IlMkMlMEEpJTBBJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;./results&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">2e-5</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">5</span>,
<span class="hljs-meta">... </span>    weight_decay=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=tokenized_imdb[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_imdb[<span class="hljs-string">&quot;test&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>    data_collator=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),k=new ke({props:{$$slots:{default:[xt]},$$scope:{ctx:_}}}),{c(){t=d("p"),t.innerHTML=i,s=c(),h(p.$$.fragment),f=c(),h(T.$$.fragment),z=c(),J=d("p"),J.textContent=Q,X=c(),C=d("ol"),C.innerHTML=H,U=c(),h(I.$$.fragment),R=c(),h(k.$$.fragment)},l(r){t=u(r,"P",{"data-svelte-h":!0}),w(t)!=="svelte-1u0fbfd"&&(t.innerHTML=i),s=m(r),$(p.$$.fragment,r),f=m(r),$(T.$$.fragment,r),z=m(r),J=u(r,"P",{"data-svelte-h":!0}),w(J)!=="svelte-1dd35iq"&&(J.textContent=Q),X=m(r),C=u(r,"OL",{"data-svelte-h":!0}),w(C)!=="svelte-1aiypan"&&(C.innerHTML=H),U=m(r),$(I.$$.fragment,r),R=m(r),$(k.$$.fragment,r)},m(r,v){n(r,t,v),n(r,s,v),g(p,r,v),n(r,f,v),g(T,r,v),n(r,z,v),n(r,J,v),n(r,X,v),n(r,C,v),n(r,U,v),g(I,r,v),n(r,R,v),g(k,r,v),V=!0},p(r,v){const B={};v&2&&(B.$$scope={dirty:v,ctx:r}),T.$set(B);const x={};v&2&&(x.$$scope={dirty:v,ctx:r}),k.$set(x)},i(r){V||(M(p.$$.fragment,r),M(T.$$.fragment,r),M(I.$$.fragment,r),M(k.$$.fragment,r),V=!0)},o(r){b(p.$$.fragment,r),b(T.$$.fragment,r),b(I.$$.fragment,r),b(k.$$.fragment,r),V=!1},d(r){r&&(a(t),a(s),a(f),a(z),a(J),a(X),a(C),a(U),a(R)),y(p,r),y(T,r),y(I,r),y(k,r)}}}function Zt(_){let t,i;return t=new De({props:{$$slots:{default:[Ct]},$$scope:{ctx:_}}}),{c(){h(t.$$.fragment)},l(s){$(t.$$.fragment,s)},m(s,p){g(t,s,p),i=!0},p(s,p){const f={};p&2&&(f.$$scope={dirty:p,ctx:s}),t.$set(f)},i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){b(t.$$.fragment,s),i=!1},d(s){y(t,s)}}}function Rt(_){let t,i='Se você não estiver familiarizado com o fine-tuning de um modelo com o Keras, dê uma olhada no tutorial básico <a href="training#finetune-with-keras">aqui</a>!';return{c(){t=d("p"),t.innerHTML=i},l(s){t=u(s,"P",{"data-svelte-h":!0}),w(t)!=="svelte-1vtmrxe"&&(t.innerHTML=i)},m(s,p){n(s,t,p)},p:ye,d(s){s&&a(t)}}}function Wt(_){let t,i='Para executar o fine-tuning de um modelo no TensorFlow, comece convertendo seu conjunto de dados para o formato <code>tf.data.Dataset</code> com <a href="https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.to_tf_dataset" rel="nofollow"><code>to_tf_dataset</code></a>. Nessa execução você deverá especificar as entradas e rótulos (no parâmetro <code>columns</code>), se deseja embaralhar o conjunto de dados, o tamanho do batch e o data collator:',s,p,f,T,z,J,Q="Configure o otimizador e alguns hiperparâmetros de treinamento:",X,C,H,U,I="Carregue o DistilBERT com <code>TFAutoModelForSequenceClassification</code> junto com o número de rótulos esperados:",R,k,V,r,v='Configure o modelo para treinamento com o método <a href="https://keras.io/api/models/model_training_apis/#compile-method" rel="nofollow"><code>compile</code></a>:',B,x,A,W,N='Chame o método <a href="https://keras.io/api/models/model_training_apis/#fit-method" rel="nofollow"><code>fit</code></a> para executar o fine-tuning do modelo:',q,E,L;return p=new F({props:{code:"dGZfdHJhaW5fc2V0JTIwJTNEJTIwdG9rZW5pemVkX2ltZGIlNUIlMjJ0cmFpbiUyMiU1RC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlNUIlMjJhdHRlbnRpb25fbWFzayUyMiUyQyUyMCUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMmxhYmVsJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEElMEF0Zl92YWxpZGF0aW9uX3NldCUyMCUzRCUyMHRva2VuaXplZF9pbWRiJTVCJTIydGVzdCUyMiU1RC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlNUIlMjJhdHRlbnRpb25fbWFzayUyMiUyQyUyMCUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMmxhYmVsJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_set = tokenized_imdb[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
<span class="hljs-meta">... </span>    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tf_validation_set = tokenized_imdb[<span class="hljs-string">&quot;test&quot;</span>].to_tf_dataset(
<span class="hljs-meta">... </span>    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)`}}),T=new ke({props:{$$slots:{default:[Rt]},$$scope:{ctx:_}}}),C=new F({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQWJhdGNoX3NpemUlMjAlM0QlMjAxNiUwQW51bV9lcG9jaHMlMjAlM0QlMjA1JTBBYmF0Y2hlc19wZXJfZXBvY2glMjAlM0QlMjBsZW4odG9rZW5pemVkX2ltZGIlNUIlMjJ0cmFpbiUyMiU1RCklMjAlMkYlMkYlMjBiYXRjaF9zaXplJTBBdG90YWxfdHJhaW5fc3RlcHMlMjAlM0QlMjBpbnQoYmF0Y2hlc19wZXJfZXBvY2glMjAqJTIwbnVtX2Vwb2NocyklMEFvcHRpbWl6ZXIlMkMlMjBzY2hlZHVsZSUyMCUzRCUyMGNyZWF0ZV9vcHRpbWl6ZXIoaW5pdF9sciUzRDJlLTUlMkMlMjBudW1fd2FybXVwX3N0ZXBzJTNEMCUyQyUyMG51bV90cmFpbl9zdGVwcyUzRHRvdGFsX3RyYWluX3N0ZXBzKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-meta">&gt;&gt;&gt; </span>batch_size = <span class="hljs-number">16</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>batches_per_epoch = <span class="hljs-built_in">len</span>(tokenized_imdb[<span class="hljs-string">&quot;train&quot;</span>]) // batch_size
<span class="hljs-meta">&gt;&gt;&gt; </span>total_train_steps = <span class="hljs-built_in">int</span>(batches_per_epoch * num_epochs)
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer, schedule = create_optimizer(init_lr=<span class="hljs-number">2e-5</span>, num_warmup_steps=<span class="hljs-number">0</span>, num_train_steps=total_train_steps)`}}),k=new F({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZCUyMiUyQyUyMG51bV9sYWJlbHMlM0QyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>, num_labels=<span class="hljs-number">2</span>)`}}),x=new F({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplcik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)`}}),E=new F({props:{code:"bW9kZWwuZml0KHglM0R0Zl90cmFpbl9zZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl92YWxpZGF0aW9uX3NldCUyQyUyMGVwb2NocyUzRDMp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(x=tf_train_set, validation_data=tf_validation_set, epochs=<span class="hljs-number">3</span>)'}}),{c(){t=d("p"),t.innerHTML=i,s=c(),h(p.$$.fragment),f=c(),h(T.$$.fragment),z=c(),J=d("p"),J.textContent=Q,X=c(),h(C.$$.fragment),H=c(),U=d("p"),U.innerHTML=I,R=c(),h(k.$$.fragment),V=c(),r=d("p"),r.innerHTML=v,B=c(),h(x.$$.fragment),A=c(),W=d("p"),W.innerHTML=N,q=c(),h(E.$$.fragment)},l(l){t=u(l,"P",{"data-svelte-h":!0}),w(t)!=="svelte-1n0wtrp"&&(t.innerHTML=i),s=m(l),$(p.$$.fragment,l),f=m(l),$(T.$$.fragment,l),z=m(l),J=u(l,"P",{"data-svelte-h":!0}),w(J)!=="svelte-xdplem"&&(J.textContent=Q),X=m(l),$(C.$$.fragment,l),H=m(l),U=u(l,"P",{"data-svelte-h":!0}),w(U)!=="svelte-t0i5j"&&(U.innerHTML=I),R=m(l),$(k.$$.fragment,l),V=m(l),r=u(l,"P",{"data-svelte-h":!0}),w(r)!=="svelte-espbvd"&&(r.innerHTML=v),B=m(l),$(x.$$.fragment,l),A=m(l),W=u(l,"P",{"data-svelte-h":!0}),w(W)!=="svelte-t6x1cw"&&(W.innerHTML=N),q=m(l),$(E.$$.fragment,l)},m(l,j){n(l,t,j),n(l,s,j),g(p,l,j),n(l,f,j),g(T,l,j),n(l,z,j),n(l,J,j),n(l,X,j),g(C,l,j),n(l,H,j),n(l,U,j),n(l,R,j),g(k,l,j),n(l,V,j),n(l,r,j),n(l,B,j),g(x,l,j),n(l,A,j),n(l,W,j),n(l,q,j),g(E,l,j),L=!0},p(l,j){const se={};j&2&&(se.$$scope={dirty:j,ctx:l}),T.$set(se)},i(l){L||(M(p.$$.fragment,l),M(T.$$.fragment,l),M(C.$$.fragment,l),M(k.$$.fragment,l),M(x.$$.fragment,l),M(E.$$.fragment,l),L=!0)},o(l){b(p.$$.fragment,l),b(T.$$.fragment,l),b(C.$$.fragment,l),b(k.$$.fragment,l),b(x.$$.fragment,l),b(E.$$.fragment,l),L=!1},d(l){l&&(a(t),a(s),a(f),a(z),a(J),a(X),a(H),a(U),a(R),a(V),a(r),a(B),a(A),a(W),a(q)),y(p,l),y(T,l),y(C,l),y(k,l),y(x,l),y(E,l)}}}function Gt(_){let t,i;return t=new De({props:{$$slots:{default:[Wt]},$$scope:{ctx:_}}}),{c(){h(t.$$.fragment)},l(s){$(t.$$.fragment,s)},m(s,p){g(t,s,p),i=!0},p(s,p){const f={};p&2&&(f.$$scope={dirty:p,ctx:s}),t.$set(f)},i(s){i||(M(t.$$.fragment,s),i=!0)},o(s){b(t.$$.fragment,s),i=!1},d(s){y(t,s)}}}function Xt(_){let t,i='Para obter um exemplo mais aprofundado de como executar o fine-tuning de um modelo para classificação de texto, dê uma olhada nesse <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification.ipynb" rel="nofollow">notebook utilizando PyTorch</a> ou nesse <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification-tf.ipynb" rel="nofollow">notebook utilizando TensorFlow</a>.';return{c(){t=d("p"),t.innerHTML=i},l(s){t=u(s,"P",{"data-svelte-h":!0}),w(t)!=="svelte-f4msrq"&&(t.innerHTML=i)},m(s,p){n(s,t,p)},p:ye,d(s){s&&a(t)}}}function zt(_){let t,i,s,p,f,T,z,J,Q,X,C="Classificação de texto",H,U,I,R,k="A classificação de texto é uma tarefa comum de NLP que atribui um rótulo ou classe a um texto. Existem muitas aplicações práticas de classificação de texto amplamente utilizadas em produção por algumas das maiores empresas da atualidade. Uma das formas mais populares de classificação de texto é a análise de sentimento, que atribui um rótulo como positivo, negativo ou neutro a um texto.",V,r,v='Este guia mostrará como realizar o fine-tuning do <a href="https://huggingface.co/distilbert-base-uncased" rel="nofollow">DistilBERT</a> no conjunto de dados <a href="https://huggingface.co/datasets/imdb" rel="nofollow">IMDb</a> para determinar se a crítica de filme é positiva ou negativa.',B,x,A,W,N,q,E,L,l,j="Carregue o conjunto de dados IMDb",se,ae,et="Carregue o conjunto de dados IMDb utilizando a biblioteca 🤗 Datasets:",xe,le,Ce,ne,tt="Em seguida, dê uma olhada em um exemplo:",Ze,oe,Re,re,st="Existem dois campos neste dataset:",We,ie,at="<li><code>text</code>: uma string contendo o texto da crítica do filme.</li> <li><code>label</code>: um valor que pode ser <code>0</code> para uma crítica negativa ou <code>1</code> para uma crítica positiva.</li>",Ge,S,D,_e,pe,Ke,je,lt="Pré-processamento dos dados",Xe,ce,nt="Carregue o tokenizador do DistilBERT para processar o campo <code>text</code>:",ze,me,Ie,de,ot="Crie uma função de pré-processamento para tokenizar o campo <code>text</code> e truncar as sequências para que não sejam maiores que o comprimento máximo de entrada do DistilBERT:",Ee,ue,Ve,fe,rt='Use a função <a href="https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.map" rel="nofollow"><code>map</code></a> do 🤗 Datasets para aplicar a função de pré-processamento em todo o conjunto de dados. Você pode acelerar a função <code>map</code> definindo <code>batched=True</code> para processar vários elementos do conjunto de dados de uma só vez:',Ye,he,Fe,$e,it="Use o <code>DataCollatorWithPadding</code> para criar um batch de exemplos. Ele também <em>preencherá dinamicamente</em> seu texto até o comprimento do elemento mais longo em seu batch, para que os exemplos do batch tenham um comprimento uniforme. Embora seja possível preencher seu texto com a função <code>tokenizer</code> definindo <code>padding=True</code>, o preenchimento dinâmico utilizando um data collator é mais eficiente.",He,K,Be,P,O,Te,ge,Oe,we,pt="Train",Ne,ee,qe,te,Qe,ve,Ae;return J=new Le({}),U=new wt({props:{id:"leNG9fN9FQU"}}),x=new ke({props:{$$slots:{default:[_t]},$$scope:{ctx:_}}}),E=new Le({}),le=new F({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBaW1kYiUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJpbWRiJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>imdb = load_dataset(<span class="hljs-string">&quot;imdb&quot;</span>)`}}),oe=new F({props:{code:"aW1kYiU1QiUyMnRlc3QlMjIlNUQlNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>imdb[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-number">0</span>]
{
    <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;I love sci-fi and am willing to put up with a lot. Sci-fi movies/TV are usually underfunded, under-appreciated and misunderstood. I tried to like this, I really did, but it is to good TV sci-fi as Babylon 5 is to Star Trek (the original). Silly prosthetics, cheap cardboard sets, stilted dialogues, CG that doesn&#x27;t match the background, and painfully one-dimensional characters cannot be overcome with a &#x27;sci-fi&#x27; setting. (I&#x27;m sure there are those of you out there who think Babylon 5 is good sci-fi TV. It&#x27;s not. It&#x27;s clichéd and uninspiring.) While US viewers might like emotion and character development, sci-fi is a genre that does not take itself seriously (cf. Star Trek). It may treat important issues, yet not as a serious philosophy. It&#x27;s really difficult to care about the characters here as they are not simply foolish, just missing a spark of life. Their actions and reactions are wooden and predictable, often painful to watch. The makers of Earth KNOW it&#x27;s rubbish as they have to always say \\&quot;Gene Roddenberry&#x27;s Earth...\\&quot; otherwise people would not continue watching. Roddenberry&#x27;s ashes must be turning in their orbit as this dull, cheap, poorly edited (watching it without advert breaks really brings this home) trudging Trabant of a show lumbers into space. Spoiler. So, kill off a main character. And then bring him back as another actor. Jeeez! Dallas all over again.&quot;</span>,
}`}}),pe=new Le({}),me=new F({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZCUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),ue=new F({props:{code:"ZGVmJTIwcHJlcHJvY2Vzc19mdW5jdGlvbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b2tlbml6ZXIoZXhhbXBsZXMlNUIlMjJ0ZXh0JTIyJTVEJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>], truncation=<span class="hljs-literal">True</span>)`}}),he=new F({props:{code:"dG9rZW5pemVkX2ltZGIlMjAlM0QlMjBpbWRiLm1hcChwcmVwcm9jZXNzX2Z1bmN0aW9uJTJDJTIwYmF0Y2hlZCUzRFRydWUp",highlighted:'tokenized_imdb = imdb.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>)'}}),K=new $t({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Ut],pytorch:[vt]},$$scope:{ctx:_}}}),ge=new Le({}),ee=new $t({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Gt],pytorch:[Zt]},$$scope:{ctx:_}}}),te=new ke({props:{$$slots:{default:[Xt]},$$scope:{ctx:_}}}),{c(){t=d("meta"),i=c(),s=d("p"),p=c(),f=d("h1"),T=d("a"),z=d("span"),h(J.$$.fragment),Q=c(),X=d("span"),X.textContent=C,H=c(),h(U.$$.fragment),I=c(),R=d("p"),R.textContent=k,V=c(),r=d("p"),r.innerHTML=v,B=c(),h(x.$$.fragment),A=c(),W=d("h2"),N=d("a"),q=d("span"),h(E.$$.fragment),L=c(),l=d("span"),l.textContent=j,se=c(),ae=d("p"),ae.textContent=et,xe=c(),h(le.$$.fragment),Ce=c(),ne=d("p"),ne.textContent=tt,Ze=c(),h(oe.$$.fragment),Re=c(),re=d("p"),re.textContent=st,We=c(),ie=d("ul"),ie.innerHTML=at,Ge=c(),S=d("h2"),D=d("a"),_e=d("span"),h(pe.$$.fragment),Ke=c(),je=d("span"),je.textContent=lt,Xe=c(),ce=d("p"),ce.innerHTML=nt,ze=c(),h(me.$$.fragment),Ie=c(),de=d("p"),de.innerHTML=ot,Ee=c(),h(ue.$$.fragment),Ve=c(),fe=d("p"),fe.innerHTML=rt,Ye=c(),h(he.$$.fragment),Fe=c(),$e=d("p"),$e.innerHTML=it,He=c(),h(K.$$.fragment),Be=c(),P=d("h2"),O=d("a"),Te=d("span"),h(ge.$$.fragment),Oe=c(),we=d("span"),we.textContent=pt,Ne=c(),h(ee.$$.fragment),qe=c(),h(te.$$.fragment),Qe=c(),ve=d("p"),this.h()},l(e){const o=jt("svelte-1phssyn",document.head);t=u(o,"META",{name:!0,content:!0}),o.forEach(a),i=m(e),s=u(e,"P",{}),Y(s).forEach(a),p=m(e),f=u(e,"H1",{class:!0});var Me=Y(f);T=u(Me,"A",{id:!0,class:!0,href:!0});var Je=Y(T);z=u(Je,"SPAN",{});var Ue=Y(z);$(J.$$.fragment,Ue),Ue.forEach(a),Je.forEach(a),Q=m(Me),X=u(Me,"SPAN",{"data-svelte-h":!0}),w(X)!=="svelte-swqf6h"&&(X.textContent=C),Me.forEach(a),H=m(e),$(U.$$.fragment,e),I=m(e),R=u(e,"P",{"data-svelte-h":!0}),w(R)!=="svelte-hyu4ic"&&(R.textContent=k),V=m(e),r=u(e,"P",{"data-svelte-h":!0}),w(r)!=="svelte-134pu2r"&&(r.innerHTML=v),B=m(e),$(x.$$.fragment,e),A=m(e),W=u(e,"H2",{class:!0});var be=Y(W);N=u(be,"A",{id:!0,class:!0,href:!0});var ct=Y(N);q=u(ct,"SPAN",{});var mt=Y(q);$(E.$$.fragment,mt),mt.forEach(a),ct.forEach(a),L=m(be),l=u(be,"SPAN",{"data-svelte-h":!0}),w(l)!=="svelte-1sttspy"&&(l.textContent=j),be.forEach(a),se=m(e),ae=u(e,"P",{"data-svelte-h":!0}),w(ae)!=="svelte-2grkld"&&(ae.textContent=et),xe=m(e),$(le.$$.fragment,e),Ce=m(e),ne=u(e,"P",{"data-svelte-h":!0}),w(ne)!=="svelte-wv20hq"&&(ne.textContent=tt),Ze=m(e),$(oe.$$.fragment,e),Re=m(e),re=u(e,"P",{"data-svelte-h":!0}),w(re)!=="svelte-a71bu2"&&(re.textContent=st),We=m(e),ie=u(e,"UL",{"data-svelte-h":!0}),w(ie)!=="svelte-cjdh2k"&&(ie.innerHTML=at),Ge=m(e),S=u(e,"H2",{class:!0});var Se=Y(S);D=u(Se,"A",{id:!0,class:!0,href:!0});var dt=Y(D);_e=u(dt,"SPAN",{});var ut=Y(_e);$(pe.$$.fragment,ut),ut.forEach(a),dt.forEach(a),Ke=m(Se),je=u(Se,"SPAN",{"data-svelte-h":!0}),w(je)!=="svelte-1xtzwqf"&&(je.textContent=lt),Se.forEach(a),Xe=m(e),ce=u(e,"P",{"data-svelte-h":!0}),w(ce)!=="svelte-z180i9"&&(ce.innerHTML=nt),ze=m(e),$(me.$$.fragment,e),Ie=m(e),de=u(e,"P",{"data-svelte-h":!0}),w(de)!=="svelte-3rjb3c"&&(de.innerHTML=ot),Ee=m(e),$(ue.$$.fragment,e),Ve=m(e),fe=u(e,"P",{"data-svelte-h":!0}),w(fe)!=="svelte-1tsw4lh"&&(fe.innerHTML=rt),Ye=m(e),$(he.$$.fragment,e),Fe=m(e),$e=u(e,"P",{"data-svelte-h":!0}),w($e)!=="svelte-purifw"&&($e.innerHTML=it),He=m(e),$(K.$$.fragment,e),Be=m(e),P=u(e,"H2",{class:!0});var Pe=Y(P);O=u(Pe,"A",{id:!0,class:!0,href:!0});var ft=Y(O);Te=u(ft,"SPAN",{});var ht=Y(Te);$(ge.$$.fragment,ht),ht.forEach(a),ft.forEach(a),Oe=m(Pe),we=u(Pe,"SPAN",{"data-svelte-h":!0}),w(we)!=="svelte-5arm0l"&&(we.textContent=pt),Pe.forEach(a),Ne=m(e),$(ee.$$.fragment,e),qe=m(e),$(te.$$.fragment,e),Qe=m(e),ve=u(e,"P",{}),Y(ve).forEach(a),this.h()},h(){Z(t,"name","hf:doc:metadata"),Z(t,"content",JSON.stringify(It)),Z(T,"id","classificao-de-texto"),Z(T,"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"),Z(T,"href","#classificao-de-texto"),Z(f,"class","relative group"),Z(N,"id","carregue-o-conjunto-de-dados-imdb"),Z(N,"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"),Z(N,"href","#carregue-o-conjunto-de-dados-imdb"),Z(W,"class","relative group"),Z(D,"id","prprocessamento-dos-dados"),Z(D,"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"),Z(D,"href","#prprocessamento-dos-dados"),Z(S,"class","relative group"),Z(O,"id","train"),Z(O,"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"),Z(O,"href","#train"),Z(P,"class","relative group")},m(e,o){G(document.head,t),n(e,i,o),n(e,s,o),n(e,p,o),n(e,f,o),G(f,T),G(T,z),g(J,z,null),G(f,Q),G(f,X),n(e,H,o),g(U,e,o),n(e,I,o),n(e,R,o),n(e,V,o),n(e,r,o),n(e,B,o),g(x,e,o),n(e,A,o),n(e,W,o),G(W,N),G(N,q),g(E,q,null),G(W,L),G(W,l),n(e,se,o),n(e,ae,o),n(e,xe,o),g(le,e,o),n(e,Ce,o),n(e,ne,o),n(e,Ze,o),g(oe,e,o),n(e,Re,o),n(e,re,o),n(e,We,o),n(e,ie,o),n(e,Ge,o),n(e,S,o),G(S,D),G(D,_e),g(pe,_e,null),G(S,Ke),G(S,je),n(e,Xe,o),n(e,ce,o),n(e,ze,o),g(me,e,o),n(e,Ie,o),n(e,de,o),n(e,Ee,o),g(ue,e,o),n(e,Ve,o),n(e,fe,o),n(e,Ye,o),g(he,e,o),n(e,Fe,o),n(e,$e,o),n(e,He,o),g(K,e,o),n(e,Be,o),n(e,P,o),G(P,O),G(O,Te),g(ge,Te,null),G(P,Oe),G(P,we),n(e,Ne,o),g(ee,e,o),n(e,qe,o),g(te,e,o),n(e,Qe,o),n(e,ve,o),Ae=!0},p(e,[o]){const Me={};o&2&&(Me.$$scope={dirty:o,ctx:e}),x.$set(Me);const Je={};o&2&&(Je.$$scope={dirty:o,ctx:e}),K.$set(Je);const Ue={};o&2&&(Ue.$$scope={dirty:o,ctx:e}),ee.$set(Ue);const be={};o&2&&(be.$$scope={dirty:o,ctx:e}),te.$set(be)},i(e){Ae||(M(J.$$.fragment,e),M(U.$$.fragment,e),M(x.$$.fragment,e),M(E.$$.fragment,e),M(le.$$.fragment,e),M(oe.$$.fragment,e),M(pe.$$.fragment,e),M(me.$$.fragment,e),M(ue.$$.fragment,e),M(he.$$.fragment,e),M(K.$$.fragment,e),M(ge.$$.fragment,e),M(ee.$$.fragment,e),M(te.$$.fragment,e),Ae=!0)},o(e){b(J.$$.fragment,e),b(U.$$.fragment,e),b(x.$$.fragment,e),b(E.$$.fragment,e),b(le.$$.fragment,e),b(oe.$$.fragment,e),b(pe.$$.fragment,e),b(me.$$.fragment,e),b(ue.$$.fragment,e),b(he.$$.fragment,e),b(K.$$.fragment,e),b(ge.$$.fragment,e),b(ee.$$.fragment,e),b(te.$$.fragment,e),Ae=!1},d(e){e&&(a(i),a(s),a(p),a(f),a(H),a(I),a(R),a(V),a(r),a(B),a(A),a(W),a(se),a(ae),a(xe),a(Ce),a(ne),a(Ze),a(Re),a(re),a(We),a(ie),a(Ge),a(S),a(Xe),a(ce),a(ze),a(Ie),a(de),a(Ee),a(Ve),a(fe),a(Ye),a(Fe),a($e),a(He),a(Be),a(P),a(Ne),a(qe),a(Qe),a(ve)),a(t),y(J),y(U,e),y(x,e),y(E),y(le,e),y(oe,e),y(pe),y(me,e),y(ue,e),y(he,e),y(K,e),y(ge),y(ee,e),y(te,e)}}}const It={local:"classificao-de-texto",sections:[{local:"carregue-o-conjunto-de-dados-imdb",title:"Carregue o conjunto de dados IMDb"},{local:"prprocessamento-dos-dados",title:"Pré-processamento dos dados"},{local:"train",title:"Train"}],title:"Classificação de texto"};function Et(_){return Mt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Qt extends bt{constructor(t){super(),yt(this,t,Et,zt,gt,{})}}export{Qt as component};
