import{s as $e,o as Ce,n as ve}from"../chunks/scheduler.01eeda35.js";import{S as je,i as Te,g as o,s,r as m,A as xe,h as r,f as a,c as l,j as ye,u as d,x as c,k as oe,y as Ue,a as n,v as u,d as h,t as f,w as M}from"../chunks/index.6dd51b66.js";import{T as _e}from"../chunks/Tip.de9bae2b.js";import{C as we}from"../chunks/CodeBlock.19ec9b8c.js";import{H as X,E as Je}from"../chunks/index.58fe8f9d.js";function ke(P){let i,y='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>.';return{c(){i=o("p"),i.innerHTML=y},l(p){i=r(p,"P",{"data-svelte-h":!0}),c(i)!=="svelte-1t6iq26"&&(i.innerHTML=y)},m(p,B){n(p,i,B)},p:ve,d(p){p&&a(i)}}}function Ze(P){let i,y,p,B,w,S,g,re='<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&amp;logo=pytorch&amp;logoColor=white"/>',E,$,z,C,pe='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.',I,v,ce="The abstract of the paper states the following:",Y,j,me="<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>",N,T,q,x,de=`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.`,L,U,Q,_,ue="Currently 6 checkpoints are available for MatCha:",A,J,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>",D,k,fe="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.",K,Z,Me="You can use these models as follows (example on a ChatQA dataset):",O,V,ee,G,te,W,ge='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 faster convergence:',ae,F,ne,b,se,R,le,H,ie;return w=new X({props:{title:"MatCha",local:"matcha",headingTag:"h1"}}),$=new X({props:{title:"Overview",local:"overview",headingTag:"h2"}}),T=new X({props:{title:"Model description",local:"model-description",headingTag:"h2"}}),U=new X({props:{title:"Usage",local:"usage",headingTag:"h2"}}),V=new we({props:{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ZXNzb3IuZGVjb2RlKHByZWRpY3Rpb25zJTVCMCU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSk=",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>))`,wrap:!1}}),G=new X({props:{title:"Fine-tuning",local:"fine-tuning",headingTag:"h2"}}),F=new we({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>)`,wrap:!1}}),b=new _e({props:{$$slots:{default:[ke]},$$scope:{ctx:P}}}),R=new Je({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/matcha.md"}}),{c(){i=o("meta"),y=s(),p=o("p"),B=s(),m(w.$$.fragment),S=s(),g=o("div"),g.innerHTML=re,E=s(),m($.$$.fragment),z=s(),C=o("p"),C.innerHTML=pe,I=s(),v=o("p"),v.textContent=ce,Y=s(),j=o("p"),j.innerHTML=me,N=s(),m(T.$$.fragment),q=s(),x=o("p"),x.innerHTML=de,L=s(),m(U.$$.fragment),Q=s(),_=o("p"),_.textContent=ue,A=s(),J=o("ul"),J.innerHTML=he,D=s(),k=o("p"),k.innerHTML=fe,K=s(),Z=o("p"),Z.textContent=Me,O=s(),m(V.$$.fragment),ee=s(),m(G.$$.fragment),te=s(),W=o("p"),W.innerHTML=ge,ae=s(),m(F.$$.fragment),ne=s(),m(b.$$.fragment),se=s(),m(R.$$.fragment),le=s(),H=o("p"),this.h()},l(e){const t=xe("svelte-u9bgzb",document.head);i=r(t,"META",{name:!0,content:!0}),t.forEach(a),y=l(e),p=r(e,"P",{}),ye(p).forEach(a),B=l(e),d(w.$$.fragment,e),S=l(e),g=r(e,"DIV",{class:!0,"data-svelte-h":!0}),c(g)!=="svelte-13t8s2t"&&(g.innerHTML=re),E=l(e),d($.$$.fragment,e),z=l(e),C=r(e,"P",{"data-svelte-h":!0}),c(C)!=="svelte-v33y47"&&(C.innerHTML=pe),I=l(e),v=r(e,"P",{"data-svelte-h":!0}),c(v)!=="svelte-1pvthah"&&(v.textContent=ce),Y=l(e),j=r(e,"P",{"data-svelte-h":!0}),c(j)!=="svelte-s1ionu"&&(j.innerHTML=me),N=l(e),d(T.$$.fragment,e),q=l(e),x=r(e,"P",{"data-svelte-h":!0}),c(x)!=="svelte-18xkt0a"&&(x.innerHTML=de),L=l(e),d(U.$$.fragment,e),Q=l(e),_=r(e,"P",{"data-svelte-h":!0}),c(_)!=="svelte-1srev77"&&(_.textContent=ue),A=l(e),J=r(e,"UL",{"data-svelte-h":!0}),c(J)!=="svelte-1y39hb1"&&(J.innerHTML=he),D=l(e),k=r(e,"P",{"data-svelte-h":!0}),c(k)!=="svelte-11agvee"&&(k.innerHTML=fe),K=l(e),Z=r(e,"P",{"data-svelte-h":!0}),c(Z)!=="svelte-1ui48j4"&&(Z.textContent=Me),O=l(e),d(V.$$.fragment,e),ee=l(e),d(G.$$.fragment,e),te=l(e),W=r(e,"P",{"data-svelte-h":!0}),c(W)!=="svelte-1watpbk"&&(W.innerHTML=ge),ae=l(e),d(F.$$.fragment,e),ne=l(e),d(b.$$.fragment,e),se=l(e),d(R.$$.fragment,e),le=l(e),H=r(e,"P",{}),ye(H).forEach(a),this.h()},h(){oe(i,"name","hf:doc:metadata"),oe(i,"content",Ve),oe(g,"class","flex flex-wrap space-x-1")},m(e,t){Ue(document.head,i),n(e,y,t),n(e,p,t),n(e,B,t),u(w,e,t),n(e,S,t),n(e,g,t),n(e,E,t),u($,e,t),n(e,z,t),n(e,C,t),n(e,I,t),n(e,v,t),n(e,Y,t),n(e,j,t),n(e,N,t),u(T,e,t),n(e,q,t),n(e,x,t),n(e,L,t),u(U,e,t),n(e,Q,t),n(e,_,t),n(e,A,t),n(e,J,t),n(e,D,t),n(e,k,t),n(e,K,t),n(e,Z,t),n(e,O,t),u(V,e,t),n(e,ee,t),u(G,e,t),n(e,te,t),n(e,W,t),n(e,ae,t),u(F,e,t),n(e,ne,t),u(b,e,t),n(e,se,t),u(R,e,t),n(e,le,t),n(e,H,t),ie=!0},p(e,[t]){const be={};t&2&&(be.$$scope={dirty:t,ctx:e}),b.$set(be)},i(e){ie||(h(w.$$.fragment,e),h($.$$.fragment,e),h(T.$$.fragment,e),h(U.$$.fragment,e),h(V.$$.fragment,e),h(G.$$.fragment,e),h(F.$$.fragment,e),h(b.$$.fragment,e),h(R.$$.fragment,e),ie=!0)},o(e){f(w.$$.fragment,e),f($.$$.fragment,e),f(T.$$.fragment,e),f(U.$$.fragment,e),f(V.$$.fragment,e),f(G.$$.fragment,e),f(F.$$.fragment,e),f(b.$$.fragment,e),f(R.$$.fragment,e),ie=!1},d(e){e&&(a(y),a(p),a(B),a(S),a(g),a(E),a(z),a(C),a(I),a(v),a(Y),a(j),a(N),a(q),a(x),a(L),a(Q),a(_),a(A),a(J),a(D),a(k),a(K),a(Z),a(O),a(ee),a(te),a(W),a(ae),a(ne),a(se),a(le),a(H)),a(i),M(w,e),M($,e),M(T,e),M(U,e),M(V,e),M(G,e),M(F,e),M(b,e),M(R,e)}}}const Ve='{"title":"MatCha","local":"matcha","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Model description","local":"model-description","sections":[],"depth":2},{"title":"Usage","local":"usage","sections":[],"depth":2},{"title":"Fine-tuning","local":"fine-tuning","sections":[],"depth":2}],"depth":1}';function Ge(P){return Ce(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Xe extends je{constructor(i){super(),Te(this,i,Ge,Ze,$e,{})}}export{Xe as component};
