Transformers documentation

MatCha

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

このモデルは2022年12月19日にHF papersで公開され、2023年6月20日にHugging Face Transformersに貢献されました。

MatCha

概要

MatChaは、Fangyu Liu、Francesco Piccinno、Syrine Krichene、Chenxi Pang、Kenton Lee、Mandar Joshi、Yasemin Altun、Nigel Collier、Julian Martin Eisenschlos による論文 MatCha: Enhancing Visual Language Pretraining with Math Reasoning and Chart Derendering で提案されました。

この論文の要旨には、次のように記載されています。

プロット、チャート、インフォグラフィックなどの視覚言語データは、人間の社会に広く存在しています。しかし、最先端の視覚言語モデルは、これらのデータに対して高い性能を発揮していません。私たちは、チャート/プロットと言語データを同時にモデル링する能力を強化するために、MatCha(Math reasoning and Chart derendering pretraining)を提案します。具体的には、視覚言語モデリングにおける重要な能力であるプロットの分解と数値推論をカバーするいくつかの事前学習タスクを提案します。MatChaの事前学習は、最近提案された画像からテキストへの視覚言語モデルであるPix2Structを起点として行います。PlotQAやChartQAなどの標準ベンチマークにおいて、MatChaモデルは最先端の手法を最大で約20%上回る性能を示しました。さらに、スクリーンショット、教科書の図、文書の図などのドメインへのMatCha事前学習の転移を調査し、全体的な性能向上を観察しました。これにより、より幅広い視覚言語タスクにおけるMatCha事前学習の有用性が検証されました。

モデルの説明

MatCha は Pix2Struct アーキテクチャを用いて学習されたモデルです。Pix2Struct に関する詳細は、Pix2Struct のドキュメントを参照してください。 MatCha は Pix2Struct アーキテクチャの Visual Question Answering サブセットです。入力された質問を画像上にレンダリングし、答えを予測します。

使用方法

現在、MatChaには6つのチェックポイントが利用可能です:

  • google/matcha: MatChaのベースモデル。MatChaをダウンストリームタスクにファインチューニングするために使用します
  • google/matcha-chartqa: ChartQAデータセットでファインチューニングされたMatChaモデルです。チャートに関する質問に回答するために使用できます。
  • google/matcha-plotqa-v1: PlotQAデータセットでファインチューニングされたMatChaモデルです。プロットに関する質問に回答するために使用できます。
  • google/matcha-plotqa-v2: PlotQAデータセットでファインチューニングされたMatChaモデルです。プロットに関する質問に回答するために使用できます。
  • google/matcha-chart2text-statista: Statista データセットでファインチューニングされた MatCha モデル。
  • google/matcha-chart2text-pew: PewデータセットでファインチューニングされたMatChaモデル。

chart2text-pew と chart2text-statista でファインチューニングされたモデルは要約に適しており、plotqa と chartqa でファインチューニングされたモデルは質問応答に適しています。

これらのモデルは、次のように使用できます(ChartQAデータセットの例):

import requests
from PIL import Image

from transformers import AutoProcessor, Pix2StructForConditionalGeneration


model = Pix2StructForConditionalGeneration.from_pretrained("google/matcha-chartqa").to(0, device_map="auto")
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))

ファインチューニング

MatChaのファインチューニングについては、pix2structのファインチューニングノートブックを参照してください。Pix2Structモデルについては、Adafactorとコサイン学習率スケジューラーを用いてモデルをファインチューニングすると、収束が速まることが確認されています:

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)

MatCha は、Pix2Struct アーキテクチャを使用して学習されたモデルです。Pix2Struct に関する詳細は、Pix2Struct のドキュメントを参照してください。

Update on GitHub