import{s as lt,n as ot,o as rt}from"../chunks/scheduler.9bc65507.js";import{S as it,i as ht,g as s,s as o,u as N,A as pt,h as l,f as t,c as r,j as p,v as P,y as c,k as i,o as h,a as n,w as A,d as B,t as H,x as X}from"../chunks/index.78c82d43.js";import{I as ne}from"../chunks/IconCopyLink.bedaa44d.js";import{C as st}from"../chunks/CodeBlock.48618ec2.js";function ct(Se){let u,se,L,le,d,g,D,x,$e,I,Ve="MatCha",oe,m,w,K,_,Je,z,We="Overview",re,j,Fe='MatCha has been proposed in the paper <a href="https://arxiv.org/abs/2212.09662" rel="nofollow">MatCha: Enhancing Visual Language Pretraining with Math Reasoning and Chart Derendering</a>, from Fangyu Liu, Francesco Piccinno, Syrine Krichene, Chenxi Pang, Kenton Lee, Mandar Joshi, Yasemin Altun, Nigel Collier, Julian Martin Eisenschlos.',ie,k,Ge="The abstract of the paper states the following:",he,U,Re="<em>Visual language data such as plots, charts, and infographics are ubiquitous in the human world. However, state-of-the-art vision-language models do not perform well on these data. We propose MatCha (Math reasoning and Chart derendering pretraining) to enhance visual language models’ capabilities in jointly modeling charts/plots and language data. Specifically, we propose several pretraining tasks that cover plot deconstruction and numerical reasoning which are the key capabilities in visual language modeling. We perform the MatCha pretraining starting from Pix2Struct, a recently proposed image-to-text visual language model. On standard benchmarks such as PlotQA and ChartQA, the MatCha model outperforms state-of-the-art methods by as much as nearly 20%. We also examine how well MatCha pretraining transfers to domains such as screenshots, textbook diagrams, and document figures and observe overall improvement, verifying the usefulness of MatCha pretraining on broader visual language tasks.</em>",pe,f,y,O,$,Te,Y,Ne="Model description",ce,J,Pe=`MatCha is a model that is trained using <code>Pix2Struct</code> architecture. You can find more information about <code>Pix2Struct</code> in the <a href="https://huggingface.co/docs/transformers/main/en/model_doc/pix2struct" rel="nofollow">Pix2Struct documentation</a>.
MatCha is a Visual Question Answering subset of <code>Pix2Struct</code> architecture. It renders the input question on the image and predicts the answer.`,ue,M,b,ee,T,Ze,q,Ae="Usage",de,Z,Be="Currently 6 checkpoints are available for MatCha:",me,E,He="<li><code>google/matcha</code>: the base MatCha model, used to fine-tune MatCha on downstream tasks</li> <li><code>google/matcha-chartqa</code>: MatCha model fine-tuned on ChartQA dataset. It can be used to answer questions about charts.</li> <li><code>google/matcha-plotqa-v1</code>: MatCha model fine-tuned on PlotQA dataset. It can be used to answer questions about plots.</li> <li><code>google/matcha-plotqa-v2</code>: MatCha model fine-tuned on PlotQA dataset. It can be used to answer questions about plots.</li> <li><code>google/matcha-chart2text-statista</code>: MatCha model fine-tuned on Statista dataset.</li> <li><code>google/matcha-chart2text-pew</code>: MatCha model fine-tuned on Pew dataset.</li>",fe,S,Xe="The models finetuned on <code>chart2text-pew</code> and <code>chart2text-statista</code> are more suited for summarization, whereas the models finetuned on <code>plotqa</code> and <code>chartqa</code> are more suited for question answering.",Me,V,Ie="You can use these models as follows (example on a ChatQA dataset):",ve,W,ge,v,C,te,F,Ee,Q,ze="Fine-tuning",we,G,Ye='To fine-tune MatCha, refer to the pix2struct <a href="https://github.com/huggingface/notebooks/blob/main/examples/image_captioning_pix2struct.ipynb" rel="nofollow">fine-tuning notebook</a>. For <code>Pix2Struct</code> models, we have found out that fine-tuning the model with Adafactor and cosine learning rate scheduler leads to faste convergence:',ye,R,be,ae,Ce;return x=new ne({}),_=new ne({}),$=new ne({}),T=new ne({}),W=new st({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMkMlMjBQaXgyU3RydWN0Rm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEElMEFtb2RlbCUyMCUzRCUyMFBpeDJTdHJ1Y3RGb3JDb25kaXRpb25hbEdlbmVyYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRm1hdGNoYS1jaGFydHFhJTIyKS50bygwKSUwQXByb2Nlc3NvciUyMCUzRCUyMEF1dG9Qcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRm1hdGNoYS1jaGFydHFhJTIyKSUwQXVybCUyMCUzRCUyMCUyMmh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSUyRnZpcy1ubHAlMkZDaGFydFFBJTJGbWFpbiUyRkNoYXJ0UUElMjUyMERhdGFzZXQlMkZ2YWwlMkZwbmclMkYyMDI5NDY3MTAwMjAxOS5wbmclMjIlMEFpbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4ocmVxdWVzdHMuZ2V0KHVybCUyQyUyMHN0cmVhbSUzRFRydWUpLnJhdyklMEElMEFpbnB1dHMlMjAlM0QlMjBwcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2UlMkMlMjB0ZXh0JTNEJTIySXMlMjB0aGUlMjBzdW0lMjBvZiUyMGFsbCUyMDQlMjBwbGFjZXMlMjBncmVhdGVyJTIwdGhhbiUyMExhb3MlM0YlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50bygwKSUwQXByZWRpY3Rpb25zJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBtYXhfbmV3X3Rva2VucyUzRDUxMiklMEFwcmludChwcm9jZXNzb3IuZGVjb2RlKHByZWRpY3Rpb25zJTVCMCU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, Pix2StructForConditionalGeneration
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

model = Pix2StructForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;google/matcha-chartqa&quot;</span>).to(<span class="hljs-number">0</span>)
processor = AutoProcessor.from_pretrained(<span class="hljs-string">&quot;google/matcha-chartqa&quot;</span>)
url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/20294671002019.png&quot;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

inputs = processor(images=image, text=<span class="hljs-string">&quot;Is the sum of all 4 places greater than Laos?&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(<span class="hljs-number">0</span>)
predictions = model.generate(**inputs, max_new_tokens=<span class="hljs-number">512</span>)
<span class="hljs-built_in">print</span>(processor.decode(predictions[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>))`}}),F=new ne({}),R=new st({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5vcHRpbWl6YXRpb24lMjBpbXBvcnQlMjBBZGFmYWN0b3IlMkMlMjBnZXRfY29zaW5lX3NjaGVkdWxlX3dpdGhfd2FybXVwJTBBJTBBb3B0aW1pemVyJTIwJTNEJTIwQWRhZmFjdG9yKHNlbGYucGFyYW1ldGVycygpJTJDJTIwc2NhbGVfcGFyYW1ldGVyJTNERmFsc2UlMkMlMjByZWxhdGl2ZV9zdGVwJTNERmFsc2UlMkMlMjBsciUzRDAuMDElMkMlMjB3ZWlnaHRfZGVjYXklM0QxZS0wNSklMEFzY2hlZHVsZXIlMjAlM0QlMjBnZXRfY29zaW5lX3NjaGVkdWxlX3dpdGhfd2FybXVwKG9wdGltaXplciUyQyUyMG51bV93YXJtdXBfc3RlcHMlM0QxMDAwJTJDJTIwbnVtX3RyYWluaW5nX3N0ZXBzJTNENDAwMDAp",highlighted:`<span class="hljs-keyword">from</span> transformers.optimization <span class="hljs-keyword">import</span> Adafactor, get_cosine_schedule_with_warmup

optimizer = Adafactor(self.parameters(), scale_parameter=<span class="hljs-literal">False</span>, relative_step=<span class="hljs-literal">False</span>, lr=<span class="hljs-number">0.01</span>, weight_decay=<span class="hljs-number">1e-05</span>)
scheduler = get_cosine_schedule_with_warmup(optimizer, num_warmup_steps=<span class="hljs-number">1000</span>, num_training_steps=<span class="hljs-number">40000</span>)`}}),{c(){u=s("meta"),se=o(),L=s("p"),le=o(),d=s("h1"),g=s("a"),D=s("span"),N(x.$$.fragment),$e=o(),I=s("span"),I.textContent=Ve,oe=o(),m=s("h2"),w=s("a"),K=s("span"),N(_.$$.fragment),Je=o(),z=s("span"),z.textContent=We,re=o(),j=s("p"),j.innerHTML=Fe,ie=o(),k=s("p"),k.textContent=Ge,he=o(),U=s("p"),U.innerHTML=Re,pe=o(),f=s("h2"),y=s("a"),O=s("span"),N($.$$.fragment),Te=o(),Y=s("span"),Y.textContent=Ne,ce=o(),J=s("p"),J.innerHTML=Pe,ue=o(),M=s("h2"),b=s("a"),ee=s("span"),N(T.$$.fragment),Ze=o(),q=s("span"),q.textContent=Ae,de=o(),Z=s("p"),Z.textContent=Be,me=o(),E=s("ul"),E.innerHTML=He,fe=o(),S=s("p"),S.innerHTML=Xe,Me=o(),V=s("p"),V.textContent=Ie,ve=o(),N(W.$$.fragment),ge=o(),v=s("h2"),C=s("a"),te=s("span"),N(F.$$.fragment),Ee=o(),Q=s("span"),Q.textContent=ze,we=o(),G=s("p"),G.innerHTML=Ye,ye=o(),N(R.$$.fragment),be=o(),ae=s("p"),this.h()},l(e){const a=pt("svelte-1phssyn",document.head);u=l(a,"META",{name:!0,content:!0}),a.forEach(t),se=r(e),L=l(e,"P",{}),p(L).forEach(t),le=r(e),d=l(e,"H1",{class:!0});var xe=p(d);g=l(xe,"A",{id:!0,class:!0,href:!0});var qe=p(g);D=l(qe,"SPAN",{});var Qe=p(D);P(x.$$.fragment,Qe),Qe.forEach(t),qe.forEach(t),$e=r(xe),I=l(xe,"SPAN",{"data-svelte-h":!0}),c(I)!=="svelte-q39z39"&&(I.textContent=Ve),xe.forEach(t),oe=r(e),m=l(e,"H2",{class:!0});var _e=p(m);w=l(_e,"A",{id:!0,class:!0,href:!0});var Le=p(w);K=l(Le,"SPAN",{});var De=p(K);P(_.$$.fragment,De),De.forEach(t),Le.forEach(t),Je=r(_e),z=l(_e,"SPAN",{"data-svelte-h":!0}),c(z)!=="svelte-1jsw1pg"&&(z.textContent=We),_e.forEach(t),re=r(e),j=l(e,"P",{"data-svelte-h":!0}),c(j)!=="svelte-v33y47"&&(j.innerHTML=Fe),ie=r(e),k=l(e,"P",{"data-svelte-h":!0}),c(k)!=="svelte-1pvthah"&&(k.textContent=Ge),he=r(e),U=l(e,"P",{"data-svelte-h":!0}),c(U)!=="svelte-s1ionu"&&(U.innerHTML=Re),pe=r(e),f=l(e,"H2",{class:!0});var je=p(f);y=l(je,"A",{id:!0,class:!0,href:!0});var Ke=p(y);O=l(Ke,"SPAN",{});var Oe=p(O);P($.$$.fragment,Oe),Oe.forEach(t),Ke.forEach(t),Te=r(je),Y=l(je,"SPAN",{"data-svelte-h":!0}),c(Y)!=="svelte-10tgin4"&&(Y.textContent=Ne),je.forEach(t),ce=r(e),J=l(e,"P",{"data-svelte-h":!0}),c(J)!=="svelte-18xkt0a"&&(J.innerHTML=Pe),ue=r(e),M=l(e,"H2",{class:!0});var ke=p(M);b=l(ke,"A",{id:!0,class:!0,href:!0});var et=p(b);ee=l(et,"SPAN",{});var tt=p(ee);P(T.$$.fragment,tt),tt.forEach(t),et.forEach(t),Ze=r(ke),q=l(ke,"SPAN",{"data-svelte-h":!0}),c(q)!=="svelte-jwh4bg"&&(q.textContent=Ae),ke.forEach(t),de=r(e),Z=l(e,"P",{"data-svelte-h":!0}),c(Z)!=="svelte-1srev77"&&(Z.textContent=Be),me=r(e),E=l(e,"UL",{"data-svelte-h":!0}),c(E)!=="svelte-1y39hb1"&&(E.innerHTML=He),fe=r(e),S=l(e,"P",{"data-svelte-h":!0}),c(S)!=="svelte-11agvee"&&(S.innerHTML=Xe),Me=r(e),V=l(e,"P",{"data-svelte-h":!0}),c(V)!=="svelte-1ui48j4"&&(V.textContent=Ie),ve=r(e),P(W.$$.fragment,e),ge=r(e),v=l(e,"H2",{class:!0});var Ue=p(v);C=l(Ue,"A",{id:!0,class:!0,href:!0});var at=p(C);te=l(at,"SPAN",{});var nt=p(te);P(F.$$.fragment,nt),nt.forEach(t),at.forEach(t),Ee=r(Ue),Q=l(Ue,"SPAN",{"data-svelte-h":!0}),c(Q)!=="svelte-nl2q21"&&(Q.textContent=ze),Ue.forEach(t),we=r(e),G=l(e,"P",{"data-svelte-h":!0}),c(G)!=="svelte-9sjid8"&&(G.innerHTML=Ye),ye=r(e),P(R.$$.fragment,e),be=r(e),ae=l(e,"P",{}),p(ae).forEach(t),this.h()},h(){i(u,"name","hf:doc:metadata"),i(u,"content",JSON.stringify(ut)),i(g,"id","matcha"),i(g,"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"),i(g,"href","#matcha"),i(d,"class","relative group"),i(w,"id","overview"),i(w,"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"),i(w,"href","#overview"),i(m,"class","relative group"),i(y,"id","model-description"),i(y,"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"),i(y,"href","#model-description"),i(f,"class","relative group"),i(b,"id","usage"),i(b,"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"),i(b,"href","#usage"),i(M,"class","relative group"),i(C,"id","finetuning"),i(C,"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"),i(C,"href","#finetuning"),i(v,"class","relative group")},m(e,a){h(document.head,u),n(e,se,a),n(e,L,a),n(e,le,a),n(e,d,a),h(d,g),h(g,D),A(x,D,null),h(d,$e),h(d,I),n(e,oe,a),n(e,m,a),h(m,w),h(w,K),A(_,K,null),h(m,Je),h(m,z),n(e,re,a),n(e,j,a),n(e,ie,a),n(e,k,a),n(e,he,a),n(e,U,a),n(e,pe,a),n(e,f,a),h(f,y),h(y,O),A($,O,null),h(f,Te),h(f,Y),n(e,ce,a),n(e,J,a),n(e,ue,a),n(e,M,a),h(M,b),h(b,ee),A(T,ee,null),h(M,Ze),h(M,q),n(e,de,a),n(e,Z,a),n(e,me,a),n(e,E,a),n(e,fe,a),n(e,S,a),n(e,Me,a),n(e,V,a),n(e,ve,a),A(W,e,a),n(e,ge,a),n(e,v,a),h(v,C),h(C,te),A(F,te,null),h(v,Ee),h(v,Q),n(e,we,a),n(e,G,a),n(e,ye,a),A(R,e,a),n(e,be,a),n(e,ae,a),Ce=!0},p:ot,i(e){Ce||(B(x.$$.fragment,e),B(_.$$.fragment,e),B($.$$.fragment,e),B(T.$$.fragment,e),B(W.$$.fragment,e),B(F.$$.fragment,e),B(R.$$.fragment,e),Ce=!0)},o(e){H(x.$$.fragment,e),H(_.$$.fragment,e),H($.$$.fragment,e),H(T.$$.fragment,e),H(W.$$.fragment,e),H(F.$$.fragment,e),H(R.$$.fragment,e),Ce=!1},d(e){e&&(t(se),t(L),t(le),t(d),t(oe),t(m),t(re),t(j),t(ie),t(k),t(he),t(U),t(pe),t(f),t(ce),t(J),t(ue),t(M),t(de),t(Z),t(me),t(E),t(fe),t(S),t(Me),t(V),t(ve),t(ge),t(v),t(we),t(G),t(ye),t(be),t(ae)),t(u),X(x),X(_),X($),X(T),X(W,e),X(F),X(R,e)}}}const ut={local:"matcha",sections:[{local:"overview",title:"Overview"},{local:"model-description",title:"Model description"},{local:"usage",title:"Usage"},{local:"finetuning",title:"Fine-tuning"}],title:"MatCha"};function dt(Se){return rt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gt extends it{constructor(u){super(),ht(this,u,dt,ct,lt,{})}}export{gt as component};
