import{s as rt,n as mt,o as ct}from"../chunks/scheduler.c3dfb84c.js";import{S as ot,i as jt,e as i,s as a,c as J,h as ht,a as r,d as e,b as n,f as yt,g as U,j as c,k as it,l as gt,m as l,n as p,t as M,o as T,p as y}from"../chunks/index.47c20be5.js";import{C as wt,H as ls,E as dt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.423d8c15.js";import{C as m}from"../chunks/CodeBlock.6375aab7.js";import{D as bt}from"../chunks/DocNotebookDropdown.78ab87d2.js";function ft(Ds){let o,Js,as,Us,j,ps,h,Ms,g,Ts,w,Ls="Your class names are likely already good descriptors of the text that you’re looking to classify. With 🤗 SetFit, you can use these class names with strong pretrained Sentence Transformer models to get a strong baseline model without any training samples.",ys,d,Ps="This guide will show you how to perform zero-shot text classification.",is,b,rs,f,Ks='We’ll use the <a href="https://huggingface.co/datasets/dair-ai/emotion" rel="nofollow">dair-ai/emotion</a> dataset to test the performance of our zero-shot model.',ms,u,cs,k,Os="This dataset stores the class names within the dataset <code>Features</code>, so we’ll extract the classes like so:",os,C,js,$,st="Otherwise, we could manually set the list of classes.",hs,I,gs,A,tt='Then, we can use <a href="/docs/setfit/main/en/reference/utility#setfit.get_templated_dataset">get_templated_dataset()</a> to synthetically generate a dummy dataset given these class names.',ws,x,ds,Z,bs,G,fs,B,et="We can use this dataset to train a SetFit model just like normal:",us,z,ks,W,Cs,R,lt="Once trained, we can evaluate the model:",$s,X,Is,_,As,N,at="And run predictions:",xs,Y,Zs,Q,Gs,V,nt="These predictions all look right!",Bs,F,zs,S,Jt="To show that the zero-shot performance of SetFit works well, we’ll compare it against a zero-shot classification model from <code>transformers</code>.",Ws,v,Rs,E,Xs,H,Ut="With its 59.1% accuracy, the 0-shot SetFit heavily outperforms the recommended zero-shot model by <code>transformers</code>.",_s,q,Ns,D,pt="Beyond getting higher accuracies, SetFit is much faster too. Let’s compute the latency of SetFit with <code>BAAI/bge-small-en-v1.5</code> versus the latency of <code>transformers</code> with <code>facebook/bart-large-mnli</code>. Both tests were performed on a GPU.",Ys,L,Qs,P,Vs,K,Fs,O,Ss,ss,Mt="So, SetFit with <code>BAAI/bge-small-en-v1.5</code> is 67x faster than <code>transformers</code> with <code>facebook/bart-large-mnli</code>, alongside being more accurate:",vs,ts,Tt='<img src="https://github.com/huggingface/setfit/assets/37621491/33f574d9-c51b-4e02-8d98-6e04e18427ef" alt="zero_shot_transformers_vs_setfit"/>',Es,es,Hs,ns,qs;return j=new wt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),h=new bt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/setfit_doc/en/zero_shot.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/setfit_doc/en/pytorch/zero_shot.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/setfit_doc/en/tensorflow/zero_shot.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/setfit_doc/en/zero_shot.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/setfit_doc/en/pytorch/zero_shot.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/setfit_doc/en/tensorflow/zero_shot.ipynb"}]}}),g=new ls({props:{title:"Zero-shot Text Classification",local:"zero-shot-text-classification",headingTag:"h1"}}),b=new ls({props:{title:"Testing dataset",local:"testing-dataset",headingTag:"h2"}}),u=new m({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBdGVzdF9kYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmRhaXItYWklMkZlbW90aW9uJTIyJTJDJTIwJTIyc3BsaXQlMjIlMkMlMjBzcGxpdCUzRCUyMnRlc3QlMjIp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

test_dataset = load_dataset(<span class="hljs-string">&quot;dair-ai/emotion&quot;</span>, <span class="hljs-string">&quot;split&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)`,wrap:!1}}),C=new m({props:{code:"Y2xhc3NlcyUyMCUzRCUyMHRlc3RfZGF0YXNldC5mZWF0dXJlcyU1QiUyMmxhYmVsJTIyJTVELm5hbWVzJTBBJTIzJTIwJTNEJTNFJTIwJTVCJ3NhZG5lc3MnJTJDJTIwJ2pveSclMkMlMjAnbG92ZSclMkMlMjAnYW5nZXInJTJDJTIwJ2ZlYXInJTJDJTIwJ3N1cnByaXNlJyU1RA==",highlighted:`classes = test_dataset.features[<span class="hljs-string">&quot;label&quot;</span>].names
<span class="hljs-comment"># =&gt; [&#x27;sadness&#x27;, &#x27;joy&#x27;, &#x27;love&#x27;, &#x27;anger&#x27;, &#x27;fear&#x27;, &#x27;surprise&#x27;]</span>`,wrap:!1}}),I=new ls({props:{title:"Synthetic dataset",local:"synthetic-dataset",headingTag:"h2"}}),x=new m({props:{code:"ZnJvbSUyMHNldGZpdCUyMGltcG9ydCUyMGdldF90ZW1wbGF0ZWRfZGF0YXNldCUwQSUwQXRyYWluX2RhdGFzZXQlMjAlM0QlMjBnZXRfdGVtcGxhdGVkX2RhdGFzZXQoKQ==",highlighted:`<span class="hljs-keyword">from</span> setfit <span class="hljs-keyword">import</span> get_templated_dataset

train_dataset = get_templated_dataset()`,wrap:!1}}),Z=new m({props:{code:"cHJpbnQodHJhaW5fZGF0YXNldCklMEElMjMlMjAlM0QlM0UlMjBEYXRhc2V0KCU3QiUwQSUyMyUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ3RleHQnJTJDJTIwJ2xhYmVsJyU1RCUyQyUwQSUyMyUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNDglMEElMjMlMjAlN0QpJTBBcHJpbnQodHJhaW5fZGF0YXNldCU1QjAlNUQpJTBBJTIzJTIwJTdCJ3RleHQnJTNBJTIwJ1RoaXMlMjBzZW50ZW5jZSUyMGlzJTIwc2FkbmVzcyclMkMlMjAnbGFiZWwnJTNBJTIwMCU3RA==",highlighted:`<span class="hljs-built_in">print</span>(train_dataset)
<span class="hljs-comment"># =&gt; Dataset({</span>
<span class="hljs-comment">#     features: [&#x27;text&#x27;, &#x27;label&#x27;],</span>
<span class="hljs-comment">#     num_rows: 48</span>
<span class="hljs-comment"># })</span>
<span class="hljs-built_in">print</span>(train_dataset[<span class="hljs-number">0</span>])
<span class="hljs-comment"># {&#x27;text&#x27;: &#x27;This sentence is sadness&#x27;, &#x27;label&#x27;: 0}</span>`,wrap:!1}}),G=new ls({props:{title:"Training",local:"training",headingTag:"h2"}}),z=new m({props:{code:"ZnJvbSUyMHNldGZpdCUyMGltcG9ydCUyMFNldEZpdE1vZGVsJTJDJTIwVHJhaW5lciUyQyUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBbW9kZWwlMjAlM0QlMjBTZXRGaXRNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyQkFBSSUyRmJnZS1zbWFsbC1lbi12MS41JTIyKSUwQSUwQWFyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMzIlMkMlMEElMjAlMjAlMjAlMjBudW1fZXBvY2hzJTNEMSUyQyUwQSklMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHRlc3RfZGF0YXNldCUyQyUwQSklMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-keyword">from</span> setfit <span class="hljs-keyword">import</span> SetFitModel, Trainer, TrainingArguments

model = SetFitModel.from_pretrained(<span class="hljs-string">&quot;BAAI/bge-small-en-v1.5&quot;</span>)

args = TrainingArguments(
    batch_size=<span class="hljs-number">32</span>,
    num_epochs=<span class="hljs-number">1</span>,
)

trainer = Trainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    eval_dataset=test_dataset,
)
trainer.train()`,wrap:!1}}),W=new m({props:{code:"KioqKiolMjBSdW5uaW5nJTIwdHJhaW5pbmclMjAqKioqKiUwQSUyMCUyME51bSUyMGV4YW1wbGVzJTIwJTNEJTIwNjAlMEElMjAlMjBOdW0lMjBlcG9jaHMlMjAlM0QlMjAxJTBBJTIwJTIwVG90YWwlMjBvcHRpbWl6YXRpb24lMjBzdGVwcyUyMCUzRCUyMDYwJTBBJTIwJTIwVG90YWwlMjB0cmFpbiUyMGJhdGNoJTIwc2l6ZSUyMCUzRCUyMDMyJTBBJTdCJ2VtYmVkZGluZ19sb3NzJyUzQSUyMDAuMjYyOCUyQyUyMCdsZWFybmluZ19yYXRlJyUzQSUyMDMuMzMzMzMzMzMzMzMzMzMzM2UtMDYlMkMlMjAnZXBvY2gnJTNBJTIwMC4wMiU3RCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUwQSU3QidlbWJlZGRpbmdfbG9zcyclM0ElMj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UyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JUUyJTk2JTg4JTdDJTIwNjAlMkY2MCUyMCU1QjAwJTNBMDklM0MwMCUzQTAwJTJDJTIwJTIwNi4zNWl0JTJGcyU1RA==",highlighted:`***** Running training *****
  <span class="hljs-type">Num</span> <span class="hljs-variable">examples</span> <span class="hljs-operator">=</span> <span class="hljs-number">60</span>
  <span class="hljs-type">Num</span> <span class="hljs-variable">epochs</span> <span class="hljs-operator">=</span> <span class="hljs-number">1</span>
  Total <span class="hljs-type">optimization</span> <span class="hljs-variable">steps</span> <span class="hljs-operator">=</span> <span class="hljs-number">60</span>
  Total train <span class="hljs-type">batch</span> <span class="hljs-variable">size</span> <span class="hljs-operator">=</span> <span class="hljs-number">32</span>
{<span class="hljs-string">&#x27;embedding_loss&#x27;</span>: <span class="hljs-number">0.2628</span>, <span class="hljs-string">&#x27;learning_rate&#x27;</span>: <span class="hljs-number">3.3333333333333333e-06</span>, <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-number">0.02</span>}                                                                                 
{<span class="hljs-string">&#x27;embedding_loss&#x27;</span>: <span class="hljs-number">0.0222</span>, <span class="hljs-string">&#x27;learning_rate&#x27;</span>: <span class="hljs-number">3.7037037037037037e-06</span>, <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-number">0.83</span>}                                                                                 
{<span class="hljs-string">&#x27;train_runtime&#x27;</span>: <span class="hljs-number">15.4717</span>, <span class="hljs-string">&#x27;train_samples_per_second&#x27;</span>: <span class="hljs-number">124.098</span>, <span class="hljs-string">&#x27;train_steps_per_second&#x27;</span>: <span class="hljs-number">3.878</span>, <span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-number">1.0</span>}                                                     
<span class="hljs-number">100</span>%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| <span class="hljs-number">60</span>/<span class="hljs-number">60</span> [<span class="hljs-number">00</span>:09&lt;<span class="hljs-number">00</span>:<span class="hljs-number">00</span>,  <span class="hljs-number">6.</span>35it/s]`,wrap:!1}}),X=new m({props:{code:"bWV0cmljcyUyMCUzRCUyMHRyYWluZXIuZXZhbHVhdGUoKSUwQXByaW50KG1ldHJpY3Mp",highlighted:`metrics = trainer.evaluate()
<span class="hljs-built_in">print</span>(metrics)`,wrap:!1}}),_=new m({props:{code:"KioqKiolMjBSdW5uaW5nJTIwZXZhbHVhdGlvbiUyMCoqKioqJTBBJTdCJ2FjY3VyYWN5JyUzQSUyMDAuNTkxJTdE",highlighted:`<span class="hljs-bullet">***** </span>Running evaluation <span class="hljs-strong">*****</span>
{<span class="hljs-emphasis">&#x27;accuracy&#x27;</span>: 0.591}`,wrap:!1}}),Y=new m({props:{code:"cHJlZHMlMjAlM0QlMjBtb2RlbC5wcmVkaWN0KCU1QiUwQSUyMCUyMCUyMCUyMCUyMmklMjBhbSUyMGp1c3QlMjBmZWVsaW5nJTIwY3Jhbmt5JTIwYW5kJTIwYmx1ZSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMmklMjBmZWVsJTIwaW5jcmVkaWJseSUyMGx1Y2t5JTIwanVzdCUyMHRvJTIwYmUlMjBhYmxlJTIwdG8lMjB0YWxrJTIwdG8lMjBoZXIlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJ5b3UncmUlMjBwaXNzaW5nJTIwbWUlMjBvZmYlMjByaWdodCUyMG5vdyUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMmklMjBkZWZpbml0ZWx5JTIwaGF2ZSUyMHRoYWxhc3NvcGhvYmlhJTJDJTIwZG9uJ3QlMjBnZXQlMjBtZSUyMG5lYXIlMjB3YXRlciUyMGxpa2UlMjB0aGF0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyaSUyMGRpZCUyMG5vdCUyMHNlZSUyMHRoYXQlMjBjb21pbmclMjBhdCUyMGFsbCUyMiUyQyUwQSU1RCklMEFwcmludCglNUJjbGFzc2VzJTVCaWR4JTVEJTIwZm9yJTIwaWR4JTIwaW4lMjBwcmVkcyU1RCk=",highlighted:`preds = model.predict([
    <span class="hljs-string">&quot;i am just feeling cranky and blue&quot;</span>,
    <span class="hljs-string">&quot;i feel incredibly lucky just to be able to talk to her&quot;</span>,
    <span class="hljs-string">&quot;you&#x27;re pissing me off right now&quot;</span>,
    <span class="hljs-string">&quot;i definitely have thalassophobia, don&#x27;t get me near water like that&quot;</span>,
    <span class="hljs-string">&quot;i did not see that coming at all&quot;</span>,
])
<span class="hljs-built_in">print</span>([classes[idx] <span class="hljs-keyword">for</span> idx <span class="hljs-keyword">in</span> preds])`,wrap:!1}}),Q=new m({props:{code:"JTVCJ3NhZG5lc3MnJTJDJTIwJ2pveSclMkMlMjAnYW5nZXInJTJDJTIwJ2ZlYXInJTJDJTIwJ3N1cnByaXNlJyU1RA==",highlighted:'[<span class="hljs-string">&#x27;sadness&#x27;</span>, <span class="hljs-string">&#x27;joy&#x27;</span>, <span class="hljs-string">&#x27;anger&#x27;</span>, <span class="hljs-string">&#x27;fear&#x27;</span>, <span class="hljs-string">&#x27;surprise&#x27;</span>]',wrap:!1}}),F=new ls({props:{title:"Baseline",local:"baseline",headingTag:"h2"}}),v=new m({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBaW1wb3J0JTIwZXZhbHVhdGUlMEElMEElMjMlMjBQcmVwYXJlJTIwdGhlJTI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ZXN0X2RhdGFzZXQlNUIlMjJsYWJlbCUyMiU1RCklMEFwcmludCh0cmFuc2Zvcm1lcnNfYWNjdXJhY3kp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">import</span> evaluate

<span class="hljs-comment"># Prepare the testing dataset</span>
test_dataset = load_dataset(<span class="hljs-string">&quot;dair-ai/emotion&quot;</span>, <span class="hljs-string">&quot;split&quot;</span>, split=<span class="hljs-string">&quot;test&quot;</span>)
classes = test_dataset.features[<span class="hljs-string">&quot;label&quot;</span>].names

<span class="hljs-comment"># Set up the zero-shot classification pipeline from transformers</span>
<span class="hljs-comment"># Uses &#x27;facebook/bart-large-mnli&#x27; by default</span>
pipe = pipeline(<span class="hljs-string">&quot;zero-shot-classification&quot;</span>, device=<span class="hljs-number">0</span>)
zeroshot_preds = pipe(test_dataset[<span class="hljs-string">&quot;text&quot;</span>], batch_size=<span class="hljs-number">16</span>, candidate_labels=classes)
preds = [classes.index(pred[<span class="hljs-string">&quot;labels&quot;</span>][<span class="hljs-number">0</span>]) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> zeroshot_preds]

<span class="hljs-comment"># Compute the accuracy</span>
metric = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)
transformers_accuracy = metric.compute(predictions=preds, references=test_dataset[<span class="hljs-string">&quot;label&quot;</span>])
<span class="hljs-built_in">print</span>(transformers_accuracy)`,wrap:!1}}),E=new m({props:{code:"JTdCJ2FjY3VyYWN5JyUzQSUyMDAuMzc2NSU3RA==",highlighted:'{<span class="hljs-string">&#x27;accuracy&#x27;</span>: <span class="hljs-number">0.3765</span>}',wrap:!1}}),q=new ls({props:{title:"Prediction latency",local:"prediction-latency",headingTag:"h2"}}),L=new m({props:{code:"aW1wb3J0JTIwdGltZSUwQSUwQXN0YXJ0X3QlMjAlM0QlMjB0aW1lLnRpbWUoKSUwQXBpcGUodGVzdF9kYXRhc2V0JTVCJTIydGV4dCUyMiU1RCUyQyUyMGJhdGNoX3NpemUlM0QzMiUyQyUyMGNhbmRpZGF0ZV9sYWJlbHMlM0RjbGFzc2VzKSUwQWRlbHRhX3QlMjAlM0QlMjB0aW1lLnRpbWUoKSUyMC0lMjBzdGFydF90JTBBcHJpbnQoZiUyMiU2MHRyYW5zZm9ybWVycyU2MCUyMHdpdGglMjAlNjBmYWNlYm9vayUyRmJhcnQtbGFyZ2UtbW5saSU2MCUyMGxhdGVuY3klM0ElMjAlN0JkZWx0YV90JTIwJTJGJTIwbGVuKHRlc3RfZGF0YXNldCU1Qid0ZXh0JyU1RCklMjAqJTIwMTAwMCUzQS40ZiU3RG1zJTIwcGVyJTIwc2VudGVuY2UlMjIp",highlighted:`<span class="hljs-keyword">import</span> time

start_t = time.time()
pipe(test_dataset[<span class="hljs-string">&quot;text&quot;</span>], batch_size=<span class="hljs-number">32</span>, candidate_labels=classes)
delta_t = time.time() - start_t
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\`transformers\` with \`facebook/bart-large-mnli\` latency: <span class="hljs-subst">{delta_t / <span class="hljs-built_in">len</span>(test_dataset[<span class="hljs-string">&#x27;text&#x27;</span>]) * <span class="hljs-number">1000</span>:<span class="hljs-number">.4</span>f}</span>ms per sentence&quot;</span>)`,wrap:!1}}),P=new m({props:{code:"JTYwdHJhbnNmb3JtZXJzJTYwJTIwd2l0aCUyMCU2MGZhY2Vib29rJTJGYmFydC1sYXJnZS1tbmxpJTYwJTIwbGF0ZW5jeSUzQSUyMDMxLjE3NjVtcyUyMHBlciUyMHNlbnRlbmNl",highlighted:'`transformers` with `facebook/bart-large-mnli` latency: <span class="hljs-number">31.1765</span>ms per sentence',wrap:!1}}),K=new m({props:{code:"aW1wb3J0JTIwdGltZSUwQSUwQXN0YXJ0X3QlMjAlM0QlMjB0aW1lLnRpbWUoKSUwQW1vZGVsLnByZWRpY3QodGVzdF9kYXRhc2V0JTVCJTIydGV4dCUyMiU1RCklMEFkZWx0YV90JTIwJTNEJTIwdGltZS50aW1lKCklMjAtJTIwc3RhcnRfdCUwQXByaW50KGYlMjJTZXRGaXQlMjB3aXRoJTIwJTYwQkFBSSUyRmJnZS1zbWFsbC1lbi12MS41JTYwJTIwbGF0ZW5jeSUzQSUyMCU3QmRlbHRhX3QlMjAlMkYlMjBsZW4odGVzdF9kYXRhc2V0JTVCJ3RleHQnJTVEKSUyMColMjAxMDAwJTNBLjRmJTdEbXMlMjBwZXIlMjBzZW50ZW5jZSUyMik=",highlighted:`<span class="hljs-keyword">import</span> time

start_t = time.time()
model.predict(test_dataset[<span class="hljs-string">&quot;text&quot;</span>])
delta_t = time.time() - start_t
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;SetFit with \`BAAI/bge-small-en-v1.5\` latency: <span class="hljs-subst">{delta_t / <span class="hljs-built_in">len</span>(test_dataset[<span class="hljs-string">&#x27;text&#x27;</span>]) * <span class="hljs-number">1000</span>:<span class="hljs-number">.4</span>f}</span>ms per sentence&quot;</span>)`,wrap:!1}}),O=new m({props:{code:"U2V0Rml0JTIwd2l0aCUyMCU2MEJBQUklMkZiZ2Utc21hbGwtZW4tdjEuNSU2MCUyMGxhdGVuY3klM0ElMjAwLjQ2MDBtcyUyMHBlciUyMHNlbnRlbmNl",highlighted:'<span class="hljs-attribute">SetFit</span> with `BAAI/bge-small-en-v1.<span class="hljs-number">5</span>` latency: <span class="hljs-number">0</span>.<span class="hljs-number">4600</span>ms per sentence',wrap:!1}}),es=new dt({props:{source:"https://github.com/huggingface/setfit/blob/main/docs/source/en/how_to/zero_shot.mdx"}}),{c(){o=i("meta"),Js=a(),as=i("p"),Us=a(),J(j.$$.fragment),ps=a(),J(h.$$.fragment),Ms=a(),J(g.$$.fragment),Ts=a(),w=i("p"),w.textContent=Ls,ys=a(),d=i("p"),d.textContent=Ps,is=a(),J(b.$$.fragment),rs=a(),f=i("p"),f.innerHTML=Ks,ms=a(),J(u.$$.fragment),cs=a(),k=i("p"),k.innerHTML=Os,os=a(),J(C.$$.fragment),js=a(),$=i("p"),$.textContent=st,hs=a(),J(I.$$.fragment),gs=a(),A=i("p"),A.innerHTML=tt,ws=a(),J(x.$$.fragment),ds=a(),J(Z.$$.fragment),bs=a(),J(G.$$.fragment),fs=a(),B=i("p"),B.textContent=et,us=a(),J(z.$$.fragment),ks=a(),J(W.$$.fragment),Cs=a(),R=i("p"),R.textContent=lt,$s=a(),J(X.$$.fragment),Is=a(),J(_.$$.fragment),As=a(),N=i("p"),N.textContent=at,xs=a(),J(Y.$$.fragment),Zs=a(),J(Q.$$.fragment),Gs=a(),V=i("p"),V.textContent=nt,Bs=a(),J(F.$$.fragment),zs=a(),S=i("p"),S.innerHTML=Jt,Ws=a(),J(v.$$.fragment),Rs=a(),J(E.$$.fragment),Xs=a(),H=i("p"),H.innerHTML=Ut,_s=a(),J(q.$$.fragment),Ns=a(),D=i("p"),D.innerHTML=pt,Ys=a(),J(L.$$.fragment),Qs=a(),J(P.$$.fragment),Vs=a(),J(K.$$.fragment),Fs=a(),J(O.$$.fragment),Ss=a(),ss=i("p"),ss.innerHTML=Mt,vs=a(),ts=i("p"),ts.innerHTML=Tt,Es=a(),J(es.$$.fragment),Hs=a(),ns=i("p"),this.h()},l(s){const t=ht("svelte-u9bgzb",document.head);o=r(t,"META",{name:!0,content:!0}),t.forEach(e),Js=n(s),as=r(s,"P",{}),yt(as).forEach(e),Us=n(s),U(j.$$.fragment,s),ps=n(s),U(h.$$.fragment,s),Ms=n(s),U(g.$$.fragment,s),Ts=n(s),w=r(s,"P",{"data-svelte-h":!0}),c(w)!=="svelte-u49hsh"&&(w.textContent=Ls),ys=n(s),d=r(s,"P",{"data-svelte-h":!0}),c(d)!=="svelte-13fxshi"&&(d.textContent=Ps),is=n(s),U(b.$$.fragment,s),rs=n(s),f=r(s,"P",{"data-svelte-h":!0}),c(f)!=="svelte-1i80jyz"&&(f.innerHTML=Ks),ms=n(s),U(u.$$.fragment,s),cs=n(s),k=r(s,"P",{"data-svelte-h":!0}),c(k)!=="svelte-1gwdkg3"&&(k.innerHTML=Os),os=n(s),U(C.$$.fragment,s),js=n(s),$=r(s,"P",{"data-svelte-h":!0}),c($)!=="svelte-2dxojw"&&($.textContent=st),hs=n(s),U(I.$$.fragment,s),gs=n(s),A=r(s,"P",{"data-svelte-h":!0}),c(A)!=="svelte-1n14wev"&&(A.innerHTML=tt),ws=n(s),U(x.$$.fragment,s),ds=n(s),U(Z.$$.fragment,s),bs=n(s),U(G.$$.fragment,s),fs=n(s),B=r(s,"P",{"data-svelte-h":!0}),c(B)!=="svelte-10h3047"&&(B.textContent=et),us=n(s),U(z.$$.fragment,s),ks=n(s),U(W.$$.fragment,s),Cs=n(s),R=r(s,"P",{"data-svelte-h":!0}),c(R)!=="svelte-24emgz"&&(R.textContent=lt),$s=n(s),U(X.$$.fragment,s),Is=n(s),U(_.$$.fragment,s),As=n(s),N=r(s,"P",{"data-svelte-h":!0}),c(N)!=="svelte-io97e0"&&(N.textContent=at),xs=n(s),U(Y.$$.fragment,s),Zs=n(s),U(Q.$$.fragment,s),Gs=n(s),V=r(s,"P",{"data-svelte-h":!0}),c(V)!=="svelte-16fgheu"&&(V.textContent=nt),Bs=n(s),U(F.$$.fragment,s),zs=n(s),S=r(s,"P",{"data-svelte-h":!0}),c(S)!=="svelte-1xcvsej"&&(S.innerHTML=Jt),Ws=n(s),U(v.$$.fragment,s),Rs=n(s),U(E.$$.fragment,s),Xs=n(s),H=r(s,"P",{"data-svelte-h":!0}),c(H)!=="svelte-1anyja6"&&(H.innerHTML=Ut),_s=n(s),U(q.$$.fragment,s),Ns=n(s),D=r(s,"P",{"data-svelte-h":!0}),c(D)!=="svelte-1a47b37"&&(D.innerHTML=pt),Ys=n(s),U(L.$$.fragment,s),Qs=n(s),U(P.$$.fragment,s),Vs=n(s),U(K.$$.fragment,s),Fs=n(s),U(O.$$.fragment,s),Ss=n(s),ss=r(s,"P",{"data-svelte-h":!0}),c(ss)!=="svelte-n991oh"&&(ss.innerHTML=Mt),vs=n(s),ts=r(s,"P",{"data-svelte-h":!0}),c(ts)!=="svelte-bqzz6k"&&(ts.innerHTML=Tt),Es=n(s),U(es.$$.fragment,s),Hs=n(s),ns=r(s,"P",{}),yt(ns).forEach(e),this.h()},h(){it(o,"name","hf:doc:metadata"),it(o,"content",ut)},m(s,t){gt(document.head,o),l(s,Js,t),l(s,as,t),l(s,Us,t),p(j,s,t),l(s,ps,t),p(h,s,t),l(s,Ms,t),p(g,s,t),l(s,Ts,t),l(s,w,t),l(s,ys,t),l(s,d,t),l(s,is,t),p(b,s,t),l(s,rs,t),l(s,f,t),l(s,ms,t),p(u,s,t),l(s,cs,t),l(s,k,t),l(s,os,t),p(C,s,t),l(s,js,t),l(s,$,t),l(s,hs,t),p(I,s,t),l(s,gs,t),l(s,A,t),l(s,ws,t),p(x,s,t),l(s,ds,t),p(Z,s,t),l(s,bs,t),p(G,s,t),l(s,fs,t),l(s,B,t),l(s,us,t),p(z,s,t),l(s,ks,t),p(W,s,t),l(s,Cs,t),l(s,R,t),l(s,$s,t),p(X,s,t),l(s,Is,t),p(_,s,t),l(s,As,t),l(s,N,t),l(s,xs,t),p(Y,s,t),l(s,Zs,t),p(Q,s,t),l(s,Gs,t),l(s,V,t),l(s,Bs,t),p(F,s,t),l(s,zs,t),l(s,S,t),l(s,Ws,t),p(v,s,t),l(s,Rs,t),p(E,s,t),l(s,Xs,t),l(s,H,t),l(s,_s,t),p(q,s,t),l(s,Ns,t),l(s,D,t),l(s,Ys,t),p(L,s,t),l(s,Qs,t),p(P,s,t),l(s,Vs,t),p(K,s,t),l(s,Fs,t),p(O,s,t),l(s,Ss,t),l(s,ss,t),l(s,vs,t),l(s,ts,t),l(s,Es,t),p(es,s,t),l(s,Hs,t),l(s,ns,t),qs=!0},p:mt,i(s){qs||(M(j.$$.fragment,s),M(h.$$.fragment,s),M(g.$$.fragment,s),M(b.$$.fragment,s),M(u.$$.fragment,s),M(C.$$.fragment,s),M(I.$$.fragment,s),M(x.$$.fragment,s),M(Z.$$.fragment,s),M(G.$$.fragment,s),M(z.$$.fragment,s),M(W.$$.fragment,s),M(X.$$.fragment,s),M(_.$$.fragment,s),M(Y.$$.fragment,s),M(Q.$$.fragment,s),M(F.$$.fragment,s),M(v.$$.fragment,s),M(E.$$.fragment,s),M(q.$$.fragment,s),M(L.$$.fragment,s),M(P.$$.fragment,s),M(K.$$.fragment,s),M(O.$$.fragment,s),M(es.$$.fragment,s),qs=!0)},o(s){T(j.$$.fragment,s),T(h.$$.fragment,s),T(g.$$.fragment,s),T(b.$$.fragment,s),T(u.$$.fragment,s),T(C.$$.fragment,s),T(I.$$.fragment,s),T(x.$$.fragment,s),T(Z.$$.fragment,s),T(G.$$.fragment,s),T(z.$$.fragment,s),T(W.$$.fragment,s),T(X.$$.fragment,s),T(_.$$.fragment,s),T(Y.$$.fragment,s),T(Q.$$.fragment,s),T(F.$$.fragment,s),T(v.$$.fragment,s),T(E.$$.fragment,s),T(q.$$.fragment,s),T(L.$$.fragment,s),T(P.$$.fragment,s),T(K.$$.fragment,s),T(O.$$.fragment,s),T(es.$$.fragment,s),qs=!1},d(s){s&&(e(Js),e(as),e(Us),e(ps),e(Ms),e(Ts),e(w),e(ys),e(d),e(is),e(rs),e(f),e(ms),e(cs),e(k),e(os),e(js),e($),e(hs),e(gs),e(A),e(ws),e(ds),e(bs),e(fs),e(B),e(us),e(ks),e(Cs),e(R),e($s),e(Is),e(As),e(N),e(xs),e(Zs),e(Gs),e(V),e(Bs),e(zs),e(S),e(Ws),e(Rs),e(Xs),e(H),e(_s),e(Ns),e(D),e(Ys),e(Qs),e(Vs),e(Fs),e(Ss),e(ss),e(vs),e(ts),e(Es),e(Hs),e(ns)),e(o),y(j,s),y(h,s),y(g,s),y(b,s),y(u,s),y(C,s),y(I,s),y(x,s),y(Z,s),y(G,s),y(z,s),y(W,s),y(X,s),y(_,s),y(Y,s),y(Q,s),y(F,s),y(v,s),y(E,s),y(q,s),y(L,s),y(P,s),y(K,s),y(O,s),y(es,s)}}}const ut='{"title":"Zero-shot Text Classification","local":"zero-shot-text-classification","sections":[{"title":"Testing dataset","local":"testing-dataset","sections":[],"depth":2},{"title":"Synthetic dataset","local":"synthetic-dataset","sections":[],"depth":2},{"title":"Training","local":"training","sections":[],"depth":2},{"title":"Baseline","local":"baseline","sections":[],"depth":2},{"title":"Prediction latency","local":"prediction-latency","sections":[],"depth":2}],"depth":1}';function kt(Ds){return ct(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Zt extends ot{constructor(o){super(),jt(this,o,kt,ft,rt,{})}}export{Zt as component};
