import{S as Ua,i as Ka,s as Ra,e as o,k as p,w as H,t as n,M as Ba,c as s,d as a,m as u,a as r,x as V,h as l,b as c,G as t,g as h,y as W,L as Xa,q as Y,o as G,B as J,v as Za}from"../../chunks/vendor-hf-doc-builder.js";import{I as qe}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Ja}from"../../chunks/CodeBlock-hf-doc-builder.js";function eo(ha){let C,Se,E,M,re,j,et,ne,tt,je,b,y,le,I,at,ie,ot,Ie,k,st,L,rt,nt,Le,U,lt,Oe,K,he,it,De,$,A,ce,O,ht,pe,ct,Qe,m,pt,ue,ut,dt,de,mt,ft,D,gt,vt,me,_t,wt,Fe,P,q,fe,Q,Ct,ge,Et,Ne,R,bt,Te,d,B,ve,$t,Pt,xt,X,_e,Mt,yt,kt,Z,we,At,qt,St,ee,Ce,jt,It,Lt,te,Ee,Ot,Dt,Qt,ae,be,Ft,Nt,ze,f,Tt,$e,zt,Ht,Pe,Vt,Wt,xe,Yt,Gt,Me,Jt,Ut,He,oe,Kt,Ve,F,We,x,S,ye,N,Rt,ke,Bt,Ye,v,Xt,T,Zt,ea,Ae,ta,aa,Ge,z,Je;return j=new qe({}),I=new qe({}),O=new qe({}),Q=new qe({}),F=new Ja({props:{code:`from transformers import AutoProcessor, Pix2StructForConditionalGeneration
import requests
from PIL import Image

model = Pix2StructForConditionalGeneration.from_pretrained("google/matcha-chartqa").to(0)
processor = AutoProcessor.from_pretrained("google/matcha-chartqa")
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/20294671002019.png"
image = Image.open(requests.get(url, stream=True).raw)

inputs = processor(images=image, text="Is the sum of all 4 places greater than Laos?", return_tensors="pt").to(0)
predictions = model.generate(**inputs, max_new_tokens=512)
print(processor.decode(predictions[0], skip_special_tokens=True))`,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>))`}}),N=new qe({}),z=new Ja({props:{code:`from transformers.optimization import Adafactor, get_cosine_schedule_with_warmup

optimizer = Adafactor(self.parameters(), scale_parameter=False, relative_step=False, lr=0.01, weight_decay=1e-05)
scheduler = get_cosine_schedule_with_warmup(optimizer, num_warmup_steps=1000, num_training_steps=40000)`,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(){C=o("meta"),Se=p(),E=o("h1"),M=o("a"),re=o("span"),H(j.$$.fragment),et=p(),ne=o("span"),tt=n("MatCha"),je=p(),b=o("h2"),y=o("a"),le=o("span"),H(I.$$.fragment),at=p(),ie=o("span"),ot=n("Overview"),Ie=p(),k=o("p"),st=n("MatCha has been proposed in the paper "),L=o("a"),rt=n("MatCha: Enhancing Visual Language Pretraining with Math Reasoning and Chart Derendering"),nt=n(", from Fangyu Liu, Francesco Piccinno, Syrine Krichene, Chenxi Pang, Kenton Lee, Mandar Joshi, Yasemin Altun, Nigel Collier, Julian Martin Eisenschlos."),Le=p(),U=o("p"),lt=n("The abstract of the paper states the following:"),Oe=p(),K=o("p"),he=o("em"),it=n("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\u2019 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."),De=p(),$=o("h2"),A=o("a"),ce=o("span"),H(O.$$.fragment),ht=p(),pe=o("span"),ct=n("Model description"),Qe=p(),m=o("p"),pt=n("MatCha is a model that is trained using "),ue=o("code"),ut=n("Pix2Struct"),dt=n(" architecture. You can find more information about "),de=o("code"),mt=n("Pix2Struct"),ft=n(" in the "),D=o("a"),gt=n("Pix2Struct documentation"),vt=n(`.
MatCha is a Visual Question Answering subset of `),me=o("code"),_t=n("Pix2Struct"),wt=n(" architecture. It renders the input question on the image and predicts the answer."),Fe=p(),P=o("h2"),q=o("a"),fe=o("span"),H(Q.$$.fragment),Ct=p(),ge=o("span"),Et=n("Usage"),Ne=p(),R=o("p"),bt=n("Currently 6 checkpoints are available for MatCha:"),Te=p(),d=o("ul"),B=o("li"),ve=o("code"),$t=n("google/matcha"),Pt=n(": the base MatCha model, used to fine-tune MatCha on downstream tasks"),xt=p(),X=o("li"),_e=o("code"),Mt=n("google/matcha-chartqa"),yt=n(": MatCha model fine-tuned on ChartQA dataset. It can be used to answer questions about charts."),kt=p(),Z=o("li"),we=o("code"),At=n("google/matcha-plotqa-v1"),qt=n(": MatCha model fine-tuned on PlotQA dataset. It can be used to answer questions about plots."),St=p(),ee=o("li"),Ce=o("code"),jt=n("google/matcha-plotqa-v2"),It=n(": MatCha model fine-tuned on PlotQA dataset. It can be used to answer questions about plots."),Lt=p(),te=o("li"),Ee=o("code"),Ot=n("google/matcha-chart2text-statista"),Dt=n(": MatCha model fine-tuned on Statista dataset."),Qt=p(),ae=o("li"),be=o("code"),Ft=n("google/matcha-chart2text-pew"),Nt=n(": MatCha model fine-tuned on Pew dataset."),ze=p(),f=o("p"),Tt=n("The models finetuned on "),$e=o("code"),zt=n("chart2text-pew"),Ht=n(" and "),Pe=o("code"),Vt=n("chart2text-statista"),Wt=n(" are more suited for summarization, whereas the models finetuned on "),xe=o("code"),Yt=n("plotqa"),Gt=n(" and "),Me=o("code"),Jt=n("chartqa"),Ut=n(" are more suited for question answering."),He=p(),oe=o("p"),Kt=n("You can use these models as follows (example on a ChatQA dataset):"),Ve=p(),H(F.$$.fragment),We=p(),x=o("h2"),S=o("a"),ye=o("span"),H(N.$$.fragment),Rt=p(),ke=o("span"),Bt=n("Fine-tuning"),Ye=p(),v=o("p"),Xt=n("To fine-tune MatCha, refer to the pix2struct "),T=o("a"),Zt=n("fine-tuning notebook"),ea=n(". For "),Ae=o("code"),ta=n("Pix2Struct"),aa=n(" models, we have found out that fine-tuning the model with Adafactor and cosine learning rate scheduler leads to faste convergence:"),Ge=p(),H(z.$$.fragment),this.h()},l(e){const i=Ba('[data-svelte="svelte-1phssyn"]',document.head);C=s(i,"META",{name:!0,content:!0}),i.forEach(a),Se=u(e),E=s(e,"H1",{class:!0});var Ue=r(E);M=s(Ue,"A",{id:!0,class:!0,href:!0});var ca=r(M);re=s(ca,"SPAN",{});var pa=r(re);V(j.$$.fragment,pa),pa.forEach(a),ca.forEach(a),et=u(Ue),ne=s(Ue,"SPAN",{});var ua=r(ne);tt=l(ua,"MatCha"),ua.forEach(a),Ue.forEach(a),je=u(e),b=s(e,"H2",{class:!0});var Ke=r(b);y=s(Ke,"A",{id:!0,class:!0,href:!0});var da=r(y);le=s(da,"SPAN",{});var ma=r(le);V(I.$$.fragment,ma),ma.forEach(a),da.forEach(a),at=u(Ke),ie=s(Ke,"SPAN",{});var fa=r(ie);ot=l(fa,"Overview"),fa.forEach(a),Ke.forEach(a),Ie=u(e),k=s(e,"P",{});var Re=r(k);st=l(Re,"MatCha has been proposed in the paper "),L=s(Re,"A",{href:!0,rel:!0});var ga=r(L);rt=l(ga,"MatCha: Enhancing Visual Language Pretraining with Math Reasoning and Chart Derendering"),ga.forEach(a),nt=l(Re,", from Fangyu Liu, Francesco Piccinno, Syrine Krichene, Chenxi Pang, Kenton Lee, Mandar Joshi, Yasemin Altun, Nigel Collier, Julian Martin Eisenschlos."),Re.forEach(a),Le=u(e),U=s(e,"P",{});var va=r(U);lt=l(va,"The abstract of the paper states the following:"),va.forEach(a),Oe=u(e),K=s(e,"P",{});var _a=r(K);he=s(_a,"EM",{});var wa=r(he);it=l(wa,"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\u2019 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."),wa.forEach(a),_a.forEach(a),De=u(e),$=s(e,"H2",{class:!0});var Be=r($);A=s(Be,"A",{id:!0,class:!0,href:!0});var Ca=r(A);ce=s(Ca,"SPAN",{});var Ea=r(ce);V(O.$$.fragment,Ea),Ea.forEach(a),Ca.forEach(a),ht=u(Be),pe=s(Be,"SPAN",{});var ba=r(pe);ct=l(ba,"Model description"),ba.forEach(a),Be.forEach(a),Qe=u(e),m=s(e,"P",{});var _=r(m);pt=l(_,"MatCha is a model that is trained using "),ue=s(_,"CODE",{});var $a=r(ue);ut=l($a,"Pix2Struct"),$a.forEach(a),dt=l(_," architecture. You can find more information about "),de=s(_,"CODE",{});var Pa=r(de);mt=l(Pa,"Pix2Struct"),Pa.forEach(a),ft=l(_," in the "),D=s(_,"A",{href:!0,rel:!0});var xa=r(D);gt=l(xa,"Pix2Struct documentation"),xa.forEach(a),vt=l(_,`.
MatCha is a Visual Question Answering subset of `),me=s(_,"CODE",{});var Ma=r(me);_t=l(Ma,"Pix2Struct"),Ma.forEach(a),wt=l(_," architecture. It renders the input question on the image and predicts the answer."),_.forEach(a),Fe=u(e),P=s(e,"H2",{class:!0});var Xe=r(P);q=s(Xe,"A",{id:!0,class:!0,href:!0});var ya=r(q);fe=s(ya,"SPAN",{});var ka=r(fe);V(Q.$$.fragment,ka),ka.forEach(a),ya.forEach(a),Ct=u(Xe),ge=s(Xe,"SPAN",{});var Aa=r(ge);Et=l(Aa,"Usage"),Aa.forEach(a),Xe.forEach(a),Ne=u(e),R=s(e,"P",{});var qa=r(R);bt=l(qa,"Currently 6 checkpoints are available for MatCha:"),qa.forEach(a),Te=u(e),d=s(e,"UL",{});var g=r(d);B=s(g,"LI",{});var oa=r(B);ve=s(oa,"CODE",{});var Sa=r(ve);$t=l(Sa,"google/matcha"),Sa.forEach(a),Pt=l(oa,": the base MatCha model, used to fine-tune MatCha on downstream tasks"),oa.forEach(a),xt=u(g),X=s(g,"LI",{});var sa=r(X);_e=s(sa,"CODE",{});var ja=r(_e);Mt=l(ja,"google/matcha-chartqa"),ja.forEach(a),yt=l(sa,": MatCha model fine-tuned on ChartQA dataset. It can be used to answer questions about charts."),sa.forEach(a),kt=u(g),Z=s(g,"LI",{});var ra=r(Z);we=s(ra,"CODE",{});var Ia=r(we);At=l(Ia,"google/matcha-plotqa-v1"),Ia.forEach(a),qt=l(ra,": MatCha model fine-tuned on PlotQA dataset. It can be used to answer questions about plots."),ra.forEach(a),St=u(g),ee=s(g,"LI",{});var na=r(ee);Ce=s(na,"CODE",{});var La=r(Ce);jt=l(La,"google/matcha-plotqa-v2"),La.forEach(a),It=l(na,": MatCha model fine-tuned on PlotQA dataset. It can be used to answer questions about plots."),na.forEach(a),Lt=u(g),te=s(g,"LI",{});var la=r(te);Ee=s(la,"CODE",{});var Oa=r(Ee);Ot=l(Oa,"google/matcha-chart2text-statista"),Oa.forEach(a),Dt=l(la,": MatCha model fine-tuned on Statista dataset."),la.forEach(a),Qt=u(g),ae=s(g,"LI",{});var ia=r(ae);be=s(ia,"CODE",{});var Da=r(be);Ft=l(Da,"google/matcha-chart2text-pew"),Da.forEach(a),Nt=l(ia,": MatCha model fine-tuned on Pew dataset."),ia.forEach(a),g.forEach(a),ze=u(e),f=s(e,"P",{});var w=r(f);Tt=l(w,"The models finetuned on "),$e=s(w,"CODE",{});var Qa=r($e);zt=l(Qa,"chart2text-pew"),Qa.forEach(a),Ht=l(w," and "),Pe=s(w,"CODE",{});var Fa=r(Pe);Vt=l(Fa,"chart2text-statista"),Fa.forEach(a),Wt=l(w," are more suited for summarization, whereas the models finetuned on "),xe=s(w,"CODE",{});var Na=r(xe);Yt=l(Na,"plotqa"),Na.forEach(a),Gt=l(w," and "),Me=s(w,"CODE",{});var Ta=r(Me);Jt=l(Ta,"chartqa"),Ta.forEach(a),Ut=l(w," are more suited for question answering."),w.forEach(a),He=u(e),oe=s(e,"P",{});var za=r(oe);Kt=l(za,"You can use these models as follows (example on a ChatQA dataset):"),za.forEach(a),Ve=u(e),V(F.$$.fragment,e),We=u(e),x=s(e,"H2",{class:!0});var Ze=r(x);S=s(Ze,"A",{id:!0,class:!0,href:!0});var Ha=r(S);ye=s(Ha,"SPAN",{});var Va=r(ye);V(N.$$.fragment,Va),Va.forEach(a),Ha.forEach(a),Rt=u(Ze),ke=s(Ze,"SPAN",{});var Wa=r(ke);Bt=l(Wa,"Fine-tuning"),Wa.forEach(a),Ze.forEach(a),Ye=u(e),v=s(e,"P",{});var se=r(v);Xt=l(se,"To fine-tune MatCha, refer to the pix2struct "),T=s(se,"A",{href:!0,rel:!0});var Ya=r(T);Zt=l(Ya,"fine-tuning notebook"),Ya.forEach(a),ea=l(se,". For "),Ae=s(se,"CODE",{});var Ga=r(Ae);ta=l(Ga,"Pix2Struct"),Ga.forEach(a),aa=l(se," models, we have found out that fine-tuning the model with Adafactor and cosine learning rate scheduler leads to faste convergence:"),se.forEach(a),Ge=u(e),V(z.$$.fragment,e),this.h()},h(){c(C,"name","hf:doc:metadata"),c(C,"content",JSON.stringify(to)),c(M,"id","matcha"),c(M,"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"),c(M,"href","#matcha"),c(E,"class","relative group"),c(y,"id","overview"),c(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"),c(y,"href","#overview"),c(b,"class","relative group"),c(L,"href","https://arxiv.org/abs/2212.09662"),c(L,"rel","nofollow"),c(A,"id","model-description"),c(A,"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"),c(A,"href","#model-description"),c($,"class","relative group"),c(D,"href","https://huggingface.co/docs/transformers/main/en/model_doc/pix2struct"),c(D,"rel","nofollow"),c(q,"id","usage"),c(q,"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"),c(q,"href","#usage"),c(P,"class","relative group"),c(S,"id","finetuning"),c(S,"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"),c(S,"href","#finetuning"),c(x,"class","relative group"),c(T,"href","https://github.com/huggingface/notebooks/blob/main/examples/image_captioning_pix2struct.ipynb"),c(T,"rel","nofollow")},m(e,i){t(document.head,C),h(e,Se,i),h(e,E,i),t(E,M),t(M,re),W(j,re,null),t(E,et),t(E,ne),t(ne,tt),h(e,je,i),h(e,b,i),t(b,y),t(y,le),W(I,le,null),t(b,at),t(b,ie),t(ie,ot),h(e,Ie,i),h(e,k,i),t(k,st),t(k,L),t(L,rt),t(k,nt),h(e,Le,i),h(e,U,i),t(U,lt),h(e,Oe,i),h(e,K,i),t(K,he),t(he,it),h(e,De,i),h(e,$,i),t($,A),t(A,ce),W(O,ce,null),t($,ht),t($,pe),t(pe,ct),h(e,Qe,i),h(e,m,i),t(m,pt),t(m,ue),t(ue,ut),t(m,dt),t(m,de),t(de,mt),t(m,ft),t(m,D),t(D,gt),t(m,vt),t(m,me),t(me,_t),t(m,wt),h(e,Fe,i),h(e,P,i),t(P,q),t(q,fe),W(Q,fe,null),t(P,Ct),t(P,ge),t(ge,Et),h(e,Ne,i),h(e,R,i),t(R,bt),h(e,Te,i),h(e,d,i),t(d,B),t(B,ve),t(ve,$t),t(B,Pt),t(d,xt),t(d,X),t(X,_e),t(_e,Mt),t(X,yt),t(d,kt),t(d,Z),t(Z,we),t(we,At),t(Z,qt),t(d,St),t(d,ee),t(ee,Ce),t(Ce,jt),t(ee,It),t(d,Lt),t(d,te),t(te,Ee),t(Ee,Ot),t(te,Dt),t(d,Qt),t(d,ae),t(ae,be),t(be,Ft),t(ae,Nt),h(e,ze,i),h(e,f,i),t(f,Tt),t(f,$e),t($e,zt),t(f,Ht),t(f,Pe),t(Pe,Vt),t(f,Wt),t(f,xe),t(xe,Yt),t(f,Gt),t(f,Me),t(Me,Jt),t(f,Ut),h(e,He,i),h(e,oe,i),t(oe,Kt),h(e,Ve,i),W(F,e,i),h(e,We,i),h(e,x,i),t(x,S),t(S,ye),W(N,ye,null),t(x,Rt),t(x,ke),t(ke,Bt),h(e,Ye,i),h(e,v,i),t(v,Xt),t(v,T),t(T,Zt),t(v,ea),t(v,Ae),t(Ae,ta),t(v,aa),h(e,Ge,i),W(z,e,i),Je=!0},p:Xa,i(e){Je||(Y(j.$$.fragment,e),Y(I.$$.fragment,e),Y(O.$$.fragment,e),Y(Q.$$.fragment,e),Y(F.$$.fragment,e),Y(N.$$.fragment,e),Y(z.$$.fragment,e),Je=!0)},o(e){G(j.$$.fragment,e),G(I.$$.fragment,e),G(O.$$.fragment,e),G(Q.$$.fragment,e),G(F.$$.fragment,e),G(N.$$.fragment,e),G(z.$$.fragment,e),Je=!1},d(e){a(C),e&&a(Se),e&&a(E),J(j),e&&a(je),e&&a(b),J(I),e&&a(Ie),e&&a(k),e&&a(Le),e&&a(U),e&&a(Oe),e&&a(K),e&&a(De),e&&a($),J(O),e&&a(Qe),e&&a(m),e&&a(Fe),e&&a(P),J(Q),e&&a(Ne),e&&a(R),e&&a(Te),e&&a(d),e&&a(ze),e&&a(f),e&&a(He),e&&a(oe),e&&a(Ve),J(F,e),e&&a(We),e&&a(x),J(N),e&&a(Ye),e&&a(v),e&&a(Ge),J(z,e)}}}const to={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 ao(ha){return Za(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class no extends Ua{constructor(C){super();Ka(this,C,ao,eo,Ra,{})}}export{no as default,to as metadata};
