Transformers documentation

DePlot

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-20 在 HF papers 上发布,并于 2023-06-20 贡献给 Hugging Face Transformers。

DePlot

概述

DePlot 由 Fangyu Liu、Julian Martin Eisenschlos、Francesco Piccinno、Syrine Krichene、Chenxi Pang、Kenton Lee、Mandar Joshi、Wenhu Chen、Nigel Collier 和 Yasemin Altun 在论文 DePlot: One-shot visual language reasoning by plot-to-table translation 中提出。

该论文的摘要指出:

图表和绘图等视觉语言在人类世界中无处不在。理解图表需要强大的推理能力。此前的最先进(SOTA)模型至少需要数万条训练样本,且其推理能力仍然十分有限,尤其是在处理复杂的人工编写查询时。本文提出了首个针对视觉语言推理的单样本(one-shot)解决方案。我们将视觉语言推理的挑战分解为两个步骤:(1)图表到文本的转换,以及(2)对转换后文本的推理。该方法的关键是一个名为 DePlot 的模态转换模块,它可以将图表或绘图的图像转换为线性化表格。DePlot 的输出可以直接用于提示预训练的大语言模型(LLM),从而利用 LLM 的少样本推理能力。为了获得 DePlot,我们通过建立统一的任务格式和指标来标准化图表到表格的任务,并在该任务上端到端地训练 DePlot。随后,DePlot 可以与 LLM 以即插即用的方式开箱即用。与在超过 >28k 个数据点上微调的 SOTA 模型相比,仅使用单样本提示的 DePlot+LLM 在图表问答任务的人工编写查询上,比微调后的 SOTA 模型提升了 24.0%。

DePlot 是一个使用 Pix2Struct 架构训练的模型。您可以在 Pix2Struct 文档 中了解有关 Pix2Struct 的更多信息。 DePlot 是 Pix2Struct 架构下的视觉问答子集。它会将输入的问题渲染到图像上,并预测答案。

使用示例

目前 DePlot 有一个可用的检查点:

  • google/deplot:在 ChartQA 数据集上微调的 DePlot
import requests
from PIL import Image

from transformers import AutoProcessor, Pix2StructForConditionalGeneration


model = Pix2StructForConditionalGeneration.from_pretrained("google/deplot", device_map="auto")
processor = AutoProcessor.from_pretrained("google/deplot")
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/5090.png"
image = Image.open(requests.get(url, stream=True).raw)

inputs = processor(images=image, text="Generate underlying data table of the figure below:", return_tensors="pt").to(model.device)
predictions = model.generate(**inputs, max_new_tokens=512)
print(processor.decode(predictions[0], skip_special_tokens=True))

微调

若要微调 DePlot,请参阅 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)

DePlot 是一个使用 Pix2Struct 架构训练的模型。有关 API 参考,请参阅 Pix2Struct 文档。

Update on GitHub