import{s as be,o as ye,n as we}from"../chunks/scheduler.25b97de1.js";import{S as $e,i as Ce,g as o,s,r as c,A as ve,h as r,f as a,c as l,j as fe,u as d,x as m,k as Me,y as je,a as n,v as u,d as h,t as f,w as M}from"../chunks/index.d9030fc9.js";import{T as Te}from"../chunks/Tip.baa67368.js";import{C as ge}from"../chunks/CodeBlock.e6cd0d95.js";import{H as X,E as xe}from"../chunks/EditOnGithub.91d95064.js";function Ue(H){let i,b='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=b},l(p){i=r(p,"P",{"data-svelte-h":!0}),m(i)!=="svelte-1t6iq26"&&(i.innerHTML=b)},m(p,R){n(p,i,R)},p:we,d(p){p&&a(i)}}}function _e(H){let i,b,p,R,y,S,w,P,$,le='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.',E,C,ie="The abstract of the paper states the following:",z,v,oe="<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>",Y,j,I,T,re=`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.`,N,x,q,U,pe="Currently 6 checkpoints are available for MatCha:",Q,_,me="<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>",A,J,ce="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.",L,Z,de="You can use these models as follows (example on a ChatQA dataset):",D,k,K,G,O,V,ue='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:',ee,W,te,g,ae,F,ne,B,se;return y=new X({props:{title:"MatCha",local:"matcha",headingTag:"h1"}}),w=new X({props:{title:"Overview",local:"overview",headingTag:"h2"}}),j=new X({props:{title:"Model description",local:"model-description",headingTag:"h2"}}),x=new X({props:{title:"Usage",local:"usage",headingTag:"h2"}}),k=new ge({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMkMlMjBQaXg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0RUcnVlKSk=",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"}}),W=new ge({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}}),g=new Te({props:{$$slots:{default:[Ue]},$$scope:{ctx:H}}}),F=new xe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/matcha.md"}}),{c(){i=o("meta"),b=s(),p=o("p"),R=s(),c(y.$$.fragment),S=s(),c(w.$$.fragment),P=s(),$=o("p"),$.innerHTML=le,E=s(),C=o("p"),C.textContent=ie,z=s(),v=o("p"),v.innerHTML=oe,Y=s(),c(j.$$.fragment),I=s(),T=o("p"),T.innerHTML=re,N=s(),c(x.$$.fragment),q=s(),U=o("p"),U.textContent=pe,Q=s(),_=o("ul"),_.innerHTML=me,A=s(),J=o("p"),J.innerHTML=ce,L=s(),Z=o("p"),Z.textContent=de,D=s(),c(k.$$.fragment),K=s(),c(G.$$.fragment),O=s(),V=o("p"),V.innerHTML=ue,ee=s(),c(W.$$.fragment),te=s(),c(g.$$.fragment),ae=s(),c(F.$$.fragment),ne=s(),B=o("p"),this.h()},l(e){const t=ve("svelte-u9bgzb",document.head);i=r(t,"META",{name:!0,content:!0}),t.forEach(a),b=l(e),p=r(e,"P",{}),fe(p).forEach(a),R=l(e),d(y.$$.fragment,e),S=l(e),d(w.$$.fragment,e),P=l(e),$=r(e,"P",{"data-svelte-h":!0}),m($)!=="svelte-v33y47"&&($.innerHTML=le),E=l(e),C=r(e,"P",{"data-svelte-h":!0}),m(C)!=="svelte-1pvthah"&&(C.textContent=ie),z=l(e),v=r(e,"P",{"data-svelte-h":!0}),m(v)!=="svelte-s1ionu"&&(v.innerHTML=oe),Y=l(e),d(j.$$.fragment,e),I=l(e),T=r(e,"P",{"data-svelte-h":!0}),m(T)!=="svelte-18xkt0a"&&(T.innerHTML=re),N=l(e),d(x.$$.fragment,e),q=l(e),U=r(e,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1srev77"&&(U.textContent=pe),Q=l(e),_=r(e,"UL",{"data-svelte-h":!0}),m(_)!=="svelte-1y39hb1"&&(_.innerHTML=me),A=l(e),J=r(e,"P",{"data-svelte-h":!0}),m(J)!=="svelte-11agvee"&&(J.innerHTML=ce),L=l(e),Z=r(e,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-1ui48j4"&&(Z.textContent=de),D=l(e),d(k.$$.fragment,e),K=l(e),d(G.$$.fragment,e),O=l(e),V=r(e,"P",{"data-svelte-h":!0}),m(V)!=="svelte-9sjid8"&&(V.innerHTML=ue),ee=l(e),d(W.$$.fragment,e),te=l(e),d(g.$$.fragment,e),ae=l(e),d(F.$$.fragment,e),ne=l(e),B=r(e,"P",{}),fe(B).forEach(a),this.h()},h(){Me(i,"name","hf:doc:metadata"),Me(i,"content",Je)},m(e,t){je(document.head,i),n(e,b,t),n(e,p,t),n(e,R,t),u(y,e,t),n(e,S,t),u(w,e,t),n(e,P,t),n(e,$,t),n(e,E,t),n(e,C,t),n(e,z,t),n(e,v,t),n(e,Y,t),u(j,e,t),n(e,I,t),n(e,T,t),n(e,N,t),u(x,e,t),n(e,q,t),n(e,U,t),n(e,Q,t),n(e,_,t),n(e,A,t),n(e,J,t),n(e,L,t),n(e,Z,t),n(e,D,t),u(k,e,t),n(e,K,t),u(G,e,t),n(e,O,t),n(e,V,t),n(e,ee,t),u(W,e,t),n(e,te,t),u(g,e,t),n(e,ae,t),u(F,e,t),n(e,ne,t),n(e,B,t),se=!0},p(e,[t]){const he={};t&2&&(he.$$scope={dirty:t,ctx:e}),g.$set(he)},i(e){se||(h(y.$$.fragment,e),h(w.$$.fragment,e),h(j.$$.fragment,e),h(x.$$.fragment,e),h(k.$$.fragment,e),h(G.$$.fragment,e),h(W.$$.fragment,e),h(g.$$.fragment,e),h(F.$$.fragment,e),se=!0)},o(e){f(y.$$.fragment,e),f(w.$$.fragment,e),f(j.$$.fragment,e),f(x.$$.fragment,e),f(k.$$.fragment,e),f(G.$$.fragment,e),f(W.$$.fragment,e),f(g.$$.fragment,e),f(F.$$.fragment,e),se=!1},d(e){e&&(a(b),a(p),a(R),a(S),a(P),a($),a(E),a(C),a(z),a(v),a(Y),a(I),a(T),a(N),a(q),a(U),a(Q),a(_),a(A),a(J),a(L),a(Z),a(D),a(K),a(O),a(V),a(ee),a(te),a(ae),a(ne),a(B)),a(i),M(y,e),M(w,e),M(j,e),M(x,e),M(k,e),M(G,e),M(W,e),M(g,e),M(F,e)}}}const Je='{"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 Ze(H){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends $e{constructor(i){super(),Ce(this,i,Ze,_e,be,{})}}export{Re as component};
