import{s as _s,n as xs,o as ks}from"../chunks/scheduler.bdbef820.js";import{S as Cs,i as vs,g as p,s as l,r as h,A as Us,h as r,f as n,c as t,j as Ts,u as c,x as m,k as Js,y as Ws,a as e,v as u,d as i,t as b,w as j}from"../chunks/index.c0aea24a.js";import{C as V}from"../chunks/CodeBlock.6ccca92e.js";import{H as cs,E as Gs}from"../chunks/EditOnGithub.725ee0c1.js";function Is(us){let o,Y,Z,N,d,F,f,is="This guide shows specific methods for processing text datasets. Learn how to:",P,g,bs='<li>Tokenize a dataset with <a href="/docs/datasets/v3.0.2/en/package_reference/main_classes#datasets.Dataset.map">map()</a>.</li> <li>Align dataset labels with label ids for NLI datasets.</li>',R,y,js='For a guide on how to process any type of dataset, take a look at the <a class="underline decoration-sky-400 decoration-2 font-semibold" href="./process">general process guide</a>.',A,$,E,M,os='The <a href="/docs/datasets/v3.0.2/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function supports processing batches of examples at once which speeds up tokenization.',B,w,ds='Load a tokenizer from 🤗 <a href="https://huggingface.co/transformers/" rel="nofollow">Transformers</a>:',Q,T,X,J,fs='Set the <code>batched</code> parameter to <code>True</code> in the <a href="/docs/datasets/v3.0.2/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function to apply the tokenizer to batches of examples:',S,_,D,x,gs='The <a href="/docs/datasets/v3.0.2/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function converts the returned values to a PyArrow-supported format. But explicitly returning the tensors as NumPy arrays is faster because it is a natively supported PyArrow format. Set <code>return_tensors=&quot;np&quot;</code> when you tokenize your text:',K,k,O,C,ss,v,ys='The <a href="/docs/datasets/v3.0.2/en/package_reference/main_classes#datasets.Dataset.align_labels_with_mapping">align_labels_with_mapping()</a> function aligns a dataset label id with the label name. Not all 🤗 Transformers models follow the prescribed label mapping of the original dataset, especially for NLI datasets. For example, the <a href="https://huggingface.co/datasets/glue" rel="nofollow">MNLI</a> dataset uses the following label mapping:',as,U,ns,W,$s="To align the dataset label mapping with the mapping used by a model, create a dictionary of the label name and id to align on:",es,G,ls,I,Ms='Pass the dictionary of the label mappings to the <a href="/docs/datasets/v3.0.2/en/package_reference/main_classes#datasets.Dataset.align_labels_with_mapping">align_labels_with_mapping()</a> function, and the column to align on:',ts,q,ps,z,ws="You can also use this function to assign a custom mapping of labels to ids.",rs,H,ms,L,hs;return d=new cs({props:{title:"Process text data",local:"process-text-data",headingTag:"h1"}}),$=new cs({props:{title:"Map",local:"map",headingTag:"h2"}}),T=new V({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJiZXJ0LWJhc2UtY2FzZWQlMjIp",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;bert-base-cased&quot;</span>)`,wrap:!1}}),_=new V({props:{code:"ZGF0YXNldCUyMCUzRCUyMGRhdGFzZXQubWFwKGxhbWJkYSUyMGV4YW1wbGVzJTNBJTIwdG9rZW5pemVyKGV4YW1wbGVzJTVCJTIydGV4dCUyMiU1RCklMkMlMjBiYXRjaGVkJTNEVHJ1ZSklMEFkYXRhc2V0JTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">map</span>(<span class="hljs-keyword">lambda</span> examples: tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>]), batched=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset[<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;text&#x27;</span>: <span class="hljs-string">&#x27;the rock is destined to be the 21st century\\&#x27;s new &quot; conan &quot; and that he\\&#x27;s going to make a splash even greater than arnold schwarzenegger , jean-claud van damme or steven segal .&#x27;</span>, 
 <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-number">1</span>, 
 <span class="hljs-string">&#x27;input_ids&#x27;</span>: [<span class="hljs-number">101</span>, <span class="hljs-number">1996</span>, <span class="hljs-number">2600</span>, <span class="hljs-number">2003</span>, <span class="hljs-number">16036</span>, <span class="hljs-number">2000</span>, <span class="hljs-number">2022</span>, <span class="hljs-number">1996</span>, <span class="hljs-number">7398</span>, <span class="hljs-number">2301</span>, <span class="hljs-number">1005</span>, <span class="hljs-number">1055</span>, <span class="hljs-number">2047</span>, <span class="hljs-number">1000</span>, <span class="hljs-number">16608</span>, <span class="hljs-number">1000</span>, <span class="hljs-number">1998</span>, <span class="hljs-number">2008</span>, <span class="hljs-number">2002</span>, <span class="hljs-number">1005</span>, <span class="hljs-number">1055</span>, <span class="hljs-number">2183</span>, <span class="hljs-number">2000</span>, <span class="hljs-number">2191</span>, <span class="hljs-number">1037</span>, <span class="hljs-number">17624</span>, <span class="hljs-number">2130</span>, <span class="hljs-number">3618</span>, <span class="hljs-number">2084</span>, <span class="hljs-number">7779</span>, <span class="hljs-number">29058</span>, <span class="hljs-number">8625</span>, <span class="hljs-number">13327</span>, <span class="hljs-number">1010</span>, <span class="hljs-number">3744</span>, <span class="hljs-number">1011</span>, <span class="hljs-number">18856</span>, <span class="hljs-number">19513</span>, <span class="hljs-number">3158</span>, <span class="hljs-number">5477</span>, <span class="hljs-number">4168</span>, <span class="hljs-number">2030</span>, <span class="hljs-number">7112</span>, <span class="hljs-number">16562</span>, <span class="hljs-number">2140</span>, <span class="hljs-number">1012</span>, <span class="hljs-number">102</span>], 
 <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>], 
 <span class="hljs-string">&#x27;attention_mask&#x27;</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]}`,wrap:!1}}),k=new V({props:{code:"ZGF0YXNldCUyMCUzRCUyMGRhdGFzZXQubWFwKGxhbWJkYSUyMGV4YW1wbGVzJTNBJTIwdG9rZW5pemVyKGV4YW1wbGVzJTVCJTIydGV4dCUyMiU1RCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIybnAlMjIpJTJDJTIwYmF0Y2hlZCUzRFRydWUp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">map</span>(<span class="hljs-keyword">lambda</span> examples: tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>], return_tensors=<span class="hljs-string">&quot;np&quot;</span>), batched=<span class="hljs-literal">True</span>)',wrap:!1}}),C=new cs({props:{title:"Align",local:"align",headingTag:"h2"}}),U=new V({props:{code:"bGFiZWwyaWQlMjAlM0QlMjAlN0IlMjJlbnRhaWxtZW50JTIyJTNBJTIwMCUyQyUyMCUyMm5ldXRyYWwlMjIlM0ElMjAxJTJDJTIwJTIyY29udHJhZGljdGlvbiUyMiUzQSUyMDIlN0Q=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>label2id = {<span class="hljs-string">&quot;entailment&quot;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&quot;neutral&quot;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&quot;contradiction&quot;</span>: <span class="hljs-number">2</span>}',wrap:!1}}),G=new V({props:{code:"bGFiZWwyaWQlMjAlM0QlMjAlN0IlMjJjb250cmFkaWN0aW9uJTIyJTNBJTIwMCUyQyUyMCUyMm5ldXRyYWwlMjIlM0ElMjAxJTJDJTIwJTIyZW50YWlsbWVudCUyMiUzQSUyMDIlN0Q=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>label2id = {<span class="hljs-string">&quot;contradiction&quot;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&quot;neutral&quot;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&quot;entailment&quot;</span>: <span class="hljs-number">2</span>}',wrap:!1}}),q=new V({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBbW5saSUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJnbHVlJTIyJTJDJTIwJTIybW5saSUyMiUyQyUyMHNwbGl0JTNEJTIydHJhaW4lMjIpJTBBbW5saV9hbGlnbmVkJTIwJTNEJTIwbW5saS5hbGlnbl9sYWJlbHNfd2l0aF9tYXBwaW5nKGxhYmVsMmlkJTJDJTIwJTIybGFiZWwlMjIp",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>mnli = load_dataset(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mnli&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>mnli_aligned = mnli.align_labels_with_mapping(label2id, <span class="hljs-string">&quot;label&quot;</span>)`,wrap:!1}}),H=new Gs({props:{source:"https://github.com/huggingface/datasets/blob/main/docs/source/nlp_process.mdx"}}),{c(){o=p("meta"),Y=l(),Z=p("p"),N=l(),h(d.$$.fragment),F=l(),f=p("p"),f.textContent=is,P=l(),g=p("ul"),g.innerHTML=bs,R=l(),y=p("p"),y.innerHTML=js,A=l(),h($.$$.fragment),E=l(),M=p("p"),M.innerHTML=os,B=l(),w=p("p"),w.innerHTML=ds,Q=l(),h(T.$$.fragment),X=l(),J=p("p"),J.innerHTML=fs,S=l(),h(_.$$.fragment),D=l(),x=p("p"),x.innerHTML=gs,K=l(),h(k.$$.fragment),O=l(),h(C.$$.fragment),ss=l(),v=p("p"),v.innerHTML=ys,as=l(),h(U.$$.fragment),ns=l(),W=p("p"),W.textContent=$s,es=l(),h(G.$$.fragment),ls=l(),I=p("p"),I.innerHTML=Ms,ts=l(),h(q.$$.fragment),ps=l(),z=p("p"),z.textContent=ws,rs=l(),h(H.$$.fragment),ms=l(),L=p("p"),this.h()},l(s){const a=Us("svelte-u9bgzb",document.head);o=r(a,"META",{name:!0,content:!0}),a.forEach(n),Y=t(s),Z=r(s,"P",{}),Ts(Z).forEach(n),N=t(s),c(d.$$.fragment,s),F=t(s),f=r(s,"P",{"data-svelte-h":!0}),m(f)!=="svelte-zxifil"&&(f.textContent=is),P=t(s),g=r(s,"UL",{"data-svelte-h":!0}),m(g)!=="svelte-y3u5xn"&&(g.innerHTML=bs),R=t(s),y=r(s,"P",{"data-svelte-h":!0}),m(y)!=="svelte-3s2bzp"&&(y.innerHTML=js),A=t(s),c($.$$.fragment,s),E=t(s),M=r(s,"P",{"data-svelte-h":!0}),m(M)!=="svelte-19n5hzr"&&(M.innerHTML=os),B=t(s),w=r(s,"P",{"data-svelte-h":!0}),m(w)!=="svelte-b5bjp1"&&(w.innerHTML=ds),Q=t(s),c(T.$$.fragment,s),X=t(s),J=r(s,"P",{"data-svelte-h":!0}),m(J)!=="svelte-1iqpc5y"&&(J.innerHTML=fs),S=t(s),c(_.$$.fragment,s),D=t(s),x=r(s,"P",{"data-svelte-h":!0}),m(x)!=="svelte-1bm1zto"&&(x.innerHTML=gs),K=t(s),c(k.$$.fragment,s),O=t(s),c(C.$$.fragment,s),ss=t(s),v=r(s,"P",{"data-svelte-h":!0}),m(v)!=="svelte-ti3lme"&&(v.innerHTML=ys),as=t(s),c(U.$$.fragment,s),ns=t(s),W=r(s,"P",{"data-svelte-h":!0}),m(W)!=="svelte-tn6t6n"&&(W.textContent=$s),es=t(s),c(G.$$.fragment,s),ls=t(s),I=r(s,"P",{"data-svelte-h":!0}),m(I)!=="svelte-o3f1c2"&&(I.innerHTML=Ms),ts=t(s),c(q.$$.fragment,s),ps=t(s),z=r(s,"P",{"data-svelte-h":!0}),m(z)!=="svelte-18y4a1w"&&(z.textContent=ws),rs=t(s),c(H.$$.fragment,s),ms=t(s),L=r(s,"P",{}),Ts(L).forEach(n),this.h()},h(){Js(o,"name","hf:doc:metadata"),Js(o,"content",qs)},m(s,a){Ws(document.head,o),e(s,Y,a),e(s,Z,a),e(s,N,a),u(d,s,a),e(s,F,a),e(s,f,a),e(s,P,a),e(s,g,a),e(s,R,a),e(s,y,a),e(s,A,a),u($,s,a),e(s,E,a),e(s,M,a),e(s,B,a),e(s,w,a),e(s,Q,a),u(T,s,a),e(s,X,a),e(s,J,a),e(s,S,a),u(_,s,a),e(s,D,a),e(s,x,a),e(s,K,a),u(k,s,a),e(s,O,a),u(C,s,a),e(s,ss,a),e(s,v,a),e(s,as,a),u(U,s,a),e(s,ns,a),e(s,W,a),e(s,es,a),u(G,s,a),e(s,ls,a),e(s,I,a),e(s,ts,a),u(q,s,a),e(s,ps,a),e(s,z,a),e(s,rs,a),u(H,s,a),e(s,ms,a),e(s,L,a),hs=!0},p:xs,i(s){hs||(i(d.$$.fragment,s),i($.$$.fragment,s),i(T.$$.fragment,s),i(_.$$.fragment,s),i(k.$$.fragment,s),i(C.$$.fragment,s),i(U.$$.fragment,s),i(G.$$.fragment,s),i(q.$$.fragment,s),i(H.$$.fragment,s),hs=!0)},o(s){b(d.$$.fragment,s),b($.$$.fragment,s),b(T.$$.fragment,s),b(_.$$.fragment,s),b(k.$$.fragment,s),b(C.$$.fragment,s),b(U.$$.fragment,s),b(G.$$.fragment,s),b(q.$$.fragment,s),b(H.$$.fragment,s),hs=!1},d(s){s&&(n(Y),n(Z),n(N),n(F),n(f),n(P),n(g),n(R),n(y),n(A),n(E),n(M),n(B),n(w),n(Q),n(X),n(J),n(S),n(D),n(x),n(K),n(O),n(ss),n(v),n(as),n(ns),n(W),n(es),n(ls),n(I),n(ts),n(ps),n(z),n(rs),n(ms),n(L)),n(o),j(d,s),j($,s),j(T,s),j(_,s),j(k,s),j(C,s),j(U,s),j(G,s),j(q,s),j(H,s)}}}const qs='{"title":"Process text data","local":"process-text-data","sections":[{"title":"Map","local":"map","sections":[],"depth":2},{"title":"Align","local":"align","sections":[],"depth":2}],"depth":1}';function zs(us){return ks(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ys extends Cs{constructor(o){super(),vs(this,o,zs,Is,_s,{})}}export{Ys as component};
