Skip to main content

Multi-Modality

PALI: A JOINTLY-SCALED MULTILINGUAL LANGUAGE-IMAGE MODEL

pali

GitHub issues GitHub forks GitHub stars GitHub license Share on Twitter Share on Facebook Share on LinkedIn Discord Share on Reddit Share on Hacker News Share on Pinterest Share on WhatsApp

The open source implementation of the Multi-Modality AI model from "PaLI: Scaling Language-Image Learning in 100+ Languages" The model architecture is text -> encoder -> decoder -> logits -> text. The Vision architecture is image -> vit -> embeddings -> encoder -> decoder -> logits -> text

NOTE

  • This is the base model architecture, no tokenizer or pretrained weights
  • To train, find tokenizer, like tokenmonster and patchify the images to make it compatible with example.py
  • We're utilizing an Encoder/Decoder as UL2 and a VIT model that embeds the image which is then injected into the text encoder decoder
  • If you would like to help train this model and release it open source please click on the agora banner and join the lab!

🌟 Appreciation

Big bear hugs 🐻💖 to LucidRains for the fab x_transformers and for championing the open source AI cause.

🚀 Install

pip install pali-torch

🧙 Usage

import torch  # Importing the torch library for tensor operations
from pali import Pali  # Importing the Pali class from the pali module

model = Pali()  # Creating an instance of the Pali class and assigning it to the variable 'model'

img = torch.randn(1, 3, 256, 256)  # Creating a random image tensor with shape (1, 3, 256, 256)
# The shape represents (batch_size, channels, height, width)

prompt = torch.randint(0, 256, (1, 1024))  # Creating a random text integer tensor with shape (1, 1024)
# The shape represents (batch_size, sequence_length)

output_text = torch.randint(0, 256, (1, 1024))  # Creating a random target text integer tensor with shape (1, 1024)
# The shape represents (batch_size, sequence_length)

out = model.forward(img, prompt, output_text, mask=None)  # Calling the forward method of the 'model' instance
# The forward method takes the image tensor, prompt tensor, output_text tensor, and an optional mask tensor as inputs
# It performs computations and returns the output tensor

print(out)  # Printing the output tensor

Vit Image Embedder

  • To embed your images, you can use the vit model:
from PIL import Image
from torchvision import transforms

from pali.model import VitModel


def img_to_tensor(img: str = "pali.png", img_size: int = 256):
    # Load image
    image = Image.open(img)

    # Define a transforms to convert the image to a tensor and apply preprocessing
    transform = transforms.Compose(
        [
            transforms.Lambda(lambda image: image.convert("RGB")),
            transforms.Resize((img_size, img_size)),  # Resize the image to 256x256
            transforms.ToTensor(),  # Convert the image to a tensor,
            transforms.Normalize(
                mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
            ),  # Normalize the pixel values
        ]
    )

    # apply transforms to the image
    x = transform(image)

    # print(f"Image shape: {x.shape}")

    # Add batch dimension
    x = x.unsqueeze(0)
    print(x.shape)

    return x


# Convert image to tensor
x = img_to_tensor()

# # Initialize model
model = VitModel()

# Forward pass
out = model(x)

# Print output shape
print(out)

Datasets Strategy

Dataset strategy as closely shown in the paper.

Here is a markdown table with metadata and links to the datasets on HuggingFace for the datasets used:

Dataset Description Size Languages Link
WebLI Large-scale web crawled image-text dataset 10B images, 12B captions 109 languages Private
CC3M Conceptual Captions dataset 3M image-text pairs English Link
CC3M-35L Translated version of CC3M to 35 languages 105M image-text pairs 36 languages Private
VQAv2 VQA dataset built on COCO images 204K images, 1.1M QA pairs English Link
VQ2A-CC3M VQA dataset built from CC3M 3M image-text pairs English Private
VQ2A-CC3M-35L Translated version of VQ2A-CC3M to 35 languages 105M image-text pairs 36 languages Private
Open Images Large scale image dataset 9M images with labels English Link
Visual Genome Image dataset with dense annotations 108K images with annotations English Link
Object365 Image dataset for object detection 500K images with labels English Private

The key datasets used for pre-training PaLI include:

  • WebLI: A large-scale multilingual image-text dataset crawled from the web, comprising 10B images and 12B captions in 109 languages.

  • CC3M-35L: CC3M Conceptual Captions dataset machine translated into 35 additional languages, totaling 105M image-text pairs in 36 languages.

  • VQ2A-CC3M-35L: VQA dataset based on CC3M, also translated into 35 languages.

The model was evaluated on diverse tasks using standard datasets like VQAv2, Open Images, COCO Captions etc. Links and details provided above.



🎉 Features

  • Double the Power: MT5 for text and ViT for images - Pali's the superhero we didn't know we needed! 💪📖🖼️
  • Winning Streak: With roots in the tried-and-true MT5 & ViT, success is in Pali's DNA. 🏆
  • Ready, Set, Go: No fuss, no muss! Get Pali rolling in no time. ⏱️
  • Easy-Peasy: Leave the heavy lifting to Pali and enjoy your smooth sailing. 🛳️

🌆 Real-World Use-Cases

  • E-commerce: Jazz up those recs! Understand products inside-out with images & descriptions. 🛍️
  • Social Media: Be the smart reply guru for posts with pics & captions. 📱
  • Healthcare: Boost diagnostics with insights from images & textual data. 🏥

📚 Citation

@inproceedings{chen2022pali,
  title={PaLI: Scaling Language-Image Learning in 100+ Languages},
  author={Chen, Xi and Wang, Xiao},
  booktitle={Conference on Neural Information Processing Systems (NeurIPS)},
  year={2022}
}

Todo

  • Make a table of datasets used in paper,
  • Provide tokenizer integration
  • Provide training script
  • Provide usage/inference scripts

📜 License

MIT

Metadata

Release files for pali-torch 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pali-torch 0.0.9
File Size Uploaded
pali_torch-0.0.9.tar.gz 28.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pali-torch 0.0.9
File Interpreter ABI Platform
pali_torch-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 53.8 kB

Release files / pali_torch-0.0.9.tar.gz

Download URL pali_torch-0.0.9.tar.gz
Size 28.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1a35e19c82fa7feabde5dc881e845b390c4afe09b18276e128a6f58c111e636e
BLAKE2b-256 checksum
How to use checksums
ce967a7419287b850ecd33f6309268bab33cec1843c1843bf7b4ea8f077c6b39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.0 Darwin/23.3.0

Release files / pali_torch-0.0.9-py3-none-any.whl

Download URL pali_torch-0.0.9-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79d02b18286fc436fd89608ba7596609f322d857870f6b530190f2e666e29bbf
BLAKE2b-256 checksum
How to use checksums
6018958be75ca1317ca51eab9db29187932fb5066a72056252b66a411c17252c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.0 Darwin/23.3.0

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page