import{s as he,n as ue,o as Me}from"../chunks/scheduler.9bc65507.js";import{S as fe,i as ge,g as i,s,r as T,A as be,h as o,f as a,c as l,j as ce,u as x,x as p,k as me,y as ye,a as n,v as J,d as _,t as Z,w as k}from"../chunks/index.707bf1b6.js";import{C as de}from"../chunks/CodeBlock.54a9f38d.js";import{H as F}from"../chunks/Heading.342b1fa6.js";function we(ee){let r,G,V,R,c,B,m,X,d,te='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.',H,h,ae="The abstract of the paper states the following:",S,u,ne="<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>",z,M,E,f,se=`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.`,I,g,P,b,le="Currently 6 checkpoints are available for MatCha:",Y,y,ie="<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>",N,w,oe="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.",Q,C,re="You can use these models as follows (example on a ChatQA dataset):",q,v,A,j,L,U,pe='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:',D,$,K,W,O;return c=new F({props:{title:"MatCha",local:"matcha",headingTag:"h1"}}),m=new F({props:{title:"Overview",local:"overview",headingTag:"h2"}}),M=new F({props:{title:"Model description",local:"model-description",headingTag:"h2"}}),g=new F({props:{title:"Usage",local:"usage",headingTag:"h2"}}),v=new de({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>))`,wrap:!1}}),j=new F({props:{title:"Fine-tuning",local:"fine-tuning",headingTag:"h2"}}),$=new de({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}}),{c(){r=i("meta"),G=s(),V=i("p"),R=s(),T(c.$$.fragment),B=s(),T(m.$$.fragment),X=s(),d=i("p"),d.innerHTML=te,H=s(),h=i("p"),h.textContent=ae,S=s(),u=i("p"),u.innerHTML=ne,z=s(),T(M.$$.fragment),E=s(),f=i("p"),f.innerHTML=se,I=s(),T(g.$$.fragment),P=s(),b=i("p"),b.textContent=le,Y=s(),y=i("ul"),y.innerHTML=ie,N=s(),w=i("p"),w.innerHTML=oe,Q=s(),C=i("p"),C.textContent=re,q=s(),T(v.$$.fragment),A=s(),T(j.$$.fragment),L=s(),U=i("p"),U.innerHTML=pe,D=s(),T($.$$.fragment),K=s(),W=i("p"),this.h()},l(e){const t=be("svelte-u9bgzb",document.head);r=o(t,"META",{name:!0,content:!0}),t.forEach(a),G=l(e),V=o(e,"P",{}),ce(V).forEach(a),R=l(e),x(c.$$.fragment,e),B=l(e),x(m.$$.fragment,e),X=l(e),d=o(e,"P",{"data-svelte-h":!0}),p(d)!=="svelte-v33y47"&&(d.innerHTML=te),H=l(e),h=o(e,"P",{"data-svelte-h":!0}),p(h)!=="svelte-1pvthah"&&(h.textContent=ae),S=l(e),u=o(e,"P",{"data-svelte-h":!0}),p(u)!=="svelte-s1ionu"&&(u.innerHTML=ne),z=l(e),x(M.$$.fragment,e),E=l(e),f=o(e,"P",{"data-svelte-h":!0}),p(f)!=="svelte-18xkt0a"&&(f.innerHTML=se),I=l(e),x(g.$$.fragment,e),P=l(e),b=o(e,"P",{"data-svelte-h":!0}),p(b)!=="svelte-1srev77"&&(b.textContent=le),Y=l(e),y=o(e,"UL",{"data-svelte-h":!0}),p(y)!=="svelte-1y39hb1"&&(y.innerHTML=ie),N=l(e),w=o(e,"P",{"data-svelte-h":!0}),p(w)!=="svelte-11agvee"&&(w.innerHTML=oe),Q=l(e),C=o(e,"P",{"data-svelte-h":!0}),p(C)!=="svelte-1ui48j4"&&(C.textContent=re),q=l(e),x(v.$$.fragment,e),A=l(e),x(j.$$.fragment,e),L=l(e),U=o(e,"P",{"data-svelte-h":!0}),p(U)!=="svelte-9sjid8"&&(U.innerHTML=pe),D=l(e),x($.$$.fragment,e),K=l(e),W=o(e,"P",{}),ce(W).forEach(a),this.h()},h(){me(r,"name","hf:doc:metadata"),me(r,"content",Ce)},m(e,t){ye(document.head,r),n(e,G,t),n(e,V,t),n(e,R,t),J(c,e,t),n(e,B,t),J(m,e,t),n(e,X,t),n(e,d,t),n(e,H,t),n(e,h,t),n(e,S,t),n(e,u,t),n(e,z,t),J(M,e,t),n(e,E,t),n(e,f,t),n(e,I,t),J(g,e,t),n(e,P,t),n(e,b,t),n(e,Y,t),n(e,y,t),n(e,N,t),n(e,w,t),n(e,Q,t),n(e,C,t),n(e,q,t),J(v,e,t),n(e,A,t),J(j,e,t),n(e,L,t),n(e,U,t),n(e,D,t),J($,e,t),n(e,K,t),n(e,W,t),O=!0},p:ue,i(e){O||(_(c.$$.fragment,e),_(m.$$.fragment,e),_(M.$$.fragment,e),_(g.$$.fragment,e),_(v.$$.fragment,e),_(j.$$.fragment,e),_($.$$.fragment,e),O=!0)},o(e){Z(c.$$.fragment,e),Z(m.$$.fragment,e),Z(M.$$.fragment,e),Z(g.$$.fragment,e),Z(v.$$.fragment,e),Z(j.$$.fragment,e),Z($.$$.fragment,e),O=!1},d(e){e&&(a(G),a(V),a(R),a(B),a(X),a(d),a(H),a(h),a(S),a(u),a(z),a(E),a(f),a(I),a(P),a(b),a(Y),a(y),a(N),a(w),a(Q),a(C),a(q),a(A),a(L),a(U),a(D),a(K),a(W)),a(r),k(c,e),k(m,e),k(M,e),k(g,e),k(v,e),k(j,e),k($,e)}}}const Ce='{"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 ve(ee){return Me(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xe extends fe{constructor(r){super(),ge(this,r,ve,we,he,{})}}export{xe as component};
