google/deplot
32233k
1---2language:3 - en4 - fr5 - ro6 - de7 - multilingual8inference: false9pipeline_tag: visual-question-answering10license: apache-2.011---12# Model card for DePlot13 14<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/deplot_architecture.png"15alt="drawing" width="600"/>16 17 18# Table of Contents19 200. [TL;DR](#TL;DR)211. [Using the model](#using-the-model)222. [Contribution](#contribution)233. [Citation](#citation)24 25# TL;DR26 27The abstract of the paper states that: 28 29> Visual language such as charts and plots is ubiquitous in the human world. Comprehending plots and charts requires strong reasoning skills. Prior state-of-the-art (SOTA) models require at least tens of thousands of training examples and their reasoning capabilities are still much limited, especially on complex human-written queries. This paper presents the first one-shot solution to visual language reasoning. We decompose the challenge of visual language reasoning into two steps: (1) plot-to-text translation, and (2) reasoning over the translated text. The key in this method is a modality conversion module, named as DePlot, which translates the image of a plot or chart to a linearized table. The output of DePlot can then be directly used to prompt a pretrained large language model (LLM), exploiting the few-shot reasoning capabilities of LLMs. To obtain DePlot, we standardize the plot-to-table task by establishing unified task formats and metrics, and train DePlot end-to-end on this task. DePlot can then be used off-the-shelf together with LLMs in a plug-and-play fashion. Compared with a SOTA model finetuned on more than >28k data points, DePlot+LLM with just one-shot prompting achieves a 24.0% improvement over finetuned SOTA on human-written queries from the task of chart QA.30 31 32# Using the model 33 34You can run a prediction by querying an input image together with a question as follows:35 36```python37from transformers import Pix2StructProcessor, Pix2StructForConditionalGeneration38import requests39from PIL import Image40 41processor = Pix2StructProcessor.from_pretrained('google/deplot')42model = Pix2StructForConditionalGeneration.from_pretrained('google/deplot')43 44url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/5090.png"45image = Image.open(requests.get(url, stream=True).raw)46 47inputs = processor(images=image, text="Generate underlying data table of the figure below:", return_tensors="pt")48predictions = model.generate(**inputs, max_new_tokens=512)49print(processor.decode(predictions[0], skip_special_tokens=True))50```51 52# Converting from T5x to huggingface53 54You can use the [`convert_pix2struct_checkpoint_to_pytorch.py`](https://github.com/huggingface/transformers/blob/main/src/transformers/models/pix2struct/convert_pix2struct_original_pytorch_to_hf.py) script as follows:55```bash56python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --is_vqa57```58if you are converting a large model, run:59```bash60python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --use-large --is_vqa61```62Once saved, you can push your converted model with the following snippet:63```python64from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor65 66model = Pix2StructForConditionalGeneration.from_pretrained(PATH_TO_SAVE)67processor = Pix2StructProcessor.from_pretrained(PATH_TO_SAVE)68 69model.push_to_hub("USERNAME/MODEL_NAME")70processor.push_to_hub("USERNAME/MODEL_NAME")71```72 73# Contribution74 75This model was originally contributed by Fangyu Liu, Julian Martin Eisenschlos et al. and added to the Hugging Face ecosystem by [Younes Belkada](https://huggingface.co/ybelkada).76 77# Citation78 79If you want to cite this work, please consider citing the original paper:80```81@misc{liu2022deplot,82 title={DePlot: One-shot visual language reasoning by plot-to-table translation},83 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},84 year={2022},85 eprint={2212.10505},86 archivePrefix={arXiv},87 primaryClass={cs.CL}88}89```