TinyCLIP-39M-PixelArt-Text

This is the text encoder of tomaarsen/TinyCLIP-39M-PixelArt, exported as a native Sentence Transformers model so that the image encoder does not need to be loaded into memory when embedding search queries. It maps text to the same 512-dimensional space as the full model's image embeddings, with Matryoshka support at 256 and 128 dimensions.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: tomaarsen/TinyCLIP-39M-PixelArt
  • Maximum Sequence Length: 77 text tokens
  • Output Dimensionality: 512 dimensions
  • Similarity Function: Cosine Similarity
  • Supported Modalities: Text
  • Parameters: 44,513,792
  • Language: English
  • License: Apache 2.0

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'pooler_output'}}, 'module_output_name': 'sentence_embedding', 'architecture': 'CLIPTextModel'})
  (1): Dense({'in_features': 512, 'out_features': 512, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
  (2): Normalize({'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
)

Usage

Direct Usage (Sentence Transformers)

First install the Sentence Transformers library:

pip install -U sentence-transformers

Use the multimodal model to embed images, then use the text-only model to embed queries into the same space:

from sentence_transformers import SentenceTransformer

multimodal_model = SentenceTransformer("tomaarsen/TinyCLIP-39M-PixelArt")
documents = [
    "https://huggingface.co/tomaarsen/TinyCLIP-39M-PixelArt/resolve/main/assets/image_0.jpg",
    "https://huggingface.co/tomaarsen/TinyCLIP-39M-PixelArt/resolve/main/assets/image_1.jpg",
    "https://huggingface.co/tomaarsen/TinyCLIP-39M-PixelArt/resolve/main/assets/image_2.jpg",
]
document_embeddings = multimodal_model.encode_document(documents, normalize_embeddings=True)
del multimodal_model

text_model = SentenceTransformer("tomaarsen/TinyCLIP-39M-PixelArt-Text")
queries = ["sturdy brass hook"]
query_embeddings = text_model.encode_query(queries, normalize_embeddings=True)
print(query_embeddings.shape, document_embeddings.shape)
# (1, 512) (3, 512)

similarities = text_model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.5635, -0.0755, -0.1246]])

For a search service, compute and store the image embeddings once. At query time, load only the text-only model and search the stored image embeddings.

Pass truncate_dim=256 or truncate_dim=128 when loading both models to use smaller embeddings. Use the same dimension for queries and images. Normalizing both sets of embeddings allows a dot-product index to reproduce cosine similarity scores.

The example images are RGB. For your own transparent pixel art, composite the image onto an RGB (128, 128, 128) background before encoding with the multimodal model, matching the training preprocessing.

Additional Resources

Citation

BibTeX

Sentence Transformers

@inproceedings{reimers-2019-sentence-bert,
    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
    author = "Reimers, Nils and Gurevych, Iryna",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
    month = "11",
    year = "2019",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/1908.10084",
}

MatryoshkaLoss

@misc{kusupati2024matryoshka,
    title={Matryoshka Representation Learning},
    author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
    year={2024},
    eprint={2205.13147},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}
Downloads last month
62
Safetensors
Model size
44.3M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for tomaarsen/TinyCLIP-39M-PixelArt-Text

Space using tomaarsen/TinyCLIP-39M-PixelArt-Text 1

Papers for tomaarsen/TinyCLIP-39M-PixelArt-Text