🚀 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}
}
