Instructions to use tomaarsen/TinyCLIP-39M-PixelArt-Text with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use tomaarsen/TinyCLIP-39M-PixelArt-Text with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("tomaarsen/TinyCLIP-39M-PixelArt-Text") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
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
- Documentation: Sentence Transformers Documentation
- Repository: Sentence Transformers on GitHub
- Multimodal model and training details: TinyCLIP-39M-PixelArt
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
- Introduction to Matryoshka Embedding Models: variable-size embeddings that can be truncated with minimal quality loss.
- Multimodal Embedding & Reranker Models with Sentence Transformers: use text and images through the same API.
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
Model tree for tomaarsen/TinyCLIP-39M-PixelArt-Text
Base model
wkcn/TinyCLIP-ViT-39M-16-Text-19M-YFCC15M