🚀 ChartVE (チャート視覚含意)
ChartVEは、論文「Do LVLMs Understand Charts? Analyzing and Correcting Factual Errors in Chart Captioning」で紹介された視覚含意モデルです。このモデルは、入力されたチャートに対する生成キャプション文の事実性を評価するために使用されます。モデルはチャート図とキャプション文を入力として受け取り、含意確率を出力します。含意確率の計算方法については、以下の「使い方」セクションを参照してください。このモデルの基礎となるアーキテクチャはUniChartです。
なお、このモデルはキャプション文をテキスト入力として期待しています。キャプションが複数文から構成される場合は、キャプションを複数の文に分割し、個々の文をChartVEに入力してからスコアを集約する必要があります。以下に、ChartVEの使用例を示します。
🚀 クイックスタート
使い方
事前学習済みモデルを直接使用する方法は次のとおりです。
from transformers import DonutProcessor, VisionEncoderDecoderModel
from PIL import Image
model_name = "khhuang/chartve"
model = VisionEncoderDecoderModel.from_pretrained(model_name).cuda()
processor = DonutProcessor.from_pretrained(model_name)
image_path = "PATH_TO_IMAGE"
def format_query(sentence):
return f"Does the image entails this statement: \"{sentence}\"?"
CAPTION_SENTENCE = "The state that has the highest number of population is California."
query = format_query(CAPTION_SENTENCE)
img = Image.open(IMAGE_PATH)
pixel_values = processor(img.convert("RGB"), random_padding=False, return_tensors="pt").pixel_values
pixel_values = pixel_values.cuda()
decoder_input_ids = processor.tokenizer(query, add_special_tokens=False, return_tensors="pt", max_length=510).input_ids.cuda()
outputs = model(pixel_values, decoder_input_ids=decoder_input_ids)
binary_entail_prob_positive = torch.nn.functional.softmax(outputs['logits'].squeeze()[-1,[2334, 49922]])[1].item()
💻 使用例
基本的な使用法
from transformers import DonutProcessor, VisionEncoderDecoderModel
from PIL import Image
model_name = "khhuang/chartve"
model = VisionEncoderDecoderModel.from_pretrained(model_name).cuda()
processor = DonutProcessor.from_pretrained(model_name)
image_path = "PATH_TO_IMAGE"
def format_query(sentence):
return f"Does the image entails this statement: \"{sentence}\"?"
CAPTION_SENTENCE = "The state that has the highest number of population is California."
query = format_query(CAPTION_SENTENCE)
img = Image.open(IMAGE_PATH)
pixel_values = processor(img.convert("RGB"), random_padding=False, return_tensors="pt").pixel_values
pixel_values = pixel_values.cuda()
decoder_input_ids = processor.tokenizer(query, add_special_tokens=False, return_tensors="pt", max_length=510).input_ids.cuda()
outputs = model(pixel_values, decoder_input_ids=decoder_input_ids)
binary_entail_prob_positive = torch.nn.functional.softmax(outputs['logits'].squeeze()[-1,[2334, 49922]])[1].item()
📄 ライセンス
このモデルはApache-2.0ライセンスの下で提供されています。
📚 引用
@misc{huang-etal-2023-do,
title = "Do LVLMs Understand Charts? Analyzing and Correcting Factual Errors in Chart Captioning",
author = "Huang, Kung-Hsiang and
Zhou, Mingyang and
Chan, Hou Pong and
Fung, Yi R. and
Wang, Zhenhailong and
Zhang, Lingyu and
Chang, Shih-Fu and
Ji, Heng",
year={2023},
eprint={2312.10160},
archivePrefix={arXiv},
primaryClass={cs.CL}
}