Transformers 文档
DePlot
并获得增强的文档体验
开始使用
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) 模型需要至少数万个训练样本,其推理能力仍然非常有限,尤其是在处理复杂的人工编写查询时。本文提出了第一个用于视觉语言推理的单次解决方案。我们将视觉语言推理的挑战分解为两个步骤:(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
from transformers import AutoProcessor, Pix2StructForConditionalGeneration
import requests
from PIL import Image
model = Pix2StructForConditionalGeneration.from_pretrained("google/deplot")
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")
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` 文档。