🚀 DePlot模型卡
DePlot是一种用于视觉语言推理的模型,它将视觉语言推理挑战分解为绘图到文本翻译和对翻译文本进行推理两个步骤,能够有效提升在复杂人类编写查询上的推理能力。
🚀 快速开始
使用模型
你可以通过以下方式,将输入图像与问题结合起来进行预测:
from transformers import Pix2StructProcessor, Pix2StructForConditionalGeneration
import requests
from PIL import Image
processor = Pix2StructProcessor.from_pretrained('google/deplot')
model = Pix2StructForConditionalGeneration.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))
从T5x转换到Hugging Face
你可以使用convert_pix2struct_checkpoint_to_pytorch.py
脚本进行转换,如下所示:
python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --is_vqa
如果你要转换大型模型,请运行:
python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --use-large --is_vqa
保存后,你可以使用以下代码片段将转换后的模型推送到Hugging Face Hub:
from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
model = Pix2StructForConditionalGeneration.from_pretrained(PATH_TO_SAVE)
processor = Pix2StructProcessor.from_pretrained(PATH_TO_SAVE)
model.push_to_hub("USERNAME/MODEL_NAME")
processor.push_to_hub("USERNAME/MODEL_NAME")
✨ 主要特性
论文摘要指出:
图表等视觉语言在人类世界中无处不在。理解图表需要强大的推理能力。先前的最先进(SOTA)模型至少需要数万条训练示例,并且它们的推理能力仍然非常有限,尤其是在处理复杂的人类编写查询时。本文提出了第一个用于视觉语言推理的一次性解决方案。我们将视觉语言推理的挑战分解为两个步骤:(1)绘图到文本的翻译,以及(2)对翻译后的文本进行推理。该方法的关键是一个名为DePlot的模态转换模块,它将绘图或图表的图像转换为线性化表格。然后,DePlot的输出可以直接用于提示预训练的大语言模型(LLM),利用LLM的少样本推理能力。为了得到DePlot,我们通过建立统一的任务格式和指标来规范绘图到表格的任务,并在该任务上对DePlot进行端到端训练。然后,DePlot可以与LLM以即插即用的方式现成使用。与在超过28k个数据点上微调的SOTA模型相比,仅使用一次性提示的DePlot + LLM在图表问答任务的人类编写查询上比微调后的SOTA模型提高了24.0%。
📄 许可证
本模型采用Apache 2.0许可证。
🔗 贡献者
此模型最初由Fangyu Liu、Julian Martin Eisenschlos等人贡献,并由Younes Belkada添加到Hugging Face生态系统中。
📚 引用
如果你想引用这项工作,请考虑引用原始论文:
@misc{liu2022deplot,
title={DePlot: One-shot visual language reasoning by plot-to-table translation},
author={Liu, Fangyu and Eisenschlos, Julian Martin and Piccinno, Francesco and Krichene, Syrine and Pang, Chenxi and Lee, Kenton and Joshi, Mandar and Chen, Wenhu and Collier, Nigel and Altun, Yasemin},
year={2022},
eprint={2212.10505},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
