import{s as Ne,n as Ge,o as Qe}from"../chunks/scheduler.5f3e6389.js";import{S as Ie,i as Ye,e as i,s as n,c as p,h as qe,a as o,d as s,b as l,f as He,g as m,j as r,k as de,l as Pe,m as a,n as h,t as f,o as u,p as g}from"../chunks/index.62df735e.js";import{C as Re,H as R,E as Ze}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.e306bd5b.js";import{C as ze}from"../chunks/CodeBlock.dc1e8be0.js";function Ve(ye){let c,Z,q,V,y,W,x,X,w,xe="<strong>So you’ve trained your model and want to see how well it’s doing on a dataset of your choice. Where do you start?</strong>",B,v,we="There is no “one size fits all” approach to choosing an evaluation metric, but some good guidelines to keep in mind are:",A,M,D,b,ve="There are 3 high-level categories of metrics:",S,$,Me='<li><em>Generic metrics</em>, which can be applied to a variety of situations and datasets, such as precision and accuracy.</li> <li><em>Task-specific metrics</em>, which are limited to a given task, such as Machine Translation (often evaluated using metrics <a href="https://huggingface.co/metrics/bleu" rel="nofollow">BLEU</a> or <a href="https://huggingface.co/metrics/rouge" rel="nofollow">ROUGE</a>) or Named Entity Recognition (often evaluated with <a href="https://huggingface.co/metrics/seqeval" rel="nofollow">seqeval</a>).</li> <li><em>Dataset-specific metrics</em>, which aim to measure model performance on specific benchmarks: for instance, the <a href="https://huggingface.co/datasets/glue" rel="nofollow">GLUE benchmark</a> has a dedicated <a href="https://huggingface.co/metrics/glue" rel="nofollow">evaluation metric</a>.</li>',F,T,be="Let’s look at each of these three cases:",O,C,K,k,$e="Many of the metrics used in the Machine Learning community are quite generic and can be applied in a variety of tasks and datasets.",ee,J,Te='This is the case for metrics like <a href="https://huggingface.co/metrics/accuracy" rel="nofollow">accuracy</a> and <a href="https://huggingface.co/metrics/precision" rel="nofollow">precision</a>, which can be used for evaluating labeled (supervised) datasets, as well as <a href="https://huggingface.co/metrics/perplexity" rel="nofollow">perplexity</a>, which can be used for evaluating different kinds of (unsupervised) generative tasks.',te,j,Ce='To see the input structure of a given metric, you can look at its metric card. For example, in the case of <a href="https://huggingface.co/metrics/precision" rel="nofollow">precision</a>, the format is:',se,_,ae,U,ne,L,ke='Popular ML tasks like Machine Translation and Named Entity Recognition have specific metrics that can be used to compare models. For example, a series of different metrics have been proposed for text generation, ranging from <a href="https://huggingface.co/metrics/bleu" rel="nofollow">BLEU</a> and its derivatives such as <a href="https://huggingface.co/metrics/google_bleu" rel="nofollow">GoogleBLEU</a> and <a href="https://huggingface.co/metrics/gleu" rel="nofollow">GLEU</a>, but also <a href="https://huggingface.co/metrics/rouge" rel="nofollow">ROUGE</a>, <a href="https://huggingface.co/metrics/mauve" rel="nofollow">MAUVE</a>, etc.',le,E,Je="You can find the right metric for your task by:",ie,H,je='<li><strong>Looking at the <a href="https://huggingface.co/tasks" rel="nofollow">Task pages</a></strong> to see what metrics can be used for evaluating models for a given task.</li> <li><strong>Checking out leaderboards</strong> on sites like <a href="https://paperswithcode.com/" rel="nofollow">Papers With Code</a> (you can search by task and by dataset).</li> <li><strong>Reading the metric cards</strong> for the relevant metrics and see which ones are a good fit for your use case. For example, see the <a href="https://github.com/huggingface/evaluate/tree/main/metrics/bleu" rel="nofollow">BLEU metric card</a> or <a href="https://github.com/huggingface/evaluate/tree/main/metrics/squad" rel="nofollow">SQuaD metric card</a>.</li> <li><strong>Looking at papers and blog posts</strong> published on the topic and see what metrics they report. This can change over time, so try to pick papers from the last couple of years!</li>',oe,z,re,N,_e='Some datasets have specific metrics associated with them — this is especially in the case of popular benchmarks like <a href="https://huggingface.co/metrics/glue" rel="nofollow">GLUE</a> and <a href="https://huggingface.co/metrics/squad" rel="nofollow">SQuAD</a>.',ce,d,Ue=`<p>💡
GLUE is actually a collection of different subsets on different tasks, so first you need to choose the one that corresponds to the NLI task, such as mnli, which is described as “crowdsourced collection of sentence pairs with textual entailment annotations”</p>`,pe,G,Le='If you are evaluating your model on a benchmark dataset like the ones mentioned above, you can use its dedicated evaluation metric. Make sure you respect the format that they require. For example, to evaluate your model on the <a href="https://huggingface.co/datasets/squad" rel="nofollow">SQuAD</a> dataset, you need to feed the <code>question</code> and <code>context</code> into your model and return the <code>prediction_text</code>, which should be compared with the <code>references</code> (based on matching the <code>id</code> of the question) :',me,Q,he,I,Ee="You can find examples of dataset structures by consulting the “Dataset Preview” function or the dataset card for a given dataset, and you can see how to use its dedicated evaluation function based on the metric card.",fe,Y,ue,P,ge;return y=new Re({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),x=new R({props:{title:"Choosing a metric for your task",local:"choosing-a-metric-for-your-task",headingTag:"h1"}}),M=new R({props:{title:"Categories of metrics",local:"categories-of-metrics",headingTag:"h2"}}),C=new R({props:{title:"Generic metrics",local:"generic-metrics",headingTag:"h3"}}),_=new ze({props:{code:"cHJlY2lzaW9uX21ldHJpYyUyMCUzRCUyMGV2YWx1YXRlLmxvYWQoJTIycHJlY2lzaW9uJTIyKSUwQXJlc3VsdHMlMjAlM0QlMjBwcmVjaXNpb25fbWV0cmljLmNvbXB1dGUocmVmZXJlbmNlcyUzRCU1QjAlMkMlMjAxJTVEJTJDJTIwcHJlZGljdGlvbnMlM0QlNUIwJTJDJTIwMSU1RCklMEFwcmludChyZXN1bHRzKQ==",highlighted:`<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">precision_metric = evaluate.load(<span class="hljs-string">&quot;precision&quot;</span>)</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">results = precision_metric.compute(references=[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>], predictions=[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>])</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python"><span class="hljs-built_in">print</span>(results)</span>
{&#x27;precision&#x27;: 1.0}`,wrap:!1}}),U=new R({props:{title:"Task-specific metrics",local:"task-specific-metrics",headingTag:"h3"}}),z=new R({props:{title:"Dataset-specific metrics",local:"dataset-specific-metrics",headingTag:"h3"}}),Q=new ze({props:{code:"ZnJvbSUyMGV2YWx1YXRlJTIwaW1wb3J0JTIwbG9hZCUwQXNxdWFkX21ldHJpYyUyMCUzRCUyMGxvYWQoJTIyc3F1YWQlMjIpJTBBcHJlZGljdGlvbnMlMjAlM0QlMjAlNUIlN0IncHJlZGljdGlvbl90ZXh0JyUzQSUyMCcxOTc2JyUyQyUyMCdpZCclM0ElMjAnNTZlMTBhM2JlMzQzM2UxNDAwNDIyYjIyJyU3RCU1RCUwQXJlZmVyZW5jZXMlMjAlM0QlMjAlNUIlN0InYW5zd2VycyclM0ElMjAlN0InYW5zd2VyX3N0YXJ0JyUzQSUyMCU1Qjk3JTVEJTJDJTIwJ3RleHQnJTNBJTIwJTVCJzE5NzYnJTVEJTdEJTJDJTIwJ2lkJyUzQSUyMCc1NmUxMGEzYmUzNDMzZTE0MDA0MjJiMjInJTdEJTVEJTBBcmVzdWx0cyUyMCUzRCUyMHNxdWFkX21ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEcHJlZGljdGlvbnMlMkMlMjByZWZlcmVuY2VzJTNEcmVmZXJlbmNlcyklMEFyZXN1bHRz",highlighted:`<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python"><span class="hljs-keyword">from</span> evaluate <span class="hljs-keyword">import</span> load</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">squad_metric = load(<span class="hljs-string">&quot;squad&quot;</span>)</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">predictions = [{<span class="hljs-string">&#x27;prediction_text&#x27;</span>: <span class="hljs-string">&#x27;1976&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;56e10a3be3433e1400422b22&#x27;</span>}]</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">references = [{<span class="hljs-string">&#x27;answers&#x27;</span>: {<span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">97</span>], <span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;1976&#x27;</span>]}, <span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;56e10a3be3433e1400422b22&#x27;</span>}]</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">results = squad_metric.compute(predictions=predictions, references=references)</span>
<span class="hljs-meta prompt_">&gt;&gt;&gt;</span> <span class="language-python">results</span>
{&#x27;exact_match&#x27;: 100.0, &#x27;f1&#x27;: 100.0}`,wrap:!1}}),Y=new Ze({props:{source:"https://github.com/huggingface/evaluate/blob/main/docs/source/choosing_a_metric.mdx"}}),{c(){c=i("meta"),Z=n(),q=i("p"),V=n(),p(y.$$.fragment),W=n(),p(x.$$.fragment),X=n(),w=i("p"),w.innerHTML=xe,B=n(),v=i("p"),v.textContent=we,A=n(),p(M.$$.fragment),D=n(),b=i("p"),b.textContent=ve,S=n(),$=i("ol"),$.innerHTML=Me,F=n(),T=i("p"),T.textContent=be,O=n(),p(C.$$.fragment),K=n(),k=i("p"),k.textContent=$e,ee=n(),J=i("p"),J.innerHTML=Te,te=n(),j=i("p"),j.innerHTML=Ce,se=n(),p(_.$$.fragment),ae=n(),p(U.$$.fragment),ne=n(),L=i("p"),L.innerHTML=ke,le=n(),E=i("p"),E.textContent=Je,ie=n(),H=i("ul"),H.innerHTML=je,oe=n(),p(z.$$.fragment),re=n(),N=i("p"),N.innerHTML=_e,ce=n(),d=i("blockquote"),d.innerHTML=Ue,pe=n(),G=i("p"),G.innerHTML=Le,me=n(),p(Q.$$.fragment),he=n(),I=i("p"),I.textContent=Ee,fe=n(),p(Y.$$.fragment),ue=n(),P=i("p"),this.h()},l(e){const t=qe("svelte-u9bgzb",document.head);c=o(t,"META",{name:!0,content:!0}),t.forEach(s),Z=l(e),q=o(e,"P",{}),He(q).forEach(s),V=l(e),m(y.$$.fragment,e),W=l(e),m(x.$$.fragment,e),X=l(e),w=o(e,"P",{"data-svelte-h":!0}),r(w)!=="svelte-w5iban"&&(w.innerHTML=xe),B=l(e),v=o(e,"P",{"data-svelte-h":!0}),r(v)!=="svelte-wmso9y"&&(v.textContent=we),A=l(e),m(M.$$.fragment,e),D=l(e),b=o(e,"P",{"data-svelte-h":!0}),r(b)!=="svelte-1rew1ae"&&(b.textContent=ve),S=l(e),$=o(e,"OL",{"data-svelte-h":!0}),r($)!=="svelte-ku3854"&&($.innerHTML=Me),F=l(e),T=o(e,"P",{"data-svelte-h":!0}),r(T)!=="svelte-1mxbm8r"&&(T.textContent=be),O=l(e),m(C.$$.fragment,e),K=l(e),k=o(e,"P",{"data-svelte-h":!0}),r(k)!=="svelte-1853br0"&&(k.textContent=$e),ee=l(e),J=o(e,"P",{"data-svelte-h":!0}),r(J)!=="svelte-1idvrws"&&(J.innerHTML=Te),te=l(e),j=o(e,"P",{"data-svelte-h":!0}),r(j)!=="svelte-10sti0h"&&(j.innerHTML=Ce),se=l(e),m(_.$$.fragment,e),ae=l(e),m(U.$$.fragment,e),ne=l(e),L=o(e,"P",{"data-svelte-h":!0}),r(L)!=="svelte-lqkjii"&&(L.innerHTML=ke),le=l(e),E=o(e,"P",{"data-svelte-h":!0}),r(E)!=="svelte-9rwqnd"&&(E.textContent=Je),ie=l(e),H=o(e,"UL",{"data-svelte-h":!0}),r(H)!=="svelte-w8ah3a"&&(H.innerHTML=je),oe=l(e),m(z.$$.fragment,e),re=l(e),N=o(e,"P",{"data-svelte-h":!0}),r(N)!=="svelte-6nmerd"&&(N.innerHTML=_e),ce=l(e),d=o(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),r(d)!=="svelte-1rno10y"&&(d.innerHTML=Ue),pe=l(e),G=o(e,"P",{"data-svelte-h":!0}),r(G)!=="svelte-tgnxzb"&&(G.innerHTML=Le),me=l(e),m(Q.$$.fragment,e),he=l(e),I=o(e,"P",{"data-svelte-h":!0}),r(I)!=="svelte-t54ozd"&&(I.textContent=Ee),fe=l(e),m(Y.$$.fragment,e),ue=l(e),P=o(e,"P",{}),He(P).forEach(s),this.h()},h(){de(c,"name","hf:doc:metadata"),de(c,"content",We),de(d,"class","warning")},m(e,t){Pe(document.head,c),a(e,Z,t),a(e,q,t),a(e,V,t),h(y,e,t),a(e,W,t),h(x,e,t),a(e,X,t),a(e,w,t),a(e,B,t),a(e,v,t),a(e,A,t),h(M,e,t),a(e,D,t),a(e,b,t),a(e,S,t),a(e,$,t),a(e,F,t),a(e,T,t),a(e,O,t),h(C,e,t),a(e,K,t),a(e,k,t),a(e,ee,t),a(e,J,t),a(e,te,t),a(e,j,t),a(e,se,t),h(_,e,t),a(e,ae,t),h(U,e,t),a(e,ne,t),a(e,L,t),a(e,le,t),a(e,E,t),a(e,ie,t),a(e,H,t),a(e,oe,t),h(z,e,t),a(e,re,t),a(e,N,t),a(e,ce,t),a(e,d,t),a(e,pe,t),a(e,G,t),a(e,me,t),h(Q,e,t),a(e,he,t),a(e,I,t),a(e,fe,t),h(Y,e,t),a(e,ue,t),a(e,P,t),ge=!0},p:Ge,i(e){ge||(f(y.$$.fragment,e),f(x.$$.fragment,e),f(M.$$.fragment,e),f(C.$$.fragment,e),f(_.$$.fragment,e),f(U.$$.fragment,e),f(z.$$.fragment,e),f(Q.$$.fragment,e),f(Y.$$.fragment,e),ge=!0)},o(e){u(y.$$.fragment,e),u(x.$$.fragment,e),u(M.$$.fragment,e),u(C.$$.fragment,e),u(_.$$.fragment,e),u(U.$$.fragment,e),u(z.$$.fragment,e),u(Q.$$.fragment,e),u(Y.$$.fragment,e),ge=!1},d(e){e&&(s(Z),s(q),s(V),s(W),s(X),s(w),s(B),s(v),s(A),s(D),s(b),s(S),s($),s(F),s(T),s(O),s(K),s(k),s(ee),s(J),s(te),s(j),s(se),s(ae),s(ne),s(L),s(le),s(E),s(ie),s(H),s(oe),s(re),s(N),s(ce),s(d),s(pe),s(G),s(me),s(he),s(I),s(fe),s(ue),s(P)),s(c),g(y,e),g(x,e),g(M,e),g(C,e),g(_,e),g(U,e),g(z,e),g(Q,e),g(Y,e)}}}const We='{"title":"Choosing a metric for your task","local":"choosing-a-metric-for-your-task","sections":[{"title":"Categories of metrics","local":"categories-of-metrics","sections":[{"title":"Generic metrics","local":"generic-metrics","sections":[],"depth":3},{"title":"Task-specific metrics","local":"task-specific-metrics","sections":[],"depth":3},{"title":"Dataset-specific metrics","local":"dataset-specific-metrics","sections":[],"depth":3}],"depth":2}],"depth":1}';function Xe(ye){return Qe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Fe extends Ie{constructor(c){super(),Ye(this,c,Xe,Ve,Ne,{})}}export{Fe as component};
