laya-web-demo / assets /parity-OtuGNq8O.js
mizchi's picture
Initial deploy
ea1a8e5 verified
Raw History Blame Contribute Delete
1.72 kB
import{a as e,i as t,n,o as r,r as i}from"./model-url-LsIpDZ5m.js";function a(e,n){return{argmaxAgrees:t(e)===t(n),maxAbsError:e.reduce((e,t,r)=>Math.max(e,Math.abs(t-n[r])),0)}}var o=document.getElementById(`status`),s=document.getElementById(`report`),c=new URLSearchParams(location.search).get(`model`)??`https://huggingface.co/mizchi/laya-multilingual-onnx/resolve/main/`;async function l(){let t=await(await fetch(`/fixtures/parity-multilingual.json`)).json();o.textContent=`loading ${c}`;let{agent:l,provider:u}=await i(c,{wasmPaths:n,batchSize:64,onProgress:e=>{o.textContent=`${e.file}: ${(e.received/1e6).toFixed(0)} / ${e.total?(e.total/1e6).toFixed(0):`?`} MB`}});o.textContent=`running on ${u}`;let d={provider:u,questions:0,argmax_agreements:0,probability_max_abs_error:0,public_result_equal:0,timings_ms:{}};for(let n of t.cases){let i=performance.now(),o=await l.predict(n.state,n.questions);d.timings_ms[n.name]=Math.round(performance.now()-i),Object.keys(n.questions).forEach((i,s)=>{let c=n.items[s].markers.length,l=n.items[s].qtype,u=t.config.temperature_by_options[r(l,c)]??t.config.temperature[l],f=e(n.logits[s].slice(0,c).map(e=>e/Math.max(.001,u))),p=o.answers[i],{argmaxAgrees:m,maxAbsError:h}=a(f,p.type===`noul`?[1-p.noul,p.noul]:Object.values(p.probabilities));d.questions+=1,m&&(d.argmax_agreements+=1),d.probability_max_abs_error=Math.max(d.probability_max_abs_error,h)}),JSON.stringify(o)===JSON.stringify(n.result)&&(d.public_result_equal+=1)}return o.textContent=`done: ${d.argmax_agreements}/${d.questions} argmax on ${u}`,s.textContent=JSON.stringify(d,null,2),d}l().then(e=>console.log(`[laya] RESULT `+JSON.stringify(e))).catch(e=>{o.textContent=`ERROR ${String(e)}`,console.error(e)});