google/pix2struct-base
8021k
1---2language:3 - en4 - fr5 - ro6 - de7 - multilingual8pipeline_tag: image-to-text9inference: false10license: apache-2.011---12 13 14# Model card for Pix2Struct - Pretrained weights15 1617 18This model is the pretrained version of `Pix2Struct`, use this model for fine-tuning purposes only.19 20# Table of Contents21 220. [TL;DR](#TL;DR)231. [Using the model](#using-the-model)242. [Contribution](#contribution)253. [Citation](#citation)26 27# TL;DR28 29Pix2Struct is an image encoder - text decoder model that is trained on image-text pairs for various tasks, including image captionning and visual question answering. The full list of available models can be found on the Table 1 of the paper:30 3132 33 34The abstract of the model states that: 35> Visually-situated language is ubiquitous—sources range from textbooks with diagrams to web pages with images and tables, to mobile apps with buttons and36forms. Perhaps due to this diversity, previous work has typically relied on domainspecific recipes with limited sharing of the underlying data, model architectures,37and objectives. We present Pix2Struct, a pretrained image-to-text model for38purely visual language understanding, which can be finetuned on tasks containing visually-situated language. Pix2Struct is pretrained by learning to parse39masked screenshots of web pages into simplified HTML. The web, with its richness of visual elements cleanly reflected in the HTML structure, provides a large40source of pretraining data well suited to the diversity of downstream tasks. Intuitively, this objective subsumes common pretraining signals such as OCR, language modeling, image captioning. In addition to the novel pretraining strategy,41we introduce a variable-resolution input representation and a more flexible integration of language and vision inputs, where language prompts such as questions42are rendered directly on top of the input image. For the first time, we show that a43single pretrained model can achieve state-of-the-art results in six out of nine tasks44across four domains: documents, illustrations, user interfaces, and natural images.45 46# Using the model 47 48## Converting from T5x to huggingface49 50You 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:51```bash52python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE53```54if you are converting a large model, run:55```bash56python convert_pix2struct_checkpoint_to_pytorch.py --t5x_checkpoint_path PATH_TO_T5X_CHECKPOINTS --pytorch_dump_path PATH_TO_SAVE --use-large57```58Once saved, you can push your converted model with the following snippet:59```python60from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor61 62model = Pix2StructForConditionalGeneration.from_pretrained(PATH_TO_SAVE)63processor = Pix2StructProcessor.from_pretrained(PATH_TO_SAVE)64 65model.push_to_hub("USERNAME/MODEL_NAME")66processor.push_to_hub("USERNAME/MODEL_NAME")67```68 69# Contribution70 71This model was originally contributed by Kenton Lee, Mandar Joshi et al. and added to the Hugging Face ecosystem by [Younes Belkada](https://huggingface.co/ybelkada).72 73# Citation74 75If you want to cite this work, please consider citing the original paper:76```77@misc{https://doi.org/10.48550/arxiv.2210.03347,78 doi = {10.48550/ARXIV.2210.03347},79 80 url = {https://arxiv.org/abs/2210.03347},81 82 author = {Lee, Kenton and Joshi, Mandar and Turc, Iulia and Hu, Hexiang and Liu, Fangyu and Eisenschlos, Julian and Khandelwal, Urvashi and Shaw, Peter and Chang, Ming-Wei and Toutanova, Kristina},83 84 keywords = {Computation and Language (cs.CL), Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},85 86 title = {Pix2Struct: Screenshot Parsing as Pretraining for Visual Language Understanding},87 88 publisher = {arXiv},89 90 year = {2022},91 92 copyright = {Creative Commons Attribution 4.0 International}93}94```